Skip to content

Commit

Permalink
fix: keep screen on during ongoing call [WPB-9033] (#3209)
Browse files Browse the repository at this point in the history
Co-authored-by: Yamil Medina <[email protected]>
  • Loading branch information
saleniuk and yamilmedina authored Jul 22, 2024
1 parent 3321e26 commit f6d43e1
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions app/src/main/kotlin/com/wire/android/ui/calling/CallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CallActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setUpScreenShootPreventionFlag()
setUpScreenshotPreventionFlag()
setUpCallingFlags()

WindowCompat.setDecorFitsSystemWindows(window, false)
Expand All @@ -83,9 +83,6 @@ class CallActivity : AppCompatActivity() {
}
}

setUpCallingFlags()
setUpScreenShootPreventionFlag()

appLogger.i("$TAG Initializing proximity sensor..")
proximitySensorManager.initialize()

Expand Down Expand Up @@ -147,6 +144,11 @@ class CallActivity : AppCompatActivity() {
proximitySensorManager.unRegisterListener()
}

override fun onDestroy() {
cleanUpCallingFlags()
super.onDestroy()
}

companion object {
private const val TAG = "CallActivity"
const val EXTRA_CONVERSATION_ID = "conversation_id"
Expand All @@ -155,19 +157,41 @@ class CallActivity : AppCompatActivity() {
}
}

fun CallActivity.setUpCallingFlags() {
private fun Activity.setUpCallingFlags() {
window.addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true)
setTurnScreenOn(true)
} else {
window.addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
}

private fun Activity.cleanUpCallingFlags() {
window.clearFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(false)
setTurnScreenOn(false)
} else {
window.clearFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
}

fun CallActivity.setUpScreenShootPreventionFlag() {
fun CallActivity.setUpScreenshotPreventionFlag() {
lifecycleScope.launch {
if (callActivityViewModel.isScreenshotCensoringConfigEnabled().await()) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
Expand Down

0 comments on commit f6d43e1

Please sign in to comment.