Skip to content

Commit

Permalink
Revert "Merge branch 'master' into Release-5.7.2"
Browse files Browse the repository at this point in the history
This reverts commit 4c819c5, reversing
changes made to 760e695.
  • Loading branch information
nsingh-branch committed Oct 20, 2023
1 parent 4c819c5 commit cddc84b
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 145 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/unit-and-instrumented-tests-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
with:
name: unit-test-api-level-$API_MIN
path: ./Branch-SDK/build/

instrumented-test-api-level-min:
name: instrumented-test-api-level-$API_MIN
runs-on: macos-latest
Expand Down Expand Up @@ -67,44 +66,6 @@ jobs:
with:
name: instrumented-test-api-level-$API_MIN
path: ./Branch-SDK/build/

jacoco-test-coverage-api-level-min:
name: jacoco-test-coverage-api-level-$API_MIN
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
needs: [unit-test-api-level-min, instrumented-test-api-level-min]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# create an emulator with google apis, runs on java 8
- name: Create Android emulator
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-"$API_MIN";google_apis;x86_64"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager --verbose create avd --force --name test --package "system-images;android-"$API_MIN";google_apis;x86_64"
# boots and waits for the emulator to be ready
- name: Launch Emulator
run: |
echo "Starting emulator and waiting for boot to complete."
nohup $ANDROID_HOME/tools/emulator -avd test -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do echo "waiting..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
# repo's gradle is configured to run on java 17
- name: Setup java 17 for gradle
uses: actions/setup-java@v3
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Run Coverage
run: |
./gradlew :Branch-SDK:jacocoTestReport --info
- name: Upload Coverage Test Report
if: success()
uses: codecov/codecov-action@v3
with:
file: ./Branch-SDK/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
fail_ci_if_error: true

unit-test-api-level-current:
name: unit-test-api-level-$API_CURRENT
runs-on: macos-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -25,7 +26,6 @@ protected void onCreate(Bundle savedInstanceState) {
setupDisableAdNetworkCalloutsSwitch();
setupPrepHelperView();
setupRetryEditText();
setupApiUrlText();
}

void setupRetryEditText() {
Expand All @@ -35,40 +35,21 @@ void setupRetryEditText() {

retryEditText.setText(Integer.toString(currentRetries));

retryEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
int retries = Integer.parseInt(textView.getText().toString());
PrefHelper.getInstance(SettingsActivity.this).setRetryCount(retries);

InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(retryEditText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set Network Retries to " + retries, Toast.LENGTH_SHORT).show();
return true;
}
return false;
});
}

void setupApiUrlText() {
final EditText apiUrlText = findViewById(R.id.api_url_text);
final PrefHelper prefHelper = PrefHelper.getInstance(this);
String currentApiUrl = prefHelper.getAPIBaseUrl();

apiUrlText.setText(currentApiUrl);

apiUrlText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
String newApiUrl = textView.getText().toString();
Branch.getInstance().setAPIUrl(newApiUrl);

InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(apiUrlText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set API Base URL to " + newApiUrl, Toast.LENGTH_SHORT).show();
return true;
retryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
int retries = Integer.valueOf(textView.getText().toString());
PrefHelper.getInstance(SettingsActivity.this).setRetryCount(retries);

InputMethodManager imm = (InputMethodManager)getSystemService(SettingsActivity.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(retryEditText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set Network Retries to " + retries, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
return false;
});
}

Expand Down
22 changes: 0 additions & 22 deletions Branch-SDK-TestBed/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,6 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/testbed_text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="API Base URL" />

<EditText
android:id="@+id/api_url_text"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="text"
android:maxLines="1"
android:hint="api2.branch.io" />

</LinearLayout>

<TextView
android:id="@+id/prefhelper_text_view"
style="@style/testbed_text_view"
Expand Down
30 changes: 0 additions & 30 deletions Branch-SDK/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ plugins {
`maven-publish`
signing
id("org.gradle.test-retry") version "1.5.3"
id("jacoco")
}
val coroutinesVersion = "1.6.4"
jacoco {
toolVersion = "0.8.10"
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to "*.jar")))
Expand Down Expand Up @@ -96,7 +92,6 @@ android {

debug {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
buildConfigField("long", "VERSION_CODE", VERSION_CODE)
buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes())
}
Expand Down Expand Up @@ -279,30 +274,5 @@ tasks {
retry {
maxRetries.set(3)
}
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
}

