mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Added back secure flag to prevent screenshots
This commit is contained in:
parent
10b7545807
commit
82071985bc
2 changed files with 47 additions and 7 deletions
|
|
@ -138,13 +138,6 @@ class CorePreferences @UiThread constructor(private val context: Context) {
|
|||
config.setInt("app", "dark_mode", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var themeMainColor: String
|
||||
get() = config.getString("ui", "theme_main_color", "orange")!!
|
||||
set(value) {
|
||||
config.setString("ui", "theme_main_color", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var linphoneConfigurationVersion: Int
|
||||
get() = config.getInt("app", "config_version", 50200)
|
||||
|
|
@ -152,6 +145,21 @@ class CorePreferences @UiThread constructor(private val context: Context) {
|
|||
config.setInt("app", "config_version", value)
|
||||
}
|
||||
|
||||
/** Allows to make screenshots */
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var enableSecureMode: Boolean
|
||||
get() = config.getBool("ui", "enable_secure_mode", true)
|
||||
set(value) {
|
||||
config.setBool("ui", "enable_secure_mode", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var themeMainColor: String
|
||||
get() = config.getString("ui", "theme_main_color", "orange")!!
|
||||
set(value) {
|
||||
config.setString("ui", "theme_main_color", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread
|
||||
val darkModeAllowed: Boolean
|
||||
get() = config.getBool("ui", "dark_mode_allowed", true)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import android.content.res.Configuration
|
|||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
@ -68,6 +69,8 @@ open class GenericActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||
|
||||
enableWindowSecureMode(corePreferences.enableSecureMode)
|
||||
|
||||
val nightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
val darkModeEnabled = corePreferences.darkMode
|
||||
Log.i(
|
||||
|
|
@ -209,4 +212,33 @@ open class GenericActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableWindowSecureMode(enable: Boolean) {
|
||||
val flags: Int = window.attributes.flags
|
||||
if ((enable && flags and WindowManager.LayoutParams.FLAG_SECURE != 0) ||
|
||||
(!enable && flags and WindowManager.LayoutParams.FLAG_SECURE == 0)
|
||||
) {
|
||||
Log.d(
|
||||
"$TAG Secure flag is already ${if (enable) "enabled" else "disabled"}, skipping..."
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
Log.i("$TAG Secure flag added to window")
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
} else {
|
||||
Log.w("$TAG Secure flag cleared from window")
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
|
||||
if (window.decorView.isAttachedToWindow) {
|
||||
Log.d("$TAG Redrawing window decorView to apply flag")
|
||||
try {
|
||||
windowManager.updateViewLayout(window.decorView, window.attributes)
|
||||
} catch (ise: IllegalStateException) {
|
||||
Log.e("$TAG Failed to update window's decorView layout: $ise")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue