package com.google.firebase.sessions.settings;

import android.util.Log;
import dn.p;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.b;
import kotlin.coroutines.jvm.internal.f;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.o0;
import kotlin.jvm.internal.t;
import org.json.JSONException;
import org.json.JSONObject;
import rm.n0;
import rm.y;
import vm.d;

/* JADX INFO: Access modifiers changed from: package-private */
@f(c = "com.google.firebase.sessions.settings.RemoteSettings$updateSettings$2$1", f = "RemoteSettings.kt", l = {125, 128, 131, 133, 134, 136}, m = "invokeSuspend")
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0001\u001a\u00020\u0000H\u008a@"}, d2 = {"Lorg/json/JSONObject;", "it", "Lrm/n0;", "<anonymous>"}, k = 3, mv = {1, 8, 0})
/* loaded from: classes3.dex */
public final class RemoteSettings$updateSettings$2$1 extends l implements p {
    /* synthetic */ Object L$0;
    Object L$1;
    Object L$2;
    int label;
    final /* synthetic */ RemoteSettings this$0;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public RemoteSettings$updateSettings$2$1(RemoteSettings remoteSettings, d<? super RemoteSettings$updateSettings$2$1> dVar) {
        super(2, dVar);
        this.this$0 = remoteSettings;
    }

    @Override // kotlin.coroutines.jvm.internal.a
    public final d<n0> create(Object obj, d<?> dVar) {
        RemoteSettings$updateSettings$2$1 remoteSettings$updateSettings$2$1 = new RemoteSettings$updateSettings$2$1(this.this$0, dVar);
        remoteSettings$updateSettings$2$1.L$0 = obj;
        return remoteSettings$updateSettings$2$1;
    }

