package com.google.android.gms.measurement.internal;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.d5;
import com.google.android.gms.internal.measurement.f5;
import com.google.android.gms.internal.measurement.k5;
import com.google.android.gms.internal.measurement.v4;
import com.google.android.gms.internal.measurement.w4;
import com.google.android.gms.internal.measurement.z4;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes2.dex */
public final class m1 implements z1 {
    public static volatile m1 I;
    public volatile Boolean A;
    public final Boolean B;
    public final Boolean C;
    public volatile boolean D;
    public int E;
    public int F;
    public final long H;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f21749a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f21750b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f21751c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String f21752d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final boolean f21753e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final l8.g f21754f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final g f21755g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final y0 f21756h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final p0 f21757i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final j1 f21758j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final m3 f21759k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final n4 f21760l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final m0 f21761m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final i8.d f21762n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final w2 f21763o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final g2 f21764p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final s f21765q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final t2 f21766r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final String f21767s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public k0 f21768t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public a3 f21769u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public r f21770v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public l0 f21771w;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public Boolean f21773y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public long f21774z;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f21772x = false;
    public final AtomicInteger G = new AtomicInteger(0);

    public m1(e2 e2Var) {
        Bundle bundle;
        int i10 = 0;
        com.google.android.gms.common.internal.w.checkNotNull(e2Var);
        Context context = e2Var.f21559a;
        l8.g gVar = new l8.g(4, i10);
        this.f21754f = gVar;
        com.bumptech.glide.f.f5561a = gVar;
        this.f21749a = context;
        this.f21750b = e2Var.zzb;
        this.f21751c = e2Var.zzc;
        this.f21752d = e2Var.zzd;
        this.f21753e = e2Var.f21561c;
        this.A = e2Var.zze;
        this.f21767s = e2Var.zzj;
        this.D = true;
        com.google.android.gms.internal.measurement.e1 e1Var = e2Var.zzg;
        if (e1Var != null && (bundle = e1Var.zzg) != null) {
            Object obj = bundle.get("measurementEnabled");
            if (obj instanceof Boolean) {
                this.B = (Boolean) obj;
            }
            Object obj2 = e1Var.zzg.get("measurementDeactivated");
            if (obj2 instanceof Boolean) {
                this.C = (Boolean) obj2;
            }
        }
        if (d5.f20154h == null && context != null) {
            Object obj3 = d5.f20153g;
            synchronized (obj3) {
                try {
                    if (d5.f20154h == null) {
                        synchronized (obj3) {
                            w4 w4Var = d5.f20154h;
                            Context applicationContext = context.getApplicationContext();
                            applicationContext = applicationContext == null ? context : applicationContext;
                            if (w4Var == null || w4Var.f20510a != applicationContext) {
                                if (w4Var != null) {
                                    v4.c();
                                    k5.a();
                                    z4.c();
                                }
                                f5 f5Var = new f5();
                                f5Var.f20192a = applicationContext;
                                d5.f20154h = new w4(applicationContext, com.google.common.base.h.n(f5Var));
                                d5.f20156j.incrementAndGet();
                            }
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                } finally {
                }
            }
        }
        this.f21762n = i8.d.f26577a;
        Long l10 = e2Var.zzi;
        this.H = l10 != null ? l10.longValue() : System.currentTimeMillis();
        g gVar2 = new g(this);
        gVar2.f21589d = new f();
        this.f21755g = gVar2;
        y0 y0Var = new y0(this);
        y0Var.y();
        this.f21756h = y0Var;
        p0 p0Var = new p0(this);
        p0Var.y();
        this.f21757i = p0Var;
        n4 n4Var = new n4(this);
        n4Var.y();
        this.f21760l = n4Var;
        p1 p1Var = new p1();
        p1Var.f21843a = this;
        this.f21761m = new m0(p1Var);
        this.f21765q = new s(this);
        w2 w2Var = new w2(this);
        w2Var.E();
        this.f21763o = w2Var;
        g2 g2Var = new g2(this);
        g2Var.E();
        this.f21764p = g2Var;
        m3 m3Var = new m3(this);
        m3Var.E();
        this.f21759k = m3Var;
        t2 t2Var = new t2(this);
        t2Var.y();
        this.f21766r = t2Var;
        j1 j1Var = new j1(this);
        j1Var.y();
        this.f21758j = j1Var;
        com.google.android.gms.internal.measurement.e1 e1Var2 = e2Var.zzg;
        boolean z10 = true ^ ((e1Var2 == null || e1Var2.f20172b == 0) ? false : true);
        if (context.getApplicationContext() instanceof Application) {
            b(g2Var);
            if (g2Var.zza().getApplicationContext() instanceof Application) {
                Application application = (Application) g2Var.zza().getApplicationContext();
                if (g2Var.f21618c == null) {
                    g2Var.f21618c = new q2(g2Var);
                }
                if (z10) {
                    application.unregisterActivityLifecycleCallbacks(g2Var.f21618c);
                    application.registerActivityLifecycleCallbacks(g2Var.f21618c);
                    g2Var.zzj().f21842n.c("Registered activity lifecycle callback");
                }
            }
        } else {
            d(p0Var);
            p0Var.f21837i.c("Application context is not an Application");
        }
        j1Var.I(new s1(this, e2Var, i10));
    }

    public static m1 a(Context context, com.google.android.gms.internal.measurement.e1 e1Var, Long l10) {
        Bundle bundle;
        if (e1Var != null && (e1Var.zze == null || e1Var.zzf == null)) {
            e1Var = new com.google.android.gms.internal.measurement.e1(e1Var.f20171a, e1Var.f20172b, e1Var.f20173c, e1Var.zzd, null, null, e1Var.zzg, null);
        }
        com.google.android.gms.common.internal.w.checkNotNull(context);
        com.google.android.gms.common.internal.w.checkNotNull(context.getApplicationContext());
        if (I == null) {
            synchronized (m1.class) {
                try {
                    if (I == null) {
                        I = new m1(new e2(context, e1Var, l10));
                    }
                } finally {
                }
            }
        } else if (e1Var != null && (bundle = e1Var.zzg) != null && bundle.containsKey("dataCollectionDefaultEnabled")) {
            com.google.android.gms.common.internal.w.checkNotNull(I);
            I.A = Boolean.valueOf(e1Var.zzg.getBoolean("dataCollectionDefaultEnabled"));
        }
        com.google.android.gms.common.internal.w.checkNotNull(I);
        return I;
    }

    public static void b(x0 x0Var) {
        if (x0Var == null) {
            throw new IllegalStateException("Component not created");
        }
        if (!x0Var.f21971b) {
            throw new IllegalStateException("Component not initialized: ".concat(String.valueOf(x0Var.getClass())));
        }
    }

    public static void c(a2 a2Var) {
        if (a2Var == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static void d(a2 a2Var) {
        if (a2Var == null) {
            throw new IllegalStateException("Component not created");
        }
        if (!a2Var.f21470b) {
            throw new IllegalStateException("Component not initialized: ".concat(String.valueOf(a2Var.getClass())));
        }
    }

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

    /* JADX WARN: Removed duplicated region for block: B:12:0x0034  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00be  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean f() {
        boolean z10;
        Boolean boolValueOf;
        PackageManager packageManager;
        ServiceInfo serviceInfo;
        if (!this.f21772x) {
            throw new IllegalStateException("AppMeasurement is not initialized");
        }
        j1 j1Var = this.f21758j;
        d(j1Var);
        j1Var.w();
        Boolean bool = this.f21773y;
        i8.d dVar = this.f21762n;
        if (bool == null || this.f21774z == 0) {
            dVar.getClass();
            this.f21774z = SystemClock.elapsedRealtime();
            n4 n4Var = this.f21760l;
            c(n4Var);
            if (n4Var.x0("android.permission.INTERNET") && n4Var.x0("android.permission.ACCESS_NETWORK_STATE")) {
                Context context = this.f21749a;
                if (!j8.e.a(context).c() && !this.f21755g.M()) {
                    if (n4.d0(context)) {
                        com.google.android.gms.common.internal.w.checkNotNull(context);
                        try {
                            packageManager = context.getPackageManager();
                        } catch (PackageManager.NameNotFoundException unused) {
                        }
                        if (packageManager != null && (serviceInfo = packageManager.getServiceInfo(new ComponentName(context, "com.google.android.gms.measurement.AppMeasurementJobService"), 0)) != null) {
                            if (serviceInfo.enabled) {
                            }
                            boolValueOf = Boolean.valueOf(z10);
                            this.f21773y = boolValueOf;
                            if (boolValueOf.booleanValue()) {
                            }
                        }
                    }
                    z10 = false;
                    boolValueOf = Boolean.valueOf(z10);
                    this.f21773y = boolValueOf;
                    if (boolValueOf.booleanValue()) {
                    }
                }
                z10 = true;
                boolValueOf = Boolean.valueOf(z10);
                this.f21773y = boolValueOf;
                if (boolValueOf.booleanValue()) {
                }
            } else {
                z10 = false;
                boolValueOf = Boolean.valueOf(z10);
                this.f21773y = boolValueOf;
                if (boolValueOf.booleanValue()) {
                    String strH = j().H();
                    l0 l0VarJ = j();
                    l0VarJ.D();
                    if (!n4Var.g0(strH, l0VarJ.f21729m)) {
                        l0 l0VarJ2 = j();
                        l0VarJ2.D();
                        boolean z11 = TextUtils.isEmpty(l0VarJ2.f21729m) ? false : true;
                        this.f21773y = Boolean.valueOf(z11);
                    }
                }
            }
        } else if (!bool.booleanValue()) {
            dVar.getClass();
            if (Math.abs(SystemClock.elapsedRealtime() - this.f21774z) > 1000) {
            }
        }
        return this.f21773y.booleanValue();
    }

    public final int g() {
        j1 j1Var = this.f21758j;
        d(j1Var);
        j1Var.w();
        Boolean boolH = this.f21755g.H("firebase_analytics_collection_deactivated");
        if (boolH != null && boolH.booleanValue()) {
            return 1;
        }
        Boolean bool = this.C;
        if (bool != null && bool.booleanValue()) {
            return 2;
        }
        j1 j1Var2 = this.f21758j;
        d(j1Var2);
        j1Var2.w();
        if (!this.D) {
            return 8;
        }
        y0 y0Var = this.f21756h;
        c(y0Var);
        y0Var.w();
        Boolean boolValueOf = y0Var.F().contains("measurement_enabled") ? Boolean.valueOf(y0Var.F().getBoolean("measurement_enabled", true)) : null;
        if (boolValueOf != null) {
            return boolValueOf.booleanValue() ? 0 : 3;
        }
        Boolean boolH2 = this.f21755g.H("firebase_analytics_collection_enabled");
        if (boolH2 != null) {
            return boolH2.booleanValue() ? 0 : 4;
        }
        Boolean bool2 = this.B;
        return bool2 != null ? bool2.booleanValue() ? 0 : 5 : (this.A == null || this.A.booleanValue()) ? 0 : 7;
    }

    public final s h() {
        s sVar = this.f21765q;
        if (sVar != null) {
            return sVar;
        }
        throw new IllegalStateException("Component not created");
    }

    public final r i() {
        d(this.f21770v);
        return this.f21770v;
    }

    public final l0 j() {
        b(this.f21771w);
        return this.f21771w;
    }

    public final m0 k() {
        return this.f21761m;
    }

    public final a3 l() {
        b(this.f21769u);
        return this.f21769u;
    }

    public final void m() {
        c(this.f21760l);
    }

    @Override // com.google.android.gms.measurement.internal.z1
    public final Context zza() {
        return this.f21749a;
    }

    @Override // com.google.android.gms.measurement.internal.z1
    public final i8.c zzb() {
        return this.f21762n;
    }

    @Override // com.google.android.gms.measurement.internal.z1
    public final l8.g zzd() {
        return this.f21754f;
    }

    @Override // com.google.android.gms.measurement.internal.z1
    public final p0 zzj() {
        p0 p0Var = this.f21757i;
        d(p0Var);
        return p0Var;
    }

    @Override // com.google.android.gms.measurement.internal.z1
    public final j1 zzl() {
        j1 j1Var = this.f21758j;
        d(j1Var);
        return j1Var;
    }
}
