package com.appsflyer.share;

import X.3i8;
import X.9Vv;
import X.9Vw;
import X.9dN;
import X.9dm;
import X.9dq;
import X.AnonymousClass0HH;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
import com.appsflyer.AFLogger;
import com.appsflyer.AppsFlyerLib;
import com.appsflyer.AppsFlyerProperties;
import com.appsflyer.internal.ai;
import com.appsflyer.internal.co;
import com.appsflyer.internal.cp;
import com.bytedance.covode.number.Covode;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;

public class CrossPromotionHelper {
    public static String AFKeystoreWrapper = "https://%simpression.%s";

    static {
        Covode.recordClassIndex(2726);
    }

    public static class c implements Runnable {
        public final cp AFInAppEventType;
        public final WeakReference<Context> AFKeystoreWrapper;
        public final boolean valueOf;
        public final String values;

        static {
            Covode.recordClassIndex(2727);
        }

        /* JADX WARNING: Removed duplicated region for block: B:30:0x00ba A[DONT_GENERATE] */
        /* JADX WARNING: Removed duplicated region for block: B:36:? A[RETURN, SYNTHETIC] */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public final void run() {
            /*
                r6 = this;
                boolean r0 = r6.valueOf
                if (r0 == 0) goto L_0x0005
                return
            L_0x0005:
                r2 = 0
                java.net.URL r1 = new java.net.URL     // Catch:{ all -> 0x00af }
                java.lang.String r0 = r6.values     // Catch:{ all -> 0x00af }
                r1.<init>(r0)     // Catch:{ all -> 0x00af }
                java.net.URLConnection r3 = INVOKEVIRTUAL_com_appsflyer_share_CrossPromotionHelper$c_com_ss_android_ugc_aweme_net_lancet_UrlConnectionLancet_openConnection(r1)     // Catch:{ all -> 0x00af }
                java.net.HttpURLConnection r3 = (java.net.HttpURLConnection) r3     // Catch:{ all -> 0x00af }
                r0 = 10000(0x2710, float:1.4013E-41)
                r3.setConnectTimeout(r0)     // Catch:{ all -> 0x00ad }
                r4 = 0
                r3.setInstanceFollowRedirects(r4)     // Catch:{ all -> 0x00ad }
                int r2 = r3.getResponseCode()     // Catch:{ all -> 0x00ad }
                r0 = 200(0xc8, float:2.8E-43)
                if (r2 == r0) goto L_0x0096
                r0 = 301(0x12d, float:4.22E-43)
                if (r2 == r0) goto L_0x0048
                r0 = 302(0x12e, float:4.23E-43)
                if (r2 == r0) goto L_0x0048
                java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = "call to "
                r1.<init>(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r6.values     // Catch:{ all -> 0x00ad }
                r1.append(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = " failed: "
                r1.append(r0)     // Catch:{ all -> 0x00ad }
                r1.append(r2)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r1.toString()     // Catch:{ all -> 0x00ad }
                com.appsflyer.AFLogger.valueOf((java.lang.String) r0)     // Catch:{ all -> 0x00ad }
                goto L_0x00a9
            L_0x0048:
                java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = "Cross promotion redirection success: "
                r1.<init>(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r6.values     // Catch:{ all -> 0x00ad }
                r1.append(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r1.toString()     // Catch:{ all -> 0x00ad }
                com.appsflyer.AFLogger.values((java.lang.String) r0, (boolean) r4)     // Catch:{ all -> 0x00ad }
                com.appsflyer.internal.cp r0 = r6.AFInAppEventType     // Catch:{ all -> 0x00ad }
                if (r0 == 0) goto L_0x00a9
                java.lang.ref.WeakReference<android.content.Context> r0 = r6.AFKeystoreWrapper     // Catch:{ all -> 0x00ad }
                java.lang.Object r0 = r0.get()     // Catch:{ all -> 0x00ad }
                if (r0 == 0) goto L_0x00a9
                com.appsflyer.internal.cp r1 = r6.AFInAppEventType     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = "Location"
                java.lang.String r0 = r3.getHeaderField(r0)     // Catch:{ all -> 0x00ad }
                r1.AFInAppEventType = r0     // Catch:{ all -> 0x00ad }
                com.appsflyer.internal.cp r5 = r6.AFInAppEventType     // Catch:{ all -> 0x00ad }
                java.lang.ref.WeakReference<android.content.Context> r0 = r6.AFKeystoreWrapper     // Catch:{ all -> 0x00ad }
                java.lang.Object r4 = r0.get()     // Catch:{ all -> 0x00ad }
                android.content.Context r4 = (android.content.Context) r4     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r5.AFInAppEventType     // Catch:{ all -> 0x00ad }
                if (r0 == 0) goto L_0x00a9
                android.content.Intent r2 = new android.content.Intent     // Catch:{ all -> 0x00ad }
                java.lang.String r1 = "android.intent.action.VIEW"
                java.lang.String r0 = r5.AFInAppEventType     // Catch:{ all -> 0x00ad }
                android.net.Uri r0 = android.net.Uri.parse(r0)     // Catch:{ all -> 0x00ad }
                r2.<init>(r1, r0)     // Catch:{ all -> 0x00ad }
                r0 = 268435456(0x10000000, float:2.5243549E-29)
                android.content.Intent r0 = r2.setFlags(r0)     // Catch:{ all -> 0x00ad }
                INVOKEVIRTUAL_com_appsflyer_share_CrossPromotionHelper$c_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivity(r4, r0)     // Catch:{ all -> 0x00ad }
                goto L_0x00a9
            L_0x0096:
                java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = "Cross promotion impressions success: "
                r1.<init>(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r6.values     // Catch:{ all -> 0x00ad }
                r1.append(r0)     // Catch:{ all -> 0x00ad }
                java.lang.String r0 = r1.toString()     // Catch:{ all -> 0x00ad }
                com.appsflyer.AFLogger.values((java.lang.String) r0, (boolean) r4)     // Catch:{ all -> 0x00ad }
            L_0x00a9:
                r3.disconnect()
                return
            L_0x00ad:
                r1 = move-exception
                goto L_0x00b1
            L_0x00af:
                r1 = move-exception
                r3 = r2
            L_0x00b1:
                java.lang.String r0 = r1.getMessage()     // Catch:{ all -> 0x00be }
                com.appsflyer.AFLogger.values((java.lang.String) r0, (java.lang.Throwable) r1)     // Catch:{ all -> 0x00be }
                if (r3 == 0) goto L_0x00bd
                r3.disconnect()
            L_0x00bd:
                return
            L_0x00be:
                r0 = move-exception
                if (r3 == 0) goto L_0x00c4
                r3.disconnect()
            L_0x00c4:
                throw r0
            */
            throw new UnsupportedOperationException("Method not decompiled: com.appsflyer.share.CrossPromotionHelper.c.run():void");
        }

