package com.appsflyer.internal;

import android.content.Context;
import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.appsflyer.AFLogger;
import com.bytedance.covode.number.Covode;
import java.util.HashMap;
import java.util.Map;

public class cj extends cl {
    public final Map<String, Object> AFInAppEventParameterName = new HashMap();

    static {
        Covode.recordClassIndex(2676);
    }

    public cj(Runnable runnable) {
        super("google", runnable);
    }

    public final void AFKeystoreWrapper(final Context context) {
        if (values(context)) {
            AFInAppEventType();
            try {
                final InstallReferrerClient build = InstallReferrerClient.newBuilder(context).build();
                AFLogger.AFInAppEventType("Connecting to Install Referrer Library...");
                build.startConnection(new InstallReferrerStateListener() {
                    static {
                        Covode.recordClassIndex(2677);
                    }

                    public final void onInstallReferrerServiceDisconnected() {
                        AFLogger.AFInAppEventType("Install Referrer service disconnected");
                    }

                    /* JADX WARNING: Can't wrap try/catch for region: R(10:19|(1:21)|22|(2:23|24)|25|27|28|29|30|(1:32)) */
                    /* JADX WARNING: Missing exception handler attribute for start block: B:29:0x0137 */
                    /* JADX WARNING: Removed duplicated region for block: B:32:0x013d A[Catch:{ all -> 0x0154 }] */
                    /* Code decompiled incorrectly, please refer to instructions dump. */
                    public final void onInstallReferrerSetupFinished(int r10) {
                        /*
                            r9 = this;
                            java.lang.String r5 = "instant"
                            java.lang.String r4 = "ReferrerClient: InstallReferrer is not ready"
                            java.lang.String r3 = "err"
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.AFInAppEventParameterName
                            java.lang.String r1 = java.lang.String.valueOf(r10)
                            java.lang.String r0 = "code"
                            r2.put(r0, r1)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.values
                            android.content.Context r0 = r3
                            java.lang.String r6 = "com.android.vending"
                            long r0 = com.appsflyer.internal.ac.valueOf(r0, r6)
                            java.lang.Long r1 = java.lang.Long.valueOf(r0)
                            java.lang.String r0 = "api_ver"
                            r2.put(r0, r1)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.values
                            android.content.Context r0 = r3
                            java.lang.String r1 = com.appsflyer.internal.ac.values((android.content.Context) r0, (java.lang.String) r6)
                            java.lang.String r0 = "api_ver_name"
                            r2.put(r0, r1)
                            r0 = -1
                            java.lang.String r2 = "response"
                            if (r10 == r0) goto L_0x0177
                            if (r10 == 0) goto L_0x0089
                            r0 = 1
                            if (r10 == r0) goto L_0x007a
                            r0 = 2
                            if (r10 == r0) goto L_0x006b
                            r0 = 3
                            if (r10 == r0) goto L_0x005c
                            java.lang.String r0 = "responseCode not found."
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                        L_0x004c:
                            java.lang.String r0 = "Install Referrer collected locally"
                            com.appsflyer.AFLogger.AFInAppEventType(r0)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            r0.AFKeystoreWrapper()
                            com.android.installreferrer.api.InstallReferrerClient r0 = r1
                            r0.endConnection()
                            return
                        L_0x005c:
                            java.lang.String r0 = "InstallReferrer DEVELOPER_ERROR"
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values
                            java.lang.String r0 = "DEVELOPER_ERROR"
                            r1.put(r2, r0)
                            goto L_0x004c
                        L_0x006b:
                            java.lang.String r0 = "InstallReferrer FEATURE_NOT_SUPPORTED"
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values
                            java.lang.String r0 = "FEATURE_NOT_SUPPORTED"
                            r1.put(r2, r0)
                            goto L_0x004c
                        L_0x007a:
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values
                            java.lang.String r0 = "SERVICE_UNAVAILABLE"
                            r1.put(r2, r0)
                            java.lang.String r0 = "InstallReferrer not supported"
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                            goto L_0x004c
                        L_0x0089:
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values
                            java.lang.String r0 = "OK"
                            r1.put(r2, r0)
                            java.lang.String r0 = "InstallReferrer connected"
                            com.appsflyer.AFLogger.AFInAppEventType(r0)     // Catch:{ all -> 0x0154 }
                            com.android.installreferrer.api.InstallReferrerClient r0 = r1     // Catch:{ all -> 0x0154 }
                            boolean r0 = r0.isReady()     // Catch:{ all -> 0x0154 }
                            if (r0 == 0) goto L_0x0148
                            com.android.installreferrer.api.InstallReferrerClient r0 = r1     // Catch:{ all -> 0x0154 }
                            com.android.installreferrer.api.ReferrerDetails r8 = r0.getInstallReferrer()     // Catch:{ all -> 0x0154 }
                            java.lang.String r2 = r8.getInstallReferrer()     // Catch:{ all -> 0x0154 }
                            if (r2 == 0) goto L_0x00bd
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.AFInAppEventParameterName     // Catch:{ all -> 0x0154 }
                            java.lang.String r0 = "val"
                            r1.put(r0, r2)     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values     // Catch:{ all -> 0x0154 }
                            java.lang.String r0 = "referrer"
                            r1.put(r0, r2)     // Catch:{ all -> 0x0154 }
                        L_0x00bd:
                            long r6 = r8.getReferrerClickTimestampSeconds()     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.AFInAppEventParameterName     // Catch:{ all -> 0x0154 }
                            java.lang.String r1 = "clk"
                            java.lang.String r0 = java.lang.Long.toString(r6)     // Catch:{ all -> 0x0154 }
                            r2.put(r1, r0)     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.values     // Catch:{ all -> 0x0154 }
                            java.lang.String r1 = "click_ts"
                            java.lang.Long r0 = java.lang.Long.valueOf(r6)     // Catch:{ all -> 0x0154 }
                            r2.put(r1, r0)     // Catch:{ all -> 0x0154 }
                            long r6 = r8.getInstallBeginTimestampSeconds()     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.AFInAppEventParameterName     // Catch:{ all -> 0x0154 }
                            java.lang.String r1 = "install"
                            java.lang.String r0 = java.lang.Long.toString(r6)     // Catch:{ all -> 0x0154 }
                            r2.put(r1, r0)     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r2 = r0.values     // Catch:{ all -> 0x0154 }
                            java.lang.String r1 = "install_begin_ts"
                            java.lang.Long r0 = java.lang.Long.valueOf(r6)     // Catch:{ all -> 0x0154 }
                            r2.put(r1, r0)     // Catch:{ all -> 0x0154 }
                            java.util.HashMap r4 = new java.util.HashMap     // Catch:{ all -> 0x0154 }
                            r4.<init>()     // Catch:{ all -> 0x0154 }
                            boolean r2 = r8.getGooglePlayInstantParam()     // Catch:{ NoSuchMethodError -> 0x0114 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ NoSuchMethodError -> 0x0114 }
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.AFInAppEventParameterName     // Catch:{ NoSuchMethodError -> 0x0114 }
                            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r2)     // Catch:{ NoSuchMethodError -> 0x0114 }
                            r1.put(r5, r0)     // Catch:{ NoSuchMethodError -> 0x0114 }
                            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r2)     // Catch:{ NoSuchMethodError -> 0x0114 }
                            r4.put(r5, r0)     // Catch:{ NoSuchMethodError -> 0x0114 }
                        L_0x0114:
                            java.lang.String r2 = "click_server_ts"
                            long r0 = r8.getReferrerClickTimestampServerSeconds()     // Catch:{ NoSuchMethodError -> 0x0137 }
                            java.lang.Long r0 = java.lang.Long.valueOf(r0)     // Catch:{ NoSuchMethodError -> 0x0137 }
                            r4.put(r2, r0)     // Catch:{ NoSuchMethodError -> 0x0137 }
                            java.lang.String r2 = "install_begin_server_ts"
                            long r0 = r8.getInstallBeginTimestampServerSeconds()     // Catch:{ NoSuchMethodError -> 0x0137 }
                            java.lang.Long r0 = java.lang.Long.valueOf(r0)     // Catch:{ NoSuchMethodError -> 0x0137 }
                            r4.put(r2, r0)     // Catch:{ NoSuchMethodError -> 0x0137 }
                            java.lang.String r1 = "install_version"
                            java.lang.String r0 = r8.getInstallVersion()     // Catch:{ NoSuchMethodError -> 0x0137 }
                            r4.put(r1, r0)     // Catch:{ NoSuchMethodError -> 0x0137 }
                        L_0x0137:
                            boolean r0 = r4.isEmpty()     // Catch:{ all -> 0x0154 }
                            if (r0 != 0) goto L_0x004c
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values     // Catch:{ all -> 0x0154 }
                            java.lang.String r0 = "google_custom"
                            r1.put(r0, r4)     // Catch:{ all -> 0x0154 }
                            goto L_0x004c
                        L_0x0148:
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r4)     // Catch:{ all -> 0x0154 }
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this     // Catch:{ all -> 0x0154 }
                            java.util.Map<java.lang.String, java.lang.Object> r0 = r0.AFInAppEventParameterName     // Catch:{ all -> 0x0154 }
                            r0.put(r3, r4)     // Catch:{ all -> 0x0154 }
                            goto L_0x004c
                        L_0x0154:
                            r2 = move-exception
                            java.lang.StringBuilder r1 = new java.lang.StringBuilder
                            java.lang.String r0 = "Failed to get install referrer: "
                            r1.<init>(r0)
                            java.lang.String r0 = r2.getMessage()
                            r1.append(r0)
                            java.lang.String r0 = r1.toString()
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.AFInAppEventParameterName
                            java.lang.String r0 = r2.getMessage()
                            r1.put(r3, r0)
                            goto L_0x004c
                        L_0x0177:
                            java.lang.String r0 = "InstallReferrer SERVICE_DISCONNECTED"
                            com.appsflyer.AFLogger.AFLogger$LogLevel(r0)
                            com.appsflyer.internal.cj r0 = com.appsflyer.internal.cj.this
                            java.util.Map<java.lang.String, java.lang.Object> r1 = r0.values
                            java.lang.String r0 = "SERVICE_DISCONNECTED"
                            r1.put(r2, r0)
                            goto L_0x004c
                        */
                        throw new UnsupportedOperationException("Method not decompiled: com.appsflyer.internal.cj.AnonymousClass2.onInstallReferrerSetupFinished(int):void");
                    }
                });
            } catch (Throwable th) {
                AFLogger.valueOf("referrerClient -> startConnection", th);
            }
        }
    }

    public static boolean values(Context context) {
        ai.valueOf();
        if (ai.AFInAppEventParameterName(ai.values(context), "appsFlyerCount", false) > 0) {
            AFLogger.AFInAppEventParameterName("Install referrer will not load, the counter > 1, ");
            return false;
        }
        try {
            Class.forName("com.android.installreferrer.api.InstallReferrerClient");
            if (ac.AFKeystoreWrapper(context, "com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE")) {
                AFLogger.AFInAppEventType("Install referrer is allowed");
                return true;
            }
            AFLogger.AFInAppEventType("Install referrer is not allowed");
            return false;
        } catch (ClassNotFoundException unused) {
            StringBuilder sb = new StringBuilder("Class ");
            sb.append("com.android.installreferrer.api.InstallReferrerClient");
            sb.append(" not found");
            AFLogger.AFInAppEventParameterName(sb.toString());
            return false;
        } catch (Throwable th) {
            AFLogger.valueOf("An error occurred while trying to verify manifest : ".concat("com.android.installreferrer.api.InstallReferrerClient"), th);
            return false;
        }
    }
}
