Cloud Messaging: add a "Re-register" button so apps can get push back without clearing data
Is your feature request related to a problem? Please describe. When an app (e.g. LINE or YouTube) registers for push, its Firebase SDK gets a token through microG and keeps it. The app's server then sends notifications to that token.
When I tap Unregister in microG -> Cloud Messaging, microG deletes the token on Google's side, but it never tells the app. So the app keeps the old token, thinks everything is fine, and never asks for a new one. Its server keeps sending to a token that no longer exists, and push for that app just silently stops. Turning "Allow registration" back on doesn't help either.
The only fix I've found is to clear the app's data and open it again, so the SDK starts over and gets a new token. But that also signs you out of the app and resets its settings. This came up in #3861, and "clear data + reopen" is what we tell people in the Huawei Community Thailand group when an app's notifications stop.
Describe the solution you'd like A "Re-register" button on the app's Cloud Messaging page. It tells the app's Firebase SDK that its token is no longer valid, so it fetches a new one by itself. No data loss, no re-login.
- If the app is still registered, microG unregisters it first, then sends the signal.
- If the app was already unregistered, microG just sends the signal.
- If "Allow registration" is off, the button is disabled.
There seems to be a signal for this already (from=google.com/iid with CMD=RST). microG's own client library understands it (GcmReceiver.java), but microG never sends it to apps.
Describe alternatives you've considered
- Clear app data (works, but you lose your login and settings)
- Make "Unregister" send the signal itself (simpler, but changes what "Unregister" means)
- Just show a hint after unregistering that the app needs its data cleared to get push again
Additional context
Is this already planned on your side, or is there a direction you'd prefer? If not, I'd be happy to put together a PR. Since it's the Firebase SDK inside each app that has to react to the signal, I'd first check that current Firebase versions still handle CMD=RST.
That intent extra "from"="google.com/iid" only works with older versions of firebase-iid, which is no longer used by modern Firebase SDK. Dependency on firebase-iid was dropped from firebase-messaging no later than firebase/firebase-android-sdk@21a9f912862bfbd801690a9f88dce22366bec8ac (see firebase-messaging.gradle). I let an LLM trace the changes in releases of firebase-messaging, and it finds out that handling for from=google.com/iid control messages was removed in firebase-messaging 20.3.0 (using firebase-iid 20.3.0), coinciding with the addition of getToken()/deleteToken() methods to FirebaseMessaging.
If the app uses firebase-messaging 20.2.4 (with firebase-iid 20.2.3) or earlier SDK, it is possible to do am broadcast --user 0 -a com.google.android.c2dm.intent.RECEIVE -n pkgname/com.google.firebase.iid.FirebaseInstanceIdReceiver --es from google.com/iid --es CMD SYNC from root or gms user, which should be enough to reset the cached token. CMD RST would also reset the instance ID store.
Newer firebase-messaging SDK doesn't seem to provide a way for GMS to invalidate its cached registration or request re-registration. com.google.firebase.messaging.NEW_TOKEN has to be a valid new FCM registration token. So far I think microG may have to register on behalf of the app and return the token as if unregistration did not happen.
For the new Firebase Installation ID (FID) path (firebase_messaging_installation_id_enabled in manifest, not yet implemented by microG), added in firebase-messaging 25.1.0 (firebase/firebase-android-sdk@3f01b025b5b651d084902c96168fea89bdb0f50d), respective new Intents have to be used instead.