package com.google.android.gms.common.api.internal;

import com.google.android.gms.internal.ads.j12;
import com.google.android.gms.internal.ads.vj1;
import com.google.android.gms.internal.ads.vy1;
import com.google.android.gms.internal.ads.w82;
import com.google.android.gms.internal.pal.de;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.SecureRandom;
import java.util.Random;
import javax.crypto.Cipher;

/* JADX INFO: loaded from: classes2.dex */
public final class x0 extends ThreadLocal {

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

    public /* synthetic */ x0(int i10) {
        this.f8305a = i10;
    }

    public final Cipher a() {
        switch (this.f8305a) {
            case 16:
                try {
                    return (Cipher) sa.j.f32734b.f32736a.q("AES/GCM/NoPadding");
                } catch (GeneralSecurityException e10) {
                    throw new IllegalStateException(e10);
                }
            case 17:
                try {
                    Cipher cipher = (Cipher) sa.j.f32734b.f32736a.q("AES/GCM-SIV/NoPadding");
                    if (fa.e.c(cipher)) {
                        return cipher;
                    }
                    return null;
                } catch (GeneralSecurityException e11) {
                    throw new IllegalStateException(e11);
                }
            case 18:
            default:
                try {
                    return (Cipher) sa.j.f32734b.f32736a.q("AES/CTR/NoPadding");
                } catch (GeneralSecurityException e12) {
                    throw new IllegalStateException(e12);
                }
            case 19:
                try {
                    return (Cipher) sa.j.f32734b.f32736a.q("AES/ECB/NoPadding");
                } catch (GeneralSecurityException e13) {
                    throw new IllegalStateException(e13);
                }
            case 20:
                try {
                    return (Cipher) sa.j.f32734b.f32736a.q("AES/CTR/NoPadding");
                } catch (GeneralSecurityException e14) {
                    throw new IllegalStateException(e14);
                }
            case 21:
                try {
                    return (Cipher) sa.j.f32734b.f32736a.q("AES/CTR/NOPADDING");
                } catch (GeneralSecurityException e15) {
                    throw new IllegalStateException(e15);
                }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:113:0x011b A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:129:0x0051 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0120  */
    @Override // java.lang.ThreadLocal
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object initialValue() {
        SecureRandom secureRandom;
        SecureRandom secureRandom2;
        Provider provider = null;
        switch (this.f8305a) {
            case 0:
                return Boolean.FALSE;
            case 1:
                return 0L;
            case 2:
                return ByteBuffer.allocate(32);
            case 3:
                try {
                    return (Cipher) w82.f17926b.a("AES/GCM/NoPadding");
                } catch (GeneralSecurityException e10) {
                    throw new IllegalStateException(e10);
                }
            case 4:
                try {
                    Cipher cipher = (Cipher) w82.f17926b.a("AES/GCM-SIV/NoPadding");
                    if (vy1.a(cipher)) {
                        return cipher;
                    }
                    return null;
                } catch (GeneralSecurityException e11) {
                    throw new IllegalStateException(e11);
                }
            case 5:
                x0 x0Var = j12.f12681a;
                Provider providerE = vj1.e();
                if (providerE == null) {
                    provider = (Provider) Class.forName("org.conscrypt.Conscrypt").getMethod("newProvider", new Class[0]).invoke(null, new Object[0]);
                    if (provider == null) {
                        try {
                            secureRandom = SecureRandom.getInstance("SHA1PRNG", provider);
                        } catch (GeneralSecurityException unused) {
                            secureRandom = new SecureRandom();
                        }
                    } else {
                        secureRandom = new SecureRandom();
                    }
                    break;
                } else {
                    try {
                        secureRandom = SecureRandom.getInstance("SHA1PRNG", providerE);
                        break;
                    } catch (GeneralSecurityException unused2) {
                        try {
                            provider = (Provider) Class.forName("org.conscrypt.Conscrypt").getMethod("newProvider", new Class[0]).invoke(null, new Object[0]);
                        } catch (Throwable unused3) {
                        }
                        if (provider == null) {
                        }
                    }
                }
                secureRandom.nextLong();
                return secureRandom;
            case 6:
                try {
                    return (Cipher) w82.f17926b.a("AES/ECB/NoPadding");
                } catch (GeneralSecurityException e12) {
                    throw new IllegalStateException(e12);
                }
            case 7:
                try {
                    return (Cipher) w82.f17926b.a("AES/CTR/NoPadding");
                } catch (GeneralSecurityException e13) {
                    throw new IllegalStateException(e13);
                }
            case 8:
                try {
                    return (Cipher) w82.f17926b.a("AES/CTR/NOPADDING");
                } catch (GeneralSecurityException e14) {
                    throw new IllegalStateException(e14);
                }
            case 9:
                return Boolean.TRUE;
            case 10:
                try {
                    return (Cipher) de.f20763e.a("AES/GCM/NoPadding");
                } catch (GeneralSecurityException e15) {
                    throw new IllegalStateException(e15);
                }
            case 11:
                try {
                    return (Cipher) de.f20763e.a("AES/GCM-SIV/NoPadding");
                } catch (GeneralSecurityException e16) {
                    throw new IllegalStateException(e16);
                }
            case 12:
                try {
                    return (Cipher) de.f20763e.a("AES/CTR/NoPadding");
                } catch (GeneralSecurityException e17) {
                    throw new IllegalStateException(e17);
                }
            case 13:
                try {
                    return (Cipher) de.f20763e.a("AES/ECB/NOPADDING");
                } catch (GeneralSecurityException e18) {
                    throw new IllegalStateException(e18);
                }
            case 14:
                try {
                    return (Cipher) de.f20763e.a("AES/CTR/NOPADDING");
                } catch (GeneralSecurityException e19) {
                    throw new IllegalStateException(e19);
                }
            case 15:
                SecureRandom secureRandom3 = new SecureRandom();
                secureRandom3.nextLong();
                return secureRandom3;
            case 16:
                return a();
            case 17:
                return a();
            case 18:
                x0 x0Var2 = ma.j0.f30531a;
                Provider providerA = ma.a.a();
                if (providerA == null) {
                    provider = (Provider) Class.forName("org.conscrypt.Conscrypt").getMethod("newProvider", new Class[0]).invoke(null, new Object[0]);
                    if (provider == null) {
                        try {
                            secureRandom2 = SecureRandom.getInstance("SHA1PRNG", provider);
                        } catch (GeneralSecurityException unused4) {
                            secureRandom2 = new SecureRandom();
                        }
                    } else {
                        secureRandom2 = new SecureRandom();
                    }
                    break;
                } else {
                    try {
                        secureRandom2 = SecureRandom.getInstance("SHA1PRNG", providerA);
                        break;
                    } catch (GeneralSecurityException unused5) {
                        try {
                            provider = (Provider) Class.forName("org.conscrypt.Conscrypt").getMethod("newProvider", new Class[0]).invoke(null, new Object[0]);
                        } catch (Throwable unused6) {
                        }
                        if (provider == null) {
                        }
                    }
                }
                secureRandom2.nextLong();
                return secureRandom2;
            case 19:
                return a();
            case 20:
                return a();
            case 21:
                return a();
            case 22:
                return a();
            default:
                return new Random();
        }
    }

    public x0() {
        this.f8305a = 2;
    }
}
