package androidx.browser.trusted;

import android.app.Notification;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import com.google.android.gms.ads.AdFormat;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.internal.ads.co0;
import com.google.android.gms.internal.ads.dr0;
import com.google.android.gms.internal.ads.fh;
import com.google.android.gms.internal.ads.hp2;
import com.google.android.gms.internal.ads.ip2;
import com.google.android.gms.internal.ads.md;
import com.google.android.gms.internal.ads.nj2;
import com.google.android.gms.internal.ads.oj2;
import com.google.android.gms.internal.ads.rd;
import com.google.android.gms.internal.ads.sd;
import com.google.android.gms.internal.ads.to2;
import com.google.android.gms.internal.ads.va2;
import com.google.android.gms.internal.ads.vi1;
import com.google.android.gms.internal.ads.yo2;
import com.google.android.gms.internal.ads.zzaum;
import com.google.android.gms.internal.ads.zzaun;
import com.google.android.gms.internal.ads.zzauo;
import com.google.android.gms.internal.atv_ads_framework.d1;
import java.util.Formatter;
import p7.l0;

/* JADX INFO: loaded from: classes.dex */
public final class k implements dr0, co0, com.tekartik.sqflite.i {

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

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

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

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

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

    public k(int i10) {
        this.f910a = i10;
        if (i10 != 7) {
            this.f912c = null;
            this.f913d = null;
            this.f911b = 0;
            this.f914e = new Object();
        }
    }

    public static final void l(long j10) throws zzaun {
        long[] jArr = {141540322, 456640674, 1141397064, 993500330, 1614820873, 3337980909L, 410218731, 1716462158, 477127367};
        long j11 = jArr[0];
        long j12 = jArr[1];
        long j13 = jArr[2];
        long j14 = jArr[3];
        long j15 = jArr[4];
        long j16 = jArr[5];
        if (j10 % ((((((j12 & (~j11)) | j13) + ((j11 & j14) | j15)) - j16) + jArr[6]) ^ (jArr[7] % 477127367)) != 0) {
            throw new zzaun();
        }
    }

    @Override // com.tekartik.sqflite.i
    public final void a() {
        Object obj = this.f913d;
        if (((HandlerThread) obj) != null) {
            ((HandlerThread) obj).quit();
            this.f913d = null;
            this.f914e = null;
        }
    }

    @Override // com.tekartik.sqflite.i
    public final void b(com.tekartik.sqflite.f fVar) {
        ((Handler) this.f914e).post(fVar.f24842a);
    }

    public final void d(d1 d1Var) {
        if (d1Var != null) {
            ec.c cVar = (ec.c) d1Var;
            androidx.media3.extractor.f fVar = (androidx.media3.extractor.f) this.f912c;
            androidx.media3.extractor.f[] fVarArr = (androidx.media3.extractor.f[]) cVar.f19915c;
            for (androidx.media3.extractor.f fVar2 : fVarArr) {
                if (fVar2 != null) {
                    fVar2.c();
                }
            }
            cVar.x(fVarArr, fVar);
            ec.b bVar = (ec.b) cVar.f19914b;
            boolean z10 = cVar.f25822e;
            ob.g gVar = z10 ? bVar.f25814b : bVar.f25816d;
            ob.g gVar2 = z10 ? bVar.f25815c : bVar.f25817e;
            int iJ = cVar.j((int) gVar.f31473b);
            int iJ2 = cVar.j((int) gVar2.f31473b);
            int i10 = -1;
            int iMax = 1;
            int i11 = 0;
            while (iJ < iJ2) {
                androidx.media3.extractor.f fVar3 = fVarArr[iJ];
                if (fVar3 != null) {
                    int i12 = fVar3.f3365f;
                    int i13 = i12 - i10;
                    if (i13 == 0) {
                        i11++;
                    } else {
                        if (i13 == 1) {
                            iMax = Math.max(iMax, i11);
                            i10 = fVar3.f3365f;
                        } else if (i13 < 0 || i12 >= fVar.f3365f || i13 > iJ) {
                            fVarArr[iJ] = null;
                        } else {
                            if (iMax > 2) {
                                i13 *= iMax - 2;
                            }
                            boolean z11 = i13 >= iJ;
                            for (int i14 = 1; i14 <= i13 && !z11; i14++) {
                                z11 = fVarArr[iJ - i14] != null;
                            }
                            if (z11) {
                                fVarArr[iJ] = null;
                            } else {
                                i10 = fVar3.f3365f;
                            }
                        }
                        i11 = 1;
                    }
                }
                iJ++;
            }
        }
    }

