package defpackage;

import android.app.Application;
import android.app.BroadcastOptions;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: renamed from: ˈᵨᵨ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1103 implements InterfaceC1959 {

    /* JADX INFO: renamed from: ᵡᵶᵬʤ, reason: contains not printable characters */
    public static volatile C1103 f4699;

    /* JADX INFO: renamed from: ʽᵡᵢᵾ, reason: contains not printable characters */
    public C2403 f4700;

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public final ᵠʽᵲ f4701;

    /* JADX INFO: renamed from: ʿᵿʽᵞ, reason: contains not printable characters */
    public final long f4702;

    /* JADX INFO: renamed from: ˀᵗ, reason: contains not printable characters */
    public int f4703;

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public final C3606 f4704;

    /* JADX INFO: renamed from: ˁʢᵛ, reason: contains not printable characters */
    public volatile boolean f4705;

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public final C3468 f4706;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final C1961 f4707;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public final C4799 f4709;

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public volatile Boolean f4710;

    /* JADX INFO: renamed from: ˊᵡᵗʨ, reason: contains not printable characters */
    public C4421 f4711;

    /* JADX INFO: renamed from: ˊᵾʽʼ, reason: contains not printable characters */
    public final String f4712;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final Context f4713;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final C1584 f4714;

    /* JADX INFO: renamed from: ˏᵩʨ, reason: contains not printable characters */
    public int f4715;

    /* JADX INFO: renamed from: ˑʢ, reason: contains not printable characters */
    public C2303 f4716;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final C2063 f4717;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final ᵖˊʨ f4718;

    /* JADX INFO: renamed from: ᵛˑﹳ, reason: contains not printable characters */
    public C1618 f4720;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final boolean f4721;

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public long f4722;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final C1533 f4723;

    /* JADX INFO: renamed from: ᵡᵶ, reason: contains not printable characters */
    public final long f4724;

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public Boolean f4725;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final C3691 f4726;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final C3740 f4727;

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public C4883 f4728;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final C3485 f4729;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public final C3335 f4730;

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public boolean f4708 = false;

    /* JADX INFO: renamed from: ᵛˀˊ, reason: contains not printable characters */
    public final AtomicInteger f4719 = new AtomicInteger(0);

    public C1103(C0348 c0348) {
        Context applicationContext;
        long jCurrentTimeMillis;
        long jElapsedRealtime;
        Context context = c0348.f2108;
        ᵖˊʨ r2 = new ᵖˊʨ(17);
        this.f4718 = r2;
        ᵷᵸˁ.ˊᵙᵾᵲ = r2;
        this.f4713 = context;
        this.f4721 = c0348.f2107;
        this.f4710 = c0348.f2104;
        this.f4712 = c0348.f2105;
        int i = 1;
        this.f4705 = true;
        if (AbstractC5464.f20691 == null && context != null) {
            Object obj = AbstractC5464.f20693;
            synchronized (obj) {
                try {
                    if (AbstractC5464.f20691 == null) {
                        synchronized (obj) {
                            C0389 c0389 = AbstractC5464.f20691;
                            Context applicationContext2 = context.getApplicationContext();
                            if (applicationContext2 == null) {
                                applicationContext2 = context;
                            }
                            if (c0389 == null || c0389.f2234 != applicationContext2) {
                                if (c0389 != null) {
                                    Iterator it = AbstractC2000.f7918.values().iterator();
                                    if (it.hasNext()) {
                                        if (it.next() != null) {
                                            throw new ClassCastException();
                                        }
                                        throw null;
                                    }
                                    AbstractC2667.m6473();
                                }
                                AbstractC5464.f20691 = new C0389(applicationContext2, ᵽˊᵘᵬ.ˊᵙᵾᵲ(new C4471(applicationContext2, 2)));
                                AbstractC5464.f20692.incrementAndGet();
                            }
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                } finally {
                }
            }
        }
        this.f4701 = ᵠʽᵲ.ᵯᵷʽ;
        C2585 c2585 = new C2585(context, AbstractC4808.f18295, InterfaceC4183.f15960, C1601.f6415);
        String strConcat = "com.google.android.gms.measurement#".concat(String.valueOf(context.getPackageName()));
        C5172 c5172M10696 = C5172.m10696();
        c5172M10696.f19474 = new ʽᵺᴵ(13, strConcat, new String[0], false);
        c2585.m5968(0, c5172M10696.m10703());
        AtomicReference atomicReference = C5429.f20597;
        if (atomicReference.get() == null) {
            try {
                applicationContext = context.getApplicationContext();
            } catch (NullPointerException unused) {
                C5429.m11044();
                ᵽˊᵘᵬ.ᵶˇᵱ(Level.WARNING, (Executor) C5429.f20594.get(), (Exception) null, "context.getApplicationContext() yielded NullPointerException", new Object[0]);
                applicationContext = null;
            }
            if (applicationContext != null) {
                while (!atomicReference.compareAndSet(null, applicationContext) && atomicReference.get() == null) {
                }
            }
        }
        Long l = c0348.f2111;
        if (l != null) {
            jCurrentTimeMillis = l.longValue();
        } else {
            this.f4701.getClass();
            jCurrentTimeMillis = System.currentTimeMillis();
        }
        this.f4702 = jCurrentTimeMillis;
        Long l2 = c0348.f2109;
        if (l2 != null) {
            jElapsedRealtime = l2.longValue();
        } else {
            this.f4701.getClass();
            jElapsedRealtime = SystemClock.elapsedRealtime();
        }
        this.f4724 = jElapsedRealtime;
        C3691 c3691 = new C3691(this);
        c3691.f14069 = C5314.f20051;
        this.f4726 = c3691;
        C3740 c3740 = new C3740(this);
        c3740.m9447();
        this.f4727 = c3740;
        C3485 c3485 = new C3485(this);
        c3485.m9447();
        this.f4729 = c3485;
        C3335 c3335 = new C3335(this);
        c3335.m9447();
        this.f4730 = c3335;
        this.f4717 = new C2063(new ᵷˇ(c0348, this));
        this.f4706 = new C3468(this);
        C1533 c1533 = new C1533(this);
        c1533.m5700();
        this.f4723 = c1533;
        C4799 c4799 = new C4799(this);
        c4799.m5700();
        this.f4709 = c4799;
        C1584 c1584 = new C1584(this);
        c1584.m5700();
        this.f4714 = c1584;
        C3606 c3606 = new C3606(this);
        c3606.m9447();
        this.f4704 = c3606;
        C1961 c1961 = new C1961(this);
        c1961.m9447();
        this.f4707 = c1961;
        C1216 c1216 = c0348.f2110;
        boolean z = c1216 == null || c1216.f5150 == 0;
        if (this.f4713.getApplicationContext() instanceof Application) {
            m3565(c4799);
            if (((C1103) ((ᵜᵪʾ) c4799).ˌᴵ).f4713.getApplicationContext() instanceof Application) {
                Application application = (Application) ((C1103) ((ᵜᵪʾ) c4799).ˌᴵ).f4713.getApplicationContext();
                if (c4799.f18269 == null) {
                    c4799.f18269 = new C3209(i, c4799);
                }
                if (z) {
                    application.unregisterActivityLifecycleCallbacks(c4799.f18269);
                    application.registerActivityLifecycleCallbacks(c4799.f18269);
                    C3485 c34852 = ((C1103) ((ᵜᵪʾ) c4799).ˌᴵ).f4729;
                    m3564(c34852);
                    c34852.f13414.m4476("Registered activity lifecycle callback");
                }
            }
        } else {
            m3564(c3485);
            c3485.f13424.m4476("Application context is not an Application");
        }
        c1961.m5246(new ᵟᵰᵕ(11, this, c0348, false));
    }

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public static C1103 m3563(Context context, C1216 c1216, Long l, Long l2) {
        Bundle bundle;
        if (c1216 != null) {
            Bundle bundle2 = c1216.f5151;
            c1216 = new C1216(c1216.f5148, c1216.f5150, c1216.f5149, bundle2, null);
        }
        ᵘᵞʿⁱ.ᵶᵥᵝ(context);
        ᵘᵞʿⁱ.ᵶᵥᵝ(context.getApplicationContext());
        if (f4699 == null) {
            synchronized (C1103.class) {
                try {
                    if (f4699 == null) {
                        f4699 = new C1103(new C0348(context, c1216, l, l2));
                    }
                } finally {
                }
            }
        } else if (c1216 != null && (bundle = c1216.f5151) != null && bundle.containsKey("dataCollectionDefaultEnabled")) {
            ᵘᵞʿⁱ.ᵶᵥᵝ(f4699);
            f4699.f4710 = Boolean.valueOf(bundle.getBoolean("dataCollectionDefaultEnabled"));
        }
        ᵘᵞʿⁱ.ᵶᵥᵝ(f4699);
        return f4699;
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public static final void m3564(AbstractC4440 abstractC4440) {
        if (abstractC4440 == null) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not created");
        } else {
            if (abstractC4440.f16934) {
                return;
            }
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not initialized: ".concat(String.valueOf(abstractC4440.getClass())));
        }
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static final void m3565(AbstractC2191 abstractC2191) {
        if (abstractC2191 == null) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not created");
        } else {
            if (abstractC2191.f8701) {
                return;
            }
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not initialized: ".concat(String.valueOf(abstractC2191.getClass())));
        }
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public static final void m3566(AbstractC2428 abstractC2428) {
        if (abstractC2428 != null) {
            return;
        }
        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not created");
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public static final void m3567(ᵜᵪʾ r0) {
        if (r0 != null) {
            return;
        }
        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Component not created");
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean m3568() {
        return m3574() == 0;
    }

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public final C2303 m3569() {
        m3565(this.f4716);
        return this.f4716;
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0029  */
    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m3570(int i, Throwable th, byte[] bArr) {
        C3485 c3485;
        C3485 c34852;
        int i2 = i;
        C3485 c34853 = this.f4729;
        if (i2 == 200 || i2 == 204) {
            if (th == null) {
                C3740 c3740 = this.f4727;
                m3567(c3740);
                c3740.f14209.m3015(true);
                if (bArr == null || bArr.length == 0) {
                    m3564(c34853);
                    c34853.f13416.m4476("Deferred Deep Link response empty.");
                    return;
                }
                try {
                    JSONObject jSONObject = new JSONObject(new String(bArr));
                    String strOptString = jSONObject.optString("deeplink", "");
                    if (TextUtils.isEmpty(strOptString)) {
                        m3564(c34853);
                        c34853.f13416.m4476("Deferred Deep Link is empty.");
                        return;
                    }
                    String strOptString2 = jSONObject.optString("gclid", "");
                    String strOptString3 = jSONObject.optString("gbraid", "");
                    String strOptString4 = jSONObject.optString("gad_source", "");
                    double dOptDouble = jSONObject.optDouble("timestamp", 0.0d);
                    Bundle bundle = new Bundle();
                    C3335 c3335 = this.f4730;
                    m3567(c3335);
                    C1103 c1103 = (C1103) ((ᵜᵪʾ) c3335).ˌᴵ;
                    if (TextUtils.isEmpty(strOptString)) {
                        c34852 = c34853;
                    } else {
                        Context context = c1103.f4713;
                        c34852 = c34853;
                        try {
                            List<ResolveInfo> listQueryIntentActivities = context.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", Uri.parse(strOptString)), 0);
                            if (listQueryIntentActivities != null && !listQueryIntentActivities.isEmpty()) {
                                if (!TextUtils.isEmpty(strOptString3)) {
                                    bundle.putString("gbraid", strOptString3);
                                }
                                if (!TextUtils.isEmpty(strOptString4)) {
                                    bundle.putString("gad_source", strOptString4);
                                }
                                bundle.putString("gclid", strOptString2);
                                bundle.putString("_cis", "ddp");
                                this.f4709.m10013("auto", "_cmp", bundle);
                                if (TextUtils.isEmpty(strOptString)) {
                                    return;
                                }
                                try {
                                    SharedPreferences.Editor editorEdit = context.getSharedPreferences("google.analytics.deferred.deeplink.prefs", 0).edit();
                                    editorEdit.putString("deeplink", strOptString);
                                    editorEdit.putLong("timestamp", Double.doubleToRawLongBits(dOptDouble));
                                    if (editorEdit.commit()) {
                                        Intent intent = new Intent("android.google.analytics.action.DEEPLINK_ACTION");
                                        Context context2 = c1103.f4713;
                                        if (Build.VERSION.SDK_INT < 34) {
                                            context2.sendBroadcast(intent);
                                            return;
                                        } else {
                                            context2.sendBroadcast(intent, null, BroadcastOptions.makeBasic().setShareIdentityEnabled(true).toBundle());
                                            return;
                                        }
                                    }
                                    return;
                                } catch (RuntimeException e) {
                                    C3485 c34854 = ((C1103) ((ᵜᵪʾ) c3335).ˌᴵ).f4729;
                                    m3564(c34854);
                                    c34854.f13423.m4474(e, "Failed to persist Deferred Deep Link. exception");
                                    return;
                                }
                            }
                        } catch (JSONException e2) {
                            e = e2;
                            c3485 = c34852;
                            m3564(c3485);
                            c3485.f13423.m4474(e, "Failed to parse the Deferred Deep Link response. exception");
                            return;
                        }
                    }
                    m3564(c34852);
                    c3485 = c34852;
                    try {
                        c3485.f13424.m4477("Deferred Deep Link validation failed. gclid, gbraid, deep link", strOptString2, strOptString3, strOptString);
                        return;
                    } catch (JSONException e3) {
                        e = e3;
                        m3564(c3485);
                        c3485.f13423.m4474(e, "Failed to parse the Deferred Deep Link response. exception");
                        return;
                    }
                } catch (JSONException e4) {
                    e = e4;
                    c3485 = c34853;
                }
            }
        } else if (i2 == 304) {
            i2 = 304;
            if (th == null) {
            }
        }
        m3564(c34853);
        c34853.f13424.m4475("Network Request for Deferred Deep Link failed. response, exception", Integer.valueOf(i2), th);
    }

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public final C2063 m3571() {
        return this.f4717;
    }

    @Override // defpackage.InterfaceC1959
    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C3485 mo3572() {
        C3485 c3485 = this.f4729;
        m3564(c3485);
        return c3485;
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final C1618 m3573() {
        m3565(this.f4720);
        return this.f4720;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final int m3574() {
        C1961 c1961 = this.f4707;
        m3564(c1961);
        c1961.m5243();
        C3691 c3691 = this.f4726;
        if (c3691.m8303()) {
            return 1;
        }
        m3564(c1961);
        c1961.m5243();
        if (!this.f4705) {
            return 8;
        }
        C3740 c3740 = this.f4727;
        m3567(c3740);
        c3740.ˈᵲᵢ();
        Boolean boolValueOf = c3740.m8407().contains("measurement_enabled") ? Boolean.valueOf(c3740.m8407().getBoolean("measurement_enabled", true)) : null;
        if (boolValueOf != null) {
            return boolValueOf.booleanValue() ? 0 : 3;
        }
        ᵖˊʨ r0 = ((C1103) ((ᵜᵪʾ) c3691).ˌᴵ).f4718;
        Boolean boolM8312 = c3691.m8312("firebase_analytics_collection_enabled");
        return boolM8312 != null ? boolM8312.booleanValue() ? 0 : 4 : (this.f4710 == null || this.f4710.booleanValue()) ? 0 : 7;
    }

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public final C4421 m3575() {
        m3565(this.f4711);
        return this.f4711;
    }

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public final C4883 m3576() {
        m3564(this.f4728);
        return this.f4728;
    }

    @Override // defpackage.InterfaceC1959
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final ᵖˊʨ mo3577() {
        return this.f4718;
    }

    @Override // defpackage.InterfaceC1959
    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final C1961 mo3578() {
        C1961 c1961 = this.f4707;
        m3564(c1961);
        return c1961;
    }

    @Override // defpackage.InterfaceC1959
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final ᵠʽᵲ mo3579() {
        return this.f4701;
    }

    @Override // defpackage.InterfaceC1959
    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final Context mo3580() {
        return this.f4713;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0035  */
    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m3581() {
        boolean z = false;
        if (!this.f4708) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("AppMeasurement is not initialized");
            return false;
        }
        C1961 c1961 = this.f4707;
        m3564(c1961);
        c1961.m5243();
        Boolean bool = this.f4725;
        ᵠʽᵲ r2 = this.f4701;
        if (bool == null || this.f4722 == 0) {
            r2.getClass();
            this.f4722 = SystemClock.elapsedRealtime();
            C3335 c3335 = this.f4730;
            m3567(c3335);
            if (c3335.m7643("android.permission.INTERNET") && c3335.m7643("android.permission.ACCESS_NETWORK_STATE")) {
                Context context = this.f4713;
                if (C1593.m4436(context).m9253() || this.f4726.m8313() || (C3335.m7619(context) && C3335.m7613(context))) {
                    z = true;
                }
            }
            this.f4725 = Boolean.valueOf(z);
            if (z) {
                this.f4725 = Boolean.valueOf(c3335.m7635(m3569().m5931()));
            }
        } else if (!bool.booleanValue()) {
            r2.getClass();
            if (Math.abs(SystemClock.elapsedRealtime() - this.f4722) > 1000) {
            }
        }
        return this.f4725.booleanValue();
    }
}
