package B0;

import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.Spatializer;
import android.opengl.Matrix;
import android.os.Handler;
import android.os.Looper;
import android.util.SparseArray;
import d3.C0785g0;
import h2.C1029b;
import java.util.concurrent.atomic.AtomicMarkableReference;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import l4.C1131c;
import m4.C1169e;
import n.U0;
import q1.C1457n;
import q1.InterfaceC1454k;
import v0.AbstractC1664c;
import x0.AbstractC1709a;

/* JADX INFO: renamed from: B0.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0016c implements T0.o {

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Object f718r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f719s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final Object f720t;

    public C0016c(C0785g0 c0785g0, String str) {
        this.f720t = c0785g0;
        P2.w.c(str);
        this.f718r = str;
    }

    public static void b(float[] fArr, float[] fArr2) {
        Matrix.setIdentityM(fArr, 0);
        float f3 = fArr2[10];
        float f7 = fArr2[8];
        float fSqrt = (float) Math.sqrt((f7 * f7) + (f3 * f3));
        float f8 = fArr2[10] / fSqrt;
        fArr[0] = f8;
        float f9 = fArr2[8];
        fArr[2] = f9 / fSqrt;
        fArr[8] = (-f9) / fSqrt;
        fArr[10] = f8;
    }

    public void a(boolean z8) {
        h2.f fVar = (h2.f) this.f720t;
        synchronized (fVar) {
            try {
                if (this.f717q) {
                    throw new IllegalStateException("editor is closed");
                }
                if (P6.g.a(((C1029b) this.f718r).f13366g, this)) {
                    h2.f.a(fVar, this, z8);
                }
                this.f717q = true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public x7.x c(int i) {
        x7.x xVar;
        h2.f fVar = (h2.f) this.f720t;
        synchronized (fVar) {
            if (this.f717q) {
                throw new IllegalStateException("editor is closed");
            }
            ((boolean[]) this.f719s)[i] = true;
            Object obj = ((C1029b) this.f718r).f13363d.get(i);
            h2.d dVar = fVar.f13378F;
            x7.x xVar2 = (x7.x) obj;
            if (!dVar.e(xVar2)) {
                u2.f.a(dVar.j(xVar2));
            }
            xVar = (x7.x) obj;
        }
        return xVar;
    }

    public void d() {
        if (this.f717q) {
            ((x0.s) this.f720t).c(new RunnableC0014a(0, this));
            this.f717q = false;
        }
    }

    public boolean e(String str, String str2) {
        synchronized (this) {
            try {
                if (!((C1169e) ((AtomicMarkableReference) this.f718r).getReference()).c(str, str2)) {
                    return false;
                }
                AtomicMarkableReference atomicMarkableReference = (AtomicMarkableReference) this.f718r;
                atomicMarkableReference.set((C1169e) atomicMarkableReference.getReference(), true);
                RunnableC0014a runnableC0014a = new RunnableC0014a(24, this);
                AtomicReference atomicReference = (AtomicReference) this.f719s;
                while (!atomicReference.compareAndSet(null, runnableC0014a)) {
                    if (atomicReference.get() != null) {
                        return true;
                    }
                }
                ((C1131c) ((U0) this.f720t).f14794b).f14384b.a(runnableC0014a);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public String f() {
        if (!this.f717q) {
            this.f717q = true;
            this.f719s = ((C0785g0) this.f720t).J().getString((String) this.f718r, null);
        }
        return (String) this.f719s;
    }

    public void g(String str) {
        SharedPreferences.Editor editorEdit = ((C0785g0) this.f720t).J().edit();
        editorEdit.putString((String) this.f718r, str);
        editorEdit.apply();
        this.f719s = str;
    }

    @Override // T0.o
    public void h() {
        ((T0.o) this.f718r).h();
        if (!this.f717q) {
            return;
        }
        int i = 0;
        while (true) {
            SparseArray sparseArray = (SparseArray) this.f720t;
            if (i >= sparseArray.size()) {
                return;
            }
            ((C1457n) sparseArray.valueAt(i)).i = true;
            i++;
        }
    }

    @Override // T0.o
    public T0.F j(int i, int i5) {
        T0.o oVar = (T0.o) this.f718r;
        if (i5 != 3) {
            this.f717q = true;
            return oVar.j(i, i5);
        }
        SparseArray sparseArray = (SparseArray) this.f720t;
        C1457n c1457n = (C1457n) sparseArray.get(i);
        if (c1457n != null) {
            return c1457n;
        }
        C1457n c1457n2 = new C1457n(oVar.j(i, i5), (InterfaceC1454k) this.f719s);
        sparseArray.put(i, c1457n2);
        return c1457n2;
    }

    @Override // T0.o
    public void v(T0.z zVar) {
        ((T0.o) this.f718r).v(zVar);
    }

    public C0016c() {
        this.f718r = new float[16];
        this.f719s = new float[16];
        this.f720t = new S0.f();
    }

    public C0016c(T0.o oVar, InterfaceC1454k interfaceC1454k) {
        this.f718r = oVar;
        this.f719s = interfaceC1454k;
        this.f720t = new SparseArray();
    }

    public C0016c(Context context, Looper looper, Looper looper2, F f3, x0.q qVar) {
        this.f718r = context.getApplicationContext();
        this.f720t = qVar.a(looper, null);
        this.f719s = new C0015b(this, qVar.a(looper2, null), f3);
    }

    public C0016c(U0 u02, boolean z8) {
        this.f720t = u02;
        this.f719s = new AtomicReference(null);
        this.f717q = z8;
        this.f718r = new AtomicMarkableReference(new C1169e(z8 ? 8192 : 1024), false);
    }

    public C0016c(int i) {
        this.f718r = new ReentrantLock();
        this.f719s = new long[i];
        this.f720t = new boolean[i];
    }

    public C0016c(h2.f fVar, C1029b c1029b) {
        this.f720t = fVar;
        this.f718r = c1029b;
        fVar.getClass();
        this.f719s = new boolean[2];
    }

    public C0016c(Context context, O0.q qVar) {
        AudioManager audioManagerQ = context == null ? null : AbstractC1664c.q(context);
        if (audioManagerQ != null) {
            context.getClass();
            if (!x0.v.K(context)) {
                Spatializer spatializer = audioManagerQ.getSpatializer();
                this.f718r = spatializer;
                this.f717q = spatializer.getImmersiveAudioLevel() != 0;
                O0.l lVar = new O0.l(qVar);
                this.f720t = lVar;
                Looper looperMyLooper = Looper.myLooper();
                AbstractC1709a.k(looperMyLooper);
                Handler handler = new Handler(looperMyLooper);
                this.f719s = handler;
                spatializer.addOnSpatializerStateChangedListener(new D0.D(handler), lVar);
                return;
            }
        }
        this.f718r = null;
        this.f717q = false;
        this.f719s = null;
        this.f720t = null;
    }
}
