Skip to content

Commit ebe57b1

Browse files
committed
Add BranchConfigurationController to manage SDK configurations
- Introduced BranchConfigurationController class to handle delayed session initialization, test mode, and tracking settings. - Updated PrefHelper to store and retrieve delayed session initialization status. - Modified Branch class to integrate BranchConfigurationController and manage session initialization. - Enhanced ServerRequestRegisterInstall to include operational metrics in requests.
1 parent cae5a54 commit ebe57b1

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import static io.branch.referral.BranchUtil.isTestModeEnabled;
66
import static io.branch.referral.Defines.Jsonkey.EXTERNAL_BROWSER;
77
import static io.branch.referral.Defines.Jsonkey.IN_APP_WEBVIEW;
8-
import static io.branch.referral.PrefHelper.KEY_ENHANCED_WEB_LINK_UX_USED;
9-
import static io.branch.referral.PrefHelper.KEY_URL_LOAD_MS;
108
import static io.branch.referral.PrefHelper.isValidBranchKey;
119
import static io.branch.referral.util.DependencyUtilsKt.billingGooglePlayClass;
1210
import static io.branch.referral.util.DependencyUtilsKt.classExists;
@@ -230,6 +228,7 @@ public class Branch {
230228
private final Context context_;
231229

232230
private final BranchQRCodeCache branchQRCodeCache_;
231+
private final BranchConfigurationController branchConfigurationController_;
233232

234233
public final ServerRequestQueue requestQueue_;
235234

@@ -325,6 +324,7 @@ private Branch(@NonNull Context context) {
325324
deviceInfo_ = new DeviceInfo(context);
326325
branchPluginSupport_ = new BranchPluginSupport(context);
327326
branchQRCodeCache_ = new BranchQRCodeCache(context);
327+
branchConfigurationController_ = new BranchConfigurationController();
328328
requestQueue_ = ServerRequestQueue.getInstance(context);
329329
}
330330

@@ -511,6 +511,9 @@ public void disableAdNetworkCallouts(boolean disabled) {
511511
*/
512512
public static void expectDelayedSessionInitialization(boolean expectDelayedInit) {
513513
disableAutoSessionInitialization = expectDelayedInit;
514+
if (expectDelayedInit && Branch.getInstance() != null) {
515+
Branch.getInstance().branchConfigurationController_.setDelayedSessionInitUsed(true);
516+
}
514517
}
515518

516519
/**
@@ -1388,6 +1391,10 @@ public BranchQRCodeCache getBranchQRCodeCache() {
13881391
return branchQRCodeCache_;
13891392
}
13901393

1394+
public BranchConfigurationController getConfigurationController() {
1395+
return branchConfigurationController_;
1396+
}
1397+
13911398
PrefHelper getPrefHelper() {
13921399
return prefHelper_;
13931400
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package io.branch.referral
2+
3+
import org.json.JSONObject
4+
5+
/**
6+
* Controller class for managing Branch SDK configurations.
7+
* This class provides methods to control and track various configuration settings of the Branch SDK.
8+
* It is used internally by the Branch SDK to manage configuration states.
9+
*/
10+
class BranchConfigurationController {
11+
/**
12+
* Sets whether delayed session initialization was used.
13+
* This flag is used to track if the app has used delayed session initialization,
14+
* which is important for analytics and debugging purposes.
15+
*
16+
* @param used Boolean indicating if delayed session initialization was used
17+
* @see Branch.expectDelayedSessionInitialization
18+
*/
19+
fun setDelayedSessionInitUsed(used: Boolean) {
20+
Branch.getInstance().prefHelper_.delayedSessionInitUsed = used
21+
}
22+
23+
/**
24+
* Gets whether delayed session initialization was used.
25+
* This can be used to check if the app has previously used delayed session initialization.
26+
*
27+
* @return Boolean indicating if delayed session initialization was used
28+
* @see Branch.expectDelayedSessionInitialization
29+
*/
30+
private fun getDelayedSessionInitUsed(): Boolean {
31+
return Branch.getInstance().prefHelper_.delayedSessionInitUsed
32+
}
33+
34+
/**
35+
* Sets whether test mode is enabled.
36+
* This flag is used to track if the app is running in test mode.
37+
*/
38+
fun setTestModeEnabled(enabled: Boolean) {
39+
if (enabled) {
40+
Branch.enableTestMode()
41+
} else {
42+
Branch.disableTestMode()
43+
}
44+
}
45+
46+
/**
47+
* Gets whether test mode is enabled.
48+
*
49+
* @return Boolean indicating if test mode is enabled
50+
*/
51+
private fun isTestModeEnabled(): Boolean {
52+
return Branch.getInstance().prefHelper_.getBool("bnc_test_mode")
53+
}
54+
55+
/**
56+
* Sets whether tracking is disabled.
57+
* This flag is used to track if the app has disabled tracking.
58+
*/
59+
fun setTrackingDisabled(disabled: Boolean) {
60+
Branch.getInstance().prefHelper_.setBool("bnc_tracking_disabled", disabled)
61+
}
62+
63+
/**
64+
* Gets whether tracking is disabled.
65+
*
66+
* @return Boolean indicating if tracking is disabled
67+
*/
68+
fun isTrackingDisabled(): Boolean {
69+
return Branch.getInstance().prefHelper_.getBool("bnc_tracking_disabled")
70+
}
71+
72+
/**
73+
* Sets whether instant deep linking is enabled.
74+
* This flag is used to track if the app has enabled instant deep linking.
75+
*/
76+
fun setInstantDeepLinkingEnabled(enabled: Boolean) {
77+
Branch.getInstance().prefHelper_.setBool("bnc_instant_deep_linking_enabled", enabled)
78+
}
79+
80+
/**
81+
* Gets whether instant deep linking is enabled.
82+
*
83+
* @return Boolean indicating if instant deep linking is enabled
84+
*/
85+
private fun isInstantDeepLinkingEnabled(): Boolean {
86+
return Branch.getInstance().prefHelper_.getBool("bnc_instant_deep_linking_enabled")
87+
}
88+
89+
/**
90+
* Serializes the current configuration state into a JSONObject.
91+
* This is used to send configuration data to the server.
92+
*
93+
* @return JSONObject containing the current configuration state
94+
*/
95+
fun serializeConfiguration(): JSONObject {
96+
return JSONObject().apply {
97+
put("expectDelayedSessionInitialization", getDelayedSessionInitUsed())
98+
put("testMode", isTestModeEnabled())
99+
put("trackingDisabled", isTrackingDisabled())
100+
put("instantDeepLinkingEnabled", isInstantDeepLinkingEnabled())
101+
}
102+
}
103+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class PrefHelper {
123123
static final String KEY_INSTALL_BEGIN_SERVER_TS = "bnc_install_begin_server_ts";
124124
static final String KEY_TRACKING_STATE = "bnc_tracking_state";
125125
static final String KEY_AD_NETWORK_CALLOUTS_DISABLED = "bnc_ad_network_callouts_disabled";
126+
static final String KEY_DELAYED_SESSION_INIT_USED = "bnc_delayed_session_init_used";
126127

127128
static final String KEY_RANDOMLY_GENERATED_UUID = "bnc_randomly_generated_uuid";
128129

@@ -1485,4 +1486,29 @@ public String getWebLinkUxTypeUsed(){
14851486
public long getWebLinkLoadTime(){
14861487
return getLong(KEY_URL_LOAD_MS);
14871488
}
1489+
1490+
/**
1491+
* Sets whether delayed session initialization was used.
1492+
* This flag is used to track if the app has used delayed session initialization,
1493+
* which is important for analytics and debugging purposes.
1494+
* The value is stored in SharedPreferences and can be retrieved using {@link #getDelayedSessionInitUsed()}.
1495+
*
1496+
* @param used Boolean indicating if delayed session initialization was used
1497+
* @see Branch#expectDelayedSessionInitialization(boolean)
1498+
*/
1499+
public void setDelayedSessionInitUsed(boolean used) {
1500+
setBool(KEY_DELAYED_SESSION_INIT_USED, used);
1501+
}
1502+
1503+
/**
1504+
* Gets whether delayed session initialization was used.
1505+
* This can be used to check if the app has previously used delayed session initialization.
1506+
* The value is retrieved from SharedPreferences and is set using {@link #setDelayedSessionInitUsed(boolean)}.
1507+
*
1508+
* @return Boolean indicating if delayed session initialization was used
1509+
* @see Branch#expectDelayedSessionInitialization(boolean)
1510+
*/
1511+
public boolean getDelayedSessionInitUsed() {
1512+
return getBool(KEY_DELAYED_SESSION_INIT_USED);
1513+
}
14881514
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public void onPreExecute() {
6161
if(installReferrerServerTS > 0){
6262
getPost().put(Defines.Jsonkey.InstallBeginServerTimeStamp.getKey(), installReferrerServerTS);
6363
}
64+
65+
JSONObject configurations = Branch.getInstance().getConfigurationController().serializeConfiguration();
66+
getPost().put("operational_metrics", configurations);
6467
} catch (JSONException e) {
6568
BranchLogger.w("Caught JSONException " + e.getMessage());
6669
}

0 commit comments

Comments
 (0)