package XnFJ5_9.Ft6VRog_36.KNBe_11;

import XnFJ5_9.XuVgy_28;
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;
/* compiled from: Jdk8WithJettyBootPlatform.java */
/* loaded from: classes.dex */
public class PGPF6hQ_2 extends X6FRs_4 {
    public final Class<?> KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Method f1516KQgRr5e_0;
    public final Method PGPF6hQ_2;
    public final Class<?> QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public final Method f1517QxJ9d_1;

    /* compiled from: Jdk8WithJettyBootPlatform.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 implements InvocationHandler {
        public String KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final List<String> f1518KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public boolean f1519KQgRr5e_0;

        public KQgRr5e_0(List<String> list) {
            this.f1518KQgRr5e_0 = list;
        }

        @Override // java.lang.reflect.InvocationHandler
        public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            String name = method.getName();
            Class<?> returnType = method.getReturnType();
            if (objArr == null) {
                objArr = XnFJ5_9.Ft6VRog_36.X6FRs_4.f1618KQgRr5e_0;
            }
            if (name.equals("supports") && Boolean.TYPE == returnType) {
                return true;
            }
            if (name.equals("unsupported") && Void.TYPE == returnType) {
                this.f1519KQgRr5e_0 = true;
                return null;
            } else if (name.equals("protocols") && objArr.length == 0) {
                return this.f1518KQgRr5e_0;
            } else {
                if ((name.equals("selectProtocol") || name.equals("select")) && String.class == returnType && objArr.length == 1 && (objArr[0] instanceof List)) {
                    List list = (List) objArr[0];
                    int size = list.size();
                    for (int i = 0; i < size; i++) {
                        String str = (String) list.get(i);
                        if (this.f1518KQgRr5e_0.contains(str)) {
                            this.KQgRr5e_0 = str;
                            return str;
                        }
                    }
                    String str2 = this.f1518KQgRr5e_0.get(0);
                    this.KQgRr5e_0 = str2;
                    return str2;
                } else if ((name.equals("protocolSelected") || name.equals("selected")) && objArr.length == 1) {
                    this.KQgRr5e_0 = (String) objArr[0];
                    return null;
                } else {
                    return method.invoke(this, objArr);
                }
            }
        }
    }

    public PGPF6hQ_2(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2) {
        this.f1516KQgRr5e_0 = method;
        this.f1517QxJ9d_1 = method2;
        this.PGPF6hQ_2 = method3;
        this.KQgRr5e_0 = cls;
        this.QxJ9d_1 = cls2;
    }

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

    @Override // XnFJ5_9.Ft6VRog_36.KNBe_11.X6FRs_4
    public void KQgRr5e_0(SSLSocket sSLSocket, String str, List<XuVgy_28> list) {
        try {
            this.f1516KQgRr5e_0.invoke(null, sSLSocket, Proxy.newProxyInstance(X6FRs_4.class.getClassLoader(), new Class[]{this.KQgRr5e_0, this.QxJ9d_1}, new KQgRr5e_0(X6FRs_4.KQgRr5e_0(list))));
        } catch (IllegalAccessException | InvocationTargetException unused) {
            throw new AssertionError("failed to set ALPN");
        }
    }

    @Override // XnFJ5_9.Ft6VRog_36.KNBe_11.X6FRs_4
    public void KQgRr5e_0(SSLSocket sSLSocket) {
        try {
            this.PGPF6hQ_2.invoke(null, sSLSocket);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            throw new AssertionError("failed to remove ALPN");
        }
    }

    @Override // XnFJ5_9.Ft6VRog_36.KNBe_11.X6FRs_4
    @Nullable
    public String KQgRr5e_0(SSLSocket sSLSocket) {
        try {
            KQgRr5e_0 kQgRr5e_0 = (KQgRr5e_0) Proxy.getInvocationHandler(this.f1517QxJ9d_1.invoke(null, sSLSocket));
            if (!kQgRr5e_0.f1519KQgRr5e_0 && kQgRr5e_0.KQgRr5e_0 == null) {
                X6FRs_4.QxJ9d_1().KQgRr5e_0(4, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", (Throwable) null);
                return null;
            } else if (kQgRr5e_0.f1519KQgRr5e_0) {
                return null;
            } else {
                return kQgRr5e_0.KQgRr5e_0;
            }
        } catch (IllegalAccessException | InvocationTargetException unused) {
            throw new AssertionError("failed to get ALPN selected protocol");
        }
    }
}
