Skip to content

Biometrics - #1113

Open
uellenberg wants to merge 2 commits into
haiwen:masterfrom
uellenberg-contrib:biometrics
Open

Biometrics#1113
uellenberg wants to merge 2 commits into
haiwen:masterfrom
uellenberg-contrib:biometrics

Conversation

@uellenberg

Copy link
Copy Markdown

This adds a simple biometric lock to the whole application. Once toggled in settings, it requires a fingerprint/password/other authentication method to be used before the app can be opened.

Until it's closed, the app will stay permanently unlocked. This doesn't implement locking when moving to a different window / after a certain period of time, account-specific locks, or wiping auth data when biometrics change.

@uellenberg

Copy link
Copy Markdown
Author

Fixes #1096

@zhwanng I'm interested in getting a security feature like this into the Seadroid app. Please let me know if you have any feedback/concerns.

The biggest issue right now is that MainActivity won't be opened until the user authenticates, so all of the code to register with the server and handle background backups won't be called. I think it's desirable to not force the user to authenticate every time they reboot their device in order for the background backup to work. I'm thinking of moving some of the code out of MainActivity and into the application, that way it always runs.

There were two bugs with TextSwitchPreference:
1. The switch display was consuming click events when they should have
   been given to the parent.
2. The materialSwitch variable became stale, and state updates didn't
   propagate correctly.

onBindViewHolder is always called when the underlying Preference
updates, so we can fix these two issues in in. Afterwards, state should
always be in sync.
This adds a simple biometric lock to the whole application. Once toggled
in settings, it requires a fingerprint/password/other authentication
method to be used before the app can be opened.

Until it's closed, the app will stay permanently unlocked. This doesn't
implement locking when moving to a different window / after a certain
period of time, account-specific locks, or wiping auth data when
biometrics change.
@uellenberg

Copy link
Copy Markdown
Author

@zhwanng Rebased with the latest changes.

jvenuto80 added a commit to jvenuto80/seadroid that referenced this pull request Mar 27, 2026
Add an app lock feature that uses AndroidX BiometricPrompt with
DEVICE_CREDENTIAL fallback, supporting fingerprint, face, PIN, and
pattern authentication — all managed by the OS with zero custom UI.

Features:
- Toggle in Settings > Security to enable/disable app lock
- Configurable lock timeout (immediately, 1/5/15/30 min)
- Lock on cold start and when returning from background
- ProcessLifecycleOwner-based background detection
- Background services (backup, sync) are NOT blocked
- Splash screen backdrop during authentication

Architecture:
- AppLockManager: centralized lock state + timeout logic
- LockedActivity: shows BiometricPrompt over splash screen
- ActivityMonitor: gates all activities when locked
- AppProcessLifeObserver: timestamps background/foreground

Fixes haiwen#1096

Inspired by PR haiwen#1113 by @uellenberg. Key improvements:
- Lock timeout support (re-lock after configurable period)
- Background services continue without authentication
- Stable biometric library (1.1.0 vs alpha)
- ProcessLifecycleOwner for reliable foreground detection
jvenuto80 added a commit to jvenuto80/seadroid that referenced this pull request Mar 27, 2026
Add an app-wide lock gate using AndroidX BiometricPrompt that supports
fingerprint, face, and device PIN/pattern/password authentication.

Key design decisions:
- Dedicated AppLockManager singleton manages lock state and timeout logic
- ActivityMonitor intercepts onActivityCreated and onActivityResumed to
  redirect to LockedActivity when locked
- AppProcessLifeObserver tracks background/foreground transitions for
  timeout-based re-locking
- Per-account settings via encryptSignature-scoped SharedPreferences
- Background services (backup, sync) are NOT blocked -- only UI access
  requires authentication
- TextSwitchPreference forces MaterialSwitch.setChecked(isChecked()) in
  onBindViewHolder to work around SwitchPreferenceCompat not reliably
  propagating state to MaterialSwitch in custom layouts

New files:
- AppLockManager.java -- centralized lock state and timeout logic
- LockedActivity.java -- full-screen BiometricPrompt gate with splash backdrop

Modified files:
- ActivityMonitor -- redirect to lock screen on create/resume
- AppProcessLifeObserver -- record background timestamp, check on foreground
- SeadroidApplication -- call lockIfEnabled() on cold start
- SplashActivity -- early return when locked to prevent duplicate navigation
- TabSettings2Fragment -- biometric switch init, sync, and timeout visibility
- TextSwitchPreference -- fix MaterialSwitch state propagation
- Settings -- BIOMETRIC_LOCK_SWITCH and LOCK_TIMEOUT per-account LiveData
- prefs_settings_2.xml -- TextSwitchPreference and ListPreference for timeout
- strings.xml, donottranslate_prefs.xml -- new string resources

Resolves haiwen#1096
Inspired by PR haiwen#1113 by uellenberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant