package q4;

import A1.G;
import B0.C0016c;
import B0.D;
import J.m;
import P.g;
import android.content.Context;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.leanback.widget.K0;
import com.martsnew.tv.R;
import d5.AbstractC0844a;
import e0.C0853a;
import g3.h;
import g4.C0988c;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicMarkableReference;
import k4.C1098a;
import k4.C1099b;
import k4.j;
import k4.r;
import k4.v;
import k4.w;
import l4.C1131c;
import m4.AbstractC1178n;
import m4.C1166b;
import m4.C1167c;
import m4.C1169e;
import m4.C1170f;
import m4.C1179o;
import m4.InterfaceC1168d;
import n.U0;
import n4.B;
import n4.C1276A;
import n4.C1278a0;
import n4.C1284d0;
import n4.C1286e0;
import n4.C1290g0;
import n4.C1292h0;
import n4.D0;
import n4.F;
import n4.O;
import n4.P;
import n4.Q;
import n4.S;
import n4.U;
import n4.V;
import n4.W;
import o4.C1350a;
import r4.C1494a;
import r4.C1495b;
import w2.C1699b;
import x2.C1711a;
import z2.o;

/* JADX INFO: renamed from: q4.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1463c {

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Object f16267f;

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

    public C1463c(ViewGroup viewGroup, View view) {
        this.f16268g = new g(18, this);
        if (viewGroup == null || view == null) {
            throw new IllegalArgumentException("Views may not be null");
        }
        this.f16262a = viewGroup;
        this.f16263b = view;
        this.f16264c = TransitionInflater.from(viewGroup.getContext()).inflateTransition(R.transition.lb_title_out);
        this.f16265d = TransitionInflater.from(viewGroup.getContext()).inflateTransition(R.transition.lb_title_in);
        this.f16266e = android.support.v4.media.session.a.d(viewGroup, new K0(this, 0));
        this.f16267f = android.support.v4.media.session.a.d(viewGroup, new K0(this, 1));
    }

    public static P a(P p3, C1170f c1170f, U0 u02, Map map) {
        Map mapUnmodifiableMap;
        O oA = p3.a();
        String strB = ((InterfaceC1168d) c1170f.f14621b).b();
        if (strB != null) {
            oA.f15262e = new C1284d0(strB);
        } else if (Log.isLoggable("FirebaseCrashlytics", 2)) {
            Log.v("FirebaseCrashlytics", "No log data to include with this event.", null);
        }
        boolean zIsEmpty = map.isEmpty();
        C0016c c0016c = (C0016c) u02.f14796d;
        if (zIsEmpty) {
            mapUnmodifiableMap = ((C1169e) ((AtomicMarkableReference) c0016c.f718r).getReference()).a();
        } else {
            HashMap map2 = new HashMap(((C1169e) ((AtomicMarkableReference) c0016c.f718r).getReference()).a());
            int i = 0;
            for (Map.Entry entry : map.entrySet()) {
                String strB2 = C1169e.b(1024, (String) entry.getKey());
                if (map2.size() < 64 || map2.containsKey(strB2)) {
                    map2.put(strB2, C1169e.b(1024, (String) entry.getValue()));
                } else {
                    i++;
                }
            }
            if (i > 0) {
                Log.w("FirebaseCrashlytics", "Ignored " + i + " keys when adding event specific keys. Maximum allowable: 1024", null);
            }
            mapUnmodifiableMap = Collections.unmodifiableMap(map2);
        }
        List listG = g(mapUnmodifiableMap);
        List listG2 = g(((C1169e) ((AtomicMarkableReference) ((C0016c) u02.f14797e).f718r).getReference()).a());
        if (!listG.isEmpty() || !listG2.isEmpty()) {
            Q q8 = p3.f15268c;
            oA.f15260c = new Q(q8.f15272a, listG, listG2, q8.f15275d, q8.f15276e, q8.f15277f, q8.f15278g);
        }
        return oA.a();
    }

    public static n4.K0 b(P p3, U0 u02) {
        List listA = ((C1179o) u02.f14798f).a();
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < listA.size(); i++) {
            AbstractC1178n abstractC1178n = (AbstractC1178n) listA.get(i);
            abstractC1178n.getClass();
            C1286e0 c1286e0 = new C1286e0();
            C1166b c1166b = (C1166b) abstractC1178n;
            String str = c1166b.f14611e;
            if (str == null) {
                throw new NullPointerException("Null variantId");
            }
            String str2 = c1166b.f14608b;
            if (str2 == null) {
                throw new NullPointerException("Null rolloutId");
            }
            c1286e0.f15364a = new C1290g0(str2, str);
            String str3 = c1166b.f14609c;
            if (str3 == null) {
                throw new NullPointerException("Null parameterKey");
            }
            c1286e0.f15365b = str3;
            String str4 = c1166b.f14610d;
            if (str4 == null) {
                throw new NullPointerException("Null parameterValue");
            }
            c1286e0.f15366c = str4;
            c1286e0.f15367d = c1166b.f14612f;
            c1286e0.f15368e = (byte) (c1286e0.f15368e | 1);
            arrayList.add(c1286e0.a());
        }
        if (arrayList.isEmpty()) {
            return p3;
        }
        O oA = p3.a();
        oA.f15263f = new C1292h0(arrayList);
        return oA.a();
    }

    public static String d(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream;
        byte[] bArr;
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        try {
            byteArrayOutputStream = new ByteArrayOutputStream();
            try {
                bArr = new byte[8192];
            } finally {
            }
        } catch (Throwable th) {
            try {
                bufferedInputStream.close();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
        while (true) {
            int i = bufferedInputStream.read(bArr);
            if (i == -1) {
                String string = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
                byteArrayOutputStream.close();
                bufferedInputStream.close();
                return string;
            }
            byteArrayOutputStream.write(bArr, 0, i);
            bufferedInputStream.close();
            throw th;
        }
    }

    public static C1463c e(Context context, w wVar, C1463c c1463c, C1098a c1098a, C1170f c1170f, U0 u02, C0853a c0853a, s4.b bVar, C0853a c0853a2, j jVar, C1131c c1131c) {
        r rVar = new r(context, wVar, c1098a, c0853a, bVar);
        C1461a c1461a = new C1461a(c1463c, bVar, jVar);
        C1350a c1350a = C1494a.f16439b;
        o.b(context);
        return new C1463c(rVar, c1461a, new C1494a(new C1495b(o.a().c(new C1711a(C1494a.f16440c, C1494a.f16441d)).a("FIREBASE_CRASHLYTICS_REPORT", new C1699b("json"), C1494a.f16442e), bVar.b(), c0853a2)), c1170f, u02, wVar, c1131c);
    }

    public static List g(Map map) {
        ArrayList arrayList = new ArrayList();
        arrayList.ensureCapacity(map.size());
        for (Map.Entry entry : map.entrySet()) {
            String str = (String) entry.getKey();
            if (str == null) {
                throw new NullPointerException("Null key");
            }
            String str2 = (String) entry.getValue();
            if (str2 == null) {
                throw new NullPointerException("Null value");
            }
            arrayList.add(new F(str, str2));
        }
        Collections.sort(arrayList, new D1.F(14));
        return Collections.unmodifiableList(arrayList);
    }

    public static synchronized void i(File file) {
        try {
            if (file.exists()) {
                if (file.isDirectory()) {
                    return;
                }
                String str = "Unexpected non-directory file: " + file + "; deleting file and creating new directory.";
                if (Log.isLoggable("FirebaseCrashlytics", 3)) {
                    Log.d("FirebaseCrashlytics", str, null);
                }
                file.delete();
            }
            if (!file.mkdirs()) {
                Log.e("FirebaseCrashlytics", "Could not create Crashlytics-specific directory: " + file, null);
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public static boolean j(File file) {
        File[] fileArrListFiles = file.listFiles();
        if (fileArrListFiles != null) {
            for (File file2 : fileArrListFiles) {
                j(file2);
            }
        }
        return file.delete();
    }

    public static List k(Object[] objArr) {
        return objArr == null ? Collections.EMPTY_LIST : Arrays.asList(objArr);
    }

    public void c(String str) {
        File file = new File((File) this.f16263b, str);
        if (file.exists() && j(file)) {
            String str2 = "Deleted previous Crashlytics file system: " + file.getPath();
            if (Log.isLoggable("FirebaseCrashlytics", 3)) {
                Log.d("FirebaseCrashlytics", str2, null);
            }
        }
    }

    public File f(String str, String str2) {
        File file = new File((File) this.f16265d, str);
        file.mkdirs();
        return new File(file, str2);
    }

    public void h(Throwable th, Thread thread, String str, C1167c c1167c, boolean z8) {
        C0853a c0853a;
        Iterator<Map.Entry<Thread, StackTraceElement[]>> it;
        C0853a c0853a2;
        boolean zEquals = str.equals("crash");
        r rVar = (r) this.f16262a;
        Context context = rVar.f13918a;
        int i = context.getResources().getConfiguration().orientation;
        Stack stack = new Stack();
        for (Throwable cause = th; cause != null; cause = cause.getCause()) {
            stack.push(cause);
        }
        C2.a aVar = null;
        while (true) {
            boolean zIsEmpty = stack.isEmpty();
            c0853a = rVar.f13921d;
            if (zIsEmpty) {
                break;
            }
            Throwable th2 = (Throwable) stack.pop();
            aVar = new C2.a(th2.getLocalizedMessage(), th2.getClass().getName(), c0853a.e(th2.getStackTrace()), aVar);
        }
        O o8 = new O();
        o8.f15259b = str;
        o8.f15258a = c1167c.f14614b;
        o8.f15264g = (byte) (o8.f15264g | 1);
        D0 d0E = C0988c.f12957b.e(context);
        int i5 = ((C1278a0) d0E).f15321c;
        Boolean boolValueOf = i5 > 0 ? Boolean.valueOf(i5 != 100) : null;
        ArrayList arrayListD = C0988c.d(context);
        byte b8 = (byte) 1;
        ArrayList arrayList = new ArrayList();
        StackTraceElement[] stackTraceElementArr = (StackTraceElement[]) aVar.f1157r;
        String name = thread.getName();
        Boolean bool = boolValueOf;
        if (name == null) {
            throw new NullPointerException("Null name");
        }
        byte b9 = (byte) 1;
        List listD = r.d(stackTraceElementArr, 4);
        if (listD == null) {
            throw new NullPointerException("Null frames");
        }
        if (b9 != 1) {
            StringBuilder sb = new StringBuilder();
            if (b9 == 0) {
                sb.append(" importance");
            }
            throw new IllegalStateException(AbstractC0844a.m("Missing required properties:", sb));
        }
        arrayList.add(new W(name, 4, listD));
        if (z8) {
            Iterator<Map.Entry<Thread, StackTraceElement[]>> it2 = Thread.getAllStackTraces().entrySet().iterator();
            while (it2.hasNext()) {
                Map.Entry<Thread, StackTraceElement[]> next = it2.next();
                Thread key = next.getKey();
                if (key.equals(thread)) {
                    it = it2;
                    c0853a2 = c0853a;
                } else {
                    StackTraceElement[] stackTraceElementArrE = c0853a.e(next.getValue());
                    String name2 = key.getName();
                    if (name2 == null) {
                        throw new NullPointerException("Null name");
                    }
                    it = it2;
                    List listD2 = r.d(stackTraceElementArrE, 0);
                    if (listD2 == null) {
                        throw new NullPointerException("Null frames");
                    }
                    if (b9 != 1) {
                        StringBuilder sb2 = new StringBuilder();
                        if (b9 == 0) {
                            sb2.append(" importance");
                        }
                        throw new IllegalStateException(AbstractC0844a.m("Missing required properties:", sb2));
                    }
                    c0853a2 = c0853a;
                    arrayList.add(new W(name2, 0, listD2));
                }
                it2 = it;
                c0853a = c0853a2;
            }
        }
        List listUnmodifiableList = Collections.unmodifiableList(arrayList);
        U uC = r.c(aVar, 0);
        V vE = r.e();
        List listA = rVar.a();
        if (listA == null) {
            throw new NullPointerException("Null binaries");
        }
        S s8 = new S(listUnmodifiableList, uC, null, vE, listA);
        if (b8 != 1) {
            StringBuilder sb3 = new StringBuilder();
            if (b8 == 0) {
                sb3.append(" uiOrientation");
            }
            throw new IllegalStateException(AbstractC0844a.m("Missing required properties:", sb3));
        }
        o8.f15260c = new Q(s8, null, null, bool, d0E, arrayListD, i);
        o8.f15261d = rVar.b(i);
        P pA = o8.a();
        C1170f c1170f = (C1170f) this.f16265d;
        U0 u02 = (U0) this.f16266e;
        n4.K0 k0B = b(a(pA, c1170f, u02, c1167c.f14615c), u02);
        if (z8) {
            ((C1461a) this.f16263b).d(k0B, c1167c.f14613a, zEquals);
        } else {
            ((C1131c) this.f16268g).f14384b.a(new D(this, k0B, c1167c, zEquals));
        }
    }

    public g3.o l(Executor executor, String str) {
        h hVar;
        ArrayList arrayListB = ((C1461a) this.f16263b).b();
        ArrayList arrayList = new ArrayList();
        int size = arrayListB.size();
        int i = 0;
        while (i < size) {
            int i5 = i + 1;
            File file = (File) arrayListB.get(i);
            try {
                C1350a c1350a = C1461a.f16255g;
                String strE = C1461a.e(file);
                c1350a.getClass();
                arrayList.add(new C1099b(C1350a.i(strE), file.getName(), file));
            } catch (IOException e8) {
                Log.w("FirebaseCrashlytics", "Could not load report file " + file + "; deleting", e8);
                file.delete();
            }
            i = i5;
        }
        ArrayList arrayList2 = new ArrayList();
        int size2 = arrayList.size();
        int i8 = 0;
        while (i8 < size2) {
            Object obj = arrayList.get(i8);
            i8++;
            C1099b c1099b = (C1099b) obj;
            if (str == null || str.equals(c1099b.f13846b)) {
                C1494a c1494a = (C1494a) this.f16264c;
                B b8 = c1099b.f13845a;
                if (b8.f15179f == null || b8.f15180g == null) {
                    v vVarB = ((w) this.f16267f).b(true);
                    C1276A c1276aA = c1099b.f13845a.a();
                    c1276aA.f15167e = vVarB.f13932a;
                    C1276A c1276aA2 = c1276aA.a().a();
                    c1276aA2.f15168f = vVarB.f13933b;
                    c1099b = new C1099b(c1276aA2.a(), c1099b.f13846b, c1099b.f13847c);
                }
                boolean z8 = str != null;
                C1495b c1495b = c1494a.f16443a;
                synchronized (c1495b.f16449f) {
                    try {
                        hVar = new h();
                        if (z8) {
                            ((AtomicInteger) c1495b.i.f12397r).getAndIncrement();
                            if (c1495b.f16449f.size() < c1495b.f16448e) {
                                C0988c c0988c = C0988c.f12956a;
                                c0988c.c("Enqueueing report: " + c1099b.f13846b);
                                c0988c.c("Queue size: " + c1495b.f16449f.size());
                                c1495b.f16450g.execute(new m(c1495b, c1099b, hVar, 10));
                                c0988c.c("Closing task for report: " + c1099b.f13846b);
                                hVar.b(c1099b);
                            } else {
                                c1495b.a();
                                String str2 = "Dropping report due to queue being full: " + c1099b.f13846b;
                                if (Log.isLoggable("FirebaseCrashlytics", 3)) {
                                    Log.d("FirebaseCrashlytics", str2, null);
                                }
                                ((AtomicInteger) c1495b.i.f12398s).getAndIncrement();
                                hVar.b(c1099b);
                            }
                        } else {
                            c1495b.b(c1099b, hVar);
                        }
                    } finally {
                    }
                }
                arrayList2.add(hVar.f12923a.d(executor, new G(26, this)));
            }
        }
        return W2.g.K(arrayList2);
    }

    public C1463c(Context context) {
        String string;
        String strReplaceAll;
        String str = ((C1278a0) C0988c.f12957b.e(context)).f15319a;
        this.f16262a = str;
        File filesDir = context.getFilesDir();
        this.f16263b = filesDir;
        if (!str.isEmpty()) {
            StringBuilder sb = new StringBuilder(".crashlytics.v3");
            sb.append(File.separator);
            if (str.length() > 40) {
                strReplaceAll = k4.g.h(str);
            } else {
                strReplaceAll = str.replaceAll("[^a-zA-Z0-9.]", "_");
            }
            sb.append(strReplaceAll);
            string = sb.toString();
        } else {
            string = ".com.google.firebase.crashlytics.files.v1";
        }
        File file = new File(filesDir, string);
        i(file);
        this.f16264c = file;
        File file2 = new File(file, "open-sessions");
        i(file2);
        this.f16265d = file2;
        File file3 = new File(file, "reports");
        i(file3);
        this.f16266e = file3;
        File file4 = new File(file, "priority-reports");
        i(file4);
        this.f16267f = file4;
        File file5 = new File(file, "native-reports");
        i(file5);
        this.f16268g = file5;
    }

    public C1463c(r rVar, C1461a c1461a, C1494a c1494a, C1170f c1170f, U0 u02, w wVar, C1131c c1131c) {
        this.f16262a = rVar;
        this.f16263b = c1461a;
        this.f16264c = c1494a;
        this.f16265d = c1170f;
        this.f16266e = u02;
        this.f16267f = wVar;
        this.f16268g = c1131c;
    }
}
