Disable voice note proximity sensor when using bluetooth headset. (#2448)
This commit is contained in:
parent
2022dae37a
commit
9c7a5e3cc8
4 changed files with 42 additions and 1 deletions
|
@ -434,6 +434,8 @@ dependencies {
|
|||
implementation libs.conscrypt.android
|
||||
implementation libs.signal.aesgcmprovider
|
||||
|
||||
implementation libs.audioswitch
|
||||
|
||||
implementation project(':libsignal-service')
|
||||
implementation project(':paging')
|
||||
implementation project(':core-util')
|
||||
|
|
|
@ -14,6 +14,8 @@ 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
|
||||
|
@ -40,6 +42,7 @@ 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
|
||||
|
||||
|
@ -50,12 +53,25 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
private fun stopListening() {
|
||||
if (proximitySensor != null) {
|
||||
unregisterCallbacksAndRelease()
|
||||
}
|
||||
|
@ -68,10 +84,19 @@ 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 ||
|
||||
|
|
|
@ -113,6 +113,7 @@ dependencyResolutionManagement {
|
|||
alias('lottie').to('com.airbnb.android:lottie:3.6.0')
|
||||
alias('stickyheadergrid').to('com.codewaves.stickyheadergrid:stickyheadergrid:0.9.4')
|
||||
alias('dnsjava').to('dnsjava:dnsjava:2.1.9')
|
||||
alias('audioswitch').to('com.twilio:audioswitch:1.1.4')
|
||||
|
||||
// Mp4Parser
|
||||
alias('mp4parser-isoparser').to('org.mp4parser', 'isoparser').versionRef('mp4parser')
|
||||
|
|
|
@ -59,6 +59,14 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
|
|||
<sha256 value="2efcab81ef91b211bacd206eaacd995a51f633a2e96b57a8fc00144c5f9c56b3" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="androidx.annotation" name="annotation" version="1.3.0">
|
||||
<artifact name="annotation-1.3.0.jar">
|
||||
<sha256 value="97dc45afefe3a1e421da42b8b6e9f90491477c45fc6178203e3a5e8a05ee8553" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
<artifact name="annotation-1.3.0.module">
|
||||
<sha256 value="9516c2ae44284ea0bd3d0eade0ee638879b708cbe31e3af92ba96c300604ebc3" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="androidx.annotation" name="annotation-experimental" version="1.0.0">
|
||||
<artifact name="annotation-experimental-1.0.0.aar">
|
||||
<sha256 value="b219d2b568e7e4ba534e09f8c2fd242343df6ccbdfbbe938846f5d740e6b0b11" origin="Generated by Gradle"/>
|
||||
|
@ -2127,6 +2135,11 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
|
|||
<sha256 value="4c56697dd1ad64b8066535c61f961a6d901e7ae5d97ae27084ba40ad620349b6" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.twilio" name="audioswitch" version="1.1.4">
|
||||
<artifact name="audioswitch-1.1.4.aar">
|
||||
<sha256 value="881dd2836afa59a2dbb2ee3a847e3675e9c9f013cb5c79d872d90ea28598077c" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.uber.rxdogtag2" name="rxdogtag" version="2.0.1">
|
||||
<artifact name="rxdogtag-2.0.1.jar">
|
||||
<sha256 value="0e09c60f88d446ff209c17a0a36503b49fdec475225d4381ae4fe9ed83fb912d" origin="Generated by Gradle"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue