Skip to content

Commit 712cd3e

Browse files
committed
release: SDK 3.1.0
1 parent dd9d485 commit 712cd3e

File tree

73 files changed

+17050
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+17050
-521
lines changed

Sources/gradle/libs.versions.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[versions]
2-
agp = "8.9.2"
2+
agp = "8.12.0"
33
android = "4.1.1.4"
44
androidCompileSdk = "36"
55
androidMinSdk = "21"
6-
androidLint = "30.1.2"
6+
androidLint = "31.12.0"
77
androidxJunit = "1.2.1"
88
androidXCoreKtx = "1.16.0"
99
androidXLibraryVersion = "1.0.0"
1010
androidXTestCoreKtx = "1.6.1"
1111
androidXTestRunner = "1.6.2"
1212
androidXTestTruth = "1.6.0"
1313
assertjCore = "3.24.2"
14-
batchSdk = "3.0.1"
15-
batchApiLevel = "301"
16-
batchMessagingApiLevel = "30"
14+
batchSdk = "3.1.0"
15+
batchApiLevel = "310"
16+
batchMessagingApiLevel = "31"
1717
batchResourcePrefix = "com_batchsdk_"
1818
batchNamespace = "com.batch.android"
1919
batchTestNamespace = "com.batch.android.test"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon May 05 15:25:03 CEST 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

Sources/sdk-lint/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ tasks.withType<Jar> {
1818
}
1919

2020
java {
21-
sourceCompatibility = JavaVersion.VERSION_1_8
22-
targetCompatibility = JavaVersion.VERSION_1_8
21+
sourceCompatibility = JavaVersion.VERSION_11
22+
targetCompatibility = JavaVersion.VERSION_11
2323
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,11 @@ else if (lastStop == null && state == State.READY) {
20402040
*/
20412041
updateVersionManagement(applicationContext);
20422042

2043+
/*
2044+
* Ensure that we have no pending display receipts job scheduled.
2045+
* (this will run only once)
2046+
*/
2047+
ensureDisplayReceiptJobsCancelled(applicationContext);
20432048
/*
20442049
* Check that we have mandatory permissions
20452050
*/
@@ -2407,24 +2412,29 @@ private static void updateVersionManagement(@NonNull Context context) {
24072412

24082413
private static void handleNewVersionMigration(Context context, String savedVersion, String currentVersion) {
24092414
Logger.internal("New version detected : " + savedVersion + " -> " + currentVersion);
2410-
2411-
int savedMajorVersion = VersionHelper.getMajor(savedVersion);
2412-
int currentMajorVersion = VersionHelper.getMajor(currentVersion);
2413-
2414-
if (savedMajorVersion <= 2 && currentMajorVersion == 3) {
2415-
removeOldPendingDisplayReceiptJobs(context);
2416-
}
2415+
// int savedMajorVersion = VersionHelper.getMajor(savedVersion);
2416+
// int currentMajorVersion = VersionHelper.getMajor(currentVersion);
24172417
}
24182418

24192419
/**
2420-
* Removes all pending display receipt jobs from the JobScheduler.
2420+
* Cancel all pending display receipt jobs from the JobScheduler.
24212421
* <p>
24222422
* This method is used to clean up any leftover display receipt jobs that might have been scheduled
24232423
* by older versions of the SDK, which could potentially cause issues with newer versions.
2424+
* <p>
2425+
* This method will run only once.
24242426
*
24252427
* @param context The application context.
24262428
*/
2427-
private static void removeOldPendingDisplayReceiptJobs(Context context) {
2429+
private static void ensureDisplayReceiptJobsCancelled(Context context) {
2430+
// Ensure that we only remove the jobs once
2431+
boolean jobsAlreadyCancelled = Boolean.parseBoolean(
2432+
ParametersProvider.get(context).get(ParameterKeys.DISPLAY_RECEIPTS_JOB_CANCELLED_KEY, "false")
2433+
);
2434+
if (jobsAlreadyCancelled) {
2435+
return;
2436+
}
2437+
24282438
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
24292439

24302440
if (scheduler == null) {
@@ -2440,6 +2450,7 @@ private static void removeOldPendingDisplayReceiptJobs(Context context) {
24402450
);
24412451
}
24422452
}
2453+
ParametersProvider.get(context).set(ParameterKeys.DISPLAY_RECEIPTS_JOB_CANCELLED_KEY, "true", true);
24432454
}
24442455

24452456
private static class InternalBroadcastReceiver extends BroadcastReceiver {

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.HashMap;
1313
import java.util.LinkedHashSet;
1414
import java.util.List;
15+
import java.util.Locale;
1516
import java.util.Map;
1617
import java.util.Set;
1718

@@ -86,8 +87,7 @@ public BatchEventAttributes put(@NonNull String key, @NonNull String value) {
8687
this.label = value;
8788
return this;
8889
}
89-
attributes.put(key, new EventTypedAttribute(value, AttributeType.STRING));
90-
return this;
90+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.STRING));
9191
}
9292

9393
/**
@@ -98,8 +98,7 @@ public BatchEventAttributes put(@NonNull String key, @NonNull String value) {
9898
* @return Same BatchEventAttributes instance, for chaining
9999
*/
100100
public BatchEventAttributes put(@NonNull String key, @NonNull URI value) {
101-
attributes.put(key, new EventTypedAttribute(value, AttributeType.URL));
102-
return this;
101+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.URL));
103102
}
104103

