Skip to content

Rebind the notification listener after an update or a reboot - #773

Open
majkinetor wants to merge 3 commits into
metabrainz:mainfrom
majkinetor:fix-listener-rebind
Open

majkinetor wants to merge 3 commits into
metabrainz:mainfrom
majkinetor:fix-listener-rebind

Conversation

@majkinetor

@majkinetor majkinetor commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #772.

After an app update, and sometimes after a reboot, Android unbinds ListenSubmissionService as a notification listener, and some phones (Honor/MagicOS, MIUI and others) don't bind it again until notification access is toggled. The service may still be running, so isServiceRunning() says all is well while no listens are submitted.

Changes

  • ListenSubmissionService: a connected flag, set in onListenerConnected and cleared in onListenerDisconnected, tracks whether the listener is actually bound. rebind() calls requestRebind() (API 24+); forceRebind() disables and re-enables the component with DONT_KILL_APP, which is what the toggle does. onListenerDisconnected() now asks for a rebind, as Android's docs suggest.
  • App.startListenService(): when access is granted but the listener isn't bound, requests a rebind, and falls back to forceRebind() if it still isn't bound 10 s later.
  • ListenServiceRestarter (new): a receiver for BOOT_COMPLETED and MY_PACKAGE_REPLACED that runs the same check, so listening comes back without opening the app.
  • AndroidManifest.xml: the receiver and RECEIVE_BOOT_COMPLETED.

Tested

On a Honor Magic V5 (MagicOS), with a release build:

  • Opening the app after a reboot brings listening back without touching notification access.
  • After a reboot without opening the app, listens are submitted as soon as music plays, provided the app is allowed to auto-launch (Settings → Apps → App launch). Without that setting MagicOS doesn't deliver BOOT_COMPLETED, so the app recovers only when opened.
  • Reinstalling the app didn't require toggling notification access.

Code written by Claude Code, reviewed and tested by me on the device.

@07jasjeet 07jasjeet left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, thanks for the opening a PR for the issue. Since I cannot reproduce the issue (but the service still works functionally same) on my side, I would like you to make the requested changes (functionally same) and we can go ahead.

Thanks for explicitly declaring use of AI.

Comment thread app/src/main/java/org/listenbrainz/android/service/ListenSubmissionService.kt Outdated
Comment thread app/src/main/java/org/listenbrainz/android/service/ListenSubmissionService.kt Outdated
majkinetor and others added 3 commits October 26, 2026 14:28
Android unbinds the listener when the app is updated or its process is
killed, and some phones (Honor/MagicOS, MIUI) don't bind it again until
notification access is toggled. Track whether the listener is bound,
request a rebind when it isn't (falling back to re-enabling the
component), and run the check on BOOT_COMPLETED and MY_PACKAGE_REPLACED.

Fixes metabrainz#772

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rebind check slept 10 s every time the listener wasn't bound yet,
which includes the normal cold start (the app starts before
onListenerConnected), and the service start waited behind it. Make
`connected` a StateFlow and wait for it with a 10 s timeout: a bind
ends the wait at once, and forceRebind() runs only when none came.
The check now runs after the service start, so nothing waits on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TD3ZmdQpxeDwPUHJj2paND
ListenServiceState is the read-only interface for classes that only
observe the state; MutableListenServiceState is the Koin singleton the
service updates. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@majkinetor

Copy link
Copy Markdown
Author

Hi, thanks for the opening a PR for the issue. Since I cannot reproduce the issue (but the service still works functionally same) on my side, I would like you to make the requested changes (functionally same) and we can go ahead.

Thanks for explicitly declaring use of AI.

Hi @07jasjeet, thanks for reviewing. Singleton added. I tested the new build and works as before.

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.

Listen submission stops after an app update or a reboot until notification access is toggled

2 participants