        public static URLConnection INVOKEVIRTUAL_com_appsflyer_share_CrossPromotionHelper$c_com_ss_android_ugc_aweme_net_lancet_UrlConnectionLancet_openConnection(URL url) {
            9dq r0;
            9dq r02;
            9Vv LJIIL = 9dN.LJ.LJIIL(new 9Vv(url, (WebView) null, (JSONObject) null, 9Vw.CONTINUE));
            if (LJIIL.LJFF == 9Vw.INTERCEPT && LJIIL.LIZIZ != null) {
                URLConnection uRLConnection = (URLConnection) LJIIL.LIZIZ;
                if (uRLConnection instanceof HttpsURLConnection) {
                    r02 = new 9dq((HttpsURLConnection) uRLConnection);
                } else if (!(uRLConnection instanceof HttpURLConnection)) {
                    return uRLConnection;
                } else {
                    r02 = new 9dm((HttpURLConnection) uRLConnection);
                }
                return r02;
            } else if (LJIIL.LJFF != 9Vw.EXCEPTION || LJIIL.LJ == null) {
                URLConnection openConnection = url.openConnection();
                if (openConnection instanceof HttpsURLConnection) {
                    r0 = new 9dq((HttpsURLConnection) openConnection);
                } else if (!(openConnection instanceof HttpURLConnection)) {
                    return openConnection;
                } else {
                    r0 = new 9dm((HttpURLConnection) openConnection);
                }
                return r0;
            } else {
                throw LJIIL.LJ;
            }
        }

