package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import com.google.android.gms.tasks.TaskCompletionSource;

/* JADX INFO: loaded from: classes2.dex */
public class eq1 {
    public final SharedPreferences a;
    public final y03 b;
    public final Object c;
    public TaskCompletionSource d;
    public boolean e;
    public Boolean f;
    public final TaskCompletionSource g;

    public eq1(y03 y03Var) {
        PackageManager packageManager;
        ApplicationInfo applicationInfo;
        Bundle bundle;
        Object obj = new Object();
        this.c = obj;
        this.d = new TaskCompletionSource();
        this.e = false;
        this.g = new TaskCompletionSource();
        y03Var.a();
        Context context = y03Var.a;
        this.b = y03Var;
        SharedPreferences sharedPreferences = context.getSharedPreferences("com.google.firebase.crashlytics", 0);
        this.a = sharedPreferences;
        Boolean boolValueOf = sharedPreferences.contains("firebase_crashlytics_collection_enabled") ? Boolean.valueOf(sharedPreferences.getBoolean("firebase_crashlytics_collection_enabled", true)) : null;
        if (boolValueOf == null) {
            try {
                packageManager = context.getPackageManager();
            } catch (PackageManager.NameNotFoundException e) {
                hh5.a.a("Could not read data collection permission from manifest", e);
            }
            Boolean boolValueOf2 = (packageManager == null || (applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 128)) == null || (bundle = applicationInfo.metaData) == null || !bundle.containsKey("firebase_crashlytics_collection_enabled")) ? null : Boolean.valueOf(applicationInfo.metaData.getBoolean("firebase_crashlytics_collection_enabled"));
            boolValueOf = boolValueOf2 == null ? null : Boolean.valueOf(Boolean.TRUE.equals(boolValueOf2));
        }
        this.f = boolValueOf;
        synchronized (obj) {
            try {
                if (a()) {
                    this.d.trySetResult(null);
                    this.e = true;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final synchronized boolean a() {
        boolean zBooleanValue;
        boolean z;
        Boolean bool = this.f;
        if (bool != null) {
            zBooleanValue = bool.booleanValue();
        } else {
            try {
                y03 y03Var = this.b;
                y03Var.a();
                fq1 fq1Var = (fq1) y03Var.g.get();
                synchronized (fq1Var) {
                    z = fq1Var.b;
                }
                zBooleanValue = z;
            } catch (IllegalStateException unused) {
                zBooleanValue = false;
            }
        }
        return zBooleanValue;
    }
}
