Skip to content

Commit 0e848fa

Browse files
[in_app_purchase] Mostly convert to Android Pigeon (#6262)
Replaces manual method channels with Pigeon. This replaces all of the method calls in both direction with Pigeon calls, and converts all the top-level objects used for params and returns to Pigeon objects. However, because of the significant object graph, in order to somewhat limit the scope of this PR I made a cut at that layer in the object graph, with nested objects still using the existing JSON serialization. In a follow-up PR, those will be converted to typed Pigeon objects as well, completing the transition. Unfortunately a significant amount of JSON code can't be removed yet even though it's now unused by the plugin, because it's part of the API of the public wrappers, so clients may be using it. Once all the JSON code is unused, we could `@Deprecated` all of it, and then could do a follow-up breaking change later to remove it. Most of flutter/flutter#117910
1 parent f4790cf commit 0e848fa

28 files changed

+5090
-2240
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.2+1
2+
3+
* Converts internal platform communication to Pigeon.
4+
15
## 0.3.2
26

37
* Adds UserChoiceBilling APIs to platform addition.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import androidx.annotation.Nullable;
1010
import com.android.billingclient.api.BillingClient;
1111
import com.android.billingclient.api.UserChoiceBillingListener;
12-
import io.flutter.plugin.common.MethodChannel;
12+
import io.flutter.plugins.inapppurchase.Messages.PlatformBillingChoiceMode;
1313

1414
/** Responsible for creating a {@link BillingClient} object. */
1515
interface BillingClientFactory {
@@ -18,14 +18,14 @@ interface BillingClientFactory {
1818
* Creates and returns a {@link BillingClient}.
1919
*
2020
* @param context The context used to create the {@link BillingClient}.
21-
* @param channel The method channel used to create the {@link BillingClient}.
21+
* @param callbackApi The callback API to be used by the {@link BillingClient}.
2222
* @param billingChoiceMode Enables the ability to offer alternative billing or Google Play
2323
* billing.
2424
* @return The {@link BillingClient} object that is created.
2525
*/
2626
BillingClient createBillingClient(
2727
@NonNull Context context,
28-
@NonNull MethodChannel channel,
29-
int billingChoiceMode,
28+
@NonNull Messages.InAppPurchaseCallbackApi callbackApi,
29+
PlatformBillingChoiceMode billingChoiceMode,
3030
@Nullable UserChoiceBillingListener userChoiceBillingListener);
3131
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010
import com.android.billingclient.api.BillingClient;
1111
import com.android.billingclient.api.UserChoiceBillingListener;
1212
import io.flutter.Log;
13-
import io.flutter.plugin.common.MethodChannel;
14-
import io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.BillingChoiceMode;
13+
import io.flutter.plugins.inapppurchase.Messages.PlatformBillingChoiceMode;
1514

1615
/** The implementation for {@link BillingClientFactory} for the plugin. */
1716
final class BillingClientFactoryImpl implements BillingClientFactory {
1817

1918
@Override
2019
public BillingClient createBillingClient(
2120
@NonNull Context context,
22-
@NonNull MethodChannel channel,
23-
int billingChoiceMode,
21+
@NonNull Messages.InAppPurchaseCallbackApi callbackApi,
22+
PlatformBillingChoiceMode billingChoiceMode,
2423
@Nullable UserChoiceBillingListener userChoiceBillingListener) {
2524
BillingClient.Builder builder = BillingClient.newBuilder(context).enablePendingPurchases();
2625
switch (billingChoiceMode) {
27-
case BillingChoiceMode.ALTERNATIVE_BILLING_ONLY:
26+
case ALTERNATIVE_BILLING_ONLY:
2827
// https://developer.android.com/google/play/billing/alternative/alternative-billing-without-user-choice-in-app
2928
builder.enableAlternativeBillingOnly();
3029
break;
31-
case BillingChoiceMode.USER_CHOICE_BILLING:
30+
case USER_CHOICE_BILLING:
3231
if (userChoiceBillingListener != null) {
3332
// https://developer.android.com/google/play/billing/alternative/alternative-billing-with-user-choice-in-app
3433
builder.enableUserChoiceBilling(userChoiceBillingListener);
@@ -38,7 +37,7 @@ public BillingClient createBillingClient(
3837
"userChoiceBillingListener null when USER_CHOICE_BILLING set. Defaulting to PLAY_BILLING_ONLY");
3938
}
4039
break;
41-
case BillingChoiceMode.PLAY_BILLING_ONLY:
40+
case PLAY_BILLING_ONLY:
4241
// Do nothing.
4342
break;
4443
default:
@@ -47,6 +46,6 @@ public BillingClient createBillingClient(
4746
"Unknown BillingChoiceMode " + billingChoiceMode + ", Defaulting to PLAY_BILLING_ONLY");
4847
break;
4948
}
50-
return builder.setListener(new PluginPurchaseListener(channel)).build();
49+
return builder.setListener(new PluginPurchaseListener(callbackApi)).build();
5150
}
5251
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
1414
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
1515
import io.flutter.plugin.common.BinaryMessenger;
16-
import io.flutter.plugin.common.MethodChannel;
1716

1817
/** Wraps a {@link BillingClient} instance and responds to Dart calls for it. */
1918
public class InAppPurchasePlugin implements FlutterPlugin, ActivityAware {
@@ -25,7 +24,6 @@ public class InAppPurchasePlugin implements FlutterPlugin, ActivityAware {
2524
// code owner of this package.
2625
static final String PROXY_VALUE = "io.flutter.plugins.inapppurchase";
2726

28-
private MethodChannel methodChannel;
2927
private MethodCallHandlerImpl methodCallHandler;
3028

3129
/** Plugin registration. */
@@ -45,7 +43,7 @@ public void onAttachedToEngine(@NonNull FlutterPlugin.FlutterPluginBinding bindi
4543

4644
@Override
4745
public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
48-
teardownMethodChannel();
46+
teardownMethodChannel(binding.getBinaryMessenger());
4947
}
5048

5149
@Override
@@ -71,16 +69,15 @@ public void onDetachedFromActivityForConfigChanges() {
7169
}
7270

7371
private void setUpMethodChannel(BinaryMessenger messenger, Context context) {
74-
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/in_app_purchase");
72+
Messages.InAppPurchaseCallbackApi handler = new Messages.InAppPurchaseCallbackApi(messenger);
7573
methodCallHandler =
7674
new MethodCallHandlerImpl(
77-
/*activity=*/ null, context, methodChannel, new BillingClientFactoryImpl());
78-
methodChannel.setMethodCallHandler(methodCallHandler);
75+
/*activity=*/ null, context, handler, new BillingClientFactoryImpl());
76+
Messages.InAppPurchaseApi.setUp(messenger, methodCallHandler);
7977
}
8078

81-
private void teardownMethodChannel() {
82-
methodChannel.setMethodCallHandler(null);
83-
methodChannel = null;
79+
private void teardownMethodChannel(BinaryMessenger messenger) {
80+
Messages.InAppPurchaseApi.setUp(messenger, null);
8481
methodCallHandler = null;
8582
}
8683

0 commit comments

Comments
 (0)