package defpackage;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.Trace;
import android.util.Base64;
import com.google.firebase.FirebaseCommonRegistrar;
import com.google.firebase.components.ComponentDiscoveryService;
import com.google.firebase.concurrent.ExecutorsRegistrar;
import j$.util.Objects;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: renamed from: ˉˎⁱ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1191 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final String f5071;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final InterfaceC5081 f5072;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C4250 f5073;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final Context f5076;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final C2592 f5077;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final C1356 f5078;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public static final Object f5070 = new Object();

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static final C3310 f5069 = new C3310(0);

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final AtomicBoolean f5074 = new AtomicBoolean(false);

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final AtomicBoolean f5080 = new AtomicBoolean();

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final CopyOnWriteArrayList f5079 = new CopyOnWriteArrayList();

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final CopyOnWriteArrayList f5075 = new CopyOnWriteArrayList();

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v14, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v7, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r0v8, types: [java.util.List] */
    public C1191(Context context, String str, C4250 c4250) {
        ?? arrayList;
        int i = 0;
        this.f5076 = context;
        ᵘᵞʿⁱ.ˊᵫᵗ(str);
        this.f5071 = str;
        this.f5073 = c4250;
        C0463 c0463 = AbstractC0851.f3754;
        Trace.beginSection("Firebase");
        Trace.beginSection("ComponentDiscovery");
        ArrayList arrayList2 = new ArrayList();
        Bundle bundle = null;
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null) {
                ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class<?>) ComponentDiscoveryService.class), 128);
                if (serviceInfo == null) {
                    Objects.toString(ComponentDiscoveryService.class);
                } else {
                    bundle = serviceInfo.metaData;
                }
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        if (bundle == null) {
            arrayList = Collections.EMPTY_LIST;
        } else {
            arrayList = new ArrayList();
            for (String str2 : bundle.keySet()) {
                if ("com.google.firebase.components.ComponentRegistrar".equals(bundle.get(str2)) && str2.startsWith("com.google.firebase.components:")) {
                    arrayList.add(str2.substring(31));
                }
            }
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(new C0118(i, (String) it.next()));
        }
        Trace.endSection();
        Trace.beginSection("Runtime");
        EnumC2215 enumC2215 = EnumC2215.f8780;
        ArrayList arrayList3 = new ArrayList();
        ArrayList arrayList4 = new ArrayList();
        arrayList3.addAll(arrayList2);
        int i2 = 1;
        arrayList3.add(new C0118(i2, new FirebaseCommonRegistrar()));
        arrayList3.add(new C0118(i2, new ExecutorsRegistrar()));
        arrayList4.add(C3954.m8688(context, Context.class, new Class[0]));
        arrayList4.add(C3954.m8688(this, C1191.class, new Class[0]));
        arrayList4.add(C3954.m8688(c4250, C4250.class, new Class[0]));
        C3664 c3664 = new C3664(14);
        if (ᵲᵧˇ.ᵪᵹᵥᵻ(context) && AbstractC0851.f3755.get()) {
            arrayList4.add(C3954.m8688(c0463, C0463.class, new Class[0]));
        }
        C1356 c1356 = new C1356(arrayList3, arrayList4, c3664);
        this.f5078 = c1356;
        Trace.endSection();
        this.f5077 = new C2592(new C4419(this, 2, context));
        this.f5072 = c1356.mo3902(C4655.class);
        C3062 c3062 = new C3062(this);
        m3677();
        if (this.f5074.get()) {
            ComponentCallbacks2C1363.f5638.f5639.get();
        }
        this.f5079.add(c3062);
        Trace.endSection();
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static C1191 m3674() {
        C1191 c1191;
        synchronized (f5070) {
            try {
                c1191 = (C1191) f5069.get("[DEFAULT]");
                if (c1191 == null) {
                    throw new IllegalStateException("Default FirebaseApp is not initialized in this process " + AbstractC0562.m2175() + ". Make sure to call FirebaseApp.initializeApp(Context) first.");
                }
                ((C4655) c1191.f5072.get()).m9784();
            } catch (Throwable th) {
                throw th;
            }
        }
        return c1191;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static C1191 m3675(Context context, C4250 c4250) {
        C1191 c1191;
        AtomicReference atomicReference = C0241.f1793;
        if (context.getApplicationContext() instanceof Application) {
            Application application = (Application) context.getApplicationContext();
            AtomicReference atomicReference2 = C0241.f1793;
            if (atomicReference2.get() == null) {
                C0241 c0241 = new C0241();
                while (true) {
                    if (atomicReference2.compareAndSet(null, c0241)) {
                        ComponentCallbacks2C1363.m3908(application);
                        ComponentCallbacks2C1363.f5638.m3910(c0241);
                        break;
                    }
                    if (atomicReference2.get() != null) {
                        break;
                    }
                }
            }
        }
        if (context.getApplicationContext() != null) {
            context = context.getApplicationContext();
        }
        synchronized (f5070) {
            C3310 c3310 = f5069;
            ᵘᵞʿⁱ.ᵝᵶ("FirebaseApp name [DEFAULT] already exists!", !c3310.containsKey("[DEFAULT]"));
            ᵘᵞʿⁱ.ᵮᵣᵗˈ(context, "Application context cannot be null.");
            c1191 = new C1191(context, "[DEFAULT]", c4250);
            c3310.put("[DEFAULT]", c1191);
        }
        c1191.m3678();
        return c1191;
    }

    public final boolean equals(Object obj) {
        if (!(obj instanceof C1191)) {
            return false;
        }
        C1191 c1191 = (C1191) obj;
        c1191.m3677();
        return this.f5071.equals(c1191.f5071);
    }

    public final int hashCode() {
        return this.f5071.hashCode();
    }

    public final String toString() {
        C3714 c3714 = new C3714(this);
        c3714.m8378(this.f5071, "name");
        c3714.m8378(this.f5073, "options");
        return c3714.toString();
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final String m3676() {
        StringBuilder sb = new StringBuilder();
        m3677();
        byte[] bytes = this.f5071.getBytes(Charset.defaultCharset());
        sb.append(bytes == null ? null : Base64.encodeToString(bytes, 11));
        sb.append("+");
        m3677();
        byte[] bytes2 = this.f5073.f16223.getBytes(Charset.defaultCharset());
        sb.append(bytes2 != null ? Base64.encodeToString(bytes2, 11) : null);
        return sb.toString();
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m3677() {
        ᵘᵞʿⁱ.ᵝᵶ("FirebaseApp was deleted", !this.f5080.get());
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m3678() {
        HashMap map;
        if (!ᵲᵧˇ.ᵪᵹᵥᵻ(this.f5076)) {
            m3677();
            Context context = this.f5076;
            AtomicReference atomicReference = C3767.f14335;
            if (atomicReference.get() == null) {
                C3767 c3767 = new C3767(context);
                while (!atomicReference.compareAndSet(null, c3767)) {
                    if (atomicReference.get() != null) {
                        return;
                    }
                }
                context.registerReceiver(c3767, new IntentFilter("android.intent.action.USER_UNLOCKED"));
                return;
            }
            return;
        }
        m3677();
        C1356 c1356 = this.f5078;
        m3677();
        boolean zEquals = "[DEFAULT]".equals(this.f5071);
        AtomicReference atomicReference2 = (AtomicReference) c1356.f5620;
        Boolean boolValueOf = Boolean.valueOf(zEquals);
        while (true) {
            if (atomicReference2.compareAndSet(null, boolValueOf)) {
                synchronized (c1356) {
                    map = new HashMap((HashMap) c1356.f5615);
                }
                c1356.m3897(map, zEquals);
                break;
            } else if (atomicReference2.get() != null) {
                break;
            }
        }
        ((C4655) this.f5072.get()).m9784();
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final boolean m3679() {
        boolean z;
        m3677();
        C0670 c0670 = (C0670) this.f5077.get();
        synchronized (c0670) {
            z = c0670.f3111;
        }
        return z;
    }
}
