package B7;

import I0.x;
import N.o;
import O1.w;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.util.Log;
import android.view.View;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import d5.AbstractC0844a;
import e6.C0890b;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import n2.C1267a;
import n2.C1271e;
import n4.u0;

/* JADX INFO: loaded from: classes.dex */
public final class a implements x, o {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ int f1038q;

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f1040s;

    public static void h(String str) {
        if (str.equalsIgnoreCase(":memory:")) {
            return;
        }
        int length = str.length() - 1;
        int i = 0;
        boolean z8 = false;
        while (i <= length) {
            boolean z9 = P6.g.f(str.charAt(!z8 ? i : length), 32) <= 0;
            if (z8) {
                if (!z9) {
                    break;
                } else {
                    length--;
                }
            } else if (z9) {
                i++;
            } else {
                z8 = true;
            }
        }
        if (str.subSequence(i, length + 1).toString().length() == 0) {
            return;
        }
        Log.w("SupportSQLite", "deleting the database file: ".concat(str));
        try {
            SQLiteDatabase.deleteDatabase(new File(str));
        } catch (Exception e8) {
            Log.w("SupportSQLite", "delete failed: ", e8);
        }
    }

    public static boolean k(int i, int i5, boolean z8) {
        if (i <= i5 || !z8) {
            return i < 0 && !z8;
        }
        return true;
    }

    @Override // I0.x
    public boolean a(String str, MediaCodecInfo.CodecCapabilities codecCapabilities) {
        return codecCapabilities.isFeatureRequired(str);
    }

    @Override // I0.x
    public int b() {
        if (((MediaCodecInfo[]) this.f1040s) == null) {
            this.f1040s = new MediaCodecList(this.f1039r).getCodecInfos();
        }
        return ((MediaCodecInfo[]) this.f1040s).length;
    }

    @Override // N.o
    public boolean c(View view) {
        ((BottomSheetBehavior) this.f1040s).y(this.f1039r);
        return true;
    }

    public void d(long j8) {
        int i = this.f1039r;
        long[] jArr = (long[]) this.f1040s;
        if (i == jArr.length) {
            this.f1040s = Arrays.copyOf(jArr, i * 2);
        }
        long[] jArr2 = (long[]) this.f1040s;
        int i5 = this.f1039r;
        this.f1039r = i5 + 1;
        jArr2[i5] = j8;
    }

    @Override // I0.x
    public MediaCodecInfo e(int i) {
        if (((MediaCodecInfo[]) this.f1040s) == null) {
            this.f1040s = new MediaCodecList(this.f1039r).getCodecInfos();
        }
        return ((MediaCodecInfo[]) this.f1040s)[i];
    }

    public void f(long[] jArr) {
        int length = this.f1039r + jArr.length;
        long[] jArr2 = (long[]) this.f1040s;
        if (length > jArr2.length) {
            this.f1040s = Arrays.copyOf(jArr2, Math.max(jArr2.length * 2, length));
        }
        System.arraycopy(jArr, 0, (long[]) this.f1040s, this.f1039r, jArr.length);
        this.f1039r = length;
    }

