Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nch-deep-linking-attribution into gdeluna-branch/SDK-2025
  • Loading branch information
gdeluna-branch committed Jul 28, 2023
2 parents 0dd0b08 + 79ed736 commit 0dce5a4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 60 deletions.
3 changes: 1 addition & 2 deletions Branch-SDK-TestBed/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ plugins {
dependencies {
implementation(project(":Branch-SDK"))
implementation("com.google.android.gms:play-services-ads-identifier:18.0.1")

implementation("com.android.billingclient:billing:5.1.0")
implementation("com.android.billingclient:billing:6.0.1")

androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test:runner:1.5.2")
Expand Down
4 changes: 3 additions & 1 deletion Branch-SDK/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ dependencies {
implementation("androidx.annotation:annotation:1.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("com.android.installreferrer:installreferrer:2.2")
implementation("com.android.billingclient:billing:5.1.0")

// --- optional dependencies -----
//Please note that the Branch SDK does not require any of the below optional dependencies to operate. This dependency is listed here so there will not be build errors,
// but the library is *not* added to your app unless you do so yourself. Please check the code in gradle-mvn-push script to see how this works

compileOnly("com.google.android.gms:play-services-ads-identifier:18.0.1")
compileOnly("com.huawei.hms:ads-installreferrer:3.4.39.302")
compileOnly("com.android.billingclient:billing:6.0.1")

androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("org.skyscreamer:jsonassert:1.5.0")
androidTestImplementation("com.google.android.gms:play-services-ads-identifier:18.0.1")
androidTestImplementation("com.android.billingclient:billing:6.0.1")


testImplementation("junit:junit:4.13.2")
testImplementation("org.json:json:20230227")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void run() {
}

@Test
public void test00GetShortUrlSyncFailure() {
public void test00GetShortUrlSync() {
String url = new BranchShortLinkBuilder(getTestContext()).getShortUrl();
Assert.assertNull(url);
Assert.assertNotNull(url);
}

@Test
Expand Down
92 changes: 38 additions & 54 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import static io.branch.referral.BranchPreinstall.getPreinstallSystemData;
import static io.branch.referral.BranchUtil.isTestModeEnabled;
import static io.branch.referral.PrefHelper.isValidBranchKey;
import static io.branch.referral.util.DependencyUtilsKt.billingGooglePlayClass;
import static io.branch.referral.util.DependencyUtilsKt.classExists;
import static io.branch.referral.util.DependencyUtilsKt.galaxyStoreInstallReferrerClass;
import static io.branch.referral.util.DependencyUtilsKt.huaweiInstallReferrerClass;
import static io.branch.referral.util.DependencyUtilsKt.xiaomiInstallReferrerClass;

import android.app.Activity;
import android.app.Application;
Expand All @@ -14,25 +19,19 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;

import com.android.billingclient.api.Purchase;

import io.branch.referral.Defines.PreinstallKey;
import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -41,7 +40,6 @@
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -54,6 +52,8 @@
import java.util.concurrent.TimeoutException;

import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Defines.PreinstallKey;
import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
import io.branch.referral.network.BranchRemoteInterface;
import io.branch.referral.network.BranchRemoteInterfaceUrlConnection;
import io.branch.referral.util.BRANCH_STANDARD_EVENT;
Expand Down Expand Up @@ -1462,35 +1462,27 @@ public void cancelShareLinkDialog(boolean animateClose) {
// PRIVATE FUNCTIONS

private String generateShortLinkSync(ServerRequestCreateUrl req) {
if (trackingController.isTrackingDisabled()) {
return req.getLongUrl();
ServerResponse response = null;
try {
int timeOut = prefHelper_.getTimeout() + 2000; // Time out is set to slightly more than link creation time to prevent any edge case
response = new GetShortLinkTask().execute(req).get(timeOut, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignore) {
}
if (initState_ == SESSION_STATE.INITIALISED) {
ServerResponse response = null;
String url = null;
if (req.isDefaultToLongUrl()) {
url = req.getLongUrl();
}
if (response != null && response.getStatusCode() == HttpURLConnection.HTTP_OK) {
try {
int timeOut = prefHelper_.getTimeout() + 2000; // Time out is set to slightly more than link creation time to prevent any edge case
response = new GetShortLinkTask().execute(req).get(timeOut, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignore) {
}
String url = null;
if (req.isDefaultToLongUrl()) {
url = req.getLongUrl();
}
if (response != null && response.getStatusCode() == HttpURLConnection.HTTP_OK) {
try {
url = response.getObject().getString("url");
if (req.getLinkPost() != null) {
linkCache_.put(req.getLinkPost(), url);
}
} catch (JSONException e) {
e.printStackTrace();
url = response.getObject().getString("url");
if (req.getLinkPost() != null) {
linkCache_.put(req.getLinkPost(), url);
}
} catch (JSONException e) {
e.printStackTrace();
}
return url;
} else {
PrefHelper.Debug("Warning: User session has not been initialized");
}
return null;
return url;
}

private JSONObject convertParamsStringToDictionary(String paramString) {
Expand Down Expand Up @@ -1783,19 +1775,19 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean ignoreWa
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.GOOGLE_INSTALL_REFERRER_FETCH_WAIT_LOCK);
}

if (classExists("com.huawei.hms.ads.installreferrer.api.InstallReferrerClient")
if (classExists(huaweiInstallReferrerClass)
&& !StoreReferrerHuaweiAppGallery.hasBeenUsed) {
waitingForHuaweiInstallReferrer = true;
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.HUAWEI_INSTALL_REFERRER_FETCH_WAIT_LOCK);
}

if (classExists("com.sec.android.app.samsungapps.installreferrer.api.InstallReferrerClient")
if (classExists(galaxyStoreInstallReferrerClass)
&& !StoreReferrerSamsungGalaxyStore.hasBeenUsed) {
waitingForSamsungInstallReferrer = true;
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.SAMSUNG_INSTALL_REFERRER_FETCH_WAIT_LOCK);
}

if (classExists("com.miui.referrer.api.GetAppsReferrerClient")
if (classExists(xiaomiInstallReferrerClass)
&& !StoreReferrerXiaomiGetApps.hasBeenUsed) {
waitingForXiaomiInstallReferrer = true;
request.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.XIAOMI_INSTALL_REFERRER_FETCH_WAIT_LOCK);
Expand Down Expand Up @@ -1846,16 +1838,6 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean ignoreWa
r.callback_ = request.callback_;
}
}

private boolean classExists(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
PrefHelper.Debug("Could not find " + className + ". If expected, import the dependency into your app.");
return false;
}
}

ServerRequestInitSession getInstallOrOpenRequest(BranchReferralInitListener callback, boolean isAutoInitialization) {
ServerRequestInitSession request;
Expand Down Expand Up @@ -3111,13 +3093,15 @@ public static void notifyNativeToInit(){
}

public void logEventWithPurchase(@NonNull Context context, @NonNull Purchase purchase) {
BillingGooglePlay.Companion.getInstance().startBillingClient(succeeded -> {
if (succeeded) {
BillingGooglePlay.Companion.getInstance().logEventWithPurchase(context, purchase);
} else {
PrefHelper.LogException("Cannot log IAP event. Billing client setup failed", new Exception("Billing Client Setup Failed"));
}
return null;
});
if (classExists(billingGooglePlayClass)) {
BillingGooglePlay.Companion.getInstance().startBillingClient(succeeded -> {
if (succeeded) {
BillingGooglePlay.Companion.getInstance().logEventWithPurchase(context, purchase);
} else {
PrefHelper.LogException("Cannot log IAP event. Billing client setup failed", new Exception("Billing Client Setup Failed"));
}
return null;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.branch.referral.util

import io.branch.referral.PrefHelper

fun classExists(className: String): Boolean {
return try {
Class.forName(className)
true
} catch (e: ClassNotFoundException) {
PrefHelper.Debug("Could not find $className. If expected, import the dependency into your app.")
false
}
}

const val playStoreInstallReferrerClass = "com.android.installreferrer.api.InstallReferrerClient"

const val playStoreAdvertisingIdClientClass =
"com.google.android.gms.ads.identifier.AdvertisingIdClient"

const val huaweiInstallReferrerClass =
"com.huawei.hms.ads.installreferrer.api.InstallReferrerClient"

const val galaxyStoreInstallReferrerClass =
"com.sec.android.app.samsungapps.installreferrer.api.InstallReferrerClient"

const val xiaomiInstallReferrerClass = "com.miui.referrer.api.GetAppsReferrerClient"

const val billingGooglePlayClass = "com.android.billingclient.api.BillingClient"
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ ANDROID_BUILD_TARGET_SDK_VERSION=33
ANDROID_BUILD_TOOLS_VERSION=30.0.2
ANDROID_BUILD_SDK_VERSION=33
android.useAndroidX=true
android.enableJetifier=true

0 comments on commit 0dce5a4

Please sign in to comment.