package vf2; import android.content.IntentFilter; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.media.AudioManager; import android.os.Build; import android.os.PowerManager; import android.util.Log; import com.xingin.tags.library.audio.CapaHeadsetReceiver; /* compiled from: CapaAudioModeManager */ public class a { /* renamed from: a reason: collision with root package name */ public AudioManager f140247a; /* renamed from: b reason: collision with root package name */ public SensorManager f140248b; /* renamed from: c reason: collision with root package name */ public PowerManager f140249c; /* renamed from: d reason: collision with root package name */ public PowerManager.WakeLock f140250d; /* renamed from: e reason: collision with root package name */ public Sensor f140251e; /* renamed from: f reason: collision with root package name */ public b f140252f; /* renamed from: g reason: collision with root package name */ public CapaHeadsetReceiver f140253g; /* renamed from: h reason: collision with root package name */ public boolean f140254h = false; /* renamed from: i reason: collision with root package name */ public boolean f140255i = false; /* renamed from: j reason: collision with root package name */ public SensorEventListener f140256j = new C2317a(); /* renamed from: vf2.a$a reason: collision with other inner class name */ /* compiled from: CapaAudioModeManager */ public class C2317a implements SensorEventListener { public C2317a() { } public void onAccuracyChanged(Sensor sensor, int i10) { } public void onSensorChanged(SensorEvent sensorEvent) { if (!a.this.f140254h) { float f14 = sensorEvent.values[0]; Log.d("AudioTag", "SensorEventListener proximiny : " + f14); if (f14 >= a.this.f140251e.getMaximumRange()) { Log.d("AudioTag", "SensorEventListener 扬声器模式"); if (a.this.f140252f != null) { a.this.f140252f.a(true); } a.this.l(true); if (a.this.f140252f != null) { a.this.f140252f.b(true); } a.this.k(); return; } Log.d("AudioTag", "SensorEventListener 听筒模式"); if (a.this.f140252f != null) { a.this.f140252f.a(false); } a.this.l(false); if (a.this.f140252f != null) { a.this.f140252f.b(false); } a.this.j(); } } } /* compiled from: CapaAudioModeManager */ public interface b { void a(boolean z14); void b(boolean z14); } public a() { tf2.a aVar = tf2.a.f133273a; this.f140247a = (AudioManager) aVar.a().getSystemService("audio"); SensorManager sensorManager = (SensorManager) aVar.a().getSystemService("sensor"); this.f140248b = sensorManager; this.f140251e = sensorManager.getDefaultSensor(8); this.f140249c = (PowerManager) aVar.a().getSystemService("power"); this.f140253g = new CapaHeadsetReceiver(); } public void g() { if (this.f140248b != null && this.f140256j != null) { Log.d("AudioTag", "AudioMode register"); this.f140248b.registerListener(this.f140256j, this.f140251e, 3); if (!this.f140255i) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.HEADSET_PLUG"); tf2.a.f133273a.a().registerReceiver(this.f140253g, intentFilter); this.f140255i = true; } } } public void h(boolean z14) { this.f140254h = z14; } public void i(b bVar) { this.f140252f = bVar; } public final void j() { if (this.f140250d == null) { this.f140250d = this.f140249c.newWakeLock(32, "CapaAudioMode"); } if (!this.f140250d.isHeld()) { this.f140250d.acquire(); } } public final void k() { PowerManager.WakeLock wakeLock = this.f140250d; if (wakeLock != null) { wakeLock.setReferenceCounted(false); this.f140250d.release(); this.f140250d = null; } } public final void l(boolean z14) { if (z14) { this.f140247a.setSpeakerphoneOn(true); this.f140247a.setMode(0); AudioManager audioManager = this.f140247a; audioManager.setStreamVolume(3, audioManager.getStreamVolume(3), 0); return; } this.f140247a.setSpeakerphoneOn(false); if (Build.VERSION.SDK_INT >= 21) { this.f140247a.setMode(3); AudioManager audioManager2 = this.f140247a; audioManager2.setStreamVolume(0, audioManager2.getStreamMaxVolume(0), 0); return; } this.f140247a.setMode(2); AudioManager audioManager3 = this.f140247a; audioManager3.setStreamVolume(0, audioManager3.getStreamMaxVolume(0), 0); } public void m() { if (this.f140248b != null && this.f140256j != null) { Log.d("AudioTag", "AudioMode unregister"); this.f140248b.unregisterListener(this.f140256j); if (this.f140255i) { tf2.a.f133273a.a().unregisterReceiver(this.f140253g); this.f140255i = false; } } } }