Skip to content

Fix crash when notification button tapped after service restart#26

Merged
Staacks merged 1 commit intoStaacks:mainfrom
blackthunder0812:fix/wakelock-uninitialized-crash
Apr 18, 2026
Merged

Fix crash when notification button tapped after service restart#26
Staacks merged 1 commit intoStaacks:mainfrom
blackthunder0812:fix/wakelock-uninitialized-crash

Conversation

@blackthunder0812
Copy link
Copy Markdown

@blackthunder0812 blackthunder0812 commented Mar 28, 2026

Summary

  • pendingActionsWakeLock was initialized in onDeviceAppeared(), but Android can call onStartCommand() before onDeviceAppeared() when the service is killed and restarted
  • Tapping a notification button in this state triggered cancelPendingActionSteps()UninitializedPropertyAccessException → crash
  • Fixed by moving the wake lock initialization to onCreate(), which is always called before onStartCommand()

Root cause

kotlin.UninitializedPropertyAccessException: lateinit property pendingActionsWakeLock has not been initialized
    at AlphaRemoteService.cancelPendingActionSteps(AlphaRemoteService.kt:300)
    at AlphaRemoteService.startCameraAction(AlphaRemoteService.kt:320)
    at AlphaRemoteService.onStartCommand(AlphaRemoteService.kt:236)

Verified on my phone, Oppo A53, Android 12, I think this will also solve #25

🤖 Generated with Claude Code

Move pendingActionsWakeLock initialization from onDeviceAppeared() to
onCreate() so it is always initialized before onStartCommand() is called.

Previously, if the service was killed and restarted by Android, a
notification button tap would trigger onStartCommand() before
onDeviceAppeared(), causing an UninitializedPropertyAccessException in
cancelPendingActionSteps().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Staacks
Copy link
Copy Markdown
Owner

Staacks commented Mar 29, 2026

Thanks a lot, looks like a clean an simple solution. I wanted to look into the app (and this issue) soon anyway and will do some testing. The companion device service is a mess across different Android versions with very different behaviors in calling the various callback, so I want to test on a few real devices before a release - but I do not see an issue with this PR. When I am back from my family vacation I will look into it.

@Staacks Staacks merged commit 1172b67 into Staacks:main Apr 18, 2026
@Staacks
Copy link
Copy Markdown
Owner

Staacks commented Apr 18, 2026

Finally did some testing and not surprisingly it works perfectly. Since I have not seen the original bug on any of my devices I cannot say for sure that it fixes it, but I would be surprised if it didn't.

Thanks again. I plan to implement one or two other things from my todo list in the next days (which usually turns our as weeks) and then make a release.

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.

3 participants