Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[in_app_purchases] Android: make sure properly disconnect the billing client object. #2509

Merged
merged 5 commits into from
Feb 10, 2020

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Feb 8, 2020

Description

Fixes a bug that the plugin disconnect the billing client at an inappropriate place. Also fixed some minor compiling warnings.

Related Issues

flutter/flutter#33210

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@cyanglaz cyanglaz requested a review from mklim as a code owner February 8, 2020 00:40
@cyanglaz cyanglaz changed the title [in_app_purchases] make sure properly disconnect the billing client object. [in_app_purchases] Android: make sure properly disconnect the billing client object. Feb 8, 2020
Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo one comment

@@ -81,7 +85,7 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding

@Override
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
methodCallHandler.setActivity(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this and not methodCallHandler.onDetachedFromActivity()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary to disconnect the billing client when activity detached from config changes (e.g. when the phone is rotated).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, could you also document that here? Everywhere else we treat these callbacks as equivalent.

@Override
public void onActivityDestroyed(Activity activity) {
if (this.activity == activity) {
if (this.applicationContext != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I would combine this with the outer if just to avoid an extra level of indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mklim
Copy link
Contributor

mklim commented Feb 8, 2020

Whoops, I forgot about tests. Please add in a unit test before merging.

@cyanglaz
Copy link
Contributor Author

cyanglaz commented Feb 8, 2020

@mklim Updated with tests

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

nit: Looks like there's an unused method to clean up now. info - The declaration '_disconnect' isn't referenced at lib/src/in_app_purchase/google_play_connection.dart:179:16 - (unused_element)

@@ -81,7 +85,7 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding

@Override
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
methodCallHandler.setActivity(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, could you also document that here? Everywhere else we treat these callbacks as equivalent.

@@ -66,6 +69,37 @@ void setActivity(@Nullable Activity activity) {
this.activity = activity;
}

// Activity Life Cycle callbacks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this comment is a little redundant. If this is more of an organizational thing I'd rather put the callbacks in an inner final class and reference that instead.

@cyanglaz cyanglaz merged commit 70d874d into flutter:master Feb 10, 2020
@cyanglaz cyanglaz deleted the in_app_purchase_state_listener branch February 11, 2020 00:28
sanekyy pushed a commit to sanekyy/plugins that referenced this pull request Feb 18, 2020
EdwinRomelta pushed a commit to EdwinRomelta/plugins that referenced this pull request Jun 11, 2020
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants