package u;

import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.util.JsonWriter;
import android.util.SparseArray;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.room.RoomDatabase;
import androidx.room.s0;
import androidx.room.t0;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.internal.ads.to;
import com.google.android.gms.internal.measurement.k4;
import com.google.android.gms.internal.measurement.l1;
import com.google.android.gms.internal.measurement.n;
import com.google.android.gms.internal.measurement.o;
import com.google.android.gms.internal.measurement.s6;
import com.google.android.gms.internal.measurement.ua;
import com.google.android.gms.internal.measurement.y5;
import com.google.android.gms.internal.measurement.z4;
import com.google.android.gms.internal.measurement.z9;
import com.google.android.gms.internal.pal.c7;
import com.google.android.gms.measurement.internal.y0;
import com.google.android.gms.measurement.internal.z;
import ea.m;
import ea.p;
import ea.q;
import ea.t;
import ie.b4;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import ma.u;
import n4.l;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.ui.IjkPlayerRuntime;
import xyz.stream.utils.f0;
import xyz.stream.view.listener.OnDialogSelectListener;

/* JADX INFO: loaded from: classes.dex */
public final class e implements l, q7.f, to, c7, OnDialogSelectListener {

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

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

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

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

    public /* synthetic */ e(Object obj, Object obj2, Object obj3, Object obj4) {
        this.f33125a = obj;
        this.f33126b = obj2;
        this.f33127c = obj3;
        this.f33128d = obj4;
    }

    public final ea.g a() throws GeneralSecurityException {
        ta.a aVarB;
        m mVar = (m) this.f33125a;
        if (mVar == null) {
            throw new GeneralSecurityException("Cannot build without parameters");
        }
        f0 f0Var = (f0) this.f33126b;
        if (f0Var == null || ((f0) this.f33127c) == null) {
            throw new GeneralSecurityException("Cannot build without key material");
        }
        if (mVar.f25697a != f0Var.E()) {
            throw new GeneralSecurityException("AES key size mismatch");
        }
        if (((m) this.f33125a).f25698b != ((f0) this.f33127c).E()) {
            throw new GeneralSecurityException("HMAC key size mismatch");
        }
        if (((m) this.f33125a).a() && ((Integer) this.f33128d) == null) {
            throw new GeneralSecurityException("Cannot create key without ID requirement with parameters with ID requirement");
        }
        if (!((m) this.f33125a).a() && ((Integer) this.f33128d) != null) {
            throw new GeneralSecurityException("Cannot create key with ID requirement with parameters without ID requirement");
        }
        ea.l lVar = ((m) this.f33125a).f25701e;
        if (lVar == ea.l.f25688d) {
            aVarB = u.f30557a;
        } else if (lVar == ea.l.f25687c) {
            aVarB = u.a(((Integer) this.f33128d).intValue());
        } else {
            if (lVar != ea.l.f25686b) {
                throw new IllegalStateException("Unknown AesCtrHmacAeadParameters.Variant: " + ((m) this.f33125a).f25701e);
            }
            aVarB = u.b(((Integer) this.f33128d).intValue());
        }
        return new ea.g((m) this.f33125a, (f0) this.f33126b, (f0) this.f33127c, aVarB, (Integer) this.f33128d);
    }

    public final q b() throws GeneralSecurityException {
        Integer num = (Integer) this.f33125a;
        if (num == null) {
            throw new GeneralSecurityException("Key size is not set");
        }
        if (((Integer) this.f33126b) == null) {
            throw new GeneralSecurityException("IV size is not set");
        }
        if (((p) this.f33128d) == null) {
            throw new GeneralSecurityException("Variant is not set");
        }
        if (((Integer) this.f33127c) != null) {
            return new q(num.intValue(), ((Integer) this.f33126b).intValue(), ((Integer) this.f33127c).intValue(), (p) this.f33128d);
        }
        throw new GeneralSecurityException("Tag size is not set");
    }

