package o;

import android.content.Context;
import android.database.Cursor;
import androidx.fragment.app.FragmentActivity;
import androidx.work.impl.WorkDatabase;
import com.google.android.gms.measurement.internal.AppMeasurementDynamiteService;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.hY, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1390hY implements InterfaceC3051yx, InterfaceC2956xx, InterfaceC2210q40 {

    /* renamed from: o, reason: collision with root package name */
    public static final J7 f562o = new J7(29);
    public final /* synthetic */ int l;
    public Object m;
    public Object n;

    public /* synthetic */ C1390hY(int i, Object obj, Object obj2) {
        this.l = i;
        this.m = obj;
        this.n = obj2;
    }

    public static C1390hY c(Context context) throws IOException {
        FileChannel channel;
        FileLock fileLockLock;
        try {
            channel = new RandomAccessFile(new File(context.getFilesDir(), "generatefid.lock"), "rw").getChannel();
            try {
                fileLockLock = channel.lock();
                try {
                    return new C1390hY(4, channel, fileLockLock);
                } catch (IOException | Error | OverlappingFileLockException unused) {
                    if (fileLockLock != null) {
                        try {
                            fileLockLock.release();
                        } catch (IOException unused2) {
                        }
                    }
                    if (channel != null) {
                        try {
                            channel.close();
                        } catch (IOException unused3) {
                        }
                    }
                    return null;
                }
            } catch (IOException | Error | OverlappingFileLockException unused4) {
                fileLockLock = null;
            }
        } catch (IOException | Error | OverlappingFileLockException unused5) {
            channel = null;
            fileLockLock = null;
        }
    }

    public void A() throws IOException {
        try {
            ((FileLock) this.n).release();
            ((FileChannel) this.m).close();
        } catch (IOException unused) {
        }
    }

    public void B(AbstractC2488t10 abstractC2488t10) {
        Xj0 xj0 = (Xj0) ((I80) this.m).get(abstractC2488t10);
        if (xj0 == null) {
            return;
        }
        xj0.a &= -2;
    }

    public void C(AbstractC2488t10 abstractC2488t10) {
        UM um = (UM) this.n;
        int iG = um.g() - 1;
        while (true) {
            if (iG < 0) {
                break;
            }
            if (abstractC2488t10 == um.h(iG)) {
                Object[] objArr = um.n;
                Object obj = objArr[iG];
                Object obj2 = AbstractC1904ms0.c;
                if (obj != obj2) {
                    objArr[iG] = obj2;
                    um.l = true;
                }
            } else {
                iG--;
            }
        }
        Xj0 xj0 = (Xj0) ((I80) this.m).remove(abstractC2488t10);
        if (xj0 != null) {
            xj0.a = 0;
            xj0.b = null;
            xj0.c = null;
            Xj0.d.c(xj0);
        }
    }

    public void D(C2627ua0 c2627ua0, BP bp) {
        ((C2062oc0) this.n).c(new RunnableC0245Jl((XY) this.m, c2627ua0, bp, 3));
    }

    public void E(C2627ua0 c2627ua0, int i) {
        ((C2062oc0) this.n).c(new Oa0((XY) this.m, c2627ua0, false, i));
    }

    public void F(AbstractC2047oQ abstractC2047oQ) {
        ZQ zq = (ZQ) this.m;
        Object objG = ((ZQ) this.n).g(abstractC2047oQ);
        if (objG != null) {
            if (!(objG instanceof UQ)) {
                throw new ClassCastException();
            }
            UQ uq = (UQ) objG;
            Object[] objArr = uq.a;
            int i = uq.b;
            for (int i2 = 0; i2 < i; i2++) {
                if (objArr[i2] != null) {
                    throw new ClassCastException();
                }
                C1072e7 c1072e7 = new C1072e7(25, abstractC2047oQ);
                Object objG2 = zq.g(null);
                if (objG2 != null) {
                    if (objG2 instanceof UQ) {
                        UQ uq2 = (UQ) objG2;
                        int i3 = uq2.b;
                        Object[] objArr2 = uq2.a;
                        int i4 = 0;
                        C0991dI c0991dIK = AbstractC0940cn0.K(0, i3);
                        int i5 = c0991dIK.l;
                        int i6 = c0991dIK.m;
                        if (i5 <= i6) {
                            while (true) {
                                objArr2[i5 - i4] = objArr2[i5];
                                if (((Boolean) c1072e7.g(objArr2[i5])).booleanValue()) {
                                    i4++;
                                }
                                if (i5 == i6) {
                                    break;
                                } else {
                                    i5++;
                                }
                            }
                        }
                        Arrays.fill(objArr2, i3 - i4, i3, (Object) null);
                        uq2.b -= i4;
                        if (uq2.g()) {
                            zq.k(null);
                        }
                        if (uq2.b == 0) {
                            zq.m(null, uq2.d());
                        }
                    } else if (((Boolean) c1072e7.g(objG2)).booleanValue()) {
                        zq.k(null);
                    }
                }
            }
        }
    }

    @Override // o.InterfaceC2210q40
    public Object a(X30 x30, Object obj) {
        return ((SC) this.m).f(x30, obj);
    }

    @Override // o.InterfaceC2210q40
    public Object b(Object obj) {
        return ((OC) this.n).g(obj);
    }

    public void d(AbstractC2488t10 abstractC2488t10, KZ kz) {
        I80 i80 = (I80) this.m;
        Xj0 xj0A = (Xj0) i80.get(abstractC2488t10);
        if (xj0A == null) {
            xj0A = Xj0.a();
            i80.put(abstractC2488t10, xj0A);
        }
        xj0A.c = kz;
        xj0A.a |= 8;
    }

    public C2730ve0 e(List list) {
        InterfaceC0764av interfaceC0764av;
        Exception e;
        InterfaceC0764av interfaceC0764av2;
        try {
            int size = list.size();
            int i = 0;
            interfaceC0764av = null;
            while (i < size) {
                try {
                    interfaceC0764av2 = (InterfaceC0764av) list.get(i);
                } catch (Exception e2) {
                    e = e2;
                }
                try {
                    interfaceC0764av2.a((C0860bv) this.n);
                    i++;
                    interfaceC0764av = interfaceC0764av2;
                } catch (Exception e3) {
                    e = e3;
                    interfaceC0764av = interfaceC0764av2;
                    StringBuilder sb = new StringBuilder();
                    StringBuilder sb2 = new StringBuilder("Error while applying EditCommand batch to buffer (length=");
                    sb2.append(((C0860bv) this.n).a.b());
                    sb2.append(", composition=");
                    sb2.append(((C0860bv) this.n).c());
                    sb2.append(", selection=");
                    C0860bv c0860bv = (C0860bv) this.n;
                    sb2.append((Object) Ue0.h(AbstractC2378rs0.u(c0860bv.b, c0860bv.c)));
                    sb2.append("):");
                    sb.append(sb2.toString());
                    sb.append('\n');
                    AbstractC3117zi.h0(list, sb, new S1(6, interfaceC0764av, this), 60);
                    throw new RuntimeException(sb.toString(), e);
                }
            }
            C0860bv c0860bv2 = (C0860bv) this.n;
            c0860bv2.getClass();
            C0977d7 c0977d7 = new C0977d7(c0860bv2.a.toString());
            C0860bv c0860bv3 = (C0860bv) this.n;
            long jU = AbstractC2378rs0.u(c0860bv3.b, c0860bv3.c);
            Ue0 ue0 = Ue0.g(((C2730ve0) this.m).b) ? null : new Ue0(jU);
            C2730ve0 c2730ve0 = new C2730ve0(c0977d7, ue0 != null ? ue0.a : AbstractC2378rs0.u(Ue0.e(jU), Ue0.f(jU)), ((C0860bv) this.n).c());
            this.m = c2730ve0;
            return c2730ve0;
        } catch (Exception e4) {
            interfaceC0764av = null;
            e = e4;
        }
    }

    public void f(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.f(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void g(boolean z) {
        androidx.fragment.app.s sVar = (androidx.fragment.app.s) this.n;
        FragmentActivity fragmentActivity = sVar.t.m;
        androidx.fragment.app.l lVar = sVar.v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.g(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    @Override // o.CZ
    public Object get() {
        switch (this.l) {
            case 7:
                return new C2900xP((Context) ((G0) this.m).m, (C3126zm0) ((C0247Jn) this.n).get());
            default:
                return new C0681a20((S8) ((CZ) this.m).get(), (InterfaceC2747vn) ((G0) this.n).m);
        }
    }

    public void h(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.h(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void i(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.i(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void j(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.j(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void k(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.k(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void l(boolean z) {
        androidx.fragment.app.s sVar = (androidx.fragment.app.s) this.n;
        FragmentActivity fragmentActivity = sVar.t.m;
        androidx.fragment.app.l lVar = sVar.v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.l(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void m(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.m(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void n(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.n(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void o(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.o(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void p(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.p(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void q(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.q(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void r(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.r(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void s(boolean z) {
        androidx.fragment.app.l lVar = ((androidx.fragment.app.s) this.n).v;
        if (lVar != null) {
            lVar.getParentFragmentManager().l.s(true);
        }
        Iterator it = ((CopyOnWriteArrayList) this.m).iterator();
        if (it.hasNext()) {
            if (it.next() != null) {
                throw new ClassCastException();
            }
            if (!z) {
                throw null;
            }
            throw null;
        }
    }

    public void t(int i) {
        int[] iArr = (int[]) this.m;
        if (iArr == null) {
            int[] iArr2 = new int[Math.max(i, 10) + 1];
            this.m = iArr2;
            Arrays.fill(iArr2, -1);
        } else if (i >= iArr.length) {
            int length = iArr.length;
            while (length <= i) {
                length *= 2;
            }
            int[] iArr3 = new int[length];
            this.m = iArr3;
            System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
            int[] iArr4 = (int[]) this.m;
            Arrays.fill(iArr4, iArr.length, iArr4.length, -1);
        }
    }

    public Long u(String str) {
        WorkDatabase workDatabase = (WorkDatabase) this.m;
        C1449i30 c1449i30D = C1449i30.d(1, "SELECT long_value FROM Preference where `key`=?");
        c1449i30D.k(1, str);
        workDatabase.b();
        Cursor cursorL = workDatabase.l(c1449i30D);
        try {
            Long lValueOf = null;
            if (cursorL.moveToFirst() && !cursorL.isNull(0)) {
                lValueOf = Long.valueOf(cursorL.getLong(0));
            }
            return lValueOf;
        } finally {
            cursorL.close();
            c1449i30D.release();
        }
    }

    public void v(C1294gY c1294gY) {
        WorkDatabase workDatabase = (WorkDatabase) this.m;
        workDatabase.b();
        workDatabase.c();
        try {
            ((C2945xr) this.n).e(c1294gY);
            workDatabase.n();
        } finally {
            workDatabase.j();
        }
    }

    public void w(int i, int i2) {
        int[] iArr = (int[]) this.m;
        if (iArr == null || i >= iArr.length) {
            return;
        }
        int i3 = i + i2;
        t(i3);
        int[] iArr2 = (int[]) this.m;
        System.arraycopy(iArr2, i, iArr2, i3, (iArr2.length - i) - i2);
        Arrays.fill((int[]) this.m, i, i3, -1);
        ArrayList arrayList = (ArrayList) this.n;
        if (arrayList == null) {
            return;
        }
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            C1773la0 c1773la0 = (C1773la0) ((ArrayList) this.n).get(size);
            int i4 = c1773la0.l;
            if (i4 >= i) {
                c1773la0.l = i4 + i2;
            }
        }
    }

    public void x(int i, int i2) {
        int[] iArr = (int[]) this.m;
        if (iArr == null || i >= iArr.length) {
            return;
        }
        int i3 = i + i2;
        t(i3);
        int[] iArr2 = (int[]) this.m;
        System.arraycopy(iArr2, i3, iArr2, i, (iArr2.length - i) - i2);
        int[] iArr3 = (int[]) this.m;
        Arrays.fill(iArr3, iArr3.length - i2, iArr3.length, -1);
        ArrayList arrayList = (ArrayList) this.n;
        if (arrayList == null) {
            return;
        }
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            C1773la0 c1773la0 = (C1773la0) ((ArrayList) this.n).get(size);
            int i4 = c1773la0.l;
            if (i4 >= i) {
                if (i4 < i3) {
                    ((ArrayList) this.n).remove(size);
                } else {
                    c1773la0.l = i4 - i2;
                }
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:138:0x01f7, code lost:
    
        continue;
     */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue
    java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "jadx.core.dex.visitors.regions.SwitchOverStringVisitor$SwitchData.getNewCases()" is null
    	at jadx.core.dex.visitors.regions.SwitchOverStringVisitor.restoreSwitchOverString(SwitchOverStringVisitor.java:109)
    	at jadx.core.dex.visitors.regions.SwitchOverStringVisitor.visitRegion(SwitchOverStringVisitor.java:66)
    	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseIterativeStepInternal(DepthRegionTraversal.java:77)
    	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseIterativeStepInternal(DepthRegionTraversal.java:82)
     */
    /* JADX WARN: Removed duplicated region for block: B:106:0x00fe A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00f7 A[Catch: IOException | XmlPullParserException -> 0x01fd, IOException | XmlPullParserException -> 0x01fd, TryCatch #0 {IOException | XmlPullParserException -> 0x01fd, blocks: (B:18:0x0056, B:91:0x01f7, B:91:0x01f7, B:26:0x0068, B:27:0x0076, B:29:0x007b, B:32:0x0085, B:40:0x009f, B:35:0x008e, B:38:0x0097, B:41:0x00ad, B:45:0x00bc, B:45:0x00bc, B:47:0x00c4, B:47:0x00c4, B:48:0x00ce, B:48:0x00ce, B:57:0x00f7, B:57:0x00f7, B:58:0x00fe, B:58:0x00fe, B:59:0x0116, B:59:0x0116, B:51:0x00d7, B:51:0x00d7, B:53:0x00df, B:53:0x00df, B:54:0x00ed, B:54:0x00ed, B:60:0x0117, B:60:0x0117, B:62:0x011f, B:62:0x011f, B:63:0x012d, B:63:0x012d, B:66:0x0137, B:66:0x0137, B:67:0x0142, B:67:0x0142, B:68:0x015a, B:68:0x015a, B:69:0x015b, B:69:0x015b, B:72:0x0165, B:72:0x0165, B:73:0x0170, B:73:0x0170, B:74:0x0188, B:74:0x0188, B:75:0x0189, B:75:0x0189, B:77:0x0191, B:77:0x0191, B:78:0x019a, B:78:0x019a, B:81:0x01a4, B:81:0x01a4, B:82:0x01ae, B:82:0x01ae, B:83:0x01c6, B:83:0x01c6, B:84:0x01c7, B:84:0x01c7, B:87:0x01d1, B:87:0x01d1, B:88:0x01db, B:88:0x01db, B:89:0x01f3, B:89:0x01f3, B:90:0x01f4, B:90:0x01f4), top: B:98:0x0056 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void y(android.content.Context r10, android.content.res.XmlResourceParser r11) throws org.xmlpull.v1.XmlPullParserException, java.lang.NumberFormatException, java.io.IOException {
        /*
            Method dump skipped, instructions count: 582
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1390hY.y(android.content.Context, android.content.res.XmlResourceParser):void");
    }

    public KZ z(AbstractC2488t10 abstractC2488t10, int i) {
        Xj0 xj0;
        KZ kz;
        I80 i80 = (I80) this.m;
        int iD = i80.d(abstractC2488t10);
        if (iD >= 0 && (xj0 = (Xj0) i80.i(iD)) != null) {
            int i2 = xj0.a;
            if ((i2 & i) != 0) {
                int i3 = i2 & (~i);
                xj0.a = i3;
                if (i == 4) {
                    kz = xj0.b;
                } else {
                    if (i != 8) {
                        throw new IllegalArgumentException("Must provide flag PRE or POST");
                    }
                    kz = xj0.c;
                }
                if ((i3 & 12) == 0) {
                    i80.g(iD);
                    xj0.a = 0;
                    xj0.b = null;
                    xj0.c = null;
                    Xj0.d.c(xj0);
                }
                return kz;
            }
        }
        return null;
    }

    public /* synthetic */ C1390hY(int i, boolean z) {
        this.l = i;
    }

    public C1390hY(AppMeasurementDynamiteService appMeasurementDynamiteService, Ap0 ap0) {
        this.l = 16;
        this.n = appMeasurementDynamiteService;
        this.m = ap0;
    }

    public C1390hY(OD od, Gm0 gm0) {
        this.l = 15;
        this.n = gm0;
        od.D(new C3037yp0(0, this));
        this.m = new HashSet();
    }

    public C1390hY(WorkDatabase workDatabase) {
        this.l = 0;
        this.m = workDatabase;
        this.n = new C2945xr(workDatabase, 1);
    }

    public C1390hY(C1533iy c1533iy) {
        this.l = 1;
        this.m = c1533iy;
        this.n = f562o;
    }

    public C1390hY(androidx.fragment.app.s sVar) {
        this.l = 6;
        this.m = new CopyOnWriteArrayList();
        this.n = sVar;
    }

    public C1390hY(int i) {
        this.l = i;
        switch (i) {
            case 13:
                this.m = new I80(0);
                this.n = new UM((Object) null);
                break;
            default:
                this.m = new ZQ();
                this.n = new ZQ();
                break;
        }
    }
}
