CamScanner.apk(点击下载) / IntegrationValidator.java


package io.branch.referral.validators;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import io.branch.referral.Branch;
import io.branch.referral.BranchUtil;
import io.branch.referral.validators.ServerRequestGetAppConfig;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class IntegrationValidator implements ServerRequestGetAppConfig.IGetAppConfigEvents {

    /* renamed from: c  reason: collision with root package name */
    private static IntegrationValidator f47881c;

    /* renamed from: a  reason: collision with root package name */
    private final BranchIntegrationModel f47882a;

    /* renamed from: b  reason: collision with root package name */
    private final String f47883b = "BranchSDK_Doctor";

    private IntegrationValidator(Context context) {
        this.f47882a = new BranchIntegrationModel(context);
    }

    private boolean b(String str) {
        List<String> list;
        if (!TextUtils.isEmpty(str) && (list = this.f47882a.f47873d) != null) {
            for (String str2 : list) {
                if (str.equals(str2)) {
                    return true;
                }
            }
        }
        return false;
    }

    private boolean c(String str) {
        Uri parse = Uri.parse(str);
        String scheme = parse.getScheme();
        String host = parse.getHost();
        if (TextUtils.isEmpty(host)) {
            host = "open";
        }
        JSONObject jSONObject = this.f47882a.f47870a;
        if (jSONObject == null) {
            return false;
        }
        Iterator<String> keys = jSONObject.keys();
        boolean z10 = false;
        while (keys.hasNext()) {
            String next = keys.next();
            if (scheme != null && scheme.equals(next)) {
                JSONArray optJSONArray = this.f47882a.f47870a.optJSONArray(next);
                if (optJSONArray != null && optJSONArray.length() > 0) {
                    int i10 = 0;
                    while (true) {
                        if (i10 < optJSONArray.length()) {
                            if (host != null && host.equals(optJSONArray.optString(i10))) {
                                z10 = true;
                                break;
                            }
                            i10++;
                        } else {
                            break;
                        }
                    }
                } else {
                    return true;
                }
            }
        }
        return z10;
    }

    private void d(JSONObject jSONObject) {
        g("3. Verifying application package name");
        if (!this.f47882a.f47874e.equals(jSONObject.optString("android_package_name"))) {
            e("Incorrect package name in Branch dashboard. Please correct your package name in dashboard -> Configuration page.", "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-branch-dashboard");
            return;
        }
        f();
        g("4. Checking Android Manifest for URI based deep link config");
        JSONObject jSONObject2 = this.f47882a.f47870a;
        if (jSONObject2 != null && jSONObject2.length() != 0) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping. Unable to verify the deep link config. Failed to read the Android Manifest");
        } else {
            e(String.format("No intent found for opening the app through uri Scheme '%s'.Please add the intent with URI scheme to your Android manifest.", jSONObject.optString("android_uri_scheme")), "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-app");
            return;
        }
        g("5. Verifying URI based deep link config with Branch dash board.");
        String optString = jSONObject.optString("android_uri_scheme");
        if (TextUtils.isEmpty(optString)) {
            e("Uri Scheme to open your app is not specified in Branch dashboard. Please add URI scheme in Branch dashboard.", "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-branch-dashboard");
            return;
        }
        f();
        g("6. Verifying intent for receiving URI scheme.");
        if (c(optString)) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping. Unable to verify intent for receiving URI scheme. Failed to read the Android Manifest");
        } else {
            e(String.format("Uri scheme '%s' specified in Branch dashboard doesn't match with the deep link intent in manifest file", optString), "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-branch-dashboard");
            return;
        }
        g("7. Checking AndroidManifest for AppLink config.");
        if (!this.f47882a.f47873d.isEmpty()) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping. Unable to verify intent for receiving URI scheme. Failed to read the Android Manifest");
        } else {
            e("Could not find any App Link hosts to support Android AppLinks. Please add intent filter for handling AppLinks in your Android Manifest file", "https://help.branch.io/using-branch/docs/android-app-links#section-add-intent-filter-to-manifest");
            return;
        }
        g("8. Verifying any supported custom link domains.");
        String optString2 = jSONObject.optString("short_url_domain");
        if (TextUtils.isEmpty(optString2) || b(optString2)) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping. Unable to verify supported custom link domains. Failed to read the Android Manifest");
        } else {
            e(String.format("Could not find intent filter to support custom link domain '%s'. Please add intent filter for handling custom link domain in your Android Manifest file ", optString2), "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-app");
            return;
        }
        g("9. Verifying default link domains integrations.");
        String optString3 = jSONObject.optString("default_short_url_domain");
        if (TextUtils.isEmpty(optString3) || b(optString3)) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping. Unable to verify default link domains. Failed to read the Android Manifest");
        } else {
            e(String.format("Could not find intent filter to support Branch default link domain '%s'. Please add intent filter for handling custom link domain in your Android Manifest file ", optString3), "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-app");
            return;
        }
        g("10. Verifying alternate link domains integrations.");
        String optString4 = jSONObject.optString("alternate_short_url_domain");
        if (TextUtils.isEmpty(optString4) || b(optString4)) {
            f();
        } else if (!this.f47882a.f47875f) {
            g("- Skipping.Unable to verify alternate link domains. Failed to read the Android Manifest");
        } else {
            e(String.format("Could not find intent filter to support alternate link domain '%s'. Please add intent filter for handling custom link domain in your Android Manifest file ", optString4), "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-app");
            return;
        }
        f();
    }

    private void e(String str, String str2) {
        StringBuilder sb2 = new StringBuilder();
        sb2.append("** ERROR ** : ");
        sb2.append(str);
        sb2.append("\nPlease follow the link for more info ");
        sb2.append(str2);
    }

    private void f() {
    }

    private void g(String str) {
        StringBuilder sb2 = new StringBuilder();
        sb2.append(str);
        sb2.append(" ... ");
    }

    public static void h(Context context) {
        if (f47881c == null) {
            f47881c = new IntegrationValidator(context);
        }
        f47881c.i(context);
    }

    private void i(Context context) {
        g("\n\n------------------- Initiating Branch integration verification ---------------------------");
        g("1. Verifying Branch instance creation");
        if (Branch.V() == null) {
            e("Branch is not initialised from your Application class. Please add `Branch.getAutoInstance(this);` to your Application#onCreate() method.", "https://help.branch.io/developers-hub/docs/android-basic-integration#section-load-branch");
            return;
        }
        f();
        g("2. Checking Branch keys");
        if (TextUtils.isEmpty(BranchUtil.f(context))) {
            e("Unable to read Branch keys from your application. Did you forget to add Branch keys in your application?.", "https://help.branch.io/developers-hub/docs/android-basic-integration#section-configure-app");
            return;
        }
        f();
        Branch.V().e0(new ServerRequestGetAppConfig(context, this));
    }

    @Override // io.branch.referral.validators.ServerRequestGetAppConfig.IGetAppConfigEvents
    public void a(JSONObject jSONObject) {
        if (jSONObject != null) {
            d(jSONObject);
        } else {
            e("Unable to read Dashboard config. Please confirm that your Branch key is properly added to the manifest. Please fix your Dashboard settings.", "https://branch.app.link/link-settings-page");
        }
    }
}