Skip to content

Commit

Permalink
release: SDK 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-roland committed Oct 29, 2024
1 parent 6de7c98 commit 8f829be
Show file tree
Hide file tree
Showing 20 changed files with 12,027 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Sources/buildSrc/src/main/java/Consts.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
object ProjectConsts {
const val COMPILE_SDK = 34
const val COMPILE_SDK = 35

const val KOTLIN_VERSION = "1.9.0"
const val KOTLIN_COROUTINES_VERSION = "1.7.1"

const val ANDROID_LINT_VERSION = "30.1.2"

const val ANDROID_GRADLE_PLUGIN_VERSION = "8.3.0"
const val ANDROID_GRADLE_PLUGIN_VERSION = "8.6.0"
const val GMS_GRADLE_PLUGIN_VERSION = "4.3.14"
}

object SDKConsts {
const val VERSION = "2.0.3"
const val API_LEVEL = 200
const val VERSION = "2.1.0"
const val API_LEVEL = 210
const val MESSAGING_API_LEVEL = 12

const val MIN_SDK = 21
Expand Down
4 changes: 2 additions & 2 deletions Sources/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 16 15:13:35 CEST 2024
#Mon Oct 07 16:54:16 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,63 @@ public BatchProfileAttributeEditor setEmailMarketingSubscription(@NonNull BatchE
return this;
}

/**
* Set the profile phone number.
* <p>
* Note: This method requires to already have a registered identifier for the user
* or to call {@link Batch.Profile#identify(String)} method before this one.
* <p>
* Example:
* <pre>
* Batch.Profile.identify("my_custom_user_id")
* Batch.Profile.editor().setPhoneNumber("+33123456789").save()
* </pre>
* @param phoneNumber A valid E.164 formatted string. Must start with a `+` and not be no longer
* than 15 digits without special characters (eg: "+33123456789"). Null to reset.
* @see <a href="https://en.wikipedia.org/wiki/E.164">E.164</a>
* @return This object instance, for method chaining.
*/
public BatchProfileAttributeEditor setPhoneNumber(@Nullable String phoneNumber) {
Context context = RuntimeManagerProvider.get().getContext();
if (context == null) {
Logger.error(TAG, "Batch does not have a context yet. Make sure Batch is started beforehand.");
return this;
}

// Ensure profile is logged in
String customUserID = UserModuleProvider.get().getCustomID(context);
if (customUserID == null) {
Logger.error(
TAG,
"You cannot set/reset a phone number to an anonymous profile. Please use the `Batch.Profile.identify` method beforehand."
);
return this;
}

// Ensure phone number is valid
if (ProfileDataHelper.isNotValidPhoneNumber(phoneNumber)) {
Logger.error(
TAG,
"setPhoneNumber called with invalid phone number format. Please make sure that the string starts with a `+` and is no longer than 15 digits."
);
return this;
}
this.profileUpdateOperation.setPhoneNumber(phoneNumber);
return this;
}

/**
* Set the profile SMS marketing subscription state.
* <p>
* Note that profile's subscription status is automatically set to unsubscribed when they send a STOP message.
* @param state State of the subscription
* @return This object instance, for method chaining.
*/
public BatchProfileAttributeEditor setSMSMarketingSubscription(@NonNull BatchSMSSubscriptionState state) {
this.profileUpdateOperation.setSMSMarketing(state);
return this;
}