    public final Looper e() {
        Looper looper;
        Object obj = this.f914e;
        synchronized (obj) {
            try {
                if (this.f911b != 0) {
                    w.f((HandlerThread) this.f912c, "Invalid state: handlerThread should already been initialized.");
                } else if (((HandlerThread) this.f912c) == null) {
                    l0.g("Starting the looper thread.");
                    HandlerThread handlerThread = new HandlerThread("LooperProvider");
                    this.f912c = handlerThread;
                    handlerThread.start();
                    this.f913d = new vi1(((HandlerThread) this.f912c).getLooper(), 0);
                    l0.g("Looper thread started.");
                } else {
                    l0.g("Resuming the looper thread");
                    obj.notifyAll();
                }
                this.f911b++;
                looper = ((HandlerThread) this.f912c).getLooper();
            } catch (Throwable th) {
                throw th;
            }
        }
        return looper;
    }

    public final void f(long j10) throws zzaun, zzauo {
        long[] jArr = {2139842053, 728564241, 750932242, 1403848321, 1892818418, 4558981222L, 1919655804, 1856374729, 899334107};
        long j11 = jArr[0];
        long j12 = jArr[1];
        long j13 = jArr[2];
        long j14 = jArr[3];
        long j15 = jArr[4];
        long j16 = jArr[5];
        long j17 = jArr[6];
        long j18 = jArr[7];
        l(j10);
        long j19 = j10 / (((((((~j11) & j12) | j13) + ((j11 & j14) | j15)) - j16) + j17) ^ (j18 % 899334107));
        if (j19 >= 0 && j19 <= ((sd) this.f912c).f16415a.length) {
            this.f911b = (int) j19;
            return;
        }
        throw new zzauo();
    }

    public final long g() {
        long[] jArr = {491705403, 818579170, 1201981453, 810223590, 1243973916, 3701563257L, 554701476, 1889947178, 1780695788};
        long j10 = jArr[0];
        long j11 = jArr[1];
        long j12 = jArr[2];
        long j13 = jArr[3];
        long j14 = jArr[4];
        long j15 = jArr[5];
        return ((long) this.f911b) * ((((((j11 & (~j10)) | j12) + ((j10 & j13) | j14)) - j15) + jArr[6]) ^ (jArr[7] % 1780695788));
    }

    public final long h() throws zzauo {
        try {
            md mdVar = (md) this.f913d;
            sd sdVar = (sd) this.f912c;
            this.f911b = this.f911b + 1;
            return mdVar.c(sdVar, r2);
        } catch (IndexOutOfBoundsException e10) {
            throw new zzauo(e10);
        }
    }

    public final int i() throws zzauo {
        switch (this.f910a) {
            case 2:
                return this.f911b;
            default:
                int[] iArr = {413360099, 1621678468, 84323740, 1621644360, 385888249, 1519637107, 6072641, 1609416931, 1031126087};
                int i10 = iArr[0];
                int i11 = iArr[1];
                int i12 = iArr[2];
                int i13 = iArr[3];
                int i14 = iArr[4];
                int i15 = iArr[5];
                int i16 = iArr[6];
                int i17 = iArr[7];
                int iA = defpackage.e.a((i11 & (~i10)) | i12, (i10 & i13) | i14, i15, i16);
                int i18 = i17 % 1031126087;
                iArr[0] = 978587665;
                iArr[1] = 1228171537;
                iArr[2] = 1025392332;
                iArr[3] = 1075859857;
                iArr[4] = 983056096;
                iArr[5] = -1399000561;
                iArr[6] = 190113083;
                iArr[7] = 1723578341;
                iArr[8] = 672563970;
                iArr[0] = 1163384280;
                iArr[1] = 546336857;
                iArr[2] = 505597090;
                iArr[3] = 546323033;
                iArr[4] = 358992768;
                iArr[5] = 1545617422;
                iArr[6] = 198628789;
                iArr[7] = 1124734562;
                iArr[8] = 530406424;
                iArr[0] = 217161528;
                iArr[1] = 116398273;
                iArr[2] = 202500381;
                iArr[3] = 316821712;
                iArr[4] = 269928733;
                iArr[5] = 415634774;
                iArr[6] = 5622716;
                iArr[7] = 529302443;
                iArr[8] = 418646579;
                try {
                    md mdVar = (md) this.f913d;
                    sd sdVar = (sd) this.f912c;
                    int i19 = this.f911b;
                    this.f911b = i19 + 1;
                    byte bC = mdVar.c(sdVar, i19);
                    int i20 = iA ^ i18;
                    md mdVar2 = (md) this.f913d;
                    sd sdVar2 = (sd) this.f912c;
                    int i21 = this.f911b;
                    this.f911b = i21 + 1;
                    int iC = (bC & i20) | ((mdVar2.c(sdVar2, i21) & i20) << 8);
                    md mdVar3 = (md) this.f913d;
                    sd sdVar3 = (sd) this.f912c;
                    int i22 = this.f911b;
                    this.f911b = i22 + 1;
                    int iC2 = iC | ((i20 & mdVar3.c(sdVar3, i22)) << 16);
                    md mdVar4 = (md) this.f913d;
                    sd sdVar4 = (sd) this.f912c;
                    int i23 = this.f911b;
                    this.f911b = i23 + 1;
                    return iC2 | (mdVar4.c(sdVar4, i23) << 24);
                } catch (IndexOutOfBoundsException e10) {
                    throw new zzauo(e10);
                }
        }
    }

