package L4;

import M4.o;
import M4.p;
import android.app.Application;
import android.content.Context;
import com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient;
import d3.R0;
import java.util.Collections;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes.dex */
public final class m implements O4.a {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final Random f4012j = new Random();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final HashMap f4013k = new HashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Context f4015b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ScheduledExecutorService f4016c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final W3.f f4017d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final E4.e f4018e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final X3.c f4019f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final D4.b f4020g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final String f4021h;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f4014a = new HashMap();
    public final HashMap i = new HashMap();

    public m(Context context, ScheduledExecutorService scheduledExecutorService, W3.f fVar, E4.e eVar, X3.c cVar, D4.b bVar) {
        this.f4015b = context;
        this.f4016c = scheduledExecutorService;
        this.f4017d = fVar;
        this.f4018e = eVar;
        this.f4019f = cVar;
        this.f4020g = bVar;
        fVar.a();
        this.f4021h = fVar.f7115c.f7128b;
        AtomicReference atomicReference = l.f4011a;
        Application application = (Application) context.getApplicationContext();
        AtomicReference atomicReference2 = l.f4011a;
        if (atomicReference2.get() == null) {
            l lVar = new l();
            while (true) {
                if (atomicReference2.compareAndSet(null, lVar)) {
                    O2.c.b(application);
                    O2.c.f5095u.a(lVar);
                    break;
                } else if (atomicReference2.get() != null) {
                    break;
                }
            }
        }
        W2.g.f(scheduledExecutorService, new i(0, this));
    }

    public final synchronized c a() throws Throwable {
        try {
            try {
                M4.d dVarC = c("fetch");
                M4.d dVarC2 = c("activate");
                M4.d dVarC3 = c("defaults");
                o oVar = new o(this.f4015b.getSharedPreferences("frc_" + this.f4021h + "_firebase_settings", 0));
                M4.j jVar = new M4.j(this.f4016c, dVarC2, dVarC3);
                W3.f fVar = this.f4017d;
                D4.b bVar = this.f4020g;
                fVar.a();
                R0 r02 = fVar.f7114b.equals("[DEFAULT]") ? new R0(bVar) : null;
                if (r02 != null) {
                    jVar.a(new j(r02));
                }
                R0 r03 = new R0(29, false);
                r03.f11692r = dVarC2;
                r03.f11693s = dVarC3;
                C2.a aVar = new C2.a(4, false);
                aVar.f1160u = Collections.newSetFromMap(new ConcurrentHashMap());
                aVar.f1158s = dVarC2;
                aVar.f1157r = r03;
                ScheduledExecutorService scheduledExecutorService = this.f4016c;
                aVar.f1159t = scheduledExecutorService;
                return b(this.f4017d, this.f4018e, this.f4019f, scheduledExecutorService, dVarC, dVarC2, dVarC3, d(dVarC, oVar), jVar, oVar, aVar);
            } catch (Throwable th) {
                th = th;
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            throw th;
        }
    }

    public final synchronized c b(W3.f fVar, E4.e eVar, X3.c cVar, Executor executor, M4.d dVar, M4.d dVar2, M4.d dVar3, M4.i iVar, M4.j jVar, o oVar, C2.a aVar) {
        try {
            if (!this.f4014a.containsKey("firebase")) {
                fVar.a();
                c cVar2 = new c(fVar.f7114b.equals("[DEFAULT]") ? cVar : null, executor, dVar, dVar2, dVar3, iVar, jVar, oVar, e(fVar, eVar, iVar, dVar2, this.f4015b, oVar), aVar);
                dVar2.b();
                dVar3.b();
                dVar.b();
                this.f4014a.put("firebase", cVar2);
                f4013k.put("firebase", cVar2);
            }
        } catch (Throwable th) {
            throw th;
        }
        return (c) this.f4014a.get("firebase");
    }

    public final M4.d c(String str) {
        p pVar;
        String str2 = "frc_" + this.f4021h + "_firebase_" + str + ".json";
        ScheduledExecutorService scheduledExecutorService = this.f4016c;
        Context context = this.f4015b;
        HashMap map = p.f4289c;
        synchronized (p.class) {
            try {
                HashMap map2 = p.f4289c;
                if (!map2.containsKey(str2)) {
                    map2.put(str2, new p(context, str2));
                }
                pVar = (p) map2.get(str2);
            } catch (Throwable th) {
                throw th;
            }
        }
        return M4.d.d(scheduledExecutorService, pVar);
    }

    public final synchronized M4.i d(M4.d dVar, o oVar) {
        E4.e eVar;
        D4.b kVar;
        ScheduledExecutorService scheduledExecutorService;
        Random random;
        String str;
        W3.f fVar;
        try {
            eVar = this.f4018e;
            W3.f fVar2 = this.f4017d;
            fVar2.a();
            kVar = fVar2.f7114b.equals("[DEFAULT]") ? this.f4020g : new k(0);
            scheduledExecutorService = this.f4016c;
            random = f4012j;
            W3.f fVar3 = this.f4017d;
            fVar3.a();
            str = fVar3.f7115c.f7127a;
            fVar = this.f4017d;
            fVar.a();
        } catch (Throwable th) {
            throw th;
        }
        return new M4.i(eVar, kVar, scheduledExecutorService, random, dVar, new ConfigFetchHttpClient(this.f4015b, fVar.f7115c.f7128b, str, oVar.f4285a.getLong("fetch_timeout_in_seconds", 60L), oVar.f4285a.getLong("fetch_timeout_in_seconds", 60L)), oVar, this.i);
    }

    public final synchronized R0 e(W3.f fVar, E4.e eVar, M4.i iVar, M4.d dVar, Context context, o oVar) {
        return new R0(fVar, eVar, iVar, dVar, context, oVar, this.f4016c);
    }
}
