Skip to content

Fix: WakeLock finalized while still held#101

Open
JulianAssmann wants to merge 1 commit intomasterfrom
fix/wakelock-finalized-while-held
Open

Fix: WakeLock finalized while still held#101
JulianAssmann wants to merge 1 commit intomasterfrom
fix/wakelock-finalized-while-held

Conversation

@JulianAssmann
Copy link
Owner

Fixes #35

Summary

  • Before re-acquiring the WakeLock (and WifiLock) in startService(), any existing held lock is now released first. This prevents orphaned lock objects from being GC'd while still held, which caused the WakeLock finalized while still held logcat error.
  • onStartCommand now handles null intents (delivered by Android on START_STICKY service restarts after a system kill) by calling startService(), ensuring locks are properly re-acquired after the OS kills and restarts the service.

Test plan

  • Run on a physical Android device (emulators don't reliably surface WakeLock issues)
  • Call enableBackgroundExecution() twice without disabling — verify no WakeLock finalized while still held in logcat
  • Call enableBackgroundExecution() then disableBackgroundExecution() — verify no error appears a few seconds later
  • Force-kill the app process with adb shell am kill <package> while service is running — verify service restarts and continues functioning

Release any existing WakeLock/WifiLock before re-acquiring in startService()
to prevent orphaned locks being GC'd while still held. Also handle null
intents in onStartCommand (OS sticky restart) by calling startService()
so locks are properly re-acquired after a system kill.
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.

Error : WakeLock finalized while still held

1 participant