Fix Android plugin: Handle intent and provide result if the intent is consumed#1121
Open
relaxedSoul wants to merge 2 commits intoryanheise:minorfrom
Open
Fix Android plugin: Handle intent and provide result if the intent is consumed#1121relaxedSoul wants to merge 2 commits intoryanheise:minorfrom
relaxedSoul wants to merge 2 commits intoryanheise:minorfrom
Conversation
When a new intent arrives, there can be several listeners for them. In case if the intent was handled by AudioService it should be consumed, and other listeners should not receive it. Otherwise, we need to return `false` in listener's method result. In this case the intent will go to the next listener.
4f5c14b to
4c6ece9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
When the Android OS opens the application with deeplink/applink (to simplify -
applink), they are provided to the app inside theIntent.The app can already be running and the
Activityis in the foreground, registered to handle the Intent with a specific intent filter. Theapplinkwill be delivered by the methodonNewIntent.Flutter provides a way to handle such links - the
flutterPluginorflutterEngineshould implement the interfaceonNewIntentListener.The bug
The audio service implements this interface, but if the
applinkis supposed to be delivered to another plugin, its listener will not be called, because the audio service listener always returns true from the functiononNewIntent.If another listener waits for intent, it will never receive it, even if the
applinkwas not for audio service, but for another purpose.Where it happens
AudioServicePlugin.java -> onAttachedToActivity method.
The method registerOnNewIntentListener() is called, and from now on, the intents will be handled by
newIntentListener.The implementation of the interface, its single method, always returns
true.The value returned here is used by Flutter (OS, eventually) to call or not call the next listener in the... I don't know if a list or a stack. I believe in the list (FIFO).
The result
truesigns that the intent was consumed, and no other listeners should be called.Fix
As far as I see, there is a method inside that makes the check, and if it fails, the intent is not handled at all. I believe this check also should deliver the result "is handled" back to the caller, and the result should be returned.
Issues or tickets, or PRs in repo
I couldn't find anything related to this bug, but there is a chance the changes will solve some other bugs: the onNewIntent handling can have a large impact on various plugins, which depend on app link handling or deeplinks.
Pre-launch Checklist
minorbranch OR my change is breaking and lands inmajorbranch.pubspec.yamlaccording to the pub versioning philosophy.* DESCRIPTION OF YOUR CHANGE (@your-git-username)).///).dart analyze.dart format.flutter testand all tests are passing.