Skip to content

Commit b9921d7

Browse files
Expose private enableLogging signature (#1262)
Add additional logging
1 parent 5c8a283 commit b9921d7

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ private void readAndStripParam(Uri data, Activity activity) {
876876
boolean activityHasValidIntent = intentState_ == INTENT_STATE.READY ||
877877
!activityLifeCycleObserver.isCurrentActivityLaunchedFromStack();
878878

879+
BranchLogger.v("activityHasValidIntent: " + activityHasValidIntent);
880+
879881
// Skip IDL if intent contains an unused Branch link.
880882
boolean noUnusedBranchLinkInIntent = !isRestartSessionRequested(activity != null ? activity.getIntent() : null);
881883

@@ -1460,7 +1462,7 @@ private void initializeSession(ServerRequestInitSession initRequest, int delay)
14601462
* will wait on the wait locks to complete any pending operations
14611463
*/
14621464
void registerAppInit(@NonNull ServerRequestInitSession request, boolean forceBranchSession) {
1463-
BranchLogger.v("registerAppInit " + request);
1465+
BranchLogger.v("registerAppInit " + request + " forceBranchSession: " + forceBranchSession);
14641466
setInitState(SESSION_STATE.INITIALISING);
14651467

14661468
ServerRequestInitSession r = requestQueue_.getSelfInitRequest();
@@ -1471,7 +1473,7 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean forceBra
14711473
// if forceBranchSession aka reInit is true, we want to preserve the callback order in case
14721474
// there is one still in flight
14731475
if (r == null || forceBranchSession) {
1474-
BranchLogger.v("Moving " + request + " " + " to front of the queue or behind network-in-progress request");
1476+
BranchLogger.v("Moving " + request + " " + "to front of the queue or behind network-in-progress request");
14751477
requestQueue_.insertRequestAtFront(request);
14761478
}
14771479
else {
@@ -1930,7 +1932,7 @@ private boolean pathMatch(String templatePath, String path) {
19301932
* @param iBranchLogging Optional interface to receive logging from the SDK.
19311933
* @param level The minimum log level for logging output.
19321934
*/
1933-
private static void enableLogging(IBranchLoggingCallbacks iBranchLogging, BranchLogger.BranchLogLevel level) {
1935+
public static void enableLogging(IBranchLoggingCallbacks iBranchLogging, BranchLogger.BranchLogLevel level) {
19341936
BranchLogger.setLoggerCallback(iBranchLogging);
19351937
BranchLogger.setLoggingLevel(level);
19361938
BranchLogger.setLoggingEnabled(true);
@@ -2303,7 +2305,9 @@ private InitSessionBuilder(Activity activity) {
23032305
// currentActivityReference_ is set in onActivityCreated (before initSession), which should happen if
23042306
// users follow Android guidelines and call super.onStart as the first thing in Activity.onStart,
23052307
// however, if they don't, we try to set currentActivityReference_ here too.
2308+
BranchLogger.v("currentActivityReference_ was " + branch.currentActivityReference_);
23062309
branch.currentActivityReference_ = new WeakReference<>(activity);
2310+
BranchLogger.v("currentActivityReference_ is now set to " + branch.currentActivityReference_);
23072311
}
23082312
}
23092313

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class BranchActivityLifecycleObserver implements Application.ActivityLifecycleCa
2525

2626
@Override
2727
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
28-
BranchLogger.v("onActivityCreated, activity = " + activity);
2928
Branch branch = Branch.getInstance();
29+
BranchLogger.v("onActivityCreated, activity = " + activity + " branch: " + branch + " Activities on stack: " + activitiesOnStack_);
3030
if (branch == null) return;
3131

3232
branch.setIntentState(Branch.INTENT_STATE.PENDING);
3333
}
3434

3535
@Override
3636
public void onActivityStarted(@NonNull Activity activity) {
37-
BranchLogger.v("onActivityStarted, activity = " + activity);
3837
Branch branch = Branch.getInstance();
38+
BranchLogger.v("onActivityStarted, activity = " + activity + " branch: " + branch + " Activities on stack: " + activitiesOnStack_);
3939
if (branch == null) {
4040
return;
4141
}
@@ -50,13 +50,15 @@ public void onActivityStarted(@NonNull Activity activity) {
5050

5151
@Override
5252
public void onActivityResumed(@NonNull Activity activity) {
53-
BranchLogger.v("onActivityResumed, activity = " + activity);
5453
Branch branch = Branch.getInstance();
54+
BranchLogger.v("onActivityResumed, activity = " + activity + " branch: " + branch + " Activities on stack: " + activitiesOnStack_);
5555
if (branch == null) return;
5656

5757
// if the intent state is bypassed from the last activity as it was closed before onResume, we need to skip this with the current
5858
// activity also to make sure we do not override the intent data
59-
if (!Branch.bypassCurrentActivityIntentState()) {
59+
boolean bypassIntentState = Branch.bypassCurrentActivityIntentState();
60+
BranchLogger.v("bypassIntentState: " + bypassIntentState);
61+
if (!bypassIntentState) {
6062
branch.onIntentReady(activity);
6163
}
6264

@@ -78,8 +80,8 @@ public void onActivityResumed(@NonNull Activity activity) {
7880

7981
@Override
8082
public void onActivityPaused(@NonNull Activity activity) {
81-
BranchLogger.v("onActivityPaused, activity = " + activity);
8283
Branch branch = Branch.getInstance();
84+
BranchLogger.v("onActivityPaused, activity = " + activity + " branch: " + branch + " Activities on stack: " + activitiesOnStack_);
8385
if (branch == null) return;
8486

8587
/* Close any opened sharing dialog.*/
@@ -90,11 +92,12 @@ public void onActivityPaused(@NonNull Activity activity) {
9092

9193
@Override
9294
public void onActivityStopped(@NonNull Activity activity) {
93-
BranchLogger.v("onActivityStopped, activity = " + activity);
9495
Branch branch = Branch.getInstance();
96+
BranchLogger.v("onActivityStopped, activity = " + activity + " branch: " + branch);
9597
if (branch == null) return;
9698

9799
activityCnt_--; // Check if this is the last activity. If so, stop the session.
100+
BranchLogger.v("activityCnt_: " + activityCnt_);
98101
if (activityCnt_ < 1) {
99102
branch.setInstantDeepLinkPossible(false);
100103
branch.closeSessionInternal();
@@ -107,8 +110,8 @@ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bun
107110

108111
@Override
109112
public void onActivityDestroyed(@NonNull Activity activity) {
110-
BranchLogger.v("onActivityDestroyed, activity = " + activity);
111113
Branch branch = Branch.getInstance();
114+
BranchLogger.v("onActivityDestroyed, activity = " + activity + " branch: " + branch + " Activities on stack: " + activitiesOnStack_);
112115
if (branch == null) return;
113116

114117
if (branch.getCurrentActivity() == activity) {
@@ -124,6 +127,9 @@ boolean isCurrentActivityLaunchedFromStack() {
124127
// don't think this is possible
125128
return false;
126129
}
130+
131+
BranchLogger.v("activitiesOnStack_: " + activitiesOnStack_ + " Current Activity: " + branch.getCurrentActivity());
132+
127133
return activitiesOnStack_.contains(branch.getCurrentActivity().toString());
128134
}
129135
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ public int getSize() {
108108
*/
109109
void enqueue(ServerRequest request) {
110110
synchronized (reqQueueLockObject) {
111+
BranchLogger.v("Queue operation enqueue. Request: " + request);
111112
if (request != null) {
112113
queue.add(request);
113114
if (getSize() >= MAX_ITEMS) {
115+
BranchLogger.v("Queue maxed out. Removing index 1.");
114116
queue.remove(1);
115117
}
116118
}
@@ -163,6 +165,7 @@ ServerRequest peekAt(int index) {
163165
synchronized (reqQueueLockObject) {
164166
try {
165167
req = queue.get(index);
168+
BranchLogger.v("Queue operation peekAt " + req);
166169
} catch (IndexOutOfBoundsException | NoSuchElementException e) {
167170
BranchLogger.e("Caught Exception ServerRequestQueue peekAt " + index + ": " + e.getMessage());
168171
}
@@ -182,6 +185,7 @@ ServerRequest peekAt(int index) {
182185
void insert(ServerRequest request, int index) {
183186
synchronized (reqQueueLockObject) {
184187
try {
188+
BranchLogger.v("Queue operation insert. Request: " + request + " Size: " + queue.size() + " Index: " + index);
185189
if (queue.size() < index) {
186190
index = queue.size();
187191
}
@@ -213,7 +217,7 @@ public ServerRequest removeAt(int index) {
213217
}
214218
return req;
215219
}
216-
220+
217221
/**
218222
* <p>As the method name implies, removes {@link ServerRequest} supplied in the parameter if it
219223
* is present in the queue.</p>
@@ -225,7 +229,9 @@ public boolean remove(ServerRequest request) {
225229
boolean isRemoved = false;
226230
synchronized (reqQueueLockObject) {
227231
try {
232+
BranchLogger.v("Queue operation remove. Request: " + request);
228233
isRemoved = queue.remove(request);
234+
BranchLogger.v("Queue operation remove. Removed: " + isRemoved);
229235
} catch (UnsupportedOperationException e) {
230236
BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage());
231237
}
@@ -239,7 +245,9 @@ public boolean remove(ServerRequest request) {
239245
void clear() {
240246
synchronized (reqQueueLockObject) {
241247
try {
248+
BranchLogger.v("Queue operation clear");
242249
queue.clear();
250+
BranchLogger.v("Queue cleared.");
243251
} catch (UnsupportedOperationException e) {
244252
BranchLogger.e("Caught UnsupportedOperationException " + e.getMessage());
245253
}
@@ -259,6 +267,7 @@ ServerRequestInitSession getSelfInitRequest() {
259267
BranchLogger.v("Checking if " + req + " is instanceof ServerRequestInitSession");
260268
if (req instanceof ServerRequestInitSession) {
261269
ServerRequestInitSession r = (ServerRequestInitSession) req;
270+
BranchLogger.v(r + " is initiated by client: " + r.initiatedByClient);
262271
if (r.initiatedByClient) {
263272
return r;
264273
}
@@ -324,11 +333,13 @@ void processNextQueueItem(String callingMethodName) {
324333
if (!(req instanceof ServerRequestRegisterInstall) && !hasUser()) {
325334
BranchLogger.d("Branch Error: User session has not been initialized!");
326335
networkCount_ = 0;
336+
BranchLogger.v("Invoking " + req + " handleFailure. Has no session. hasUser: " + hasUser());
327337
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
328338
}
329339
// Determine if a session is needed to execute (SDK-271)
330340
else if (requestNeedsSession(req) && !isSessionAvailableForRequest()) {
331341
networkCount_ = 0;
342+
BranchLogger.v("Invoking " + req + " handleFailure. Has no session.");
332343
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
333344
} else {
334345
executeTimedBranchPostTask(req, Branch.getInstance().prefHelper_.getTaskTimeout());
@@ -351,7 +362,7 @@ else if (requestNeedsSession(req) && !isSessionAvailableForRequest()) {
351362
}
352363

353364
void insertRequestAtFront(ServerRequest req) {
354-
BranchLogger.v("insertRequestAtFront " + req + " networkCount_: " + networkCount_);
365+
BranchLogger.v("Queue operation insertRequestAtFront " + req + " networkCount_: " + networkCount_);
355366
if (networkCount_ == 0) {
356367
this.insert(req, 0);
357368
} else {
@@ -393,6 +404,7 @@ void updateAllRequestsInQueue() {
393404
try {
394405
for (int i = 0; i < this.getSize(); i++) {
395406
ServerRequest req = this.peekAt(i);
407+
BranchLogger.v("Queue operation updateAllRequestsInQueue updating: " + req);
396408
if (req != null) {
397409
JSONObject reqJson = req.getPost();
398410
if (reqJson != null) {

0 commit comments

Comments
 (0)