package android.support.v4.media.session;

import B4.A;
import B4.C0023t;
import B4.I;
import B4.k0;
import I4.d;
import I4.e;
import K4.y;
import S.g;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Trace;
import android.util.Log;
import android.webkit.WebView;
import c0.C0334b;
import com.google.android.gms.internal.measurement.J1;
import h4.h;
import h4.i;
import io.flutter.embedding.android.KeyboardMap;
import io.flutter.plugin.common.MethodCall;
import io.sentry.B0;
import io.sentry.C0732k1;
import io.sentry.ILogger;
import io.sentry.W0;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.security.GeneralSecurityException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Pattern;
import p0.AbstractC0928a;
import q4.l;
import r4.AbstractC0983h;
import y0.AbstractC1110a;

/* JADX INFO: loaded from: classes.dex */
public abstract class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static long f3667a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static Method f3668b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static Method f3669c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static Method f3670d;

    public static final d5.a a(MethodCall methodCall) {
        Boolean bool = (Boolean) methodCall.argument("isSpeakerphoneOn");
        if (bool == null) {
            throw new IllegalStateException("isSpeakerphoneOn is required");
        }
        boolean zBooleanValue = bool.booleanValue();
        Boolean bool2 = (Boolean) methodCall.argument("stayAwake");
        if (bool2 == null) {
            throw new IllegalStateException("stayAwake is required");
        }
        boolean zBooleanValue2 = bool2.booleanValue();
        Integer num = (Integer) methodCall.argument("contentType");
        if (num == null) {
            throw new IllegalStateException("contentType is required");
        }
        int iIntValue = num.intValue();
        Integer num2 = (Integer) methodCall.argument("usageType");
        if (num2 == null) {
            throw new IllegalStateException("usageType is required");
        }
        int iIntValue2 = num2.intValue();
        Integer num3 = (Integer) methodCall.argument("audioFocus");
        if (num3 == null) {
            throw new IllegalStateException("audioFocus is required");
        }
        int iIntValue3 = num3.intValue();
        Integer num4 = (Integer) methodCall.argument("audioMode");
        if (num4 != null) {
            return new d5.a(zBooleanValue, zBooleanValue2, iIntValue, iIntValue2, iIntValue3, num4.intValue());
        }
        throw new IllegalStateException("audioMode is required");
    }

    public static void b(String str) {
        C0732k1 c0732k1O = C0732k1.O();
        c0732k1O.getClass();
        ((CopyOnWriteArraySet) c0732k1O.f7858l).add(str);
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0042  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static boolean c(int r8, android.graphics.Rect r9, android.graphics.Rect r10, android.graphics.Rect r11) {
        /*
            boolean r0 = d(r8, r9, r10)
            boolean r1 = d(r8, r9, r11)
            if (r1 != 0) goto L75
            if (r0 != 0) goto Le
            goto L75
        Le:
            java.lang.String r0 = "direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}."
            r1 = 130(0x82, float:1.82E-43)
            r2 = 33
            r3 = 66
            r4 = 17
            r5 = 1
            if (r8 == r4) goto L3c
            if (r8 == r2) goto L35
            if (r8 == r3) goto L2e
            if (r8 != r1) goto L28
            int r6 = r9.bottom
            int r7 = r11.top
            if (r6 > r7) goto L74
            goto L42
        L28:
            java.lang.IllegalArgumentException r8 = new java.lang.IllegalArgumentException
            r8.<init>(r0)
            throw r8
        L2e:
            int r6 = r9.right
            int r7 = r11.left
            if (r6 > r7) goto L74
            goto L42
        L35:
            int r6 = r9.top
            int r7 = r11.bottom
            if (r6 < r7) goto L74
            goto L42
        L3c:
            int r6 = r9.left
            int r7 = r11.right
            if (r6 < r7) goto L74
        L42:
            if (r8 == r4) goto L74
            if (r8 != r3) goto L47
            goto L74
        L47:
            int r10 = l(r8, r9, r10)
            if (r8 == r4) goto L69
            if (r8 == r2) goto L64
            if (r8 == r3) goto L5f
            if (r8 != r1) goto L59
            int r8 = r11.bottom
            int r9 = r9.bottom
        L57:
            int r8 = r8 - r9
            goto L6e
        L59:
            java.lang.IllegalArgumentException r8 = new java.lang.IllegalArgumentException
            r8.<init>(r0)
            throw r8
        L5f:
            int r8 = r11.right
            int r9 = r9.right
            goto L57
        L64:
            int r8 = r9.top
            int r9 = r11.top
            goto L57
        L69:
            int r8 = r9.left
            int r9 = r11.left
            goto L57
        L6e:
            int r8 = java.lang.Math.max(r5, r8)
            if (r10 >= r8) goto L75
        L74:
            return r5
        L75:
            r8 = 0
            return r8
        */
        throw new UnsupportedOperationException("Method not decompiled: android.support.v4.media.session.b.c(int, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect):boolean");
    }

    public static boolean d(int i, Rect rect, Rect rect2) {
        if (i != 17) {
            if (i != 33) {
                if (i != 66) {
                    if (i != 130) {
                        throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
                    }
                }
            }
            return rect2.right >= rect.left && rect2.left <= rect.right;
        }
        return rect2.bottom >= rect.top && rect2.top <= rect.bottom;
    }

    public static byte[] e(byte[]... bArr) throws GeneralSecurityException {
        int length = 0;
        for (byte[] bArr2 : bArr) {
            if (length > Integer.MAX_VALUE - bArr2.length) {
                throw new GeneralSecurityException("exceeded size limit");
            }
            length += bArr2.length;
        }
        byte[] bArr3 = new byte[length];
        int length2 = 0;
        for (byte[] bArr4 : bArr) {
            System.arraycopy(bArr4, 0, bArr3, length2, bArr4.length);
            length2 += bArr4.length;
        }
        return bArr3;
    }

    public static InvocationHandler f() {
        ClassLoader classLoader;
        if (Build.VERSION.SDK_INT >= 28) {
            classLoader = WebView.getWebViewClassLoader();
        } else {
            try {
                Method declaredMethod = WebView.class.getDeclaredMethod("getFactory", new Class[0]);
                declaredMethod.setAccessible(true);
                classLoader = declaredMethod.invoke(null, new Object[0]).getClass().getClassLoader();
            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e2) {
                throw new RuntimeException(e2);
            }
        }
        return (InvocationHandler) Class.forName("org.chromium.support_lib_glue.SupportLibReflectionUtil", false, classLoader).getDeclaredMethod("createWebViewProviderFactory", new Class[0]).invoke(null, new Object[0]);
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    public static y g(String str) {
        AbstractC0983h.e("javaName", str);
        int iHashCode = str.hashCode();
        if (iHashCode != 79201641) {
            if (iHashCode != 79923350) {
                switch (iHashCode) {
                    case -503070503:
                        if (str.equals("TLSv1.1")) {
                            return y.TLS_1_1;
                        }
                        break;
                    case -503070502:
                        if (str.equals("TLSv1.2")) {
                            return y.TLS_1_2;
                        }
                        break;
                    case -503070501:
                        if (str.equals("TLSv1.3")) {
                            return y.TLS_1_3;
                        }
                        break;
                }
            } else if (str.equals("TLSv1")) {
                return y.TLS_1_0;
            }
        } else if (str.equals("SSLv3")) {
            return y.SSL_3_0;
        }
        throw new IllegalArgumentException(AbstractC0983h.h("Unexpected TLS version: ", str));
    }

    public static void h(String str, Exception exc) {
        if (exc instanceof InvocationTargetException) {
            Throwable cause = exc.getCause();
            if (!(cause instanceof RuntimeException)) {
                throw new RuntimeException(cause);
            }
            throw ((RuntimeException) cause);
        }
        Log.v("Trace", "Unable to call " + str + " via reflection", exc);
    }

    public static int i(int i) {
        if (i == 1) {
            return 0;
        }
        if (i == 2) {
            return 1;
        }
        if (i == 4) {
            return 2;
        }
        if (i == 8) {
            return 3;
        }
        if (i == 16) {
            return 4;
        }
        if (i == 32) {
            return 5;
        }
        if (i == 64) {
            return 6;
        }
        if (i == 128) {
            return 7;
        }
        if (i == 256) {
            return 8;
        }
        if (i == 512) {
            return 9;
        }
        throw new IllegalArgumentException(AbstractC0928a.i(i, "type needs to be >= FIRST and <= LAST, type="));
    }

    public static boolean j(int i, Rect rect, Rect rect2) {
        if (i == 17) {
            int i5 = rect.right;
            int i6 = rect2.right;
            return (i5 > i6 || rect.left >= i6) && rect.left > rect2.left;
        }
        if (i == 33) {
            int i7 = rect.bottom;
            int i8 = rect2.bottom;
            return (i7 > i8 || rect.top >= i8) && rect.top > rect2.top;
        }
        if (i == 66) {
            int i9 = rect.left;
            int i10 = rect2.left;
            return (i9 < i10 || rect.right <= i10) && rect.right < rect2.right;
        }
        if (i != 130) {
            throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
        }
        int i11 = rect.top;
        int i12 = rect2.top;
        return (i11 < i12 || rect.bottom <= i12) && rect.bottom < rect2.bottom;
    }

    public static boolean k() {
        if (Build.VERSION.SDK_INT >= 29) {
            return AbstractC1110a.c();
        }
        try {
            if (f3668b == null) {
                f3667a = Trace.class.getField("TRACE_TAG_APP").getLong(null);
                f3668b = Trace.class.getMethod("isTagEnabled", Long.TYPE);
            }
            return ((Boolean) f3668b.invoke(null, Long.valueOf(f3667a))).booleanValue();
        } catch (Exception e2) {
            h("isTagEnabled", e2);
            return false;
        }
    }

    public static int l(int i, Rect rect, Rect rect2) {
        int i5;
        int i6;
        if (i == 17) {
            i5 = rect.left;
            i6 = rect2.right;
        } else if (i == 33) {
            i5 = rect.top;
            i6 = rect2.bottom;
        } else if (i == 66) {
            i5 = rect2.left;
            i6 = rect.right;
        } else {
            if (i != 130) {
                throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
            }
            i5 = rect2.top;
            i6 = rect.bottom;
        }
        return Math.max(0, i5 - i6);
    }

    public static Typeface m(Configuration configuration, Typeface typeface) {
        if (Build.VERSION.SDK_INT < 31 || configuration.fontWeightAdjustment == Integer.MAX_VALUE || configuration.fontWeightAdjustment == 0 || typeface == null) {
            return null;
        }
        return Typeface.create(typeface, J1.h(configuration.fontWeightAdjustment + typeface.getWeight(), 1, 1000), typeface.isItalic());
    }

    public static int n(int i, Rect rect, Rect rect2) {
        if (i != 17) {
            if (i != 33) {
                if (i != 66) {
                    if (i != 130) {
                        throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
                    }
                }
            }
            return Math.abs(((rect.width() / 2) + rect.left) - ((rect2.width() / 2) + rect2.left));
        }
        return Math.abs(((rect.height() / 2) + rect.top) - ((rect2.height() / 2) + rect2.top));
    }

    public static Z.a o(String str, g gVar, P2.a aVar, int i) {
        h4.b bVar;
        int i5 = 4;
        if ((i & 2) != 0) {
            gVar = null;
        }
        l c0023t = aVar;
        if ((i & 4) != 0) {
            c0023t = new C0023t(i5);
        }
        e eVar = I.f205a;
        h bVar2 = d.f1002m;
        k0 k0Var = new k0();
        bVar2.getClass();
        i iVar = i.f6533k;
        if (k0Var != iVar) {
            h hVarL = bVar2.l(k0Var.getKey());
            if (hVarL == iVar) {
                bVar2 = k0Var;
            } else {
                h4.d dVar = h4.d.f6532k;
                h4.e eVar2 = (h4.e) hVarL.h(dVar);
                if (eVar2 == null) {
                    bVar = new h4.b(hVarL, k0Var);
                } else {
                    h hVarL2 = hVarL.l(dVar);
                    if (hVarL2 == iVar) {
                        bVar2 = new h4.b(k0Var, eVar2);
                    } else {
                        bVar = new h4.b(new h4.b(hVarL2, k0Var), eVar2);
                    }
                }
                bVar2 = bVar;
            }
        }
        G4.c cVarA = A.a(bVar2);
        AbstractC0983h.e("name", str);
        return new Z.a(str, gVar, c0023t, cVarA);
    }

    public static C0334b p(MappedByteBuffer mappedByteBuffer) throws IOException {
        long j5;
        ByteBuffer byteBufferDuplicate = mappedByteBuffer.duplicate();
        byteBufferDuplicate.order(ByteOrder.BIG_ENDIAN);
        byteBufferDuplicate.position(byteBufferDuplicate.position() + 4);
        int i = byteBufferDuplicate.getShort() & 65535;
        if (i > 100) {
            throw new IOException("Cannot read metadata.");
        }
        byteBufferDuplicate.position(byteBufferDuplicate.position() + 6);
        int i5 = 0;
        while (true) {
            if (i5 >= i) {
                j5 = -1;
                break;
            }
            int i6 = byteBufferDuplicate.getInt();
            byteBufferDuplicate.position(byteBufferDuplicate.position() + 4);
            j5 = ((long) byteBufferDuplicate.getInt()) & KeyboardMap.kValueMask;
            byteBufferDuplicate.position(byteBufferDuplicate.position() + 4);
            if (1835365473 == i6) {
                break;
            }
            i5++;
        }
        if (j5 != -1) {
            byteBufferDuplicate.position(byteBufferDuplicate.position() + ((int) (j5 - ((long) byteBufferDuplicate.position()))));
            byteBufferDuplicate.position(byteBufferDuplicate.position() + 12);
            long j6 = ((long) byteBufferDuplicate.getInt()) & KeyboardMap.kValueMask;
            for (int i7 = 0; i7 < j6; i7++) {
                int i8 = byteBufferDuplicate.getInt();
                long j7 = ((long) byteBufferDuplicate.getInt()) & KeyboardMap.kValueMask;
                byteBufferDuplicate.getInt();
                if (1164798569 == i8 || 1701669481 == i8) {
                    byteBufferDuplicate.position((int) (j7 + j5));
                    C0334b c0334b = new C0334b();
                    byteBufferDuplicate.order(ByteOrder.LITTLE_ENDIAN);
                    int iPosition = byteBufferDuplicate.position() + byteBufferDuplicate.getInt(byteBufferDuplicate.position());
                    c0334b.f2384d = byteBufferDuplicate;
                    c0334b.f2381a = iPosition;
                    int i9 = iPosition - byteBufferDuplicate.getInt(iPosition);
                    c0334b.f2382b = i9;
                    c0334b.f2383c = ((ByteBuffer) c0334b.f2384d).getShort(i9);
                    return c0334b;
                }
            }
        }
        throw new IOException("Cannot read metadata.");
    }

    public static void q(W0 w02, B0 b02, ILogger iLogger) {
        if (w02.f7048k != null) {
            b02.x("event_id").r(iLogger, w02.f7048k);
        }
        b02.x("contexts").r(iLogger, w02.f7049l);
        if (w02.f7050m != null) {
            b02.x("sdk").r(iLogger, w02.f7050m);
        }
        if (w02.f7051n != null) {
            b02.x("request").r(iLogger, w02.f7051n);
        }
        AbstractMap abstractMap = w02.f7052o;
        if (abstractMap != null && !abstractMap.isEmpty()) {
            b02.x("tags").r(iLogger, w02.f7052o);
        }
        if (w02.p != null) {
            b02.x("release").m(w02.p);
        }
        if (w02.q != null) {
            b02.x("environment").m(w02.q);
        }
        if (w02.f7053r != null) {
            b02.x("platform").m(w02.f7053r);
        }
        if (w02.f7054s != null) {
            b02.x("user").r(iLogger, w02.f7054s);
        }
        if (w02.f7056u != null) {
            b02.x("server_name").m(w02.f7056u);
        }
        if (w02.f7057v != null) {
            b02.x("dist").m(w02.f7057v);
        }
        List list = w02.f7058w;
        if (list != null && !list.isEmpty()) {
            b02.x("breadcrumbs").r(iLogger, w02.f7058w);
        }
        if (w02.f7059x != null) {
            b02.x("debug_meta").r(iLogger, w02.f7059x);
        }
        AbstractMap abstractMap2 = w02.f7060y;
        if (abstractMap2 == null || abstractMap2.isEmpty()) {
            return;
        }
        b02.x("extra").r(iLogger, w02.f7060y);
    }

    public static int r(int i) {
        return (int) (((long) Integer.rotateLeft((int) (((long) i) * (-862048943)), 15)) * 461845907);
    }

    public static final String s(String str) {
        AbstractC0983h.e("<this>", str);
        Pattern patternCompile = Pattern.compile("(.)(\\p{Upper})");
        AbstractC0983h.d("compile(...)", patternCompile);
        String strReplaceAll = patternCompile.matcher(str).replaceAll("$1_$2");
        AbstractC0983h.d("replaceAll(...)", strReplaceAll);
        Pattern patternCompile2 = Pattern.compile("(.) (.)");
        AbstractC0983h.d("compile(...)", patternCompile2);
        String strReplaceAll2 = patternCompile2.matcher(strReplaceAll).replaceAll("$1_$2");
        AbstractC0983h.d("replaceAll(...)", strReplaceAll2);
        String upperCase = strReplaceAll2.toUpperCase(Locale.ROOT);
        AbstractC0983h.d("this as java.lang.String).toUpperCase(Locale.ROOT)", upperCase);
        return upperCase;
    }

    public static String t(String str) {
        return str.length() <= 127 ? str : str.substring(0, 127);
    }

    public static final void u(ByteBuffer byteBuffer, ByteBuffer byteBuffer2, ByteBuffer byteBuffer3, int i) {
        if (i < 0 || byteBuffer2.remaining() < i || byteBuffer3.remaining() < i || byteBuffer.remaining() < i) {
            throw new IllegalArgumentException("That combination of buffers, offsets and length to xor result in out-of-bond accesses.");
        }
        for (int i5 = 0; i5 < i; i5++) {
            byteBuffer.put((byte) (byteBuffer2.get() ^ byteBuffer3.get()));
        }
    }

    public static final byte[] v(int i, int i5, int i6, byte[] bArr, byte[] bArr2) {
        if (i6 < 0 || bArr.length - i6 < i || bArr2.length - i6 < i5) {
            throw new IllegalArgumentException("That combination of buffers, offsets and length to xor result in out-of-bond accesses.");
        }
        byte[] bArr3 = new byte[i6];
        for (int i7 = 0; i7 < i6; i7++) {
            bArr3[i7] = (byte) (bArr[i7 + i] ^ bArr2[i7 + i5]);
        }
        return bArr3;
    }

    public static final byte[] w(byte[] bArr, byte[] bArr2) {
        if (bArr.length == bArr2.length) {
            return v(0, 0, bArr.length, bArr, bArr2);
        }
        throw new IllegalArgumentException("The lengths of x and y should match.");
    }
}
