Skip to content

Commit 6dfbf81

Browse files
Remove user agent string query from start up (#1259)
* Remove user agent string query from opens Only query when needed by v2 event * revert test change * adding unlock in catch
1 parent 8135611 commit 6dfbf81

File tree

6 files changed

+12
-29
lines changed

6 files changed

+12
-29
lines changed

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ protected void onStart() {
720720

721721
private void initSessionsWithTests() {
722722
boolean testUserAgent = true;
723-
userAgentTests(testUserAgent, 10);
723+
userAgentTests(testUserAgent, 1);
724724
}
725725

726726
// Enqueue several v2 events prior to init to simulate worst timing conditions for user agent fetch

Branch-SDK/src/main/java/io/branch/referral/Branch.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean forceBra
14651465

14661466
ServerRequestInitSession r = requestQueue_.getSelfInitRequest();
14671467
BranchLogger.v("Ordering init calls");
1468+
BranchLogger.v("Self init request: " + r);
14681469
requestQueue_.printQueue();
14691470

14701471
// if forceBranchSession aka reInit is true, we want to preserve the callback order in case
@@ -1555,8 +1556,12 @@ public void notifyNetworkAvailable() {
15551556
}
15561557

15571558
private void setActivityLifeCycleObserver(Application application) {
1559+
BranchLogger.v("setActivityLifeCycleObserver activityLifeCycleObserver: " + activityLifeCycleObserver
1560+
+ " application: " + application);
15581561
try {
15591562
activityLifeCycleObserver = new BranchActivityLifecycleObserver();
1563+
BranchLogger.v("setActivityLifeCycleObserver set new activityLifeCycleObserver: " + activityLifeCycleObserver
1564+
+ " application: " + application);
15601565
/* Set an observer for activity life cycle events. */
15611566
application.unregisterActivityLifecycleCallbacks(activityLifeCycleObserver);
15621567
application.registerActivityLifecycleCallbacks(activityLifeCycleObserver);
@@ -1836,8 +1841,8 @@ void checkForAutoDeepLinkConfiguration() {
18361841
}
18371842
}
18381843
}
1844+
BranchLogger.v("deepLinkActivity " + deepLinkActivity + " getCurrentActivity " + getCurrentActivity());
18391845
if (deepLinkActivity != null && getCurrentActivity() != null) {
1840-
BranchLogger.v("deepLinkActivity " + deepLinkActivity + " getCurrentActivity " + getCurrentActivity());
18411846
Activity currentActivity = getCurrentActivity();
18421847

18431848
Intent intent = new Intent(currentActivity, Class.forName(deepLinkActivity));

Branch-SDK/src/main/java/io/branch/referral/DeviceInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ public void resumeWith(@NonNull Object o) {
312312
}
313313
catch (Exception exception){
314314
BranchLogger.w("Caught exception trying to set userAgent " + exception.getMessage());
315+
Branch.getInstance().requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.USER_AGENT_STRING_LOCK);
316+
Branch.getInstance().requestQueue_.processNextQueueItem("getUserAgentAsync");
315317
}
316318
}
317319

Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,6 @@ public void onRequestSucceeded(ServerResponse response, Branch branch) {
9292
void onInitSessionCompleted(ServerResponse response, Branch branch) {
9393
DeepLinkRoutingValidator.validate(branch.currentActivityReference_);
9494
branch.updateSkipURLFormats();
95-
96-
// Run this after session init, ahead of any V2 event, in the background.
97-
if (!Branch.userAgentSync && TextUtils.isEmpty(Branch._userAgentString)) {
98-
DeviceSignalsKt.getUserAgentAsync(branch.getApplicationContext(), new Continuation<String>() {
99-
@NonNull
100-
@Override
101-
public CoroutineContext getContext() {
102-
return EmptyCoroutineContext.INSTANCE;
103-
}
104-
105-
@Override
106-
public void resumeWith(@NonNull Object o) {
107-
if (o != null) {
108-
BranchLogger.v("onInitSessionCompleted resumeWith userAgent " + o + " on thread " + Thread.currentThread().getName());
109-
Branch._userAgentString = (String) o;
110-
}
111-
112-
Branch.getInstance().requestQueue_.unlockProcessWait(PROCESS_WAIT_LOCK.USER_AGENT_STRING_LOCK);
113-
Branch.getInstance().requestQueue_.processNextQueueItem("getUserAgentAsync resumeWith");
114-
}
115-
});
116-
}
117-
else {
118-
BranchLogger.v("Deferring userAgent string call for sync retrieval");
119-
}
120-
12195
BranchLogger.v("onInitSessionCompleted on thread " + Thread.currentThread().getName());
12296
}
12397

Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void clear() {
256256
ServerRequestInitSession getSelfInitRequest() {
257257
synchronized (reqQueueLockObject) {
258258
for (ServerRequest req : queue) {
259+
BranchLogger.v("Checking if " + req + " is instanceof ServerRequestInitSession");
259260
if (req instanceof ServerRequestInitSession) {
260261
ServerRequestInitSession r = (ServerRequestInitSession) req;
261262
if (r.initiatedByClient) {
@@ -350,6 +351,7 @@ else if (requestNeedsSession(req) && !isSessionAvailableForRequest()) {
350351
}
351352

352353
void insertRequestAtFront(ServerRequest req) {
354+
BranchLogger.v("insertRequestAtFront " + req + " networkCount_: " + networkCount_);
353355
if (networkCount_ == 0) {
354356
this.insert(req, 0);
355357
} else {

Branch-SDK/src/main/java/io/branch/referral/util/BranchEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public void handleFailure(int statusCode, String causeMsg) {
287287
BranchLogger.v("Preparing V2 event, user agent is " + Branch._userAgentString);
288288

289289
if(TextUtils.isEmpty(Branch._userAgentString)){
290-
BranchLogger.v("handleNewRequest adding process wait lock USER_AGENT_STRING_LOCK");
290+
BranchLogger.v("User agent is empty, handleNewRequest adding process wait lock USER_AGENT_STRING_LOCK");
291291
req.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.USER_AGENT_STRING_LOCK);
292292
}
293293

0 commit comments

Comments
 (0)