Skip to content

Commit c50c218

Browse files
authored
[in_app_purchase_android] Bump com.android.billingclient:billing from 5.2.0 to 6.0.0. (#4390)
Takeover of #3988 Conflicts had built up and it required some additional changes so I figured it would be easier to just make my own new branch to fix. Changes from last PR 1. I made the particular ProrationMode enum value we were using a constant and put the deprecation suppression on that constant. 2. I made a helper to wrap the other deprecated method (`setReplaceProrationMode`). 3. Added todos with links to the issue for replacing the deprecated classes/methods.
1 parent 12ec9fe commit c50c218

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.0+9
2+
3+
* Bumps com.android.billingclient:billing from 5.2.0 to 6.0.0.
4+
15
## 0.3.0+8
26

37
* Adds a [guide for migrating](migration_guide.md) to [0.3.0](#0.3.0).

packages/in_app_purchase/in_app_purchase_android/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ dependencies {
6161
// org.jetbrains.kotlin:kotlin-bom artifact purpose is to align kotlin stdlib and related code versions.
6262
// See: https://youtrack.jetbrains.com/issue/KT-55297/kotlin-stdlib-should-declare-constraints-on-kotlin-stdlib-jdk8-and-kotlin-stdlib-jdk7
6363
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.22"))
64-
implementation 'com.android.billingclient:billing:5.2.0'
64+
implementation 'com.android.billingclient:billing:6.0.0'
6565
testImplementation 'junit:junit:4.13.2'
6666
testImplementation 'org.json:json:20230618'
6767
testImplementation 'org.mockito:mockito-core:5.4.0'

packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.android.billingclient.api.BillingClient;
2323
import com.android.billingclient.api.BillingClientStateListener;
2424
import com.android.billingclient.api.BillingFlowParams;
25-
import com.android.billingclient.api.BillingFlowParams.ProrationMode;
2625
import com.android.billingclient.api.BillingResult;
2726
import com.android.billingclient.api.ConsumeParams;
2827
import com.android.billingclient.api.ConsumeResponseListener;
@@ -67,6 +66,14 @@ static final class MethodNames {
6766
private MethodNames() {}
6867
}
6968

69+
// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
70+
// ReplacementMode enum values.
71+
// https://github.com/flutter/flutter/issues/128957.
72+
@SuppressWarnings(value = "deprecation")
73+
private static final int PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY =
74+
com.android.billingclient.api.BillingFlowParams.ProrationMode
75+
.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY;
76+
7077
private static final String TAG = "InAppPurchasePlugin";
7178
private static final String LOAD_PRODUCT_DOC_URL =
7279
"https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale";
@@ -156,7 +163,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
156163
(String) call.argument("purchaseToken"),
157164
call.hasArgument("prorationMode")
158165
? (int) call.argument("prorationMode")
159-
: ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY,
166+
: PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY,
160167
result);
161168
break;
162169
case MethodNames.QUERY_PURCHASES_ASYNC:
@@ -273,7 +280,7 @@ private void launchBillingFlow(
273280
}
274281

275282
if (oldProduct == null
276-
&& prorationMode != ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) {
283+
&& prorationMode != PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) {
277284
result.error(
278285
"IN_APP_PURCHASE_REQUIRE_OLD_PRODUCT",
279286
"launchBillingFlow failed because oldProduct is null. You must provide a valid oldProduct in order to use a proration mode.",
@@ -322,15 +329,24 @@ private void launchBillingFlow(
322329
BillingFlowParams.SubscriptionUpdateParams.newBuilder();
323330
if (oldProduct != null && !oldProduct.isEmpty() && purchaseToken != null) {
324331
subscriptionUpdateParamsBuilder.setOldPurchaseToken(purchaseToken);
325-
// The proration mode value has to match one of the following declared in
326-
// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode
327-
subscriptionUpdateParamsBuilder.setReplaceProrationMode(prorationMode);
332+
// Set the prorationMode using a helper to minimize impact of deprecation warning suppression.
333+
setReplaceProrationMode(subscriptionUpdateParamsBuilder, prorationMode);
328334
paramsBuilder.setSubscriptionUpdateParams(subscriptionUpdateParamsBuilder.build());
329335
}
330336
result.success(
331337
fromBillingResult(billingClient.launchBillingFlow(activity, paramsBuilder.build())));
332338
}
333339

340+
// TODO(gmackall): Replace uses of deprecated setReplaceProrationMode.
341+
// https://github.com/flutter/flutter/issues/128957.
342+
@SuppressWarnings(value = "deprecation")
343+
private void setReplaceProrationMode(
344+
BillingFlowParams.SubscriptionUpdateParams.Builder builder, int prorationMode) {
345+
// The proration mode value has to match one of the following declared in
346+
// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode
347+
builder.setReplaceProrationMode(prorationMode);
348+
}
349+
334350
private void consumeAsync(String purchaseToken, final MethodChannel.Result result) {
335351
if (billingClientError(result)) {
336352
return;

packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,11 @@ public void launchBillingFlow_ok_AccountId() {
416416
verify(result, times(1)).success(fromBillingResult(billingResult));
417417
}
418418

419+
// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
420+
// ReplacementMode enum values.
421+
// https://github.com/flutter/flutter/issues/128957.
419422
@Test
423+
@SuppressWarnings(value = "deprecation")
420424
public void launchBillingFlow_ok_Proration() {
421425
// Fetch the product details first and query the method call
422426
String productId = "foo";
@@ -453,7 +457,11 @@ public void launchBillingFlow_ok_Proration() {
453457
verify(result, times(1)).success(fromBillingResult(billingResult));
454458
}
455459

460+
// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
461+
// ReplacementMode enum values.
462+
// https://github.com/flutter/flutter/issues/128957.
456463
@Test
464+
@SuppressWarnings(value = "deprecation")
457465
public void launchBillingFlow_ok_Proration_with_null_OldProduct() {
458466
// Fetch the product details first and query the method call
459467
String productId = "foo";
@@ -487,7 +495,11 @@ public void launchBillingFlow_ok_Proration_with_null_OldProduct() {
487495
verify(result, never()).success(any());
488496
}
489497

498+
// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
499+
// ReplacementMode enum values.
500+
// https://github.com/flutter/flutter/issues/128957.
490501
@Test
502+
@SuppressWarnings(value = "deprecation")
491503
public void launchBillingFlow_ok_Full() {
492504
// Fetch the product details first and query the method call
493505
String productId = "foo";

packages/in_app_purchase/in_app_purchase_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_android
22
description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.3.0+8
5+
version: 0.3.0+9
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)