d.java 源代码


package q3;

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.annotation.Nullable;
import javax.net.ssl.SSLSocket;
import okhttp3.v;

public class d extends f {

    private final Method f25728c;

    private final Method f25729d;

    private final Method f25730e;

    private final Class<?> f25731f;

    private final Class<?> f25732g;

    private static class a implements InvocationHandler {

        private final List<String> f25733a;

        boolean f25734b;

        String f25735c;

        a(List<String> list) {
            this.f25733a = list;
        }

        @Override
        public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            String name = method.getName();
            Class<?> returnType = method.getReturnType();
            if (objArr == null) {
                objArr = j3.c.f23288b;
            }
            if (name.equals("supports") && Boolean.TYPE == returnType) {
                return Boolean.TRUE;
            }
            if (name.equals("unsupported") && Void.TYPE == returnType) {
                this.f25734b = true;
                return null;
            }
            if (name.equals("protocols") && objArr.length == 0) {
                return this.f25733a;
            }
            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 i6 = 0; i6 < size; i6++) {
                        if (this.f25733a.contains(list.get(i6))) {
                            String str = (String) list.get(i6);
                            this.f25735c = str;
                            return str;
                        }
                    }
                    String str2 = this.f25733a.get(0);
                    this.f25735c = str2;
                    return str2;
                }
            }
            if ((name.equals("protocolSelected") || name.equals("selected")) && objArr.length == 1) {
                this.f25735c = (String) objArr[0];
                return null;
            }
            return method.invoke(this, objArr);
        }
    }

    d(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2) {
        this.f25728c = method;
        this.f25729d = method2;
        this.f25730e = method3;
        this.f25731f = cls;
        this.f25732g = cls2;
    }

    public static f r() {
        try {
            Class<?> cls = Class.forName("org.eclipse.jetty.alpn.ALPN");
            Class<?> cls2 = Class.forName("org.eclipse.jetty.alpn.ALPN$Provider");
            return new d(cls.getMethod("put", SSLSocket.class, cls2), cls.getMethod("get", SSLSocket.class), cls.getMethod("remove", SSLSocket.class), Class.forName("org.eclipse.jetty.alpn.ALPN$ClientProvider"), Class.forName("org.eclipse.jetty.alpn.ALPN$ServerProvider"));
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            return null;
        }
    }

    @Override
    public void a(SSLSocket sSLSocket) {
        try {
            this.f25730e.invoke(null, sSLSocket);
        } catch (IllegalAccessException | InvocationTargetException e6) {
            throw j3.c.a("unable to remove alpn", e6);
        }
    }

    @Override
    public void f(SSLSocket sSLSocket, String str, List<v> list) {
        try {
            this.f25728c.invoke(null, sSLSocket, Proxy.newProxyInstance(f.class.getClassLoader(), new Class[]{this.f25731f, this.f25732g}, new a(f.b(list))));
        } catch (IllegalAccessException | InvocationTargetException e6) {
            throw j3.c.a("unable to set alpn", e6);
        }
    }

    @Override
    @Nullable
    public String l(SSLSocket sSLSocket) {
        try {
            a aVar = (a) Proxy.getInvocationHandler(this.f25729d.invoke(null, sSLSocket));
            boolean z6 = aVar.f25734b;
            if (!z6 && aVar.f25735c == null) {
                f.i().p(4, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", null);
                return null;
            }
            if (z6) {
                return null;
            }
            return aVar.f25735c;
        } catch (IllegalAccessException | InvocationTargetException e6) {
            throw j3.c.a("unable to get selected protocol", e6);
        }
    }
}