package o;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicMarkableReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Mn, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0324Mn {
    public static final C0195Hn r = new C0195Hn(1);
    public static final Charset s = Charset.forName("UTF-8");
    public final Context a;
    public final C0637Yo b;
    public final DH c;
    public final Zf0 d;
    public final C3126zm0 e;
    public final C2227qG f;
    public final C1533iy g;
    public final N8 h;
    public final C1390hY i;
    public final C0506Tn j;
    public final E2 k;
    public final C0221In l;
    public final U7 m;
    public C3129zo n;

    /* renamed from: o, reason: collision with root package name */
    public final Qc0 f244o = new Qc0();
    public final Qc0 p = new Qc0();
    public final Qc0 q = new Qc0();

    public C0324Mn(Context context, C2227qG c2227qG, C0637Yo c0637Yo, C1533iy c1533iy, DH dh, N8 n8, Zf0 zf0, C1390hY c1390hY, U7 u7, C0506Tn c0506Tn, E2 e2, C0221In c0221In, C3126zm0 c3126zm0) {
        new AtomicBoolean(false);
        this.a = context;
        this.f = c2227qG;
        this.b = c0637Yo;
        this.g = c1533iy;
        this.c = dh;
        this.h = n8;
        this.d = zf0;
        this.i = c1390hY;
        this.j = c0506Tn;
        this.k = e2;
        this.l = c0221In;
        this.m = u7;
        this.e = c3126zm0;
    }

    public static Hw0 a(C0324Mn c0324Mn) {
        Hw0 hw0R;
        c0324Mn.getClass();
        ArrayList arrayList = new ArrayList();
        for (File file : C1533iy.e(((File) c0324Mn.g.n).listFiles(r))) {
            try {
                long j = Long.parseLong(file.getName().substring(3));
                try {
                    Class.forName("com.google.firebase.crash.FirebaseCrash");
                    hw0R = AbstractC0752ap.K(null);
                } catch (ClassNotFoundException unused) {
                    Log.isLoggable("FirebaseCrashlytics", 3);
                    hw0R = AbstractC0752ap.r(new ScheduledThreadPoolExecutor(1), new CallableC0299Ln(c0324Mn, j));
                }
                arrayList.add(hw0R);
            } catch (NumberFormatException unused2) {
                file.getName();
            }
            file.delete();
        }
        return AbstractC0752ap.j0(arrayList);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:173:0x0501  */
    /* JADX WARN: Removed duplicated region for block: B:255:0x0110 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00fe  */
    /* JADX WARN: Type inference failed for: r12v13 */
    /* JADX WARN: Type inference failed for: r12v14, types: [int] */
    /* JADX WARN: Type inference failed for: r12v20 */
    /* JADX WARN: Type inference failed for: r14v32, types: [int] */
    /* JADX WARN: Type inference failed for: r14v33 */
    /* JADX WARN: Type inference failed for: r14v36 */
    /* JADX WARN: Type inference failed for: r14v40 */
    /* JADX WARN: Type inference failed for: r14v41 */
    /* JADX WARN: Type inference failed for: r32v0, types: [boolean] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void b(boolean r32, o.C0598Xb r33, boolean r34) throws java.lang.Throwable {
        /*
            Method dump skipped, instructions count: 1657
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C0324Mn.b(boolean, o.Xb, boolean):void");
    }

    public final void c(String str, Boolean bool) {
        String str2;
        String str3;
        String str4;
        int i;
        Integer num;
        Map mapUnmodifiableMap;
        List listUnmodifiableList;
        long jCurrentTimeMillis = System.currentTimeMillis() / 1000;
        Log.isLoggable("FirebaseCrashlytics", 3);
        Locale locale = Locale.US;
        C2227qG c2227qG = this.f;
        N8 n8 = this.h;
        C1776lc c1776lc = new C1776lc(c2227qG.c, n8.f, n8.g, c2227qG.c().a, AbstractC2462sn.c(n8.d != null ? 4 : 1), n8.h);
        String str5 = Build.VERSION.RELEASE;
        String str6 = Build.VERSION.CODENAME;
        C1966nc c1966nc = new C1966nc(C1884mi0.G());
        Context context = this.a;
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        long blockCount = statFs.getBlockCount() * statFs.getBlockSize();
        EnumC1505ij enumC1505ij = EnumC1505ij.l;
        String str7 = Build.CPU_ABI;
        if (TextUtils.isEmpty(str7)) {
            Log.isLoggable("FirebaseCrashlytics", 2);
        } else {
            EnumC1505ij enumC1505ij2 = (EnumC1505ij) EnumC1505ij.m.get(str7.toLowerCase(locale));
            if (enumC1505ij2 != null) {
                enumC1505ij = enumC1505ij2;
            }
        }
        int iOrdinal = enumC1505ij.ordinal();
        String str8 = Build.MODEL;
        int iAvailableProcessors = Runtime.getRuntime().availableProcessors();
        long jN = C1884mi0.n(context);
        boolean zE = C1884mi0.E();
        int iZ = C1884mi0.z();
        String str9 = Build.MANUFACTURER;
        String str10 = Build.PRODUCT;
        C1871mc c1871mc = new C1871mc(iOrdinal, iAvailableProcessors, jN, blockCount, zE, iZ);
        C0506Tn c0506Tn = this.j;
        C1681kc c1681kc = new C1681kc(c1776lc, c1966nc, c1871mc);
        c0506Tn.getClass();
        Log.isLoggable("FirebaseCrashlytics", 2);
        c0506Tn.a.a(new C0480Sn(str, jCurrentTimeMillis, c1681kc));
        if (!bool.booleanValue() || str == null) {
            str2 = str9;
            str3 = str10;
            str4 = str8;
            i = 4;
        } else {
            Zf0 zf0 = this.d;
            synchronized (((String) zf0.c)) {
                zf0.c = str;
                XJ xj = (XJ) ((AtomicMarkableReference) ((C0949cs) zf0.d).b).getReference();
                synchronized (xj) {
                    mapUnmodifiableMap = Collections.unmodifiableMap(new HashMap(xj.a));
                }
                C1257g30 c1257g30 = (C1257g30) zf0.f;
                synchronized (c1257g30) {
                    listUnmodifiableList = Collections.unmodifiableList(new ArrayList(c1257g30.a));
                }
                str4 = str8;
                str2 = str9;
                str3 = str10;
                i = 4;
                ((ExecutorC0014Ao) ((C3126zm0) zf0.b).n).a(new RunnableC2373rq(zf0, str, mapUnmodifiableMap, listUnmodifiableList, 2));
            }
        }
        C1390hY c1390hY = this.i;
        ((InterfaceC0646Yx) c1390hY.n).b();
        c1390hY.n = C1390hY.f562o;
        if (str != null) {
            c1390hY.n = new OZ(((C1533iy) c1390hY.m).b(str, "userlog"));
        }
        this.l.a(str);
        U7 u7 = this.m;
        C2749vo c2749vo = (C2749vo) u7.m;
        Charset charset = AbstractC2654uo.a;
        C0649Za c0649Za = new C0649Za();
        c0649Za.a = "20.0.3";
        N8 n82 = c2749vo.c;
        String str11 = n82.a;
        if (str11 == null) {
            throw new NullPointerException("Null gmpAppId");
        }
        c0649Za.b = str11;
        C2227qG c2227qG2 = c2749vo.b;
        String str12 = c2227qG2.c().a;
        if (str12 == null) {
            throw new NullPointerException("Null installationUuid");
        }
        c0649Za.d = str12;
        c0649Za.e = c2227qG2.c().b;
        c0649Za.f = c2227qG2.c().c;
        String str13 = n82.f;
        if (str13 == null) {
            throw new NullPointerException("Null buildVersion");
        }
        c0649Za.h = str13;
        String str14 = n82.g;
        if (str14 == null) {
            throw new NullPointerException("Null displayVersion");
        }
        c0649Za.i = str14;
        c0649Za.c = i;
        c0649Za.m = (byte) (c0649Za.m | 1);
        C1490ib c1490ib = new C1490ib();
        c1490ib.f = false;
        byte b = (byte) (c1490ib.m | 2);
        c1490ib.d = jCurrentTimeMillis;
        c1490ib.m = (byte) (b | 1);
        if (str == null) {
            throw new NullPointerException("Null identifier");
        }
        c1490ib.b = str;
        String str15 = C2749vo.g;
        if (str15 == null) {
            throw new NullPointerException("Null generator");
        }
        c1490ib.a = str15;
        String str16 = c2227qG2.c;
        if (str16 == null) {
            throw new NullPointerException("Null identifier");
        }
        String str17 = c2227qG2.c().a;
        DH dh = n82.h;
        if (((C3040yr) dh.m) == null) {
            dh.m = new C3040yr(dh);
        }
        C3040yr c3040yr = (C3040yr) dh.m;
        String str18 = (String) c3040yr.m;
        if (c3040yr == null) {
            dh.m = new C3040yr(dh);
        }
        c1490ib.g = new C1679kb(str16, str13, str14, str17, str18, (String) ((C3040yr) dh.m).n);
        C0183Hb c0183Hb = new C0183Hb();
        c0183Hb.a = 3;
        c0183Hb.e = (byte) (c0183Hb.e | 1);
        if (str5 == null) {
            throw new NullPointerException("Null version");
        }
        c0183Hb.b = str5;
        if (str6 == null) {
            throw new NullPointerException("Null buildVersion");
        }
        c0183Hb.c = str6;
        c0183Hb.d = C1884mi0.G();
        c0183Hb.e = (byte) (c0183Hb.e | 2);
        c1490ib.i = c0183Hb.a();
        StatFs statFs2 = new StatFs(Environment.getDataDirectory().getPath());
        int iIntValue = 7;
        if (!TextUtils.isEmpty(str7) && (num = (Integer) C2749vo.f.get(str7.toLowerCase(locale))) != null) {
            iIntValue = num.intValue();
        }
        int iAvailableProcessors2 = Runtime.getRuntime().availableProcessors();
        long jN2 = C1884mi0.n(c2749vo.a);
        long blockCount2 = statFs2.getBlockCount() * statFs2.getBlockSize();
        boolean zE2 = C1884mi0.E();
        int iZ2 = C1884mi0.z();
        C1869mb c1869mb = new C1869mb();
        c1869mb.a = iIntValue;
        byte b2 = (byte) (c1869mb.j | 1);
        c1869mb.j = b2;
        if (str4 == null) {
            throw new NullPointerException("Null model");
        }
        c1869mb.b = str4;
        c1869mb.c = iAvailableProcessors2;
        c1869mb.d = jN2;
        c1869mb.e = blockCount2;
        c1869mb.f = zE2;
        c1869mb.g = iZ2;
        c1869mb.j = (byte) (((byte) (((byte) (((byte) (((byte) (b2 | 2)) | 4)) | 8)) | 16)) | 32);
        String str19 = str2;
        if (str19 == null) {
            throw new NullPointerException("Null manufacturer");
        }
        c1869mb.h = str19;
        String str20 = str3;
        if (str20 == null) {
            throw new NullPointerException("Null modelClass");
        }
        c1869mb.i = str20;
        c1490ib.j = c1869mb.a();
        c1490ib.l = 3;
        c1490ib.m = (byte) (c1490ib.m | 4);
        c0649Za.j = c1490ib.a();
        C0724ab c0724abA = c0649Za.a();
        C1533iy c1533iy = ((C2939xo) u7.n).b;
        AbstractC2559to abstractC2559to = c0724abA.k;
        if (abstractC2559to == null) {
            Log.isLoggable("FirebaseCrashlytics", 3);
            return;
        }
        String str21 = ((C1584jb) abstractC2559to).b;
        try {
            C2939xo.g.getClass();
            C2939xo.f(c1533iy.b(str21, "report"), C2844wo.a.c(c0724abA));
            File fileB = c1533iy.b(str21, "start-time");
            long j = ((C1584jb) abstractC2559to).d;
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(fileB), C2939xo.e);
            try {
                outputStreamWriter.write("");
                fileB.setLastModified(j * 1000);
                outputStreamWriter.close();
            } finally {
            }
        } catch (IOException unused) {
            Log.isLoggable("FirebaseCrashlytics", 3);
        }
    }

    public final String d() throws Resources.NotFoundException, IOException {
        Context context = this.a;
        int iA = C1884mi0.A(context, "com.google.firebase.crashlytics.version_control_info", "string");
        String string = iA == 0 ? null : context.getResources().getString(iA);
        if (string != null) {
            Log.isLoggable("FirebaseCrashlytics", 3);
            return Base64.encodeToString(string.getBytes(s), 0);
        }
        ClassLoader classLoader = C0324Mn.class.getClassLoader();
        InputStream resourceAsStream = classLoader == null ? null : classLoader.getResourceAsStream("META-INF/version-control-info.textproto");
        if (resourceAsStream == null) {
            if (resourceAsStream != null) {
                resourceAsStream.close();
            }
            return null;
        }
        try {
            Log.isLoggable("FirebaseCrashlytics", 3);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            try {
                byte[] bArr = new byte[1024];
                while (true) {
                    int i = resourceAsStream.read(bArr);
                    if (i == -1) {
                        byte[] byteArray = byteArrayOutputStream.toByteArray();
                        byteArrayOutputStream.close();
                        String strEncodeToString = Base64.encodeToString(byteArray, 0);
                        resourceAsStream.close();
                        return strEncodeToString;
                    }
                    byteArrayOutputStream.write(bArr, 0, i);
                }
            } finally {
            }
        } catch (Throwable th) {
            try {
                resourceAsStream.close();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }

    public final void e() throws Resources.NotFoundException {
        try {
            String strD = d();
            if (strD != null) {
                try {
                    this.d.a(strD);
                } catch (IllegalArgumentException e) {
                    Context context = this.a;
                    if (context != null && (context.getApplicationInfo().flags & 2) != 0) {
                        throw e;
                    }
                }
            }
        } catch (IOException unused) {
        }
    }

    public final void f(Hw0 hw0) {
        Hw0 hw02;
        Hw0 hw0T;
        Qc0 qc0 = this.f244o;
        C1533iy c1533iy = ((C2939xo) this.m.n).b;
        if (C1533iy.e(((File) c1533iy.p).listFiles()).isEmpty() && C1533iy.e(((File) c1533iy.q).listFiles()).isEmpty() && C1533iy.e(((File) c1533iy.r).listFiles()).isEmpty()) {
            Log.isLoggable("FirebaseCrashlytics", 2);
            qc0.d(Boolean.FALSE);
            return;
        }
        Log.isLoggable("FirebaseCrashlytics", 2);
        C0637Yo c0637Yo = this.b;
        if (c0637Yo.a()) {
            Log.isLoggable("FirebaseCrashlytics", 3);
            qc0.d(Boolean.FALSE);
            hw0T = AbstractC0752ap.K(Boolean.TRUE);
        } else {
            Log.isLoggable("FirebaseCrashlytics", 3);
            Log.isLoggable("FirebaseCrashlytics", 2);
            qc0.d(Boolean.TRUE);
            synchronized (c0637Yo.c) {
                hw02 = c0637Yo.d.a;
            }
            Hw0 hw0J = hw02.j(new C0688a6(13));
            Log.isLoggable("FirebaseCrashlytics", 3);
            hw0T = AbstractC1904ms0.t(hw0J, this.p.a);
        }
        hw0T.i((ExecutorC0014Ao) this.e.m, new C3040yr(4, this, hw0, false));
    }
}
