package I2;

import Y4.InterfaceC0843i;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader;
import android.os.Build;
import androidx.leanback.widget.C1077i;
import com.google.android.gms.internal.play_billing.zzc;
import com.google.android.gms.internal.play_billing.zzcs;
import com.google.android.gms.internal.play_billing.zzie;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.TimeoutException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import n4.C2626d;
import p0.AbstractC2686D;
import p0.AbstractC2701g;
import p0.AbstractC2715v;
import p5.C2740j;

/* JADX INFO: loaded from: classes.dex */
public final class O implements zzcs, W3.a, p0.O {

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

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

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

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

    public O(int i6, String str, ArrayList arrayList, ArrayList arrayList2) {
        this.f2523a = i6;
        this.f2526d = str;
        this.f2524b = arrayList;
        this.f2525c = arrayList2;
    }

    public void a(boolean z6, n4.w wVar, C2740j c2740j, boolean z7) {
        A4.g.o(c2740j, "source");
        int iMin = Math.min(wVar.f21772c, ((n4.w) wVar.f21776g.f2526d).f21772c);
        C2740j c2740j2 = wVar.f21770a;
        boolean z8 = c2740j2.f23100b > 0;
        int i6 = (int) c2740j.f23100b;
        if (z8 || iMin < i6) {
            if (!z8 && iMin > 0) {
                wVar.b(iMin, c2740j, false);
            }
            c2740j2.write(c2740j, (int) c2740j.f23100b);
            wVar.f21775f = z6 | wVar.f21775f;
        } else {
            wVar.b(i6, c2740j, z6);
        }
        if (z7) {
            try {
                ((C2626d) this.f2525c).flush();
            } catch (IOException e6) {
                throw new RuntimeException(e6);
            }
        }
    }

    public int b() {
        Paint.Cap strokeCap = ((Paint) this.f2524b).getStrokeCap();
        int i6 = strokeCap == null ? -1 : AbstractC2701g.f22918a[strokeCap.ordinal()];
        if (i6 == 1) {
            return 0;
        }
        if (i6 != 2) {
            return i6 != 3 ? 0 : 2;
        }
        return 1;
    }

    @Override // W3.a
    public byte[] c(byte[] bArr, int i6) throws InvalidAlgorithmParameterException {
        if (i6 > this.f2523a) {
            throw new InvalidAlgorithmParameterException("tag size too big");
        }
        Y3.q qVar = (Y3.q) this.f2524b;
        ((Mac) qVar.get()).update(bArr);
        return Arrays.copyOf(((Mac) qVar.get()).doFinal(), i6);
    }

    public int d() {
        Paint.Join strokeJoin = ((Paint) this.f2524b).getStrokeJoin();
        int i6 = strokeJoin == null ? -1 : AbstractC2701g.f22919b[strokeJoin.ordinal()];
        if (i6 == 1) {
            return 0;
        }
        if (i6 != 2) {
            return i6 != 3 ? 0 : 1;
        }
        return 2;
    }

    public void e(float f6) {
        ((Paint) this.f2524b).setAlpha((int) Math.rint(f6 * 255.0f));
    }

    public void f(int i6) {
        if (this.f2523a == i6) {
            return;
        }
        this.f2523a = i6;
        int i7 = Build.VERSION.SDK_INT;
        Paint paint = (Paint) this.f2524b;
        if (i7 >= 29) {
            paint.setBlendMode(AbstractC2686D.E(i6));
        } else {
            paint.setXfermode(new PorterDuffXfermode(AbstractC2686D.M(i6)));
        }
    }

    public void g(long j4) {
        ((Paint) this.f2524b).setColor(AbstractC2686D.I(j4));
    }

    public void h(AbstractC2715v abstractC2715v) {
        this.f2526d = abstractC2715v;
        ((Paint) this.f2524b).setColorFilter(abstractC2715v != null ? abstractC2715v.f22948a : null);
    }

    public void i(int i6) {
        ((Paint) this.f2524b).setFilterBitmap(!(i6 == 0));
    }

