Skip to content

feat: auto lock - #95

Merged
OffRange merged 35 commits into
v2from
feat/auto-lock
Sep 6, 2026
Merged

OffRange merged 35 commits into
v2from
feat/auto-lock

Conversation

@OffRange

@OffRange OffRange commented Sep 6, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It makes broad, security-sensitive changes to session/ARK lifetime handling and process-lifecycle locking behavior that warrant careful human validation.

Pull request overview

Implements an auto-lock mechanism that ends the security session when the app backgrounds (configurable via Settings), while introducing a “system handoff” concept to keep the session alive across intentional round-trips to OS/system screens (settings pickers, NFC settings, Autofill screens, etc.). This also refactors session ARK access to a scoped API (withArk) to make in-memory key wiping safe across suspending operations.

Changes:

  • Add persisted auto-lock timeout (LockInfo) and a SessionLockObserver wired to process lifecycle + screen-off to end sessions on background/timeout.
  • Replace direct ARK reads (session.ark) with Session.withArk(...) / withArkOr(...), backed by ArkHolder to defer zeroing until in-flight crypto completes.
  • Add “handoff-aware” launchers/wrappers for system screens so intentional OS navigation doesn’t immediately trigger auto-lock; update navigation to use an overlay-based gate.
File summaries
File Description
gradle/libs.versions.toml Adds version-catalog entry for androidx.lifecycle:lifecycle-process.
feature/vault/src/test/kotlin/de/davis/keygo/feature/vault/domain/usecase/MoveItemsToVaultUseCaseTest.kt Updates tests for new Session ARK access (currentArk).
feature/vault/src/main/kotlin/de/davis/keygo/feature/vault/domain/usecase/CreateVaultUseCase.kt Wraps ARK usage with withArkOr to avoid use-after-wipe.
feature/totp/src/main/kotlin/de/davis/keygo/feature/totp/presentation/component/QRScanner.kt Uses handoff-aware system-screen starter for permission settings navigation.
feature/settings/src/test/kotlin/de/davis/keygo/feature/settings/presentation/SettingsViewModelTest.kt Adds tests for auto-lock timeout state + persistence.
feature/settings/src/test/kotlin/de/davis/keygo/feature/settings/presentation/component/SettingsDslTest.kt Adds tests for new picker DSL entry behavior.
feature/settings/src/test/kotlin/de/davis/keygo/feature/settings/presentation/changepassword/ChangePasswordViewModelTest.kt Adds tests ensuring session end clears sensitive fields and UI state.
feature/settings/src/main/res/values/strings.xml Adds strings/plurals for auto-lock UI and a cancel label.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/SettingsViewModel.kt Observes/persists lock timeout via LockInfoRepository.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/SettingsUiState.kt Adds lockTimeout to Settings UI state.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/SettingsUiEvent.kt Adds SetAutoLockTimeout UI event.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/SettingsScreen.kt Uses handoff-aware launcher for OS autofill selection intent.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/SettingsContent.kt Adds auto-lock timeout picker and timeout-to-label mapping.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/component/SettingsList.kt Implements picker row + dialog UI.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/component/SettingsEntry.kt Adds SettingsEntry.Picker model.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/component/SettingsDsl.kt Adds DSL builder for picker entries.
feature/settings/src/main/kotlin/de/davis/keygo/feature/settings/presentation/changepassword/ChangePasswordViewModel.kt Clears sensitive fields when the session ends.
feature/onboarding/src/main/kotlin/de/davis/keygo/feature/onboarding/presentation/OnboardingScreen.kt Uses handoff-aware launcher for OS autofill picker.
feature/item/view/src/main/kotlin/de/davis/keygo/feature/item/view/domain/WebsiteHandler.kt Minor formatting-only adjustment.
feature/item/view/src/main/kotlin/de/davis/keygo/feature/item/view/data/WebsiteHandlerImpl.kt Wraps browser launch in system handoff to avoid immediate lock.
feature/credit-card/src/main/kotlin/de/davis/keygo/feature/credit_card/presentation/NfcInfoCard.kt Uses handoff-aware starter for NFC settings intent.
feature/credit-card/build.gradle.kts Adds dependency on :core:security for handoff utilities.
feature/backup/src/test/kotlin/de/davis/keygo/feature/backup/domain/usecase/ImportBackupUseCaseTest.kt Updates tests for new ARK access (currentArk).
feature/backup/src/test/kotlin/de/davis/keygo/feature/backup/domain/usecase/FinishExportWizardUseCaseTest.kt Updates tests for new ARK access (currentArk).
feature/backup/src/test/kotlin/de/davis/keygo/feature/backup/domain/usecase/ExportBackupUseCaseTest.kt Updates tests for new ARK access (currentArk) and escrow provisioning.
feature/backup/src/test/kotlin/de/davis/keygo/feature/backup/domain/BackupArkUnlockerTest.kt Updates tests to use withArk access pattern.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/presentation/import/ImportFilePicker.kt Uses handoff-aware launcher + failure reporting for document picker.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/presentation/export/ExportWizardScreen.kt Uses handoff-aware launcher + failure reporting for folder picker.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/domain/usecase/ImportBackupUseCase.kt Uses isActive/withArkOr and factors JSON import helper with failure mapping.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/domain/usecase/FinishExportWizardUseCase.kt Uses withArkOr and maps crypto failures via Result helpers.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/domain/BackupEscrowReconciler.kt Moves reconcile coroutine to injected app scope with IO dispatcher.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/domain/BackupArkUnlocker.kt Avoids raw ARK access; prefers live session via withArk when available.
feature/backup/src/main/kotlin/de/davis/keygo/feature/backup/data/BackupSession.kt Implements withArk for recovered-backup ARK handling.
feature/autofill/src/main/kotlin/de/davis/keygo/feature/autofill/presentation/activity/AutofillActivity.kt Uses handoff-aware launcher for SMS consent prompt.
feature/autofill/src/main/kotlin/de/davis/keygo/feature/autofill/data/repository/ChromeAutofillRepositoryImpl.kt Wraps Chrome settings navigation in SystemHandoff.
core/util/src/main/kotlin/de/davis/keygo/core/util/di/CoreUtilModule.kt Introduces app-wide CoroutineScope provider for long-lived work.
core/util/src/main/kotlin/de/davis/keygo/core/util/di/annotation/AppScopeQualifier.kt Adds qualifier annotation for app scope injection.
core/security/src/testFixtures/kotlin/de/davis/keygo/core/security/time/FakeElapsedTimeProvider.kt Adds fake elapsed-time provider for deterministic clock tests.
core/security/src/testFixtures/kotlin/de/davis/keygo/core/security/FakeLockInfoRepository.kt Adds test fixture repository for lock timeout persistence/observation.
core/security/src/testFixtures/kotlin/de/davis/keygo/core/security/crypto/FakeSession.kt Reworks session fake to use ArkHolder semantics and expose currentArk.
core/security/src/test/kotlin/de/davis/keygo/core/security/presentation/HandoffLauncherTest.kt Adds tests for handoff-aware launcher behavior.
core/security/src/test/kotlin/de/davis/keygo/core/security/domain/SystemHandoffTest.kt Adds tests for SystemHandoff round-trip semantics.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/time/SessionClockImplTest.kt Adds tests for clock expiration behavior.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/SystemHandoffImplTest.kt Adds tests for atomic pending-count handoff implementation.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/SessionLockObserverTest.kt Adds Robolectric tests for lifecycle-based auto-lock and handoff grace.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/SessionImplTest.kt Updates tests for withArk API and wipe semantics.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/SessionArkLifetimeTest.kt Adds tests ensuring ARK lifetime safety across suspending blocks.
core/security/src/test/kotlin/de/davis/keygo/core/security/data/mapper/LockInfoMapperTest.kt Adds tests for proto/domain timeout round-trip + downgrade safety.
core/security/src/test/kotlin/de/davis/keygo/core/security/crypto/CryptographicScopeImplTest.kt Updates tests for new ARK access (currentArk).
core/security/src/main/proto/lock_info.proto Adds proto schema for persisting auto-lock timeout.
core/security/src/main/kotlin/de/davis/keygo/core/security/presentation/HandoffLauncher.kt Adds handoff-aware ActivityResult launcher wrappers.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/time/SessionClock.kt Adds session clock interface for inactivity tracking.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/time/ElapsedTimeProvider.kt Adds elapsed-time provider abstraction.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/SystemHandoff.kt Adds handoff contract + forRoundTrip helper returning Result.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/Session.kt Replaces raw ARK exposure with withArk and withArkOr helpers.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/repository/LockInfoRepository.kt Adds repository API for lock timeout persistence.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/model/LockInfo.kt Adds domain model for auto-lock timeout options.
core/security/src/main/kotlin/de/davis/keygo/core/security/domain/ArkHolder.kt Adds reader-counted ARK holder with deferred zeroing.
core/security/src/main/kotlin/de/davis/keygo/core/security/di/CoreSecurityModule.kt Provides proto DataStore for lock info.
core/security/src/main/kotlin/de/davis/keygo/core/security/di/annotation/LockInfoQualifier.kt Adds qualifier annotation for lock-info DataStore injection.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/time/SessionClockImpl.kt Implements inactivity clock using elapsed realtime provider.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/time/ElapsedTimeProviderImpl.kt Implements elapsed-time provider via SystemClock.elapsedRealtime().
core/security/src/main/kotlin/de/davis/keygo/core/security/data/SystemHandoffImpl.kt Implements pending handoff counting via AtomicInteger.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/SessionLockObserver.kt Implements process lifecycle auto-lock with timeout + screen-off handling.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/SessionImpl.kt Refactors session to use ArkHolder and new withArk API.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/repository/LockInfoRepositoryImpl.kt Implements lock-info persistence via DataStore + proto mapping.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/mapper/LockInfoMapper.kt Maps proto lock timeout values to/from domain model.
core/security/src/main/kotlin/de/davis/keygo/core/security/data/crypto/CryptographicScopeProviderImpl.kt Adapts vault key unwrap to withArkOr and mapFailure.
core/security/build.gradle.kts Enables protobuf plugin, adds lifecycle-process + Robolectric test dependency.
core/identity/src/test/kotlin/de/davis/keygo/core/identity/domain/usecase/UnlockWithPasswordUseCaseTest.kt Updates assertions for new fake session ARK access (currentArk).
core/identity/src/test/kotlin/de/davis/keygo/core/identity/domain/usecase/CreateAccessUseCaseTest.kt Updates assertions for new fake session ARK access (currentArk).
core/identity/src/main/kotlin/de/davis/keygo/core/identity/presentation/BiometricEnrollmentAdapterImpl.kt Uses withArkOr to wrap session access in Result flow.
app/src/test/kotlin/de/davis/keygo/app/presentation/navigation/AppNavigatorTest.kt Updates navigation model tests for overlay + locking semantics.
app/src/main/kotlin/de/davis/keygo/app/presentation/navigation/EntryProvider.kt Switches import/onboarding flow completion to overlay clearing/pushing.
app/src/main/kotlin/de/davis/keygo/app/presentation/navigation/AppNavigator.kt Refactors “launch flow” into overlay stack and adds lock/unlock gating logic.
app/src/main/kotlin/de/davis/keygo/app/presentation/navigation/AppNavigationState.kt Renames launch stack to overlay stack and updates entry decoration logic.
app/src/main/kotlin/de/davis/keygo/app/presentation/MainActivity.kt Locks app (gate overlay) when session ends instead of replacing launch flow.
app/src/main/kotlin/de/davis/keygo/app/presentation/AppViewModel.kt Updates session-state comment to reflect new gating approach.
Review details
  • Files reviewed: 77/78 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread core/security/src/main/proto/lock_info.proto
@OffRange
OffRange merged commit e1c15b3 into v2 Sep 6, 2026
9 checks passed
@OffRange
OffRange deleted the feat/auto-lock branch September 6, 2026 17:52
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.

2 participants