package o;

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.common.internal.Preconditions;
import com.google.firebase.messaging.FirebaseMessaging;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicMarkableReference;
import java.util.concurrent.atomic.AtomicReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.cs, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0949cs {
    public boolean a;
    public final Object b;
    public Serializable c;
    public Object d;

    public C0949cs(C1617jr0 c1617jr0, String str) {
        this.d = c1617jr0;
        Preconditions.checkNotEmpty(str);
        this.b = str;
    }

    public void a(boolean z) {
        C1332gs c1332gs = (C1332gs) this.d;
        synchronized (c1332gs) {
            try {
                if (this.a) {
                    throw new IllegalStateException("editor is closed");
                }
                if (F3.c(((C1044ds) this.b).g, this)) {
                    C1332gs.b(c1332gs, this, z);
                }
                this.a = true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public SV b(int i) {
        SV sv;
        C1332gs c1332gs = (C1332gs) this.d;
        synchronized (c1332gs) {
            if (this.a) {
                throw new IllegalStateException("editor is closed");
            }
            ((boolean[]) this.c)[i] = true;
            Object obj = ((C1044ds) this.b).d.get(i);
            C1236fs c1236fs = c1332gs.A;
            SV sv2 = (SV) obj;
            if (!c1236fs.e(sv2)) {
                AbstractC1345h.a(c1236fs.j(sv2));
            }
            sv = (SV) obj;
        }
        return sv;
    }

    public int[] c() {
        synchronized (this) {
            try {
                if (!this.a) {
                    return null;
                }
                long[] jArr = (long[]) this.b;
                int length = jArr.length;
                int i = 0;
                int i2 = 0;
                while (i < length) {
                    int i3 = i2 + 1;
                    int i4 = 1;
                    boolean z = jArr[i] > 0;
                    boolean[] zArr = (boolean[]) this.c;
                    if (z != zArr[i2]) {
                        int[] iArr = (int[]) this.d;
                        if (!z) {
                            i4 = 2;
                        }
                        iArr[i2] = i4;
                    } else {
                        ((int[]) this.d)[i2] = 0;
                    }
                    zArr[i2] = z;
                    i++;
                    i2 = i3;
                }
                this.a = false;
                return (int[]) ((int[]) this.d).clone();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public synchronized void d() {
        try {
            if (this.a) {
                return;
            }
            Boolean boolF = f();
            this.c = boolF;
            if (boolF == null) {
                C0387Oy c0387Oy = new C0387Oy(0);
                C0178Gw c0178Gw = (C0178Gw) ((InterfaceC2250qb0) this.b);
                c0178Gw.a(c0178Gw.c, c0387Oy);
            }
            this.a = true;
        } catch (Throwable th) {
            throw th;
        }
    }

    public synchronized boolean e() {
        Boolean bool;
        try {
            d();
            bool = (Boolean) this.c;
        } catch (Throwable th) {
            throw th;
        }
        return bool != null ? bool.booleanValue() : ((FirebaseMessaging) this.d).a.h();
    }

    public Boolean f() {
        ApplicationInfo applicationInfo;
        Bundle bundle;
        C0076Cy c0076Cy = ((FirebaseMessaging) this.d).a;
        c0076Cy.a();
        Context context = c0076Cy.a;
        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 String g() {
        if (!this.a) {
            this.a = true;
            C1617jr0 c1617jr0 = (C1617jr0) this.d;
            this.c = c1617jr0.w().getString((String) this.b, null);
        }
        return (String) this.c;
    }

    public void h(String str) {
        SharedPreferences.Editor editorEdit = ((C1617jr0) this.d).w().edit();
        editorEdit.putString((String) this.b, str);
        editorEdit.apply();
        this.c = str;
    }

    public C0949cs() {
        this.b = new Object();
        this.c = new ArrayList();
        this.d = new ArrayList();
        this.a = true;
    }

    public C0949cs(Zf0 zf0, boolean z) {
        this.d = zf0;
        this.c = new AtomicReference(null);
        this.a = z;
        this.b = new AtomicMarkableReference(new XJ(z ? 8192 : 1024), false);
    }

    /* JADX WARN: Type inference failed for: r0v1, types: [boolean[], java.io.Serializable] */
    public C0949cs(int i) {
        this.b = new long[i];
        this.c = new boolean[i];
        this.d = new int[i];
    }

    /* JADX WARN: Type inference failed for: r1v2, types: [boolean[], java.io.Serializable] */
    public C0949cs(C1332gs c1332gs, C1044ds c1044ds) {
        this.d = c1332gs;
        this.b = c1044ds;
        this.c = new boolean[2];
    }

    public C0949cs(FirebaseMessaging firebaseMessaging, InterfaceC2250qb0 interfaceC2250qb0) {
        this.d = firebaseMessaging;
        this.b = interfaceC2250qb0;
    }
}
