Fixed proximity sensor disabled after app has been put in background and then resumed by clicking on the call notification

This commit is contained in:
Sylvain Berfini 2026-02-23 10:38:30 +01:00
parent 37200ecf8f
commit 70183f76fc
2 changed files with 14 additions and 1 deletions

View file

@ -384,6 +384,7 @@ class CallActivity : GenericActivity() {
coreContext.postOnCoreThread { coreContext.postOnCoreThread {
coreContext.notificationsManager.showInCallForegroundServiceNotificationIfNeeded() coreContext.notificationsManager.showInCallForegroundServiceNotificationIfNeeded()
callViewModel.updateProximitySensor()
} }
} }

View file

@ -1553,27 +1553,39 @@ class CurrentCallViewModel
} }
@WorkerThread @WorkerThread
private fun updateProximitySensor() { fun updateProximitySensor() {
if (::currentCall.isInitialized) { if (::currentCall.isInitialized) {
val callState = currentCall.state val callState = currentCall.state
Log.i("$TAG Call is in state [$callState], enabling/disabling proximity sensor if needed")
if (LinphoneUtils.isCallIncoming(callState)) { if (LinphoneUtils.isCallIncoming(callState)) {
Log.i("$TAG Call is incoming, disabling proximity sensor")
proximitySensorEnabled.postValue(false) proximitySensorEnabled.postValue(false)
} else if (LinphoneUtils.isCallOutgoing(callState)) { } else if (LinphoneUtils.isCallOutgoing(callState)) {
val videoEnabled = currentCall.params.isVideoEnabled val videoEnabled = currentCall.params.isVideoEnabled
if (videoEnabled) {
Log.i("$TAG Call is outgoing and video is enabled, disabling proximity sensor")
} else {
Log.i("$TAG Call is outgoing and video is disabled, enabling proximity sensor")
}
proximitySensorEnabled.postValue(!videoEnabled) proximitySensorEnabled.postValue(!videoEnabled)
} else { } else {
if (isSendingVideo.value == true || isReceivingVideo.value == true) { if (isSendingVideo.value == true || isReceivingVideo.value == true) {
Log.i("$TAG Video is being sent and/or received, disabling proximity sensor")
proximitySensorEnabled.postValue(false) proximitySensorEnabled.postValue(false)
} else { } else {
val outputAudioDevice = currentCall.outputAudioDevice ?: coreContext.core.outputAudioDevice val outputAudioDevice = currentCall.outputAudioDevice ?: coreContext.core.outputAudioDevice
if (outputAudioDevice != null && outputAudioDevice.type == AudioDevice.Type.Earpiece) { if (outputAudioDevice != null && outputAudioDevice.type == AudioDevice.Type.Earpiece) {
Log.i("$TAG Audio device is earpiece, enabling proximity sensor")
proximitySensorEnabled.postValue(true) proximitySensorEnabled.postValue(true)
} else { } else {
Log.i("$TAG Audio device is [${outputAudioDevice?.type}], disabling proximity sensor")
proximitySensorEnabled.postValue(false) proximitySensorEnabled.postValue(false)
} }
} }
} }
} else { } else {
Log.w("$TAG No current call, disabling proximity sensor")
proximitySensorEnabled.postValue(false) proximitySensorEnabled.postValue(false)
} }
} }