Repository navigation
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
9e0c61c to
6b60a45
Compare
… exactly once Foreground messages went from the broadcast receiver to the plugin through a `LiveData`, which caused two bugs: - Messages were lost: `postValue` keeps only the last of the values posted before the main thread runs, so a burst of pushes reached `onMessage` as a single message (5 back to back: only the last one arrived). - Old messages were delivered again: `LiveData` hands its last value to every new observer, so each newly attached engine (app reopened after Back while the process lived, or another engine) got the previous foreground message as a new `onMessage` (#12411). `FlutterFirebaseRemoteMessageDispatcher` replaces it. It delivers each message once, in order, to the engines whose Dart listens to `FirebaseMessaging.onMessage`, which now tells the plugin when it starts and stops listening (`Messaging#startForegroundMessages` / `Messaging#stopForegroundMessages`). The signal is sent from this package, which ships with the native code, so the two cannot get out of step. Messages received while no engine listens are kept for up to a minute and handed to the first one that does. Engines that never listen, like the background engine that runs `onBackgroundMessage`, get none. `FlutterFirebaseRemoteMessageLiveData` is deprecated: `postRemoteMessage` forwards to the dispatcher, and its observers are still told about every message. The main channel buffer is also enlarged, with every message sent to Dart: engines created with `new FlutterEngine(...)` register plugins before running Dart, and Flutter drops messages until then. Tests: - JUnit tests for the dispatcher, added to `android-unit-tests`. - Dart tests for the start/stop signal. - e2e tests that hand messages to the real receiver through a test-only channel in the example app: a burst reaches `onMessage` once and in order, a second engine started later gets only the new messages, and messages sent before Dart handles the channel are all kept. Each fails on the previous code.
7c4eecb to
40c1414
Compare
Description
On Android, foreground messages go from
FlutterFirebaseMessagingReceiverto the plugin through aLiveData. That caused two bugs, both reproduced on an emulator (Pixel 9a):1. Messages lost in bursts. The receiver posts with
postValuefrom a background thread, andpostValuekeeps only the last of the values posted before the main thread runs. 5 messages handed to the receiver back to back reachedonMessageas 1 (the last).2. Old messages delivered again (#12411, closed by the stale bot, never fixed).
LiveDatahands its last value to every new observer, so each newly attached engine gets the previous foreground message as a newonMessage. For example: a message arrives, the user leaves with Back (the engine is destroyed, the process is kept), then reopens the app, and the new engine gets the old message again.FlutterFirebaseRemoteMessageDispatcherreplaces theLiveData:FirebaseMessaging.onMessage.Messaging#startForegroundMessages/Messaging#stopForegroundMessages). The signal is sent from thefirebase_messagingpackage, which ships together with the native code, so a newer native side can't be paired with Dart that never sends it.onBackgroundMessage, get none.FlutterFirebaseRemoteMessageLiveDatais kept for compatibility. It is deprecated,postRemoteMessageforwards to the dispatcher, and its observers are still told about every message.The main channel buffer is also enlarged (Flutter keeps one message by default), with every message sent to Dart. Engines created with
new FlutterEngine(...)register plugins before they run Dart, and Flutter drops messages until then.onMessagegets 1 (the last)Notes:
plugins.flutter.io/firebase_messagingchannel on Android (flutter_test's default platform) now also seeMessaging#startForegroundMessages/Messaging#stopForegroundMessagescalls.LiveDatas still replay their last value to new engines (onTokenRefreshwith the same token); left as is.Tests
android/src/test, now run byandroid-unit-tests): bursts, every listener, no replay to later listeners, kept messages delivered once, lifetime and size limits, removal, and the legacyLiveDatabeing notified.firebase_messaging/test/on_message_listening_test.dart): start on the first listen, stop on the last cancel, nothing on iOS.example/integration_test/remote_notification_delivery.dart, run bye2e-messaging): a test-only channel in the example'sMainActivity.kthands FCM-shaped intents to the realFlutterFirebaseMessagingReceiver. Each test below fails on the previous code and passes with this change:onMessageonce and in order;Related Issues
Fixes #12411. Builds on #18830 (merged).
Checklist
///).melos run analyze) does not report any problems on my PR.Breaking Change