Skip to content

Start KeyCachingService when the lock screen is shown, not when created - #2249

Merged
mpretty-cyro merged 2 commits into
devfrom
fix/screen-lock-start-service-foreground
Nov 5, 2026
Merged

mpretty-cyro merged 2 commits into
devfrom
fix/screen-lock-start-service-foreground

Conversation

@mpretty-cyro

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Virtual device: Pixel 6 profile, API 37 (arm64), play flavour, debug
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Crash cluster: BackgroundServiceStartNotAllowedException from ScreenLockActivity.onCreate → startService. The activity can
be created while the app is in the background, where Android 12+ refuses startService.

ScreenLockActivity still binds in onCreate and now starts the service from onResume. The service has to be started, not
just bound: the static KeyCachingService.setMasterSecret helper unbinds straight away, and onDestroy clears the key.

Testing: on an emulator with app lock on, cold-launched, unlocked, and checked KeyCachingService is started and in the foreground (dumpsys activity services). Launching with the screen off didn't reproduce the exception on dev, so the crash itself is unconfirmed.

ScreenLockActivity started KeyCachingService in onCreate. The activity
can be created while the app is in the background, where Android 12+
throws BackgroundServiceStartNotAllowedException, crashing the launch.
Keep binding in onCreate and start the service from onResume, which is
always reached before the user can unlock.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

lgtm

@mpretty-cyro
mpretty-cyro marked this pull request as ready for review November 5, 2026 03:13
@mpretty-cyro
mpretty-cyro merged commit 479cbd5 into dev Nov 5, 2026
8 of 10 checks passed
@mpretty-cyro
mpretty-cyro deleted the fix/screen-lock-start-service-foreground branch November 5, 2026 03:13
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