package okhttp3.internal.platform;

import c.h;
import c.q.d.g;
import c.q.d.j;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.Protocol;

/* JADX INFO: compiled from: Jdk9Platform.kt */
/* JADX INFO: loaded from: classes.dex */
public final class Jdk9Platform extends Platform {
    public static final Companion Companion = new Companion(null);
    public final Method getProtocolMethod;
    public final Method setProtocolMethod;

    /* JADX INFO: compiled from: Jdk9Platform.kt */
    public static final class Companion {
        private Companion() {
        }

        public final Jdk9Platform buildIfSupported() {
            try {
                Method method = SSLParameters.class.getMethod("setApplicationProtocols", String[].class);
                Method method2 = SSLSocket.class.getMethod("getApplicationProtocol", new Class[0]);
                j.b(method, "setProtocolMethod");
                j.b(method2, "getProtocolMethod");
                return new Jdk9Platform(method, method2);
            } catch (NoSuchMethodException unused) {
                return null;
            }
        }

        public /* synthetic */ Companion(g gVar) {
            this();
        }
    }

    public Jdk9Platform(Method method, Method method2) {
        j.c(method, "setProtocolMethod");
        j.c(method2, "getProtocolMethod");
        this.setProtocolMethod = method;
        this.getProtocolMethod = method2;
    }

    @Override // okhttp3.internal.platform.Platform
    public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<? extends Protocol> list) {
        j.c(sSLSocket, "sslSocket");
        j.c(list, "protocols");
        try {
            SSLParameters sSLParameters = sSLSocket.getSSLParameters();
            List<String> listAlpnProtocolNames = Platform.Companion.alpnProtocolNames(list);
            Method method = this.setProtocolMethod;
            Object[] objArr = new Object[1];
            if (listAlpnProtocolNames == null) {
                throw new h("null cannot be cast to non-null type java.util.Collection<T>");
            }
            Object[] array = listAlpnProtocolNames.toArray(new String[0]);
            if (array == null) {
                throw new h("null cannot be cast to non-null type kotlin.Array<T>");
            }
            objArr[0] = array;
            method.invoke(sSLParameters, objArr);
            sSLSocket.setSSLParameters(sSLParameters);
        } catch (IllegalAccessException e2) {
            throw new AssertionError("failed to set SSL parameters", e2);
        } catch (InvocationTargetException e3) {
            throw new AssertionError("failed to set SSL parameters", e3);
        }
    }

    @Override // okhttp3.internal.platform.Platform
    public String getSelectedProtocol(SSLSocket sSLSocket) {
        j.c(sSLSocket, "socket");
        try {
            String str = (String) this.getProtocolMethod.invoke(sSLSocket, new Object[0]);
            if (str != null) {
                if (!j.a(str, "")) {
                    return str;
                }
            }
            return null;
        } catch (IllegalAccessException e2) {
            throw new AssertionError("failed to get ALPN selected protocol", e2);
        } catch (InvocationTargetException e3) {
            throw new AssertionError("failed to get ALPN selected protocol", e3);
        }
    }

    @Override // okhttp3.internal.platform.Platform
    public X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
        j.c(sSLSocketFactory, "sslSocketFactory");
        throw new UnsupportedOperationException("clientBuilder.sslSocketFactory(SSLSocketFactory) not supported on JDK 9+");
    }
}
