android-branch-deep-linking-attribution
android-branch-deep-linking-attribution copied to clipboard
The useTestInstance key from branch.json file always overrides programmatically set test mode
trafficstars
As per the doc in BranchUtil.java, it says that
// setting isTestModeEnabled_ programmatically overrides both manifest and branch.json configurations.
But during the branch initialization while reading the branch key
public static String readBranchKey(Context context) {
String branchKey = null;
// branch.json overrides manifest or string resources configurations
BranchJsonConfig jsonConfig = BranchJsonConfig.getInstance(context);
if (jsonConfig.isValid()) branchKey = jsonConfig.getBranchKey();
if (branchKey != null) return branchKey;
String metaDataKey = isTestModeEnabled() ? "io.branch.sdk.BranchKey.test" : "io.branch.sdk.BranchKey";
// manifest overrides string resources
try {
final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
if (ai.metaData != null) {
branchKey = ai.metaData.getString(metaDataKey);
if (branchKey == null && isTestModeEnabled()) {
// If test mode is enabled, but the test key cannot be found, fall back to the live key.
branchKey = ai.metaData.getString("io.branch.sdk.BranchKey");
}
}
} catch (final PackageManager.NameNotFoundException ignore) { }
if (branchKey != null) return branchKey;
// check string resources as the last resort
Resources resources = context.getResources();
branchKey = resources.getString(resources.getIdentifier(metaDataKey, "string", context.getPackageName()));
return branchKey;
}
Here we can see that branch key is returned based on useTestInstance key from branch.json file itself. It is not considering the programmatically set test mode value.
The code for reading the branch key contradicts the statement provided on the top.(setting isTestModeEnabled_ programmatically overrides both manifest and branch.json configurations) Please clarify as we are trying to change test mode while using branch.json file and we are unable to achieve it.