package D0;

import android.content.Context;
import android.media.AudioDeviceInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import java.util.Objects;
import u0.C1567c;

/* JADX INFO: renamed from: D0.h, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0071h {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final A1.G f1549b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final C0068e f1551d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final C0069f f1553f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public K4.c f1555h;
    public C1567c i;

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

    public C0071h(Context context, A1.G g8, C1567c c1567c, K4.c cVar) {
        Context applicationContext = context.getApplicationContext();
        this.f1548a = applicationContext;
        this.f1549b = g8;
        this.i = c1567c;
        this.f1555h = cVar;
        int i = x0.v.f18553a;
        Looper looperMyLooper = Looper.myLooper();
        Handler handler = new Handler(looperMyLooper == null ? Looper.getMainLooper() : looperMyLooper, null);
        this.f1550c = handler;
        this.f1551d = x0.v.f18553a >= 23 ? new C0068e(this) : null;
        this.f1552e = new C0070g(0, this);
        C0067d c0067d = C0067d.f1537c;
        String str = Build.MANUFACTURER;
        Uri uriFor = (str.equals("Amazon") || str.equals("Xiaomi")) ? Settings.Global.getUriFor("external_surround_sound_enabled") : null;
        this.f1553f = uriFor != null ? new C0069f(this, handler, applicationContext.getContentResolver(), uriFor) : null;
    }

    public final void a(C0067d c0067d) {
        O0.q qVar;
        if (!this.f1556j || c0067d.equals(this.f1554g)) {
            return;
        }
        this.f1554g = c0067d;
        F f3 = (F) this.f1549b.f63r;
        f3.getClass();
        Looper looperMyLooper = Looper.myLooper();
        Looper looper = f3.f1472f0;
        if (looper != looperMyLooper) {
            String name = looper == null ? "null" : looper.getThread().getName();
            throw new IllegalStateException("Current looper (" + (looperMyLooper == null ? "null" : looperMyLooper.getThread().getName()) + ") is not the playback looper (" + name + ")");
        }
        C0067d c0067d2 = f3.f1491w;
        if (c0067d2 == null || c0067d.equals(c0067d2)) {
            return;
        }
        f3.f1491w = c0067d;
        K4.c cVar = f3.f1486r;
        if (cVar != null) {
            H h8 = (H) cVar.f3604r;
            synchronized (h8.f756q) {
                qVar = h8.f755G;
            }
            if (qVar != null) {
                qVar.f();
            }
        }
    }

    public final void b(AudioDeviceInfo audioDeviceInfo) {
        K4.c cVar = this.f1555h;
        if (Objects.equals(audioDeviceInfo, cVar == null ? null : (AudioDeviceInfo) cVar.f3604r)) {
            return;
        }
        K4.c cVar2 = audioDeviceInfo != null ? new K4.c(4, audioDeviceInfo) : null;
        this.f1555h = cVar2;
        a(C0067d.c(this.f1548a, this.i, cVar2));
    }
}
