package android.support.v4.media.session;

import A6.n;
import B6.k;
import E6.i;
import P6.g;
import Q1.c;
import Z6.C0369i;
import Z6.C0379t;
import android.content.Context;
import android.database.SQLException;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.transition.Scene;
import android.util.Log;
import android.view.ViewGroup;
import b7.r;
import b7.s;
import b7.t;
import b7.u;
import com.google.android.gms.internal.measurement.C1;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import k7.x;
import n.C1234s0;
import q1.C1444a;
import q1.C1455l;
import q1.InterfaceC1447d;
import v0.AbstractC1664c;
import x0.d;

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final /* synthetic */ int f7713c = 0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final /* synthetic */ int f7714d = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final /* synthetic */ int f7715e = 0;

    public static void a(Throwable th, Throwable th2) throws IllegalAccessException, InvocationTargetException {
        g.e(th, "<this>");
        g.e(th2, "exception");
        if (th != th2) {
            Integer num = J6.a.f3507a;
            if (num == null || num.intValue() >= 19) {
                th.addSuppressed(th2);
                return;
            }
            Method method = I6.a.f3406a;
            if (method != null) {
                method.invoke(th, th2);
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Type inference failed for: r5v0, types: [O6.a, Q1.c] */
    /* JADX WARN: Type inference failed for: r5v1, types: [O6.a] */
    /* JADX WARN: Type inference failed for: r5v3, types: [O6.a] */
    /* JADX WARN: Type inference failed for: r5v6 */
    /* JADX WARN: Type inference failed for: r5v7 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object b(u uVar, c cVar, G6.c cVar2) throws Throwable {
        r rVar;
        if (cVar2 instanceof r) {
            rVar = (r) cVar2;
            int i = rVar.f9271v;
            if ((i & Integer.MIN_VALUE) != 0) {
                rVar.f9271v = i - Integer.MIN_VALUE;
            } else {
                rVar = new r(cVar2);
            }
        }
        Object obj = rVar.f9270u;
        F6.a aVar = F6.a.f2580q;
        int i5 = rVar.f9271v;
        try {
            if (i5 == 0) {
                C1.N(obj);
                i iVar = rVar.f3016r;
                g.b(iVar);
                if (iVar.K(C0379t.f7546r) != uVar) {
                    throw new IllegalStateException("awaitClose() can only be invoked from the producer context");
                }
                rVar.f9269t = cVar;
                rVar.f9271v = 1;
                C0369i c0369i = new C0369i(1, C1.A(rVar));
                c0369i.v();
                ((t) uVar).j0(new s(c0369i));
                cVar = cVar;
                if (c0369i.u() == aVar) {
                    return aVar;
                }
            } else {
                if (i5 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                O6.a aVar2 = rVar.f9269t;
                C1.N(obj);
                cVar = aVar2;
            }
            cVar.a();
            return n.f457a;
        } catch (Throwable th) {
            cVar.a();
            throw th;
        }
    }

    public static void c(int i, int i5, int i8) {
        if (i >= 0 && i5 <= i8) {
            if (i > i5) {
                throw new IllegalArgumentException(I1.a.o("fromIndex: ", i, i5, " > toIndex: "));
            }
            return;
        }
        throw new IndexOutOfBoundsException("fromIndex: " + i + ", toIndex: " + i5 + ", size: " + i8);
    }

    public static Scene d(ViewGroup viewGroup, Runnable runnable) {
        Scene scene = new Scene(viewGroup);
        scene.setEnterAction(runnable);
        return scene;
    }

    public static void e(String str, String str2, Object obj) {
        String strN = n(str);
        if (Log.isLoggable(strN, 3)) {
            Log.d(strN, String.format(str2, obj));
        }
    }

    public static void g(String str, String str2, Exception exc) {
        String strN = n(str);
        if (Log.isLoggable(strN, 6)) {
            Log.e(strN, str2, exc);
        }
    }

    public static final void i(X1.a aVar, String str) {
        g.e(aVar, "<this>");
        g.e(str, "sql");
        X1.c cVarH0 = aVar.h0(str);
        try {
            cVarH0.W();
            W3.b.j(cVarH0, null);
        } finally {
        }
    }

    public static x j(String str) throws IOException {
        if (str.equals("http/1.0")) {
            return x.f14194r;
        }
        if (str.equals("http/1.1")) {
            return x.f14195s;
        }
        if (str.equals("h2_prior_knowledge")) {
            return x.f14198v;
        }
        if (str.equals("h2")) {
            return x.f14197u;
        }
        if (str.equals("spdy/3.1")) {
            return x.f14196t;
        }
        if (str.equals("quic")) {
            return x.f14199w;
        }
        throw new IOException("Unexpected protocol: ".concat(str));
    }

    public static Drawable l(Context context, int i) {
        return C1234s0.d().f(context, i);
    }

    public static long m(double d8) {
        AbstractC1664c.e("not a normal value", o(d8));
        int exponent = Math.getExponent(d8);
        long jDoubleToRawLongBits = Double.doubleToRawLongBits(d8) & 4503599627370495L;
        return exponent == -1023 ? jDoubleToRawLongBits << 1 : jDoubleToRawLongBits | 4503599627370496L;
    }

    public static String n(String str) {
        if (Build.VERSION.SDK_INT >= 26) {
            return "TRuntime.".concat(str);
        }
        String strConcat = "TRuntime.".concat(str);
        return strConcat.length() > 23 ? strConcat.substring(0, 23) : strConcat;
    }

    public static boolean o(double d8) {
        return Math.getExponent(d8) <= 1023;
    }

    public static void q(InterfaceC1447d interfaceC1447d, int i, d dVar) {
        long jI = interfaceC1447d.i(i);
        List listF = interfaceC1447d.f(jI);
        if (listF.isEmpty()) {
            return;
        }
        if (i == interfaceC1447d.k() - 1) {
            throw new IllegalStateException();
        }
        long jI2 = interfaceC1447d.i(i + 1) - interfaceC1447d.i(i);
        if (jI2 > 0) {
            dVar.a(new C1444a(jI, jI2, listF));
        }
    }

    public static int s(double d8) {
        if (Double.isNaN(d8)) {
            throw new IllegalArgumentException("Cannot round NaN value.");
        }
        if (d8 > 2.147483647E9d) {
            return Integer.MAX_VALUE;
        }
        if (d8 < -2.147483648E9d) {
            return Integer.MIN_VALUE;
        }
        return (int) Math.round(d8);
    }

    public static final void t(int i, String str) {
        StringBuilder sb = new StringBuilder();
        sb.append("Error code: " + i);
        if (str != null) {
            sb.append(", message: ".concat(str));
        }
        throw new SQLException(sb.toString());
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0051  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void u(InterfaceC1447d interfaceC1447d, C1455l c1455l, d dVar) {
        int iB;
        boolean z8;
        long j8 = c1455l.f16222a;
        if (j8 == -9223372036854775807L) {
            iB = 0;
        } else {
            iB = interfaceC1447d.b(j8);
            if (iB == -1) {
                iB = interfaceC1447d.k();
            }
            if (iB > 0 && interfaceC1447d.i(iB - 1) == j8) {
                iB--;
            }
        }
        if (j8 == -9223372036854775807L || iB >= interfaceC1447d.k()) {
            z8 = false;
        } else {
            List listF = interfaceC1447d.f(j8);
            long jI = interfaceC1447d.i(iB);
            if (!listF.isEmpty()) {
                long j9 = c1455l.f16222a;
                if (j9 < jI) {
                    dVar.a(new C1444a(j9, jI - j9, listF));
                    z8 = true;
                }
            }
        }
        for (int i = iB; i < interfaceC1447d.k(); i++) {
            q(interfaceC1447d, i, dVar);
        }
        if (c1455l.f16223b) {
            if (z8) {
                iB--;
            }
            for (int i5 = 0; i5 < iB; i5++) {
                q(interfaceC1447d, i5, dVar);
            }
            if (z8) {
                dVar.a(new C1444a(interfaceC1447d.i(iB), j8 - interfaceC1447d.i(iB), interfaceC1447d.f(j8)));
            }
        }
    }

    public static final List v(List list) {
        int size = list.size();
        return size != 0 ? size != 1 ? Collections.unmodifiableList(new ArrayList(list)) : Collections.singletonList(k.h0(list)) : B6.t.f1032q;
    }

    public static final Map w(Map map) {
        int size = map.size();
        if (size == 0) {
            return B6.u.f1033q;
        }
        if (size != 1) {
            return Collections.unmodifiableMap(new LinkedHashMap(map));
        }
        Map.Entry entry = (Map.Entry) k.g0(map.entrySet());
        return Collections.singletonMap(entry.getKey(), entry.getValue());
    }

    public static int x(int i) {
        if (i == 0) {
            return 1;
        }
        if (i == 1) {
            return 2;
        }
        if (i == 2) {
            return 3;
        }
        if (i != 3) {
            return i != 4 ? 0 : 5;
        }
        return 4;
    }

    public abstract String f(byte[] bArr, int i, int i5);

    public abstract int h(String str, byte[] bArr, int i, int i5);

    public abstract void k(x3.t tVar, float f3, float f7);

    public boolean p(byte[] bArr, int i, int i5) {
        return r(bArr, i, i5) == 0;
    }

    public abstract int r(byte[] bArr, int i, int i5);
}
