package T4;

import L1.C0154z;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import javax.net.ssl.SSLSocket;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public class f implements n {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final e f2872f = new e();

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

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

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

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

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

    public f(Class cls) throws NoSuchMethodException {
        this.f2873a = cls;
        Method declaredMethod = cls.getDeclaredMethod("setUseSessionTickets", Boolean.TYPE);
        AbstractC0983h.d("sslSocketClass.getDeclar…:class.javaPrimitiveType)", declaredMethod);
        this.f2874b = declaredMethod;
        this.f2875c = cls.getMethod("setHostname", String.class);
        this.f2876d = cls.getMethod("getAlpnSelectedProtocol", new Class[0]);
        this.f2877e = cls.getMethod("setAlpnProtocols", byte[].class);
    }

    @Override // T4.n
    public final boolean a(SSLSocket sSLSocket) {
        return this.f2873a.isInstance(sSLSocket);
    }

    @Override // T4.n
    public final String b(SSLSocket sSLSocket) {
        if (!this.f2873a.isInstance(sSLSocket)) {
            return null;
        }
        try {
            byte[] bArr = (byte[]) this.f2876d.invoke(sSLSocket, new Object[0]);
            if (bArr == null) {
                return null;
            }
            return new String(bArr, A4.a.f73a);
        } catch (IllegalAccessException e2) {
            throw new AssertionError(e2);
        } catch (InvocationTargetException e6) {
            Throwable cause = e6.getCause();
            if ((cause instanceof NullPointerException) && AbstractC0983h.a(((NullPointerException) cause).getMessage(), "ssl == null")) {
                return null;
            }
            throw new AssertionError(e6);
        }
    }

    @Override // T4.n
    public final void c(SSLSocket sSLSocket, String str, List list) {
        AbstractC0983h.e("protocols", list);
        if (this.f2873a.isInstance(sSLSocket)) {
            try {
                this.f2874b.invoke(sSLSocket, Boolean.TRUE);
                if (str != null) {
                    this.f2875c.invoke(sSLSocket, str);
                }
                Method method = this.f2877e;
                S4.o oVar = S4.o.f2834a;
                method.invoke(sSLSocket, C0154z.g(list));
            } catch (IllegalAccessException e2) {
                throw new AssertionError(e2);
            } catch (InvocationTargetException e6) {
                throw new AssertionError(e6);
            }
        }
    }

    @Override // T4.n
    public final boolean isSupported() {
        boolean z5 = S4.c.f2815e;
        return S4.c.f2815e;
    }
}
