Merge pull request #1585 from nextcloud/bugfix/noid/showKeyguardForToggleChat

enable keyguard for toggle chat
This commit is contained in:
Marcel Hibbe 2021-09-17 15:31:03 +02:00 committed by GitHub
commit caa8915130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,7 +22,9 @@
package com.nextcloud.talk.activities
import android.app.KeyguardManager
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.Window
@ -56,11 +58,10 @@ class MagicCallActivity : BaseActivity() {
setTheme(R.style.CallTheme)
requestWindowFeature(Window.FEATURE_NO_TITLE)
dismissKeyguard()
window.addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN or
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
)
window.decorView.systemUiVisibility = systemUiVisibility
@ -99,6 +100,7 @@ class MagicCallActivity : BaseActivity() {
}
fun showChat() {
enableKeyguard()
binding.chatControllerView.visibility = View.VISIBLE
binding.controllerContainer.visibility = View.GONE
chatController.wasDetached = false
@ -116,6 +118,33 @@ class MagicCallActivity : BaseActivity() {
eventBus.post(ConfigurationChangeEvent())
}
private fun dismissKeyguard() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true)
setTurnScreenOn(true)
val keyguardManager = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard(this, null)
} else {
window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
}
private fun enableKeyguard() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(false)
} else {
window.clearFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
}
companion object {
private val TAG = "MagicCallActivity"