Skip to content

Commit 8f829be

Browse files
committed
release: SDK 2.1.0
1 parent 6de7c98 commit 8f829be

File tree

20 files changed

+12027
-13
lines changed

20 files changed

+12027
-13
lines changed

Sources/buildSrc/src/main/java/Consts.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
object ProjectConsts {
2-
const val COMPILE_SDK = 34
2+
const val COMPILE_SDK = 35
33

44
const val KOTLIN_VERSION = "1.9.0"
55
const val KOTLIN_COROUTINES_VERSION = "1.7.1"
66

77
const val ANDROID_LINT_VERSION = "30.1.2"
88

9-
const val ANDROID_GRADLE_PLUGIN_VERSION = "8.3.0"
9+
const val ANDROID_GRADLE_PLUGIN_VERSION = "8.6.0"
1010
const val GMS_GRADLE_PLUGIN_VERSION = "4.3.14"
1111
}
1212

1313
object SDKConsts {
14-
const val VERSION = "2.0.3"
15-
const val API_LEVEL = 200
14+
const val VERSION = "2.1.0"
15+
const val API_LEVEL = 210
1616
const val MESSAGING_API_LEVEL = 12
1717

1818
const val MIN_SDK = 21
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Apr 16 15:13:35 CEST 2024
1+
#Mon Oct 07 16:54:16 CEST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

Sources/sdk/src/main/java/com/batch/android/BatchProfileAttributeEditor.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,63 @@ public BatchProfileAttributeEditor setEmailMarketingSubscription(@NonNull BatchE
137137
return this;
138138
}
139139

140+
/**
141+
* Set the profile phone number.
142+
* <p>
143+
* Note: This method requires to already have a registered identifier for the user
144+
* or to call {@link Batch.Profile#identify(String)} method before this one.
145+
* <p>
146+
* Example:
147+
* <pre>
148+
* Batch.Profile.identify("my_custom_user_id")
149+
* Batch.Profile.editor().setPhoneNumber("+33123456789").save()
150+
* </pre>
151+
* @param phoneNumber A valid E.164 formatted string. Must start with a `+` and not be no longer
152+
* than 15 digits without special characters (eg: "+33123456789"). Null to reset.
153+
* @see <a href="https://en.wikipedia.org/wiki/E.164">E.164</a>
154+
* @return This object instance, for method chaining.
155+
*/
156+
public BatchProfileAttributeEditor setPhoneNumber(@Nullable String phoneNumber) {
157+
Context context = RuntimeManagerProvider.get().getContext();
158+
if (context == null) {
159+
Logger.error(TAG, "Batch does not have a context yet. Make sure Batch is started beforehand.");
160+
return this;
161+
}
162+
163+
// Ensure profile is logged in
164+
String customUserID = UserModuleProvider.get().getCustomID(context);
165+
if (customUserID == null) {
166+
Logger.error(
167+
TAG,
168+
"You cannot set/reset a phone number to an anonymous profile. Please use the `Batch.Profile.identify` method beforehand."
169+
);
170+
return this;
171+
}
172+
173+
// Ensure phone number is valid
174+
if (ProfileDataHelper.isNotValidPhoneNumber(phoneNumber)) {
175+
Logger.error(
176+
TAG,
177+
"setPhoneNumber called with invalid phone number format. Please make sure that the string starts with a `+` and is no longer than 15 digits."
178+
);
179+
return this;
180+
}
181+
this.profileUpdateOperation.setPhoneNumber(phoneNumber);
182+
return this;
183+
}
184+
185+
/**
186+
* Set the profile SMS marketing subscription state.
187+
* <p>
188+
* Note that profile's subscription status is automatically set to unsubscribed when they send a STOP message.
189+
* @param state State of the subscription
190+
* @return This object instance, for method chaining.
191+
*/
192+
public BatchProfileAttributeEditor setSMSMarketingSubscription(@NonNull BatchSMSSubscriptionState state) {
193+
this.profileUpdateOperation.setSMSMarketing(state);
194+
return this;
195+
}
196+
140197
/**
141198
* Set a custom profile attribute for a key.
142199
*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.batch.android;
2+
3+
import com.batch.android.annotation.PublicSDK;
4+
5+
/**
6+
* Enum defining the state of an SMS subscription
7+
*/
8+
@PublicSDK
9+
public enum BatchSMSSubscriptionState {
10+
SUBSCRIBED,
11+
UNSUBSCRIBED,
12+
}

Sources/sdk/src/main/java/com/batch/android/WebserviceParameterUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import androidx.annotation.NonNull;
55
import com.batch.android.core.systemparameters.SystemParameter;
66
import com.batch.android.core.systemparameters.SystemParameterRegistry;
7-
import com.batch.android.core.systemparameters.SystemParameterShortName;
87
import com.batch.android.di.providers.DataCollectionModuleProvider;
98
import com.batch.android.di.providers.SystemParameterRegistryProvider;
109
import com.batch.android.json.JSONObject;

Sources/sdk/src/main/java/com/batch/android/core/systemparameters/SystemParameterHelper.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import android.content.pm.PackageManager.NameNotFoundException;
77
import android.os.Build;
88
import androidx.annotation.NonNull;
9-
import com.batch.android.core.Logger;
9+
import androidx.annotation.Nullable;
10+
import com.batch.android.core.ParameterKeys;
1011
import com.batch.android.core.Parameters;
1112
import com.batch.android.core.Webservice;
13+
import com.batch.android.di.providers.ParametersProvider;
1214
import com.batch.android.json.JSONException;
1315
import com.batch.android.json.JSONObject;
1416
import java.util.Date;
@@ -29,6 +31,7 @@ public final class SystemParameterHelper {
2931
* @param applicationContext The application context.
3032
* @return The application bundle name.
3133
*/
34+
@NonNull
3235
public static String getBundleName(Context applicationContext) {
3336
return applicationContext.getPackageName();
3437
}
@@ -38,6 +41,7 @@ public static String getBundleName(Context applicationContext) {
3841
*
3942
* @return timezone or null on failure.
4043
*/
44+
@Nullable
4145
public static String getDeviceTimezone() {
4246
try {
4347
return TimeZone.getDefault().getID();
@@ -51,6 +55,7 @@ public static String getDeviceTimezone() {
5155
*
5256
* @return language
5357
*/
58+
@NonNull
5459
public static String getDeviceLanguage() {
5560
return Locale.getDefault().toLanguageTag();
5661
}
@@ -60,6 +65,7 @@ public static String getDeviceLanguage() {
6065
*
6166
* @return country
6267
*/
68+
@NonNull
6369
public static String getDeviceCountry() {
6470
return Locale.getDefault().getCountry();
6571
}
@@ -69,6 +75,7 @@ public static String getDeviceCountry() {
6975
*
7076
* @return The current date
7177
*/
78+
@NonNull
7279
public static String getDeviceDate() {
7380
return Webservice.formatDate(new Date());
7481
}
@@ -79,6 +86,7 @@ public static String getDeviceDate() {
7986
* @param applicationContext The application context.
8087
* @return Installation date or null on failure.
8188
*/
89+
@Nullable
8290
public static Long getFirstInstallDate(Context applicationContext) {
8391
try {
8492
PackageManager packageManager = applicationContext.getPackageManager();
@@ -96,6 +104,7 @@ public static Long getFirstInstallDate(Context applicationContext) {
96104
* @param applicationContext The application context.
97105
* @return Last update date or null on failure.
98106
*/
107+
@Nullable
99108
public static Long getLastUpdateDate(Context applicationContext) {
100109
try {
101110
PackageManager packageManager = applicationContext.getPackageManager();
@@ -107,11 +116,24 @@ public static Long getLastUpdateDate(Context applicationContext) {
107116
return null;
108117
}
109118

119+
/**
120+
* Get the device install date.
121+
*
122+
* @param context Android's context to access shared preferences
123+
* @return The device install date
124+
*/
125+
@Nullable
126+
public static Long getDeviceInstallDate(Context context) {
127+
String value = ParametersProvider.get(context).get(ParameterKeys.INSTALL_TIMESTAMP_KEY);
128+
return value != null ? Long.parseLong(value) : null;
129+
}
130+
110131
/**
111132
* Return the Brand name of the device
112133
*
113134
* @return Brand name if found, null otherwise
114135
*/
136+
@Nullable
115137
public static String getDeviceBrand() {
116138
try {
117139
return Build.BRAND;
@@ -125,6 +147,7 @@ public static String getDeviceBrand() {
125147
*
126148
* @return The device model if found, null otherwise.
127149
*/
150+
@Nullable
128151
public static String getDeviceModel() {
129152
try {
130153
return Build.MODEL;
@@ -139,6 +162,7 @@ public static String getDeviceModel() {
139162
* @param applicationContext The application context.
140163
* @return AppVersion if found, null otherwise
141164
*/
165+
@Nullable
142166
public static String getAppVersion(Context applicationContext) {
143167
try {
144168
PackageInfo info = applicationContext
@@ -156,6 +180,7 @@ public static String getAppVersion(Context applicationContext) {
156180
* @param applicationContext The application context.
157181
* @return AppVersion code if found, null otherwise
158182
*/
183+
@Nullable
159184
public static Integer getAppVersionCode(Context applicationContext) {
160185
try {
161186
PackageManager packageManager = applicationContext.getApplicationContext().getPackageManager();
@@ -175,6 +200,7 @@ public static Integer getAppVersionCode(Context applicationContext) {
175200
*
176201
* @return Version.
177202
*/
203+
@NonNull
178204
public static String getOSVersion() {
179205
return String.format("Android %s", Build.VERSION.RELEASE);
180206
}
@@ -184,6 +210,7 @@ public static String getOSVersion() {
184210
*
185211
* @return Bridge version string
186212
*/
213+
@NonNull
187214
public static String getBridgeVersion() {
188215
return System.getProperty(Parameters.BRIDGE_VERSION_ENVIRONEMENT_VAR, "");
189216
}
@@ -193,6 +220,7 @@ public static String getBridgeVersion() {
193220
*
194221
* @return Plugin version string
195222
*/
223+
@NonNull
196224
public static String getPluginVersion() {
197225
return System.getProperty(Parameters.PLUGIN_VERSION_ENVIRONEMENT_VAR, "");
198226
}
@@ -201,6 +229,7 @@ public static String getPluginVersion() {
201229
* Get the android sdk api level
202230
* @return The android sdk api level
203231
*/
232+
@NonNull
204233
public static String getOSSdkLevel() {
205234
return String.valueOf(Build.VERSION.SDK_INT);
206235
}
@@ -209,6 +238,7 @@ public static String getOSSdkLevel() {
209238
* Get the batch sdk api level
210239
* @return The batch sdk api level
211240
*/
241+
@NonNull
212242
public static String getSdkApiLevel() {
213243
return String.valueOf(Parameters.API_LEVEL);
214244
}
@@ -217,6 +247,7 @@ public static String getSdkApiLevel() {
217247
* Get the batch sdk messaging api level
218248
* @return The batch sdk messaging api level
219249
*/
250+
@NonNull
220251
public static String getSdkMessagingApiLevel() {
221252
return String.valueOf(Parameters.MESSAGING_API_LEVEL);
222253
}
@@ -229,6 +260,7 @@ public static String getSdkMessagingApiLevel() {
229260
* @return A JSONObject related to the given list of parameters
230261
* @throws JSONException parsing exception
231262
*/
263+
@NonNull
232264
public static JSONObject serializeSystemParameters(@NonNull List<WatchedSystemParameter> parameters)
233265
throws JSONException {
234266
JSONObject serializedParameters = new JSONObject();

Sources/sdk/src/main/java/com/batch/android/core/systemparameters/SystemParameterRegistry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import androidx.annotation.NonNull;
55
import androidx.annotation.Nullable;
66
import com.batch.android.Batch;
7-
import com.batch.android.core.ParameterKeys;
87
import com.batch.android.core.Webservice;
98
import com.batch.android.di.providers.DataCollectionModuleProvider;
10-
import com.batch.android.di.providers.ParametersProvider;
119
import com.batch.android.di.providers.UserModuleProvider;
1210
import com.batch.android.processor.Module;
1311
import com.batch.android.processor.Provide;
@@ -58,7 +56,10 @@ private SystemParameterRegistry(@NonNull Context context) {
5856
SystemParameter deviceInstallDate = new WatchedSystemParameter(
5957
context,
6058
SystemParameterShortName.DEVICE_INSTALL_DATE,
61-
() -> ParametersProvider.get(context).get(ParameterKeys.INSTALL_TIMESTAMP_KEY)
59+
() -> {
60+
Long date = SystemParameterHelper.getDeviceInstallDate(context);
61+
return date != null ? Webservice.formatDate(new Date(date)) : null;
62+
}
6263
);
6364

6465
SystemParameter bundleName = new WatchedSystemParameter(

Sources/sdk/src/main/java/com/batch/android/debug/BatchDebugActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public void onCampaignMenuSelected(String campaignToken) {
8282

8383
@Override
8484
protected void onCreate(Bundle savedInstanceState) {
85+
// Workaround to opt-out the android 15 edge to edge enforcement.
86+
// This is a temporary fix since this api will be soon deprecated by google.
87+
// But using the view compat to handle inset force us to bump the minimal androidx core version.
88+
getTheme().applyStyle(R.style.com_batchsdk_OptOutEdgeToEdgeEnforcement, false);
89+
8590
super.onCreate(savedInstanceState);
8691
setContentView(R.layout.com_batchsdk_debug_view);
8792
if (savedInstanceState == null) {

Sources/sdk/src/main/java/com/batch/android/messaging/view/formats/WebFormatView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public WebFormatView(
118118
webSettings.setSupportZoom(false);
119119
webSettings.setDefaultTextEncodingName("utf-8");
120120
webSettings.setSupportMultipleWindows(true);
121+
webSettings.setAllowContentAccess(false);
121122

122123
// Work around an issue where android could show "ERR_CACHE_MISS"
123124
// In a perfect world we would like to make use of the browser cache

Sources/sdk/src/main/java/com/batch/android/module/ProfileModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public void identify(@Nullable String identifier) {
8989
return;
9090
}
9191

92+
if (ProfileDataHelper.isBlocklistedCustomUserID(identifier)) {
93+
Logger.error(
94+
TAG,
95+
"identify called with a blocklisted identifier: `" +
96+
identifier +
97+
"`, Please ensure you have correctly implemented the API."
98+
);
99+
return;
100+
}
101+
92102
Context context = RuntimeManagerProvider.get().getContext();
93103
if (context == null) {
94104
Logger.error(TAG, "Batch does not have a context yet. Make sure Batch is started.");

0 commit comments

Comments
 (0)