正在查看: Vi App v10.18.0 应用的 Branch.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Vi App v10.18.0 应用的 Branch.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.branch.referral;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import io.branch.indexing.BranchUniversalObject;
import io.branch.interfaces.IBranchLoggingCallbacks;
import io.branch.referral.Defines;
import io.branch.referral.ServerRequest;
import io.branch.referral.ServerRequestGetLATD;
import io.branch.referral.SystemObserver;
import io.branch.referral.network.BranchRemoteInterface;
import io.branch.referral.network.BranchRemoteInterfaceUrlConnection;
import io.branch.referral.util.BRANCH_STANDARD_EVENT;
import io.branch.referral.util.BranchEvent;
import io.branch.referral.util.LinkProperties;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.json.JSONException;
import org.json.JSONObject;
public class Branch {
private static final String BRANCH_LIBRARY_VERSION;
private static final String[] EXTERNAL_INTENT_EXTRA_KEY_WHITE_LIST;
private static final String GOOGLE_VERSION_TAG;
public static String _userAgentString;
private static Branch branchReferral_;
private static boolean bypassCurrentActivityIntentState_;
public static boolean bypassWaitingForIntent_;
public static boolean deferInitForPluginRuntime;
public static boolean disableAutoSessionInitialization;
private static boolean disableDeviceIDFetch_;
private static boolean enableInstantDeepLinking;
public static String installDeveloperId;
private static boolean isActivityLifeCycleCallbackRegistered_;
private static String pluginName;
private static String pluginVersion;
public static boolean referringLinkAttributionForPreinstalledAppsEnabled;
public static boolean userAgentSync;
private BranchActivityLifecycleObserver activityLifeCycleObserver;
private final BranchPluginSupport branchPluginSupport_;
private final BranchQRCodeCache branchQRCodeCache_;
private final Context context_;
public WeakReference<Activity> currentActivityReference_;
private JSONObject deeplinkDebugParams_;
private InitSessionBuilder deferredSessionBuilder;
private final DeviceInfo deviceInfo_;
public final PrefHelper prefHelper_;
public final ServerRequestQueue requestQueue_;
private ShareLinkManager shareLinkManager_;
private final TrackingController trackingController;
public final ConcurrentHashMap<BranchLinkData, String> linkCache_ = new ConcurrentHashMap<>();
private INTENT_STATE intentState_ = INTENT_STATE.PENDING;
public SESSION_STATE initState_ = SESSION_STATE.UNINITIALISED;
public boolean closeRequestNeeded = false;
public CountDownLatch getFirstReferringParamsLatch = null;
public CountDownLatch getLatestReferringParamsLatch = null;
private boolean isInstantDeepLinkPossible = false;
private BranchRemoteInterface branchRemoteInterface_ = new BranchRemoteInterfaceUrlConnection(this);
public interface BranchLinkCreateListener {
void onLinkCreate(String str, BranchError branchError);
}
public interface BranchLinkShareListener {
void onChannelSelected(String str);
void onLinkShareResponse(String str, String str2, BranchError branchError);
void onShareLinkDialogDismissed();
void onShareLinkDialogLaunched();
}
public interface BranchListResponseListener {
}
public interface BranchNativeLinkShareListener {
void onChannelSelected(String str);
void onLinkShareResponse(String str, BranchError branchError);
}
public interface BranchReferralInitListener {
void onInitFinished(@Nullable JSONObject jSONObject, @Nullable BranchError branchError);
}
public interface BranchReferralStateChangedListener {
}
public interface BranchUniversalReferralInitListener {
void onInitFinished(@Nullable BranchUniversalObject branchUniversalObject, @Nullable LinkProperties linkProperties, @Nullable BranchError branchError);
}
public interface ExtendedBranchLinkShareListener extends BranchLinkShareListener {
boolean onChannelSelected(String str, BranchUniversalObject branchUniversalObject, LinkProperties linkProperties);
}
public class GetShortLinkTask extends AsyncTask<ServerRequest, Void, ServerResponse> {
private GetShortLinkTask() {
}
@Override
public ServerResponse doInBackground(ServerRequest... serverRequestArr) {
BranchRemoteInterface branchRemoteInterface = Branch.this.branchRemoteInterface_;
JSONObject post = serverRequestArr[0].getPost();
StringBuilder sb = new StringBuilder();
sb.append(Branch.this.prefHelper_.getAPIBaseUrl());
Defines.RequestPath requestPath = Defines.RequestPath.GetURL;
sb.append(requestPath.getPath());
return branchRemoteInterface.make_restful_post(post, sb.toString(), requestPath.getPath(), Branch.this.prefHelper_.getBranchKey());
}
}
public interface IChannelProperties {
String getSharingMessageForChannel(String str);
String getSharingTitleForChannel(String str);
}
public enum INTENT_STATE {
PENDING,
READY
}
public static class InitSessionBuilder {
private BranchReferralInitListener callback;
private int delay;
private Boolean ignoreIntent;
private boolean isAutoInitialization;
private boolean isReInitializing;
private Uri uri;
private void cacheSessionBuilder(InitSessionBuilder initSessionBuilder) {
Branch.getInstance().deferredSessionBuilder = this;
BranchLogger.v("Session initialization deferred until plugin invokes notifyNativeToInit()\nCaching Session Builder " + Branch.getInstance().deferredSessionBuilder + "\nuri: " + Branch.getInstance().deferredSessionBuilder.uri + "\ncallback: " + Branch.getInstance().deferredSessionBuilder.callback + "\nisReInitializing: " + Branch.getInstance().deferredSessionBuilder.isReInitializing + "\ndelay: " + Branch.getInstance().deferredSessionBuilder.delay + "\nisAutoInitialization: " + Branch.getInstance().deferredSessionBuilder.isAutoInitialization + "\nignoreIntent: " + Branch.getInstance().deferredSessionBuilder.ignoreIntent);
}
public void init() {
BranchLogger.v("Beginning session initialization");
BranchLogger.v("Session uri is " + this.uri);
BranchLogger.v("Callback is " + this.callback);
BranchLogger.v("Is auto init " + this.isAutoInitialization);
BranchLogger.v("Will ignore intent " + this.ignoreIntent);
BranchLogger.v("Is reinitializing " + this.isReInitializing);
if (Branch.deferInitForPluginRuntime) {
BranchLogger.v("Session init is deferred until signaled by plugin.");
cacheSessionBuilder(this);
return;
}
Branch branch = Branch.getInstance();
if (branch == null) {
BranchLogger.logAlways("Branch is not setup properly, make sure to call getAutoInstance in your application class or declare BranchApp in your manifest.");
return;
}
Boolean bool = this.ignoreIntent;
if (bool != null) {
Branch.bypassWaitingForIntent(bool.booleanValue());
}
Activity currentActivity = branch.getCurrentActivity();
Intent intent = currentActivity != null ? currentActivity.getIntent() : null;
if (currentActivity != null && intent != null && ActivityCompat.getReferrer(currentActivity) != null) {
PrefHelper.getInstance(currentActivity).setInitialReferrer(ActivityCompat.getReferrer(currentActivity).toString());
}
Uri uri = this.uri;
if (uri != null) {
branch.readAndStripParam(uri, currentActivity);
} else if (this.isReInitializing && branch.isRestartSessionRequested(intent)) {
branch.readAndStripParam(intent != null ? intent.getData() : null, currentActivity);
} else if (this.isReInitializing) {
BranchReferralInitListener branchReferralInitListener = this.callback;
if (branchReferralInitListener != null) {
branchReferralInitListener.onInitFinished(null, new BranchError("", -119));
return;
}
return;
}
BranchLogger.v("isInstantDeepLinkPossible " + branch.isInstantDeepLinkPossible);
if (branch.isInstantDeepLinkPossible) {
branch.isInstantDeepLinkPossible = false;
BranchReferralInitListener branchReferralInitListener2 = this.callback;
if (branchReferralInitListener2 != null) {
branchReferralInitListener2.onInitFinished(branch.getLatestReferringParams(), null);
}
Branch.getInstance().requestQueue_.addExtraInstrumentationData(Defines.Jsonkey.InstantDeepLinkSession.getKey(), "true");
branch.checkForAutoDeepLinkConfiguration();
this.callback = null;
}
if (this.delay > 0) {
Branch.expectDelayedSessionInitialization(true);
}
ServerRequestInitSession installOrOpenRequest = branch.getInstallOrOpenRequest(this.callback, this.isAutoInitialization);
BranchLogger.d("Creating " + installOrOpenRequest + " from init on thread " + Thread.currentThread().getName());
branch.initializeSession(installOrOpenRequest, this.delay);
}
public InitSessionBuilder isAutoInitialization(boolean z) {
this.isAutoInitialization = z;
return this;
}
public void reInit() {
this.isReInitializing = true;
init();
}
public InitSessionBuilder withCallback(BranchReferralInitListener branchReferralInitListener) {
BranchLogger.v("InitSessionBuilder setting BranchReferralInitListener withCallback with " + branchReferralInitListener);
this.callback = branchReferralInitListener;
return this;
}
public InitSessionBuilder withData(Uri uri) {
BranchLogger.v("InitSessionBuilder setting withData with " + uri);
this.uri = uri;
return this;
}
private InitSessionBuilder(Activity activity) {
Branch branch = Branch.getInstance();
if (activity != null) {
if (branch.getCurrentActivity() == null || !branch.getCurrentActivity().getLocalClassName().equals(activity.getLocalClassName())) {
branch.currentActivityReference_ = new WeakReference<>(activity);
}
}
}
}
public interface LogoutStatusListener {
void onLogoutFinished(boolean z, BranchError branchError);
}
public enum SESSION_STATE {
INITIALISED,
INITIALISING,
UNINITIALISED
}
public interface TrackingStateCallback {
void onTrackingStateChanged(boolean z, @Nullable JSONObject jSONObject, @Nullable BranchError branchError);
}
static {
String str = "io.branch.sdk.android:library:" + getSdkVersionNumber();
BRANCH_LIBRARY_VERSION = str;
GOOGLE_VERSION_TAG = "!SDK-VERSION-STRING!:" + str;
_userAgentString = "";
bypassWaitingForIntent_ = false;
bypassCurrentActivityIntentState_ = false;
referringLinkAttributionForPreinstalledAppsEnabled = false;
isActivityLifeCycleCallbackRegistered_ = false;
deferInitForPluginRuntime = false;
EXTERNAL_INTENT_EXTRA_KEY_WHITE_LIST = new String[]{"extra_launch_uri", "branch_intent"};
installDeveloperId = null;
enableInstantDeepLinking = false;
pluginVersion = null;
pluginName = null;
}
private Branch(@NonNull Context context) {
this.context_ = context;
this.prefHelper_ = PrefHelper.getInstance(context);
this.trackingController = new TrackingController(context);
this.deviceInfo_ = new DeviceInfo(context);
this.branchPluginSupport_ = new BranchPluginSupport(context);
this.branchQRCodeCache_ = new BranchQRCodeCache(context);
this.requestQueue_ = ServerRequestQueue.getInstance(context);
}
private JSONObject appendDebugParams(JSONObject jSONObject) {
if (jSONObject != null) {
try {
JSONObject jSONObject2 = this.deeplinkDebugParams_;
if (jSONObject2 != null) {
if (jSONObject2.length() > 0) {
BranchLogger.v("You're currently in deep link debug mode. Please comment out 'setDeepLinkDebugMode' to receive the deep link parameters from a real Branch link");
}
Iterator<String> keys = this.deeplinkDebugParams_.keys();
while (keys.hasNext()) {
String next = keys.next();
jSONObject.put(next, this.deeplinkDebugParams_.get(next));
}
}
} catch (Exception e) {
BranchLogger.d(e.getMessage());
}
}
return jSONObject;
}
public static boolean bypassCurrentActivityIntentState() {
return bypassCurrentActivityIntentState_;
}
public static void bypassWaitingForIntent(boolean z) {
bypassWaitingForIntent_ = z;
}
private boolean checkForAutoDeepLinkKeys(JSONObject jSONObject, ActivityInfo activityInfo) {
if (activityInfo.metaData.getString("io.branch.sdk.auto_link_keys") != null) {
for (String str : activityInfo.metaData.getString("io.branch.sdk.auto_link_keys").split(",")) {
if (jSONObject.has(str)) {
return true;
}
}
}
return false;
}
private boolean checkForAutoDeepLinkPath(org.json.JSONObject r5, android.content.pm.ActivityInfo r6) {
throw new UnsupportedOperationException("Method not decompiled: io.branch.referral.Branch.checkForAutoDeepLinkPath(org.json.JSONObject, android.content.pm.ActivityInfo):boolean");
}
private boolean checkIntentForSessionRestart(Intent intent) {
if (intent != null) {
return intent.getBooleanExtra(Defines.IntentKeys.ForceNewBranchSession.getKey(), false);
}
return false;
}
private boolean checkIntentForUnusedBranchLink(Intent intent) {
if (intent != null) {
return (intent.getStringExtra(Defines.IntentKeys.BranchURI.getKey()) != null) && (intent.getBooleanExtra(Defines.IntentKeys.BranchLinkUsed.getKey(), false) ^ true);
}
return false;
}
private JSONObject convertParamsStringToDictionary(String str) {
if (str.equals("bnc_no_value")) {
return new JSONObject();
}
try {
return new JSONObject(str);
} catch (JSONException unused) {
try {
return new JSONObject(new String(Base64.decode(str.getBytes(), 2)));
} catch (JSONException e) {
e.printStackTrace();
return new JSONObject();
}
}
}
public static void deferInitForPluginRuntime(boolean z) {
BranchLogger.v("deferInitForPluginRuntime " + z);
deferInitForPluginRuntime = z;
if (z) {
expectDelayedSessionInitialization(z);
}
}
public static void enableLogging() {
enableLogging(null);
}
private void executeClose() {
SESSION_STATE session_state = this.initState_;
SESSION_STATE session_state2 = SESSION_STATE.UNINITIALISED;
if (session_state != session_state2) {
setInitState(session_state2);
}
}
public static void expectDelayedSessionInitialization(boolean z) {
disableAutoSessionInitialization = z;
}
private void extractAppLink(Uri uri, Activity activity) {
if (uri == null || activity == null) {
return;
}
String scheme = uri.getScheme();
Intent intent = activity.getIntent();
if (scheme == null || intent == null) {
return;
}
if ((!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) || TextUtils.isEmpty(uri.getHost()) || isIntentParamsAlreadyConsumed(activity)) {
return;
}
if (uri.toString().equalsIgnoreCase(UniversalResourceAnalyser.getInstance(this.context_).getStrippedURL(uri.toString()))) {
this.prefHelper_.setAppLink(uri.toString());
}
intent.putExtra(Defines.IntentKeys.BranchLinkUsed.getKey(), true);
activity.setIntent(intent);
}
private boolean extractBranchLinkFromIntentExtra(Activity activity) {
BranchLogger.v("extractBranchLinkFromIntentExtra " + activity);
if (activity == null) {
return false;
}
try {
if (activity.getIntent() == null || activity.getIntent().getExtras() == null || isIntentParamsAlreadyConsumed(activity)) {
return false;
}
Object obj = activity.getIntent().getExtras().get(Defines.IntentKeys.BranchURI.getKey());
String str = null;
if (obj instanceof String) {
str = (String) obj;
} else if (obj instanceof Uri) {
str = ((Uri) obj).toString();
}
if (TextUtils.isEmpty(str)) {
return false;
}
this.prefHelper_.setPushIdentifier(str);
Intent intent = activity.getIntent();
intent.putExtra(Defines.IntentKeys.BranchLinkUsed.getKey(), true);
activity.setIntent(intent);
return true;
} catch (Exception e) {
BranchLogger.d(e.getMessage());
return false;
}
}
private boolean extractClickID(Uri uri, Activity activity) {
String queryParameter;
String str;
if (uri != null) {
try {
if (!uri.isHierarchical() || (queryParameter = uri.getQueryParameter(Defines.Jsonkey.LinkClickID.getKey())) == null) {
return false;
}
this.prefHelper_.setLinkClickIdentifier(queryParameter);
String str2 = "link_click_id=" + queryParameter;
String uri2 = uri.toString();
if (str2.equals(uri.getQuery())) {
str = "\\?" + str2;
} else if (uri2.length() - str2.length() == uri2.indexOf(str2)) {
str = "&" + str2;
} else {
str = str2 + "&";
}
activity.getIntent().setData(Uri.parse(uri2.replaceFirst(str, "")));
activity.getIntent().putExtra(Defines.IntentKeys.BranchLinkUsed.getKey(), true);
return true;
} catch (Exception e) {
BranchLogger.d(e.getMessage());
}
}
return false;
}
private void extractExternalUriAndIntentExtras(Uri uri, Activity activity) {
BranchLogger.v("extractExternalUriAndIntentExtras " + uri + " " + activity);
try {
if (isIntentParamsAlreadyConsumed(activity)) {
return;
}
String strippedURL = UniversalResourceAnalyser.getInstance(this.context_).getStrippedURL(uri.toString());
this.prefHelper_.setExternalIntentUri(strippedURL);
if (strippedURL.equals(uri.toString())) {
Bundle extras = activity.getIntent().getExtras();
Set<String> keySet = extras.keySet();
if (keySet.isEmpty()) {
return;
}
JSONObject jSONObject = new JSONObject();
for (String str : EXTERNAL_INTENT_EXTRA_KEY_WHITE_LIST) {
if (keySet.contains(str)) {
jSONObject.put(str, extras.get(str));
}
}
if (jSONObject.length() > 0) {
this.prefHelper_.setExternalIntentExtra(jSONObject.toString());
}
}
} catch (Exception e) {
BranchLogger.d(e.getMessage());
}
}
private void extractSessionParamsForIDL(Uri uri, Activity activity) {
if (activity == null || activity.getIntent() == null) {
return;
}
Intent intent = activity.getIntent();
if (uri != null) {
try {
if (!isIntentParamsAlreadyConsumed(activity)) {
Defines.IntentKeys intentKeys = Defines.IntentKeys.BranchData;
if (!TextUtils.isEmpty(intent.getStringExtra(intentKeys.getKey()))) {
String stringExtra = intent.getStringExtra(intentKeys.getKey());
if (stringExtra != null) {
JSONObject jSONObject = new JSONObject(stringExtra);
jSONObject.put(Defines.Jsonkey.Clicked_Branch_Link.getKey(), true);
this.prefHelper_.setSessionParams(jSONObject.toString());
this.isInstantDeepLinkPossible = true;
}
intent.removeExtra(intentKeys.getKey());
activity.setIntent(intent);
return;
}
if (uri.isHierarchical() && Boolean.valueOf(uri.getQueryParameter(Defines.Jsonkey.Instant.getKey())).booleanValue()) {
JSONObject jSONObject2 = new JSONObject();
for (String str : uri.getQueryParameterNames()) {
jSONObject2.put(str, uri.getQueryParameter(str));
}
jSONObject2.put(Defines.Jsonkey.Clicked_Branch_Link.getKey(), true);
this.prefHelper_.setSessionParams(jSONObject2.toString());
this.isInstantDeepLinkPossible = true;
return;
}
return;
}
} catch (JSONException e) {
BranchLogger.d(e.getMessage());
return;
}
}
if (this.prefHelper_.getInstallParams().equals("bnc_no_value")) {
return;
}
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put(Defines.Jsonkey.IsFirstSession.getKey(), false);
this.prefHelper_.setSessionParams(jSONObject3.toString());
this.isInstantDeepLinkPossible = true;
}
private String generateShortLinkSync(ServerRequestCreateUrl serverRequestCreateUrl) {
ServerResponse serverResponse;
try {
serverResponse = new GetShortLinkTask().execute(serverRequestCreateUrl).get(this.prefHelper_.getTimeout() + 2000, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
BranchLogger.d(e.getMessage());
serverResponse = null;
}
String longUrl = serverRequestCreateUrl.isDefaultToLongUrl() ? serverRequestCreateUrl.getLongUrl() : null;
if (serverResponse != null && serverResponse.getStatusCode() == 200) {
try {
longUrl = serverResponse.getObject().getString("url");
if (serverRequestCreateUrl.getLinkPost() != null) {
this.linkCache_.put(serverRequestCreateUrl.getLinkPost(), longUrl);
}
} catch (JSONException e2) {
e2.printStackTrace();
}
}
return longUrl;
}
public static synchronized Branch getAutoInstance(@NonNull Context context) {
Branch branch;
synchronized (Branch.class) {
if (branchReferral_ == null) {
if (BranchUtil.getEnableLoggingConfig(context)) {
enableLogging();
}
deferInitForPluginRuntime(BranchUtil.getDeferInitForPluginRuntimeConfig(context));
BranchUtil.setAPIBaseUrlFromConfig(context);
BranchUtil.setTestMode(BranchUtil.checkTestMode(context));
Branch initBranchSDK = initBranchSDK(context, BranchUtil.readBranchKey(context));
branchReferral_ = initBranchSDK;
BranchPreinstall.getPreinstallSystemData(initBranchSDK, context);
}
branch = branchReferral_;
}
return branch;
}
public static synchronized Branch getInstance() {
Branch branch;
synchronized (Branch.class) {
if (branchReferral_ == null) {
BranchLogger.v("Branch instance is not created yet. Make sure you call getAutoInstance(Context).");
}
branch = branchReferral_;
}
return branch;
}
public static String getPluginName() {
return pluginName;
}
public static String getPluginVersion() {
return pluginVersion;
}
public static String getSdkVersionNumber() {
return "5.11.0";
}
private static synchronized Branch initBranchSDK(@NonNull Context context, String str) {
synchronized (Branch.class) {
if (branchReferral_ != null) {
BranchLogger.w("Warning, attempted to reinitialize Branch SDK singleton!");
return branchReferral_;
}
branchReferral_ = new Branch(context.getApplicationContext());
if (TextUtils.isEmpty(str)) {
BranchLogger.w("Warning: Please enter your branch_key in your project's Manifest file!");
branchReferral_.prefHelper_.setBranchKey("bnc_no_value");
} else {
branchReferral_.prefHelper_.setBranchKey(str);
}
if (context instanceof Application) {
branchReferral_.setActivityLifeCycleObserver((Application) context);
}
return branchReferral_;
}
}
private void initTasks(final ServerRequest serverRequest, boolean z) {
BranchLogger.v("initTasks " + serverRequest + " ignoreWaitLocks " + z);
if (!z) {
if (this.intentState_ != INTENT_STATE.READY && isWaitingForIntent()) {
BranchLogger.v("Adding INTENT_PENDING_WAIT_LOCK");
serverRequest.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INTENT_PENDING_WAIT_LOCK);
}
serverRequest.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.GAID_FETCH_WAIT_LOCK);
if (serverRequest instanceof ServerRequestRegisterInstall) {
serverRequest.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
this.deviceInfo_.getSystemObserver().fetchInstallReferrer(this.context_, new SystemObserver.InstallReferrerFetchEvents() {
@Override
public void onInstallReferrersFinished() {
serverRequest.removeProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
Branch.this.requestQueue_.processNextQueueItem("onInstallReferrersFinished");
}
});
}
}
this.deviceInfo_.getSystemObserver().fetchAdId(this.context_, new SystemObserver.AdsParamsFetchEvents() {
@Override
public void onAdsParamsFetchFinished() {
Branch.this.requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.GAID_FETCH_WAIT_LOCK);
Branch.this.requestQueue_.processNextQueueItem("onAdsParamsFetchFinished");
}
});
}
public void initializeSession(ServerRequestInitSession serverRequestInitSession, int i) {
BranchLogger.v("initializeSession " + serverRequestInitSession + " delay " + i);
if (this.prefHelper_.getBranchKey() == null || this.prefHelper_.getBranchKey().equalsIgnoreCase("bnc_no_value")) {
setInitState(SESSION_STATE.UNINITIALISED);
BranchReferralInitListener branchReferralInitListener = serverRequestInitSession.callback_;
if (branchReferralInitListener != null) {
branchReferralInitListener.onInitFinished(null, new BranchError("Trouble initializing Branch.", -114));
}
BranchLogger.w("Warning: Please enter your branch_key in your project's manifest");
return;
}
if (BranchUtil.isTestModeEnabled()) {
BranchLogger.w("Warning: You are using your test app's Branch Key. Remember to change it to live Branch Key during deployment.");
}
if (i > 0) {
serverRequestInitSession.addProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.USER_SET_WAIT_LOCK);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Branch.this.removeSessionInitializationDelay();
}
}, i);
}
Intent intent = getCurrentActivity() != null ? getCurrentActivity().getIntent() : null;
boolean isRestartSessionRequested = isRestartSessionRequested(intent);
SESSION_STATE initState = getInitState();
BranchLogger.v("Intent: " + intent + " forceBranchSession: " + isRestartSessionRequested + " initState: " + initState);
if (initState == SESSION_STATE.UNINITIALISED || isRestartSessionRequested) {
if (isRestartSessionRequested && intent != null) {
intent.removeExtra(Defines.IntentKeys.ForceNewBranchSession.getKey());
}
registerAppInit(serverRequestInitSession, false, isRestartSessionRequested);
return;
}
BranchReferralInitListener branchReferralInitListener2 = serverRequestInitSession.callback_;
if (branchReferralInitListener2 != null) {
branchReferralInitListener2.onInitFinished(null, new BranchError("Warning.", -118));
}
}
private boolean isActivityLaunchedFromHistory(Activity activity) {
return (activity == null || activity.getIntent() == null || (activity.getIntent().getFlags() & 1048576) == 0) ? false : true;
}
public static boolean isDeviceIDFetchDisabled() {
return disableDeviceIDFetch_;
}
private boolean isIntentParamsAlreadyConsumed(Activity activity) {
boolean z = false;
if (activity != null && activity.getIntent() != null && activity.getIntent().getBooleanExtra(Defines.IntentKeys.BranchLinkUsed.getKey(), false)) {
z = true;
}
BranchLogger.v("isIntentParamsAlreadyConsumed " + z);
return z;
}
public static boolean isReferringLinkAttributionForPreinstalledAppsEnabled() {
return referringLinkAttributionForPreinstalledAppsEnabled;
}
public static boolean isWaitingForIntent() {
return !bypassWaitingForIntent_;
}
public static void notifyNativeToInit() {
BranchLogger.v("notifyNativeToInit deferredSessionBuilder " + getInstance().deferredSessionBuilder);
SESSION_STATE initState = getInstance().getInitState();
if (initState == SESSION_STATE.UNINITIALISED) {
deferInitForPluginRuntime = false;
if (getInstance().deferredSessionBuilder != null) {
getInstance().deferredSessionBuilder.init();
return;
}
return;
}
BranchLogger.v("notifyNativeToInit session is not uninitialized. Session state is " + initState);
}
private boolean pathMatch(String str, String str2) {
String[] split = str.split("\\?")[0].split("/");
String[] split2 = str2.split("\\?")[0].split("/");
if (split.length != split2.length) {
return false;
}
for (int i = 0; i < split.length && i < split2.length; i++) {
String str3 = split[i];
if (!str3.equals(split2[i]) && !str3.contains("*")) {
return false;
}
}
return true;
}
public void readAndStripParam(Uri uri, Activity activity) {
BranchLogger.v("Read params uri: " + uri + " bypassCurrentActivityIntentState: " + bypassCurrentActivityIntentState_ + " intent state: " + this.intentState_);
if (enableInstantDeepLinking) {
boolean z = this.intentState_ == INTENT_STATE.READY || !this.activityLifeCycleObserver.isCurrentActivityLaunchedFromStack();
boolean z2 = !isRestartSessionRequested(activity != null ? activity.getIntent() : null);
if (z && z2) {
extractSessionParamsForIDL(uri, activity);
}
}
if (bypassCurrentActivityIntentState_) {
this.intentState_ = INTENT_STATE.READY;
}
if (this.intentState_ == INTENT_STATE.READY) {
extractExternalUriAndIntentExtras(uri, activity);
if (extractBranchLinkFromIntentExtra(activity) || isActivityLaunchedFromHistory(activity) || extractClickID(uri, activity)) {
return;
}
extractAppLink(uri, activity);
}
}
public static void registerPlugin(String str, String str2) {
pluginName = str;
pluginVersion = str2;
}
public static InitSessionBuilder sessionBuilder(Activity activity) {
return new InitSessionBuilder(activity);
}
public static void setAPIUrl(String str) {
if (TextUtils.isEmpty(str)) {
BranchLogger.w("setAPIUrl: URL cannot be empty or null");
return;
}
if (!str.endsWith("/")) {
str = str + "/";
}
PrefHelper.setAPIUrl(str);
BranchLogger.v("setAPIUrl: Branch API URL was set to " + str);
}
private void setActivityLifeCycleObserver(Application application) {
try {
BranchActivityLifecycleObserver branchActivityLifecycleObserver = new BranchActivityLifecycleObserver();
this.activityLifeCycleObserver = branchActivityLifecycleObserver;
application.unregisterActivityLifecycleCallbacks(branchActivityLifecycleObserver);
application.registerActivityLifecycleCallbacks(this.activityLifeCycleObserver);
isActivityLifeCycleCallbackRegistered_ = true;
} catch (NoClassDefFoundError | NoSuchMethodError unused) {
isActivityLifeCycleCallbackRegistered_ = false;
BranchLogger.v(new BranchError("", -108).getMessage());
}
}
public void addFacebookPartnerParameterWithName(@NonNull String str, @NonNull String str2) {
if (this.trackingController.isTrackingDisabled()) {
return;
}
this.prefHelper_.partnerParams_.addFacebookParameter(str, str2);
}
public Branch addInstallMetadata(@NonNull String str, @NonNull String str2) {
this.prefHelper_.addInstallMetadata(str, str2);
return this;
}
public void addSnapPartnerParameterWithName(@NonNull String str, @NonNull String str2) {
if (this.trackingController.isTrackingDisabled()) {
return;
}
this.prefHelper_.partnerParams_.addSnapParameter(str, str2);
}
public void checkForAutoDeepLinkConfiguration() {
Bundle bundle;
JSONObject latestReferringParams = getLatestReferringParams();
String str = null;
try {
Defines.Jsonkey jsonkey = Defines.Jsonkey.Clicked_Branch_Link;
if (latestReferringParams.has(jsonkey.getKey()) && latestReferringParams.getBoolean(jsonkey.getKey())) {
if (latestReferringParams.length() > 0) {
Bundle bundle2 = this.context_.getPackageManager().getApplicationInfo(this.context_.getPackageName(), 128).metaData;
if (bundle2 == null || !bundle2.getBoolean("io.branch.sdk.auto_link_disable", false)) {
ActivityInfo[] activityInfoArr = this.context_.getPackageManager().getPackageInfo(this.context_.getPackageName(), 129).activities;
int i = 1501;
if (activityInfoArr != null) {
for (ActivityInfo activityInfo : activityInfoArr) {
if (activityInfo != null && (bundle = activityInfo.metaData) != null && ((bundle.getString("io.branch.sdk.auto_link_keys") != null || activityInfo.metaData.getString("io.branch.sdk.auto_link_path") != null) && (checkForAutoDeepLinkKeys(latestReferringParams, activityInfo) || checkForAutoDeepLinkPath(latestReferringParams, activityInfo)))) {
str = activityInfo.name;
i = activityInfo.metaData.getInt("io.branch.sdk.auto_link_request_code", 1501);
break;
}
}
}
if (str == null || getCurrentActivity() == null) {
BranchLogger.v("No activity reference to launch deep linked activity");
return;
}
BranchLogger.v("deepLinkActivity " + str + " getCurrentActivity " + getCurrentActivity());
Activity currentActivity = getCurrentActivity();
Intent intent = new Intent(currentActivity, Class.forName(str));
intent.putExtra(Defines.IntentKeys.AutoDeepLinked.getKey(), "true");
intent.putExtra(Defines.Jsonkey.ReferringData.getKey(), latestReferringParams.toString());
Iterator<String> keys = latestReferringParams.keys();
while (keys.hasNext()) {
String next = keys.next();
intent.putExtra(next, latestReferringParams.getString(next));
}
currentActivity.startActivityForResult(intent, i);
return;
}
return;
}
return;
}
BranchLogger.v("Does not have Clicked_Branch_Link or Clicked_Branch_Link is false, returning");
} catch (PackageManager.NameNotFoundException unused) {
BranchLogger.w("Warning: Please make sure Activity names set for auto deep link are correct!");
} catch (ClassNotFoundException unused2) {
BranchLogger.w("Warning: Please make sure Activity names set for auto deep link are correct! Error while looking for activity " + ((String) null));
} catch (Exception unused3) {
}
}
public void clearPartnerParameters() {
this.prefHelper_.partnerParams_.clearAllParameters();
}
public void clearPendingRequests() {
this.requestQueue_.clear();
}
public void closeSessionInternal() {
clearPartnerParameters();
executeClose();
this.prefHelper_.setSessionParams("bnc_no_value");
this.prefHelper_.setExternalIntentUri(null);
this.trackingController.updateTrackingState(this.context_);
}
public void disableTracking(boolean z, @Nullable TrackingStateCallback trackingStateCallback) {
this.trackingController.disableTracking(this.context_, z, trackingStateCallback);
}
public String generateShortLinkInternal(ServerRequestCreateUrl serverRequestCreateUrl) {
if (serverRequestCreateUrl.constructError_ || serverRequestCreateUrl.handleErrors(this.context_)) {
return null;
}
if (this.linkCache_.containsKey(serverRequestCreateUrl.getLinkPost())) {
String str = this.linkCache_.get(serverRequestCreateUrl.getLinkPost());
serverRequestCreateUrl.onUrlAvailable(str);
return str;
}
if (!serverRequestCreateUrl.isAsync()) {
return generateShortLinkSync(serverRequestCreateUrl);
}
this.requestQueue_.handleNewRequest(serverRequestCreateUrl);
return null;
}
public Context getApplicationContext() {
return this.context_;
}
public BranchQRCodeCache getBranchQRCodeCache() {
return this.branchQRCodeCache_;
}
public BranchRemoteInterface getBranchRemoteInterface() {
return this.branchRemoteInterface_;
}
@Nullable
public Activity getCurrentActivity() {
WeakReference<Activity> weakReference = this.currentActivityReference_;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
public JSONObject getDeeplinkDebugParams() {
JSONObject jSONObject = this.deeplinkDebugParams_;
if (jSONObject != null && jSONObject.length() > 0) {
BranchLogger.v("You're currently in deep link debug mode. Please comment out 'setDeepLinkDebugMode' to receive the deep link parameters from a real Branch link");
}
return this.deeplinkDebugParams_;
}
public DeviceInfo getDeviceInfo() {
return this.deviceInfo_;
}
public JSONObject getFirstReferringParams() {
return appendDebugParams(convertParamsStringToDictionary(this.prefHelper_.getInstallParams()));
}
public SESSION_STATE getInitState() {
return this.initState_;
}
public ServerRequestInitSession getInstallOrOpenRequest(BranchReferralInitListener branchReferralInitListener, boolean z) {
return this.requestQueue_.hasUser() ? new ServerRequestRegisterOpen(this.context_, branchReferralInitListener, z) : new ServerRequestRegisterInstall(this.context_, branchReferralInitListener, z);
}
public void getLastAttributedTouchData(ServerRequestGetLATD.BranchLastAttributedTouchDataListener branchLastAttributedTouchDataListener, int i) {
if (this.context_ != null) {
this.requestQueue_.handleNewRequest(new ServerRequestGetLATD(this.context_, Defines.RequestPath.GetLATD, branchLastAttributedTouchDataListener, i));
}
}
public JSONObject getLatestReferringParams() {
return appendDebugParams(convertParamsStringToDictionary(this.prefHelper_.getSessionParams()));
}
public JSONObject getLatestReferringParamsSync() {
CountDownLatch countDownLatch = new CountDownLatch(1);
this.getLatestReferringParamsLatch = countDownLatch;
try {
if (this.initState_ != SESSION_STATE.INITIALISED) {
countDownLatch.await(2500L, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException unused) {
}
JSONObject appendDebugParams = appendDebugParams(convertParamsStringToDictionary(this.prefHelper_.getSessionParams()));
this.getLatestReferringParamsLatch = null;
return appendDebugParams;
}
public PrefHelper getPrefHelper() {
return this.prefHelper_;
}
public ShareLinkManager getShareLinkManager() {
return this.shareLinkManager_;
}
public TrackingController getTrackingController() {
return this.trackingController;
}
public boolean isIDLSession() {
return Boolean.parseBoolean(getInstance().requestQueue_.instrumentationExtraData_.get(Defines.Jsonkey.InstantDeepLinkSession.getKey()));
}
public boolean isInstantDeepLinkPossible() {
return this.isInstantDeepLinkPossible;
}
public boolean isRestartSessionRequested(Intent intent) {
return checkIntentForSessionRestart(intent) || checkIntentForUnusedBranchLink(intent);
}
public boolean isTrackingDisabled() {
return this.trackingController.isTrackingDisabled();
}
public void logout() {
logout(null);
}
public void onIntentReady(@NonNull Activity activity) {
BranchLogger.v("onIntentReady " + activity + " removing INTENT_PENDING_WAIT_LOCK");
setIntentState(INTENT_STATE.READY);
this.requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.INTENT_PENDING_WAIT_LOCK);
if ((activity.getIntent() == null || getInitState() == SESSION_STATE.INITIALISED) ? false : true) {
readAndStripParam(activity.getIntent().getData(), activity);
}
this.requestQueue_.processNextQueueItem("onIntentReady");
}
public void registerAppInit(@NonNull ServerRequestInitSession serverRequestInitSession, boolean z, boolean z2) {
BranchLogger.v("registerAppInit " + serverRequestInitSession);
setInitState(SESSION_STATE.INITIALISING);
ServerRequestInitSession selfInitRequest = this.requestQueue_.getSelfInitRequest();
BranchLogger.v("Ordering init calls");
this.requestQueue_.printQueue();
if (selfInitRequest == null || z2) {
BranchLogger.v("Moving " + serverRequestInitSession + " to front of the queue or behind network-in-progress request");
this.requestQueue_.insertRequestAtFront(serverRequestInitSession);
} else {
BranchLogger.v("Retrieved " + selfInitRequest + " with callback " + selfInitRequest.callback_ + " in queue currently");
selfInitRequest.callback_ = serverRequestInitSession.callback_;
StringBuilder sb = new StringBuilder();
sb.append(selfInitRequest);
sb.append(" now has callback ");
sb.append(serverRequestInitSession.callback_);
BranchLogger.v(sb.toString());
}
BranchLogger.v("Finished ordering init calls");
this.requestQueue_.printQueue();
initTasks(serverRequestInitSession, z);
this.requestQueue_.processNextQueueItem("registerAppInit");
}
public void registerView(BranchUniversalObject branchUniversalObject, BranchUniversalObject.RegisterViewStatusListener registerViewStatusListener) {
if (this.context_ != null) {
new BranchEvent(BRANCH_STANDARD_EVENT.VIEW_ITEM).addContentItems(new BranchUniversalObject[]{branchUniversalObject}).logEvent(this.context_);
}
}
public void removeSessionInitializationDelay() {
this.requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.USER_SET_WAIT_LOCK);
this.requestQueue_.processNextQueueItem("removeSessionInitializationDelay");
}
public void setDMAParamsForEEA(boolean z, boolean z2, boolean z3) {
this.prefHelper_.setEEARegion(z);
this.prefHelper_.setAdPersonalizationConsent(z2);
this.prefHelper_.setAdUserDataUsageConsent(z3);
}
public void setIdentity(@NonNull String str) {
setIdentity(str, null);
}
public void setInitState(SESSION_STATE session_state) {
this.initState_ = session_state;
}
public void setInstantDeepLinkPossible(boolean z) {
this.isInstantDeepLinkPossible = z;
}
public void setIntentState(INTENT_STATE intent_state) {
this.intentState_ = intent_state;
}
public Branch setPreinstallCampaign(@NonNull String str) {
addInstallMetadata(Defines.PreinstallKey.campaign.getKey(), str);
return this;
}
public Branch setPreinstallPartner(@NonNull String str) {
addInstallMetadata(Defines.PreinstallKey.partner.getKey(), str);
return this;
}
public void setRequestMetadata(@NonNull String str, @NonNull String str2) {
this.prefHelper_.setRequestMetadata(str, str2);
}
public void shareLink(BranchShareSheetBuilder branchShareSheetBuilder) {
ShareLinkManager shareLinkManager = this.shareLinkManager_;
if (shareLinkManager != null) {
shareLinkManager.cancelShareLinkDialog(true);
}
ShareLinkManager shareLinkManager2 = new ShareLinkManager();
this.shareLinkManager_ = shareLinkManager2;
shareLinkManager2.shareLink(branchShareSheetBuilder);
}
public void unlockSDKInitWaitLock() {
ServerRequestQueue serverRequestQueue = this.requestQueue_;
if (serverRequestQueue == null) {
return;
}
serverRequestQueue.postInitClear();
this.requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.SDK_INIT_WAIT_LOCK);
this.requestQueue_.processNextQueueItem("unlockSDKInitWaitLock");
}
public void updateSkipURLFormats() {
UniversalResourceAnalyser.getInstance(this.context_).checkAndUpdateSkipURLFormats(this.context_);
}
public static void enableLogging(IBranchLoggingCallbacks iBranchLoggingCallbacks) {
BranchLogger.setLoggerCallback(iBranchLoggingCallbacks);
BranchLogger.logAlways(GOOGLE_VERSION_TAG);
BranchLogger.setLoggingEnabled(true);
}
public void disableTracking(boolean z) {
disableTracking(z, null);
}
public void logout(LogoutStatusListener logoutStatusListener) {
this.prefHelper_.setIdentity("bnc_no_value");
this.prefHelper_.clearUserValues();
this.linkCache_.clear();
this.requestQueue_.clear();
if (logoutStatusListener != null) {
logoutStatusListener.onLogoutFinished(true, null);
}
}
public void setIdentity(@NonNull String str, @Nullable BranchReferralInitListener branchReferralInitListener) {
if (str != null && !str.equals(this.prefHelper_.getIdentity())) {
installDeveloperId = str;
this.prefHelper_.setIdentity(str);
}
if (branchReferralInitListener != null) {
branchReferralInitListener.onInitFinished(getFirstReferringParams(), null);
}
}
}