From 71cdd02338a75bdeb0ef1e96ad6ddcb1f51b1ca8 Mon Sep 17 00:00:00 2001 From: Alexis Oyama Date: Wed, 6 Jun 2018 22:20:55 -0700 Subject: [PATCH 1/2] Android SDK 4.0.3 --- .../src/main/java/com/leanplum/internal/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java b/AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java index 4a63745f3..2f39aa14d 100644 --- a/AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java +++ b/AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java @@ -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.2"; + public static String LEANPLUM_VERSION = "4.0.3"; public static String CLIENT = "android"; static final String LEANPLUM_PACKAGE_IDENTIFIER = BuildConfig.LEANPLUM_PACKAGE_IDENTIFIER; From 5ee0d769e29990d3f76e73e64be93a62b309bed2 Mon Sep 17 00:00:00 2001 From: Alexis Oyama Date: Wed, 6 Jun 2018 23:55:14 -0700 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"fix(ANR):=20Moves=20saveRequestFo?= =?UTF-8?q?rLater=20from=20main=20thread.=20Adds=20synchroniz=E2=80=A6=20(?= =?UTF-8?q?#162)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1a3e3b93c23967e417fc0053ee73f5d10a044848. --- .../internal/LeanplumEventDataManager.java | 17 +----- .../java/com/leanplum/internal/Request.java | 57 ++++++++----------- .../com/leanplum/__setup/AbstractTest.java | 3 - .../com/leanplum/internal/RequestTest.java | 4 -- 4 files changed, 24 insertions(+), 57 deletions(-) diff --git a/AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumEventDataManager.java b/AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumEventDataManager.java index 813d89712..b02b2fb79 100644 --- a/AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumEventDataManager.java +++ b/AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumEventDataManager.java @@ -29,7 +29,6 @@ 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; @@ -42,8 +41,6 @@ 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. @@ -60,7 +57,6 @@ 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; @@ -69,7 +65,7 @@ public class LeanplumEventDataManager { * * @param context Current context. */ - public static synchronized void init(Context context) { + public static void init(Context context) { if (database != null) { Log.e("Database is already initialized."); return; @@ -185,17 +181,6 @@ 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 void executeAsyncTask(AsyncTask task, - T... params) { - task.executeOnExecutor(sqlLiteThreadExecutor, params); - } - private static class LeanplumDataBaseManager extends SQLiteOpenHelper { LeanplumDataBaseManager(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); diff --git a/AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java b/AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java index c51747a07..ed81be052 100644 --- a/AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java +++ b/AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java @@ -230,41 +230,30 @@ private Map createArgsDictionary() { return args; } - private void saveRequestForLater(final Map args) { - final Request currentRequest = this; - LeanplumEventDataManager.executeAsyncTask(new AsyncTask() { - @Override - protected Void doInBackground(Void... params) { - try { - 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); - } - } - } catch (Throwable t) { - Util.handleException(t); - } - return null; + private void saveRequestForLater(Map 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); + } + } } public void send() { diff --git a/AndroidSDKTests/src/test/java/com/leanplum/__setup/AbstractTest.java b/AndroidSDKTests/src/test/java/com/leanplum/__setup/AbstractTest.java index b51927bf3..a81ce688f 100644 --- a/AndroidSDKTests/src/test/java/com/leanplum/__setup/AbstractTest.java +++ b/AndroidSDKTests/src/test/java/com/leanplum/__setup/AbstractTest.java @@ -130,9 +130,6 @@ public void before() throws Exception { // Mock with our executor which will run on main thread. ReflectionHelpers.setStaticField(Util.class, "asyncExecutor", new SynchronousExecutor()); ReflectionHelpers.setStaticField(Util.class, "singleThreadExecutor", new SynchronousExecutor()); - ReflectionHelpers.setStaticField(LeanplumEventDataManager.class, "sqlLiteThreadExecutor", - new SynchronousExecutor()); - ReflectionHelpers.setStaticField(LeanplumEventDataManager.class, "databaseManager", null); ReflectionHelpers.setStaticField(LeanplumEventDataManager.class, "database", null); // Get and set application context. diff --git a/AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java b/AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java index ad4e533cb..807a5452a 100644 --- a/AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java +++ b/AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java @@ -24,7 +24,6 @@ import com.leanplum.Leanplum; import com.leanplum.__setup.LeanplumTestApp; -import com.leanplum._whitebox.utilities.SynchronousExecutor; import junit.framework.TestCase; @@ -35,7 +34,6 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import org.robolectric.util.ReflectionHelpers; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -67,8 +65,6 @@ public void setUp() { Application context = RuntimeEnvironment.application; assertNotNull(context); Leanplum.setApplicationContext(context); - ReflectionHelpers.setStaticField(LeanplumEventDataManager.class, "sqlLiteThreadExecutor", new SynchronousExecutor()); - LeanplumEventDataManagerTest.setDatabaseToNull(); } /**