package com.ironsource.mediationsdk; import android.content.Context; import android.os.SystemClock; import android.text.TextUtils; import com.facebook.appevents.UserDataStore; import com.google.firebase.perf.network.FirebasePerfUrlConnection; import com.ironsource.cr; import com.ironsource.environment.thread.IronSourceThreadManager; import com.ironsource.f5; import com.ironsource.h5; import com.ironsource.i9; import com.ironsource.l4; import com.ironsource.mediationsdk.IronSource; import com.ironsource.mediationsdk.d; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.mediationsdk.logger.IronSourceLogger; import com.ironsource.mediationsdk.logger.IronSourceLoggerManager; import com.ironsource.mediationsdk.utils.IronSourceAES; import com.ironsource.mediationsdk.utils.IronSourceUtils; import com.ironsource.xa; import com.mbridge.msdk.newreward.function.common.MBridgeCommon; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.ref.WeakReference; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public class e { private final String a = "1"; private final String b = MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE; private final String c = MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE; private final String d = "GenericNotifications"; private f e; private IronSource.AD_UNIT f; private h5 g; private l4 h; private ISBannerSize i; public static class a implements Runnable { protected WeakReference a; protected d.a b; protected int c; protected String d; protected long e; protected int f; private int h; private final URL k; private final JSONObject l; private final boolean m; private final int n; private final long o; private final boolean p; private final boolean q; protected String g = "other"; protected String i = ""; protected int j = 0; public a(l4 l4Var, URL url, JSONObject jSONObject, boolean z, int i, long j, boolean z2, boolean z3, int i2) { this.a = new WeakReference<>(l4Var); this.k = url; this.l = jSONObject; this.m = z; this.n = i; this.o = j; this.p = z2; this.q = z3; this.h = i2; } private String a() { return this.h == 2 ? xa.b().d() : xa.b().c(); } private String a(HttpURLConnection httpURLConnection) throws IOException { InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream()); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { bufferedReader.close(); inputStreamReader.close(); return sb.toString(); } sb.append(readLine); } } private HttpURLConnection a(URL url, long j) throws IOException { HttpURLConnection httpURLConnection = (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection())); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); httpURLConnection.setReadTimeout((int) j); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); return httpURLConnection; } private JSONObject a(String str, String str2) throws JSONException { String decode = IronSourceAES.decode(str, str2); if (TextUtils.isEmpty(decode)) { throw new JSONException("decryption error"); } return new JSONObject(decode); } private void a(long j, long j2) { long time = j - (new Date().getTime() - j2); if (time > 0) { SystemClock.sleep(time); } } /* JADX WARN: Removed duplicated region for block: B:13:0x0078 */ /* JADX WARN: Removed duplicated region for block: B:14:0x0065 */ /* JADX WARN: Removed duplicated region for block: B:6:0x0059 */ /* JADX WARN: Removed duplicated region for block: B:9:0x006d */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private void a(java.net.HttpURLConnection r8, org.json.JSONObject r9, boolean r10) throws java.lang.Exception { /* r7 = this; java.io.OutputStream r8 = r8.getOutputStream() java.io.OutputStreamWriter r0 = new java.io.OutputStreamWriter java.lang.String r1 = "UTF-8" r0.(r8, r1) java.io.BufferedWriter r1 = new java.io.BufferedWriter r1.(r0) int r2 = r7.h r3 = 2 if (r2 != r3) goto L4d com.ironsource.xa r2 = com.ironsource.xa.b() // Catch: org.json.JSONException -> L1e java.lang.String r2 = r2.a() // Catch: org.json.JSONException -> L1e goto L4f L1e: r2 = move-exception com.ironsource.i9 r4 = com.ironsource.i9.d() r4.a(r2) java.lang.String r4 = r2.getLocalizedMessage() r7.i = r4 r4 = 1015(0x3f7, float:1.422E-42) r7.j = r4 r4 = 1 r7.h = r4 com.ironsource.mediationsdk.logger.IronLog r4 = com.ironsource.mediationsdk.logger.IronLog.INTERNAL java.lang.StringBuilder r5 = new java.lang.StringBuilder r5.() java.lang.String r6 = "get encrypted session key exception " r5.append(r6) java.lang.String r2 = r2.getMessage() r5.append(r2) java.lang.String r2 = r5.toString() r4.error(r2) L4d: java.lang.String r2 = "" L4f: java.lang.String r9 = r9.toString() java.lang.String r4 = r7.a() if (r10 == 0) goto L65 com.ironsource.mediationsdk.logger.IronLog r10 = com.ironsource.mediationsdk.logger.IronLog.INTERNAL java.lang.String r5 = "compressing and encrypting auction request" r10.verbose(r5) java.lang.String r9 = com.ironsource.mediationsdk.utils.IronSourceAES.compressAndEncrypt(r4, r9) goto L69 L65: java.lang.String r9 = com.ironsource.mediationsdk.utils.IronSourceAES.encode(r4, r9) L69: int r10 = r7.h if (r10 != r3) goto L78 java.lang.Object[] r9 = new java.lang.Object[]{r2, r9} java.lang.String r10 = "{\"sk\" : \"%1$s\", \"ct\" : \"%2$s\"}" java.lang.String r9 = java.lang.String.format(r10, r9) goto L82 L78: java.lang.Object[] r9 = new java.lang.Object[]{r9} java.lang.String r10 = "{\"request\" : \"%1$s\"}" java.lang.String r9 = java.lang.String.format(r10, r9) L82: r1.write(r9) r1.flush() r1.close() r0.close() r8.close() return */ throw new UnsupportedOperationException("Method not decompiled: com.ironsource.mediationsdk.e.a.a(java.net.HttpURLConnection, org.json.JSONObject, boolean):void"); } private JSONObject b(String str, String str2) throws JSONException { IronLog.INTERNAL.verbose("decrypting and decompressing auction response"); String decryptAndDecompress = IronSourceAES.decryptAndDecompress(str, str2); if (decryptAndDecompress != null) { return new JSONObject(decryptAndDecompress); } throw new JSONException("decompression error"); } public JSONObject a(JSONObject jSONObject, boolean z) throws JSONException { String a = a(); String string = jSONObject.getString(this.h == 2 ? UserDataStore.CITY : cr.n); return z ? b(a, string) : a(a, string); } public void a(String str, boolean z, boolean z2) throws JSONException { if (TextUtils.isEmpty(str)) { throw new JSONException("empty response"); } JSONObject jSONObject = new JSONObject(str); if (z) { jSONObject = a(jSONObject, z2); } d.a a = d.b().a(jSONObject); this.b = a; this.c = a.c(); this.d = this.b.d(); } public void a(boolean z, l4 l4Var, long j) { if (z) { l4Var.a(this.b.h(), this.b.a(), this.b.e(), this.b.f(), this.b.b(), this.f + 1, j, this.j, this.i); } else { l4Var.a(this.c, this.d, this.f + 1, this.g, j); } } public boolean b() { long time; int responseCode; String str; this.e = new Date().getTime(); try { this.h = this.j == 1015 ? 1 : this.h; this.f = 0; HttpURLConnection httpURLConnection = null; while (true) { int i = this.f; int i2 = this.n; if (i >= i2) { this.f = i2 - 1; this.g = "trials_fail"; return false; } try { time = new Date().getTime(); String str2 = "Auction Handler: auction trial " + (this.f + 1) + " out of " + this.n + " max trials"; IronSourceLoggerManager.getLogger().log(IronSourceLogger.IronSourceTag.INTERNAL, str2, 0); IronSourceUtils.sendAutomationLog(str2); httpURLConnection = a(this.k, this.o); a(httpURLConnection, this.l, this.p); responseCode = httpURLConnection.getResponseCode(); } catch (SocketTimeoutException e) { i9.d().a(e); if (httpURLConnection != null) { httpURLConnection.disconnect(); } this.c = 1006; this.d = "Connection timed out"; IronLog.INTERNAL.error("Auction socket timeout exception " + e.getMessage()); } catch (Throwable th) { i9.d().a(th); IronLog.INTERNAL.error("getting exception " + th); if (httpURLConnection != null) { httpURLConnection.disconnect(); } this.c = 1000; this.d = th.getMessage(); this.g = "other"; return false; } if (responseCode == 200 || responseCode == 204) { try { a(a(httpURLConnection), this.m, this.q); httpURLConnection.disconnect(); return true; } catch (JSONException e2) { i9.d().a(e2); if (e2.getMessage() != null && e2.getMessage().equalsIgnoreCase("decryption error")) { this.c = 1003; str = "Auction decryption error"; } else if (e2.getMessage() == null || !e2.getMessage().equalsIgnoreCase("decompression error")) { this.c = 1002; str = "Auction parsing error"; } else { this.c = 1008; str = "Auction decompression error"; } this.d = str; this.g = "parsing"; IronLog.INTERNAL.error("Auction handle response exception " + e2.getMessage()); httpURLConnection.disconnect(); return false; } } this.c = 1001; String str3 = "Auction response code not valid, error code response from server - " + responseCode; this.d = str3; IronLog.INTERNAL.error(str3); httpURLConnection.disconnect(); if (this.f < this.n - 1) { a(this.o, time); } this.f++; } } catch (Exception e3) { i9.d().a(e3); this.c = 1007; this.d = e3.getMessage(); this.f = 0; this.g = "other"; IronLog.INTERNAL.error("Auction request exception " + e3.getMessage()); return false; } } @Override // java.lang.Runnable public void run() { boolean b = b(); l4 l4Var = this.a.get(); if (l4Var == null) { return; } a(b, l4Var, new Date().getTime() - this.e); } } @Deprecated public e(IronSource.AD_UNIT ad_unit, h5 h5Var, l4 l4Var) { this.f = ad_unit; this.g = h5Var; this.h = l4Var; } public e(f fVar) { this.e = fVar; } private JSONObject a(Map map, List list, h hVar, int i, boolean z, IronSourceSegment ironSourceSegment) throws JSONException { i iVar = new i(this.f); iVar.a(map); iVar.a(list); iVar.a(hVar); iVar.a(i); iVar.a(this.i); iVar.a(ironSourceSegment); iVar.b(z); return d.b().a(iVar); } public void a(Context context, i iVar, l4 l4Var) { try { IronSourceThreadManager.INSTANCE.postMediationBackgroundTask(this.e.a(context, iVar, l4Var)); } catch (Exception e) { i9.d().a(e); IronLog.INTERNAL.error("execute auction exception " + e.getMessage()); if (l4Var != null) { l4Var.a(1000, e.getMessage(), 0, "other", 0L); } } } @Deprecated public void a(Context context, Map map, List list, h hVar, int i, IronSourceSegment ironSourceSegment) { try { boolean isEncryptedResponse = IronSourceUtils.isEncryptedResponse(); IronSourceThreadManager.INSTANCE.postMediationBackgroundTask(new a(this.h, new URL(this.g.a(false)), a(map, list, hVar, i, isEncryptedResponse, ironSourceSegment), isEncryptedResponse, this.g.g(), this.g.m(), this.g.n(), this.g.o(), this.g.d())); } catch (Exception e) { i9.d().a(e); IronLog.INTERNAL.error("execute auction exception " + e.getMessage()); this.h.a(1000, e.getMessage(), 0, "other", 0L); } } @Deprecated public void a(Context context, Map map, List list, h hVar, int i, IronSourceSegment ironSourceSegment, ISBannerSize iSBannerSize) { this.i = iSBannerSize; a(context, map, list, hVar, i, ironSourceSegment); } public void a(f5 f5Var, int i, f5 f5Var2) { Iterator it = f5Var.g().iterator(); while (it.hasNext()) { d.b().a("reportLoadSuccess", f5Var.c(), d.b().a(it.next(), i, f5Var, "", "", "")); } if (f5Var2 != null) { Iterator it2 = f5Var2.g().iterator(); while (it2.hasNext()) { d.b().a("reportLoadSuccess", "GenericNotifications", d.b().a(it2.next(), i, f5Var, "", MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE, "")); } } } public void a(f5 f5Var, int i, f5 f5Var2, String str) { Iterator it = f5Var.b().iterator(); while (it.hasNext()) { d.b().a("reportImpression", f5Var.c(), d.b().a(it.next(), i, f5Var, "", "", str)); } if (f5Var2 != null) { Iterator it2 = f5Var2.b().iterator(); while (it2.hasNext()) { d.b().a("reportImpression", "GenericNotifications", d.b().a(it2.next(), i, f5Var, "", MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE, str)); } } } public void a(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, int i, f5 f5Var, f5 f5Var2) { int i2 = f5Var2.i(); Iterator it = arrayList.iterator(); while (it.hasNext()) { String next = it.next(); if (!next.equals(f5Var2.c())) { f5 f5Var3 = concurrentHashMap.get(next); int i3 = f5Var3.i(); String h = f5Var3.h(); String str = i3 < i2 ? "1" : MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE; IronLog.INTERNAL.verbose("instance=" + f5Var3.c() + ", instancePriceOrder= " + i3 + ", loseReasonCode=" + str + ", winnerInstance=" + f5Var2.c() + ", winnerInstancePriceOrder=" + i2); Iterator it2 = f5Var3.f().iterator(); while (it2.hasNext()) { d.b().a("reportAuctionLose", f5Var3.c(), d.b().a(it2.next(), i, f5Var2, h, str, "")); } } } if (f5Var != null) { Iterator it3 = f5Var.f().iterator(); while (it3.hasNext()) { d.b().a("reportAuctionLose", "GenericNotifications", d.b().a(it3.next(), i, f5Var2, "", MBridgeCommon.DYNAMIC_VIEW_TEMPLATE_VALUE, "")); } } } public void a(CopyOnWriteArrayList copyOnWriteArrayList, ConcurrentHashMap concurrentHashMap, int i, f5 f5Var, f5 f5Var2) { ArrayList arrayList = new ArrayList<>(); Iterator it = copyOnWriteArrayList.iterator(); while (it.hasNext()) { arrayList.add(it.next().c()); } a(arrayList, concurrentHashMap, i, f5Var, f5Var2); } public boolean a() { return this.e.a(); } }