    public void j(Shader shader) {
        this.f2525c = shader;
        ((Paint) this.f2524b).setShader(shader);
    }

    public void k(int i6) {
        ((Paint) this.f2524b).setStrokeCap(i6 == 2 ? Paint.Cap.SQUARE : i6 == 1 ? Paint.Cap.ROUND : i6 == 0 ? Paint.Cap.BUTT : Paint.Cap.BUTT);
    }

    public void l(int i6) {
        ((Paint) this.f2524b).setStrokeJoin(i6 == 0 ? Paint.Join.MITER : i6 == 2 ? Paint.Join.BEVEL : i6 == 1 ? Paint.Join.ROUND : Paint.Join.MITER);
    }

    public void m(float f6) {
        ((Paint) this.f2524b).setStrokeWidth(f6);
    }

    public void n(int i6) {
        ((Paint) this.f2524b).setStyle(i6 == 1 ? Paint.Style.STROKE : Paint.Style.FILL);
    }

    public void o(n4.w wVar, int i6) {
        if (wVar == null) {
            ((n4.w) this.f2526d).a(i6);
            p();
            return;
        }
        wVar.a(i6);
        C1077i c1077i = new C1077i();
        wVar.c(Math.min(wVar.f21772c, ((n4.w) wVar.f21776g.f2526d).f21772c), c1077i);
        if (c1077i.f11981a > 0) {
            try {
                ((C2626d) this.f2525c).flush();
            } catch (IOException e6) {
                throw new RuntimeException(e6);
            }
        }
    }

