package com.google.firebase.sessions.settings; import com.ironsource.nb; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Map; import javax.net.ssl.HttpsURLConnection; import kotlin.ResultKt; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt; import kotlin.coroutines.jvm.internal.SuspendLambda; import kotlin.jvm.functions.Function2; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Ref; import kotlinx.coroutines.CoroutineScope; import org.json.JSONObject; /* loaded from: classes3.dex */ public final class RemoteSettingsFetcher$doConfigFetch$2 extends SuspendLambda implements Function2 { public final /* synthetic */ Map $headerOptions; public final /* synthetic */ Function2 $onFailure; public final /* synthetic */ Function2 $onSuccess; public int label; public final /* synthetic */ RemoteSettingsFetcher this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public RemoteSettingsFetcher$doConfigFetch$2(RemoteSettingsFetcher remoteSettingsFetcher, Map map, Function2 function2, Function2 function22, Continuation continuation) { super(2, continuation); this.this$0 = remoteSettingsFetcher; this.$headerOptions = map; this.$onSuccess = function2; this.$onFailure = function22; } @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl public final Continuation create(Object obj, Continuation continuation) { return new RemoteSettingsFetcher$doConfigFetch$2(this.this$0, this.$headerOptions, this.$onSuccess, this.$onFailure, continuation); } @Override // kotlin.jvm.functions.Function2 public final Object invoke(CoroutineScope coroutineScope, Continuation continuation) { return ((RemoteSettingsFetcher$doConfigFetch$2) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r6v0, types: [T, java.lang.String] */ @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl public final Object invokeSuspend(Object obj) { Object coroutine_suspended; URL url; coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); int i = this.label; try { if (i == 0) { ResultKt.throwOnFailure(obj); url = this.this$0.settingsUrl(); URLConnection openConnection = url.openConnection(); Intrinsics.checkNotNull(openConnection, "null cannot be cast to non-null type javax.net.ssl.HttpsURLConnection"); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) openConnection; httpsURLConnection.setRequestMethod("GET"); httpsURLConnection.setRequestProperty("Accept", nb.L); for (Map.Entry entry : this.$headerOptions.entrySet()) { httpsURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); } int responseCode = httpsURLConnection.getResponseCode(); if (responseCode == 200) { InputStream inputStream = httpsURLConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder sb = new StringBuilder(); Ref.ObjectRef objectRef = new Ref.ObjectRef(); while (true) { ?? readLine = bufferedReader.readLine(); objectRef.element = readLine; if (readLine == 0) { break; } sb.append((String) readLine); } bufferedReader.close(); inputStream.close(); JSONObject jSONObject = new JSONObject(sb.toString()); Function2 function2 = this.$onSuccess; this.label = 1; if (function2.invoke(jSONObject, this) == coroutine_suspended) { return coroutine_suspended; } } else { Function2 function22 = this.$onFailure; String str = "Bad response code: " + responseCode; this.label = 2; if (function22.invoke(str, this) == coroutine_suspended) { return coroutine_suspended; } } } else if (i == 1 || i == 2) { ResultKt.throwOnFailure(obj); } else { if (i != 3) { throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } ResultKt.throwOnFailure(obj); } } catch (Exception e) { Function2 function23 = this.$onFailure; String message = e.getMessage(); if (message == null) { message = e.toString(); } this.label = 3; if (function23.invoke(message, this) == coroutine_suspended) { return coroutine_suspended; } } return Unit.INSTANCE; } }