package p447.p448.p457;

import android.os.Build;
import android.security.NetworkSecurityPolicy;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.X509TrustManager;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p447.EnumC6924;
import p447.p448.p457.p458.C7073;
import p447.p448.p457.p458.C7079;
import p447.p448.p457.p458.C7081;
import p447.p448.p457.p458.C7083;
import p447.p448.p457.p458.C7085;
import p447.p448.p457.p458.C7087;
import p447.p448.p457.p458.InterfaceC7086;
import p447.p448.p460.AbstractC7093;
import p447.p448.p460.InterfaceC7096;

/* JADX INFO: renamed from: ސ.ޣ.މ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7054 extends C7069 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final boolean f20559;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final C7055 f20560 = new C7055(null);

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final List<InterfaceC7086> f20561;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C7081 f20562;

    /* JADX INFO: renamed from: ސ.ޣ.މ.ؠ$֏, reason: contains not printable characters */
    public static final class C7055 {
        public C7055() {
        }

        public /* synthetic */ C7055(DefaultConstructorMarker defaultConstructorMarker) {
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.މ.ؠ$ؠ, reason: contains not printable characters */
    public static final class C7056 implements InterfaceC7096 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final X509TrustManager f20563;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final Method f20564;

        public C7056(X509TrustManager x509TrustManager, Method method) {
            if (x509TrustManager == null) {
                C6635.m9824("trustManager");
                throw null;
            }
            if (method == null) {
                C6635.m9824("findByIssuerAndSignatureMethod");
                throw null;
            }
            this.f20563 = x509TrustManager;
            this.f20564 = method;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof C7056)) {
                return false;
            }
            C7056 c7056 = (C7056) obj;
            return C6635.m9825(this.f20563, c7056.f20563) && C6635.m9825(this.f20564, c7056.f20564);
        }

        public int hashCode() {
            X509TrustManager x509TrustManager = this.f20563;
            int iHashCode = (x509TrustManager != null ? x509TrustManager.hashCode() : 0) * 31;
            Method method = this.f20564;
            return iHashCode + (method != null ? method.hashCode() : 0);
        }

        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("CustomTrustRootIndex(trustManager=");
            sbM4889.append(this.f20563);
            sbM4889.append(", findByIssuerAndSignatureMethod=");
            sbM4889.append(this.f20564);
            sbM4889.append(")");
            return sbM4889.toString();
        }

        @Override // p447.p448.p460.InterfaceC7096
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public X509Certificate mo10374(X509Certificate x509Certificate) {
            if (x509Certificate == null) {
                C6635.m9824("cert");
                throw null;
            }
            try {
                Object objInvoke = this.f20564.invoke(this.f20563, x509Certificate);
                if (objInvoke != null) {
                    return ((TrustAnchor) objInvoke).getTrustedCert();
                }
                throw new TypeCastException("null cannot be cast to non-null type java.security.cert.TrustAnchor");
            } catch (IllegalAccessException e) {
                throw new AssertionError("unable to get issues and signature", e);
            } catch (InvocationTargetException unused) {
                return null;
            }
        }
    }

    static {
        boolean z = true;
        if (!C7069.f20588.m10383() || Build.VERSION.SDK_INT >= 30) {
            z = false;
        } else if (1 == 0) {
            StringBuilder sbM4889 = C2803.m4889("Expected Android API level 21+ but was ");
            sbM4889.append(Build.VERSION.SDK_INT);
            throw new IllegalStateException(sbM4889.toString().toString());
        }
        f20559 = z;
    }

    public C7054() throws NoSuchMethodException {
        C7087 c7087;
        Method method;
        Method method2;
        InterfaceC7086[] interfaceC7086Arr = new InterfaceC7086[4];
        Method method3 = null;
        if (C7087.f20611 == null) {
            throw null;
        }
        try {
            Class<?> cls = Class.forName("com.android.org.conscrypt.OpenSSLSocketImpl");
            Class<?> cls2 = Class.forName("com.android.org.conscrypt.OpenSSLSocketFactoryImpl");
            Class<?> cls3 = Class.forName("com.android.org.conscrypt.SSLParametersImpl");
            C6635.m9823((Object) cls3, "paramsClass");
            c7087 = new C7087(cls, cls2, cls3);
        } catch (Exception e) {
            if (C7069.f20588 == null) {
                throw null;
            }
            C7069.f20586.m10381("unable to load android socket classes", 5, e);
            c7087 = null;
        }
        interfaceC7086Arr[0] = c7087;
        if (C7083.f20607 == null || C7059.f20569 == null) {
            throw null;
        }
        interfaceC7086Arr[1] = C7059.f20568 ? new C7083() : null;
        interfaceC7086Arr[2] = new C7085("com.google.android.gms.org.conscrypt");
        if (C7079.f20602 == null || C7057.f20566 == null) {
            throw null;
        }
        interfaceC7086Arr[3] = C7057.f20565 ? new C7079() : null;
        List listM7185 = C4303.m7185((Object[]) interfaceC7086Arr);
        ArrayList arrayList = new ArrayList();
        for (Object obj : (ArrayList) listM7185) {
            if (((InterfaceC7086) obj).mo10387()) {
                arrayList.add(obj);
            }
        }
        this.f20561 = arrayList;
        if (C7081.f20603 == null) {
            throw null;
        }
        try {
            Class<?> cls4 = Class.forName("dalvik.system.CloseGuard");
            Method method4 = cls4.getMethod("get", new Class[0]);
            method2 = cls4.getMethod("open", String.class);
            method = cls4.getMethod("warnIfOpen", new Class[0]);
            method3 = method4;
        } catch (Exception unused) {
            method = null;
            method2 = null;
        }
        this.f20562 = new C7081(method3, method2, method);
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public Object mo10370(String str) {
        if (str == null) {
            C6635.m9824("closer");
            throw null;
        }
        C7081 c7081 = this.f20562;
        Method method = c7081.f20604;
        if (method == null) {
            return null;
        }
        try {
            Object objInvoke = method.invoke(null, new Object[0]);
            Method method2 = c7081.f20605;
            if (method2 != null) {
                method2.invoke(objInvoke, str);
                return objInvoke;
            }
            C6635.m9822();
            throw null;
        } catch (Exception unused) {
            return null;
        }
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ֏ */
    public AbstractC7093 mo10366(X509TrustManager x509TrustManager) {
        if (x509TrustManager != null) {
            C7073 c7073M10391 = C7073.f20590.m10391(x509TrustManager);
            return c7073M10391 != null ? c7073M10391 : super.mo10366(x509TrustManager);
        }
        C6635.m9824("trustManager");
        throw null;
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo10371(String str, Object obj) {
        if (str == null) {
            C6635.m9824("message");
            throw null;
        }
        C7081 c7081 = this.f20562;
        if (c7081 == null) {
            throw null;
        }
        boolean z = false;
        if (obj != null) {
            try {
                Method method = c7081.f20606;
                if (method == null) {
                    C6635.m9822();
                    throw null;
                }
                method.invoke(obj, new Object[0]);
                z = true;
            } catch (Exception unused) {
            }
        }
        if (z) {
            return;
        }
        C7069.m10380(this, str, 5, null, 4, null);
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo10372(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
        if (socket == null) {
            C6635.m9824("socket");
            throw null;
        }
        if (inetSocketAddress == null) {
            C6635.m9824("address");
            throw null;
        }
        try {
            socket.connect(inetSocketAddress, i);
        } catch (ClassCastException e) {
            if (Build.VERSION.SDK_INT != 26) {
                throw e;
            }
            throw new IOException("Exception in connect", e);
        }
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ֏ */
    public void mo10367(SSLSocket sSLSocket, String str, List<EnumC6924> list) {
        Object obj = null;
        if (sSLSocket == null) {
            C6635.m9824("sslSocket");
            throw null;
        }
        if (list == null) {
            C6635.m9824("protocols");
            throw null;
        }
        Iterator<T> it = this.f20561.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            Object next = it.next();
            if (((InterfaceC7086) next).mo10388(sSLSocket)) {
                obj = next;
                break;
            }
        }
        InterfaceC7086 interfaceC7086 = (InterfaceC7086) obj;
        if (interfaceC7086 != null) {
            interfaceC7086.mo10386(sSLSocket, str, list);
        }
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ؠ */
    public String mo10368(SSLSocket sSLSocket) {
        Object next;
        if (sSLSocket == null) {
            C6635.m9824("sslSocket");
            throw null;
        }
        Iterator<T> it = this.f20561.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            if (((InterfaceC7086) next).mo10388(sSLSocket)) {
                break;
            }
        }
        InterfaceC7086 interfaceC7086 = (InterfaceC7086) next;
        if (interfaceC7086 != null) {
            return interfaceC7086.mo10385(sSLSocket);
        }
        return null;
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public InterfaceC7096 mo10373(X509TrustManager x509TrustManager) {
        if (x509TrustManager == null) {
            C6635.m9824("trustManager");
            throw null;
        }
        try {
            Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class);
            C6635.m9823((Object) declaredMethod, "method");
            declaredMethod.setAccessible(true);
            return new C7056(x509TrustManager, declaredMethod);
        } catch (NoSuchMethodException unused) {
            return super.mo10373(x509TrustManager);
        }
    }

    @Override // p447.p448.p457.C7069
    /* JADX INFO: renamed from: ؠ */
    public boolean mo10369(String str) {
        if (str == null) {
            C6635.m9824("hostname");
            throw null;
        }
        int i = Build.VERSION.SDK_INT;
        if (i >= 24) {
            return NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(str);
        }
        if (i < 23) {
            return true;
        }
        NetworkSecurityPolicy networkSecurityPolicy = NetworkSecurityPolicy.getInstance();
        C6635.m9823((Object) networkSecurityPolicy, "NetworkSecurityPolicy.getInstance()");
        return networkSecurityPolicy.isCleartextTrafficPermitted();
    }
}
