package d3;

import F7.C0131o;
import F7.ExecutorC0117a;
import F7.InterfaceC0121e;
import F7.InterfaceC0123g;
import F7.InterfaceC0124h;
import N1.C0199b0;
import T0.AbstractC0302b;
import T0.C0307g;
import T0.InterfaceC0308h;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.media.LoudnessCodecController;
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Trace;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.Surface;
import android.view.View;
import com.google.android.datatransport.cct.CctBackendFactory;
import com.google.android.datatransport.runtime.backends.TransportBackendDiscovery;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import k7.InterfaceC1113e;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import u.AbstractC1563h;
import u0.C1578n;
import u0.C1579o;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public class R0 implements InterfaceC0308h, A1.E, InterfaceC0123g, InterfaceC0124h, InterfaceC1113e, G0.r, I0.m, I0.n, P0.n {

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

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

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

    public /* synthetic */ R0(int i, boolean z8) {
        this.f11691q = i;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0047 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0042 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static R0 E(Context context) {
        FileChannel channel;
        FileLock fileLockLock;
        try {
            channel = new RandomAccessFile(new File(context.getFilesDir(), "generatefid.lock"), "rw").getChannel();
            try {
                fileLockLock = channel.lock();
            } catch (IOException | Error | OverlappingFileLockException e8) {
                e = e8;
                fileLockLock = null;
            }
        } catch (IOException | Error | OverlappingFileLockException e9) {
            e = e9;
            channel = null;
            fileLockLock = null;
        }
        try {
            return new R0(channel, fileLockLock, 11, false);
        } catch (IOException e10) {
            e = e10;
            Log.e("CrossProcessLock", "encountered error while creating and acquiring the lock, ignoring", e);
            if (fileLockLock != null) {
                try {
                    fileLockLock.release();
                } catch (IOException unused) {
                }
            }
            if (channel != null) {
                try {
                    channel.close();
                } catch (IOException unused2) {
                }
            }
            return null;
        } catch (Error e11) {
            e = e11;
            Log.e("CrossProcessLock", "encountered error while creating and acquiring the lock, ignoring", e);
            if (fileLockLock != null) {
            }
            if (channel != null) {
            }
            return null;
        } catch (OverlappingFileLockException e12) {
            e = e12;
            Log.e("CrossProcessLock", "encountered error while creating and acquiring the lock, ignoring", e);
            if (fileLockLock != null) {
            }
            if (channel != null) {
            }
            return null;
        }
    }

    public static int Q(int i, int i5) {
        int i8 = 0;
        int i9 = 0;
        for (int i10 = 0; i10 < i; i10++) {
            i8++;
            if (i8 == i5) {
                i9++;
                i8 = 0;
            } else if (i8 > i5) {
                i9++;
                i8 = 1;
            }
        }
        return i8 + 1 > i5 ? i9 + 1 : i9;
    }

    @Override // T0.InterfaceC0308h
    public void A() {
        byte[] bArr = x0.v.f18555c;
        x0.o oVar = (x0.o) this.f11693s;
        oVar.getClass();
        oVar.D(bArr.length, bArr);
    }

    @Override // k7.InterfaceC1113e
    public void B(k7.C c3) {
        InterfaceC0124h interfaceC0124h = (InterfaceC0124h) this.f11692r;
        F7.B b8 = (F7.B) this.f11693s;
        try {
            try {
                interfaceC0124h.p(b8, b8.e(c3));
            } catch (Throwable th) {
                F7.b0.s(th);
                th.printStackTrace();
            }
        } catch (Throwable th2) {
            F7.b0.s(th2);
            try {
                interfaceC0124h.v(b8, th2);
            } catch (Throwable th3) {
                F7.b0.s(th3);
                th3.printStackTrace();
            }
        }
    }

    @Override // I0.n
    public MediaFormat C() {
        return ((MediaCodec) this.f11692r).getOutputFormat();
    }

    public void F(N1.t0 t0Var, A7.a aVar) {
        q.i iVar = (q.i) this.f11692r;
        N1.D0 d0A = (N1.D0) iVar.get(t0Var);
        if (d0A == null) {
            d0A = N1.D0.a();
            iVar.put(t0Var, d0A);
        }
        d0A.f4441c = aVar;
        d0A.f4439a |= 8;
    }

    public synchronized void G() {
        if (!((LinkedHashSet) this.f11692r).isEmpty()) {
            ((M4.m) this.f11693s).e(0L);
        }
    }

    public void H() {
        switch (this.f11691q) {
            case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                this.f11692r = null;
                this.f11693s = null;
                break;
            default:
                int[] iArr = (int[]) this.f11692r;
                if (iArr != null) {
                    Arrays.fill(iArr, -1);
                }
                this.f11693s = null;
                break;
        }
    }

    public void I(long j8, x0.o oVar) {
        if (oVar.a() < 9) {
            return;
        }
        int iG = oVar.g();
        int iG2 = oVar.g();
        int iT = oVar.t();
        if (iG == 434 && iG2 == 1195456820 && iT == 3) {
            AbstractC0302b.e(j8, oVar, (T0.F[]) this.f11693s);
        }
    }

    @Override // I0.m
    /* JADX INFO: renamed from: J, reason: merged with bridge method [inline-methods] */
    public I0.d D(O3.q qVar) throws Exception {
        MediaCodec mediaCodecCreateByCodecName;
        String str = ((I0.q) qVar.f5165a).f3234a;
        I0.d dVar = null;
        try {
            Trace.beginSection("createCodec:" + str);
            mediaCodecCreateByCodecName = MediaCodec.createByCodecName(str);
            try {
                I0.d dVar2 = new I0.d(mediaCodecCreateByCodecName, (HandlerThread) ((I0.c) this.f11692r).get(), new I0.g(mediaCodecCreateByCodecName, (HandlerThread) ((I0.c) this.f11693s).get()), (A1.y) qVar.f5170f);
                try {
                    Trace.endSection();
                    Surface surface = (Surface) qVar.f5168d;
                    I0.d.b(dVar2, (MediaFormat) qVar.f5166b, surface, (MediaCrypto) qVar.f5169e, (surface == null && ((I0.q) qVar.f5165a).f3241h && x0.v.f18553a >= 35) ? 8 : 0);
                    return dVar2;
                } catch (Exception e8) {
                    e = e8;
                    dVar = dVar2;
                    if (dVar != null) {
                        dVar.a();
                    } else if (mediaCodecCreateByCodecName != null) {
                        mediaCodecCreateByCodecName.release();
                    }
                    throw e;
                }
            } catch (Exception e9) {
                e = e9;
            }
        } catch (Exception e10) {
            e = e10;
            mediaCodecCreateByCodecName = null;
        }
    }

    public void K(T0.o oVar, A1.M m8) {
        int i = 0;
        while (true) {
            T0.F[] fArr = (T0.F[]) this.f11693s;
            if (i >= fArr.length) {
                return;
            }
            m8.a();
            m8.b();
            T0.F fJ = oVar.j(m8.f102d, 3);
            C1579o c1579o = (C1579o) ((List) this.f11692r).get(i);
            String str = c1579o.f17358n;
            AbstractC1709a.c("Invalid closed caption MIME type provided: " + str, "application/cea-608".equals(str) || "application/cea-708".equals(str));
            C1578n c1578n = new C1578n();
            m8.b();
            c1578n.f17309a = m8.f103e;
            c1578n.f17319l = u0.E.m("video/mp2t");
            c1578n.f17320m = u0.E.m(str);
            c1578n.f17313e = c1579o.f17350e;
            c1578n.f17312d = c1579o.f17349d;
            c1578n.H = c1579o.f17340I;
            c1578n.f17323p = c1579o.f17361q;
            I1.a.w(c1578n, fJ);
            fArr[i] = fJ;
            i++;
        }
    }

    public void L(int i) {
        int[] iArr = (int[]) this.f11692r;
        if (iArr == null) {
            int[] iArr2 = new int[Math.max(i, 10) + 1];
            this.f11692r = iArr2;
            Arrays.fill(iArr2, -1);
        } else if (i >= iArr.length) {
            int length = iArr.length;
            while (length <= i) {
                length *= 2;
            }
            int[] iArr3 = new int[length];
            this.f11692r = iArr3;
            System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
            int[] iArr4 = (int[]) this.f11692r;
            Arrays.fill(iArr4, iArr.length, iArr4.length, -1);
        }
    }

    public View M(int i, int i5, int i8, int i9) {
        View viewH;
        C0199b0 c0199b0 = (C0199b0) this.f11692r;
        int iD = c0199b0.d();
        int iC = c0199b0.c();
        int i10 = i5 > i ? 1 : -1;
        View view = null;
        while (i != i5) {
            switch (c0199b0.f4510a) {
                case n4.u0.f15495q /* 0 */:
                    viewH = c0199b0.f4511b.H(i);
                    break;
                default:
                    viewH = c0199b0.f4511b.H(i);
                    break;
            }
            int iB = c0199b0.b(viewH);
            int iA = c0199b0.a(viewH);
            N1.C0 c02 = (N1.C0) this.f11693s;
            c02.f4426b = iD;
            c02.f4427c = iC;
            c02.f4428d = iB;
            c02.f4429e = iA;
            if (i8 != 0) {
                c02.f4425a = i8;
                if (c02.a()) {
                    return viewH;
                }
            }
            if (i9 != 0) {
                c02.f4425a = i9;
                if (c02.a()) {
                    view = viewH;
                }
            }
            i += i10;
        }
        return view;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x003e  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0046  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public CctBackendFactory N(String str) {
        Bundle bundle;
        Map map;
        PackageManager packageManager;
        if (((Map) this.f11693s) == null) {
            Context context = (Context) this.f11692r;
            try {
                packageManager = context.getPackageManager();
            } catch (PackageManager.NameNotFoundException unused) {
                Log.w("BackendRegistry", "Application info not found.");
            }
            if (packageManager == null) {
                Log.w("BackendRegistry", "Context has no PackageManager.");
            } else {
                ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class<?>) TransportBackendDiscovery.class), 128);
                if (serviceInfo == null) {
                    Log.w("BackendRegistry", "TransportBackendDiscovery has no service info.");
                } else {
                    bundle = serviceInfo.metaData;
                    if (bundle != null) {
                        Log.w("BackendRegistry", "Could not retrieve metadata, returning empty list of transport backends.");
                        map = Collections.EMPTY_MAP;
                    } else {
                        HashMap map2 = new HashMap();
                        for (String str2 : bundle.keySet()) {
                            Object obj = bundle.get(str2);
                            if ((obj instanceof String) && str2.startsWith("backend:")) {
                                for (String str3 : ((String) obj).split(",", -1)) {
                                    String strTrim = str3.trim();
                                    if (!strTrim.isEmpty()) {
                                        map2.put(strTrim, str2.substring(8));
                                    }
                                }
                            }
                        }
                        map = map2;
                    }
                    this.f11693s = map;
                }
            }
            bundle = null;
            if (bundle != null) {
            }
            this.f11693s = map;
        }
        String str4 = (String) ((Map) this.f11693s).get(str);
        if (str4 == null) {
            return null;
        }
        try {
            return (CctBackendFactory) Class.forName(str4).asSubclass(CctBackendFactory.class).getDeclaredConstructor(null).newInstance(null);
        } catch (ClassNotFoundException e8) {
            Log.w("BackendRegistry", "Class " + str4 + " is not found.", e8);
            return null;
        } catch (IllegalAccessException e9) {
            Log.w("BackendRegistry", "Could not instantiate " + str4 + ".", e9);
            return null;
        } catch (InstantiationException e10) {
            Log.w("BackendRegistry", "Could not instantiate " + str4 + ".", e10);
            return null;
        } catch (NoSuchMethodException e11) {
            Log.w("BackendRegistry", "Could not instantiate ".concat(str4), e11);
            return null;
        } catch (InvocationTargetException e12) {
            Log.w("BackendRegistry", "Could not instantiate ".concat(str4), e12);
            return null;
        }
    }

    public P4.d O(M4.f fVar) throws L4.d {
        String string;
        JSONArray jSONArray = fVar.f4237g;
        long j8 = fVar.f4236f;
        HashSet hashSet = new HashSet();
        for (int i = 0; i < jSONArray.length(); i++) {
            try {
                JSONObject jSONObject = jSONArray.getJSONObject(i);
                String string2 = jSONObject.getString("rolloutId");
                JSONArray jSONArray2 = jSONObject.getJSONArray("affectedParameterKeys");
                if (jSONArray2.length() > 1) {
                    Log.w("FirebaseRemoteConfig", String.format("Rollout has multiple affected parameter keys.Only the first key will be included in RolloutsState. rolloutId: %s, affectedParameterKeys: %s", string2, jSONArray2));
                }
                String strOptString = jSONArray2.optString(0, "");
                M4.f fVarC = ((M4.d) this.f11692r).c();
                String string3 = null;
                if (fVarC == null) {
                    string = null;
                } else {
                    try {
                        string = fVarC.f4232b.getString(strOptString);
                    } catch (JSONException unused) {
                        string = null;
                    }
                }
                if (string == null) {
                    M4.f fVarC2 = ((M4.d) this.f11693s).c();
                    if (fVarC2 != null) {
                        try {
                            string3 = fVarC2.f4232b.getString(strOptString);
                        } catch (JSONException unused2) {
                        }
                    }
                    string = string3 != null ? string3 : "";
                }
                int i5 = P4.e.f5508a;
                P4.b bVar = new P4.b();
                if (string2 == null) {
                    throw new NullPointerException("Null rolloutId");
                }
                bVar.f5496a = string2;
                String string4 = jSONObject.getString("variantId");
                if (string4 == null) {
                    throw new NullPointerException("Null variantId");
                }
                bVar.f5497b = string4;
                if (strOptString == null) {
                    throw new NullPointerException("Null parameterKey");
                }
                bVar.f5498c = strOptString;
                bVar.f5499d = string;
                bVar.f5500e = j8;
                bVar.f5501f = (byte) (bVar.f5501f | 1);
                hashSet.add(bVar.a());
            } catch (JSONException e8) {
                throw new L4.d("Exception parsing rollouts metadata to create RolloutsState.", e8);
            }
        }
        return new P4.d(hashSet);
    }

    public File P() {
        if (((File) this.f11692r) == null) {
            synchronized (this) {
                try {
                    if (((File) this.f11692r) == null) {
                        W3.f fVar = (W3.f) this.f11693s;
                        fVar.a();
                        this.f11692r = new File(fVar.f7113a.getFilesDir(), "PersistedInstallation." + ((W3.f) this.f11693s).d() + ".json");
                    }
                } finally {
                }
            }
        }
        return (File) this.f11692r;
    }

    public void R(F4.b bVar) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("Fid", bVar.f2501a);
            jSONObject.put("Status", AbstractC1563h.c(bVar.f2502b));
            jSONObject.put("AuthToken", bVar.f2503c);
            jSONObject.put("RefreshToken", bVar.f2504d);
            jSONObject.put("TokenCreationEpochInSecs", bVar.f2506f);
            jSONObject.put("ExpiresInSecs", bVar.f2505e);
            jSONObject.put("FisError", bVar.f2507g);
            W3.f fVar = (W3.f) this.f11693s;
            fVar.a();
            File fileCreateTempFile = File.createTempFile("PersistedInstallation", "tmp", fVar.f7113a.getFilesDir());
            FileOutputStream fileOutputStream = new FileOutputStream(fileCreateTempFile);
            fileOutputStream.write(jSONObject.toString().getBytes("UTF-8"));
            fileOutputStream.close();
            if (fileCreateTempFile.renameTo(P())) {
            } else {
                throw new IOException("unable to rename the tmpfile to PersistedInstallation");
            }
        } catch (IOException | JSONException unused) {
        }
    }

    public void S() {
        ((SparseIntArray) this.f11692r).clear();
    }

    public boolean T(View view) {
        C0199b0 c0199b0 = (C0199b0) this.f11692r;
        int iD = c0199b0.d();
        int iC = c0199b0.c();
        int iB = c0199b0.b(view);
        int iA = c0199b0.a(view);
        N1.C0 c02 = (N1.C0) this.f11693s;
        c02.f4426b = iD;
        c02.f4427c = iC;
        c02.f4428d = iB;
        c02.f4429e = iA;
        c02.f4425a = 24579;
        return c02.a();
    }

    public void U(int i, int i5) {
        int[] iArr = (int[]) this.f11692r;
        if (iArr == null || i >= iArr.length) {
            return;
        }
        int i8 = i + i5;
        L(i8);
        int[] iArr2 = (int[]) this.f11692r;
        System.arraycopy(iArr2, i, iArr2, i8, (iArr2.length - i) - i5);
        Arrays.fill((int[]) this.f11692r, i, i8, -1);
        ArrayList arrayList = (ArrayList) this.f11693s;
        if (arrayList == null) {
            return;
        }
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            N1.z0 z0Var = (N1.z0) ((ArrayList) this.f11693s).get(size);
            int i9 = z0Var.f4729q;
            if (i9 >= i) {
                z0Var.f4729q = i9 + i5;
            }
        }
    }

    public void V(int i, int i5) {
        int[] iArr = (int[]) this.f11692r;
        if (iArr == null || i >= iArr.length) {
            return;
        }
        int i8 = i + i5;
        L(i8);
        int[] iArr2 = (int[]) this.f11692r;
        System.arraycopy(iArr2, i8, iArr2, i, (iArr2.length - i) - i5);
        int[] iArr3 = (int[]) this.f11692r;
        Arrays.fill(iArr3, iArr3.length - i5, iArr3.length, -1);
        ArrayList arrayList = (ArrayList) this.f11693s;
        if (arrayList == null) {
            return;
        }
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            N1.z0 z0Var = (N1.z0) ((ArrayList) this.f11693s).get(size);
            int i9 = z0Var.f4729q;
            if (i9 >= i) {
                if (i9 < i8) {
                    ((ArrayList) this.f11693s).remove(size);
                } else {
                    z0Var.f4729q = i9 - i5;
                }
            }
        }
    }

    public void W(Throwable th) {
        int i = 1;
        Y0 y02 = (Y0) this.f11693s;
        y02.E();
        y02.f11859y = false;
        C0817r0 c0817r0 = (C0817r0) y02.f5146q;
        int i5 = 2;
        if (c0817r0.f12148w.R(null, I.a1)) {
            String message = th.getMessage();
            y02.D = false;
            if (message != null) {
                if ((th instanceof IllegalStateException) || message.contains("garbage collected") || th.getClass().getSimpleName().equals("ServiceUnavailableException")) {
                    if (message.contains("Background")) {
                        y02.D = true;
                    }
                    i5 = 1;
                } else if ((th instanceof SecurityException) && !message.endsWith("READ_DEVICE_CONFIG")) {
                    i5 = 3;
                }
            }
        }
        int i8 = i5 - 1;
        E1 e12 = (E1) this.f11692r;
        Z z8 = c0817r0.f12150y;
        if (i8 == 0) {
            C0817r0.k(z8);
            z8.f11878y.d("registerTriggerAsync failed with retriable error. Will try later. App ID, throwable", Z.M(c0817r0.n().K()), Z.M(th.toString()));
            y02.f11860z = 1;
            y02.c0().add(e12);
            return;
        }
        if (i8 != 1) {
            C0817r0.k(z8);
            z8.f11875v.d("registerTriggerAsync failed. Dropping URI. App ID, Throwable", Z.M(c0817r0.n().K()), th);
            d0();
            y02.f11860z = 1;
            y02.S();
            return;
        }
        y02.c0().add(e12);
        if (y02.f11860z > ((Integer) I.f11594w0.a(null)).intValue()) {
            y02.f11860z = 1;
            C0817r0.k(z8);
            z8.f11878y.d("registerTriggerAsync failed. May try later. App ID, throwable", Z.M(c0817r0.n().K()), Z.M(th.toString()));
            return;
        }
        C0817r0.k(z8);
        z8.f11878y.e("registerTriggerAsync failed. App ID, delay in seconds, throwable", Z.M(c0817r0.n().K()), Z.M(String.valueOf(y02.f11860z)), Z.M(th.toString()));
        int i9 = y02.f11860z;
        if (y02.f11842A == null) {
            y02.f11842A = new P0(y02, c0817r0, i);
        }
        y02.f11842A.c(((long) i9) * 1000);
        int i10 = y02.f11860z;
        y02.f11860z = i10 + i10;
    }

    public void X(J.h hVar) {
        int i = hVar.f3430b;
        ExecutorC0117a executorC0117a = (ExecutorC0117a) this.f11693s;
        K4.c cVar = (K4.c) this.f11692r;
        if (i != 0) {
            executorC0117a.execute(new J.a(i, 0, cVar));
        } else {
            executorC0117a.execute(new G3.b(cVar, 2, hVar.f3429a));
        }
    }

    public A7.a Y(N1.t0 t0Var, int i) {
        N1.D0 d02;
        A7.a aVar;
        q.i iVar = (q.i) this.f11692r;
        int iC = iVar.c(t0Var);
        if (iC >= 0 && (d02 = (N1.D0) iVar.h(iC)) != null) {
            int i5 = d02.f4439a;
            if ((i5 & i) != 0) {
                int i8 = i5 & (~i);
                d02.f4439a = i8;
                if (i == 4) {
                    aVar = d02.f4440b;
                } else {
                    if (i != 8) {
                        throw new IllegalArgumentException("Must provide flag PRE or POST");
                    }
                    aVar = d02.f4441c;
                }
                if ((i8 & 12) == 0) {
                    iVar.f(iC);
                    d02.f4439a = 0;
                    d02.f4440b = null;
                    d02.f4441c = null;
                    N1.D0.f4438d.c(d02);
                }
                return aVar;
            }
        }
        return null;
    }

    public F4.b Z() {
        JSONObject jSONObject;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[16384];
        try {
            FileInputStream fileInputStream = new FileInputStream(P());
            while (true) {
                try {
                    int i = fileInputStream.read(bArr, 0, 16384);
                    if (i < 0) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, i);
                } finally {
                }
            }
            jSONObject = new JSONObject(byteArrayOutputStream.toString());
            fileInputStream.close();
        } catch (IOException | JSONException unused) {
            jSONObject = new JSONObject();
        }
        String strOptString = jSONObject.optString("Fid", null);
        int iOptInt = jSONObject.optInt("Status", 0);
        String strOptString2 = jSONObject.optString("AuthToken", null);
        String strOptString3 = jSONObject.optString("RefreshToken", null);
        long jOptLong = jSONObject.optLong("TokenCreationEpochInSecs", 0L);
        long jOptLong2 = jSONObject.optLong("ExpiresInSecs", 0L);
        String strOptString4 = jSONObject.optString("FisError", null);
        int i5 = AbstractC1563h.d(5)[iOptInt];
        if (i5 == 0) {
            throw new NullPointerException("Null registrationStatus");
        }
        String str = i5 == 0 ? " registrationStatus" : "";
        if (str.isEmpty()) {
            return new F4.b(strOptString, i5, strOptString2, strOptString3, jOptLong2, jOptLong, strOptString4);
        }
        throw new IllegalStateException("Missing required properties:".concat(str));
    }

    @Override // I0.n
    public void a() {
        A1.y yVar = (A1.y) this.f11693s;
        MediaCodec mediaCodec = (MediaCodec) this.f11692r;
        try {
            int i = x0.v.f18553a;
            if (i >= 30 && i < 33) {
                mediaCodec.stop();
            }
            if (i >= 35 && yVar != null) {
                yVar.z(mediaCodec);
            }
            mediaCodec.release();
        } catch (Throwable th) {
            if (x0.v.f18553a >= 35 && yVar != null) {
                yVar.z(mediaCodec);
            }
            mediaCodec.release();
            throw th;
        }
    }

    public void a0() {
        try {
            ((FileLock) this.f11693s).release();
            ((FileChannel) this.f11692r).close();
        } catch (IOException e8) {
            Log.e("CrossProcessLock", "encountered error while releasing, ignoring", e8);
        }
    }

    public void b0(N1.t0 t0Var) {
        N1.D0 d02 = (N1.D0) ((q.i) this.f11692r).get(t0Var);
        if (d02 == null) {
            return;
        }
        d02.f4439a &= -2;
    }

    @Override // I0.n
    public void c(Bundle bundle) {
        ((MediaCodec) this.f11692r).setParameters(bundle);
    }

    public void c0(N1.t0 t0Var) {
        q.g gVar = (q.g) this.f11693s;
        int iK = gVar.k() - 1;
        while (true) {
            if (iK < 0) {
                break;
            }
            if (t0Var == gVar.l(iK)) {
                Object[] objArr = gVar.f16184s;
                Object obj = objArr[iK];
                Object obj2 = q.h.f16186a;
                if (obj != obj2) {
                    objArr[iK] = obj2;
                    gVar.f16182q = true;
                }
            } else {
                iK--;
            }
        }
        N1.D0 d02 = (N1.D0) ((q.i) this.f11692r).remove(t0Var);
        if (d02 != null) {
            d02.f4439a = 0;
            d02.f4440b = null;
            d02.f4441c = null;
            N1.D0.f4438d.c(d02);
        }
    }

    @Override // I0.n
    public void d(int i, A0.d dVar, long j8, int i5) {
        ((MediaCodec) this.f11692r).queueSecureInputBuffer(i, 0, dVar.i, j8, i5);
    }

    public void d0() {
        C0817r0 c0817r0 = (C0817r0) ((Y0) this.f11693s).f5146q;
        C0785g0 c0785g0 = c0817r0.f12149x;
        C0817r0.i(c0785g0);
        SparseArray sparseArrayK = c0785g0.K();
        E1 e12 = (E1) this.f11692r;
        sparseArrayK.put(e12.f11455s, Long.valueOf(e12.f11454r));
        C0785g0 c0785g02 = c0817r0.f12149x;
        C0817r0.i(c0785g02);
        int[] iArr = new int[sparseArrayK.size()];
        long[] jArr = new long[sparseArrayK.size()];
        for (int i = 0; i < sparseArrayK.size(); i++) {
            iArr[i] = sparseArrayK.keyAt(i);
            jArr[i] = ((Long) sparseArrayK.valueAt(i)).longValue();
        }
        Bundle bundle = new Bundle();
        bundle.putIntArray("uriSources", iArr);
        bundle.putLongArray("uriTimestamps", jArr);
        c0785g02.f11960E.Q(bundle);
    }

    @Override // A1.E
    public void e(x0.o oVar) {
        A1.J j8;
        if (oVar.t() == 0 && (oVar.t() & 128) != 0) {
            oVar.G(6);
            int iA = oVar.a() / 4;
            int i = 0;
            while (true) {
                j8 = (A1.J) this.f11693s;
                if (i >= iA) {
                    break;
                }
                T0.H h8 = (T0.H) this.f11692r;
                oVar.e(h8.f6361d, 0, 4);
                h8.q(0);
                int i5 = h8.i(16);
                h8.t(3);
                if (i5 == 0) {
                    h8.t(13);
                } else {
                    int i8 = h8.i(13);
                    if (j8.f81h.get(i8) == null) {
                        j8.f81h.put(i8, new A1.F(new A1.I(j8, i8)));
                        j8.f86n++;
                    }
                }
                i++;
            }
            if (j8.f74a != 2) {
                j8.f81h.remove(0);
            }
        }
    }

    @Override // I0.n
    public void f(int i, int i5, long j8, int i8) {
        ((MediaCodec) this.f11692r).queueInputBuffer(i, 0, i5, j8, i8);
    }

    @Override // I0.n
    public void flush() {
        ((MediaCodec) this.f11692r).flush();
    }

    @Override // I0.n
    public int g(MediaCodec.BufferInfo bufferInfo) {
        int iDequeueOutputBuffer;
        do {
            iDequeueOutputBuffer = ((MediaCodec) this.f11692r).dequeueOutputBuffer(bufferInfo, 0L);
        } while (iDequeueOutputBuffer == -3);
        return iDequeueOutputBuffer;
    }

    @Override // G0.r
    public P0.n h(G0.n nVar, G0.k kVar) {
        ((x3.e) this.f11692r).getClass();
        return new R0(new G0.q(nVar, kVar), (List) this.f11693s, 20, false);
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x00e5  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0118 A[EDGE_INSN: B:68:0x0118->B:52:0x0118 BREAK  A[LOOP:1: B:38:0x00df->B:51:0x0107], SYNTHETIC] */
    @Override // T0.InterfaceC0308h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0307g i(T0.j jVar, long j8) {
        long j9 = jVar.f6428t;
        int iMin = (int) Math.min(20000L, jVar.f6427s - j9);
        x0.o oVar = (x0.o) this.f11693s;
        oVar.C(iMin);
        jVar.f(oVar.f18539a, 0, iMin, false);
        int i = -1;
        int i5 = -1;
        long j10 = -9223372036854775807L;
        while (oVar.a() >= 4) {
            if (A1.A.a(oVar.f18540b, oVar.f18539a) != 442) {
                oVar.G(1);
            } else {
                oVar.G(4);
                long jC = A1.B.c(oVar);
                if (jC != -9223372036854775807L) {
                    long jB = ((x0.t) this.f11692r).b(jC);
                    if (jB > j8) {
                        return j10 == -9223372036854775807L ? new C0307g(-1, jB, j9) : new C0307g(0, -9223372036854775807L, j9 + ((long) i5));
                    }
                    if (jB + 100000 > j8) {
                        return new C0307g(0, -9223372036854775807L, j9 + ((long) oVar.f18540b));
                    }
                    j10 = jB;
                    i5 = oVar.f18540b;
                }
                int i8 = oVar.f18541c;
                if (oVar.a() < 10) {
                    oVar.F(i8);
                } else {
                    oVar.G(9);
                    int iT = oVar.t() & 7;
                    if (oVar.a() < iT) {
                        oVar.F(i8);
                    } else {
                        oVar.G(iT);
                        if (oVar.a() < 4) {
                            oVar.F(i8);
                        } else {
                            if (A1.A.a(oVar.f18540b, oVar.f18539a) == 443) {
                                oVar.G(4);
                                int iZ = oVar.z();
                                if (oVar.a() >= iZ) {
                                    oVar.G(iZ);
                                    while (true) {
                                        if (oVar.a() >= 4) {
                                            break;
                                        }
                                        int iA = A1.A.a(oVar.f18540b, oVar.f18539a);
                                        if (iA == 442 || iA == 441 || (iA >>> 8) != 1) {
                                            break;
                                        }
                                        oVar.G(4);
                                        if (oVar.a() < 2) {
                                            oVar.F(i8);
                                            break;
                                        }
                                        oVar.F(Math.min(oVar.f18541c, oVar.f18540b + oVar.z()));
                                    }
                                } else {
                                    oVar.F(i8);
                                }
                            } else {
                                while (true) {
                                    if (oVar.a() >= 4) {
                                    }
                                    oVar.F(Math.min(oVar.f18541c, oVar.f18540b + oVar.z()));
                                }
                            }
                        }
                    }
                }
                i = oVar.f18540b;
            }
        }
        return j10 != -9223372036854775807L ? new C0307g(-2, j10, j9 + ((long) i)) : C0307g.f6415d;
    }

    @Override // I0.n
    public void j(long j8, int i) {
        ((MediaCodec) this.f11692r).releaseOutputBuffer(i, j8);
    }

    @Override // I0.n
    public void k() {
        ((MediaCodec) this.f11692r).detachOutputSurface();
    }

    @Override // I0.n
    public ByteBuffer l(int i) {
        return ((MediaCodec) this.f11692r).getInputBuffer(i);
    }

    @Override // I0.n
    public void m(Surface surface) {
        ((MediaCodec) this.f11692r).setOutputSurface(surface);
    }

    @Override // I0.n
    public void n(int i) {
        ((MediaCodec) this.f11692r).releaseOutputBuffer(i, false);
    }

    @Override // F7.InterfaceC0123g
    public Type o() {
        return (Type) this.f11692r;
    }

    @Override // F7.InterfaceC0124h
    public void p(InterfaceC0121e interfaceC0121e, F7.T t6) {
        ((C0131o) this.f11693s).f2713q.execute(new B0.X(this, (InterfaceC0124h) this.f11692r, t6, 2));
    }

    @Override // I0.n
    public ByteBuffer q(int i) {
        return ((MediaCodec) this.f11692r).getOutputBuffer(i);
    }

    @Override // I0.n
    public void r(R0.i iVar, Handler handler) {
        ((MediaCodec) this.f11692r).setOnFrameRenderedListener(new I0.b(this, iVar, 1), handler);
    }

    @Override // F7.InterfaceC0123g
    public Object s(F7.B b8) {
        Executor executor = (Executor) this.f11693s;
        return executor == null ? b8 : new C0131o(executor, b8);
    }

    @Override // I0.n
    public /* synthetic */ boolean t(K4.c cVar) {
        return false;
    }

    @Override // G0.r
    public P0.n u() {
        return new R0(((x3.e) this.f11692r).u(), (List) this.f11693s, 20, false);
    }

    @Override // F7.InterfaceC0124h
    public void v(InterfaceC0121e interfaceC0121e, Throwable th) {
        ((C0131o) this.f11693s).f2713q.execute(new B0.X(this, (InterfaceC0124h) this.f11692r, th, 3));
    }

    @Override // P0.n
    public G0.o w(Uri uri, z0.j jVar) {
        G0.o oVarW = ((P0.n) this.f11692r).w(uri, jVar);
        List list = (List) this.f11693s;
        return (list == null || list.isEmpty()) ? oVarW : (G0.o) oVarW.a(list);
    }

    @Override // k7.InterfaceC1113e
    public void x(o7.i iVar, IOException iOException) {
        try {
            ((InterfaceC0124h) this.f11692r).v((F7.B) this.f11693s, iOException);
        } catch (Throwable th) {
            F7.b0.s(th);
            th.printStackTrace();
        }
    }

    @Override // I0.n
    public int y() {
        return ((MediaCodec) this.f11692r).dequeueInputBuffer(0L);
    }

    @Override // I0.n
    public void z(int i) {
        ((MediaCodec) this.f11692r).setVideoScalingMode(i);
    }

    public /* synthetic */ R0(Object obj, int i, Object obj2) {
        this.f11691q = i;
        this.f11692r = obj2;
        this.f11693s = obj;
    }

    public /* synthetic */ R0(Object obj, Object obj2, int i, boolean z8) {
        this.f11691q = i;
        this.f11692r = obj;
        this.f11693s = obj2;
    }

    public R0(R2.b bVar, C4.f fVar) {
        this.f11691q = 28;
        this.f11693s = "ClientTelemetry.API";
        this.f11692r = bVar;
    }

    public R0(List list) {
        this.f11691q = 4;
        this.f11692r = list;
        this.f11693s = new T0.F[list.size()];
    }

    public R0(D4.b bVar) {
        this.f11691q = 22;
        this.f11693s = Collections.synchronizedMap(new HashMap());
        this.f11692r = bVar;
    }

    public R0(W3.f fVar, E4.e eVar, M4.i iVar, M4.d dVar, Context context, M4.o oVar, ScheduledExecutorService scheduledExecutorService) {
        this.f11691q = 21;
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        this.f11692r = linkedHashSet;
        this.f11693s = new M4.m(fVar, eVar, iVar, dVar, context, linkedHashSet, oVar, scheduledExecutorService);
    }

    public R0(x0.t tVar) {
        this.f11691q = 2;
        this.f11692r = tVar;
        this.f11693s = new x0.o();
    }

    public R0(W3.f fVar) {
        this.f11691q = 12;
        this.f11693s = fVar;
    }

    public R0(Context context, int i) {
        this.f11691q = i;
        switch (i) {
            case 9:
                this.f11692r = context;
                break;
            default:
                this.f11693s = null;
                this.f11692r = context;
                break;
        }
    }

    public R0(MediaCodec mediaCodec, A1.y yVar) {
        this.f11691q = 18;
        this.f11692r = mediaCodec;
        this.f11693s = yVar;
        if (x0.v.f18553a < 35 || yVar == null) {
            return;
        }
        LoudnessCodecController loudnessCodecController = (LoudnessCodecController) yVar.f365t;
        if (loudnessCodecController == null || loudnessCodecController.addMediaCodec(mediaCodec)) {
            AbstractC1709a.j(((HashSet) yVar.f363r).add(mediaCodec));
        }
    }

    public R0(C0199b0 c0199b0) {
        this.f11691q = 26;
        this.f11692r = c0199b0;
        N1.C0 c02 = new N1.C0();
        c02.f4425a = 0;
        this.f11693s = c02;
    }

    public R0(MediaCodec.CryptoInfo cryptoInfo) {
        this.f11691q = 1;
        this.f11692r = cryptoInfo;
        this.f11693s = A0.c.e();
    }

    public R0(ArrayList arrayList, ArrayList arrayList2) {
        this.f11691q = 10;
        int size = arrayList.size();
        this.f11692r = new int[size];
        this.f11693s = new float[size];
        for (int i = 0; i < size; i++) {
            ((int[]) this.f11692r)[i] = ((Integer) arrayList.get(i)).intValue();
            ((float[]) this.f11693s)[i] = ((Float) arrayList2.get(i)).floatValue();
        }
    }

    public R0(int i, int i5) {
        this.f11691q = 10;
        this.f11692r = new int[]{i, i5};
        this.f11693s = new float[]{0.0f, 1.0f};
    }

    public R0(int i, int i5, int i8) {
        this.f11691q = 10;
        this.f11692r = new int[]{i, i5, i8};
        this.f11693s = new float[]{0.0f, 0.5f, 1.0f};
    }

    public R0(A1.J j8) {
        this.f11691q = 3;
        this.f11693s = j8;
        this.f11692r = new T0.H(4, new byte[4]);
    }

    public R0(int i) {
        this.f11691q = i;
        switch (i) {
            case 27:
                this.f11692r = new q.i(0);
                this.f11693s = new q.g();
                break;
            default:
                this.f11692r = new SparseIntArray();
                this.f11693s = new SparseIntArray();
                break;
        }
    }

    @Override // A1.E
    public void b(x0.t tVar, T0.o oVar, A1.M m8) {
    }
}