    /*  JADX ERROR: JadxOverflowException in pass: LoopRegionVisitor
        jadx.core.utils.exceptions.JadxOverflowException: LoopRegionVisitor.assignOnlyInLoop endless recursion
        	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
        	at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
        	at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
        */
    public void p() {
        /*
            r13 = this;
            java.lang.Object r0 = r13.f2524b
            n4.n r0 = (n4.n) r0
            n4.w[] r1 = r0.k()
            java.util.List r2 = java.util.Arrays.asList(r1)
            java.util.Collections.shuffle(r2)
            java.lang.Object r2 = r13.f2526d
            n4.w r2 = (n4.w) r2
            int r2 = r2.f21772c
            int r3 = r1.length
        L16:
            r4 = 0
            if (r3 <= 0) goto L6a
            if (r2 <= 0) goto L6a
            float r5 = (float) r2
            float r6 = (float) r3
            float r5 = r5 / r6
            double r5 = (double) r5
            double r5 = java.lang.Math.ceil(r5)
            int r5 = (int) r5
            r6 = r4
            r7 = r6
        L26:
            if (r7 >= r3) goto L68
            if (r2 <= 0) goto L68
            r8 = r1[r7]
            int r9 = r8.f21772c
            p5.j r10 = r8.f21770a
            long r11 = r10.f23100b
            int r11 = (int) r11
            int r9 = java.lang.Math.min(r9, r11)
            int r9 = java.lang.Math.max(r4, r9)
            int r11 = r8.f21773d
            int r9 = r9 - r11
            int r9 = java.lang.Math.min(r9, r5)
            int r9 = java.lang.Math.min(r2, r9)
            if (r9 <= 0) goto L4e
            int r11 = r8.f21773d
            int r11 = r11 + r9
            r8.f21773d = r11
            int r2 = r2 - r9
        L4e:
            int r9 = r8.f21772c
            long r10 = r10.f23100b
            int r10 = (int) r10
            int r9 = java.lang.Math.min(r9, r10)
            int r9 = java.lang.Math.max(r4, r9)
            int r10 = r8.f21773d
            int r9 = r9 - r10
            if (r9 <= 0) goto L65
            int r9 = r6 + 1
            r1[r6] = r8
            r6 = r9
        L65:
            int r7 = r7 + 1
            goto L26
        L68:
            r3 = r6
            goto L16
        L6a:
            androidx.leanback.widget.i r1 = new androidx.leanback.widget.i
            r1.<init>()
            n4.w[] r0 = r0.k()
            int r2 = r0.length
            r3 = r4
        L75:
            if (r3 >= r2) goto L83
            r5 = r0[r3]
            int r6 = r5.f21773d
            r5.c(r6, r1)
            r5.f21773d = r4
            int r3 = r3 + 1
            goto L75
        L83:
            int r0 = r1.f11981a
            if (r0 <= 0) goto L96
            java.lang.Object r0 = r13.f2525c     // Catch: java.io.IOException -> L8f
            n4.d r0 = (n4.C2626d) r0     // Catch: java.io.IOException -> L8f
            r0.flush()     // Catch: java.io.IOException -> L8f
            return
        L8f:
            r0 = move-exception
            java.lang.RuntimeException r1 = new java.lang.RuntimeException
            r1.<init>(r0)
            throw r1
        L96:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: I2.O.p():void");
    }

    @Override // com.google.android.gms.internal.play_billing.zzcs
    public void zza(Throwable th) {
        boolean z6 = th instanceof TimeoutException;
        S s6 = (S) this.f2526d;
        if (z6) {
            s6.P(28, V.f2541E, zzie.BILLING_OVERRIDE_SERVICE_CALL_TIMEOUT);
            zzc.zzo("BillingClientTesting", "Asynchronous call to Billing Override Service timed out.", th);
        } else {
            s6.P(28, V.f2541E, zzie.BILLING_OVERRIDE_SERVICE_CALL_EXCEPTION);
            zzc.zzo("BillingClientTesting", "An error occurred while retrieving billing override.", th);
        }
        ((Runnable) this.f2525c).run();
    }

    @Override // com.google.android.gms.internal.play_billing.zzcs
    public void zzb(Object obj) {
        Integer num = (Integer) obj;
        if (num.intValue() <= 0) {
            ((Runnable) this.f2525c).run();
            return;
        }
        int iIntValue = num.intValue();
        S s6 = (S) this.f2526d;
        s6.getClass();
        C0328l c0328lA = V.a(iIntValue, "Billing override value was set by a license tester.");
        s6.P(this.f2523a, c0328lA, zzie.LICENSE_TESTER_BILLING_OVERRIDE);
        ((E1.a) this.f2524b).accept(c0328lA);
    }

    public O(S s6, int i6, E1.a aVar, Runnable runnable) {
        this.f2523a = i6;
        this.f2524b = aVar;
        this.f2525c = runnable;
        Objects.requireNonNull(s6);
        this.f2526d = s6;
    }

    public O(Paint paint) {
        this.f2524b = paint;
        this.f2523a = 3;
    }

    public O(n4.n nVar, C2626d c2626d) {
        this.f2524b = nVar;
        this.f2525c = c2626d;
        this.f2523a = 65535;
        this.f2526d = new n4.w(this, 0, 65535, null);
    }

    public O(String str, SecretKeySpec secretKeySpec) throws GeneralSecurityException {
        Y3.q qVar = new Y3.q(this);
        this.f2524b = qVar;
        if (A0.a.b(2)) {
            this.f2526d = str;
            this.f2525c = secretKeySpec;
            if (secretKeySpec.getEncoded().length >= 16) {
                switch (str) {
                    case "HMACSHA1":
                        this.f2523a = 20;
                        break;
                    case "HMACSHA224":
                        this.f2523a = 28;
                        break;
                    case "HMACSHA256":
                        this.f2523a = 32;
                        break;
                    case "HMACSHA384":
                        this.f2523a = 48;
                        break;
                    case "HMACSHA512":
                        this.f2523a = 64;
                        break;
                    default:
                        throw new NoSuchAlgorithmException("unknown Hmac algorithm: ".concat(str));
                }
                qVar.get();
                return;
            }
            throw new InvalidAlgorithmParameterException("key size too small, need at least 16 bytes");
        }
        throw new GeneralSecurityException("Can not use HMAC in FIPS-mode, as BoringCrypto module is not available.");
    }

    public O(int i6, A4.j jVar, X4.a aVar, InterfaceC0843i interfaceC0843i) {
        this.f2524b = interfaceC0843i;
        this.f2523a = i6;
        this.f2525c = aVar;
        this.f2526d = jVar;
    }
}
