package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.LongSparseArray;
import com.google.crypto.tink.internal.TinkBugException;
import com.hierynomus.smbj.common.SMBRuntimeException;
import java.io.ByteArrayInputStream;
import java.io.CharConversionException;
import java.io.IOException;
import java.io.Serializable;
import java.security.GeneralSecurityException;
import java.security.KeyStoreException;
import java.security.ProviderException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/* renamed from: ˏˀ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1818 implements ᵿᵸˋ {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public Object f7384;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public Object f7385;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public Object f7386;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public String f7387;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public Serializable f7388;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final /* synthetic */ int f7389;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public Object f7390;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public Object f7391;

    public C1818() {
        this.f7389 = 1;
        this.f7391 = null;
        this.f7387 = null;
        this.f7390 = null;
        this.f7388 = null;
        this.f7386 = null;
        this.f7384 = null;
    }

    public C1818(String str) {
        this.f7389 = 0;
        this.f7391 = AbstractC1385.m4255(C1818.class);
        this.f7387 = str;
        this.f7390 = SMBRuntimeException.f1138;
        ReentrantLock reentrantLock = new ReentrantLock();
        this.f7388 = reentrantLock;
        this.f7386 = reentrantLock.newCondition();
    }

    public C1818(C3057 c3057, String str, Long l, C2694 c2694, C3604 c3604, ArrayList arrayList, LongSparseArray longSparseArray) {
        this.f7389 = 2;
        this.f7391 = c3057;
        this.f7387 = str;
        this.f7390 = l;
        this.f7388 = c2694;
        this.f7386 = c3604;
        this.f7384 = arrayList;
        this.f7385 = longSparseArray;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public static ˊʘ m5161(byte[] bArr) throws IOException {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
        try {
            C2903 c2903M7074 = C2903.m7074(byteArrayInputStream, C1523.m4449());
            byteArrayInputStream.close();
            return new ˊʘ(0, (C3952) ᵧˉʙ.ᵾᵬ(c2903M7074).ˀᵗᵝᵭ().m861());
        } catch (Throwable th) {
            byteArrayInputStream.close();
            throw th;
        }
    }

    public String toString() {
        switch (this.f7389) {
            case 0:
                return this.f7387;
            default:
                return super.toString();
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public Object m5162(String str, InterfaceC4943 interfaceC4943) {
        return Boolean.valueOf(((C3057) this.f7391).f11710 == null);
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public Boolean m5163() {
        return Boolean.valueOf(((C3604) this.f7386).f13441);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public ˊʘ m5164() throws GeneralSecurityException, IOException {
        int i;
        ᵿʤˑᵦ r1 = (ᵿʤˑᵦ) this.f7384;
        Integer num = null;
        if (r1 == null) {
            C0910.m3048("cannot read or generate keyset");
            return null;
        }
        AbstractC0596 abstractC0596 = (AbstractC0596) r1.ᵢˇᵭ;
        if (abstractC0596 == null) {
            try {
                abstractC0596 = ˆᴵ.ᵨᵳʝ((abstractC0596 instanceof C4076 ? (C4708) ((C4076) abstractC0596).f15266.f10550 : (C4708) ((C2720) C2542.f9905.m6412(abstractC0596)).f10550).m952());
            } catch (GeneralSecurityException e) {
                throw new TinkBugException("Parsing parameters failed in getProto(). You probably want to call some Tink register function for " + abstractC0596, e);
            }
        }
        ArrayList arrayList = new ArrayList();
        C3549 c3549 = C3549.f13301;
        C1577 c1577 = new C1577(abstractC0596);
        ᵥᵵ r12 = ᵥᵵ.ˀᵗᵝᵭ;
        c1577.f6242 = r12;
        c1577.f6243 = true;
        int size = arrayList.size();
        int i2 = 0;
        while (i2 < size) {
            Object obj = arrayList.get(i2);
            i2++;
            ((C1577) obj).f6243 = false;
        }
        arrayList.add(c1577);
        ArrayList arrayList2 = new ArrayList(arrayList.size());
        for (int i3 = 0; i3 < arrayList.size() - 1; i3++) {
            if (((C1577) arrayList.get(i3)).f6242 == r12 && ((C1577) arrayList.get(i3 + 1)).f6242 != r12) {
                C0910.m3048("Entries with 'withRandomId()' may only be followed by other entries with 'withRandomId()'.");
                return null;
            }
        }
        HashSet hashSet = new HashSet();
        int size2 = arrayList.size();
        Integer numValueOf = null;
        int i4 = 0;
        while (i4 < size2) {
            Object obj2 = arrayList.get(i4);
            i4++;
            C1577 c15772 = (C1577) obj2;
            c15772.getClass();
            AbstractC0596 abstractC05962 = c15772.f6244;
            ᵥᵵ r14 = c15772.f6242;
            if (r14 == null) {
                Integer num2 = num;
                C0910.m3048("No ID was set (with withFixedId or withRandomId)");
                return num2;
            }
            if (r14 == r12) {
                int i5 = 0;
                while (true) {
                    if (i5 != 0 && !hashSet.contains(Integer.valueOf(i5))) {
                        break;
                    }
                    int i6 = AbstractC1067.f4631;
                    i5 = 0;
                    while (i5 == 0) {
                        byte[] bArrM11138 = AbstractC5513.m11138(4);
                        i5 = (bArrM11138[3] & 255) | ((bArrM11138[1] & 255) << 16) | ((bArrM11138[0] & 255) << 24) | ((bArrM11138[2] & 255) << 8);
                        num = num;
                    }
                }
                i = i5;
            } else {
                i = 0;
            }
            Integer num3 = num;
            if (hashSet.contains(Integer.valueOf(i))) {
                throw new GeneralSecurityException(AbstractC3915.m8596(i, "Id ", " is used twice in the keyset"));
            }
            hashSet.add(Integer.valueOf(i));
            C3021 c3021 = new C3021(C1562.f6218.m4535(abstractC05962, abstractC05962.mo2479() ? Integer.valueOf(i) : num3), EnumC0195.f1656, i, c15772.f6243, false, C3021.f11646);
            int i7 = i;
            if (c15772.f6243) {
                if (numValueOf != null) {
                    C0910.m3048("Two primaries were set");
                    return num3;
                }
                numValueOf = Integer.valueOf(i7);
            }
            arrayList2.add(c3021);
            num = num3;
        }
        Integer num4 = num;
        if (numValueOf == null) {
            C0910.m3048("No primary was set");
            return num4;
        }
        ᵧˉʙ r13 = new ᵧˉʙ(arrayList2, c3549);
        if (!c3549.f13302.isEmpty()) {
            C0910 c0910 = new C0910(20);
            ArrayList arrayList3 = new ArrayList(arrayList2.size());
            int size3 = arrayList2.size();
            int i8 = 0;
            while (i8 < size3) {
                Object obj3 = arrayList2.get(i8);
                i8++;
                C3021 c30212 = (C3021) obj3;
                arrayList3.add(new C3021(c30212.f11651, c30212.f11652, c30212.f11653, c30212.f11647, c30212.f11649, c0910));
            }
            r13 = new ᵧˉʙ(arrayList3, c3549, r13, 25);
        }
        Context context = (Context) this.f7391;
        String str = this.f7387;
        C5553 c5553 = new C5553(context, str, (String) this.f7390);
        C0863 c0863 = (C0863) this.f7386;
        try {
            if (c0863 != null) {
                AbstractC0220.m1517(r13, c5553, c0863, new byte[0]);
            } else if (!((SharedPreferences.Editor) c5553.f20833).putString(str, AbstractC0220.m1505(r13.ˀᵗᵝᵭ().m952())).commit()) {
                throw new IOException("Failed to write to SharedPreferences");
            }
            return new ˊʘ(0, (C3952) r13.ˀᵗᵝᵭ().m861());
        } catch (IOException e2) {
            throw new GeneralSecurityException(e2);
        }
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public Object m5165(String str, InterfaceC4943 interfaceC4943) {
        boolean z = ᵲᵝᵪ.ᵹᵝᵶ(str, ((C3057) this.f7391).f11710);
        if (!z) {
            ((C3604) this.f7386).f13441 = !((ArrayList) this.f7384).isEmpty();
        }
        return Boolean.valueOf(z);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public synchronized C2931 m5166() {
        C2931 c2931;
        try {
            if (this.f7387 == null) {
                throw new IllegalArgumentException("keysetName cannot be null");
            }
            synchronized (C2931.f11362) {
                try {
                    Context context = (Context) this.f7391;
                    String str = this.f7387;
                    String str2 = (String) this.f7390;
                    byte[] bArrM1519 = null;
                    if (str != null) {
                        Context applicationContext = context.getApplicationContext();
                        try {
                            String string = (str2 == null ? PreferenceManager.getDefaultSharedPreferences(applicationContext) : applicationContext.getSharedPreferences(str2, 0)).getString(str, null);
                            if (string != null) {
                                bArrM1519 = AbstractC0220.m1519(string);
                            }
                        } catch (ClassCastException | IllegalArgumentException unused) {
                            throw new CharConversionException(AbstractC4486.m9550("can't read keyset; the pref value ", str, " is not a valid hex string"));
                        }
                    } else {
                        ᵹˉᵞ.ˌᵜᵹᵩ("keysetName cannot be null");
                    }
                    String str3 = (String) this.f7388;
                    if (bArrM1519 == null) {
                        if (str3 != null) {
                            this.f7386 = m5168();
                        }
                        this.f7385 = m5164();
                    } else if (str3 != null) {
                        this.f7385 = m5170(bArrM1519);
                    } else {
                        this.f7385 = m5161(bArrM1519);
                    }
                    c2931 = new C2931(this);
                } finally {
                }
            }
        } catch (Throwable th) {
            throw th;
        }
        return c2931;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public java.lang.Object m5167(ˋˊʽ r11, defpackage.InterfaceC4943 r12) {
        /*
            r10 = this;
            boolean r0 = r12 instanceof ˎᵦ
            if (r0 == 0) goto L13
            r0 = r12
            ˎᵦ r0 = (ˎᵦ) r0
            int r1 = r0.ˀᵗᵝᵭ
            r2 = -2147483648(0xffffffff80000000, float:-0.0)
            r3 = r1 & r2
            if (r3 == 0) goto L13
            int r1 = r1 - r2
            r0.ˀᵗᵝᵭ = r1
            goto L1a
        L13:
            ˎᵦ r0 = new ˎᵦ
            ːᵱ r12 = (defpackage.AbstractC1989) r12
            r0.<init>(r10, r12)
        L1a:
            java.lang.Object r12 = r0.ᵤᵙᵷ
            int r1 = r0.ˀᵗᵝᵭ
            r2 = 0
            r3 = 1
            if (r1 == 0) goto L30
            if (r1 != r3) goto L2a
            ᵚᵪ r10 = r0.ᵾᵬ
            ʼٴ.ᵺᵠ(r12)
            goto L78
        L2a:
            java.lang.String r10 = "call to 'resume' before 'invoke' with coroutine"
            ᵹˉᵞ.ᵳٴᵶ(r10)
            return r2
        L30:
            ʼٴ.ᵺᵠ(r12)
            java.lang.String r12 = r11.ᵥᵯˎ
            java.lang.String r1 = r10.f7387
            boolean r12 = ᵲᵝᵪ.ᵹᵝᵶ(r12, r1)
            if (r12 == 0) goto L80
            java.lang.Object r12 = r10.f7391
            ᵟᵡᵷ r12 = (defpackage.C3057) r12
            java.lang.String r7 = r11.ᵥᵯˎ
            r12.f11710 = r7
            ᵚᵸ r4 = new ᵚᵸ
            java.lang.String r8 = r11.ˏᵙ
            java.lang.Object r11 = r10.f7390
            r9 = r11
            java.lang.Long r9 = (java.lang.Long) r9
            r5 = 0
            r4.<init>(r5, r7, r8, r9)
            java.io.Serializable r10 = r10.f7388
            ᵚᵪ r10 = (defpackage.C2694) r10
            ˊᵿʗ r11 = ar.tvplayer.core.data.database.TvPlayerDatabase.ᵝᵵᵺ
            ar.tvplayer.core.data.database.TvPlayerDatabase r11 = r11.ᵯٴᵦ()
            יᵎ r11 = r11.ᵤᵙᵷ()
            r0.ᵾᵬ = r10
            r0.ˀᵗᵝᵭ = r3
            ᵹᵩᵩ r12 = r11.ᵥᵯˎ
            ˌˑᵟˆ r1 = new ˌˑᵟˆ
            r5 = 16
            r1.<init>(r11, r4, r2, r5)
            r11 = 0
            java.lang.Object r12 = ᵕˏᵛ.ˆᵼᵷˊ(r0, r1, r12, r11, r3)
            ᵣˊᵛ r11 = defpackage.EnumC3346.f12524
            if (r12 != r11) goto L78
            return r11
        L78:
            java.lang.Number r12 = (java.lang.Number) r12
            long r11 = r12.longValue()
            r10.f10450 = r11
        L80:
            ᵧˈᵽᵰ r10 = defpackage.C3637.f13536
            return r10
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C1818.m5167(ˋˊʽ, ᵸʚˑ):java.lang.Object");
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public C0863 m5168() throws KeyStoreException {
        Object obj = C2931.f11362;
        try {
            boolean zM3390 = AbstractC1026.m3390((String) this.f7388);
            try {
                return AbstractC1026.m3391((String) this.f7388);
            } catch (GeneralSecurityException | ProviderException e) {
                if (!zM3390) {
                    throw new KeyStoreException(AbstractC4486.m9550("the master key ", (String) this.f7388, " exists but is unusable"), e);
                }
                Object obj2 = C2931.f11362;
                return null;
            }
        } catch (GeneralSecurityException | ProviderException unused) {
            Object obj3 = C2931.f11362;
            return null;
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public Object m5169(long j, TimeUnit timeUnit) {
        Condition condition = (Condition) this.f7386;
        String str = this.f7387;
        InterfaceC0567 interfaceC0567 = (InterfaceC0567) this.f7391;
        ReentrantLock reentrantLock = (ReentrantLock) this.f7388;
        reentrantLock.lock();
        try {
            try {
                Throwable th = (Throwable) this.f7385;
                if (th != null) {
                    throw th;
                }
                AbstractC0681 abstractC0681 = (AbstractC0681) this.f7384;
                if (abstractC0681 != null) {
                    reentrantLock.unlock();
                    return abstractC0681;
                }
                interfaceC0567.mo2409(str, "Awaiting << {} >>");
                if (j == 0) {
                    while (((AbstractC0681) this.f7384) == null && ((Throwable) this.f7385) == null) {
                        condition.await();
                    }
                } else if (!condition.await(j, timeUnit)) {
                    reentrantLock.unlock();
                    return null;
                }
                Throwable th2 = (Throwable) this.f7385;
                if (th2 != null) {
                    interfaceC0567.mo2391("<< {} >> woke to: {}", str, th2);
                    throw ((Throwable) this.f7385);
                }
                AbstractC0681 abstractC06812 = (AbstractC0681) this.f7384;
                reentrantLock.unlock();
                return abstractC06812;
            } catch (InterruptedException e) {
                throw ((C4912) this.f7390).m10352(e);
            }
        } catch (Throwable th3) {
            reentrantLock.unlock();
            throw th3;
        }
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public ˊʘ m5170(byte[] bArr) {
        try {
            this.f7386 = AbstractC1026.m3391((String) this.f7388);
            try {
                return new ˊʘ(0, (C3952) AbstractC0220.m1512(new C2931(new ByteArrayInputStream(bArr)), (C0863) this.f7386, new byte[0]).ˀᵗᵝᵭ().m861());
            } catch (IOException | GeneralSecurityException e) {
                try {
                    return m5161(bArr);
                } catch (IOException unused) {
                    throw e;
                }
            }
        } catch (GeneralSecurityException | ProviderException e2) {
            try {
                ˊʘ r5 = m5161(bArr);
                Object obj = C2931.f11362;
                return r5;
            } catch (IOException unused2) {
                throw e2;
            }
        }
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public Object m5171(ᵧʓˎˌ r9, InterfaceC4943 interfaceC4943) {
        long j = r9.ᵴᵳ;
        LongSparseArray longSparseArray = (LongSparseArray) this.f7385;
        C2694 c2694 = (C2694) this.f7388;
        HashSet hashSet = (HashSet) longSparseArray.get(c2694.f10450);
        C3637 c3637 = C3637.f13536;
        if (hashSet != null) {
            if (!hashSet.contains(new Long(j))) {
                hashSet.add(new Long(j));
            }
            return c3637;
        }
        long j2 = c2694.f10450;
        Long[] lArr = {new Long(j)};
        HashSet hashSet2 = new HashSet(AbstractC4546.m9659(1));
        hashSet2.add(lArr[0]);
        longSparseArray.put(j2, hashSet2);
        ((ArrayList) this.f7384).add(ᵛᵾˏ.ˀᵗᵝᵭ(r9, c2694.f10450));
        return c3637;
    }
}