105104
/**
@@ -110,8 +109,7 @@ public BatchEventAttributes put(@NonNull String key, @NonNull URI value) {
110109
* @return Same BatchEventAttributes instance, for chaining
111110
*/
112111
public BatchEventAttributes put(@NonNull String key, float value) {
113-
attributes.put(key, new EventTypedAttribute(value, AttributeType.DOUBLE));
114-
return this;
112+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.DOUBLE));
115113
}
116114

117115
/**
@@ -122,8 +120,7 @@ public BatchEventAttributes put(@NonNull String key, float value) {
122120
* @return Same BatchEventAttributes instance, for chaining
123121
*/
124122
public BatchEventAttributes put(@NonNull String key, double value) {
125-
attributes.put(key, new EventTypedAttribute(value, AttributeType.DOUBLE));
126-
return this;
123+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.DOUBLE));
127124
}
128125

129126
/**
@@ -134,8 +131,7 @@ public BatchEventAttributes put(@NonNull String key, double value) {
134131
* @return Same BatchEventAttributes instance, for chaining
135132
*/
136133
public BatchEventAttributes put(@NonNull String key, int value) {
137-
attributes.put(key, new EventTypedAttribute(value, AttributeType.LONG));
138-
return this;
134+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.LONG));
139135
}
140136

141137
/**
@@ -146,8 +142,7 @@ public BatchEventAttributes put(@NonNull String key, int value) {
146142
* @return Same BatchEventAttributes instance, for chaining
147143
*/
148144
public BatchEventAttributes put(@NonNull String key, long value) {
149-
attributes.put(key, new EventTypedAttribute(value, AttributeType.LONG));
150-
return this;
145+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.LONG));
151146
}
152147

153148
/**
@@ -158,8 +153,7 @@ public BatchEventAttributes put(@NonNull String key, long value) {
158153
* @return Same BatchEventAttributes instance, for chaining
159154
*/
160155
public BatchEventAttributes put(@NonNull String key, boolean value) {
161-
attributes.put(key, new EventTypedAttribute(value, AttributeType.BOOL));
162-
return this;
156+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.BOOL));
163157
}
164158

165159
/**
@@ -170,8 +164,7 @@ public BatchEventAttributes put(@NonNull String key, boolean value) {
170164
* @return Same BatchEventAttributes instance, for chaining
171165
*/
172166
public BatchEventAttributes put(@NonNull String key, @NonNull Date value) {
173-
attributes.put(key, new EventTypedAttribute(value.getTime(), AttributeType.DATE));
174-
return this;
167+
return this.putTypedAttribute(key, new EventTypedAttribute(value.getTime(), AttributeType.DATE));
175168
}
176169