    @Override // q7.f
    public final /* synthetic */ void c(JsonWriter jsonWriter) throws IOException {
        q7.g.c((String) this.f33125a, (String) this.f33126b, (Map) this.f33127c, (byte[]) this.f33128d, jsonWriter);
    }

    public final ea.u d() throws GeneralSecurityException {
        Integer num = (Integer) this.f33125a;
        if (num == null) {
            throw new GeneralSecurityException("Key size is not set");
        }
        if (((t) this.f33128d) == null) {
            throw new GeneralSecurityException("Variant is not set");
        }
        if (((Integer) this.f33126b) == null) {
            throw new GeneralSecurityException("IV size is not set");
        }
        if (((Integer) this.f33127c) != null) {
            return new ea.u(num.intValue(), ((Integer) this.f33126b).intValue(), ((Integer) this.f33127c).intValue(), (t) this.f33128d);
        }
        throw new GeneralSecurityException("Tag size is not set");
    }

    public final na.l e() throws GeneralSecurityException {
        Integer num = (Integer) this.f33125a;
        if (num == null) {
            throw new GeneralSecurityException("key size is not set");
        }
        if (((Integer) this.f33126b) == null) {
            throw new GeneralSecurityException("tag size is not set");
        }
        if (((na.j) this.f33127c) == null) {
            throw new GeneralSecurityException("hash type is not set");
        }
        if (((na.k) this.f33128d) == null) {
            throw new GeneralSecurityException("variant is not set");
        }
        if (num.intValue() < 16) {
            throw new InvalidAlgorithmParameterException(String.format("Invalid key size in bytes %d; must be at least 16 bytes", (Integer) this.f33125a));
        }
        int iIntValue = ((Integer) this.f33126b).intValue();
        na.j jVar = (na.j) this.f33127c;
        if (iIntValue < 10) {
            throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; must be at least 10 bytes", Integer.valueOf(iIntValue)));
        }
        if (jVar == na.j.f31152b) {
            if (iIntValue > 20) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 20 bytes for SHA1", Integer.valueOf(iIntValue)));
            }
        } else if (jVar == na.j.f31153c) {
            if (iIntValue > 28) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 28 bytes for SHA224", Integer.valueOf(iIntValue)));
            }
        } else if (jVar == na.j.f31154d) {
            if (iIntValue > 32) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 32 bytes for SHA256", Integer.valueOf(iIntValue)));
            }
        } else if (jVar == na.j.f31155e) {
            if (iIntValue > 48) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 48 bytes for SHA384", Integer.valueOf(iIntValue)));
            }
        } else {
            if (jVar != na.j.f31156f) {
                throw new GeneralSecurityException("unknown hash type; must be SHA256, SHA384 or SHA512");
            }
            if (iIntValue > 64) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 64 bytes for SHA512", Integer.valueOf(iIntValue)));
            }
        }
        return new na.l(((Integer) this.f33125a).intValue(), ((Integer) this.f33126b).intValue(), (na.k) this.f33128d, (na.j) this.f33127c);
    }

    public final void f(String str) {
        ((RoomDatabase) this.f33125a).assertNotSuspendingTransaction();
        l3.j jVarA = ((t0) this.f33127c).a();
        if (str == null) {
            jVarA.d(1);
        } else {
            jVarA.l(1, str);
        }
        ((RoomDatabase) this.f33125a).beginTransaction();
        try {
            jVarA.n();
            ((RoomDatabase) this.f33125a).setTransactionSuccessful();
        } finally {
            ((RoomDatabase) this.f33125a).endTransaction();
            ((t0) this.f33127c).c(jVarA);
        }
    }

    public final void g() {
        ((RoomDatabase) this.f33125a).assertNotSuspendingTransaction();
        l3.j jVarA = ((t0) this.f33128d).a();
        ((RoomDatabase) this.f33125a).beginTransaction();
        try {
            jVarA.n();
            ((RoomDatabase) this.f33125a).setTransactionSuccessful();
        } finally {
            ((RoomDatabase) this.f33125a).endTransaction();
            ((t0) this.f33128d).c(jVarA);
        }
    }

    @Override // n4.l
    public final androidx.work.i getProgressForWorkSpecId(String str) {
        s0 s0VarK = s0.k(1, "SELECT progress FROM WorkProgress WHERE work_spec_id=?");
        if (str == null) {
            s0VarK.d(1);
        } else {
            s0VarK.l(1, str);
        }
        ((RoomDatabase) this.f33125a).assertNotSuspendingTransaction();
        Cursor cursorC = androidx.room.util.b.c((RoomDatabase) this.f33125a, s0VarK);
        try {
            return cursorC.moveToFirst() ? androidx.work.i.a(cursorC.getBlob(0)) : null;
        } finally {
            cursorC.close();
            s0VarK.m();
        }
    }

    public final void h(n4.k kVar) {
        ((RoomDatabase) this.f33125a).assertNotSuspendingTransaction();
        ((RoomDatabase) this.f33125a).beginTransaction();
        try {
            ((androidx.room.i) this.f33126b).e(kVar);
            ((RoomDatabase) this.f33125a).setTransactionSuccessful();
        } finally {
            ((RoomDatabase) this.f33125a).endTransaction();
        }
    }

    public final void i() {
        this.f33126b = 12;
    }

    public final void j(int i10) throws GeneralSecurityException {
        if (i10 != 12 && i10 != 16) {
            throw new GeneralSecurityException(String.format("Invalid IV size in bytes %d; acceptable values have 12 or 16 bytes", Integer.valueOf(i10)));
        }
        this.f33126b = Integer.valueOf(i10);
    }

    public final void k(int i10) throws InvalidAlgorithmParameterException {
        if (i10 != 16 && i10 != 24 && i10 != 32) {
            throw new InvalidAlgorithmParameterException(String.format("Invalid key size %d; only 16-byte, 24-byte and 32-byte AES keys are supported", Integer.valueOf(i10)));
        }
        this.f33125a = Integer.valueOf(i10);
    }

    public final void l(int i10) throws InvalidAlgorithmParameterException {
        if (i10 != 16 && i10 != 24 && i10 != 32) {
            throw new InvalidAlgorithmParameterException(String.format("Invalid key size %d; only 16-byte, 24-byte and 32-byte AES keys are supported", Integer.valueOf(i10)));
        }
        this.f33125a = Integer.valueOf(i10);
    }

    public final void m() {
        this.f33127c = 16;
    }

    public final void n() {
        this.f33127c = 16;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x008f  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0124 A[Catch: NumberFormatException | JSONException -> 0x012c, NumberFormatException | JSONException -> 0x012c, TRY_LEAVE, TryCatch #1 {NumberFormatException | JSONException -> 0x012c, blocks: (B:9:0x002b, B:42:0x0097, B:42:0x0097, B:43:0x00a8, B:43:0x00a8, B:45:0x00bb, B:45:0x00bb, B:47:0x00cd, B:47:0x00cd, B:48:0x00d6, B:48:0x00d6, B:49:0x00da, B:49:0x00da, B:51:0x00ed, B:51:0x00ed, B:53:0x00ff, B:53:0x00ff, B:54:0x0108, B:54:0x0108, B:55:0x010c, B:55:0x010c, B:56:0x0118, B:56:0x0118, B:57:0x0124, B:57:0x0124, B:20:0x0058, B:23:0x0062, B:26:0x006c, B:29:0x0076, B:32:0x0080), top: B:75:0x002b, outer: #0 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Bundle o() {
        byte b10;
        if (((Bundle) this.f33127c) == null) {
            String string = ((y0) this.f33128d).F().getString((String) this.f33125a, null);
            if (string != null) {
                try {
                    Bundle bundle = new Bundle();
                    JSONArray jSONArray = new JSONArray(string);
                    for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                        try {
                            JSONObject jSONObject = jSONArray.getJSONObject(i10);
                            String string2 = jSONObject.getString("n");
                            String string3 = jSONObject.getString("t");
                            int iHashCode = string3.hashCode();
                            if (iHashCode == 100) {
                                if (string3.equals("d")) {
                                    b10 = 1;
                                }
                                if (b10 == 0) {
                                }
                            } else if (iHashCode == 108) {
                                if (string3.equals(CmcdData.STREAM_TYPE_LIVE)) {
                                    b10 = 2;
                                }
                                if (b10 == 0) {
                                }
                            } else if (iHashCode == 115) {
                                if (string3.equals(CmcdData.STREAMING_FORMAT_SS)) {
                                    b10 = 0;
                                }
                                if (b10 == 0) {
                                }
                            } else if (iHashCode != 3352) {
                                b10 = (iHashCode == 3445 && string3.equals("la")) ? (byte) 4 : (byte) -1;
                                if (b10 == 0) {
                                    bundle.putString(string2, jSONObject.getString("v"));
                                } else if (b10 == 1) {
                                    bundle.putDouble(string2, Double.parseDouble(jSONObject.getString("v")));
                                } else if (b10 == 2) {
                                    bundle.putLong(string2, Long.parseLong(jSONObject.getString("v")));
                                } else if (b10 == 3) {
                                    z9.a();
                                    if (((y0) this.f33128d).s().J(null, z.H0)) {
                                        JSONArray jSONArray2 = new JSONArray(jSONObject.getString("v"));
                                        int length = jSONArray2.length();
                                        int[] iArr = new int[length];
                                        for (int i11 = 0; i11 < length; i11++) {
                                            iArr[i11] = jSONArray2.optInt(i11);
                                        }
                                        bundle.putIntArray(string2, iArr);
                                    }
                                } else if (b10 != 4) {
                                    ((y0) this.f33128d).zzj().f21834f.b(string3, "Unrecognized persisted bundle type. Type");
                                } else {
                                    z9.a();
                                    if (((y0) this.f33128d).s().J(null, z.H0)) {
                                        JSONArray jSONArray3 = new JSONArray(jSONObject.getString("v"));
                                        int length2 = jSONArray3.length();
                                        long[] jArr = new long[length2];
                                        for (int i12 = 0; i12 < length2; i12++) {
                                            jArr[i12] = jSONArray3.optLong(i12);
                                        }
                                        bundle.putLongArray(string2, jArr);
                                    }
                                }
                            } else {
                                if (string3.equals("ia")) {
                                    b10 = 3;
                                }
                                if (b10 == 0) {
                                }
                            }
                        } catch (NumberFormatException | JSONException unused) {
                            ((y0) this.f33128d).zzj().f21834f.c("Error reading value from SharedPreferences. Value dropped");
                        }
                    }
                    this.f33127c = bundle;
                } catch (JSONException unused2) {
                    ((y0) this.f33128d).zzj().f21834f.c("Error loading bundle from SharedPreferences. Values will be lost");
                }
            }
            if (((Bundle) this.f33127c) == null) {
                this.f33127c = (Bundle) this.f33126b;
            }
        }
        return ((y0) this.f33128d).s().J(null, z.f22044j1) ? new Bundle((Bundle) w.checkNotNull((Bundle) this.f33127c)) : (Bundle) w.checkNotNull((Bundle) this.f33127c);
    }

    @Override // xyz.stream.view.listener.OnDialogSelectListener
    public final void onCancelClick() {
        super.onCancelClick();
        ((e.m) this.f33125a).show();
    }

    @Override // xyz.stream.view.listener.OnDialogSelectListener
    public final void onItemSelected(int i10) {
        ((e.m) this.f33125a).show();
        for (Map.Entry entry : ((Map) this.f33126b).entrySet()) {
            if (((String) entry.getValue()).equals(((List) this.f33127c).get(i10))) {
                f0.o().v(((Integer) entry.getKey()).intValue(), IjkPlayerRuntime.SP_SUBTITLE_SIZE);
                ((b4) this.f33128d).f26711x.setText((CharSequence) entry.getValue());
                return;
            }
        }
    }

    public final n p(com.google.android.gms.internal.measurement.e eVar) {
        n nVarA = n.f20321v;
        Iterator itP = eVar.p();
        while (itP.hasNext()) {
            nVarA = ((z4) this.f33126b).a(this, eVar.h(((Integer) itP.next()).intValue()));
            if (nVarA instanceof com.google.android.gms.internal.measurement.h) {
                break;
            }
        }
        return nVarA;
    }

    public final n q(n nVar) {
        return ((z4) this.f33126b).a(this, nVar);
    }

    public final n r(String str) {
        e eVar = this;
        while (!((Map) eVar.f33127c).containsKey(str)) {
            Object obj = eVar.f33125a;
            if (((e) obj) == null) {
                throw new IllegalArgumentException(String.format("%s is not defined", str));
            }
            eVar = (e) obj;
        }
        return (n) ((Map) eVar.f33127c).get(str);
    }

    public final n s(e eVar, k4... k4VarArr) {
        n nVarI = n.f20321v;
        for (k4 k4Var : k4VarArr) {
            nVarI = y5.i(k4Var);
            y5.w((e) this.f33127c);
            if ((nVarI instanceof com.google.android.gms.internal.measurement.q) || (nVarI instanceof o)) {
                nVarI = ((z4) this.f33125a).a(eVar, nVarI);
            }
        }
        return nVarI;
    }

    public final e t() {
        return new e(this, (z4) this.f33126b);
    }

    public final void u(Bundle bundle) {
        if (bundle == null) {
            bundle = new Bundle();
        } else if (((y0) this.f33128d).s().J(null, z.f22044j1)) {
            bundle = new Bundle(bundle);
        }
        SharedPreferences.Editor editorEdit = ((y0) this.f33128d).F().edit();
        if (bundle.size() == 0) {
            editorEdit.remove((String) this.f33125a);
        } else {
            String str = (String) this.f33125a;
            JSONArray jSONArray = new JSONArray();
            for (String str2 : bundle.keySet()) {
                Object obj = bundle.get(str2);
                if (obj != null) {
                    try {
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("n", str2);
                        z9.a();
                        if (((y0) this.f33128d).s().J(null, z.H0)) {
                            if (obj instanceof String) {
                                jSONObject.put("v", String.valueOf(obj));
                                jSONObject.put("t", CmcdData.STREAMING_FORMAT_SS);
                            } else if (obj instanceof Long) {
                                jSONObject.put("v", String.valueOf(obj));
                                jSONObject.put("t", CmcdData.STREAM_TYPE_LIVE);
                            } else if (obj instanceof int[]) {
                                jSONObject.put("v", Arrays.toString((int[]) obj));
                                jSONObject.put("t", "ia");
                            } else if (obj instanceof long[]) {
                                jSONObject.put("v", Arrays.toString((long[]) obj));
                                jSONObject.put("t", "la");
                            } else if (obj instanceof Double) {
                                jSONObject.put("v", String.valueOf(obj));
                                jSONObject.put("t", "d");
                            } else {
                                ((y0) this.f33128d).zzj().f21834f.b(obj.getClass(), "Cannot serialize bundle value to SharedPreferences. Type");
                            }
                            jSONArray.put(jSONObject);
                        } else {
                            jSONObject.put("v", String.valueOf(obj));
                            if (obj instanceof String) {
                                jSONObject.put("t", CmcdData.STREAMING_FORMAT_SS);
                            } else if (obj instanceof Long) {
                                jSONObject.put("t", CmcdData.STREAM_TYPE_LIVE);
                            } else if (obj instanceof Double) {
                                jSONObject.put("t", "d");
                            } else {
                                ((y0) this.f33128d).zzj().f21834f.b(obj.getClass(), "Cannot serialize bundle value to SharedPreferences. Type");
                            }
                            jSONArray.put(jSONObject);
                        }
                    } catch (JSONException e10) {
                        ((y0) this.f33128d).zzj().f21834f.b(e10, "Cannot serialize bundle value to SharedPreferences");
                    }
                }
            }
            editorEdit.putString(str, jSONArray.toString());
        }
        editorEdit.apply();
        this.f33127c = bundle;
    }

    public final void v(String str, n nVar) {
        if (((Map) this.f33128d).containsKey(str)) {
            return;
        }
        if (nVar == null) {
            ((Map) this.f33127c).remove(str);
        } else {
            ((Map) this.f33127c).put(str, nVar);
        }
    }

    public final boolean w(String str) {
        e eVar = this;
        while (!((Map) eVar.f33127c).containsKey(str)) {
            Object obj = eVar.f33125a;
            if (((e) obj) == null) {
                return false;
            }
            eVar = (e) obj;
        }
        return true;
    }

    public final void x(String str, n nVar) {
        e eVar = this;
        while (!((Map) eVar.f33127c).containsKey(str)) {
            Object obj = eVar.f33125a;
            if (((e) obj) == null || !((e) obj).w(str)) {
                break;
            } else {
                eVar = (e) eVar.f33125a;
            }
        }
        if (((Map) eVar.f33128d).containsKey(str)) {
            return;
        }
        if (nVar == null) {
            ((Map) eVar.f33127c).remove(str);
        } else {
            ((Map) eVar.f33127c).put(str, nVar);
        }
    }

    public e(e eVar, z4 z4Var) {
        this.f33127c = new HashMap();
        this.f33128d = new HashMap();
        this.f33125a = eVar;
        this.f33126b = z4Var;
    }

    public e(int i10) {
        if (i10 == 2) {
            this.f33125a = new androidx.collection.f(0);
            this.f33126b = new SparseArray();
            this.f33127c = new androidx.collection.l();
            this.f33128d = new androidx.collection.f(0);
            return;
        }
        if (i10 == 4) {
            this.f33125a = null;
            this.f33126b = new ArrayList();
            this.f33127c = null;
            this.f33128d = "";
            return;
        }
        if (i10 != 7) {
            switch (i10) {
                case 11:
                    this.f33125a = null;
                    this.f33126b = null;
                    this.f33127c = null;
                    this.f33128d = null;
                    break;
                case 12:
                    this.f33125a = null;
                    this.f33126b = null;
                    this.f33127c = null;
                    this.f33128d = p.f25723d;
                    break;
                case 13:
                    this.f33125a = null;
                    this.f33126b = null;
                    this.f33127c = null;
                    this.f33128d = t.f25759d;
                    break;
                case 14:
                    break;
                case 15:
                    this.f33125a = null;
                    this.f33126b = null;
                    this.f33127c = null;
                    this.f33128d = na.k.f31161e;
                    break;
                default:
                    this.f33125a = new h(256, 0);
                    this.f33126b = new h(256, 0);
                    this.f33127c = new h(256, 0);
                    this.f33128d = new k[32];
                    break;
            }
            return;
        }
        z4 z4Var = new z4(3);
        this.f33125a = z4Var;
        e eVar = new e((e) null, z4Var);
        this.f33127c = eVar;
        this.f33126b = eVar.t();
        s6 s6Var = new s6(0);
        this.f33128d = s6Var;
        ((e) this.f33127c).x("require", new ua(s6Var));
        s6 s6Var2 = (s6) this.f33128d;
        s6Var2.f20410a.put("internal.platform", new l1());
        ((e) this.f33127c).x("runtime.counter", new com.google.android.gms.internal.measurement.g(Double.valueOf(0.0d)));
    }

    public e(y0 y0Var, String str) {
        this.f33128d = y0Var;
        w.checkNotEmpty(str);
        this.f33125a = str;
        if (y0Var.s().J(null, z.f22044j1)) {
            this.f33126b = new Bundle();
        } else {
            this.f33126b = new Bundle();
        }
    }
}
