package o;

import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.util.Clock;
import com.google.android.gms.common.util.DefaultClock;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Kr0 implements InterfaceC1619js0 {
    public static volatile Kr0 E;
    public int A;
    public int B;
    public final long D;
    public final Context a;
    public final boolean b;
    public final C2616uQ c;
    public final C1421ho0 d;
    public final C1617jr0 e;
    public final Nq0 f;
    public final Fr0 g;
    public final C2382ru0 h;
    public final C2574tv0 i;
    public final Eq0 j;
    public final Clock k;
    public final C2191pt0 l;
    public final Xs0 m;
    public final C2752vp0 n;

    /* renamed from: o, reason: collision with root package name */
    public final C0952ct0 f198o;
    public final String p;
    public Cq0 q;
    public Vt0 r;
    public Ho0 s;
    public C2944xq0 t;
    public C1047dt0 u;
    public Boolean w;
    public long x;
    public volatile Boolean y;
    public volatile boolean z;
    public boolean v = false;
    public final AtomicInteger C = new AtomicInteger(0);

    public Kr0(C2758vs0 c2758vs0) {
        InterfaceC2819wb0 c2914xb0;
        Context context;
        Preconditions.checkNotNull(c2758vs0);
        Context context2 = c2758vs0.a;
        C2616uQ c2616uQ = new C2616uQ(28);
        this.c = c2616uQ;
        Co0.j = c2616uQ;
        this.a = context2;
        this.b = c2758vs0.e;
        this.y = c2758vs0.b;
        this.p = c2758vs0.g;
        this.z = true;
        if (Gs0.h == null && context2 != null) {
            Object obj = Gs0.g;
            synchronized (obj) {
                try {
                    if (Gs0.h == null) {
                        synchronized (obj) {
                            C2473ss0 c2473ss0 = Gs0.h;
                            Context applicationContext = context2.getApplicationContext();
                            if (applicationContext == null) {
                                applicationContext = context2;
                            }
                            if (c2473ss0 == null || c2473ss0.a != applicationContext) {
                                if (c2473ss0 != null) {
                                    com.google.android.gms.internal.measurement.a.c();
                                    Ks0.a();
                                    synchronized (com.google.android.gms.internal.measurement.c.class) {
                                        try {
                                            com.google.android.gms.internal.measurement.c cVar = com.google.android.gms.internal.measurement.c.d;
                                            if (cVar != null && (context = cVar.a) != null && cVar.b != null && cVar.c) {
                                                context.getContentResolver().unregisterContentObserver(com.google.android.gms.internal.measurement.c.d.b);
                                            }
                                            com.google.android.gms.internal.measurement.c.d = null;
                                        } finally {
                                        }
                                    }
                                }
                                C0507To c0507To = new C0507To(applicationContext, 2);
                                if (c0507To instanceof Serializable) {
                                    c2914xb0 = new C2914xb0(c0507To);
                                } else {
                                    C3009yb0 c3009yb0 = new C3009yb0();
                                    c3009yb0.l = c0507To;
                                    c2914xb0 = c3009yb0;
                                }
                                Gs0.h = new C2473ss0(applicationContext, c2914xb0);
                                Gs0.i.incrementAndGet();
                            }
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                } finally {
                }
            }
        }
        Clock defaultClock = DefaultClock.getInstance();
        this.k = defaultClock;
        Long l = c2758vs0.f;
        this.D = l != null ? l.longValue() : defaultClock.currentTimeMillis();
        C1421ho0 c1421ho0 = new C1421ho0(this);
        c1421ho0.d = C0847bo0.a;
        this.d = c1421ho0;
        C1617jr0 c1617jr0 = new C1617jr0(this);
        c1617jr0.v();
        this.e = c1617jr0;
        Nq0 nq0 = new Nq0(this);
        nq0.v();
        this.f = nq0;
        C2574tv0 c2574tv0 = new C2574tv0(this);
        c2574tv0.v();
        this.i = c2574tv0;
        this.j = new Eq0(new Ir0(c2758vs0, this));
        this.n = new C2752vp0(this);
        C2191pt0 c2191pt0 = new C2191pt0(this);
        c2191pt0.u();
        this.l = c2191pt0;
        Xs0 xs0 = new Xs0(this);
        xs0.u();
        this.m = xs0;
        C2382ru0 c2382ru0 = new C2382ru0(this);
        c2382ru0.u();
        this.h = c2382ru0;
        C0952ct0 c0952ct0 = new C0952ct0(this);
        c0952ct0.v();
        this.f198o = c0952ct0;
        Fr0 fr0 = new Fr0(this);
        fr0.v();
        this.g = fr0;
        Dp0 dp0 = c2758vs0.d;
        boolean z = dp0 == null || dp0.m == 0;
        if (context2.getApplicationContext() instanceof Application) {
            k(xs0);
            if (((Kr0) xs0.a).a.getApplicationContext() instanceof Application) {
                Application application = (Application) ((Kr0) xs0.a).a.getApplicationContext();
                if (xs0.c == null) {
                    xs0.c = new C0308Lx(2, xs0);
                }
                if (z) {
                    application.unregisterActivityLifecycleCallbacks(xs0.c);
                    application.registerActivityLifecycleCallbacks(xs0.c);
                    Nq0 nq02 = ((Kr0) xs0.a).f;
                    l(nq02);
                    nq02.n.b("Registered activity lifecycle callback");
                }
            }
        } else {
            l(nq0);
            nq0.i.b("Application context is not an Application");
        }
        fr0.B(new RunnableC0890cD(27, this, c2758vs0, false));
    }

    public static final void i(Vp0 vp0) {
        if (vp0 == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static final void j(Eu0 eu0) {
        if (eu0 == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static final void k(AbstractC2090oq0 abstractC2090oq0) {
        if (abstractC2090oq0 == null) {
            throw new IllegalStateException("Component not created");
        }
        if (!abstractC2090oq0.b) {
            throw new IllegalStateException("Component not initialized: ".concat(String.valueOf(abstractC2090oq0.getClass())));
        }
    }

    public static final void l(AbstractC1429hs0 abstractC1429hs0) {
        if (abstractC1429hs0 == null) {
            throw new IllegalStateException("Component not created");
        }
        if (!abstractC1429hs0.b) {
            throw new IllegalStateException("Component not initialized: ".concat(String.valueOf(abstractC1429hs0.getClass())));
        }
    }

    public static Kr0 r(Context context, Dp0 dp0, Long l) {
        Bundle bundle;
        if (dp0 != null) {
            Bundle bundle2 = dp0.f87o;
            dp0 = new Dp0(dp0.l, dp0.m, dp0.n, bundle2, null);
        }
        Preconditions.checkNotNull(context);
        Preconditions.checkNotNull(context.getApplicationContext());
        if (E == null) {
            synchronized (Kr0.class) {
                try {
                    if (E == null) {
                        E = new Kr0(new C2758vs0(context, dp0, l));
                    }
                } finally {
                }
            }
        } else if (dp0 != null && (bundle = dp0.f87o) != null && bundle.containsKey("dataCollectionDefaultEnabled")) {
            Preconditions.checkNotNull(E);
            E.y = Boolean.valueOf(bundle.getBoolean("dataCollectionDefaultEnabled"));
        }
        Preconditions.checkNotNull(E);
        return E;
    }

    public final boolean a() {
        return g() == 0;
    }

    @Override // o.InterfaceC1619js0
    public final Nq0 b() {
        Nq0 nq0 = this.f;
        l(nq0);
        return nq0;
    }

    @Override // o.InterfaceC1619js0
    public final Fr0 c() {
        Fr0 fr0 = this.g;
        l(fr0);
        return fr0;
    }

    @Override // o.InterfaceC1619js0
    public final Context d() {
        return this.a;
    }

    @Override // o.InterfaceC1619js0
    public final Clock e() {
        return this.k;
    }

    @Override // o.InterfaceC1619js0
    public final C2616uQ f() {
        return this.c;
    }

    public final int g() {
        Fr0 fr0 = this.g;
        l(fr0);
        fr0.r();
        C1421ho0 c1421ho0 = this.d;
        if (c1421ho0.F()) {
            return 1;
        }
        l(fr0);
        fr0.r();
        if (!this.z) {
            return 8;
        }
        C1617jr0 c1617jr0 = this.e;
        j(c1617jr0);
        c1617jr0.r();
        Boolean boolValueOf = c1617jr0.w().contains("measurement_enabled") ? Boolean.valueOf(c1617jr0.w().getBoolean("measurement_enabled", true)) : null;
        if (boolValueOf != null) {
            return boolValueOf.booleanValue() ? 0 : 3;
        }
        C2616uQ c2616uQ = ((Kr0) c1421ho0.a).c;
        Boolean boolE = c1421ho0.E("firebase_analytics_collection_enabled");
        return boolE != null ? boolE.booleanValue() ? 0 : 4 : (this.y == null || this.y.booleanValue()) ? 0 : 7;
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x0083  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean h() {
        /*
            r7 = this;
            boolean r0 = r7.v
            if (r0 == 0) goto La5
            o.Fr0 r0 = r7.g
            l(r0)
            r0.r()
            java.lang.Boolean r0 = r7.w
            com.google.android.gms.common.util.Clock r1 = r7.k
            if (r0 == 0) goto L31
            long r2 = r7.x
            r4 = 0
            int r2 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
            if (r2 == 0) goto L31
            boolean r0 = r0.booleanValue()
            if (r0 != 0) goto L9e
            long r2 = r1.elapsedRealtime()
            long r4 = r7.x
            long r2 = r2 - r4
            long r2 = java.lang.Math.abs(r2)
            r4 = 1000(0x3e8, double:4.94E-321)
            int r0 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
            if (r0 <= 0) goto L9e
        L31:
            long r0 = r1.elapsedRealtime()
            r7.x = r0
            o.tv0 r0 = r7.i
            j(r0)
            java.lang.String r1 = "android.permission.INTERNET"
            boolean r1 = r0.O(r1)
            r2 = 0
            if (r1 == 0) goto L84
            java.lang.String r1 = "android.permission.ACCESS_NETWORK_STATE"
            boolean r1 = r0.O(r1)
            if (r1 == 0) goto L84
            android.content.Context r1 = r7.a
            com.google.android.gms.common.wrappers.PackageManagerWrapper r3 = com.google.android.gms.common.wrappers.Wrappers.packageManager(r1)
            boolean r3 = r3.isCallerInstantApp()
            r4 = 1
            if (r3 != 0) goto L83
            o.ho0 r3 = r7.d
            boolean r3 = r3.v()
            if (r3 != 0) goto L83
            boolean r3 = o.C2574tv0.h0(r1)
            if (r3 == 0) goto L84
            com.google.android.gms.common.internal.Preconditions.checkNotNull(r1)
            java.lang.String r3 = "com.google.android.gms.measurement.AppMeasurementJobService"
            android.content.pm.PackageManager r5 = r1.getPackageManager()     // Catch: android.content.pm.PackageManager.NameNotFoundException -> L84
            if (r5 != 0) goto L74
            goto L84
        L74:
            android.content.ComponentName r6 = new android.content.ComponentName     // Catch: android.content.pm.PackageManager.NameNotFoundException -> L84
            r6.<init>(r1, r3)     // Catch: android.content.pm.PackageManager.NameNotFoundException -> L84
            android.content.pm.ServiceInfo r1 = r5.getServiceInfo(r6, r2)     // Catch: android.content.pm.PackageManager.NameNotFoundException -> L84
            if (r1 == 0) goto L84
            boolean r1 = r1.enabled     // Catch: android.content.pm.PackageManager.NameNotFoundException -> L84
            if (r1 == 0) goto L84
        L83:
            r2 = r4
        L84:
            java.lang.Boolean r1 = java.lang.Boolean.valueOf(r2)
            r7.w = r1
            if (r2 == 0) goto L9e
            o.xq0 r1 = r7.q()
            java.lang.String r1 = r1.z()
            boolean r0 = r0.w(r1)
            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r0)
            r7.w = r0
        L9e:
            java.lang.Boolean r0 = r7.w
            boolean r0 = r0.booleanValue()
            return r0
        La5:
            java.lang.IllegalStateException r0 = new java.lang.IllegalStateException
            java.lang.String r1 = "AppMeasurement is not initialized"
            r0.<init>(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Kr0.h():boolean");
    }

    public final Eq0 m() {
        return this.j;
    }

    public final Cq0 n() {
        k(this.q);
        return this.q;
    }

    public final Vt0 o() {
        k(this.r);
        return this.r;
    }

    public final Ho0 p() {
        l(this.s);
        return this.s;
    }

    public final C2944xq0 q() {
        k(this.t);
        return this.t;
    }
}
