package okhttp3.internal.platform; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocket; /* loaded from: classes5.dex */ public final class Jdk9Platform extends Platform { public final Method getProtocolMethod; public final Method setProtocolMethod; public Jdk9Platform(Method method, Method method2) { this.setProtocolMethod = method; this.getProtocolMethod = method2; } @Override // okhttp3.internal.platform.Platform public void configureTlsExtensions(SSLSocket sSLSocket, String str, List list) { try { SSLParameters sSLParameters = sSLSocket.getSSLParameters(); List alpnProtocolNames = Platform.alpnProtocolNames(list); this.setProtocolMethod.invoke(sSLParameters, alpnProtocolNames.toArray(new String[alpnProtocolNames.size()])); sSLSocket.setSSLParameters(sSLParameters); } catch (IllegalAccessException | InvocationTargetException e) { throw new AssertionError("failed to set SSL parameters", e); } } @Override // okhttp3.internal.platform.Platform public String getSelectedProtocol(SSLSocket sSLSocket) { try { String str = (String) this.getProtocolMethod.invoke(sSLSocket, new Object[0]); if (str != null) { if (!str.equals("")) { return str; } } return null; } catch (IllegalAccessException e) { throw new AssertionError("failed to get ALPN selected protocol", e); } catch (InvocationTargetException e2) { if (e2.getCause() instanceof UnsupportedOperationException) { return null; } throw new AssertionError("failed to get ALPN selected protocol", e2); } } public static Jdk9Platform buildIfSupported() { try { return new Jdk9Platform(SSLParameters.class.getMethod("setApplicationProtocols", String[].class), SSLSocket.class.getMethod("getApplicationProtocol", new Class[0])); } catch (NoSuchMethodException unused) { return null; } } }