Skip to content

Commit 8ed0daa

Browse files
Always execute init tasks through Tracking Controller (#1228)
Always execute init tasks
1 parent 8fb29ef commit 8ed0daa

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

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

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ private void initializeSession(ServerRequestInitSession initRequest, int delay)
14311431
if (forceBranchSession && intent != null) {
14321432
intent.removeExtra(Defines.IntentKeys.ForceNewBranchSession.getKey()); // SDK-881, avoid double initialization
14331433
}
1434-
registerAppInit(initRequest, false, forceBranchSession);
1434+
registerAppInit(initRequest, forceBranchSession);
14351435
} else if (initRequest.callback_ != null) {
14361436
// Else, let the user know session initialization failed because it's already initialized.
14371437
initRequest.callback_.onInitFinished(null, new BranchError("Warning.", BranchError.ERR_BRANCH_ALREADY_INITIALIZED));
@@ -1442,7 +1442,7 @@ private void initializeSession(ServerRequestInitSession initRequest, int delay)
14421442
* Registers app init with params filtered from the intent. Unless ignoreIntent = true, this
14431443
* will wait on the wait locks to complete any pending operations
14441444
*/
1445-
void registerAppInit(@NonNull ServerRequestInitSession request, boolean ignoreWaitLocks, boolean forceBranchSession) {
1445+
void registerAppInit(@NonNull ServerRequestInitSession request, boolean forceBranchSession) {
14461446
BranchLogger.v("registerAppInit " + request);
14471447
setInitState(SESSION_STATE.INITIALISING);
14481448

@@ -1464,38 +1464,37 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean ignoreWa
14641464
}
14651465
BranchLogger.v("Finished ordering init calls");
14661466
requestQueue_.printQueue();
1467-
initTasks(request, ignoreWaitLocks);
1467+
initTasks(request);
14681468

14691469
requestQueue_.processNextQueueItem("registerAppInit");
14701470
}
14711471

1472-
private void initTasks(ServerRequest request, boolean ignoreWaitLocks) {
1473-
BranchLogger.v("initTasks " + request + " ignoreWaitLocks " + ignoreWaitLocks);
1474-
if (!ignoreWaitLocks) {
1475-
// Single top activities can be launched from stack and there may be a new intent provided with onNewIntent() call.
1476-
// In this case need to wait till onResume to get the latest intent. Bypass this if bypassWaitingForIntent_ is true.
1477-
if (intentState_ != INTENT_STATE.READY && isWaitingForIntent()) {
1478-
BranchLogger.v("Adding INTENT_PENDING_WAIT_LOCK");
1479-
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INTENT_PENDING_WAIT_LOCK);
1480-
}
1481-
1482-
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.GAID_FETCH_WAIT_LOCK);
1483-
1484-
if (request instanceof ServerRequestRegisterInstall) {
1485-
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
1486-
BranchLogger.v("Adding INSTALL_REFERRER_FETCH_WAIT_LOCK");
1487-
1488-
deviceInfo_.getSystemObserver().fetchInstallReferrer(context_, new SystemObserver.InstallReferrerFetchEvents(){
1489-
@Override
1490-
public void onInstallReferrersFinished() {
1491-
request.removeProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
1492-
BranchLogger.v("INSTALL_REFERRER_FETCH_WAIT_LOCK removed");
1493-
requestQueue_.processNextQueueItem("onInstallReferrersFinished");
1494-
}
1495-
});
1496-
}
1472+
private void initTasks(ServerRequest request) {
1473+
BranchLogger.v("initTasks " + request);
1474+
// Single top activities can be launched from stack and there may be a new intent provided with onNewIntent() call.
1475+
// In this case need to wait till onResume to get the latest intent. Bypass this if bypassWaitingForIntent_ is true.
1476+
if (intentState_ != INTENT_STATE.READY && isWaitingForIntent()) {
1477+
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INTENT_PENDING_WAIT_LOCK);
1478+
BranchLogger.v("Added INTENT_PENDING_WAIT_LOCK");
1479+
}
1480+
1481+
if (request instanceof ServerRequestRegisterInstall) {
1482+
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
1483+
BranchLogger.v("Added INSTALL_REFERRER_FETCH_WAIT_LOCK");
1484+
1485+
deviceInfo_.getSystemObserver().fetchInstallReferrer(context_, new SystemObserver.InstallReferrerFetchEvents() {
1486+
@Override
1487+
public void onInstallReferrersFinished() {
1488+
request.removeProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
1489+
BranchLogger.v("INSTALL_REFERRER_FETCH_WAIT_LOCK removed");
1490+
requestQueue_.processNextQueueItem("onInstallReferrersFinished");
1491+
}
1492+
});
14971493
}
14981494

1495+
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.GAID_FETCH_WAIT_LOCK);
1496+
BranchLogger.v("Added GAID_FETCH_WAIT_LOCK");
1497+
14991498
deviceInfo_.getSystemObserver().fetchAdId(context_, new SystemObserver.AdsParamsFetchEvents() {
15001499
@Override
15011500
public void onAdsParamsFetchFinished() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ else if (isHuaweiMobileServicesAvailable(context)) {
459459
}
460460

461461
private void fetchHuaweiAdId(Context context, AdsParamsFetchEvents callback) {
462+
BranchLogger.v("Begin fetchHuaweiAdId");
462463
if(DependencyUtilsKt.classExists(DependencyUtilsKt.huaweiAdvertisingIdClientClass)) {
463464
AdvertisingIdsKt.getHuaweiAdvertisingInfoObject(context, new Continuation<com.huawei.hms.ads.identifier.AdvertisingIdClient.Info>() {
464465
@NonNull
@@ -508,6 +509,7 @@ public void resumeWith(Object o) {
508509

509510

510511
private void fetchGoogleAdId(Context context, AdsParamsFetchEvents callback) {
512+
BranchLogger.v("Begin fetchGoogleAdId");
511513
if(DependencyUtilsKt.classExists(DependencyUtilsKt.playStoreAdvertisingIdClientClass)) {
512514
AdvertisingIdsKt.getGoogleAdvertisingInfoObject(context, new Continuation<AdvertisingIdClient.Info>() {
513515
@NonNull
@@ -555,7 +557,7 @@ public void resumeWith(Object o) {
555557
}
556558

557559
private void setFireAdId(Context context, AdsParamsFetchEvents callback) {
558-
BranchLogger.v("setFireAdId");
560+
BranchLogger.v("Begin setFireAdId");
559561
AdvertisingIdsKt.getAmazonFireAdvertisingInfoObject(context, new Continuation<Pair<? extends Integer, ? extends String>>() {
560562
@NonNull
561563
@Override
@@ -590,6 +592,7 @@ public void resumeWith(@NonNull Object o) {
590592
}
591593

592594
public void fetchInstallReferrer(Context context_, InstallReferrerFetchEvents callback) {
595+
BranchLogger.v("Begin fetchInstallReferrer");
593596
try {
594597
InstallReferrersKt.fetchLatestInstallReferrer(context_, new Continuation<InstallReferrerResult>() {
595598
@NonNull

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class TrackingController {
2525
}
2626

2727
void disableTracking(Context context, boolean disableTracking, @Nullable Branch.TrackingStateCallback callback) {
28+
BranchLogger.v("disableTracking context: " + context + " disableTracking: " + disableTracking + " callback: " + callback);
2829
// If the tracking state is already set to the desired state, then return instantly
2930
if (trackingDisabled == disableTracking) {
3031
if (callback != null) {
@@ -86,9 +87,10 @@ private void onTrackingDisabled(Context context) {
8687
}
8788

8889
private void onTrackingEnabled(Branch.BranchReferralInitListener callback) {
90+
BranchLogger.v("onTrackingEnabled callback: " + callback);
8991
Branch branch = Branch.getInstance();
9092
if (branch != null) {
91-
branch.registerAppInit(branch.getInstallOrOpenRequest(callback, true), true, false);
93+
branch.registerAppInit(branch.getInstallOrOpenRequest(callback, true), false);
9294
}
9395
}
9496
}

0 commit comments

Comments
 (0)