/**
* Set a custom profile attribute for a key.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.batch.android;

import com.batch.android.annotation.PublicSDK;

/**
* Enum defining the state of an SMS subscription
*/
@PublicSDK
public enum BatchSMSSubscriptionState {
SUBSCRIBED,
UNSUBSCRIBED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import androidx.annotation.NonNull;
import com.batch.android.core.systemparameters.SystemParameter;
import com.batch.android.core.systemparameters.SystemParameterRegistry;
import com.batch.android.core.systemparameters.SystemParameterShortName;
import com.batch.android.di.providers.DataCollectionModuleProvider;
import com.batch.android.di.providers.SystemParameterRegistryProvider;
import com.batch.android.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import androidx.annotation.NonNull;
import com.batch.android.core.Logger;
import androidx.annotation.Nullable;
import com.batch.android.core.ParameterKeys;
import com.batch.android.core.Parameters;
import com.batch.android.core.Webservice;
import com.batch.android.di.providers.ParametersProvider;
import com.batch.android.json.JSONException;
import com.batch.android.json.JSONObject;
import java.util.Date;
Expand All @@ -29,6 +31,7 @@ public final class SystemParameterHelper {
* @param applicationContext The application context.
* @return The application bundle name.
*/
@NonNull
public static String getBundleName(Context applicationContext) {
return applicationContext.getPackageName();
}
Expand All @@ -38,6 +41,7 @@ public static String getBundleName(Context applicationContext) {
*
* @return timezone or null on failure.
*/
@Nullable
public static String getDeviceTimezone() {
try {
return TimeZone.getDefault().getID();
Expand All @@ -51,6 +55,7 @@ public static String getDeviceTimezone() {
*
* @return language
*/
@NonNull
public static String getDeviceLanguage() {
return Locale.getDefault().toLanguageTag();
}
Expand All @@ -60,6 +65,7 @@ public static String getDeviceLanguage() {
*
* @return country
*/
@NonNull
public static String getDeviceCountry() {
return Locale.getDefault().getCountry();
}
Expand All @@ -69,6 +75,7 @@ public static String getDeviceCountry() {
*
* @return The current date
*/
@NonNull
public static String getDeviceDate() {
return Webservice.formatDate(new Date());
}
Expand All @@ -79,6 +86,7 @@ public static String getDeviceDate() {
* @param applicationContext The application context.
* @return Installation date or null on failure.
*/
@Nullable
public static Long getFirstInstallDate(Context applicationContext) {
try {
PackageManager packageManager = applicationContext.getPackageManager();
Expand All @@ -96,6 +104,7 @@ public static Long getFirstInstallDate(Context applicationContext) {
* @param applicationContext The application context.
* @return Last update date or null on failure.
*/
@Nullable
public static Long getLastUpdateDate(Context applicationContext) {
try {
PackageManager packageManager = applicationContext.getPackageManager();
Expand All @@ -107,11 +116,24 @@ public static Long getLastUpdateDate(Context applicationContext) {
return null;
}

/**
* Get the device install date.
*
* @param context Android's context to access shared preferences
* @return The device install date
*/
@Nullable
public static Long getDeviceInstallDate(Context context) {
String value = ParametersProvider.get(context).get(ParameterKeys.INSTALL_TIMESTAMP_KEY);
return value != null ? Long.parseLong(value) : null;
}

/**
* Return the Brand name of the device
*
* @return Brand name if found, null otherwise
*/
@Nullable
public static String getDeviceBrand() {
try {
return Build.BRAND;
Expand All @@ -125,6 +147,7 @@ public static String getDeviceBrand() {
*
* @return The device model if found, null otherwise.
*/
@Nullable
public static String getDeviceModel() {
try {
return Build.MODEL;
Expand All @@ -139,6 +162,7 @@ public static String getDeviceModel() {
* @param applicationContext The application context.
* @return AppVersion if found, null otherwise
*/
@Nullable
public static String getAppVersion(Context applicationContext) {
try {
PackageInfo info = applicationContext
Expand All @@ -156,6 +180,7 @@ public static String getAppVersion(Context applicationContext) {
* @param applicationContext The application context.
* @return AppVersion code if found, null otherwise
*/
@Nullable
public static Integer getAppVersionCode(Context applicationContext) {
try {
PackageManager packageManager = applicationContext.getApplicationContext().getPackageManager();
Expand All @@ -175,6 +200,7 @@ public static Integer getAppVersionCode(Context applicationContext) {
*
* @return Version.
*/
@NonNull
public static String getOSVersion() {
return String.format("Android %s", Build.VERSION.RELEASE);
}
Expand All @@ -184,6 +210,7 @@ public static String getOSVersion() {
*
* @return Bridge version string
*/
@NonNull
public static String getBridgeVersion() {
return System.getProperty(Parameters.BRIDGE_VERSION_ENVIRONEMENT_VAR, "");
}
Expand All @@ -193,6 +220,7 @@ public static String getBridgeVersion() {
*
* @return Plugin version string
*/
@NonNull
public static String getPluginVersion() {
return System.getProperty(Parameters.PLUGIN_VERSION_ENVIRONEMENT_VAR, "");
}
Expand All @@ -201,6 +229,7 @@ public static String getPluginVersion() {
* Get the android sdk api level
* @return The android sdk api level
*/
@NonNull
public static String getOSSdkLevel() {
return String.valueOf(Build.VERSION.SDK_INT);
}
Expand All @@ -209,6 +238,7 @@ public static String getOSSdkLevel() {
* Get the batch sdk api level
* @return The batch sdk api level
*/
@NonNull
public static String getSdkApiLevel() {
return String.valueOf(Parameters.API_LEVEL);
}
Expand All @@ -217,6 +247,7 @@ public static String getSdkApiLevel() {
* Get the batch sdk messaging api level
* @return The batch sdk messaging api level
*/
@NonNull
public static String getSdkMessagingApiLevel() {
return String.valueOf(Parameters.MESSAGING_API_LEVEL);
}
Expand All @@ -229,6 +260,7 @@ public static String getSdkMessagingApiLevel() {
* @return A JSONObject related to the given list of parameters
* @throws JSONException parsing exception
*/
@NonNull
public static JSONObject serializeSystemParameters(@NonNull List<WatchedSystemParameter> parameters)
throws JSONException {
JSONObject serializedParameters = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.batch.android.Batch;
import com.batch.android.core.ParameterKeys;
import com.batch.android.core.Webservice;
import com.batch.android.di.providers.DataCollectionModuleProvider;
import com.batch.android.di.providers.ParametersProvider;
import com.batch.android.di.providers.UserModuleProvider;
import com.batch.android.processor.Module;
import com.batch.android.processor.Provide;
Expand Down Expand Up @@ -58,7 +56,10 @@ private SystemParameterRegistry(@NonNull Context context) {
SystemParameter deviceInstallDate = new WatchedSystemParameter(
context,
SystemParameterShortName.DEVICE_INSTALL_DATE,
() -> ParametersProvider.get(context).get(ParameterKeys.INSTALL_TIMESTAMP_KEY)
() -> {
Long date = SystemParameterHelper.getDeviceInstallDate(context);
return date != null ? Webservice.formatDate(new Date(date)) : null;
}
);

SystemParameter bundleName = new WatchedSystemParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public void onCampaignMenuSelected(String campaignToken) {

@Override
protected void onCreate(Bundle savedInstanceState) {
// Workaround to opt-out the android 15 edge to edge enforcement.
// This is a temporary fix since this api will be soon deprecated by google.
// But using the view compat to handle inset force us to bump the minimal androidx core version.
getTheme().applyStyle(R.style.com_batchsdk_OptOutEdgeToEdgeEnforcement, false);

super.onCreate(savedInstanceState);
setContentView(R.layout.com_batchsdk_debug_view);
if (savedInstanceState == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public WebFormatView(
webSettings.setSupportZoom(false);
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setSupportMultipleWindows(true);
webSettings.setAllowContentAccess(false);

// Work around an issue where android could show "ERR_CACHE_MISS"
// In a perfect world we would like to make use of the browser cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void identify(@Nullable String identifier) {
return;
}

if (ProfileDataHelper.isBlocklistedCustomUserID(identifier)) {
Logger.error(
TAG,
"identify called with a blocklisted identifier: `" +
identifier +
"`, Please ensure you have correctly implemented the API."
);
return;
}

Context context = RuntimeManagerProvider.get().getContext();
if (context == null) {
Logger.error(TAG, "Batch does not have a context yet. Make sure Batch is started.");
Expand Down
Loading

0 comments on commit 8f829be

Please sign in to comment.