- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
129 lines
5.3 KiB
Java
129 lines
5.3 KiB
Java
package okhttp3.internal.platform;
|
|
|
|
import csdk.gluads.Consts;
|
|
import java.lang.reflect.InvocationHandler;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Proxy;
|
|
import java.util.List;
|
|
import javax.net.ssl.SSLSocket;
|
|
import okhttp3.internal.Util;
|
|
|
|
/* loaded from: classes5.dex */
|
|
public class Jdk8WithJettyBootPlatform extends Platform {
|
|
public final Class clientProviderClass;
|
|
public final Method getMethod;
|
|
public final Method putMethod;
|
|
public final Method removeMethod;
|
|
public final Class serverProviderClass;
|
|
|
|
public Jdk8WithJettyBootPlatform(Method method, Method method2, Method method3, Class cls, Class cls2) {
|
|
this.putMethod = method;
|
|
this.getMethod = method2;
|
|
this.removeMethod = method3;
|
|
this.clientProviderClass = cls;
|
|
this.serverProviderClass = cls2;
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.Platform
|
|
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List list) {
|
|
try {
|
|
this.putMethod.invoke(null, sSLSocket, Proxy.newProxyInstance(Platform.class.getClassLoader(), new Class[]{this.clientProviderClass, this.serverProviderClass}, new AlpnProvider(Platform.alpnProtocolNames(list))));
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
throw new AssertionError("failed to set ALPN", e);
|
|
}
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.Platform
|
|
public void afterHandshake(SSLSocket sSLSocket) {
|
|
try {
|
|
this.removeMethod.invoke(null, sSLSocket);
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
throw new AssertionError("failed to remove ALPN", e);
|
|
}
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.Platform
|
|
public String getSelectedProtocol(SSLSocket sSLSocket) {
|
|
try {
|
|
AlpnProvider alpnProvider = (AlpnProvider) Proxy.getInvocationHandler(this.getMethod.invoke(null, sSLSocket));
|
|
boolean z = alpnProvider.unsupported;
|
|
if (!z && alpnProvider.selected == null) {
|
|
Platform.get().log(4, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", null);
|
|
return null;
|
|
}
|
|
if (z) {
|
|
return null;
|
|
}
|
|
return alpnProvider.selected;
|
|
} catch (IllegalAccessException e) {
|
|
e = e;
|
|
throw new AssertionError("failed to get ALPN selected protocol", e);
|
|
} catch (InvocationTargetException e2) {
|
|
e = e2;
|
|
throw new AssertionError("failed to get ALPN selected protocol", e);
|
|
}
|
|
}
|
|
|
|
public static Platform buildIfSupported() {
|
|
try {
|
|
Class<?> cls = Class.forName("org.eclipse.jetty.alpn.ALPN", true, null);
|
|
Class<?> cls2 = Class.forName("org.eclipse.jetty.alpn.ALPN$Provider", true, null);
|
|
return new Jdk8WithJettyBootPlatform(cls.getMethod("put", SSLSocket.class, cls2), cls.getMethod("get", SSLSocket.class), cls.getMethod("remove", SSLSocket.class), Class.forName("org.eclipse.jetty.alpn.ALPN$ClientProvider", true, null), Class.forName("org.eclipse.jetty.alpn.ALPN$ServerProvider", true, null));
|
|
} catch (ClassNotFoundException | NoSuchMethodException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static class AlpnProvider implements InvocationHandler {
|
|
public final List protocols;
|
|
public String selected;
|
|
public boolean unsupported;
|
|
|
|
public AlpnProvider(List list) {
|
|
this.protocols = list;
|
|
}
|
|
|
|
@Override // java.lang.reflect.InvocationHandler
|
|
public Object invoke(Object obj, Method method, Object[] objArr) {
|
|
String name = method.getName();
|
|
Class<?> returnType = method.getReturnType();
|
|
if (objArr == null) {
|
|
objArr = Util.EMPTY_STRING_ARRAY;
|
|
}
|
|
if (name.equals("supports") && Boolean.TYPE == returnType) {
|
|
return Boolean.TRUE;
|
|
}
|
|
if (name.equals(Consts.SDK_PRIVACY_STAGE_UNSUPPORTED) && Void.TYPE == returnType) {
|
|
this.unsupported = true;
|
|
return null;
|
|
}
|
|
if (name.equals("protocols") && objArr.length == 0) {
|
|
return this.protocols;
|
|
}
|
|
if ((name.equals("selectProtocol") || name.equals("select")) && String.class == returnType && objArr.length == 1) {
|
|
Object obj2 = objArr[0];
|
|
if (obj2 instanceof List) {
|
|
List list = (List) obj2;
|
|
int size = list.size();
|
|
for (int i = 0; i < size; i++) {
|
|
String str = (String) list.get(i);
|
|
if (this.protocols.contains(str)) {
|
|
this.selected = str;
|
|
return str;
|
|
}
|
|
}
|
|
String str2 = (String) this.protocols.get(0);
|
|
this.selected = str2;
|
|
return str2;
|
|
}
|
|
}
|
|
if ((name.equals("protocolSelected") || name.equals("selected")) && objArr.length == 1) {
|
|
this.selected = (String) objArr[0];
|
|
return null;
|
|
}
|
|
return method.invoke(this, objArr);
|
|
}
|
|
}
|
|
}
|