177170
/**
@@ -182,8 +175,7 @@ public BatchEventAttributes put(@NonNull String key, @NonNull Date value) {
182175
* @return Same BatchEventAttributes instance, for chaining
183176
*/
184177
public BatchEventAttributes put(@NonNull String key, @NonNull BatchEventAttributes value) {
185-
attributes.put(key, new EventTypedAttribute(value, AttributeType.OBJECT));
186-
return this;
178+
return this.putTypedAttribute(key, new EventTypedAttribute(value, AttributeType.OBJECT));
187179
}
188180

189181
/**
@@ -194,8 +186,7 @@ public BatchEventAttributes put(@NonNull String key, @NonNull BatchEventAttribut
194186
* @return Same BatchEventAttributes instance, for chaining
195187
*/
196188
public BatchEventAttributes putObjectList(@NonNull String key, @NonNull List<BatchEventAttributes> value) {
197-
attributes.put(key, new EventTypedAttribute(new ArrayList<>(value), AttributeType.OBJECT_ARRAY));
198-
return this;
189+
return this.putTypedAttribute(key, new EventTypedAttribute(new ArrayList<>(value), AttributeType.OBJECT_ARRAY));
199190
}
200191

201192
/**
@@ -210,7 +201,17 @@ public BatchEventAttributes putStringList(@NonNull String key, @NonNull List<Str
210201
this.tags = new LinkedHashSet<>(value);
211202
return this;
212203
}
213-
attributes.put(key, new EventTypedAttribute(new ArrayList<>(value), AttributeType.STRING_ARRAY));
204+
return this.putTypedAttribute(key, new EventTypedAttribute(new ArrayList<>(value), AttributeType.STRING_ARRAY));
205+
}
206+
207+
/**
208+
* Add EventTypedAttribute and normalize key
209+
*
210+
* @param key The key to use
211+
* @param attribute The attribute to add
212+
*/
213+
private BatchEventAttributes putTypedAttribute(@NonNull String key, @NonNull EventTypedAttribute attribute) {
214+
attributes.put(key.toLowerCase(Locale.US), attribute);
214215
return this;
215216
}
216217

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,116 @@
11
package com.batch.android;
22

33
import android.content.Context;
4+
import androidx.annotation.NonNull;
45
import com.batch.android.core.Logger;
5-
import com.batch.android.core.MessagePackWebservice;
66
import com.batch.android.core.ParameterKeys;
77
import com.batch.android.core.TaskRunnable;
88
import com.batch.android.core.domain.DomainURLBuilder;
9+
import com.batch.android.json.JSONException;
10+
import com.batch.android.json.JSONObject;
911
import com.batch.android.metrics.MetricRegistry;
1012
import com.batch.android.post.LocalCampaignsJITPostDataProvider;
13+
import com.batch.android.post.PostDataProvider;
14+
import com.batch.android.query.response.LocalCampaignsResponse;
1115
import com.batch.android.webservice.listener.LocalCampaignsJITWebserviceListener;
1216
import java.net.MalformedURLException;
1317
import java.util.List;
1418

