package com.applovin.impl; import androidx.core.util.Consumer; import com.applovin.impl.eg; import com.applovin.impl.sdk.utils.CollectionUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.impl.vi; import com.applovin.sdk.AppLovinErrorCodes; import java.io.IOException; import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.HashMap; import java.util.List; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class d4 { private static final List e = Arrays.asList("5.0/i", "4.0/ad", "1.0/mediate"); private final com.applovin.impl.sdk.j a; private final com.applovin.impl.sdk.n b; private final eg c; private d d; public interface e { void a(String str, int i, String str2, Object obj); void a(String str, Object obj, int i); } public d a() { return this.d; } public d4(com.applovin.impl.sdk.j jVar) { this.a = jVar; this.b = jVar.J(); eg egVar = new eg(jVar); this.c = egVar; egVar.a(); } public class c implements Consumer { private final String a; private final com.applovin.impl.sdk.network.a b; private final String c; private final Object d; private final boolean e; private final b f; private final e g; private c(String str, com.applovin.impl.sdk.network.a aVar, String str2, Object obj, boolean z, b bVar, e eVar) { this.a = str; this.b = aVar; this.c = str2; this.d = obj; this.e = z; this.f = bVar; this.g = eVar; } @Override // androidx.core.util.Consumer /* renamed from: a, reason: merged with bridge method [inline-methods] */ public void accept(eg.d dVar) { int i; long e = dVar.e(); Object obj = null; int i2 = 0; try { int c = dVar.c(); try { if (c <= 0) { d4.this.a(this.c, this.a, c, e, (Throwable) null); this.g.a(this.a, c, null, null); return; } if (c >= 200 && c < 400) { b bVar = this.f; if (bVar != null) { bVar.a(e); } d4.this.a(this.c, this.a, c, e); byte[] d = dVar.d(); if (yp.f(com.applovin.impl.sdk.j.l()) && (!this.e || vi.b(d) != vi.a.V2)) { d4.this.a.p().a(d != null ? new String(dVar.d(), Charset.forName("UTF-8")) : "", this.a, this.b.b() != null ? this.b.b().toString() : ""); } if (d != null) { String str = new String(dVar.d(), Charset.forName("UTF-8")); b bVar2 = this.f; if (bVar2 != null) { bVar2.b(d.length); if (this.b.r()) { d4.this.d = new d(this.b.f(), d.length, e); } } if (this.e) { String b = vi.b(d, d4.this.a.b0(), d4.this.a); if (b == null) { HashMap hashMap = new HashMap(2); hashMap.put("request", StringUtils.getHostAndPath(this.a)); hashMap.put(com.ironsource.cr.n, str); d4.this.a.A().trackEvent("rdf", hashMap); } str = b; } try { this.g.a(this.a, d4.this.a(str, this.d), c); return; } catch (Throwable th) { String str2 = "Unable to parse response from " + StringUtils.getHostAndPath(this.a) + " because of " + th.getClass().getName() + " : " + th.getMessage(); com.applovin.impl.sdk.n unused = d4.this.b; if (com.applovin.impl.sdk.n.a()) { d4.this.b.a("ConnectionManager", str2, th); } d4.this.a.D().c(ca.n); d4.this.a.E().a("ConnectionManager", "failedToParseResponse", th, CollectionUtils.hashMap("url", StringUtils.getHostAndPath(this.a))); this.g.a(this.a, AppLovinErrorCodes.INVALID_RESPONSE, str2, null); return; } } this.g.a(this.a, this.d, c); return; } this.g.a(this.a, c, null, null); } catch (MalformedURLException e2) { e = e2; i = c; if (this.d == null) { d4.this.a(this.c, this.a, i, e); this.g.a(this.a, this.d, -901); } else { d4.this.a(this.c, this.a, i, e, e); this.g.a(this.a, -901, e.getMessage(), null); } } catch (Throwable th2) { th = th2; i2 = c; if (((Boolean) d4.this.a.a(sj.q)).booleanValue()) { i2 = dVar.b(); } if (i2 == 0) { i2 = d4.this.a(th); } int i3 = i2; try { byte[] f = dVar.f(); String str3 = new String(f); if (f != null) { if (this.e) { str3 = vi.b(f, d4.this.a.b0(), d4.this.a); } obj = d4.this.a(str3, this.d); } } catch (Throwable unused2) { } d4.this.a(this.c, this.a, i3, e, th); this.g.a(this.a, i3, th.getMessage(), obj); } } catch (MalformedURLException e3) { e = e3; i = 0; } catch (Throwable th3) { th = th3; } } } public static class b { private long a; private long b; /* JADX INFO: Access modifiers changed from: private */ public void a(long j) { this.a = j; } /* JADX INFO: Access modifiers changed from: private */ public void b(long j) { this.b = j; } public long a() { return this.a; } public long b() { return this.b; } } public static class d { private final long a = System.currentTimeMillis(); private final String b; private final long c; private final long d; public long a() { return this.d; } public long b() { return this.c; } public long c() { return this.a; } public String d() { return this.b; } public String toString() { return "ConnectionManager.RequestMeasurement(timestampMillis=" + c() + ", urlHostAndPathString=" + d() + ", responseSizeBytes=" + b() + ", connectionTimeMillis=" + a() + ")"; } public d(String str, long j, long j2) { this.b = str; this.c = j; this.d = j2; } public boolean a(Object obj) { return obj instanceof d; } public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof d)) { return false; } d dVar = (d) obj; if (!dVar.a(this) || c() != dVar.c() || b() != dVar.b() || a() != dVar.a()) { return false; } String d = d(); String d2 = dVar.d(); return d != null ? d.equals(d2) : d2 == null; } public int hashCode() { long c = c(); long b = b(); int i = ((((int) (c ^ (c >>> 32))) + 59) * 59) + ((int) (b ^ (b >>> 32))); long a = a(); String d = d(); return (((i * 59) + ((int) ((a >>> 32) ^ a))) * 59) + (d == null ? 43 : d.hashCode()); } } /* JADX INFO: Access modifiers changed from: private */ public int a(Throwable th) { if (th instanceof UnknownHostException) { return -1009; } if (th instanceof SocketTimeoutException) { return -1001; } if (th instanceof IOException) { return -100; } return th instanceof JSONException ? -104 : -1; } /* JADX INFO: Access modifiers changed from: private */ public Object a(String str, Object obj) { if (obj == null) { return str; } if (str != null && str.length() >= 3) { if (obj instanceof JSONObject) { return new JSONObject(str); } if (obj instanceof es) { return fs.a(str, this.a); } if (obj instanceof String) { return str; } if (com.applovin.impl.sdk.n.a()) { this.b.b("ConnectionManager", "Failed to process response of type '" + obj.getClass().getName() + "'"); } } return obj; } /* JADX WARN: Removed duplicated region for block: B:66:0x024f A[Catch: all -> 0x0175, TryCatch #1 {all -> 0x0175, blocks: (B:42:0x0129, B:44:0x0139, B:47:0x0165, B:48:0x0161, B:49:0x017a, B:52:0x019f, B:54:0x01bb, B:58:0x01dd, B:61:0x0235, B:64:0x0244, B:66:0x024f, B:67:0x01e1, B:70:0x01e9, B:77:0x0201, B:79:0x0207, B:80:0x0221, B:81:0x01ca, B:82:0x0252, B:84:0x0258, B:85:0x026c, B:73:0x01fa), top: B:41:0x0129, inners: #2 }] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public void a(com.applovin.impl.sdk.network.a r24, com.applovin.impl.d4.b r25, com.applovin.impl.d4.e r26) { /* Method dump skipped, instructions count: 734 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.applovin.impl.d4.a(com.applovin.impl.sdk.network.a, com.applovin.impl.d4$b, com.applovin.impl.d4$e):void"); } /* JADX INFO: Access modifiers changed from: private */ public void a(String str, String str2, int i, long j) { if (com.applovin.impl.sdk.n.a()) { this.b.d("ConnectionManager", "Successful " + str + " returned " + i + " in " + (j / 1000.0f) + " s over " + e4.g(this.a) + " to " + a(str2)); } } /* JADX INFO: Access modifiers changed from: private */ public void a(String str, String str2, int i, long j, Throwable th) { if (com.applovin.impl.sdk.n.a()) { this.b.a("ConnectionManager", "Failed " + str + " returned " + i + " in " + (j / 1000.0f) + " s over " + e4.g(this.a) + " to " + a(str2), th); } } private String a(String str) { return "#" + str.hashCode() + " \"" + StringUtils.getHostAndPath(str) + "\""; } }