package g.i0.j;

import g.x;
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;

/* JADX INFO: loaded from: classes.dex */
public class d extends f {

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Class<?> f6411f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Class<?> f6412g;

    public static class a implements InvocationHandler {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final List<String> f6413a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public boolean f6414b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public String f6415c;

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

        @Override // java.lang.reflect.InvocationHandler
        public Object invoke(Object obj, Method method, Object[] objArr) {
            Object obj2;
            String name = method.getName();
            Class<?> returnType = method.getReturnType();
            if (objArr == null) {
                objArr = g.i0.c.f6155b;
            }
            if (name.equals("supports") && Boolean.TYPE == returnType) {
                return Boolean.TRUE;
            }
            if (name.equals("unsupported") && Void.TYPE == returnType) {
                this.f6414b = true;
                return null;
            }
            if (name.equals("protocols") && objArr.length == 0) {
                return this.f6413a;
            }
            if ((!name.equals("selectProtocol") && !name.equals("select")) || String.class != returnType || objArr.length != 1 || !(objArr[0] instanceof List)) {
                if ((!name.equals("protocolSelected") && !name.equals("selected")) || objArr.length != 1) {
                    return method.invoke(this, objArr);
                }
                this.f6415c = (String) objArr[0];
                return null;
            }
            List list = (List) objArr[0];
            int size = list.size();
            int i2 = 0;
            while (true) {
                if (i2 >= size) {
                    obj2 = this.f6413a.get(0);
                    break;
                }
                if (this.f6413a.contains(list.get(i2))) {
                    obj2 = list.get(i2);
                    break;
                }
                i2++;
            }
            String str = (String) obj2;
            this.f6415c = str;
            return str;
        }
    }

    public d(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2) {
        this.f6408c = method;
        this.f6409d = method2;
        this.f6410e = method3;
        this.f6411f = cls;
        this.f6412g = cls2;
    }

    @Override // g.i0.j.f
    public void a(SSLSocket sSLSocket) {
        try {
            this.f6410e.invoke(null, sSLSocket);
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw g.i0.c.a("unable to remove alpn", e2);
        }
    }

    @Override // g.i0.j.f
    public void f(SSLSocket sSLSocket, String str, List<x> list) {
        try {
            this.f6408c.invoke(null, sSLSocket, Proxy.newProxyInstance(f.class.getClassLoader(), new Class[]{this.f6411f, this.f6412g}, new a(f.b(list))));
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw g.i0.c.a("unable to set alpn", e2);
        }
    }

    @Override // g.i0.j.f
    @Nullable
    public String i(SSLSocket sSLSocket) {
        try {
            a aVar = (a) Proxy.getInvocationHandler(this.f6409d.invoke(null, sSLSocket));
            boolean z = aVar.f6414b;
            if (!z && aVar.f6415c == null) {
                f.f6419a.l(4, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", null);
                return null;
            }
            if (z) {
                return null;
            }
            return aVar.f6415c;
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw g.i0.c.a("unable to get selected protocol", e2);
        }
    }
}
