Repository navigation
Commit c840e38
authored
[quick_actions_android] Return null from getLaunchAction when no activity is attached (flutter#12331)
`getLaunchAction` threw `quick_action_getlaunchaction_no_activity` when the plugin had no attached activity. `QuickActionsAndroid.initialize` calls `getLaunchAction` unconditionally, so `initialize` threw a `PlatformException` that callers could not prevent.
An engine can legitimately run without an attached activity. A cached engine warmed up by a background service is the common case: `audio_service` supplies a cached engine to its activity and also warms up that same engine from `AudioService.onCreate`, so `main()` runs with no activity when a media button or Android Auto starts the service.
This returns `null` in that case instead, and logs at debug level. The throw provided no recovery value:
* `initialize` registers the Dart handler before it calls `getLaunchAction`, so the handler is already installed when the exception is thrown.
* When an activity does attach, `QuickActionsPlugin.onAttachedToActivity` calls `onNewIntent(activity.getIntent())`, which reports the shortcut through `AndroidQuickActionsFlutterApi.launchAction`.
`null` is also already the return value for the other "cannot answer" case in this method, on the line directly above (`if (!isVersionAllowed())`).
Verified on an Android 12 emulator by pointing an app at this branch and starting its audio service with no UI: no exception, and a shortcut tap afterwards still routed correctly. A cold start from a shortcut still returns the action, so the activity-present path is unchanged. The new unit test fails with `io.flutter.plugins.quickactions.FlutterError` against the unmodified file.
Fixes flutter#190348
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 7660d46 commit c840e38
4 files changed
Lines changed: 29 additions & 6 deletions
File tree
- packages/quick_actions/quick_actions_android
- android/src
- main/java/io/flutter/plugins/quickactions
- test/java/io/flutter/plugins/quickactions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
109 | 113 | | |
110 | 114 | | |
111 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
53 | 71 | | |
54 | 72 | | |
55 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments