Skip to content

Commit 772257d

Browse files
committed
4.0.1
2 parents 10c8146 + c5bb9fa commit 772257d

24 files changed

+1426
-244
lines changed

AndroidSDKCore/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<uses-sdk android:minSdkVersion="14"/>
5-
<!-- Minimum permissions needed for SDK to work -->
5+
<!-- Minimum permissions needed for SDK to work. -->
66
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
77
<uses-permission android:name="android.permission.INTERNET"/>
88
</manifest>

AndroidSDKCore/src/main/java/com/leanplum/internal/ActionManager.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.leanplum.callbacks.ActionCallback;
3232
import com.leanplum.utils.SharedPreferencesUtil;
3333

34-
import java.lang.reflect.Modifier;
34+
import java.util.Date;
3535
import java.util.HashMap;
3636
import java.util.List;
3737
import java.util.Map;
@@ -54,12 +54,14 @@ public class ActionManager {
5454
private static final String LEANPLUM_LOCAL_PUSH_HELPER =
5555
"com.leanplum.internal.LeanplumLocalPushHelper";
5656
private static final String PREFERENCES_NAME = "__leanplum_messaging__";
57+
private static LocationManager locationManager;
5758
private static boolean loggedLocationManagerFailure = false;
5859

5960
public static class MessageMatchResult {
6061
public boolean matchedTrigger;
6162
public boolean matchedUnlessTrigger;
6263
public boolean matchedLimit;
64+
public boolean matchedActivePeriod;
6365
}
6466

6567
public static synchronized ActionManager getInstance() {
@@ -69,14 +71,19 @@ public static synchronized ActionManager getInstance() {
6971
return instance;
7072
}
7173

72-
public static LocationManager getLocationManager() {
74+
public static synchronized LocationManager getLocationManager() {
75+
if (locationManager != null) {
76+
return locationManager;
77+
}
78+
7379
if (Util.hasPlayServices()) {
7480
try {
7581
// Reflection here prevents linker errors
7682
// if Google Play Services is not used in the client app.
77-
return (LocationManager) Class
83+
locationManager = (LocationManager) Class
7884
.forName("com.leanplum.LocationManagerImplementation")
7985
.getMethod("instance").invoke(null);
86+
return locationManager;
8087
} catch (Throwable t) {
8188
if (!loggedLocationManagerFailure) {
8289
Log.w("Geofencing support requires leanplum-location module and Google Play " +
@@ -246,8 +253,8 @@ public MessageMatchResult shouldShowMessage(String messageId, Map<String, Object
246253
// 2. Must match at least one trigger.
247254
result.matchedTrigger = matchedTriggers(messageConfig.get("whenTriggers"), when, eventName,
248255
contextualValues);
249-
result.matchedUnlessTrigger = matchedTriggers(messageConfig.get("unlessTriggers"), when, eventName,
250-
contextualValues);
256+
result.matchedUnlessTrigger =
257+
matchedTriggers(messageConfig.get("unlessTriggers"), when, eventName, contextualValues);
251258
if (!result.matchedTrigger && !result.matchedUnlessTrigger) {
252259
return result;
253260
}
@@ -259,6 +266,18 @@ public MessageMatchResult shouldShowMessage(String messageId, Map<String, Object
259266
limitConfig = CollectionUtil.uncheckedCast(limitConfigObj);
260267
}
261268
result.matchedLimit = matchesLimits(messageId, limitConfig);
269+
270+
// 4. Must be within active period.
271+
Object messageStartTime = messageConfig.get("startTime");
272+
Object messageEndTime = messageConfig.get("endTime");
273+
if (messageStartTime == null || messageEndTime == null) {
274+
result.matchedActivePeriod = true;
275+
} else {
276+
long currentTime = new Date().getTime();
277+
result.matchedActivePeriod = currentTime >= (long) messageStartTime &&
278+
currentTime <= (long) messageEndTime;
279+
}
280+
262281
return result;
263282
}
264283

AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Constants {
3636
public static int SOCKET_PORT = 80;
3737
public static int NETWORK_TIMEOUT_SECONDS = 10;
3838
public static int NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS = 10;
39-
public static String LEANPLUM_VERSION = "4.0.0";
39+
public static String LEANPLUM_VERSION = "4.0.1";
4040
public static String CLIENT = "android";
4141

4242
static final String LEANPLUM_PACKAGE_IDENTIFIER = BuildConfig.LEANPLUM_PACKAGE_IDENTIFIER;

AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumEventDataManager.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.database.DatabaseUtils;
3030
import android.database.sqlite.SQLiteDatabase;
3131
import android.database.sqlite.SQLiteOpenHelper;
32+
import android.os.AsyncTask;
3233

3334
import com.leanplum.Leanplum;
3435
import com.leanplum.utils.SharedPreferencesUtil;
@@ -41,6 +42,8 @@
4142
import java.util.Locale;
4243
import java.util.Map;
4344
import java.util.UUID;
45+
import java.util.concurrent.Executor;
46+
import java.util.concurrent.Executors;
4447

4548
/**
4649
* LeanplumEventDataManager class to work with SQLite.
@@ -57,6 +60,7 @@ public class LeanplumEventDataManager {
5760
private static SQLiteDatabase database;
5861
private static LeanplumDataBaseManager databaseManager;
5962
private static ContentValues contentValues = new ContentValues();
63+
private static final Executor sqlLiteThreadExecutor = Executors.newSingleThreadExecutor();
6064

6165
static boolean willSendErrorLog = false;
6266

@@ -65,7 +69,7 @@ public class LeanplumEventDataManager {
6569
*
6670
* @param context Current context.
6771
*/
68-
public static void init(Context context) {
72+
public static synchronized void init(Context context) {
6973
if (database != null) {
7074
Log.e("Database is already initialized.");
7175
return;
@@ -181,6 +185,17 @@ private static void handleSQLiteError(String log, Throwable t) {
181185
}
182186
}
183187

188+
/**
189+
* Execute async task on single thread Executer.
190+
*
191+
* @param task Async task to execute.
192+
* @param params Params.
193+
*/
194+
static <T> void executeAsyncTask(AsyncTask<T, ?, ?> task,
195+
T... params) {
196+
task.executeOnExecutor(sqlLiteThreadExecutor, params);
197+
}
198+
184199
private static class LeanplumDataBaseManager extends SQLiteOpenHelper {
185200
LeanplumDataBaseManager(Context context) {
186201
super(context, DATABASE_NAME, null, DATABASE_VERSION);

AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumInternal.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ static void maybePerformActions(String[] whenConditions, String eventName, int f
183183
result.matchedTrigger |= conditionResult.matchedTrigger;
184184
result.matchedUnlessTrigger |= conditionResult.matchedUnlessTrigger;
185185
result.matchedLimit |= conditionResult.matchedLimit;
186+
result.matchedActivePeriod |= conditionResult.matchedActivePeriod;
186187
}
187188

188189
// Make sure we cancel before matching in case the criteria overlap.
@@ -205,6 +206,11 @@ public void variablesChanged() {
205206
});
206207
}
207208

209+
// Make sure message is within the active period.
210+
if(!result.matchedActivePeriod){
211+
continue;
212+
}
213+
208214
if (result.matchedTrigger) {
209215
ActionManager.getInstance().recordMessageTrigger(internalMessageId);
210216

AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,37 @@ private Map<String, Object> createArgsDictionary() {
230230
return args;
231231
}
232232

233-
private void saveRequestForLater(Map<String, Object> args) {
234-
synchronized (Request.class) {
235-
Context context = Leanplum.getContext();
236-
SharedPreferences preferences = context.getSharedPreferences(
237-
LEANPLUM, Context.MODE_PRIVATE);
238-
SharedPreferences.Editor editor = preferences.edit();
239-
long count = LeanplumEventDataManager.getEventsCount();
240-
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
241-
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
242-
uuid = UUID.randomUUID().toString();
243-
editor.putString(Constants.Defaults.UUID_KEY, uuid);
244-
SharedPreferencesUtil.commitChanges(editor);
245-
}
246-
args.put(UUID_KEY, uuid);
247-
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));
248-
249-
dataBaseIndex = count;
250-
// Checks if here response and/or error callback for this request. We need to add callbacks to
251-
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
252-
// will handle error callback for this event.
253-
if (response != null || error != null && !Util.isConnected()) {
254-
eventCallbackManager.addCallbacks(this, response, error);
233+
private void saveRequestForLater(final Map<String, Object> args) {
234+
final Request currentRequest = this;
235+
LeanplumEventDataManager.executeAsyncTask(new AsyncTask<Void, Void, Void>() {
236+
@Override
237+
protected Void doInBackground(Void... params) {
238+
synchronized (Request.class) {
239+
Context context = Leanplum.getContext();
240+
SharedPreferences preferences = context.getSharedPreferences(
241+
LEANPLUM, Context.MODE_PRIVATE);
242+
SharedPreferences.Editor editor = preferences.edit();
243+
long count = LeanplumEventDataManager.getEventsCount();
244+
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
245+
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
246+
uuid = UUID.randomUUID().toString();
247+
editor.putString(Constants.Defaults.UUID_KEY, uuid);
248+
SharedPreferencesUtil.commitChanges(editor);
249+
}
250+
args.put(UUID_KEY, uuid);
251+
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));
252+
253+
dataBaseIndex = count;
254+
// Checks if here response and/or error callback for this request. We need to add callbacks to
255+
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
256+
// will handle error callback for this event.
257+
if (response != null || error != null && !Util.isConnected()) {
258+
eventCallbackManager.addCallbacks(currentRequest, response, error);
259+
}
260+
return null;
261+
}
255262
}
256-
}
263+
});
257264
}
258265

259266
public void send() {

AndroidSDKFcm/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<uses-sdk android:minSdkVersion="14"/>
55
<application>
6-
<!-- Leanplum FCM Message Handling Service -->
6+
<!-- Leanplum FCM Message Handling Service. -->
77
<service
88
android:name="com.leanplum.LeanplumPushFirebaseMessagingService"
99
android:enabled="true"
@@ -13,12 +13,12 @@
1313
</intent-filter>
1414
</service>
1515

16-
<!-- Leanplum FCM Registration Job Service -->
16+
<!-- Leanplum FCM Registration Job Service. -->
1717
<service android:name="com.leanplum.LeanplumFcmRegistrationJobService"
1818
android:permission="android.permission.BIND_JOB_SERVICE"/>
1919

2020

21-
<!-- Leanplum FCM Instance ID Service -->
21+
<!-- Leanplum FCM Instance ID Service. -->
2222
<service
2323
android:name="com.leanplum.LeanplumPushFcmListenerService"
2424
android:enabled="true"
@@ -28,7 +28,7 @@
2828
</intent-filter>
2929
</service>
3030

31-
<!-- Leanplum Push Notification Receiver for FCM -->
31+
<!-- Leanplum Push Notification Receiver for FCM. -->
3232
<receiver
3333
android:name="com.leanplum.LeanplumPushReceiver"
3434
android:enabled="true"

AndroidSDKGcm/src/main/AndroidManifest.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<uses-sdk android:minSdkVersion="14"/>
5-
<!-- Permissions for GCM -->
5+
<!-- Permissions for GCM. -->
66
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
77
<permission
88
android:name="${applicationId}.permission.C2D_MESSAGE"
99
android:protectionLevel="signature"/>
1010
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
11+
1112
<application>
1213
<receiver
1314
android:name="com.google.android.gms.gcm.GcmReceiver"
@@ -22,7 +23,7 @@
2223
</intent-filter>
2324
</receiver>
2425

25-
<!-- Leanplum Push Notification Receiver for GCM -->
26+
<!-- Leanplum Push Notification Receiver for GCM. -->
2627
<receiver
2728
android:name="com.leanplum.LeanplumPushReceiver"
2829
android:enabled="true"
@@ -32,7 +33,7 @@
3233
</intent-filter>
3334
</receiver>
3435

35-
<!-- Leanplum GCM Message Handling Service -->
36+
<!-- Leanplum GCM Message Handling Service. -->
3637
<service
3738
android:name="com.leanplum.LeanplumPushListenerService"
3839
android:enabled="true"
@@ -42,12 +43,12 @@
4243
</intent-filter>
4344
</service>
4445

45-
<!-- Leanplum GCM Registration Job Service -->
46+
<!-- Leanplum GCM Registration Job Service. -->
4647
<service
4748
android:name="com.leanplum.LeanplumGcmRegistrationJobService"
4849
android:permission="android.permission.BIND_JOB_SERVICE"/>
4950

50-
<!-- Leanplum GCM Instance ID Service -->
51+
<!-- Leanplum GCM Instance ID Service. -->
5152
<service
5253
android:name="com.leanplum.LeanplumPushInstanceIDService"
5354
android:enabled="true"

AndroidSDKLocation/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<uses-sdk android:minSdkVersion="14"/>
5+
<!-- Permissions for geofencing. -->
6+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
7+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
8+
59
<application>
610
<!-- Geofencing Service -->
711
<service android:name="com.leanplum.ReceiveTransitionsIntentService"/>

AndroidSDKPush/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
<uses-sdk android:minSdkVersion="14"/>
55
<application>
6-
<!-- Leanplum GCM/FCM Registration Service -->
6+
<!-- Leanplum GCM/FCM Registration Service. -->
77
<service android:name="com.leanplum.LeanplumPushRegistrationService"/>
8-
<!-- Leanplum Local Push Notification Service-->
8+
<!-- Leanplum Local Push Notification Service. -->
99
<service android:name="com.leanplum.LeanplumLocalPushListenerService"/>
1010
</application>
1111
</manifest>

0 commit comments

Comments
 (0)