package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.LongSparseArray;
import ar.tvplayer.core.data.database.TvPlayerDatabase;
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;

/* JADX INFO: renamed from: ᵜːˀᵵ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2859 implements ᵙʼ {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public Object f10950;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final /* synthetic */ int f10951;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public Object f10952;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public Object f10953;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public String f10954;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public Object f10955;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public Serializable f10956;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public Object f10957;

    public C2859() {
        this.f10951 = 1;
        this.f10953 = null;
        this.f10954 = null;
        this.f10955 = null;
        this.f10956 = null;
        this.f10957 = null;
        this.f10950 = null;
    }

    public C2859(String str) {
        this.f10951 = 0;
        this.f10953 = AbstractC2626.m6386(C2859.class);
        this.f10954 = str;
        this.f10955 = SMBRuntimeException.f1138;
        ReentrantLock reentrantLock = new ReentrantLock();
        this.f10956 = reentrantLock;
        this.f10957 = reentrantLock.newCondition();
    }

    public C2859(C2761 c2761, String str, Long l, C5124 c5124, C2406 c2406, ArrayList arrayList, LongSparseArray longSparseArray) {
        this.f10951 = 2;
        this.f10953 = c2761;
        this.f10954 = str;
        this.f10955 = l;
        this.f10956 = c5124;
        this.f10957 = c2406;
        this.f10950 = arrayList;
        this.f10952 = longSparseArray;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static ᵢʒʡᵟ m6841(byte[] bArr) throws IOException {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
        try {
            C1495 c1495M4266 = C1495.m4266(byteArrayInputStream, C2082.m5556());
            byteArrayInputStream.close();
            return new ᵢʒʡᵟ(5, (C0072) ᵣˊˈᵪ.ᵨᵼⁱ(c1495M4266).ˈᵲᵢ().m885());
        } catch (Throwable th) {
            byteArrayInputStream.close();
            throw th;
        }
    }

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

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object m6842(ᵡᵔ r11, InterfaceC2643 interfaceC2643) {
        ᵺʾˁᵴ r0;
        C5124 c5124;
        if (interfaceC2643 instanceof ᵺʾˁᵴ) {
            r0 = (ᵺʾˁᵴ) interfaceC2643;
            int i = r0.ˈᵲᵢ;
            if ((i & Integer.MIN_VALUE) != 0) {
                r0.ˈᵲᵢ = i - Integer.MIN_VALUE;
            } else {
                r0 = new ᵺʾˁᵴ(this, (AbstractC3500) interfaceC2643);
            }
        }
        Object obj = r0.ᵯᵷʽ;
        int i2 = r0.ˈᵲᵢ;
        if (i2 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            if (ᵥˈᵛ.ˊᵫᵗ(r11.ᵲᵶᵳˈ, this.f10954)) {
                C2761 c2761 = (C2761) this.f10953;
                String str = r11.ᵲᵶᵳˈ;
                c2761.f10617 = str;
                ᵨᵡ r4 = new ᵨᵡ(0L, str, r11.ːˏᵟᵯ, (Long) this.f10955);
                c5124 = (C5124) this.f10956;
                ᵘᵎᵮˏ r112 = TvPlayerDatabase.ᵱᵽʡᵚ.ᵱᵽʡᵚ().ᵶˇᵱ();
                r0.ᵨᵼⁱ = c5124;
                r0.ˈᵲᵢ = 1;
                obj = ᵗʓ.ˈᵲᵢ(r0, new ᵗˈ(r112, r4, (InterfaceC2643) null, 15), r112.ᵲᵶᵳˈ, false, true);
                EnumC0111 enumC0111 = EnumC0111.f1384;
                if (obj == enumC0111) {
                    return enumC0111;
                }
            }
            return C5063.f19112;
        }
        if (i2 != 1) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
            return null;
        }
        c5124 = r0.ᵨᵼⁱ;
        ᵟˌᵫ.ˊˌˊ(obj);
        c5124.f19281 = ((Number) obj).longValue();
        return C5063.f19112;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public Object m6843(ᵫᵨᵤˎ r9, InterfaceC2643 interfaceC2643) {
        long j = r9.ʽˈˋ;
        LongSparseArray longSparseArray = (LongSparseArray) this.f10952;
        C5124 c5124 = (C5124) this.f10956;
        HashSet hashSet = (HashSet) longSparseArray.get(c5124.f19281);
        C5063 c5063 = C5063.f19112;
        if (hashSet != null) {
            if (!hashSet.contains(new Long(j))) {
                hashSet.add(new Long(j));
            }
            return c5063;
        }
        long j2 = c5124.f19281;
        Long[] lArr = {new Long(j)};
        HashSet hashSet2 = new HashSet(AbstractC2206.m5791(1));
        hashSet2.add(lArr[0]);
        longSparseArray.put(j2, hashSet2);
        ((ArrayList) this.f10950).add(ᵣˉ.ˋˈ(r9, c5124.f19281));
        return c5063;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public Object m6844(String str, InterfaceC2643 interfaceC2643) {
        return Boolean.valueOf(((C2761) this.f10953).f10617 == null);
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public C4658 m6845() throws KeyStoreException {
        Object obj = C1014.f4399;
        try {
            boolean zM4535 = AbstractC1638.m4535((String) this.f10956);
            try {
                return AbstractC1638.m4534((String) this.f10956);
            } catch (GeneralSecurityException | ProviderException e) {
                if (!zM4535) {
                    throw new KeyStoreException(AbstractC3589.m8117("the master key ", (String) this.f10956, " exists but is unusable"), e);
                }
                Object obj2 = C1014.f4399;
                return null;
            }
        } catch (GeneralSecurityException | ProviderException unused) {
            Object obj3 = C1014.f4399;
            return null;
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public synchronized C1014 m6846() {
        C1014 c1014;
        try {
            if (this.f10954 == null) {
                throw new IllegalArgumentException("keysetName cannot be null");
            }
            synchronized (C1014.f4399) {
                try {
                    Context context = (Context) this.f10953;
                    String str = this.f10954;
                    String str2 = (String) this.f10955;
                    byte[] bArr = 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) {
                                bArr = ᵴᵧˈ.ᵶᵥᵝ(string);
                            }
                        } catch (ClassCastException | IllegalArgumentException unused) {
                            throw new CharConversionException(AbstractC3589.m8117("can't read keyset; the pref value ", str, " is not a valid hex string"));
                        }
                    } else {
                        ᵕᵩʽᵲ.ᵮᵣᵗˈ("keysetName cannot be null");
                    }
                    String str3 = (String) this.f10956;
                    if (bArr == null) {
                        if (str3 != null) {
                            this.f10957 = m6845();
                        }
                        this.f10952 = m6849();
                    } else if (str3 != null) {
                        this.f10952 = m6850(bArr);
                    } else {
                        this.f10952 = m6841(bArr);
                    }
                    c1014 = new C1014(this);
                } finally {
                }
            }
        } catch (Throwable th) {
            throw th;
        }
        return c1014;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public Object m6847(String str, InterfaceC2643 interfaceC2643) {
        boolean z = ᵥˈᵛ.ˊᵫᵗ(str, ((C2761) this.f10953).f10617);
        if (!z) {
            ((C2406) this.f10957).f9391 = !((ArrayList) this.f10950).isEmpty();
        }
        return Boolean.valueOf(z);
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public Object m6848(long j, TimeUnit timeUnit) {
        Condition condition = (Condition) this.f10957;
        String str = this.f10954;
        InterfaceC5025 interfaceC5025 = (InterfaceC5025) this.f10953;
        ReentrantLock reentrantLock = (ReentrantLock) this.f10956;
        reentrantLock.lock();
        try {
            try {
                Throwable th = (Throwable) this.f10952;
                if (th != null) {
                    throw th;
                }
                AbstractC1899 abstractC1899 = (AbstractC1899) this.f10950;
                if (abstractC1899 != null) {
                    reentrantLock.unlock();
                    return abstractC1899;
                }
                interfaceC5025.mo9486(str, "Awaiting << {} >>");
                if (j == 0) {
                    while (((AbstractC1899) this.f10950) == null && ((Throwable) this.f10952) == null) {
                        condition.await();
                    }
                } else if (!condition.await(j, timeUnit)) {
                    reentrantLock.unlock();
                    return null;
                }
                Throwable th2 = (Throwable) this.f10952;
                if (th2 != null) {
                    interfaceC5025.mo9491("<< {} >> woke to: {}", str, th2);
                    throw ((Throwable) this.f10952);
                }
                AbstractC1899 abstractC18992 = (AbstractC1899) this.f10950;
                reentrantLock.unlock();
                return abstractC18992;
            } catch (InterruptedException e) {
                throw ((C5314) this.f10955).m10899(e);
            }
        } catch (Throwable th3) {
            reentrantLock.unlock();
            throw th3;
        }
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public ᵢʒʡᵟ m6849() throws GeneralSecurityException {
        int i;
        ʽˎˇˌ r1 = (ʽˎˇˌ) this.f10950;
        Integer num = null;
        if (r1 == null) {
            C1685.m4558("cannot read or generate keyset");
            return null;
        }
        AbstractC1378 abstractC1378 = (AbstractC1378) r1.ᵜᵪʾ;
        if (abstractC1378 == null) {
            try {
                abstractC1378 = ᵶᵦ.ˏːˆ((abstractC1378 instanceof C5440 ? (C4763) ((C5440) abstractC1378).f20634.f3432 : (C4763) ((C0767) C5495.f20773.m11128(abstractC1378)).f3432).m896());
            } catch (GeneralSecurityException e) {
                throw new TinkBugException("Parsing parameters failed in getProto(). You probably want to call some Tink register function for " + abstractC1378, e);
            }
        }
        ArrayList arrayList = new ArrayList();
        C2629 c2629 = C2629.f10227;
        C2730 c2730 = new C2730(abstractC1378);
        ᵱᵻᵧᵷ r12 = ᵱᵻᵧᵷ.ᵯᵷʽ;
        c2730.f10500 = r12;
        c2730.f10501 = true;
        int size = arrayList.size();
        int i2 = 0;
        while (i2 < size) {
            Object obj = arrayList.get(i2);
            i2++;
            ((C2730) obj).f10501 = false;
        }
        arrayList.add(c2730);
        ArrayList arrayList2 = new ArrayList(arrayList.size());
        for (int i3 = 0; i3 < arrayList.size() - 1; i3++) {
            if (((C2730) arrayList.get(i3)).f10500 == r12 && ((C2730) arrayList.get(i3 + 1)).f10500 != r12) {
                C1685.m4558("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++;
            C2730 c27302 = (C2730) obj2;
            c27302.getClass();
            AbstractC1378 abstractC13782 = c27302.f10499;
            ᵱᵻᵧᵷ r14 = c27302.f10500;
            if (r14 == null) {
                Integer num2 = num;
                C1685.m4558("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 = AbstractC0184.f1626;
                    i5 = 0;
                    while (i5 == 0) {
                        byte[] bArrM5643 = AbstractC2133.m5643(4);
                        i5 = (bArrM5643[3] & 255) | ((bArrM5643[1] & 255) << 16) | ((bArrM5643[0] & 255) << 24) | ((bArrM5643[2] & 255) << 8);
                        num = num;
                    }
                }
                i = i5;
            } else {
                i = 0;
            }
            Integer num3 = num;
            if (hashSet.contains(Integer.valueOf(i))) {
                throw new GeneralSecurityException(AbstractC0793.m2876(i, "Id ", " is used twice in the keyset"));
            }
            hashSet.add(Integer.valueOf(i));
            C4353 c4353 = new C4353(C4290.f16355.m9268(abstractC13782, abstractC13782.mo1829() ? Integer.valueOf(i) : num3), EnumC2872.f10981, i, c27302.f10501, false, C4353.f16559);
            int i7 = i;
            if (c27302.f10501) {
                if (numValueOf != null) {
                    C1685.m4558("Two primaries were set");
                    return num3;
                }
                numValueOf = Integer.valueOf(i7);
            }
            arrayList2.add(c4353);
            num = num3;
        }
        Integer num4 = num;
        if (numValueOf == null) {
            C1685.m4558("No primary was set");
            return num4;
        }
        ᵣˊˈᵪ r13 = new ᵣˊˈᵪ(arrayList2, c2629);
        if (!c2629.f10228.isEmpty()) {
            C1685 c1685 = new C1685(19);
            ArrayList arrayList3 = new ArrayList(arrayList2.size());
            int size3 = arrayList2.size();
            int i8 = 0;
            while (i8 < size3) {
                Object obj3 = arrayList2.get(i8);
                i8++;
                C4353 c43532 = (C4353) obj3;
                arrayList3.add(new C4353(c43532.f16563, c43532.f16560, c43532.f16565, c43532.f16562, c43532.f16566, c1685));
            }
            r13 = new ᵣˊˈᵪ(arrayList3, c2629, r13, 25);
        }
        Context context = (Context) this.f10953;
        String str = this.f10954;
        C1709 c1709 = new C1709(context, str, (String) this.f10955);
        C4658 c4658 = (C4658) this.f10957;
        try {
            if (c4658 != null) {
                ᵴᵧˈ.ˉᵲ(r13, c1709, c4658, new byte[0]);
            } else if (!((SharedPreferences.Editor) c1709.f6833).putString(str, ᵴᵧˈ.ᵮᵣᵗˈ(r13.ˈᵲᵢ().m896())).commit()) {
                throw new IOException("Failed to write to SharedPreferences");
            }
            return new ᵢʒʡᵟ(5, (C0072) r13.ˈᵲᵢ().m885());
        } catch (IOException e2) {
            throw new GeneralSecurityException(e2);
        }
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public ᵢʒʡᵟ m6850(byte[] bArr) {
        try {
            this.f10957 = AbstractC1638.m4534((String) this.f10956);
            try {
                return new ᵢʒʡᵟ(5, (C0072) ᵴᵧˈ.ᵟᵹᵙ(new ᵟˑʽ(new ByteArrayInputStream(bArr)), (C4658) this.f10957, new byte[0]).ˈᵲᵢ().m885());
            } catch (IOException | GeneralSecurityException e) {
                try {
                    return m6841(bArr);
                } catch (IOException unused) {
                    throw e;
                }
            }
        } catch (GeneralSecurityException | ProviderException e2) {
            try {
                ᵢʒʡᵟ r4 = m6841(bArr);
                Object obj = C1014.f4399;
                return r4;
            } catch (IOException unused2) {
                throw e2;
            }
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public Boolean m6851() {
        return Boolean.valueOf(((C2406) this.f10957).f9391);
    }
}
