This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[In_App_Purchase] Avoids possible NullPointerException with background registrations. #2014
Merged
mklim
merged 10 commits into
flutter-team-archive:master
from
juliocbcotta:plugin/in_app_purchase_null_fix
Aug 29, 2019
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52cd0a0
Do not register plugin if Activity is null.
juliocbcotta da055d5
Revert unrelated changes.
juliocbcotta bcf733a
Adds UnitTest for registration.
juliocbcotta cdaea15
Allow background registration and adds check for Activity nullability…
juliocbcotta 65a6a1a
update tests and changelog.
juliocbcotta 346dd51
Update packages/in_app_purchase/android/src/main/java/io/flutter/plug…
juliocbcotta ee54c28
Update packages/in_app_purchase/CHANGELOG.md
juliocbcotta f7ef931
Merge branch 'master' into plugin/in_app_purchase_null_fix
juliocbcotta 7db64ef
Merge branch 'plugin/in_app_purchase_null_fix' of github.com:BugsBunn…
juliocbcotta 78f82ff
Merge branch 'master' into plugin/in_app_purchase_null_fix
juliocbcotta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for devs in this state it's better to throw a
RuntimeExceptionwith an error message and crash than to silently fail, even in release mode. This case means that none of the functions of the plugin are going to actually work, so silently returning is slipping the app into an unrecoverable error state. None of the API calls will work, and there isn't going to be a clear sign or reason why from the app developer's side. What do you think?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the same strategy used here. It is of my understanding that the plugin will get a second change to register itself when an Activity is available. Raising an exception here would make that impossible to to flutter developers to handle. When a background or foreground registration happens it execute a "register all command" . That can be seem here and in foreground here. In other words, it would make impossible to use Alarm Manager Plugin and In App Purchase plugin in the same project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks for the clarification. I've done some digging on my end to understand this better.
So from my testing IFF the user sets up a custom
Application.javawithandroid_alarm_manager, like in the example app, the callbacks always try to register with a null activity. The Flutter app using these periodic callbacks sets up the plugins usingMainActivityin the typical way in its standard isolate, and can make calls like expected. However the callbacks are always registered with a null activity, regardless of whether or not the plugin is in the foreground when the callbacks fire.Throwing an exception like I originally suggested definitely doesn't make sense, because this registration happens for all plugins whether or not they're actually used in the callback. So that would make this unusable in conjunction with the plugin, like you mentioned.
This return also introduces some potential new runtime errors IFF the callbacks try to use the IAP API at all in their callbacks, since they always execute with a background isolate and null activity, but not all of the IAP methods actually need an activity at all. On some more thought about this I think that's a regression we probably want to avoid. The critical
launchBillingFlowone requires anActivity, but I can see a dev using only unrelated methods likequeryPurchasesin their background callbacks instead.Sorry about the back and forth. With that in mind, I think a better approach would be to actually accept registration when
activityis null, but to markInAppPurchasePlugin#activityas@Nullableand returnresult.error()inlaunchBillingFlowif it's called whileactivityis null. This is similar to how we enforce thatBillingClienthas been set correctly in API calls that require it with theInAppPurchase#billingClientErrorhelper method. I think the same"UNAVAILABLE"tag but with a different message about the activity would make sense. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no problem in this back and forth. We are evolving in the solution. :-)
I hadn't thought about enabling the plugin usage in background, nice catch.
I will update the code/tests as needed.