package d3;

import P2.C0253j;
import android.app.Application;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.internal.measurement.C0722x1;
import com.google.android.gms.internal.measurement.C0727y1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: renamed from: d3.r0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0817r0 implements B0 {
    public static volatile C0817r0 X;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final A1 f12121A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final W1 f12122B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final T f12123C;
    public final T2.a D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final C0795j1 f12124E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final Y0 f12125F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final C0764A f12126G;
    public final C0774c1 H;

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

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public S f12128J;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public C0824t1 f12129K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public C0814q f12130L;

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public P f12131M;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public C0777d1 f12132N;

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

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

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public volatile Boolean f12136R;

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    public volatile boolean f12137S;

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public int f12138T;

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public int f12139U;

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public final long f12141W;

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

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

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

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

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

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final C0253j f12147v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final C0784g f12148w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final C0785g0 f12149x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final Z f12150y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C0815q0 f12151z;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public boolean f12133O = false;

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    public final AtomicInteger f12140V = new AtomicInteger(0);

    /* JADX WARN: Code restructure failed: missing block: B:27:0x007d, code lost:
    
        r11 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x0082, code lost:
    
        throw r11;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0817r0(I0 i02) {
        Context context = i02.f11601a;
        C0253j c0253j = new C0253j(24);
        this.f12147v = c0253j;
        G0.f11472k = c0253j;
        this.f12142q = context;
        this.f12143r = i02.f11602b;
        this.f12144s = i02.f11603c;
        this.f12145t = i02.f11604d;
        this.f12146u = i02.f11608h;
        this.f12136R = i02.f11605e;
        this.f12127I = i02.f11609j;
        this.f12137S = true;
        if (com.google.android.gms.internal.measurement.I1.f9606h == null && context != null) {
            Object obj = com.google.android.gms.internal.measurement.I1.f9605g;
            synchronized (obj) {
                try {
                    if (com.google.android.gms.internal.measurement.I1.f9606h == null) {
                        synchronized (obj) {
                            C0722x1 c0722x1 = com.google.android.gms.internal.measurement.I1.f9606h;
                            final Context applicationContext = context.getApplicationContext();
                            if (applicationContext == null) {
                                applicationContext = context;
                            }
                            if (c0722x1 == null || c0722x1.f10062a != applicationContext) {
                                if (c0722x1 != null) {
                                    C0727y1.c();
                                    com.google.android.gms.internal.measurement.J1.a();
                                    com.google.android.gms.internal.measurement.B1.m();
                                }
                                com.google.android.gms.internal.measurement.I1.f9606h = new C0722x1(applicationContext, W2.g.A(new B3.l() { // from class: com.google.android.gms.internal.measurement.G1
                                    /* JADX WARN: Removed duplicated region for block: B:20:0x003a A[Catch: all -> 0x0026, TryCatch #3 {all -> 0x0026, all -> 0x0073, blocks: (B:6:0x000b, B:8:0x000f, B:10:0x001d, B:20:0x003a, B:75:0x0164, B:15:0x0029, B:17:0x0031, B:21:0x003f, B:23:0x0045, B:25:0x004b, B:26:0x004f, B:74:0x0160, B:76:0x0167, B:77:0x016a, B:78:0x016b, B:27:0x0053, B:29:0x0057, B:30:0x0064, B:32:0x006a, B:38:0x0080, B:40:0x0086, B:41:0x008c, B:61:0x0144, B:62:0x0147, B:70:0x0157, B:69:0x0154, B:71:0x0158, B:72:0x015d, B:73:0x015e, B:33:0x0070, B:37:0x0077), top: B:88:0x000b }] */
                                    @Override // B3.l
                                    /*
                                        Code decompiled incorrectly, please refer to instructions dump.
                                    */
                                    public final Object get() {
                                        B3.g gVar;
                                        StrictMode.ThreadPolicy threadPolicyAllowThreadDiskReads;
                                        B3.g jVar;
                                        B3.g jVar2;
                                        Object obj2 = I1.f9605g;
                                        Context contextCreateDeviceProtectedStorageContext = applicationContext;
                                        B3.g gVar2 = C1.f9564a;
                                        if (gVar2 != null) {
                                            return gVar2;
                                        }
                                        synchronized (C1.class) {
                                            try {
                                                gVar = C1.f9564a;
                                                if (gVar == null) {
                                                    String str = Build.TYPE;
                                                    String str2 = Build.TAGS;
                                                    q.e eVar = E1.f9586a;
                                                    if (str.equals("eng") || str.equals("userdebug")) {
                                                        if (str2.contains("dev-keys") || str2.contains("test-keys")) {
                                                            if (AbstractC0717w1.a() && !contextCreateDeviceProtectedStorageContext.isDeviceProtectedStorage()) {
                                                                contextCreateDeviceProtectedStorageContext = contextCreateDeviceProtectedStorageContext.createDeviceProtectedStorageContext();
                                                            }
                                                            threadPolicyAllowThreadDiskReads = StrictMode.allowThreadDiskReads();
                                                            StrictMode.allowThreadDiskWrites();
                                                            try {
                                                                File file = new File(contextCreateDeviceProtectedStorageContext.getDir("phenotype_hermetic", 0), "overrides.txt");
                                                                jVar = file.exists() ? new B3.j(file) : B3.a.f971q;
                                                            } catch (RuntimeException e8) {
                                                                Log.e("HermeticFileOverrides", "no data dir", e8);
                                                                jVar = B3.a.f971q;
                                                            }
                                                            if (jVar.b()) {
                                                                File file2 = (File) jVar.a();
                                                                try {
                                                                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file2)));
                                                                    try {
                                                                        q.i iVar = new q.i(0);
                                                                        HashMap map = new HashMap();
                                                                        while (true) {
                                                                            String line = bufferedReader.readLine();
                                                                            if (line == null) {
                                                                                break;
                                                                            }
                                                                            String[] strArrSplit = line.split(" ", 3);
                                                                            if (strArrSplit.length != 3) {
                                                                                Log.e("HermeticFileOverrides", "Invalid: " + line);
                                                                            } else {
                                                                                String str3 = new String(strArrSplit[0]);
                                                                                String strDecode = Uri.decode(new String(strArrSplit[1]));
                                                                                String strDecode2 = (String) map.get(strArrSplit[2]);
                                                                                if (strDecode2 == null) {
                                                                                    String str4 = new String(strArrSplit[2]);
                                                                                    strDecode2 = Uri.decode(str4);
                                                                                    if (strDecode2.length() < 1024 || strDecode2 == str4) {
                                                                                        map.put(str4, strDecode2);
                                                                                    }
                                                                                }
                                                                                q.i iVar2 = (q.i) iVar.get(str3);
                                                                                if (iVar2 == null) {
                                                                                    iVar2 = new q.i(0);
                                                                                    iVar.put(str3, iVar2);
                                                                                }
                                                                                iVar2.put(strDecode, strDecode2);
                                                                            }
                                                                        }
                                                                        Log.w("HermeticFileOverrides", "Parsed " + file2.toString() + " for Android package " + contextCreateDeviceProtectedStorageContext.getPackageName());
                                                                        C0732z1 c0732z1 = new C0732z1(iVar);
                                                                        bufferedReader.close();
                                                                        jVar2 = new B3.j(c0732z1);
                                                                    } finally {
                                                                        try {
                                                                            bufferedReader.close();
                                                                        } catch (Throwable th) {
                                                                            th.addSuppressed(th);
                                                                        }
                                                                    }
                                                                } catch (IOException e9) {
                                                                    throw new RuntimeException(e9);
                                                                }
                                                            } else {
                                                                jVar2 = B3.a.f971q;
                                                            }
                                                            StrictMode.setThreadPolicy(threadPolicyAllowThreadDiskReads);
                                                            gVar = jVar2;
                                                        } else {
                                                            gVar = B3.a.f971q;
                                                        }
                                                        C1.f9564a = gVar;
                                                    }
                                                }
                                            } catch (Throwable th2) {
                                                StrictMode.setThreadPolicy(threadPolicyAllowThreadDiskReads);
                                                throw th2;
                                            } finally {
                                            }
                                        }
                                        return gVar;
                                    }
                                }));
                                com.google.android.gms.internal.measurement.I1.i.incrementAndGet();
                            }
                        }
                    }
                } finally {
                }
            }
        }
        this.D = T2.a.f6551a;
        Long l8 = i02.i;
        this.f12141W = l8 != null ? l8.longValue() : System.currentTimeMillis();
        C0784g c0784g = new C0784g(this);
        c0784g.f11954t = new x3.e(24);
        this.f12148w = c0784g;
        C0785g0 c0785g0 = new C0785g0(this);
        c0785g0.H();
        this.f12149x = c0785g0;
        Z z8 = new Z(this);
        z8.H();
        this.f12150y = z8;
        W1 w12 = new W1(this);
        w12.H();
        this.f12122B = w12;
        this.f12123C = new T(new C0791i0(this, 2));
        this.f12126G = new C0764A(this);
        C0795j1 c0795j1 = new C0795j1(this);
        c0795j1.G();
        this.f12124E = c0795j1;
        Y0 y02 = new Y0(this);
        y02.G();
        this.f12125F = y02;
        A1 a1 = new A1(this);
        a1.G();
        this.f12121A = a1;
        C0774c1 c0774c1 = new C0774c1(this);
        c0774c1.H();
        this.H = c0774c1;
        C0815q0 c0815q0 = new C0815q0(this);
        c0815q0.H();
        this.f12151z = c0815q0;
        com.google.android.gms.internal.measurement.U u8 = i02.f11607g;
        boolean z9 = u8 == null || u8.f9686r == 0;
        if (context.getApplicationContext() instanceof Application) {
            j(y02);
            if (((C0817r0) y02.f5146q).f12142q.getApplicationContext() instanceof Application) {
                Application application = (Application) ((C0817r0) y02.f5146q).f12142q.getApplicationContext();
                if (y02.f11853s == null) {
                    y02.f11853s = new X0(y02);
                }
                if (z9) {
                    application.unregisterActivityLifecycleCallbacks(y02.f11853s);
                    application.registerActivityLifecycleCallbacks(y02.f11853s);
                    Z z10 = ((C0817r0) y02.f5146q).f12150y;
                    k(z10);
                    z10.D.b("Registered activity lifecycle callback");
                }
            }
        } else {
            k(z8);
            z8.f11878y.b("Application context is not an Application");
        }
        c0815q0.O(new G3.b(this, i02, 9, false));
    }

    public static final void h(AbstractC0765B abstractC0765B) {
        if (abstractC0765B == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static final void i(O3.e eVar) {
        if (eVar == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static final void j(F f3) {
        if (f3 == null) {
            throw new IllegalStateException("Component not created");
        }
        if (!f3.f11456r) {
            throw new IllegalStateException("Component not initialized: ".concat(String.valueOf(f3.getClass())));
        }
    }

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

    public static C0817r0 q(Context context, com.google.android.gms.internal.measurement.U u8, Long l8) {
        Bundle bundle;
        if (u8 != null && (u8.f9689u == null || u8.f9690v == null)) {
            u8 = new com.google.android.gms.internal.measurement.U(u8.f9685q, u8.f9686r, u8.f9687s, u8.f9688t, null, null, u8.f9691w, null);
        }
        P2.w.f(context);
        P2.w.f(context.getApplicationContext());
        if (X == null) {
            synchronized (C0817r0.class) {
                try {
                    if (X == null) {
                        X = new C0817r0(new I0(context, u8, l8));
                    }
                } finally {
                }
            }
        } else if (u8 != null && (bundle = u8.f9691w) != null && bundle.containsKey("dataCollectionDefaultEnabled")) {
            P2.w.f(X);
            X.f12136R = Boolean.valueOf(bundle.getBoolean("dataCollectionDefaultEnabled"));
        }
        P2.w.f(X);
        return X;
    }

    @Override // d3.B0
    public final Context a() {
        return this.f12142q;
    }

    @Override // d3.B0
    public final C0253j b() {
        return this.f12147v;
    }

    @Override // d3.B0
    public final C0815q0 c() {
        C0815q0 c0815q0 = this.f12151z;
        k(c0815q0);
        return c0815q0;
    }

    @Override // d3.B0
    public final T2.a d() {
        return this.D;
    }

    @Override // d3.B0
    public final Z e() {
        Z z8 = this.f12150y;
        k(z8);
        return z8;
    }

    public final boolean f() {
        return l() == 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0034  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x007f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean g() {
        boolean z8;
        if (!this.f12133O) {
            throw new IllegalStateException("AppMeasurement is not initialized");
        }
        C0815q0 c0815q0 = this.f12151z;
        k(c0815q0);
        c0815q0.E();
        Boolean bool = this.f12134P;
        T2.a aVar = this.D;
        if (bool == null || this.f12135Q == 0) {
            aVar.getClass();
            this.f12135Q = SystemClock.elapsedRealtime();
            W1 w12 = this.f12122B;
            i(w12);
            boolean zT0 = w12.t0("android.permission.INTERNET");
            C0784g c0784g = this.f12148w;
            boolean z9 = true;
            if (zT0 && w12.t0("android.permission.ACCESS_NETWORK_STATE")) {
                Context context = this.f12142q;
                if (U2.b.a(context).d() || c0784g.H() || (W1.A0(context) && W1.C0(context))) {
                    z8 = true;
                }
                this.f12134P = Boolean.valueOf(z8);
                if (z8) {
                }
            } else {
                z8 = false;
                this.f12134P = Boolean.valueOf(z8);
                if (z8) {
                    if (!w12.n0(n().L(), n().J()) && (c0784g.R(null, I.f11580q1) || TextUtils.isEmpty(n().J()))) {
                        z9 = false;
                    }
                    this.f12134P = Boolean.valueOf(z9);
                }
            }
        } else if (!bool.booleanValue()) {
            aVar.getClass();
            if (Math.abs(SystemClock.elapsedRealtime() - this.f12135Q) > 1000) {
            }
        }
        return this.f12134P.booleanValue();
    }

    public final int l() {
        C0815q0 c0815q0 = this.f12151z;
        k(c0815q0);
        c0815q0.E();
        C0784g c0784g = this.f12148w;
        if (c0784g.F()) {
            return 1;
        }
        k(c0815q0);
        c0815q0.E();
        if (!this.f12137S) {
            return 8;
        }
        C0785g0 c0785g0 = this.f12149x;
        i(c0785g0);
        c0785g0.E();
        Boolean boolValueOf = c0785g0.J().contains("measurement_enabled") ? Boolean.valueOf(c0785g0.J().getBoolean("measurement_enabled", true)) : null;
        if (boolValueOf != null) {
            return boolValueOf.booleanValue() ? 0 : 3;
        }
        C0253j c0253j = ((C0817r0) c0784g.f5146q).f12147v;
        Boolean boolP = c0784g.P("firebase_analytics_collection_enabled");
        return boolP != null ? boolP.booleanValue() ? 0 : 4 : (this.f12136R == null || this.f12136R.booleanValue()) ? 0 : 7;
    }

    public final C0814q m() {
        k(this.f12130L);
        return this.f12130L;
    }

    public final P n() {
        j(this.f12131M);
        return this.f12131M;
    }

    public final S o() {
        j(this.f12128J);
        return this.f12128J;
    }

    public final T p() {
        return this.f12123C;
    }

    public final C0824t1 r() {
        j(this.f12129K);
        return this.f12129K;
    }

    public final String s() {
        if (this.f12148w.R(null, I.f11580q1)) {
            return null;
        }
        return this.f12143r;
    }
}
