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 com.google.firebase.provider.FirebaseInitProvider;
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;

/* renamed from: ᵕˎˊ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2288 {

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final C4446 f8943;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C4246 f8945;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final Context f8947;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final String f8948;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final InterfaceC3290 f8950;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C2549 f8951;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public static final Object f8941 = new Object();

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public static final C1200 f8940 = new C1200(0);

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final AtomicBoolean f8942 = new AtomicBoolean(false);

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final AtomicBoolean f8944 = new AtomicBoolean();

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final CopyOnWriteArrayList f8946 = new CopyOnWriteArrayList();

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final CopyOnWriteArrayList f8949 = 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 C2288(Context context, String str, C4246 c4246) throws PackageManager.NameNotFoundException {
        ?? arrayList;
        int i = 0;
        this.f8947 = context;
        ᵩʛʽ.ˏˋٴ(str);
        this.f8948 = str;
        this.f8945 = c4246;
        C1267 c1267 = FirebaseInitProvider.ᵧᵾˀˈ;
        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 C3845(i, (String) it.next()));
        }
        Trace.endSection();
        Trace.beginSection("Runtime");
        EnumC1217 enumC1217 = EnumC1217.f5145;
        ArrayList arrayList3 = new ArrayList();
        ArrayList arrayList4 = new ArrayList();
        arrayList3.addAll(arrayList2);
        int i2 = 1;
        arrayList3.add(new C3845(i2, new FirebaseCommonRegistrar()));
        arrayList3.add(new C3845(i2, new ExecutorsRegistrar()));
        arrayList4.add(C1703.m4893(context, Context.class, new Class[0]));
        arrayList4.add(C1703.m4893(this, C2288.class, new Class[0]));
        arrayList4.add(C1703.m4893(c4246, C4246.class, new Class[0]));
        ˊᵻ r11 = new ˊᵻ(14);
        if (ᵮʛˀ.ᵡʠ(context) && FirebaseInitProvider.ᵢˇᵭ.get()) {
            arrayList4.add(C1703.m4893(c1267, C1267.class, new Class[0]));
        }
        C2549 c2549 = new C2549(arrayList3, arrayList4, r11);
        this.f8951 = c2549;
        Trace.endSection();
        this.f8943 = new C4446(new C0692(this, 2, context));
        this.f8950 = c2549.mo6431(C1054.class);
        C3800 c3800 = new C3800(this);
        m5993();
        if (this.f8942.get()) {
            ComponentCallbacks2C5475.f20548.f20550.get();
        }
        this.f8946.add(c3800);
        Trace.endSection();
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static C2288 m5989(Context context, C4246 c4246) {
        C2288 c2288;
        AtomicReference atomicReference = C2027.f8136;
        if (context.getApplicationContext() instanceof Application) {
            Application application = (Application) context.getApplicationContext();
            AtomicReference atomicReference2 = C2027.f8136;
            if (atomicReference2.get() == null) {
                C2027 c2027 = new C2027();
                while (true) {
                    if (atomicReference2.compareAndSet(null, c2027)) {
                        ComponentCallbacks2C5475.m11104(application);
                        ComponentCallbacks2C5475.f20548.m11106(c2027);
                        break;
                    }
                    if (atomicReference2.get() != null) {
                        break;
                    }
                }
            }
        }
        if (context.getApplicationContext() != null) {
            context = context.getApplicationContext();
        }
        synchronized (f8941) {
            C1200 c1200 = f8940;
            ᵩʛʽ.ˌᵜᵹᵩ("FirebaseApp name [DEFAULT] already exists!", !c1200.containsKey("[DEFAULT]"));
            ᵩʛʽ.ᵶᵷᵕ(context, "Application context cannot be null.");
            c2288 = new C2288(context, "[DEFAULT]", c4246);
            c1200.put("[DEFAULT]", c2288);
        }
        c2288.m5994();
        return c2288;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static C2288 m5990() {
        C2288 c2288;
        synchronized (f8941) {
            try {
                c2288 = (C2288) f8940.get("[DEFAULT]");
                if (c2288 == null) {
                    throw new IllegalStateException("Default FirebaseApp is not initialized in this process " + AbstractC3502.m7992() + ". Make sure to call FirebaseApp.initializeApp(Context) first.");
                }
                ((C1054) c2288.f8950.get()).m3424();
            } catch (Throwable th) {
                throw th;
            }
        }
        return c2288;
    }

    public final boolean equals(Object obj) {
        if (!(obj instanceof C2288)) {
            return false;
        }
        C2288 c2288 = (C2288) obj;
        c2288.m5993();
        return this.f8948.equals(c2288.f8948);
    }

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

    public final String toString() {
        ᵶˉᵹʣ r0 = new ᵶˉᵹʣ(this);
        r0.ˎˏʜʾ(this.f8948, "name");
        r0.ˎˏʜʾ(this.f8945, "options");
        return r0.toString();
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final boolean m5991() {
        boolean z;
        m5993();
        C2247 c2247 = (C2247) this.f8943.get();
        synchronized (c2247) {
            z = c2247.f8799;
        }
        return z;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final String m5992() {
        StringBuilder sb = new StringBuilder();
        m5993();
        byte[] bytes = this.f8948.getBytes(Charset.defaultCharset());
        sb.append(bytes == null ? null : Base64.encodeToString(bytes, 11));
        sb.append("+");
        m5993();
        byte[] bytes2 = this.f8945.f15904.getBytes(Charset.defaultCharset());
        sb.append(bytes2 != null ? Base64.encodeToString(bytes2, 11) : null);
        return sb.toString();
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m5993() {
        ᵩʛʽ.ˌᵜᵹᵩ("FirebaseApp was deleted", !this.f8944.get());
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m5994() {
        HashMap map;
        if (!ᵮʛˀ.ᵡʠ(this.f8947)) {
            m5993();
            Context context = this.f8947;
            AtomicReference atomicReference = C0517.f2680;
            if (atomicReference.get() == null) {
                C0517 c0517 = new C0517(context);
                while (!atomicReference.compareAndSet(null, c0517)) {
                    if (atomicReference.get() != null) {
                        return;
                    }
                }
                context.registerReceiver(c0517, new IntentFilter("android.intent.action.USER_UNLOCKED"));
                return;
            }
            return;
        }
        m5993();
        C2549 c2549 = this.f8951;
        m5993();
        boolean zEquals = "[DEFAULT]".equals(this.f8948);
        AtomicReference atomicReference2 = (AtomicReference) c2549.f9930;
        Boolean boolValueOf = Boolean.valueOf(zEquals);
        while (true) {
            if (atomicReference2.compareAndSet(null, boolValueOf)) {
                synchronized (c2549) {
                    map = new HashMap((HashMap) c2549.f9933);
                }
                c2549.m6430(map, zEquals);
                break;
            } else if (atomicReference2.get() != null) {
                break;
            }
        }
        ((C1054) this.f8950.get()).m3424();
    }
}