    public final long j() throws zzaum, zzauo {
        int[] iArr = {1246322141, 272302173, 1841378864, 825937997, 658822930, -1784934195, 38700438, 1600766768, 649830540};
        int i10 = 0;
        int i11 = iArr[0];
        int i12 = iArr[1];
        int i13 = iArr[2];
        int i14 = iArr[3];
        int i15 = iArr[4];
        int i16 = iArr[5];
        int i17 = iArr[6];
        int i18 = iArr[7];
        int iA = defpackage.e.a((i12 & (~i11)) | i13, (i11 & i14) | i15, i16, i17);
        int i19 = i18 % 649830540;
        iArr[0] = 680326130;
        iArr[1] = 1378702392;
        iArr[2] = 3315809;
        iArr[3] = 1913472410;
        iArr[4] = 739293607;
        iArr[5] = -1193353858;
        iArr[6] = 1053514403;
        iArr[7] = 1743768897;
        iArr[8] = 152059765;
        iArr[0] = 973294814;
        iArr[1] = 1252035530;
        iArr[2] = 51191353;
        iArr[3] = 1755616710;
        iArr[4] = 889459732;
        iArr[5] = 1628051670;
        iArr[6] = 133875502;
        iArr[7] = 1861701682;
        iArr[8] = 1196748250;
        iArr[0] = 29116548;
        iArr[1] = 174422021;
        iArr[2] = 84710160;
        iArr[3] = -1973327347;
        iArr[4] = -1266641286;
        iArr[5] = -1298677495;
        iArr[6] = 593052434;
        iArr[7] = 2091729405;
        iArr[8] = 1207774949;
        iArr[0] = 80201211;
        iArr[1] = 1629524354;
        iArr[2] = 38778411;
        iArr[3] = 1977746312;
        iArr[4] = 382371455;
        iArr[5] = -934978761;
        iArr[6] = 1438507752;
        iArr[7] = 1050760512;
        iArr[8] = 184320788;
        long j10 = 0;
        while (i10 < (iA ^ i19)) {
            try {
                md mdVar = (md) this.f913d;
                sd sdVar = (sd) this.f912c;
                int i20 = this.f911b;
                this.f911b = i20 + 1;
                byte bC = mdVar.c(sdVar, i20);
                j10 |= ((long) (bC & 127)) << i10;
                if (i10 == 63) {
                    if (bC > 1) {
                        throw new zzaum();
                    }
                    i10 = 63;
                }
                if ((bC & 128) == 0) {
                    return (j10 >>> 1) ^ (-(j10 & 1));
                }
                i10 += 7;
            } catch (IndexOutOfBoundsException e10) {
                throw new zzauo(e10);
            }
        }
        throw new zzaum();
    }

    public final sd k(long j10) throws zzaun, zzauo {
        int[] iArr = {1667674495, 1502201381, 1197125461, 478240810, 622476187, -1652496091, 840440151, 1203013321, 774318984};
        int i10 = iArr[0];
        int i11 = iArr[1];
        int i12 = iArr[2];
        int i13 = iArr[3];
        int i14 = iArr[4];
        int i15 = iArr[5];
        int i16 = iArr[6];
        int i17 = iArr[7];
        int iA = defpackage.e.a((i11 & (~i10)) | i12, (i10 & i13) | i14, i15, i16);
        l(g() + j10);
        int i18 = this.f911b;
        long j11 = i18;
        sd sdVar = (sd) this.f912c;
        long j12 = (j10 >> ((i17 % 774318984) ^ iA)) + j11;
        if (j12 > sdVar.f16415a.length || j12 < j11) {
            throw new zzauo();
        }
        try {
            int i19 = (int) j12;
            sd sdVarF = ((md) this.f913d).f(sdVar, i18, i19);
            this.f911b = i19;
            return sdVarF;
        } catch (IndexOutOfBoundsException e10) {
            throw new AssertionError(rd.a("CEiv6BFfPnitUE+D"), e10);
        }
    }

