Skip to content

Commit

Permalink
[SDK-2444] Support for setting FB App ID through branch.json (#1198)
Browse files Browse the repository at this point in the history
* Support for setting FB App ID through branch.json

* Fixed lines
  • Loading branch information
nsingh-branch authored Jun 7, 2024
1 parent c4981d0 commit b2fd74d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
16 changes: 14 additions & 2 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ synchronized public static Branch getAutoInstance(@NonNull Context context) {

BranchUtil.setAPIBaseUrlFromConfig(context);

BranchUtil.setFbAppIdFromConfig(context);

BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
branchReferral_ = initBranchSDK(context, BranchUtil.readBranchKey(context));
getPreinstallSystemData(branchReferral_, context);
Expand Down Expand Up @@ -407,7 +409,7 @@ public static Branch getAutoInstance(@NonNull Context context, @NonNull String b
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));

BranchUtil.setAPIBaseUrlFromConfig(context);

BranchUtil.setFbAppIdFromConfig(context);
BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
// If a Branch key is passed already use it. Else read the key
if (!isValidBranchKey(branchKey)) {
Expand Down Expand Up @@ -2561,7 +2563,17 @@ public static void useEUEndpoint() {
PrefHelper.useEUEndpoint(true);
}

/**
* Sets the Facebook App ID for the Branch instance.
*
* @param fbAppID The Facebook App ID as a {@link String}.
*/
public static void setFBAppID(String fbAppID) {
PrefHelper.fbAppId_ = fbAppID;
if (!TextUtils.isEmpty(fbAppID)) {
PrefHelper.fbAppId_ = fbAppID;
BranchLogger.v("setFBAppID to " + fbAppID);
} else {
BranchLogger.w("setFBAppID: fbAppID cannot be empty or null");
}
}
}
25 changes: 23 additions & 2 deletions Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public enum BranchJsonKey {
useTestInstance,
enableLogging,
deferInitForPluginRuntime,
apiUrl
apiUrl,
fbAppId
}

/*
Expand All @@ -46,7 +47,8 @@ public enum BranchJsonKey {
"useTestInstance": true,
"enableLogging": true,
"deferInitForPluginRuntime": true,
"apiUrl": "https://api2.branch.io"
"apiUrl": "https://api2.branch.io",
"fbAppId": "xyz123456789"
}
*/

Expand Down Expand Up @@ -202,4 +204,23 @@ public String getAPIUrl() {
return null;
}
}

@Nullable
public String getFbAppId() {
if (mConfiguration == null) {
return null;
}

try {
if (!mConfiguration.has(BranchJsonKey.fbAppId.toString())) {
return null;
}

return mConfiguration.getString(BranchJsonKey.fbAppId.toString());
}
catch (JSONException exception) {
Log.e(TAG, "Error parsing branch.json: " + exception.getMessage());
return null;
}
}
}
12 changes: 11 additions & 1 deletion Branch-SDK/src/main/java/io/branch/referral/BranchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,17 @@ public static boolean getDeferInitForPluginRuntimeConfig(Context context){
public static void setAPIBaseUrlFromConfig(Context context) {
BranchJsonConfig jsonConfig = BranchJsonConfig.getInstance(context);
String apiUrl = jsonConfig.getAPIUrl();
Branch.setAPIUrl(apiUrl);
if (!TextUtils.isEmpty(apiUrl)) {
Branch.setAPIUrl(apiUrl);
}
}

public static void setFbAppIdFromConfig(Context context) {
BranchJsonConfig jsonConfig = BranchJsonConfig.getInstance(context);
String fbAppId = jsonConfig.getFbAppId();
if (!TextUtils.isEmpty(fbAppId)) {
Branch.setFBAppID(fbAppId);
}
}

/**
Expand Down

0 comments on commit b2fd74d

Please sign in to comment.