package s7;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.SSLSocket;
import k7.x;

/* JADX INFO: loaded from: classes.dex */
public final class j extends n {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Method f16929c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Method f16930d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Method f16931e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Class f16932f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Class f16933g;

    public j(Method method, Method method2, Method method3, Class cls, Class cls2) {
        this.f16929c = method;
        this.f16930d = method2;
        this.f16931e = method3;
        this.f16932f = cls;
        this.f16933g = cls2;
    }

    @Override // s7.n
    public final void a(SSLSocket sSLSocket) {
        try {
            this.f16931e.invoke(null, sSLSocket);
        } catch (IllegalAccessException e8) {
            throw new AssertionError("failed to remove ALPN", e8);
        } catch (InvocationTargetException e9) {
            throw new AssertionError("failed to remove ALPN", e9);
        }
    }

    @Override // s7.n
    public final void d(SSLSocket sSLSocket, String str, List list) {
        P6.g.e(list, "protocols");
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            if (((x) obj) != x.f14194r) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayList2 = new ArrayList(B6.m.a0(arrayList));
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj2 = arrayList.get(i);
            i++;
            arrayList2.add(((x) obj2).f14201q);
        }
        try {
            this.f16929c.invoke(null, sSLSocket, Proxy.newProxyInstance(n.class.getClassLoader(), new Class[]{this.f16932f, this.f16933g}, new i(arrayList2)));
        } catch (IllegalAccessException e8) {
            throw new AssertionError("failed to set ALPN", e8);
        } catch (InvocationTargetException e9) {
            throw new AssertionError("failed to set ALPN", e9);
        }
    }

    @Override // s7.n
    public final String f(SSLSocket sSLSocket) {
        try {
            InvocationHandler invocationHandler = Proxy.getInvocationHandler(this.f16930d.invoke(null, sSLSocket));
            P6.g.c(invocationHandler, "null cannot be cast to non-null type okhttp3.internal.platform.Jdk8WithJettyBootPlatform.AlpnProvider");
            i iVar = (i) invocationHandler;
            boolean z8 = iVar.f16927b;
            if (!z8 && iVar.f16928c == null) {
                n.i("ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", 4, null);
                return null;
            }
            if (z8) {
                return null;
            }
            return iVar.f16928c;
        } catch (IllegalAccessException e8) {
            throw new AssertionError("failed to get ALPN selected protocol", e8);
        } catch (InvocationTargetException e9) {
            throw new AssertionError("failed to get ALPN selected protocol", e9);
        }
    }
}
