Commit 1522bd8
authored
fix(messaging,android): fix an issue that could cause duplicate call stack (#18122)
* fix(messaging,android): fix an issue that could cause duplicate call stack
* refactor(messaging,android): drop unreachable shellArgs path from background executor
Removing the eager background-isolate start left FlutterShellArgs always
null: the only remaining caller is the lazy path in
FlutterFirebaseMessagingBackgroundService.onCreate(), which goes through
the no-arg startBackgroundIsolate() and passed null explicitly.
Collapses the shellArgs parameter and its unreachable branch, and drops
the two imports that became unused.
This does not reopen #4078. That was a ClassCastException from casting
FlutterFragmentActivity to FlutterActivity to reach getFlutterShellArgs();
#4341 fixed it by switching to FlutterShellArgs.fromIntent(). With the
activity no longer consulted at all, the cast that caused #4078 is gone.
* revert(messaging): restore example minSdk = 23
The minSdk = 23 -> flutter.minSdkVersion change was unrelated to the
duplicate-call-stack fix, and it breaks the example on the oldest Flutter
this package supports. pubspec declares flutter: '>=3.27.0', where
FlutterExtension.minSdkVersion is 21, while firebase_messaging's
local-config.gradle sets minSdk=23 -- so the manifest merger fails with
"minSdkVersion 21 cannot be smaller than version 23 declared in library".
CI only runs stable (currently 3.44.6, where the default is 24), so the
break would not show up here. Nine other example apps hardcode
minSdk = 23 for the same reason.
* feat(messaging,android): persist shell args so the lazy background isolate keeps them
The eager background-isolate start was the only place with access to an
activity, so removing it left the background engine with no shell args at
all. Instead of dropping them, capture them at registration -- where an
activity is still available -- and persist them next to the callback
handles already stored in SharedPreferences. The lazy start in
FlutterFirebaseMessagingBackgroundService.onCreate() then restores them.
This is strictly wider coverage than before: previously the killed-app
path (the common background case) already started the isolate through the
no-arg overload with null args, so shell args only applied when an
activity happened to be alive. Now they apply in both paths.
Stored as a JSON array rather than a String set because arg order is
significant. org.json is already used by FlutterFirebaseMessagingStore.
Passing null or empty clears the stored value, so args cannot go stale
across a launch that has no activity.
* revert(messaging,android): drop shell args persistence in favour of manifest flags
Reverts the SharedPreferences plumbing added to carry FlutterShellArgs
into the lazily-started background isolate, and documents the forward
path instead.
FlutterShellArgs is @deprecated upstream with a TODO to delete it once
engine args via Intent are unsupported (flutter/flutter#180686). Its
documented replacement, FlutterEngineFlags, reads flags from
<application> metadata in AndroidManifest.xml -- and FlutterLoader
applies those inside ensureInitializationComplete, which this executor
already calls. So manifest-declared flags reach the background engine
with no plugin code at all.
FlutterEngineFlags cannot be referenced directly: it first shipped in
Flutter 3.44.0, while this package supports flutter: '>=3.27.0'. Naming
it would break compilation on 3.27 through 3.43, and CI only runs stable
so that would not be caught here.
Net effect: no deprecated API, less code, and engine flags handled by the
mechanism Flutter is standardising on.
* docs(messaging): document Android background isolate engine flags
The background isolate runs in its own FlutterEngine started from a
service, so command-line engine flags never reached it, and the
intent-based mechanism that partially covered this is deprecated upstream
(flutter/flutter#180686).
Documents the supported replacement: <application> metadata in
AndroidManifest.xml, which FlutterLoader applies to every engine it
initializes. Notes the Flutter 3.44.0 floor, the mandatory
io.flutter.embedding.android. prefix, that most flags are ignored in
release builds, and that the command line wins over the manifest.
* style(messaging,android): rewrap javadoc to satisfy google-java-format1 parent 6b1fbc9 commit 1522bd8
4 files changed
Lines changed: 57 additions & 59 deletions
File tree
- docs/cloud-messaging
- packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
155 | 189 | | |
156 | 190 | | |
157 | 191 | | |
| |||
Lines changed: 15 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
| |||
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
109 | | - | |
| 107 | + | |
110 | 108 | | |
111 | 109 | | |
112 | 110 | | |
113 | 111 | | |
114 | | - | |
115 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
116 | 123 | | |
117 | 124 | | |
118 | 125 | | |
| |||
131 | 138 | | |
132 | 139 | | |
133 | 140 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
147 | 144 | | |
148 | 145 | | |
149 | 146 | | |
| |||
Lines changed: 0 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 39 | | |
63 | 40 | | |
64 | 41 | | |
| |||
Lines changed: 8 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
424 | 423 | | |
425 | 424 | | |
426 | 425 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
433 | 429 | | |
434 | 430 | | |
435 | 431 | | |
| |||
458 | 454 | | |
459 | 455 | | |
460 | 456 | | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
470 | 462 | | |
471 | 463 | | |
472 | | - | |
473 | | - | |
474 | 464 | | |
475 | 465 | | |
476 | 466 | | |
| |||
0 commit comments