Hide logs behind authentication prompt

This commit is contained in:
ajp_anton
2026-07-26 15:15:45 +00:00
parent 6b93492a0e
commit 3bc71cdc61
2 changed files with 43 additions and 4 deletions
@@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
WindowCompat.setDecorFitsSystemWindows(window, true) WindowCompat.setDecorFitsSystemWindows(window, true)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
showLockedOverlay(AppLockStore(this).enabled)
val isNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == val isNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK ==
Configuration.UI_MODE_NIGHT_YES Configuration.UI_MODE_NIGHT_YES
WindowInsetsControllerCompat(window, binding.root).isAppearanceLightNavigationBars = !isNightMode WindowInsetsControllerCompat(window, binding.root).isAppearanceLightNavigationBars = !isNightMode
@@ -84,12 +85,20 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (needsUnlock && AppLockStore(this).enabled) requestUnlock() if (needsUnlock && AppLockStore(this).enabled) {
showLockedOverlay(true)
requestUnlock()
} else {
showLockedOverlay(false)
}
} }
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
if (!isChangingConfigurations) needsUnlock = true if (!isChangingConfigurations) {
needsUnlock = true
if (AppLockStore(this).enabled) showLockedOverlay(true)
}
} }
private fun requestUnlock() { private fun requestUnlock() {
@@ -98,11 +107,18 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
.setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG or Authenticators.DEVICE_CREDENTIAL) .setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG or Authenticators.DEVICE_CREDENTIAL)
.build() .build()
.authenticate(CancellationSignal(), mainExecutor, object : BiometricPrompt.AuthenticationCallback() { .authenticate(CancellationSignal(), mainExecutor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult?) { needsUnlock = false } override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult?) {
needsUnlock = false
showLockedOverlay(false)
}
override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) { finishAndRemoveTask() } override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) { finishAndRemoveTask() }
}) })
} }
private fun showLockedOverlay(visible: Boolean) {
binding.lockOverlay.visibility = if (visible) View.VISIBLE else View.GONE
}
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean {
navigateTo(item.itemId) navigateTo(item.itemId)
if (!permanentSidebar) { if (!permanentSidebar) {
+24 -1
View File
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<se.ajpanton.notificationlog.SafeInsetDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<se.ajpanton.notificationlog.SafeInsetDrawerLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -61,3 +65,22 @@
app:menu="@menu/drawer_menu" /> app:menu="@menu/drawer_menu" />
</se.ajpanton.notificationlog.SafeInsetDrawerLayout> </se.ajpanton.notificationlog.SafeInsetDrawerLayout>
<LinearLayout
android:id="@+id/lock_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/window_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification Log is locked"
android:textAppearance="?attr/textAppearanceHeadline6" />
</LinearLayout>
</FrameLayout>