From c2386ab178d26f5bcfd3e1d07817c0eb9213c9a0 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Tue, 15 Oct 2024 22:58:12 -0700 Subject: [PATCH 1/5] removing some disk operations --- .../io/branch/referral/ServerRequest.java | 23 --------- .../branch/referral/ServerRequestQueue.java | 50 +------------------ 2 files changed, 1 insertion(+), 72 deletions(-) diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java index d3c256504..66e6ab983 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java @@ -395,29 +395,6 @@ public static ServerRequest fromJSON(JSONObject json, Context context) { return null; } - /** - *

Factory method for creating the specific server requests objects. Creates requests according - * to the request path.

- * - * @param requestPath Path for the server request. see {@link Defines.RequestPath} - * @param post A {@link JSONObject} object containing post data stored as key-value pairs. - * @param context Application context. - * @return A {@link ServerRequest} object for the given Post data. - */ - private static ServerRequest getExtendedServerRequest(String requestPath, JSONObject post, Context context, boolean initiatedByClient) { - ServerRequest extendedReq = null; - - if (requestPath.equalsIgnoreCase(Defines.RequestPath.GetURL.getPath())) { - extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context); - } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) { - extendedReq = new ServerRequestRegisterInstall(Defines.RequestPath.RegisterInstall, post, context, initiatedByClient); - } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterOpen.getPath())) { - extendedReq = new ServerRequestRegisterOpen(Defines.RequestPath.RegisterOpen, post, context, initiatedByClient); - } - - return extendedReq; - } - /** * Updates the google ads parameters. This should be called only from a background thread since it involves GADS method invocation using reflection * Ensure that when there is a valid GAID/AID, remove the SSAID if it's being used diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java index 3dde498ad..80041b6b6 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java @@ -83,50 +83,7 @@ static void shutDown() { private ServerRequestQueue(Context c) { sharedPref = c.getSharedPreferences("BNC_Server_Request_Queue", Context.MODE_PRIVATE); editor = sharedPref.edit(); - queue = retrieve(c); - } - - private void persist() { - try { - JSONArray jsonArr = new JSONArray(); - synchronized (reqQueueLockObject) { - for (ServerRequest aQueue : queue) { - if (aQueue.isPersistable()) { - JSONObject json = aQueue.toJSON(); - if (json != null) { - jsonArr.put(json); - } - } - } - } - - editor.putString(PREF_KEY, jsonArr.toString()).apply(); - } catch (Exception ex) { - String msg = ex.getMessage(); - BranchLogger.e("Failed to persist queue" + (msg == null ? "" : msg)); - } - } - - private List retrieve(Context context) { - String jsonStr = sharedPref.getString(PREF_KEY, null); - List result = Collections.synchronizedList(new LinkedList()); - synchronized (reqQueueLockObject) { - if (jsonStr != null) { - try { - JSONArray jsonArr = new JSONArray(jsonStr); - for (int i = 0, size = Math.min(jsonArr.length(), MAX_ITEMS); i < size; i++) { - JSONObject json = jsonArr.getJSONObject(i); - ServerRequest req = ServerRequest.fromJSON(json, context); - if (req != null) { - result.add(req); - } - } - } catch (JSONException e) { - BranchLogger.w("Caught JSONException " + e.getMessage()); - } - } - } - return result; + queue = Collections.synchronizedList(new LinkedList()); } /** @@ -154,7 +111,6 @@ void enqueue(ServerRequest request) { if (getSize() >= MAX_ITEMS) { queue.remove(1); } - persist(); } } } @@ -228,7 +184,6 @@ void insert(ServerRequest request, int index) { index = queue.size(); } queue.add(index, request); - persist(); } catch (IndexOutOfBoundsException e) { BranchLogger.e("Caught IndexOutOfBoundsException " + e.getMessage()); } @@ -250,7 +205,6 @@ public ServerRequest removeAt(int index) { synchronized (reqQueueLockObject) { try { req = queue.remove(index); - persist(); } catch (IndexOutOfBoundsException e) { BranchLogger.e("Caught IndexOutOfBoundsException " + e.getMessage()); } @@ -270,7 +224,6 @@ public boolean remove(ServerRequest request) { synchronized (reqQueueLockObject) { try { isRemoved = queue.remove(request); - persist(); } catch (UnsupportedOperationException e) { BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage()); } @@ -285,7 +238,6 @@ void clear() { synchronized (reqQueueLockObject) { try { queue.clear(); - persist(); } catch (UnsupportedOperationException e) { BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage()); } From 2bc9613eaa333aaf937374dffbef6e8a08a98c74 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 16 Oct 2024 01:38:13 -0700 Subject: [PATCH 2/5] keep disk based tests --- .../io/branch/referral/ServerRequest.java | 31 +++++++++++++++++-- build.gradle.kts | 4 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java index 66e6ab983..6f743a62c 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java @@ -348,7 +348,8 @@ public JSONObject toJSON() { } return json; } - + + // TODO: Replace with in-memory only ServerRequest objects. /** *

Converts a {@link JSONObject} object containing keys stored as key-value pairs into * a {@link ServerRequest}.

@@ -388,13 +389,37 @@ public static ServerRequest fromJSON(JSONObject json, Context context) { } catch (JSONException e) { BranchLogger.w("Caught JSONException " + e.getMessage()); } - + if (!TextUtils.isEmpty(requestPath)) { return getExtendedServerRequest(requestPath, post, context, initiatedByClient); } return null; } - + + // TODO: Replace with in-memory only ServerRequest objects. + /** + *

Factory method for creating the specific server requests objects. Creates requests according + * to the request path.

+ * + * @param requestPath Path for the server request. see {@link Defines.RequestPath} + * @param post A {@link JSONObject} object containing post data stored as key-value pairs. + * @param context Application context. + * @return A {@link ServerRequest} object for the given Post data. + */ + private static ServerRequest getExtendedServerRequest(String requestPath, JSONObject post, Context context, boolean initiatedByClient) { + ServerRequest extendedReq = null; + + if (requestPath.equalsIgnoreCase(Defines.RequestPath.GetURL.getPath())) { + extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context); + } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) { + extendedReq = new ServerRequestRegisterInstall(Defines.RequestPath.RegisterInstall, post, context, initiatedByClient); + } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterOpen.getPath())) { + extendedReq = new ServerRequestRegisterOpen(Defines.RequestPath.RegisterOpen, post, context, initiatedByClient); + } + + return extendedReq; + } + /** * Updates the google ads parameters. This should be called only from a background thread since it involves GADS method invocation using reflection * Ensure that when there is a valid GAID/AID, remove the SSAID if it's being used diff --git a/build.gradle.kts b/build.gradle.kts index 07c3224a0..55f707167 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ import org.gradle.api.tasks.testing.logging.* plugins { - id("com.android.library") version "8.1.2" apply false - id("com.android.application") version "8.1.2" apply false + id("com.android.library") version "8.3.2" apply false + id("com.android.application") version "8.3.2" apply false id("org.jetbrains.kotlin.android") version "1.6.21" apply false } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 70880f24e..d84ea14c9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ #Sun Apr 07 13:06:19 PDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 76a7e6aa2aea256e4ed6cc1fa7d7ccb1cfec6077 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 16 Oct 2024 01:48:03 -0700 Subject: [PATCH 3/5] Update ServerRequest.java --- Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java index 6f743a62c..c975350bb 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java @@ -408,7 +408,6 @@ public static ServerRequest fromJSON(JSONObject json, Context context) { */ private static ServerRequest getExtendedServerRequest(String requestPath, JSONObject post, Context context, boolean initiatedByClient) { ServerRequest extendedReq = null; - if (requestPath.equalsIgnoreCase(Defines.RequestPath.GetURL.getPath())) { extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context); } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) { @@ -416,7 +415,6 @@ private static ServerRequest getExtendedServerRequest(String requestPath, JSONOb } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterOpen.getPath())) { extendedReq = new ServerRequestRegisterOpen(Defines.RequestPath.RegisterOpen, post, context, initiatedByClient); } - return extendedReq; } From d6b3defe861bed999366d2527df1b0d905baf772 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 16 Oct 2024 01:48:43 -0700 Subject: [PATCH 4/5] Update ServerRequest.java --- Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java index c975350bb..4a8119c99 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java @@ -408,6 +408,7 @@ public static ServerRequest fromJSON(JSONObject json, Context context) { */ private static ServerRequest getExtendedServerRequest(String requestPath, JSONObject post, Context context, boolean initiatedByClient) { ServerRequest extendedReq = null; + if (requestPath.equalsIgnoreCase(Defines.RequestPath.GetURL.getPath())) { extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context); } else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) { @@ -417,7 +418,7 @@ private static ServerRequest getExtendedServerRequest(String requestPath, JSONOb } return extendedReq; } - + /** * Updates the google ads parameters. This should be called only from a background thread since it involves GADS method invocation using reflection * Ensure that when there is a valid GAID/AID, remove the SSAID if it's being used From 134107a906eff9bb799d653d86b5db1185e34b0e Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 16 Oct 2024 02:06:14 -0700 Subject: [PATCH 5/5] remove isPersistable --- .../main/java/io/branch/referral/ServerRequest.java | 13 ++----------- .../io/branch/referral/ServerRequestCreateUrl.java | 5 ----- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java index 4a8119c99..d27a5c8d2 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java @@ -139,16 +139,7 @@ protected ServerRequest(Defines.RequestPath requestPath, JSONObject post, Contex public boolean shouldRetryOnFail() { return false; } - - /** - * Specifies whether this request should be persisted to memory in order to re send in the next session - * - * @return {@code true} by default. Should be override for request that need not to be persisted - */ - boolean isPersistable() { - return true; - } - + /** * Specifies whether this request should add the limit app tracking value * @@ -418,7 +409,7 @@ private static ServerRequest getExtendedServerRequest(String requestPath, JSONOb } return extendedReq; } - + /** * Updates the google ads parameters. This should be called only from a background thread since it involves GADS method invocation using reflection * Ensure that when there is a valid GAID/AID, remove the SSAID if it's being used diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestCreateUrl.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestCreateUrl.java index 3b70fe021..f57859a15 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestCreateUrl.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestCreateUrl.java @@ -257,11 +257,6 @@ private String generateLongUrlWithParams(String baseUrl) { return longUrl; } - @Override - boolean isPersistable() { - return false; // No need to retrieve create url request from previous session - } - @Override protected boolean prepareExecuteWithoutTracking() { // SDK-271 -- Allow creation of short links when tracking is disabled.