Skip to content

Commit 9817339

Browse files
committed
Refactor test mode and tracking management in Branch SDK
- Updated enableTestMode and disableTestMode methods in Branch class to utilize BranchConfigurationController for better encapsulation. - Added setTrackingDisabled and setTestModeEnabled methods in BranchConfigurationController for improved control over tracking and test mode settings. - Enhanced null safety checks in tracking management methods.
1 parent c71b98d commit 9817339

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ public BranchRemoteInterface getBranchRemoteInterface() {
467467
* </p>
468468
*/
469469
public static void enableTestMode() {
470-
BranchUtil.setTestMode(true);
470+
if (Branch.getInstance() != null) {
471+
Branch.getInstance().branchConfigurationController_.setTestModeEnabled(true);
472+
} else {
473+
BranchUtil.setTestMode(true);
474+
}
471475
BranchLogger.logAlways("enableTestMode has been changed. It now uses the test key but will not" +
472476
" log or randomize the device IDs. If you wish to enable logging, please invoke enableLogging." +
473477
" If you wish to simulate installs, please see add a Test Device (https://help.branch.io/using-branch/docs/adding-test-devices)" +
@@ -480,7 +484,11 @@ public static void enableTestMode() {
480484
* </p>
481485
*/
482486
public static void disableTestMode() {
483-
BranchUtil.setTestMode(false);
487+
if (Branch.getInstance() != null) {
488+
Branch.getInstance().branchConfigurationController_.setTestModeEnabled(false);
489+
} else {
490+
BranchUtil.setTestMode(false);
491+
}
484492
}
485493

486494
/**
@@ -554,6 +562,9 @@ public static void setCDNBaseUrl(String url) {
554562
* with {@link Defines.BranchAttributionLevel#NONE} instead to disable tracking.
555563
* */
556564
@Deprecated public void disableTracking(boolean disableTracking, @Nullable TrackingStateCallback callback) {
565+
if (branchConfigurationController_ != null) {
566+
branchConfigurationController_.setTrackingDisabled(disableTracking);
567+
}
557568
trackingController.disableTracking(context_, disableTracking, callback);
558569
}
559570

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BranchConfigurationController {
3838
*
3939
* @return Boolean indicating if test mode is enabled
4040
*/
41-
private fun isTestModeEnabled(): Boolean {
41+
fun isTestModeEnabled(): Boolean {
4242
return BranchUtil.isTestModeEnabled()
4343
}
4444

@@ -48,7 +48,29 @@ class BranchConfigurationController {
4848
* @return Boolean indicating if tracking is disabled
4949
*/
5050
fun isTrackingDisabled(): Boolean {
51-
return Branch.getInstance().prefHelper_.getBool("bnc_tracking_disabled")
51+
return Branch.getInstance()?.prefHelper_?.getBool("bnc_tracking_disabled") ?: false
52+
}
53+
54+
/**
55+
* Sets whether tracking should be disabled.
56+
* When tracking is disabled, the SDK will not track any user data or state,
57+
* and it will not initiate any network calls except for deep linking operations.
58+
*
59+
* @param disabled Boolean indicating if tracking should be disabled
60+
*/
61+
fun setTrackingDisabled(disabled: Boolean) {
62+
Branch.getInstance()?.prefHelper_?.setBool("bnc_tracking_disabled", disabled)
63+
}
64+
65+
/**
66+
* Sets whether test mode should be enabled.
67+
* When test mode is enabled, the SDK will use test keys and endpoints.
68+
* This is useful for development and testing purposes.
69+
*
70+
* @param enabled Boolean indicating if test mode should be enabled
71+
*/
72+
fun setTestModeEnabled(enabled: Boolean) {
73+
BranchUtil.setTestMode(enabled)
5274
}
5375

5476
/**

0 commit comments

Comments
 (0)