Prevent proximity sensor to turn screen off while on incoming/outgoing call fragments

This commit is contained in:
Sylvain Berfini 2022-11-18 11:08:09 +01:00
parent 0895db1a62
commit 483443fd60
3 changed files with 29 additions and 1 deletions

View file

@ -81,4 +81,15 @@ class IncomingCallFragment : GenericFragment<VoipCallIncomingFragmentBinding>()
coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface
}
}
// We don't want the proximity sensor to turn screen OFF in this fragment
override fun onResume() {
super.onResume()
controlsViewModel.forceDisableProximitySensor.value = true
}
override fun onPause() {
controlsViewModel.forceDisableProximitySensor.value = false
super.onPause()
}
}

View file

@ -83,4 +83,15 @@ class OutgoingCallFragment : GenericVideoPreviewFragment<VoipCallOutgoingFragmen
}
}
}
// We don't want the proximity sensor to turn screen OFF in this fragment
override fun onResume() {
super.onResume()
controlsViewModel.forceDisableProximitySensor.value = true
}
override fun onPause() {
controlsViewModel.forceDisableProximitySensor.value = false
super.onPause()
}
}

View file

@ -75,6 +75,8 @@ class ControlsViewModel : ViewModel() {
val proximitySensorEnabled = MediatorLiveData<Boolean>()
val forceDisableProximitySensor = MutableLiveData<Boolean>()
val showTakeSnapshotButton = MutableLiveData<Boolean>()
val goToConferenceParticipantsListEvent: MutableLiveData<Event<Boolean>> by lazy {
@ -199,6 +201,7 @@ class ControlsViewModel : ViewModel() {
extraButtonsMenuTranslateY.value = AppUtils.getDimension(R.dimen.voip_call_extra_buttons_translate_y)
audioRoutesMenuTranslateY.value = AppUtils.getDimension(R.dimen.voip_audio_routes_menu_translate_y)
audioRoutesSelected.value = false
forceDisableProximitySensor.value = false
nonEarpieceOutputAudioDevice.value = coreContext.core.outputAudioDevice?.type != AudioDevice.Type.Earpiece
proximitySensorEnabled.value = shouldProximitySensorBeEnabled()
@ -208,6 +211,9 @@ class ControlsViewModel : ViewModel() {
proximitySensorEnabled.addSource(nonEarpieceOutputAudioDevice) {
proximitySensorEnabled.value = shouldProximitySensorBeEnabled()
}
proximitySensorEnabled.addSource(forceDisableProximitySensor) {
proximitySensorEnabled.value = shouldProximitySensorBeEnabled()
}
updateUI()
@ -448,6 +454,6 @@ class ControlsViewModel : ViewModel() {
}
private fun shouldProximitySensorBeEnabled(): Boolean {
return !(isVideoEnabled.value ?: false) && !(nonEarpieceOutputAudioDevice.value ?: false)
return forceDisableProximitySensor.value == false && !(isVideoEnabled.value ?: false) && !(nonEarpieceOutputAudioDevice.value ?: false)
}
}