15-
class LocalCampaignsJITWebservice extends MessagePackWebservice implements TaskRunnable {
19+
class LocalCampaignsJITWebservice extends BatchWebservice implements TaskRunnable {
1620

1721
private static final String TAG = "LocalCampaignsJITWebservice";
1822

1923
/**
2024
* Web service callback
2125
*/
26+
@NonNull
2227
private final LocalCampaignsJITWebserviceListener listener;
2328

29+
@NonNull
30+
private final LocalCampaignsJITPostDataProvider dataProvider;
31+
32+
@SuppressWarnings("ConstantConditions")
2433
protected LocalCampaignsJITWebservice(
2534
Context context,
26-
LocalCampaignsJITWebserviceListener listener,
27-
LocalCampaignsJITPostDataProvider dataProvider,
35+
@NonNull LocalCampaignsJITWebserviceListener listener,
36+
@NonNull LocalCampaignsJITPostDataProvider dataProvider,
37+
@NonNull LocalCampaignsResponse.Version campaignsVersion,
2838
String... parameters
2939
) throws MalformedURLException {
30-
super(context, dataProvider, DomainURLBuilder.LOCAL_CAMPAIGNS_JIT_WS_URL, addBatchApiKey(parameters));
40+
super(
41+
context,
42+
RequestType.POST,
43+
campaignsVersion == LocalCampaignsResponse.Version.MEP
44+
? DomainURLBuilder.LOCAL_CAMPAIGNS_JIT_MEP_WS_URL
45+
: DomainURLBuilder.LOCAL_CAMPAIGNS_JIT_CEP_WS_URL,
46+
addBatchApiKey(parameters)
47+
);
3148
if (listener == null) {
3249
throw new NullPointerException("Listener is null");
3350
}
51+
if (dataProvider == null) {
52+
throw new NullPointerException("DataProvider is null");
53+
}
3454
this.listener = listener;
55+
this.dataProvider = dataProvider;
3556
}
3657

3758
@Override
3859
public String getTaskIdentifier() {
3960
return "Batch/localcampaignsjitws";
4061
}
4162

63+
@Override
64+
protected PostDataProvider<JSONObject> getPostDataProvider() {
65+
return dataProvider;
66+
}
67+
4268
@Override
4369
public void run() {
4470
Logger.internal(TAG, "Webservice started");
4571
MetricRegistry.localCampaignsJITResponseTime.startTimer();
4672
try {
47-
byte[] response = executeRequest();
73+
JSONObject response = getBasicJsonResponseBody();
4874
MetricRegistry.localCampaignsJITResponseTime.observeDuration();
4975
MetricRegistry.localCampaignsJITCount.labels("OK").inc();
50-
LocalCampaignsJITPostDataProvider dataProvider = (LocalCampaignsJITPostDataProvider) getPostDataProvider();
51-
List<String> eligibleCampaigns = dataProvider.unpack(response);
76+
List<String> eligibleCampaigns = dataProvider.deserializeResponse(response);
5277
this.listener.onSuccess(eligibleCampaigns);
5378
} catch (WebserviceError error) {
5479
MetricRegistry.localCampaignsJITResponseTime.observeDuration();
5580
MetricRegistry.localCampaignsJITCount.labels("KO").inc();
5681
Logger.internal(TAG, error.getReason().toString(), error.getCause());
5782
this.listener.onFailure(error);
83+
} catch (JSONException e) {
84+
Logger.internal(TAG, "Error while parsing response", e);
85+
this.listener.onFailure(null);
5886
}
5987
}
6088

89+
@Override
90+
protected String getURLSorterPatternParameterKey() {
91+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_URLSORTER_PATTERN_KEY;
92+
}
93+
94+
@Override
95+
protected String getCryptorTypeParameterKey() {
96+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_CRYPTORTYPE_KEY;
97+
}
98+
99+
@Override
100+
protected String getCryptorModeParameterKey() {
101+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_CRYPTORMODE_KEY;
102+
}
103+
104+
@Override
105+
protected String getPostCryptorTypeParameterKey() {
106+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_POST_CRYPTORTYPE_KEY;
107+
}
108+
109+
@Override
110+
protected String getReadCryptorTypeParameterKey() {
111+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_READ_CRYPTORTYPE_KEY;
112+
}
113+
61114
@Override
62115
protected String getSpecificConnectTimeoutKey() {
63116
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_CONNECT_TIMEOUT_KEY;
@@ -72,4 +125,9 @@ protected String getSpecificReadTimeoutKey() {
72125
protected String getSpecificRetryCountKey() {
73126
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_RETRYCOUNT_KEY;
74127
}
128+
129+
@Override
130+
protected String getPropertyParameterKey() {
131+
return ParameterKeys.LOCAL_CAMPAIGNS_JIT_WS_PROPERTY_KEY;
132+
}
75133
}

0 commit comments

Comments
 (0)