package u9; import android.os.Build; import android.util.Log; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.cert.TrustAnchor; import java.security.cert.X509Certificate; import java.util.List; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSocket; import javax.net.ssl.X509TrustManager; /* loaded from: classes2.dex */ class f extends j { /* renamed from: c, reason: collision with root package name */ private final Class f14737c; /* renamed from: d, reason: collision with root package name */ private final Class f14738d; /* renamed from: e, reason: collision with root package name */ private final Method f14739e; /* renamed from: f, reason: collision with root package name */ private final Method f14740f; /* renamed from: g, reason: collision with root package name */ private final Method f14741g; /* renamed from: h, reason: collision with root package name */ private final Method f14742h; /* renamed from: i, reason: collision with root package name */ private final b f14743i = b.b(); static final class a extends w9.c { /* renamed from: a, reason: collision with root package name */ private final Object f14744a; /* renamed from: b, reason: collision with root package name */ private final Method f14745b; a(Object obj, Method method) { this.f14744a = obj; this.f14745b = method; } @Override // w9.c public List a(List list, String str) { try { return (List) this.f14745b.invoke(this.f14744a, (X509Certificate[]) list.toArray(new X509Certificate[list.size()]), "RSA", str); } catch (IllegalAccessException e10) { throw new AssertionError(e10); } catch (InvocationTargetException e11) { SSLPeerUnverifiedException sSLPeerUnverifiedException = new SSLPeerUnverifiedException(e11.getMessage()); sSLPeerUnverifiedException.initCause(e11); throw sSLPeerUnverifiedException; } } public boolean equals(Object obj) { return obj instanceof a; } public int hashCode() { return 0; } } static final class b { /* renamed from: a, reason: collision with root package name */ private final Method f14746a; /* renamed from: b, reason: collision with root package name */ private final Method f14747b; /* renamed from: c, reason: collision with root package name */ private final Method f14748c; b(Method method, Method method2, Method method3) { this.f14746a = method; this.f14747b = method2; this.f14748c = method3; } static b b() { Method method; Method method2; Method method3; try { Class cls = Class.forName("dalvik.system.CloseGuard"); method = cls.getMethod("get", new Class[0]); method3 = cls.getMethod("open", String.class); method2 = cls.getMethod("warnIfOpen", new Class[0]); } catch (Exception unused) { method = null; method2 = null; method3 = null; } return new b(method, method3, method2); } Object a(String str) { Method method = this.f14746a; if (method != null) { try { Object invoke = method.invoke(null, new Object[0]); this.f14747b.invoke(invoke, str); return invoke; } catch (Exception unused) { } } return null; } boolean c(Object obj) { if (obj == null) { return false; } try { this.f14748c.invoke(obj, new Object[0]); return true; } catch (Exception unused) { return false; } } } static final class c implements w9.e { /* renamed from: a, reason: collision with root package name */ private final X509TrustManager f14749a; /* renamed from: b, reason: collision with root package name */ private final Method f14750b; c(X509TrustManager x509TrustManager, Method method) { this.f14750b = method; this.f14749a = x509TrustManager; } @Override // w9.e public X509Certificate a(X509Certificate x509Certificate) { try { TrustAnchor trustAnchor = (TrustAnchor) this.f14750b.invoke(this.f14749a, x509Certificate); if (trustAnchor != null) { return trustAnchor.getTrustedCert(); } return null; } catch (IllegalAccessException e10) { throw new AssertionError("unable to get issues and signature", e10); } catch (InvocationTargetException unused) { return null; } } public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof c)) { return false; } c cVar = (c) obj; return this.f14749a.equals(cVar.f14749a) && this.f14750b.equals(cVar.f14750b); } public int hashCode() { return this.f14749a.hashCode() + (this.f14750b.hashCode() * 31); } } f(Class cls, Class cls2, Method method, Method method2, Method method3, Method method4) { this.f14737c = cls; this.f14738d = cls2; this.f14739e = method; this.f14740f = method2; this.f14741g = method3; this.f14742h = method4; } private boolean u(String str, Class cls, Object obj) { try { return ((Boolean) cls.getMethod("isCleartextTrafficPermitted", new Class[0]).invoke(obj, new Object[0])).booleanValue(); } catch (NoSuchMethodException unused) { return super.q(str); } } private boolean v(String str, Class cls, Object obj) { try { return ((Boolean) cls.getMethod("isCleartextTrafficPermitted", String.class).invoke(obj, str)).booleanValue(); } catch (NoSuchMethodException unused) { return u(str, cls, obj); } } public static j w() { if (!j.p()) { return null; } try { Class cls = Class.forName("com.android.org.conscrypt.SSLParametersImpl"); Class cls2 = Class.forName("com.android.org.conscrypt.OpenSSLSocketImpl"); try { return new f(cls, cls2, cls2.getDeclaredMethod("setUseSessionTickets", Boolean.TYPE), cls2.getMethod("setHostname", String.class), cls2.getMethod("getAlpnSelectedProtocol", new Class[0]), cls2.getMethod("setAlpnProtocols", byte[].class)); } catch (NoSuchMethodException unused) { throw new IllegalStateException("Expected Android API level 21+ but was " + Build.VERSION.SDK_INT); } } catch (ClassNotFoundException unused2) { return null; } } static int x() { try { return Build.VERSION.SDK_INT; } catch (NoClassDefFoundError unused) { return 0; } } @Override // u9.j public w9.c c(X509TrustManager x509TrustManager) { try { Class cls = Class.forName("android.net.http.X509TrustManagerExtensions"); return new a(cls.getConstructor(X509TrustManager.class).newInstance(x509TrustManager), cls.getMethod("checkServerTrusted", X509Certificate[].class, String.class, String.class)); } catch (Exception unused) { return super.c(x509TrustManager); } } @Override // u9.j public w9.e d(X509TrustManager x509TrustManager) { try { Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class); declaredMethod.setAccessible(true); return new c(x509TrustManager, declaredMethod); } catch (NoSuchMethodException unused) { return super.d(x509TrustManager); } } @Override // u9.j public void g(SSLSocket sSLSocket, String str, List list) { if (this.f14738d.isInstance(sSLSocket)) { if (str != null) { try { this.f14739e.invoke(sSLSocket, Boolean.TRUE); this.f14740f.invoke(sSLSocket, str); } catch (IllegalAccessException | InvocationTargetException e10) { throw new AssertionError(e10); } } this.f14742h.invoke(sSLSocket, j.e(list)); } } @Override // u9.j public void h(Socket socket, InetSocketAddress inetSocketAddress, int i10) { try { socket.connect(inetSocketAddress, i10); } catch (AssertionError e10) { if (!o9.e.A(e10)) { throw e10; } throw new IOException(e10); } catch (ClassCastException e11) { if (Build.VERSION.SDK_INT != 26) { throw e11; } throw new IOException("Exception in connect", e11); } } @Override // u9.j public SSLContext m() { boolean z10 = true; try { if (Build.VERSION.SDK_INT >= 22) { z10 = false; } } catch (NoClassDefFoundError unused) { } if (z10) { try { return SSLContext.getInstance("TLSv1.2"); } catch (NoSuchAlgorithmException unused2) { } } try { return SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e10) { throw new IllegalStateException("No TLS provider", e10); } } @Override // u9.j public String n(SSLSocket sSLSocket) { if (!this.f14738d.isInstance(sSLSocket)) { return null; } try { byte[] bArr = (byte[]) this.f14741g.invoke(sSLSocket, new Object[0]); if (bArr != null) { return new String(bArr, StandardCharsets.UTF_8); } return null; } catch (IllegalAccessException | InvocationTargetException e10) { throw new AssertionError(e10); } } @Override // u9.j public Object o(String str) { return this.f14743i.a(str); } @Override // u9.j public boolean q(String str) { try { Class cls = Class.forName("android.security.NetworkSecurityPolicy"); return v(str, cls, cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0])); } catch (ClassNotFoundException | NoSuchMethodException unused) { return super.q(str); } catch (IllegalAccessException e10) { e = e10; throw new AssertionError("unable to determine cleartext support", e); } catch (IllegalArgumentException e11) { e = e11; throw new AssertionError("unable to determine cleartext support", e); } catch (InvocationTargetException e12) { e = e12; throw new AssertionError("unable to determine cleartext support", e); } } @Override // u9.j public void s(int i10, String str, Throwable th) { int min; int i11 = i10 != 5 ? 3 : 5; if (th != null) { str = str + '\n' + Log.getStackTraceString(th); } int length = str.length(); int i12 = 0; while (i12 < length) { int indexOf = str.indexOf(10, i12); if (indexOf == -1) { indexOf = length; } while (true) { min = Math.min(indexOf, i12 + 4000); Log.println(i11, "OkHttp", str.substring(i12, min)); if (min >= indexOf) { break; } else { i12 = min; } } i12 = min + 1; } } @Override // u9.j public void t(String str, Object obj) { if (this.f14743i.c(obj)) { return; } s(5, str, null); } }