    public void g() {
        WeakReference weakReference;
        this.f1039r = 0;
        Iterator it = ((LinkedHashMap) this.f1040s).values().iterator();
        while (it.hasNext()) {
            ArrayList arrayList = (ArrayList) it.next();
            if (arrayList.size() <= 1) {
                C1271e c1271e = (C1271e) B6.k.i0(arrayList);
                if (((c1271e == null || (weakReference = c1271e.f15134b) == null) ? null : (Bitmap) weakReference.get()) == null) {
                    it.remove();
                }
            } else {
                int size = arrayList.size();
                int i = 0;
                for (int i5 = 0; i5 < size; i5++) {
                    int i8 = i5 - i;
                    if (((C1271e) arrayList.get(i8)).f15134b.get() == null) {
                        arrayList.remove(i8);
                        i++;
                    }
                }
                if (arrayList.isEmpty()) {
                    it.remove();
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:44:0x0061  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0086  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int i(int i, d6.o oVar, boolean z8, int i5, boolean z9) {
        P6.g.e(oVar, "spanSizeLookup");
        C0890b c0890b = (C0890b) this.f1040s;
        int i8 = c0890b.f12500b;
        if (i8 != 1) {
            int i9 = z8 ? 1 : -1;
            if (oVar != d6.o.f12307e) {
                int iA = oVar.a(i, i8);
                byte b8 = z8 != z9 ? (byte) 1 : (byte) -1;
                int i10 = (z9 ? b8 <= 0 : b8 > 0) ? 1 : -1;
                int i11 = !z9 ? 0 : c0890b.f12500b - 1;
                int i12 = i;
                do {
                    i12 += i9;
                    if (k(i12, i5, z8) || (iA = iA + i10) < 0) {
                        break;
                    }
                } while (iA <= c0890b.f12500b - 1);
                if (k(i12, i5, z8)) {
                    i12 = -1;
                    if (i12 != -1) {
                        if (this.f1039r != -1 && 1 != c0890b.f12500b) {
                            if (!z8 && !z9) {
                                i9 *= -1;
                            }
                            for (int i13 = i12; !k(i13, i5, z8) && i13 != i; i13 += i9) {
                                int iA2 = oVar.a(i13, c0890b.f12500b);
                                if (z9) {
                                    if (iA2 <= this.f1039r) {
                                        return i13;
                                    }
                                } else {
                                    if (iA2 >= this.f1039r) {
                                        return i13;
                                    }
                                }
                            }
                        }
                        return i12;
                    }
                } else {
                    int iA3 = oVar.a(i12, c0890b.f12500b);
                    while (iA3 != i11 && iA3 > 0 && iA3 < c0890b.f12500b) {
                        int i14 = i12 + i9;
                        if (k(i14, i5, z8)) {
                            break;
                        }
                        iA3 += i10;
                        i12 = i14;
                    }
                    if (k(i12, i5, z8)) {
                    }
                    if (i12 != -1) {
                    }
                }
            } else if (i / i8 != i5 / i8) {
                int i15 = (i8 * i9) + i;
                return ((i15 < i5 || i9 >= 0) && (i15 > i5 || i9 <= 0)) ? i5 : i15;
            }
        }
        return -1;
    }

    public long j(int i) {
        if (i >= 0 && i < this.f1039r) {
            return ((long[]) this.f1040s)[i];
        }
        StringBuilder sbO = AbstractC0844a.o(i, "Invalid index ", ", size is ");
        sbO.append(this.f1039r);
        throw new IndexOutOfBoundsException(sbO.toString());
    }

    @Override // I0.x
    public boolean l(String str, String str2, MediaCodecInfo.CodecCapabilities codecCapabilities) {
        return codecCapabilities.isFeatureSupported(str);
    }

    @Override // I0.x
    public boolean m() {
        return true;
    }

    public void n(Z1.c cVar, int i, int i5) {
        ((w) this.f1040s).e(new R1.a(cVar), i, i5);
    }

    public void o(int i, int i5) {
        for (int i8 = 0; i8 < i5; i8++) {
            boolean z8 = true;
            if (((i >>> ((i5 - i8) - 1)) & 1) != 1) {
                z8 = false;
            }
            p(z8);
        }
    }

    public void p(boolean z8) {
        int i = this.f1039r;
        int[] iArr = (int[]) this.f1040s;
        if (i == iArr.length * 8) {
            int[] iArrCopyOf = Arrays.copyOf(iArr, iArr.length + 32);
            P6.g.d(iArrCopyOf, "copyOf(...)");
            this.f1040s = iArrCopyOf;
        }
        if (z8) {
            int[] iArr2 = (int[]) this.f1040s;
            int i5 = this.f1039r;
            iArr2[i5 / 8] = (128 >>> (i5 % 8)) | iArr2[i5 / 8];
        }
        this.f1039r++;
    }

    public long q(T0.j jVar) {
        x0.o oVar = (x0.o) this.f1040s;
        int i = 0;
        jVar.f(oVar.f18539a, 0, 1, false);
        int i5 = oVar.f18539a[0] & 255;
        if (i5 == 0) {
            return Long.MIN_VALUE;
        }
        int i8 = 128;
        int i9 = 0;
        while ((i5 & i8) == 0) {
            i8 >>= 1;
            i9++;
        }
        int i10 = i5 & (~i8);
        jVar.f(oVar.f18539a, 1, i9, false);
        while (i < i9) {
            i++;
            i10 = (oVar.f18539a[i] & 255) + (i10 << 8);
        }
        this.f1039r = i9 + 1 + this.f1039r;
        return i10;
    }

    public void r(int i, d6.o oVar) {
        P6.g.e(oVar, "spanSizeLookup");
        C0890b c0890b = (C0890b) this.f1040s;
        int i5 = c0890b.f12500b;
        if (i5 == 1 || oVar == d6.o.f12307e) {
            return;
        }
        int iA = oVar.a(i, i5);
        if (1 == c0890b.f12500b) {
            return;
        }
        this.f1039r = iA;
    }

    public synchronized void s(C1267a c1267a, Bitmap bitmap, Map map, int i) {
        try {
            LinkedHashMap linkedHashMap = (LinkedHashMap) this.f1040s;
            Object arrayList = linkedHashMap.get(c1267a);
            if (arrayList == null) {
                arrayList = new ArrayList();
                linkedHashMap.put(c1267a, arrayList);
            }
            ArrayList arrayList2 = (ArrayList) arrayList;
            int iIdentityHashCode = System.identityHashCode(bitmap);
            C1271e c1271e = new C1271e(iIdentityHashCode, new WeakReference(bitmap), map, i);
            int size = arrayList2.size();
            int i5 = 0;
            while (true) {
                if (i5 >= size) {
                    arrayList2.add(c1271e);
                    break;
                }
                C1271e c1271e2 = (C1271e) arrayList2.get(i5);
                if (i < c1271e2.f15136d) {
                    i5++;
                } else if (c1271e2.f15133a == iIdentityHashCode && c1271e2.f15134b.get() == bitmap) {
                    arrayList2.set(i5, c1271e);
                } else {
                    arrayList2.add(i5, c1271e);
                }
            }
            int i8 = this.f1039r;
            this.f1039r = i8 + 1;
            if (i8 >= 10) {
                g();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public synchronized void t(int i) {
        if (i >= 10 && i != 20) {
            g();
        }
    }

    public String toString() {
        switch (this.f1038q) {
            case u0.f15495q /* 0 */:
                StringBuilder sb = new StringBuilder();
                int i = this.f1039r;
                for (int i5 = 0; i5 < i; i5++) {
                    sb.append(((((int[]) this.f1040s)[i5 / 8] >>> (7 - (i5 % 8))) & 1) == 1 ? '1' : '0');
                }
                String string = sb.toString();
                P6.g.d(string, "toString(...)");
                return string;
            default:
                return super.toString();
        }
    }

    public /* synthetic */ a(int i, int i5, Object obj) {
        this.f1038q = i5;
        this.f1040s = obj;
        this.f1039r = i;
    }

    public a(M2.b bVar, int i) {
        this.f1038q = 3;
        P2.w.f(bVar);
        this.f1040s = bVar;
        this.f1039r = i;
    }

    public a(int i, String str) {
        this.f1038q = 10;
        this.f1039r = i;
        this.f1040s = str;
    }

    public a(C0890b c0890b) {
        this.f1038q = 5;
        this.f1040s = c0890b;
        this.f1039r = -1;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public a(int i, byte b8) {
        this(32, 12);
        this.f1038q = i;
        switch (i) {
            case 9:
                this.f1040s = new LinkedHashMap();
                break;
            case 12:
                break;
            default:
                this.f1040s = new x0.o(8);
                break;
        }
    }

    public a(int i, int i5) {
        this.f1038q = i5;
        switch (i5) {
            case 12:
                this.f1040s = new long[i];
                break;
            default:
                this.f1039r = i;
                break;
        }
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public a(w wVar, int i) {
        this(i, 2);
        this.f1038q = 2;
        this.f1040s = wVar;
    }

    public a(boolean z8, boolean z9, boolean z10) {
        this.f1038q = 1;
        this.f1039r = (z8 || z9 || z10) ? 1 : 0;
    }
}
