package okhttp3.internal.platform; import com.google.android.gms.analytics.ecommerce.ProductAction; import com.huawei.hms.android.SystemUtils; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; import java.util.List; import javax.net.ssl.SSLSocket; import o.C14953gcr; import o.C14957gcv; import okhttp3.Protocol; /* loaded from: classes.dex */ public final class Jdk8WithJettyBootPlatform extends Platform { public static final Companion Companion = new Companion(null); private final Class clientProviderClass; private final Method getMethod; private final Method putMethod; private final Method removeMethod; private final Class serverProviderClass; public Jdk8WithJettyBootPlatform(Method method, Method method2, Method method3, Class cls, Class cls2) { C14957gcv.e(method, ""); C14957gcv.e(method2, ""); C14957gcv.e(method3, ""); C14957gcv.e(cls, ""); C14957gcv.e(cls2, ""); this.putMethod = method; this.getMethod = method2; this.removeMethod = method3; this.clientProviderClass = cls; this.serverProviderClass = cls2; } @Override // okhttp3.internal.platform.Platform public final void configureTlsExtensions(SSLSocket sSLSocket, String str, List list) { C14957gcv.e(sSLSocket, ""); C14957gcv.e(list, ""); try { this.putMethod.invoke(null, sSLSocket, Proxy.newProxyInstance(Platform.class.getClassLoader(), new Class[]{this.clientProviderClass, this.serverProviderClass}, new AlpnProvider(Platform.Companion.alpnProtocolNames(list)))); } catch (IllegalAccessException e) { throw new AssertionError("failed to set ALPN", e); } catch (InvocationTargetException e2) { throw new AssertionError("failed to set ALPN", e2); } } @Override // okhttp3.internal.platform.Platform public final void afterHandshake(SSLSocket sSLSocket) { C14957gcv.e(sSLSocket, ""); try { this.removeMethod.invoke(null, sSLSocket); } catch (IllegalAccessException e) { throw new AssertionError("failed to remove ALPN", e); } catch (InvocationTargetException e2) { throw new AssertionError("failed to remove ALPN", e2); } } @Override // okhttp3.internal.platform.Platform public final String getSelectedProtocol(SSLSocket sSLSocket) { C14957gcv.e(sSLSocket, ""); try { InvocationHandler invocationHandler = Proxy.getInvocationHandler(this.getMethod.invoke(null, sSLSocket)); if (invocationHandler == null) { throw new NullPointerException("null cannot be cast to non-null type okhttp3.internal.platform.Jdk8WithJettyBootPlatform.AlpnProvider"); } AlpnProvider alpnProvider = (AlpnProvider) invocationHandler; if (!alpnProvider.getUnsupported() && alpnProvider.getSelected() == null) { Platform.log$default(this, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", 0, null, 6, null); return null; } if (alpnProvider.getUnsupported()) { return null; } return alpnProvider.getSelected(); } catch (IllegalAccessException e) { throw new AssertionError("failed to get ALPN selected protocol", e); } catch (InvocationTargetException e2) { throw new AssertionError("failed to get ALPN selected protocol", e2); } } /* loaded from: classes.dex */ static final class AlpnProvider implements InvocationHandler { private final List protocols; private String selected; private boolean unsupported; public AlpnProvider(List list) { C14957gcv.e(list, ""); this.protocols = list; } @Override // java.lang.reflect.InvocationHandler public final Object invoke(Object obj, Method method, Object[] objArr) throws Throwable { C14957gcv.e(obj, ""); C14957gcv.e(method, ""); if (objArr == null) { objArr = new Object[0]; } String name = method.getName(); Class returnType = method.getReturnType(); if (C14957gcv.b((Object) name, (Object) "supports") && C14957gcv.b(Boolean.TYPE, returnType)) { return Boolean.TRUE; } if (C14957gcv.b((Object) name, (Object) "unsupported") && C14957gcv.b(Void.TYPE, returnType)) { this.unsupported = true; return null; } if (C14957gcv.b((Object) name, (Object) "protocols") && objArr.length == 0) { return this.protocols; } if ((C14957gcv.b((Object) name, (Object) "selectProtocol") || C14957gcv.b((Object) name, (Object) "select")) && C14957gcv.b(String.class, returnType) && objArr.length == 1) { Object obj2 = objArr[0]; if (obj2 instanceof List) { if (obj2 != null) { List list = (List) obj2; int size = list.size(); if (size >= 0) { int i = 0; while (true) { Object obj3 = list.get(i); if (obj3 == null) { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } String str = (String) obj3; if (!this.protocols.contains(str)) { if (i == size) { break; } i++; } else { this.selected = str; return str; } } } String str2 = this.protocols.get(0); this.selected = str2; return str2; } throw new NullPointerException("null cannot be cast to non-null type kotlin.collections.List<*>"); } } if ((C14957gcv.b((Object) name, (Object) "protocolSelected") || C14957gcv.b((Object) name, (Object) "selected")) && objArr.length == 1) { Object obj4 = objArr[0]; if (obj4 == null) { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } this.selected = (String) obj4; return null; } return method.invoke(this, Arrays.copyOf(objArr, objArr.length)); } public final void setUnsupported(boolean z) { this.unsupported = z; } public final void setSelected(String str) { this.selected = str; } public final boolean getUnsupported() { return this.unsupported; } public final String getSelected() { return this.selected; } } /* loaded from: classes.dex */ public static final class Companion { private Companion() { } public final Platform buildIfSupported() { String property = System.getProperty("java.specification.version", SystemUtils.UNKNOWN); try { C14957gcv.c((Object) property, ""); if (Integer.parseInt(property) >= 9) { return null; } } catch (NumberFormatException unused) { } try { Class cls = Class.forName("org.eclipse.jetty.alpn.ALPN", true, null); Class cls2 = Class.forName(C14957gcv.c("org.eclipse.jetty.alpn.ALPN", (Object) "$Provider"), true, null); Class cls3 = Class.forName(C14957gcv.c("org.eclipse.jetty.alpn.ALPN", (Object) "$ClientProvider"), true, null); Class cls4 = Class.forName(C14957gcv.c("org.eclipse.jetty.alpn.ALPN", (Object) "$ServerProvider"), true, null); Method method = cls.getMethod("put", SSLSocket.class, cls2); Method method2 = cls.getMethod("get", SSLSocket.class); Method method3 = cls.getMethod(ProductAction.ACTION_REMOVE, SSLSocket.class); C14957gcv.c(method, ""); C14957gcv.c(method2, ""); C14957gcv.c(method3, ""); C14957gcv.c(cls3, ""); C14957gcv.c(cls4, ""); return new Jdk8WithJettyBootPlatform(method, method2, method3, cls3, cls4); } catch (ClassNotFoundException | NoSuchMethodException unused2) { return null; } } public /* synthetic */ Companion(C14953gcr c14953gcr) { this(); } } }