Skip to content

[in_app_purchase][android] BillingClient connection is not restored after it's lost #110663

@SynSzakala

Description

@SynSzakala

As described in Google Play Billing docs, connection to the BillingClient may be lost at any time and apps making use of this API should implement their own connection management logic.
App is notified about such a disconnection via BillingClientStateListener.onBillingServiceDisconnected() and/or BillingClientResponseCode.SERVICE_DISCONNECTED

Currently, InAppPurchaseAndroidPlatform ignores onBillingServiceDisconnected callback and does not handle BillingResponse.serviceDisconnected:

https://github.com/flutter/plugins/blob/35372527c70ed0ae4cc5392330f53ede9774d88a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart#L222-L223

https://github.com/flutter/plugins/blob/35372527c70ed0ae4cc5392330f53ede9774d88a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart#L154-L176

To be consistent with iOS, Android implementation of InAppPurchase should manage the BillingClient connection transparently, so that a operation never fails because of BillingClient disconnection.

In my own experience, frequency of such disconnects varies between devices. On one of the devices I've tested, connection was lost every time the app was paused. Since starting the purchase flow opens system payment UI (which pauses the app), when user made the payment and came back to the app, completePurchase method failed silently because of the lost connection. This, in turn, caused every purchase to be eventually refunded due to lack of acknowledgement.

This issue was also reported in #40054

Steps to Reproduce

  1. Run any app that makes use of in_app_purchase on Android (e.g. official in_app_purchase example)
  2. Perform any action that makes use of BillingClient API (e.g. start - and then possibly cancel - a purchase flow)
  3. Simulate disconnection of BillingClient by executing adb shell pm clear com.android.vending on the host machine (Billing service disconnected. should appear in logcat)
  4. Perform any action that makes use of BillingClient API (as in step 2.)

Expected results: Action completes with success

Actual results: Action fails (e.g. in case of queryProductDetails call, empty list is returned)

Reproduced on:

  • Flutter 3.0.4
  • in_app_purchase 3.0.7
  • in_app_purchase_android 0.2.3+3

flutter doctor -v:

[✓] Flutter (Channel stable, 3.0.4, on Ubuntu 22.04.1 LTS 5.15.0-46-generic, locale pl_PL.UTF-8)
    • Flutter version 3.0.4 at /home/kuba/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 85684f9300 (9 weeks ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

[!] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
    • Android SDK at /home/kuba/tools/android-sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2)
    • IntelliJ at /home/kuba/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/222.3739.54
    • Flutter plugin version 69.0.5
    • Dart plugin version 222.3739.24

[✓] Connected device (3 available)
    • ANE LX1 (mobile) • 9WV7N18426037007 • android-arm64  • Android 9 (API 28)
    • Linux (desktop)  • linux            • linux-x64      • Ubuntu 22.04.1 LTS 5.15.0-46-generic
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

Logs

Logs from reproduction using my own app using in_app_purchase on Android:

I/flutter (18225): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (18225): │ 💡 [SubscriptionService] Product details found, starting purchase: 
I/flutter (18225): │ 💡 title=Standard (haveagood.one)
I/flutter (18225): │ 💡 price=9,99 zł
I/flutter (18225): │ 💡 description=
I/flutter (18225): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
...omitted...
W/BillingClient(18225): Billing service disconnected.
...omitted
I/flutter (18225): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (18225): │ Exception: Product details not found for standard1
I/flutter (18225): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
...omitted...
I/flutter (18225): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (18225): │ ⛔ Uncaught error
I/flutter (18225): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listp: in_app_purchasePlugin for in-app purchasepackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions