-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[in_app_purchase_android] Implement BillingClient connection management and introduce BillingClientManager
#6309
Conversation
BillingClient connection management and introduce BillingClientManager
|
I look forward to this PR being merged. |
|
@GaryQian Ping on this review. |
| @@ -0,0 +1,147 @@ | |||
| // Copyright 2013 The Flutter Authors. All rights reserved. | |||
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.
You should document in BillingClient the drawbacks of using the BillingClient class directly and point them to the newly recommended way of handling operations using this new BillingClientManager class.
| return await block(client); | ||
| } | ||
|
|
||
| /// Ends connection to the [BillingClient]. |
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.
Document when/under what conditions dispose should be called.
| const String kInvalidBillingResultErrorMessage = | ||
| 'Invalid billing result map from method channel.'; | ||
|
|
||
| /// Abstraction of result of [BillingClient] operation that includes |
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.
Is this class in the correct file? I expected this to live in the billing_client_manager.dart file.
packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart
Outdated
Show resolved
Hide resolved
| return purchaseDetails; | ||
| } | ||
|
|
||
| final InAppPurchaseAndroidPlatformAddition addition = |
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.
Avoid unnecessary refactors
|
|
||
| /// [BillingClient] instance managed by this [BillingClientManager]. | ||
| /// | ||
| /// This field should not be accessed outside of test code. |
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.
This sentence is redundant as @VisibleForTesting will enforce preventing its usage outside of tests.
...purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_manager.dart
Show resolved
Hide resolved
…econnect # Conflicts: # packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md # packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
| test('connects on initialization', () { | ||
| expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1)); | ||
| }); | ||
| test('waits for connection before executing the operations', () { |
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.
nit: newline between tests
| expect(runCalled, equals(true)); | ||
| expect(runRawCalled, equals(true)); | ||
| }); | ||
| test('re-connects when client sends onBillingServiceDisconnected', () { |
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.
nit: newline between tests
| ); | ||
| expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(2)); | ||
| }); | ||
| test( |
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.
nit: newline between tests
| expect(result.responseCode, equals(BillingResponse.ok)); | ||
| }, | ||
| ); | ||
| test('does not re-connect when disposed', () { |
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.
nit: newline between tests
| ); | ||
| expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(2)); | ||
| }); | ||
| test( |
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.
nit: newline between tests
| //await iapAndroidPlatform.isAvailable(); | ||
| expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1)); | ||
| }); | ||
| test('re-connects when client sends onBillingServiceDisconnected', () { |
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.
nit: newline between tests
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| import 'billing_client_wrapper.dart'; | ||
| import '../../billing_client_wrappers.dart'; |
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.
Prefer directly importing billing_client_manager.dart over the export file which contains extraneous imports.
|
@SynSzakala Overall looks good, just a few small nits. Let me know when you address them! |
c9d6bfe to
51bb55a
Compare
|
@SynSzakala It looks like there are some CLA signing issues where your secondary email needs to accept the CLA, or you can amend the commit that used your alternate email address and force-push. |
GaryQian
left a comment
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.
LGTM! Thanks for your contribution. Once you address the CLA issue, we can move forwards.
51bb55a to
213ec8a
Compare
|
@GaryQian Everything should be ready for merge now. |
|
Thanks for this PR! The issue with lost connections leading to refunded purchases is hitting us pretty hard in production, so this is much appreciated. |
|
@stuartmorgan @GaryQian Is there anything preventing us from merging this? |
stuartmorgan-g
left a comment
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.
@SynSzakala Could you address all of the open comments from @GaryQian's review, and fix the analysis issues that are causing repo_checks to fail?
Once that's done I can approve this for landing.
|
|
||
| Future<List<PurchaseDetails>> _getPurchaseDetailsFromResult( | ||
| PurchasesResultWrapper resultWrapper) async { | ||
| PurchasesResultWrapper resultWrapper, |
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.
Why have you added commas everywhere? Changing formatting of lines that you aren't otherwise changing makes the diff (and git blame) more confusing.
|
@SynSzakala When you get a chance to fix the failing analyzer checks, we can move forwards with this. Thanks! |
|
@SynSzakala It looks like the analyzer complaints are just warnings to do with 4 unneeded |
|
@GaryQian @stuartmorgan Cleared all comments (including unnecessary refactors), fixed analyzer issues. Looking forward to merge this! |
…ndroid_billing_client_reconnect # Conflicts: # packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
aa02afc to
6bc41e0
Compare
GaryQian
left a comment
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.
LGTM! Thanks
|
@stuartmorgan @GaryQian Are there any additional steps needed to merge this? I don't have the access to add "autosubmit" label as suggested in Tree Hygiene |
This needs a second review, per https://github.com/flutter/flutter/wiki/Tree-hygiene#getting-a-code-review @bparrishMines Could you do the second review here, as the ecosystem-side codeowner for this plugin? |
|
We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages. Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord. Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state! |
This PR adds management of
BillingClientconnection to Android implementation ofInAppPurchase. This should fix issues caused by lost connections.New and previously existing connection management is extracted to a new component,
BillingClientManager.This component is exported in
billing_client_wrappers.dart, so that it can also be used when interacting withBillingClientdirectly.Fixes flutter/flutter#110663
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.