package com.google.android.gms.internal.measurement;

import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes2.dex */
public final class j1 {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static volatile j1 f20247j;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final i8.d f20249b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final s8.a f20251d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ArrayList f20252e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f20253f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f20254g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public volatile t0 f20256i;

    public j1(Context context, String str, String str2, String str3, Bundle bundle) {
        if (str == null || str3 == null || str2 == null) {
            this.f20248a = "FA";
        } else {
            try {
                Class.forName("com.google.firebase.analytics.FirebaseAnalytics", false, j1.class.getClassLoader());
                this.f20248a = "FA";
            } catch (ClassNotFoundException unused) {
                this.f20248a = str;
            }
        }
        this.f20249b = i8.d.f26577a;
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new o6.a());
        threadPoolExecutor.allowCoreThreadTimeOut(true);
        this.f20250c = Executors.unconfigurableExecutorService(threadPoolExecutor);
        this.f20251d = new s8.a(this);
        this.f20252e = new ArrayList();
        try {
            try {
                if (new com.google.android.gms.measurement.internal.h1(context, com.google.android.gms.measurement.internal.h1.a(context)).zza("google_app_id") != null) {
                    try {
                        Class.forName("com.google.firebase.analytics.FirebaseAnalytics", false, j1.class.getClassLoader());
                    } catch (ClassNotFoundException unused2) {
                        this.f20255h = null;
                        this.f20254g = true;
                        return;
                    }
                }
            } catch (IllegalStateException unused3) {
            }
        } catch (IllegalStateException unused4) {
        }
        if (str3 == null || str2 == null) {
            this.f20255h = "fa";
        } else {
            try {
                Class.forName("com.google.firebase.analytics.FirebaseAnalytics", false, j1.class.getClassLoader());
                this.f20255h = "fa";
            } catch (ClassNotFoundException unused5) {
                this.f20255h = str2;
            }
        }
        d(new f1(this, str2, str3, context, bundle));
        Application application = (Application) context.getApplicationContext();
        if (application == null) {
            return;
        }
        application.registerActivityLifecycleCallbacks(new i1(this));
    }

    public static j1 a(Context context, String str, String str2, String str3, Bundle bundle) {
        com.google.android.gms.common.internal.w.checkNotNull(context);
        if (f20247j == null) {
            synchronized (j1.class) {
                try {
                    if (f20247j == null) {
                        f20247j = new j1(context, str, str2, str3, bundle);
                    }
                } finally {
                }
            }
        }
        return f20247j;
    }

    public final List b(String str, String str2) {
        u0 u0Var = new u0();
        d(new n1(this, str, str2, u0Var, 0));
        List list = (List) u0.O(List.class, u0Var.M(5000L));
        return list == null ? Collections.emptyList() : list;
    }

    public final Map c(String str, String str2, boolean z10) {
        u0 u0Var = new u0();
        d(new m1(this, str, str2, z10, u0Var));
        Bundle bundleM = u0Var.M(5000L);
        if (bundleM == null || bundleM.size() == 0) {
            return Collections.emptyMap();
        }
        HashMap map = new HashMap(bundleM.size());
        for (String str3 : bundleM.keySet()) {
            Object obj = bundleM.get(str3);
            if ((obj instanceof Double) || (obj instanceof Long) || (obj instanceof String)) {
                map.put(str3, obj);
            }
        }
        return map;
    }

    public final void d(g1 g1Var) {
        this.f20250c.execute(g1Var);
    }

    public final void e(Exception exc, boolean z10, boolean z11) {
        this.f20254g |= z10;
        if (!z10 && z11) {
            d(new r1(this, exc));
        }
    }
}
