package com.ironsource; import android.content.Context; import android.text.TextUtils; import com.ironsource.cr; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.mediationsdk.logger.IronSourceError; import com.ironsource.mediationsdk.logger.IronSourceLogger; import com.ironsource.mediationsdk.logger.IronSourceLoggerManager; import com.ironsource.mediationsdk.p; import com.ironsource.mediationsdk.server.HttpFunctions; import com.ironsource.mediationsdk.server.ServerURL; import com.ironsource.mediationsdk.utils.ErrorBuilder; import com.ironsource.mediationsdk.utils.IronSourceAES; import com.mbridge.msdk.newreward.function.common.MBridgeError; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Ref; import kotlin.jvm.internal.SourceDebugExtension; import org.json.JSONException; import org.json.JSONObject; @SourceDebugExtension({"SMAP\nServerInit.kt\nKotlin\n*S Kotlin\n*F\n+ 1 ServerInit.kt\ncom/unity3d/sdk/internal/init/ServerInit\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,190:1\n1#2:191\n*E\n"}) /* loaded from: classes2.dex */ public final class ar { private final dq a(String str) { return str != null ? new dq(2110, str) : new dq(dq.d, "noServerResponse"); } /* JADX WARN: Multi-variable type inference failed */ private final nq a(Context context, sq sqVar, iq iqVar) { try { String a = sqVar.a(context); if (TextUtils.isEmpty(a)) { a = sqVar.b(context); IronSourceLoggerManager.getLogger().log(IronSourceLogger.IronSourceTag.INTERNAL, "using custom identifier", 1); } String str = a; final Ref.ObjectRef objectRef = new Ref.ObjectRef(); String sendPostRequest = HttpFunctions.sendPostRequest(ServerURL.buildInitURL(context, iqVar.d(), iqVar.f(), str, null, true, null, false), ah.a().toString(), new p.c() { // from class: com.ironsource.ar$$ExternalSyntheticLambda0 @Override // com.ironsource.mediationsdk.p.c public final void a(String str2) { ar.a(Ref.ObjectRef.this, str2); } }); if (sendPostRequest == null) { IronLog.INTERNAL.warning("serverResponseString is null"); return new nq(a((String) objectRef.element)); } if (sqVar.c()) { IronLog ironLog = IronLog.INTERNAL; ironLog.verbose("encrypt"); JSONObject jSONObject = new JSONObject(sendPostRequest); String encryptedResponse = jSONObject.optString(cr.n); if (TextUtils.isEmpty(encryptedResponse)) { ironLog.warning("encryptedResponse is empty - return null"); return new nq(new dq(2100, gq.h)); } boolean optBoolean = jSONObject.optBoolean("compression", false); Intrinsics.checkNotNullExpressionValue(encryptedResponse, "encryptedResponse"); sendPostRequest = a(encryptedResponse, optBoolean); if (TextUtils.isEmpty(sendPostRequest)) { ironLog.warning("encoded response invalid - return null"); sqVar.d(); return new nq(new dq(dq.f, gq.g)); } } cr crVar = new cr(context, iqVar.d(), iqVar.f(), sendPostRequest); crVar.a(cr.a.SERVER); if (crVar.p()) { return new nq(new jq(crVar)); } IronLog.INTERNAL.warning("response invalid - return null"); return new nq(new dq(dq.e, "serverResponseIsNotValid")); } catch (Exception e) { i9.d().a(e); IronLog.INTERNAL.warning("exception = " + e); return new nq(e instanceof JSONException ? new dq(dq.e, "serverResponseIsNotValid") : new dq(510, "internal error")); } } private final String a(String str, boolean z) { String decryptAndDecompress = z ? IronSourceAES.decryptAndDecompress(xa.b().c(), str) : IronSourceAES.decode(xa.b().c(), str); Intrinsics.checkNotNullExpressionValue(decryptAndDecompress, "{\n IronSourceAES.de… encryptedResponse)\n }"); return decryptAndDecompress; } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Multi-variable type inference failed */ public static final void a(Ref.ObjectRef reason, String errorMessage) { Intrinsics.checkNotNullParameter(reason, "$reason"); Intrinsics.checkNotNullParameter(errorMessage, "errorMessage"); reason.element = errorMessage; } private final nq b(Context context, sq sqVar, iq iqVar) { nq a = a(context, sqVar, iqVar); if (a.c()) { return a; } IronSourceLoggerManager logger = IronSourceLoggerManager.getLogger(); IronSourceLogger.IronSourceTag ironSourceTag = IronSourceLogger.IronSourceTag.INTERNAL; logger.log(ironSourceTag, "Null or invalid response. Trying to get cached response", 0); cr a2 = sqVar.a(context, iqVar.d()); if (a2 == null) { return a; } nq nqVar = new nq(new jq(a2)); IronSourceError buildUsingCachedConfigurationError = ErrorBuilder.buildUsingCachedConfigurationError(iqVar.d(), iqVar.f()); IronSourceLoggerManager.getLogger().log(ironSourceTag, buildUsingCachedConfigurationError + ": " + nqVar.b(), 1); sqVar.e(); return nqVar; } public final void a(Context context, iq request, sq tools, hq listener) { dq a; Intrinsics.checkNotNullParameter(context, "context"); Intrinsics.checkNotNullParameter(request, "request"); Intrinsics.checkNotNullParameter(tools, "tools"); Intrinsics.checkNotNullParameter(listener, "listener"); String f = request.f(); if (f == null) { f = ""; } tools.a("userId", f); tools.a("appKey", request.d()); tools.b().i(request.f()); nq b = b(context, tools, request); if (b.b() != null) { bq bqVar = new bq(b.b()); if (b.c()) { listener.a(bqVar); return; } a = new dq(dq.e, "serverResponseIsNotValid"); } else { a = b.a(); if (a == null) { a = new dq(510, MBridgeError.ERROR_MESSAGE_UN_KNOWN); } } listener.a(a); } }