    @Override // com.tekartik.sqflite.i
    public final void start() {
        HandlerThread handlerThread = new HandlerThread((String) this.f912c, this.f911b);
        this.f913d = handlerThread;
        handlerThread.start();
        this.f914e = new Handler(((HandlerThread) this.f913d).getLooper());
    }

    public final String toString() {
        switch (this.f910a) {
            case 6:
                d1[] d1VarArr = (d1[]) this.f913d;
                d1 d1Var = d1VarArr[0];
                if (d1Var == null) {
                    d1Var = d1VarArr[this.f911b + 1];
                }
                Formatter formatter = new Formatter();
                for (int i10 = 0; i10 < ((androidx.media3.extractor.f[]) d1Var.f19915c).length; i10++) {
                    try {
                        formatter.format("CW %3d:", Integer.valueOf(i10));
                        for (int i11 = 0; i11 < this.f911b + 2; i11++) {
                            Object obj = this.f913d;
                            if (((d1[]) obj)[i11] == null) {
                                formatter.format("    |   ", new Object[0]);
                            } else {
                                androidx.media3.extractor.f fVar = ((androidx.media3.extractor.f[]) ((d1[]) obj)[i11].f19915c)[i10];
                                if (fVar == null) {
                                    formatter.format("    |   ", new Object[0]);
                                } else {
                                    formatter.format(" %3d|%3d", Integer.valueOf(fVar.f3365f), Integer.valueOf(fVar.f3364e));
                                }
                            }
                        }
                        formatter.format("%n", new Object[0]);
                    } catch (Throwable th) {
                        try {
                            formatter.close();
                            break;
                        } catch (Throwable th2) {
                            th.addSuppressed(th2);
                        }
                        throw th;
                    }
                }
                String string = formatter.toString();
                formatter.close();
                return string;
            default:
                return super.toString();
        }
    }

    @Override // com.google.android.gms.internal.ads.dr0, com.google.android.gms.internal.ads.co0
    /* JADX INFO: renamed from: zza */
    public final /* synthetic */ void mo2zza(Object obj) {
        switch (this.f910a) {
            case 4:
                ((oj2) obj).c(this.f911b);
                break;
            default:
                ((ip2) obj).zzai(0, ((hp2) this.f912c).zzb, (to2) this.f913d, (yo2) this.f914e, this.f911b);
                break;
        }
    }

    public /* synthetic */ k(int i10, fh fhVar, fh fhVar2, nj2 nj2Var) {
        this.f910a = 4;
        this.f912c = nj2Var;
        this.f911b = i10;
        this.f913d = fhVar;
        this.f914e = fhVar2;
    }

    public k(sd sdVar, int i10, md mdVar) {
        this.f910a = 3;
        this.f912c = sdVar;
        this.f911b = i10;
        this.f913d = mdVar;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public k(sd sdVar, int i10, md mdVar, l8.k kVar) {
        this(sdVar, i10, mdVar);
        this.f910a = 3;
        this.f914e = kVar;
    }

    public /* synthetic */ k(hp2 hp2Var, to2 to2Var, yo2 yo2Var, int i10) {
        this.f910a = 5;
        this.f912c = hp2Var;
        this.f913d = to2Var;
        this.f914e = yo2Var;
        this.f911b = i10;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public k(l8.k kVar) {
        this(sd.f16413b, 0, new va2(7));
        this.f910a = 3;
        this.f914e = kVar;
    }

    public k(String str) {
        this.f910a = 2;
        this.f914e = new g7.f(new g7.e());
        this.f912c = str;
    }

    public k(String str, AdFormat adFormat) {
        this.f910a = 2;
        this.f914e = new g7.f(new g7.e());
        this.f912c = str;
        this.f913d = adFormat;
    }

    public k(androidx.media3.extractor.f fVar, ec.b bVar) {
        this.f910a = 6;
        this.f912c = fVar;
        int i10 = fVar.f3361b;
        this.f911b = i10;
        this.f914e = bVar;
        this.f913d = new d1[i10 + 2];
    }

    public k(int i10, int i11) {
        this.f910a = 8;
        this.f912c = "Sqflite";
        this.f911b = i10;
    }

    public k(String str, int i10, Notification notification, String str2) {
        this.f910a = 0;
        this.f912c = str;
        this.f911b = i10;
        this.f914e = notification;
        this.f913d = str2;
    }
}
