Skip to content

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Enuviel committed May 4, 2018
2 parents 10c8146 + c5bb9fa commit 772257d
Show file tree
Hide file tree
Showing 24 changed files with 1,426 additions and 244 deletions.
2 changes: 1 addition & 1 deletion AndroidSDKCore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="14"/>
<!-- Minimum permissions needed for SDK to work -->
<!-- Minimum permissions needed for SDK to work. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.leanplum.callbacks.ActionCallback;
import com.leanplum.utils.SharedPreferencesUtil;

import java.lang.reflect.Modifier;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -54,12 +54,14 @@ public class ActionManager {
private static final String LEANPLUM_LOCAL_PUSH_HELPER =
"com.leanplum.internal.LeanplumLocalPushHelper";
private static final String PREFERENCES_NAME = "__leanplum_messaging__";
private static LocationManager locationManager;
private static boolean loggedLocationManagerFailure = false;

public static class MessageMatchResult {
public boolean matchedTrigger;
public boolean matchedUnlessTrigger;
public boolean matchedLimit;
public boolean matchedActivePeriod;
}

public static synchronized ActionManager getInstance() {
Expand All @@ -69,14 +71,19 @@ public static synchronized ActionManager getInstance() {
return instance;
}

public static LocationManager getLocationManager() {
public static synchronized LocationManager getLocationManager() {
if (locationManager != null) {
return locationManager;
}

if (Util.hasPlayServices()) {
try {
// Reflection here prevents linker errors
// if Google Play Services is not used in the client app.
return (LocationManager) Class
locationManager = (LocationManager) Class
.forName("com.leanplum.LocationManagerImplementation")
.getMethod("instance").invoke(null);
return locationManager;
} catch (Throwable t) {
if (!loggedLocationManagerFailure) {
Log.w("Geofencing support requires leanplum-location module and Google Play " +
Expand Down Expand Up @@ -246,8 +253,8 @@ public MessageMatchResult shouldShowMessage(String messageId, Map<String, Object
// 2. Must match at least one trigger.
result.matchedTrigger = matchedTriggers(messageConfig.get("whenTriggers"), when, eventName,
contextualValues);
result.matchedUnlessTrigger = matchedTriggers(messageConfig.get("unlessTriggers"), when, eventName,
contextualValues);
result.matchedUnlessTrigger =
matchedTriggers(messageConfig.get("unlessTriggers"), when, eventName, contextualValues);
if (!result.matchedTrigger && !result.matchedUnlessTrigger) {
return result;
}
Expand All @@ -259,6 +266,18 @@ public MessageMatchResult shouldShowMessage(String messageId, Map<String, Object
limitConfig = CollectionUtil.uncheckedCast(limitConfigObj);
}
result.matchedLimit = matchesLimits(messageId, limitConfig);

// 4. Must be within active period.
Object messageStartTime = messageConfig.get("startTime");
Object messageEndTime = messageConfig.get("endTime");
if (messageStartTime == null || messageEndTime == null) {
result.matchedActivePeriod = true;
} else {
long currentTime = new Date().getTime();
result.matchedActivePeriod = currentTime >= (long) messageStartTime &&
currentTime <= (long) messageEndTime;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Constants {
public static int SOCKET_PORT = 80;
public static int NETWORK_TIMEOUT_SECONDS = 10;
public static int NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS = 10;
public static String LEANPLUM_VERSION = "4.0.0";
public static String LEANPLUM_VERSION = "4.0.1";
public static String CLIENT = "android";

static final String LEANPLUM_PACKAGE_IDENTIFIER = BuildConfig.LEANPLUM_PACKAGE_IDENTIFIER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.AsyncTask;

import com.leanplum.Leanplum;
import com.leanplum.utils.SharedPreferencesUtil;
Expand All @@ -41,6 +42,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

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

static boolean willSendErrorLog = false;

Expand All @@ -65,7 +69,7 @@ public class LeanplumEventDataManager {
*
* @param context Current context.
*/
public static void init(Context context) {
public static synchronized void init(Context context) {
if (database != null) {
Log.e("Database is already initialized.");
return;
Expand Down Expand Up @@ -181,6 +185,17 @@ private static void handleSQLiteError(String log, Throwable t) {
}
}

/**
* Execute async task on single thread Executer.
*
* @param task Async task to execute.
* @param params Params.
*/
static <T> void executeAsyncTask(AsyncTask<T, ?, ?> task,
T... params) {
task.executeOnExecutor(sqlLiteThreadExecutor, params);
}

private static class LeanplumDataBaseManager extends SQLiteOpenHelper {
LeanplumDataBaseManager(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static void maybePerformActions(String[] whenConditions, String eventName, int f
result.matchedTrigger |= conditionResult.matchedTrigger;
result.matchedUnlessTrigger |= conditionResult.matchedUnlessTrigger;
result.matchedLimit |= conditionResult.matchedLimit;
result.matchedActivePeriod |= conditionResult.matchedActivePeriod;
}

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

// Make sure message is within the active period.
if(!result.matchedActivePeriod){
continue;
}

if (result.matchedTrigger) {
ActionManager.getInstance().recordMessageTrigger(internalMessageId);

Expand Down
53 changes: 30 additions & 23 deletions AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,30 +230,37 @@ private Map<String, Object> createArgsDictionary() {
return args;
}

private void saveRequestForLater(Map<String, Object> args) {
synchronized (Request.class) {
Context context = Leanplum.getContext();
SharedPreferences preferences = context.getSharedPreferences(
LEANPLUM, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
long count = LeanplumEventDataManager.getEventsCount();
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
uuid = UUID.randomUUID().toString();
editor.putString(Constants.Defaults.UUID_KEY, uuid);
SharedPreferencesUtil.commitChanges(editor);
}
args.put(UUID_KEY, uuid);
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));

dataBaseIndex = count;
// Checks if here response and/or error callback for this request. We need to add callbacks to
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
// will handle error callback for this event.
if (response != null || error != null && !Util.isConnected()) {
eventCallbackManager.addCallbacks(this, response, error);
private void saveRequestForLater(final Map<String, Object> args) {
final Request currentRequest = this;
LeanplumEventDataManager.executeAsyncTask(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
synchronized (Request.class) {
Context context = Leanplum.getContext();
SharedPreferences preferences = context.getSharedPreferences(
LEANPLUM, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
long count = LeanplumEventDataManager.getEventsCount();
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
uuid = UUID.randomUUID().toString();
editor.putString(Constants.Defaults.UUID_KEY, uuid);
SharedPreferencesUtil.commitChanges(editor);
}
args.put(UUID_KEY, uuid);
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));

dataBaseIndex = count;
// Checks if here response and/or error callback for this request. We need to add callbacks to
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
// will handle error callback for this event.
if (response != null || error != null && !Util.isConnected()) {
eventCallbackManager.addCallbacks(currentRequest, response, error);
}
return null;
}
}
}
});
}

public void send() {
Expand Down
8 changes: 4 additions & 4 deletions AndroidSDKFcm/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<uses-sdk android:minSdkVersion="14"/>
<application>
<!-- Leanplum FCM Message Handling Service -->
<!-- Leanplum FCM Message Handling Service. -->
<service
android:name="com.leanplum.LeanplumPushFirebaseMessagingService"
android:enabled="true"
Expand All @@ -13,12 +13,12 @@
</intent-filter>
</service>

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


<!-- Leanplum FCM Instance ID Service -->
<!-- Leanplum FCM Instance ID Service. -->
<service
android:name="com.leanplum.LeanplumPushFcmListenerService"
android:enabled="true"
Expand All @@ -28,7 +28,7 @@
</intent-filter>
</service>

<!-- Leanplum Push Notification Receiver for FCM -->
<!-- Leanplum Push Notification Receiver for FCM. -->
<receiver
android:name="com.leanplum.LeanplumPushReceiver"
android:enabled="true"
Expand Down
11 changes: 6 additions & 5 deletions AndroidSDKGcm/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="14"/>
<!-- Permissions for GCM -->
<!-- Permissions for GCM. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>

<application>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
Expand All @@ -22,7 +23,7 @@
</intent-filter>
</receiver>

<!-- Leanplum Push Notification Receiver for GCM -->
<!-- Leanplum Push Notification Receiver for GCM. -->
<receiver
android:name="com.leanplum.LeanplumPushReceiver"
android:enabled="true"
Expand All @@ -32,7 +33,7 @@
</intent-filter>
</receiver>

<!-- Leanplum GCM Message Handling Service -->
<!-- Leanplum GCM Message Handling Service. -->
<service
android:name="com.leanplum.LeanplumPushListenerService"
android:enabled="true"
Expand All @@ -42,12 +43,12 @@
</intent-filter>
</service>

<!-- Leanplum GCM Registration Job Service -->
<!-- Leanplum GCM Registration Job Service. -->
<service
android:name="com.leanplum.LeanplumGcmRegistrationJobService"
android:permission="android.permission.BIND_JOB_SERVICE"/>

<!-- Leanplum GCM Instance ID Service -->
<!-- Leanplum GCM Instance ID Service. -->
<service
android:name="com.leanplum.LeanplumPushInstanceIDService"
android:enabled="true"
Expand Down
4 changes: 4 additions & 0 deletions AndroidSDKLocation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="14"/>
<!-- Permissions for geofencing. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application>
<!-- Geofencing Service -->
<service android:name="com.leanplum.ReceiveTransitionsIntentService"/>
Expand Down
4 changes: 2 additions & 2 deletions AndroidSDKPush/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<uses-sdk android:minSdkVersion="14"/>
<application>
<!-- Leanplum GCM/FCM Registration Service -->
<!-- Leanplum GCM/FCM Registration Service. -->
<service android:name="com.leanplum.LeanplumPushRegistrationService"/>
<!-- Leanplum Local Push Notification Service-->
<!-- Leanplum Local Push Notification Service. -->
<service android:name="com.leanplum.LeanplumLocalPushListenerService"/>
</application>
</manifest>
Loading

0 comments on commit 772257d

Please sign in to comment.