Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2329] Added apiUrl check in BranchJSONConfig #1183

Merged
merged 11 commits into from
Apr 1, 2024
3 changes: 3 additions & 0 deletions Branch-SDK-TestBed/src/main/assets/branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ protected void onStart() {
Branch.getInstance().addFacebookPartnerParameterWithName("ph", getHashedValue("6516006060"));
Log.d("BranchSDK_Tester", "initSession");

initSessionsWithTests();
//initSessionsWithTests();

// Branch integration validation: Validate Branch integration with your app
// NOTE : The below method will run few checks for verifying correctness of the Branch integration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void setupApiUrlText() {
apiUrlText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
String newApiUrl = textView.getText().toString();
Branch.setAPIUrl(newApiUrl);
Branch.setAPIUrl("https://myapi.com/");

InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(apiUrlText.getWindowToken(), 0);
Expand Down
5 changes: 5 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@
// Should only be set in json config
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));

BranchUtil.setAPIBaseUrlFromConfig(context);

BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
branchReferral_ = initBranchSDK(context, BranchUtil.readBranchKey(context));
getPreinstallSystemData(branchReferral_, context);
Expand Down Expand Up @@ -404,6 +406,8 @@
// Should only be set in json config
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));

BranchUtil.setAPIBaseUrlFromConfig(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 @@ -504,6 +508,7 @@
*/
public static void setAPIUrl(String url) {
PrefHelper.setAPIUrl(url);
BranchLogger.v("setAPIUrl: Branch API URL was set to " + url);

Check warning on line 511 in Branch-SDK/src/main/java/io/branch/referral/Branch.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L511 was not covered by tests
}
/**
* <p>Sets a custom CDN base URL.</p>
Expand Down
20 changes: 18 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 @@ -29,7 +29,8 @@
liveKey,
useTestInstance,
enableLogging,
deferInitForPluginRuntime
deferInitForPluginRuntime,
apiUrl
}

/*
Expand All @@ -44,7 +45,8 @@
"liveKey":"key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB",
"useTestInstance": true,
"enableLogging": true,
"deferInitForPluginRuntime": true
"deferInitForPluginRuntime": true,
"apiUrl": "https://api.branch.io"
}
*/

Expand Down Expand Up @@ -186,4 +188,18 @@
return false;
}
}

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

try {
if (!mConfiguration.has("apiUrl")) return null;
return mConfiguration.getString("apiUrl");

Check warning on line 198 in Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java#L198

Added line #L198 was not covered by tests
}
catch (JSONException exception) {
Log.e(TAG, "Error parsing branch.json: " + exception.getMessage());
return null;

Check warning on line 202 in Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/BranchJsonConfig.java#L200-L202

Added lines #L200 - L202 were not covered by tests
}
}
}
9 changes: 9 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/BranchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

import android.text.TextUtils;
import android.util.DisplayMetrics;

import org.json.JSONArray;
Expand Down Expand Up @@ -139,6 +140,14 @@
return deferInitForPluginRuntime;
}

public static void setAPIBaseUrlFromConfig(Context context) {
BranchJsonConfig jsonConfig = BranchJsonConfig.getInstance(context);
String apiUrl = jsonConfig.getAPIUrl();
if (!TextUtils.isEmpty(apiUrl)) {
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
Branch.setAPIUrl(apiUrl + "/");

Check warning on line 147 in Branch-SDK/src/main/java/io/branch/referral/BranchUtil.java

View check run for this annotation

Codecov / codecov/patch

Branch-SDK/src/main/java/io/branch/referral/BranchUtil.java#L147

Added line #L147 was not covered by tests
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Get the value of "io.branch.sdk.TestMode" entry in application manifest or from String res.
* This value can be overridden via. {@link Branch#enableTestMode()}
Expand Down
Loading