Fix issue with screen guard while in ongoing call.

This commit is contained in:
Alex Hart
2026-01-23 14:36:32 -04:00
parent 798d4b90c3
commit 19a8ec02cb

View File

@@ -137,14 +137,6 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
lifecycleDisposable.bindTo(this)
if (Build.VERSION.SDK_INT >= 27) {
setShowWhenLocked(true)
setTurnScreenOn(true)
} else {
@Suppress("DEPRECATION")
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
}
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
@@ -398,6 +390,10 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
event.isRemoteVideoOffer
callScreen.setWebRtcCallState(event.state)
if (event.state != previousCallState) {
setTurnScreenOnForCallState(event.state)
}
when (event.state) {
WebRtcViewModel.State.IDLE -> Unit
WebRtcViewModel.State.CALL_PRE_JOIN -> handleCallPreJoin(event)
@@ -1063,6 +1059,33 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
}
}
/**
* Controls lock screen and screen-on behavior based on call state.
* - Show over lock screen: Only for incoming ringing calls, so user can answer.
* - Turn screen on: For any ongoing call state, so screen stays on during call.
*/
private fun setTurnScreenOnForCallState(callState: WebRtcViewModel.State) {
val isIncomingRinging = callState == WebRtcViewModel.State.CALL_INCOMING
val isOngoingCall = callState.inOngoingCall
if (Build.VERSION.SDK_INT >= 27) {
setShowWhenLocked(isIncomingRinging)
setTurnScreenOn(isOngoingCall)
} else {
@Suppress("DEPRECATION")
if (isIncomingRinging) {
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
}
if (isOngoingCall) {
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
}
}
}
private fun enterPipModeIfPossible(): Boolean {
if (isSystemPipEnabledAndAvailable()) {
if (viewModel.canEnterPipMode().value == true) {