package p138.p176.p177.p242.p265.p266;

import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import p000.p001.p002.p003.p004.C0567;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.Ǐ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class RunnableC4772 implements Runnable {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final URL f14390;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C4753 f14391;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final String f14392;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Map<String, String> f14393;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final /* synthetic */ C4838 f14394;

    public RunnableC4772(C4838 c4838, String str, URL url, C4753 c4753) {
        this.f14394 = c4838;
        C0567.m1926(str);
        C0567.m1910(url);
        C0567.m1910(c4753);
        this.f14390 = url;
        this.f14391 = c4753;
        this.f14392 = str;
        this.f14393 = null;
    }

    @Override // java.lang.Runnable
    public final void run() throws Throwable {
        HttpURLConnection httpURLConnectionM8149;
        Map<String, List<String>> map;
        Map<String, List<String>> map2;
        Map<String, List<String>> headerFields;
        this.f14394.mo8006();
        int responseCode = 0;
        try {
            httpURLConnectionM8149 = this.f14394.m8149(this.f14390);
            try {
                if (this.f14393 != null) {
                    for (Map.Entry<String, String> entry : this.f14393.entrySet()) {
                        httpURLConnectionM8149.addRequestProperty(entry.getKey(), entry.getValue());
                    }
                }
                responseCode = httpURLConnectionM8149.getResponseCode();
                headerFields = httpURLConnectionM8149.getHeaderFields();
            } catch (IOException e) {
                e = e;
                map2 = null;
            } catch (Throwable th) {
                th = th;
                map = null;
            }
        } catch (IOException e2) {
            e = e2;
            httpURLConnectionM8149 = null;
            map2 = null;
        } catch (Throwable th2) {
            th = th2;
            httpURLConnectionM8149 = null;
            map = null;
        }
        try {
            byte[] bArrM8148 = C4838.m8148(httpURLConnectionM8149);
            httpURLConnectionM8149.disconnect();
            m8011(responseCode, null, bArrM8148, headerFields);
        } catch (IOException e3) {
            map2 = headerFields;
            e = e3;
            if (httpURLConnectionM8149 != null) {
                httpURLConnectionM8149.disconnect();
            }
            m8011(responseCode, e, null, map2);
        } catch (Throwable th3) {
            map = headerFields;
            th = th3;
            if (httpURLConnectionM8149 != null) {
                httpURLConnectionM8149.disconnect();
            }
            m8011(responseCode, null, null, map);
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8011(final int i, final Exception exc, final byte[] bArr, final Map<String, List<String>> map) {
        C4771 c4771Mo8163 = this.f14394.mo8163();
        Runnable runnable = new Runnable(this, i, exc, bArr, map) { // from class: ދ.ހ.֏.ހ.ބ.֏.Ȋ

            /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
            public final RunnableC4772 f14400;

            /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
            public final int f14401;

            /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
            public final Exception f14402;

            /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
            public final byte[] f14403;

            /* JADX INFO: renamed from: އ, reason: contains not printable characters */
            public final Map f14404;

            {
                this.f14400 = this;
                this.f14401 = i;
                this.f14402 = exc;
                this.f14403 = bArr;
                this.f14404 = map;
            }

            @Override // java.lang.Runnable
            public final void run() {
                List<ResolveInfo> listQueryIntentActivities;
                RunnableC4772 runnableC4772 = this.f14400;
                int i2 = this.f14401;
                Exception exc2 = this.f14402;
                byte[] bArr2 = this.f14403;
                C4974 c4974 = runnableC4772.f14391.f14283;
                boolean z = true;
                if (!((i2 == 200 || i2 == 204 || i2 == 304) && exc2 == null)) {
                    c4974.mo8165().f14447.m8036("Network Request for Deferred Deep Link failed. response, exception", Integer.valueOf(i2), exc2);
                    return;
                }
                c4974.m8501().f14668.m8204(true);
                if (bArr2.length == 0) {
                    c4974.mo8165().f14451.m8034("Deferred Deep Link response empty.");
                    return;
                }
                try {
                    JSONObject jSONObject = new JSONObject(new String(bArr2));
                    String strOptString = jSONObject.optString("deeplink", "");
                    String strOptString2 = jSONObject.optString("gclid", "");
                    double dOptDouble = jSONObject.optDouble("timestamp", 0.0d);
                    if (TextUtils.isEmpty(strOptString)) {
                        c4974.mo8165().f14451.m8034("Deferred Deep Link is empty.");
                        return;
                    }
                    C4887 c4887M8504 = c4974.m8504();
                    c4887M8504.mo8055();
                    if (TextUtils.isEmpty(strOptString) || (listQueryIntentActivities = c4887M8504.f14588.f15009.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", Uri.parse(strOptString)), 0)) == null || listQueryIntentActivities.isEmpty()) {
                        z = false;
                    }
                    if (!z) {
                        c4974.mo8165().f14447.m8036("Deferred Deep Link validation failed. gclid, deep link", strOptString2, strOptString);
                        return;
                    }
                    Bundle bundle = new Bundle();
                    bundle.putString("gclid", strOptString2);
                    bundle.putString("_cis", "ddp");
                    c4974.f15024.m7972("auto", "_cmp", bundle);
                    C4887 c4887M85042 = c4974.m8504();
                    if (TextUtils.isEmpty(strOptString) || !c4887M85042.m8256(strOptString, dOptDouble)) {
                        return;
                    }
                    c4887M85042.f14588.f15009.sendBroadcast(new Intent("android.google.analytics.action.DEEPLINK_ACTION"));
                } catch (JSONException e) {
                    c4974.mo8165().f14444.m8035("Failed to parse the Deferred Deep Link response. exception", e);
                }
            }
        };
        c4771Mo8163.m8482();
        C0567.m1910(runnable);
        c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnable, "Task exception on worker thread"));
    }
}