        public static void INVOKEVIRTUAL_com_appsflyer_share_CrossPromotionHelper$c_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivity(Context context, Intent intent) {
            3i8.LIZ(intent, context);
            context.startActivity(intent);
        }

        public c(String str, cp cpVar, Context context, boolean z) {
            this.values = str;
            this.AFInAppEventType = cpVar;
            this.AFKeystoreWrapper = new WeakReference<>(context);
            this.valueOf = z;
        }
    }

    public static void setUrl(Map<String, String> map) {
        for (Map.Entry next : map.entrySet()) {
            String str = (String) next.getValue();
            Object key = next.getKey();
            int hashCode = key.hashCode();
            if (hashCode != 96801) {
                if (hashCode == 120623625 && key.equals("impression")) {
                    AFKeystoreWrapper = str;
                }
            } else if (key.equals("app")) {
                co.valueOf = str;
            }
        }
    }

    public static void logAndOpenStore(Context context, String str, String str2) {
        logAndOpenStore(context, str, str2, (Map<String, String>) null);
    }

    public static void logCrossPromoteImpression(Context context, String str, String str2) {
        logCrossPromoteImpression(context, str, str2, (Map<String, String>) null);
    }

    public static void logAndOpenStore(Context context, String str, String str2, Map<String, String> map) {
        LinkGenerator AFInAppEventType = AFInAppEventType(context, str, str2, map, AnonymousClass0HH.LIZ(co.valueOf, new Object[]{AppsFlyerLib.getInstance().getHostPrefix(), ai.valueOf().getHostName()}));
        if (AppsFlyerProperties.getInstance().getBoolean("waitForCustomerId", false)) {
            AFLogger.values("CustomerUserId not set, track And Open Store is disabled", true);
            return;
        }
        if (map == null) {
            map = new HashMap<>();
        }
        map.put("af_campaign", str2);
        AppsFlyerLib.getInstance().logEvent(context, "af_cross_promotion", map);
        new Thread(new c(AFInAppEventType.generateLink(), new cp(), context, AppsFlyerLib.getInstance().isStopped())).start();
    }

    public static void logCrossPromoteImpression(Context context, String str, String str2, Map<String, String> map) {
        if (AppsFlyerProperties.getInstance().getBoolean("waitForCustomerId", false)) {
            AFLogger.values("CustomerUserId not set, Promote Impression is disabled", true);
            return;
        }
        new Thread(new c(AFInAppEventType(context, str, str2, map, AnonymousClass0HH.LIZ(AFKeystoreWrapper, new Object[]{AppsFlyerLib.getInstance().getHostPrefix(), ai.valueOf().getHostName()})).generateLink(), (cp) null, (Context) null, AppsFlyerLib.getInstance().isStopped())).start();
    }

    public static LinkGenerator AFInAppEventType(Context context, String str, String str2, Map<String, String> map, String str3) {
        LinkGenerator linkGenerator = new LinkGenerator("af_cross_promotion");
        linkGenerator.AFInAppEventParameterName = str3;
        linkGenerator.AFKeystoreWrapper = str;
        linkGenerator.addParameter("af_siteid", context.getPackageName());
        if (str2 != null) {
            linkGenerator.setCampaign(str2);
        }
        if (map != null) {
            linkGenerator.addParameters(map);
        }
        String string = AppsFlyerProperties.getInstance().getString("advertiserId");
        if (string != null) {
            linkGenerator.addParameter("advertising_id", string);
        }
        return linkGenerator;
    }
}
