package com.google.firebase.messaging;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final db.c f24227a;

    @Nullable
    @GuardedBy("this")
    private Boolean autoInitEnabled;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ FirebaseMessaging f24229c;

    @Nullable
    @GuardedBy("this")
    private db.a dataCollectionDefaultChangeEventHandler;

    public o(FirebaseMessaging firebaseMessaging, db.c cVar) {
        this.f24229c = firebaseMessaging;
        this.f24227a = cVar;
    }

    @Nullable
    private Boolean readEnabled() {
        ApplicationInfo applicationInfo;
        Bundle bundle;
        ua.g gVar = this.f24229c.f24121a;
        gVar.a();
        Context context = gVar.f33401a;
        SharedPreferences sharedPreferences = context.getSharedPreferences("com.google.firebase.messaging", 0);
        if (sharedPreferences.contains("auto_init")) {
            return Boolean.valueOf(sharedPreferences.getBoolean("auto_init", false));
        }
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager == null || (applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 128)) == null || (bundle = applicationInfo.metaData) == null || !bundle.containsKey("firebase_messaging_auto_init_enabled")) {
                return null;
            }
            return Boolean.valueOf(applicationInfo.metaData.getBoolean("firebase_messaging_auto_init_enabled"));
        } catch (PackageManager.NameNotFoundException unused) {
            return null;
        }
    }

    public final synchronized void a() {
        try {
            if (this.f24228b) {
                return;
            }
            Boolean enabled = readEnabled();
            this.autoInitEnabled = enabled;
            if (enabled == null) {
                androidx.media3.exoplayer.offline.c cVar = new androidx.media3.exoplayer.offline.c(this);
                this.dataCollectionDefaultChangeEventHandler = cVar;
                com.google.firebase.components.l lVar = (com.google.firebase.components.l) this.f24227a;
                lVar.a(lVar.f24030c, cVar);
            }
            this.f24228b = true;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized boolean b() {
        boolean z10;
        boolean zBooleanValue;
        try {
            a();
            Boolean bool = this.autoInitEnabled;
            if (bool != null) {
                zBooleanValue = bool.booleanValue();
            } else {
                ua.g gVar = this.f24229c.f24121a;
                gVar.a();
                kb.a aVar = (kb.a) gVar.f33407g.get();
                synchronized (aVar) {
                    z10 = aVar.f29097b;
                }
                zBooleanValue = z10;
            }
        } catch (Throwable th) {
            throw th;
        }
        return zBooleanValue;
    }
}
