Revert "Disable voice note proximity sensor when using bluetooth headset. (#2448)"

This reverts commit 9c7a5e3cc8.
This commit is contained in:
Cody Henthorne
2022-06-28 17:10:33 -04:00
parent ba6e1b5dd5
commit 1129ca28fb
4 changed files with 1 additions and 45 deletions

View File

@@ -14,8 +14,6 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.twilio.audioswitch.AudioDevice
import com.twilio.audioswitch.AudioSwitch
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.util.ServiceUtil
import java.util.concurrent.TimeUnit
@@ -42,7 +40,6 @@ class VoiceNoteProximityWakeLockManager(
private val mediaControllerCallback = MediaControllerCallback()
private val hardwareSensorEventListener = HardwareSensorEventListener()
private val audioSwitch: AudioSwitch? = if (Build.VERSION.SDK_INT < 31) AudioSwitch(activity.applicationContext) else null
private var startTime: Long = -1
@@ -53,25 +50,12 @@ class VoiceNoteProximityWakeLockManager(
}
override fun onResume(owner: LifecycleOwner) {
if (audioSwitch == null) {
startListening()
} else {
audioSwitch.start { _, selectedAudioDevice -> onFocusedAudioDeviceChanged(selectedAudioDevice) }
}
}
override fun onPause(owner: LifecycleOwner) {
audioSwitch?.stop()
stopListening()
}
private fun startListening() {
if (proximitySensor != null) {
mediaController.registerCallback(mediaControllerCallback)
}
}
private fun stopListening() {
override fun onPause(owner: LifecycleOwner) {
if (proximitySensor != null) {
unregisterCallbacksAndRelease()
}
@@ -84,19 +68,10 @@ class VoiceNoteProximityWakeLockManager(
fun unregisterFromLifecycle() {
if (proximitySensor != null) {
stopListening()
activity.lifecycle.removeObserver(this)
}
}
private fun onFocusedAudioDeviceChanged(audioDevice: AudioDevice?) {
if (audioDevice is AudioDevice.BluetoothHeadset) {
stopListening()
} else {
startListening()
}
}
private fun isActivityResumed() = activity.lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)
private fun isPlayerActive() = mediaController.playbackState.state == PlaybackStateCompat.STATE_BUFFERING ||