Skip to content

Commit 7babb5a

Browse files
committed
Enhance plugin runtime initialization handling
- Updated Branch class to ensure proper handling of deferred initialization for plugin runtime. - Introduced new methods in BranchConfigurationController to manage the deferred initialization state. - Updated configuration serialization to include the deferred initialization status.
1 parent 7c9ebb6 commit 7babb5a

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,10 @@ static void deferInitForPluginRuntime(boolean isDeferred){
25812581

25822582
deferInitForPluginRuntime = isDeferred;
25832583
if(isDeferred){
2584-
expectDelayedSessionInitialization(isDeferred);
2584+
expectDelayedSessionInitialization(true);
2585+
if (Branch.getInstance() != null) {
2586+
Branch.getInstance().branchConfigurationController_.setDeferInitForPluginRuntime(true);
2587+
}
25852588
}
25862589
}
25872590

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@ class BranchConfigurationController {
3939
* @return Boolean indicating if test mode is enabled
4040
*/
4141
private fun isTestModeEnabled(): Boolean {
42-
return Branch.getInstance()?.prefHelper_?.getBool(PrefHelper.KEY_TEST_MODE) ?: false
43-
}
44-
45-
/**
46-
* Sets whether tracking is disabled.
47-
* This flag is used to track if the app has disabled tracking.
48-
*/
49-
fun setTrackingDisabled(disabled: Boolean) {
50-
Branch.getInstance().prefHelper_.setBool("bnc_tracking_disabled", disabled)
42+
return BranchUtil.isTestModeEnabled()
5143
}
5244

5345
/**
@@ -68,6 +60,26 @@ class BranchConfigurationController {
6860
return Branch.getInstance().prefHelper_.getBool("bnc_instant_deep_linking_enabled")
6961
}
7062

63+
/**
64+
* Sets whether plugin runtime initialization should be deferred.
65+
* This is used for cross-process communication scenarios like React Native,
66+
* where we need to wait for the plugin to signal when it's ready before initializing.
67+
*
68+
* @param deferred Boolean indicating if plugin runtime initialization should be deferred
69+
*/
70+
fun setDeferInitForPluginRuntime(deferred: Boolean) {
71+
Branch.getInstance()?.prefHelper_?.setBool("bnc_defer_init_for_plugin_runtime", deferred)
72+
}
73+
74+
/**
75+
* Gets whether plugin runtime initialization is deferred.
76+
*
77+
* @return Boolean indicating if plugin runtime initialization is deferred
78+
*/
79+
private fun isDeferInitForPluginRuntime(): Boolean {
80+
return Branch.getInstance().prefHelper_.getBool("bnc_defer_init_for_plugin_runtime")
81+
}
82+
7183
/**
7284
* Serializes the current configuration state into a JSONObject.
7385
* This is used to send configuration data to the server.
@@ -77,13 +89,14 @@ class BranchConfigurationController {
7789
fun serializeConfiguration(): JSONObject {
7890
return try {
7991
JSONObject().apply {
80-
put(\"expectDelayedSessionInitialization\", getDelayedSessionInitUsed())
81-
put(\"testMode\", isTestModeEnabled())
82-
put(\"trackingDisabled\", isTrackingDisabled())
83-
put(\"instantDeepLinkingEnabled\", isInstantDeepLinkingEnabled())
92+
put("expectDelayedSessionInitialization", getDelayedSessionInitUsed())
93+
put("testMode", isTestModeEnabled())
94+
put("trackingDisabled", isTrackingDisabled())
95+
put("instantDeepLinkingEnabled", isInstantDeepLinkingEnabled())
96+
put("deferInitForPluginRuntime", isDeferInitForPluginRuntime())
8497
}
8598
} catch (e: Exception) {
86-
BranchLogger.w(\"Error serializing configuration: ${e.message}\")
99+
BranchLogger.w("Error serializing configuration: ${e.message}")
87100
JSONObject()
88101
}
89102
}

0 commit comments

Comments
 (0)