tasks.create<JacocoReport>("jacocoTestReport") {
group = "Reporting"
description = "Generate Jacoco code coverage reports after running tests."
dependsOn("testDebugUnitTest","createDebugCoverageReport")
reports {
xml.required.set(true)
html.required.set(true)
}
sourceDirectories.setFrom("${project.projectDir}/src/main/java")
classDirectories.setFrom("${project.buildDir}/intermediates/javac/debug/classes")
executionData.setFrom(
fileTree(project.buildDir) {
include(
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec",
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ public void testGetAPIBaseUrl() {

@Test
public void testSetAPIUrl_Example() {
prefHelper.setAPIUrl("https://www.example.com/");
PrefHelper.setAPIUrl("https://www.example.com/");
String actual = prefHelper.getAPIBaseUrl();
Assert.assertEquals("https://www.example.com/", actual);
}

@Test
public void testSetAPIUrl_InvalidHttp() {
prefHelper.setAPIUrl("http://www.example.com/");
PrefHelper.setAPIUrl("http://www.example.com/");
assertDefaultURL();
}

@Test
public void testSetAPIUrl_InvalidNull() {
prefHelper.setAPIUrl(null);
PrefHelper.setAPIUrl(null);
assertDefaultURL();
}

@Test
public void testSetAPIUrl_InvalidEmpty() {
prefHelper.setAPIUrl("");
PrefHelper.setAPIUrl("");
assertDefaultURL();
}

Expand Down
17 changes: 6 additions & 11 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,10 @@ public static void expectDelayedSessionInitialization(boolean expectDelayedInit)
* <p>Sets a custom base URL for all calls to the Branch API. Requires https.</p>
* @param url The {@link String} URL base URL that the Branch API uses.
*/
public void setAPIUrl(String url) {
if (prefHelper_ != null && url.length() > 0) {
prefHelper_.setAPIUrl(url);
}
public static void setAPIUrl(String url) {
PrefHelper.setAPIUrl(url);
}

/**
* <p>Sets a custom CDN base URL.</p>
* @param url The {@link String} base URL for CDN endpoints.
Expand Down Expand Up @@ -1025,13 +1024,9 @@ public void logout() {
* @param callback An instance of {@link io.branch.referral.Branch.LogoutStatusListener} to callback with the logout operation status.
*/
public void logout(LogoutStatusListener callback) {
prefHelper_.setIdentity(PrefHelper.NO_STRING_VALUE);
prefHelper_.clearUserValues();
//On Logout clear the link cache and all pending requests
linkCache_.clear();
requestQueue_.clear();
if (callback != null) {
callback.onLogoutFinished(true, null);
ServerRequest req = new ServerRequestLogout(context_, callback);
if (!req.constructError_ && !req.handleErrors(context_)) {
requestQueue_.handleNewRequest(req);
}
}

Expand Down
1 change: 1 addition & 0 deletions Branch-SDK/src/main/java/io/branch/referral/Defines.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public enum RequestPath {
RegisterInstall("v1/install"),
RegisterOpen("v1/open"),
IdentifyUser("v1/profile"),
Logout("v1/logout"),
ContentEvent("v1/content-events"),
TrackStandardEvent("v2/event/standard"),
TrackCustomEvent("v2/event/custom"),
Expand Down
15 changes: 10 additions & 5 deletions Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public class PrefHelper {

static final String KEY_REFERRING_URL_QUERY_PARAMETERS = "bnc_referringUrlQueryParameters";
static final String KEY_ANON_ID = "bnc_anon_id";
private static final String KEY_BASE_URL = "bnc_base_url";

/**
* Internal static variable of own type {@link PrefHelper}. This variable holds the single
Expand Down Expand Up @@ -157,6 +156,11 @@ public class PrefHelper {
*/
private final JSONObject secondaryRequestMetadata = new JSONObject();

/**
* Branch Custom server url. Used by clients that want to proxy all requests.
*/
private static String customServerURL_ = null;

/**
* Branch Custom server url. Used by clients that want to proxy all CDN requests.
*/
Expand Down Expand Up @@ -203,15 +207,16 @@ static void shutDown() {
// Reset all of the statics.
enableLogging_ = false;
prefHelper_ = null;
customServerURL_ = null;
customCDNBaseURL_ = null;
}

/**
* <p>Sets a custom base URL for all calls to the Branch API. Requires https.</p>
* @param url The {@link String} URL base URL that the Branch API uses.
*/
public void setAPIUrl(String url) {
setString(KEY_BASE_URL, url);
static void setAPIUrl(String url) {
customServerURL_ = url;
}

/**
Expand All @@ -222,8 +227,8 @@ public void setAPIUrl(String url) {
* API uses.
*/
public String getAPIBaseUrl() {
if (URLUtil.isHttpsUrl(getString(KEY_BASE_URL))) {
return getString(KEY_BASE_URL);
if (URLUtil.isHttpsUrl(customServerURL_)) {
return customServerURL_;
}

if (Build.VERSION.SDK_INT >= 20) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ private static ServerRequest getExtendedServerRequest(String requestPath, JSONOb
extendedReq = new ServerRequestCreateUrl(Defines.RequestPath.GetURL, post, context);
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.IdentifyUser.getPath())) {
extendedReq = new ServerRequestIdentifyUserRequest(Defines.RequestPath.IdentifyUser, post, context);
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.Logout.getPath())) {
extendedReq = new ServerRequestLogout(Defines.RequestPath.Logout, post, context);
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterInstall.getPath())) {
extendedReq = new ServerRequestRegisterInstall(Defines.RequestPath.RegisterInstall, post, context, initiatedByClient);
} else if (requestPath.equalsIgnoreCase(Defines.RequestPath.RegisterOpen.getPath())) {
Expand Down
Loading

0 comments on commit cddc84b

Please sign in to comment.