    /* JADX WARN: Failed to find 'out' block for switch in B:2:0x000f. Please report as an issue. */
    /* JADX WARN: Removed duplicated region for block: B:12:0x019f A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:16:0x0165  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x0142  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0162  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x011f  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00fc  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00f4  */
    @Override // kotlin.coroutines.jvm.internal.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object f10;
        o0 o0Var;
        Boolean bool;
        o0 o0Var2;
        o0 o0Var3;
        SettingsCache settingsCache;
        o0 o0Var4;
        o0 o0Var5;
        Integer num;
        SettingsCache settingsCache2;
        Double d10;
        SettingsCache settingsCache3;
        Integer num2;
        n0 n0Var;
        SettingsCache settingsCache4;
        SettingsCache settingsCache5;
        SettingsCache settingsCache6;
        Long d11;
        f10 = wm.d.f();
        switch (this.label) {
            case 0:
                y.b(obj);
                JSONObject jSONObject = (JSONObject) this.L$0;
                Log.d(RemoteSettings.TAG, "Fetched settings: " + jSONObject);
                o0 o0Var6 = new o0();
                o0Var = new o0();
                o0 o0Var7 = new o0();
                if (jSONObject.has("app_quality")) {
                    Object obj2 = jSONObject.get("app_quality");
                    t.e(obj2, "null cannot be cast to non-null type org.json.JSONObject");
                    JSONObject jSONObject2 = (JSONObject) obj2;
                    try {
                        bool = jSONObject2.has("sessions_enabled") ? (Boolean) jSONObject2.get("sessions_enabled") : null;
                        try {
                            if (jSONObject2.has("sampling_rate")) {
                                o0Var6.f26199p = (Double) jSONObject2.get("sampling_rate");
                            }
                            if (jSONObject2.has("session_timeout_seconds")) {
                                o0Var.f26199p = (Integer) jSONObject2.get("session_timeout_seconds");
                            }
                            if (jSONObject2.has("cache_duration")) {
                                o0Var7.f26199p = (Integer) jSONObject2.get("cache_duration");
                            }
                        } catch (JSONException e10) {
                            e = e10;
                            Log.e(RemoteSettings.TAG, "Error parsing the configs remotely fetched: ", e);
                            if (bool == null) {
                            }
                        }
                    } catch (JSONException e11) {
                        e = e11;
                        bool = null;
                    }
                } else {
                    bool = null;
                }
                if (bool == null) {
                    RemoteSettings remoteSettings = this.this$0;
                    bool.booleanValue();
                    settingsCache = remoteSettings.getSettingsCache();
                    this.L$0 = o0Var6;
                    this.L$1 = o0Var;
                    this.L$2 = o0Var7;
                    this.label = 1;
                    if (settingsCache.updateSettingsEnabled(bool, this) == f10) {
                        return f10;
                    }
                    o0Var4 = o0Var6;
                    o0Var5 = o0Var;
                    o0Var3 = o0Var7;
                    o0Var = o0Var5;
                    o0Var2 = o0Var4;
                    num = (Integer) o0Var.f26199p;
                    if (num != null) {
                        RemoteSettings remoteSettings2 = this.this$0;
                        num.intValue();
                        settingsCache2 = remoteSettings2.getSettingsCache();
                        Integer num3 = (Integer) o0Var.f26199p;
                        this.L$0 = o0Var2;
                        this.L$1 = o0Var3;
                        this.L$2 = null;
                        this.label = 2;
                        if (settingsCache2.updateSessionRestartTimeout(num3, this) == f10) {
                            return f10;
                        }
                    }
                    d10 = (Double) o0Var2.f26199p;
                    if (d10 != null) {
                        RemoteSettings remoteSettings3 = this.this$0;
                        d10.doubleValue();
                        settingsCache3 = remoteSettings3.getSettingsCache();
                        Double d12 = (Double) o0Var2.f26199p;
                        this.L$0 = o0Var3;
                        this.L$1 = null;
                        this.L$2 = null;
                        this.label = 3;
                        if (settingsCache3.updateSamplingRate(d12, this) == f10) {
                            return f10;
                        }
                    }
                    num2 = (Integer) o0Var3.f26199p;
                    if (num2 == null) {
                        n0Var = null;
                        if (n0Var == null) {
                        }
                        settingsCache6 = this.this$0.getSettingsCache();
                        d11 = b.d(System.currentTimeMillis());
                        this.L$0 = null;
                        this.L$1 = null;
                        this.L$2 = null;
                        this.label = 6;
                        if (settingsCache6.updateSessionCacheUpdatedTime(d11, this) == f10) {
                        }
                        return n0.f34904a;
                    }
                    RemoteSettings remoteSettings4 = this.this$0;
                    num2.intValue();
                    settingsCache4 = remoteSettings4.getSettingsCache();
                    Integer num4 = (Integer) o0Var3.f26199p;
                    this.L$0 = null;
                    this.L$1 = null;
                    this.L$2 = null;
                    this.label = 4;
                    if (settingsCache4.updateSessionCacheDuration(num4, this) == f10) {
                        return f10;
                    }
                    n0Var = n0.f34904a;
                    if (n0Var == null) {
                        settingsCache5 = this.this$0.getSettingsCache();
                        Integer c10 = b.c(86400);
                        this.L$0 = null;
                        this.L$1 = null;
                        this.L$2 = null;
                        this.label = 5;
                        if (settingsCache5.updateSessionCacheDuration(c10, this) == f10) {
                            return f10;
                        }
                    }
                    settingsCache6 = this.this$0.getSettingsCache();
                    d11 = b.d(System.currentTimeMillis());
                    this.L$0 = null;
                    this.L$1 = null;
                    this.L$2 = null;
                    this.label = 6;
                    if (settingsCache6.updateSessionCacheUpdatedTime(d11, this) == f10) {
                        return f10;
                    }
                    return n0.f34904a;
                }
                o0Var2 = o0Var6;
                o0Var3 = o0Var7;
                num = (Integer) o0Var.f26199p;
                if (num != null) {
                }
                d10 = (Double) o0Var2.f26199p;
                if (d10 != null) {
                }
                num2 = (Integer) o0Var3.f26199p;
                if (num2 == null) {
                }
            case 1:
                o0Var3 = (o0) this.L$2;
                o0Var5 = (o0) this.L$1;
                o0Var4 = (o0) this.L$0;
                y.b(obj);
                o0Var = o0Var5;
                o0Var2 = o0Var4;
                num = (Integer) o0Var.f26199p;
                if (num != null) {
                }
                d10 = (Double) o0Var2.f26199p;
                if (d10 != null) {
                }
                num2 = (Integer) o0Var3.f26199p;
                if (num2 == null) {
                }
                break;
            case 2:
                o0Var3 = (o0) this.L$1;
                o0Var2 = (o0) this.L$0;
                y.b(obj);
                d10 = (Double) o0Var2.f26199p;
                if (d10 != null) {
                }
                num2 = (Integer) o0Var3.f26199p;
                if (num2 == null) {
                }
                break;
            case 3:
                o0Var3 = (o0) this.L$0;
                y.b(obj);
                num2 = (Integer) o0Var3.f26199p;
                if (num2 == null) {
                }
                break;
            case 4:
                y.b(obj);
                n0Var = n0.f34904a;
                if (n0Var == null) {
                }
                settingsCache6 = this.this$0.getSettingsCache();
                d11 = b.d(System.currentTimeMillis());
                this.L$0 = null;
                this.L$1 = null;
                this.L$2 = null;
                this.label = 6;
                if (settingsCache6.updateSessionCacheUpdatedTime(d11, this) == f10) {
                }
                return n0.f34904a;
            case 5:
                y.b(obj);
                settingsCache6 = this.this$0.getSettingsCache();
                d11 = b.d(System.currentTimeMillis());
                this.L$0 = null;
                this.L$1 = null;
                this.L$2 = null;
                this.label = 6;
                if (settingsCache6.updateSessionCacheUpdatedTime(d11, this) == f10) {
                }
                return n0.f34904a;
            case 6:
                y.b(obj);
                return n0.f34904a;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }

    @Override // dn.p
    public final Object invoke(JSONObject jSONObject, d<? super n0> dVar) {
        return ((RemoteSettings$updateSettings$2$1) create(jSONObject, dVar)).invokeSuspend(n0.f34904a);
    }
}
