package p138.p176.p291;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.util.Base64;
import android.util.Log;
import com.google.firebase.components.ComponentDiscoveryService;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.concurrent.GuardedBy;
import p000.p001.p002.p003.p004.C0567;
import p037.p057.C1714;
import p138.p176.p177.p242.p246.p247.p248.ComponentCallbacks2C4215;
import p138.p176.p177.p242.p246.p249.C4281;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p177.p242.p246.p253.C4314;
import p138.p176.p291.p295.C5583;
import p138.p176.p291.p295.C5588;
import p138.p176.p291.p295.C5594;
import p138.p176.p291.p295.C5598;
import p138.p176.p291.p295.C5601;
import p138.p176.p291.p295.InterfaceC5586;
import p138.p176.p291.p295.InterfaceC5589;
import p138.p176.p291.p295.InterfaceC5590;
import p138.p176.p291.p318.InterfaceC5898;
import p138.p176.p291.p319.InterfaceC5902;
import p138.p176.p291.p322.InterfaceC5963;
import p138.p176.p291.p326.C6000;
import p138.p176.p291.p327.AbstractC6005;
import p138.p176.p291.p327.InterfaceC6006;
import p402.C6536;

/* JADX INFO: renamed from: ދ.ހ.ށ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C5559 {

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public static final Object f15972 = new Object();

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final Executor f15973 = new ExecutorC5563(null);

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    @GuardedBy("LOCK")
    public static final Map<String, C5559> f15974 = new C1714();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Context f15975;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final String f15976;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C5565 f15977;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C5594 f15978;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C5601<C6000> f15981;

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

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final AtomicBoolean f15980 = new AtomicBoolean();

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final List<InterfaceC5561> f15982 = new CopyOnWriteArrayList();

    /* JADX INFO: renamed from: ދ.ހ.ށ.ހ$ؠ, reason: contains not printable characters */
    public interface InterfaceC5561 {
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        void m8933(boolean z);
    }

    /* JADX INFO: renamed from: ދ.ހ.ށ.ހ$ހ, reason: contains not printable characters */
    @TargetApi(14)
    public static class C5562 implements ComponentCallbacks2C4215.InterfaceC4216 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public static AtomicReference<C5562> f15983 = new AtomicReference<>();

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public static /* synthetic */ void m8934(Context context) {
            if (context.getApplicationContext() instanceof Application) {
                Application application = (Application) context.getApplicationContext();
                if (f15983.get() == null) {
                    C5562 c5562 = new C5562();
                    if (f15983.compareAndSet(null, c5562)) {
                        ComponentCallbacks2C4215.m6876(application);
                        ComponentCallbacks2C4215.f13416.m6877(c5562);
                    }
                }
            }
        }

        @Override // p138.p176.p177.p242.p246.p247.p248.ComponentCallbacks2C4215.InterfaceC4216
        /* JADX INFO: renamed from: ֏ */
        public void mo6879(boolean z) {
            synchronized (C5559.f15972) {
                for (C5559 c5559 : new ArrayList(C5559.f15974.values())) {
                    if (c5559.f15979.get()) {
                        Log.d("FirebaseApp", "Notifying background state change listeners.");
                        Iterator<InterfaceC5561> it = c5559.f15982.iterator();
                        while (it.hasNext()) {
                            it.next().m8933(z);
                        }
                    }
                }
            }
        }
    }

    /* JADX INFO: renamed from: ދ.ހ.ށ.ހ$ށ, reason: contains not printable characters */
    public static class ExecutorC5563 implements Executor {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public static final Handler f15984 = new Handler(Looper.getMainLooper());

        public /* synthetic */ ExecutorC5563(C5560 c5560) {
        }

        @Override // java.util.concurrent.Executor
        public void execute(Runnable runnable) {
            f15984.post(runnable);
        }
    }

    /* JADX INFO: renamed from: ދ.ހ.ށ.ހ$ނ, reason: contains not printable characters */
    @TargetApi(24)
    public static class C5564 extends BroadcastReceiver {

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public static AtomicReference<C5564> f15985 = new AtomicReference<>();

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Context f15986;

        public C5564(Context context) {
            this.f15986 = context;
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            synchronized (C5559.f15972) {
                Iterator<C5559> it = C5559.f15974.values().iterator();
                while (it.hasNext()) {
                    it.next().m8930();
                }
            }
            this.f15986.unregisterReceiver(this);
        }
    }

    /* JADX WARN: Can't wrap try/catch for region: R(15:0|2|(2:54|3)|(1:5)(2:6|(1:8)(11:9|13|(1:15)(4:16|(4:19|(1:73)(3:70|23|74)|71|17)|68|24)|25|(7:28|55|29|59|(3:58|31|62)(3:57|32|61)|60|26)|52|44|47|(1:49)|50|51))|12|13|(0)(0)|25|(1:26)|52|44|47|(0)|50|51) */
    /* JADX WARN: Code restructure failed: missing block: B:46:0x0149, code lost:
    
        r14 = null;
     */
    /* JADX WARN: Removed duplicated region for block: B:15:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:16:0x0080  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x00cb  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0189  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C5559(final Context context, String str, C5565 c5565) {
        Bundle bundle;
        List<String> listEmptyList;
        PackageManager packageManager;
        new CopyOnWriteArrayList();
        C0567.m1910(context);
        this.f15975 = context;
        C0567.m1926(str);
        this.f15976 = str;
        C0567.m1910(c5565);
        this.f15977 = c5565;
        C5588 c5588 = new C5588(ComponentDiscoveryService.class, null);
        try {
            packageManager = context.getPackageManager();
        } catch (PackageManager.NameNotFoundException unused) {
            Log.w("ComponentDiscovery", "Application info not found.");
        }
        if (packageManager == null) {
            Log.w("ComponentDiscovery", "Context has no PackageManager.");
        } else {
            ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, c5588.f16028), 128);
            if (serviceInfo != null) {
                bundle = serviceInfo.metaData;
                if (bundle != null) {
                    Log.w("ComponentDiscovery", "Could not retrieve metadata, returning empty list of registrars.");
                    listEmptyList = Collections.emptyList();
                } else {
                    ArrayList 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));
                        }
                    }
                    listEmptyList = arrayList;
                }
                ArrayList arrayList2 = new ArrayList();
                for (String str3 : listEmptyList) {
                    try {
                        Class<?> cls = Class.forName(str3);
                        if (InterfaceC5590.class.isAssignableFrom(cls)) {
                            arrayList2.add((InterfaceC5590) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]));
                        } else {
                            Log.w("ComponentDiscovery", String.format("Class %s is not an instance of %s", str3, "com.google.firebase.components.ComponentRegistrar"));
                        }
                    } catch (ClassNotFoundException e) {
                        Log.w("ComponentDiscovery", String.format("Class %s is not an found.", str3), e);
                    } catch (IllegalAccessException e2) {
                        Log.w("ComponentDiscovery", String.format("Could not instantiate %s.", str3), e2);
                    } catch (InstantiationException e3) {
                        Log.w("ComponentDiscovery", String.format("Could not instantiate %s.", str3), e3);
                    } catch (NoSuchMethodException e4) {
                        Log.w("ComponentDiscovery", String.format("Could not instantiate %s", str3), e4);
                    } catch (InvocationTargetException e5) {
                        Log.w("ComponentDiscovery", String.format("Could not instantiate %s", str3), e5);
                    }
                }
                String string = C6536.f19307.toString();
                Executor executor = f15973;
                C5583[] c5583Arr = new C5583[8];
                c5583Arr[0] = C5583.m8946(context, Context.class, new Class[0]);
                c5583Arr[1] = C5583.m8946(this, C5559.class, new Class[0]);
                c5583Arr[2] = C5583.m8946(c5565, C5565.class, new Class[0]);
                c5583Arr[3] = C4303.m7061("fire-android", "");
                c5583Arr[4] = C4303.m7061("fire-core", "19.3.0");
                c5583Arr[5] = string != null ? C4303.m7061("kotlin", string) : null;
                C5583.C5585 c5585M8945 = C5583.m8945(InterfaceC6006.class);
                c5585M8945.m8950(new C5598(AbstractC6005.class, 2, 0));
                c5585M8945.m8949(new InterfaceC5589() { // from class: ދ.ހ.ށ.ތ.ؠ
                    @Override // p138.p176.p291.p295.InterfaceC5589
                    /* JADX INFO: renamed from: ֏ */
                    public Object mo8939(InterfaceC5586 interfaceC5586) {
                        return new C6003(interfaceC5586.mo8944(AbstractC6005.class), C6004.m9345());
                    }
                });
                c5583Arr[6] = c5585M8945.m8951();
                C5583.C5585 c5585M89452 = C5583.m8945(InterfaceC5902.class);
                c5585M89452.m8950(C5598.m8957(Context.class));
                c5585M89452.m8949(new InterfaceC5589() { // from class: ދ.ހ.ށ.އ.֏
                    @Override // p138.p176.p291.p295.InterfaceC5589
                    /* JADX INFO: renamed from: ֏ */
                    public Object mo8939(InterfaceC5586 interfaceC5586) {
                        return new C5901((Context) interfaceC5586.mo8943(Context.class));
                    }
                });
                c5583Arr[7] = c5585M89452.m8951();
                this.f15978 = new C5594(executor, arrayList2, c5583Arr);
                this.f15981 = new C5601<>(new InterfaceC5963(this, context) { // from class: ދ.ހ.ށ.ؠ

                    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
                    public final C5559 f15970;

                    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
                    public final Context f15971;

                    {
                        this.f15970 = this;
                        this.f15971 = context;
                    }

                    @Override // p138.p176.p291.p322.InterfaceC5963
                    public Object get() {
                        return C5559.m8926(this.f15970, this.f15971);
                    }
                });
            }
            Log.w("ComponentDiscovery", c5588.f16028 + " has no service info.");
        }
        bundle = null;
        if (bundle != null) {
        }
        ArrayList arrayList22 = new ArrayList();
        while (r0.hasNext()) {
        }
        String string2 = C6536.f19307.toString();
        Executor executor2 = f15973;
        C5583[] c5583Arr2 = new C5583[8];
        c5583Arr2[0] = C5583.m8946(context, Context.class, new Class[0]);
        c5583Arr2[1] = C5583.m8946(this, C5559.class, new Class[0]);
        c5583Arr2[2] = C5583.m8946(c5565, C5565.class, new Class[0]);
        c5583Arr2[3] = C4303.m7061("fire-android", "");
        c5583Arr2[4] = C4303.m7061("fire-core", "19.3.0");
        c5583Arr2[5] = string2 != null ? C4303.m7061("kotlin", string2) : null;
        C5583.C5585 c5585M89453 = C5583.m8945(InterfaceC6006.class);
        c5585M89453.m8950(new C5598(AbstractC6005.class, 2, 0));
        c5585M89453.m8949(new InterfaceC5589() { // from class: ދ.ހ.ށ.ތ.ؠ
            @Override // p138.p176.p291.p295.InterfaceC5589
            /* JADX INFO: renamed from: ֏ */
            public Object mo8939(InterfaceC5586 interfaceC5586) {
                return new C6003(interfaceC5586.mo8944(AbstractC6005.class), C6004.m9345());
            }
        });
        c5583Arr2[6] = c5585M89453.m8951();
        C5583.C5585 c5585M894522 = C5583.m8945(InterfaceC5902.class);
        c5585M894522.m8950(C5598.m8957(Context.class));
        c5585M894522.m8949(new InterfaceC5589() { // from class: ދ.ހ.ށ.އ.֏
            @Override // p138.p176.p291.p295.InterfaceC5589
            /* JADX INFO: renamed from: ֏ */
            public Object mo8939(InterfaceC5586 interfaceC5586) {
                return new C5901((Context) interfaceC5586.mo8943(Context.class));
            }
        });
        c5583Arr2[7] = c5585M894522.m8951();
        this.f15978 = new C5594(executor2, arrayList22, c5583Arr2);
        this.f15981 = new C5601<>(new InterfaceC5963(this, context) { // from class: ދ.ހ.ށ.ؠ

            /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
            public final C5559 f15970;

            /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
            public final Context f15971;

            {
                this.f15970 = this;
                this.f15971 = context;
            }

            @Override // p138.p176.p291.p322.InterfaceC5963
            public Object get() {
                return C5559.m8926(this.f15970, this.f15971);
            }
        });
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C5559 m8924(Context context) {
        synchronized (f15972) {
            if (f15974.containsKey("[DEFAULT]")) {
                return m8927();
            }
            C5565 c5565M8935 = C5565.m8935(context);
            if (c5565M8935 == null) {
                Log.w("FirebaseApp", "Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.");
                return null;
            }
            return m8925(context, c5565M8935, "[DEFAULT]");
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C5559 m8925(Context context, C5565 c5565, String str) {
        C5559 c5559;
        C5562.m8934(context);
        String strTrim = str.trim();
        if (context.getApplicationContext() != null) {
            context = context.getApplicationContext();
        }
        synchronized (f15972) {
            C0567.m1921(!f15974.containsKey(strTrim), "FirebaseApp name " + strTrim + " already exists!");
            C0567.m1857(context, (Object) "Application context cannot be null.");
            c5559 = new C5559(context, strTrim, c5565);
            f15974.put(strTrim, c5559);
        }
        c5559.m8930();
        return c5559;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ C6000 m8926(C5559 c5559, Context context) {
        return new C6000(context, c5559.m8929(), (InterfaceC5898) c5559.f15978.mo8943(InterfaceC5898.class));
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static C5559 m8927() {
        C5559 c5559;
        synchronized (f15972) {
            c5559 = f15974.get("[DEFAULT]");
            if (c5559 == null) {
                throw new IllegalStateException("Default FirebaseApp is not initialized in this process " + C4314.m7213() + ". Make sure to call FirebaseApp.initializeApp(Context) first.");
            }
        }
        return c5559;
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof C5559)) {
            return false;
        }
        String str = this.f15976;
        C5559 c5559 = (C5559) obj;
        c5559.m8928();
        return str.equals(c5559.f15976);
    }

    public int hashCode() {
        return this.f15976.hashCode();
    }

    public String toString() {
        C4281 c4281M1935 = C0567.m1935(this);
        c4281M1935.m6962("name", this.f15976);
        c4281M1935.m6962("options", this.f15977);
        return c4281M1935.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8928() {
        C0567.m1921(!this.f15980.get(), "FirebaseApp was deleted");
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public String m8929() {
        StringBuilder sb = new StringBuilder();
        m8928();
        byte[] bytes = this.f15976.getBytes(Charset.defaultCharset());
        sb.append(bytes == null ? null : Base64.encodeToString(bytes, 11));
        sb.append("+");
        m8928();
        byte[] bytes2 = this.f15977.f15988.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 m8930() {
        if (!(Build.VERSION.SDK_INT >= 24 ? ((UserManager) this.f15975.getSystemService(UserManager.class)).isUserUnlocked() : true)) {
            Context context = this.f15975;
            if (C5564.f15985.get() == null) {
                C5564 c5564 = new C5564(context);
                if (C5564.f15985.compareAndSet(null, c5564)) {
                    context.registerReceiver(c5564, new IntentFilter("android.intent.action.USER_UNLOCKED"));
                    return;
                }
                return;
            }
            return;
        }
        C5594 c5594 = this.f15978;
        boolean zM8932 = m8932();
        for (Map.Entry<C5583<?>, C5601<?>> entry : c5594.f16034.entrySet()) {
            C5583<?> key = entry.getKey();
            C5601<?> value = entry.getValue();
            if (!(key.f16018 == 1)) {
                if (!(key.f16018 == 2) || !zM8932) {
                }
            }
            value.get();
        }
        c5594.f16037.m8960();
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public boolean m8931() {
        m8928();
        return this.f15981.get().f16873.get();
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public boolean m8932() {
        m8928();
        return "[DEFAULT]".equals(this.f15976);
    }
}
