From a670a91661770895f595b20006be570e0ab41934 Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Tue, 17 Dec 2024 15:04:02 +0800 Subject: [PATCH] Optimizing google play implementation (#18047) * Optimizing google play implementation * Initializing member variables * Remove redundant code --------- Co-authored-by: qiuguohua --- @types/jsb.d.ts | 6 +- editor/engine-features/render-config.json | 6 +- editor/i18n/en/localization.js | 4 +- editor/i18n/zh/localization.js | 6 +- .../vendor/google/billing/GoogleBilling.java | 8 +- .../google/billing/GoogleBillingHelper.java | 493 ++++++++---------- .../vendor/google/billing/GoogleBilling.cpp | 25 +- native/vendor/google/billing/GoogleBilling.h | 12 +- .../google/billing/GoogleBillingHelper.cpp | 18 +- .../google/billing/GoogleBillingHelper.h | 6 +- .../billing/build-params/BillingFlowParams.h | 4 +- .../build-params/PendingPurchasesParams.h | 4 +- .../billing/result-values/BillingResult.h | 8 +- .../billing/result-values/ProductDetails.h | 4 +- 14 files changed, 279 insertions(+), 325 deletions(-) diff --git a/@types/jsb.d.ts b/@types/jsb.d.ts index 79d5c167f05..69251386de5 100644 --- a/@types/jsb.d.ts +++ b/@types/jsb.d.ts @@ -1411,9 +1411,9 @@ declare namespace jsb { isExternalOfferAvailableAsync: (listener: ExternalOfferAvailabilityListener) => void; isFeatureSupported: (productType: string) => BillingResult; - showAlternativeBillingOnlyInformationDialog: (listener: AlternativeBillingOnlyInformationDialogListener) => BillingResult; - showExternalOfferInformationDialog: (listener: ExternalOfferInformationDialogListener) => BillingResult; - showInAppMessages: (params: InAppMessageParams, listener: InAppMessageResponseListener) => BillingResult; + showAlternativeBillingOnlyInformationDialog: (listener: AlternativeBillingOnlyInformationDialogListener) => void; + showExternalOfferInformationDialog: (listener: ExternalOfferInformationDialogListener) => void; + showInAppMessages: (params: InAppMessageParams, listener: InAppMessageResponseListener) => void; } } diff --git a/editor/engine-features/render-config.json b/editor/engine-features/render-config.json index 11fb2949889..59845f66005 100644 --- a/editor/engine-features/render-config.json +++ b/editor/engine-features/render-config.json @@ -312,10 +312,10 @@ "2d" ] }, - "vendor": { + "vendor-google": { "default": false, - "label": "i18n:ENGINE.features.vendor.label", - "description": "i18n:ENGINE.features.vendor.description", + "label": "i18n:ENGINE.features.vendor_google.label", + "description": "i18n:ENGINE.features.vendor_google.description", "enginePlugin": false, "isNativeModule": true, "cmakeConfig": "USE_VENDOR", diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index bfbb09859e1..ad6e95257ef 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -1043,8 +1043,8 @@ module.exports = link(mixin({ label: "Tiled Map", description: "Tiled map support.", }, - vendor: { - label: "Vendor", + vendor_google: { + label: "Vendor Google", description: "Vendor support.", }, spine: { diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index 92675fffe63..f8f4170e5e8 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -1021,9 +1021,9 @@ module.exports = link(mixin({ label: "Tiled 地图", description: "Tiled 地图支持。", }, - vendor: { - label: "Vendor", - description: "Vendor 支持.", + vendor_google: { + label: "Vendor Google", + description: "Vendor Google 支持.", }, spine: { label: "Spine 动画", diff --git a/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java b/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java index f6a5f256f93..40f08200a23 100644 --- a/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java +++ b/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java @@ -203,12 +203,8 @@ public void queryProductDetailsAsync(String[] productIds, String[] productTypes, Log.e(TAG, e.getMessage()); } } - public void launchBillingFlow(BillingFlowParams params) { - try { - _billingClient.launchBillingFlow(GlobalObject.getActivity(), params); - } catch (RuntimeException e) { - Log.e(TAG, e.getMessage()); - } + public BillingResult launchBillingFlow(BillingFlowParams params) { + return _billingClient.launchBillingFlow(GlobalObject.getActivity(), params); } public void queryPurchasesAsync(String type, @NonNull PurchasesResponseListener listener) { diff --git a/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java b/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java index 599ba1df080..2ba775d8c9c 100644 --- a/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java +++ b/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java @@ -56,11 +56,12 @@ of this software and associated documentation files (the "Software"), to deal import com.android.billingclient.api.UserChoiceDetails; import com.cocos.lib.CocosHelper; import com.cocos.lib.GlobalObject; +import android.util.Log; import android.util.SparseArray; import com.android.billingclient.api.BillingClientStateListener; public final class GoogleBillingHelper { - + private static final String TAG = GoogleBillingHelper.class.getSimpleName(); private static SparseArray googleBillings = new SparseArray(); private static int billingTag = 0; @@ -68,24 +69,12 @@ public static int newTag() { return billingTag++; } public static void createGoogleBilling(int tag, BillingClient.Builder builder) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = new GoogleBilling(tag, builder); - googleBillings.put(tag, billing); - } - }); + GoogleBilling billing = new GoogleBilling(tag, builder); + googleBillings.put(tag, billing); } - public static int removeGoogleBilling(int tag) { - final int index = billingTag; - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - googleBillings.remove(tag); - } - }); - return billingTag++; + public static void removeGoogleBilling(int tag) { + googleBillings.remove(tag); } public static final class BillingClientPurchasesUpdatedListener implements PurchasesUpdatedListener { @@ -186,49 +175,40 @@ public static Purchase getPurchase(int tag, int purchaseId) { public static void startConnection(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.startConnection( - new BillingClientStateListener() { - @Override - public void onBillingSetupFinished(BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onBillingSetupFinished(tag, callbackId, billingResult); - } - }); - } + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.startConnection( + new BillingClientStateListener() { + @Override + public void onBillingSetupFinished(BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onBillingSetupFinished(tag, callbackId, billingResult); + } + }); + } - @Override - public void onBillingServiceDisconnected() { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onBillingServiceDisconnected(tag, callbackId); - } - }); + @Override + public void onBillingServiceDisconnected() { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onBillingServiceDisconnected(tag, callbackId); + } + }); - } - }); } - } - }); + }); } public static void endConnection(int tag) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.endConnection(); - } - } - }); + GoogleBilling billing = googleBillings.get(tag); + if (billing != null) { + billing.endConnection(); + } } public static int getConnectionState(int tag) { @@ -256,280 +236,263 @@ public static boolean isReady(int tag) { } public static void createAlternativeBillingOnlyReportingDetailsAsync(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.createAlternativeBillingOnlyReportingDetailsAsync( - new AlternativeBillingOnlyReportingDetailsListener() { - @Override - public void onAlternativeBillingOnlyTokenResponse(@NonNull BillingResult var1, @Nullable AlternativeBillingOnlyReportingDetails var2) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onAlternativeBillingOnlyTokenResponse(tag, callbackId, var1, var2); - } - }); - } + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.createAlternativeBillingOnlyReportingDetailsAsync( + new AlternativeBillingOnlyReportingDetailsListener() { + @Override + public void onAlternativeBillingOnlyTokenResponse(@NonNull BillingResult var1, @Nullable AlternativeBillingOnlyReportingDetails var2) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onAlternativeBillingOnlyTokenResponse(tag, callbackId, var1, var2); } - ); + }); } } - }); + ); } public static void isAlternativeBillingOnlyAvailableAsync(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.isAlternativeBillingOnlyAvailableAsync( - new AlternativeBillingOnlyAvailabilityListener() { - @Override - public void onAlternativeBillingOnlyAvailabilityResponse(@NonNull BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onAlternativeBillingOnlyAvailabilityResponse(tag, callbackId, billingResult); - } - }); - } + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.isAlternativeBillingOnlyAvailableAsync( + new AlternativeBillingOnlyAvailabilityListener() { + @Override + public void onAlternativeBillingOnlyAvailabilityResponse(@NonNull BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onAlternativeBillingOnlyAvailabilityResponse(tag, callbackId, billingResult); } - ); + }); } } - }); + ); } public static void createExternalOfferReportingDetailsAsync(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.createExternalOfferReportingDetailsAsync( - new ExternalOfferReportingDetailsListener() { - @Override - public void onExternalOfferReportingDetailsResponse(@NonNull BillingResult billingResult, @Nullable ExternalOfferReportingDetails externalOfferReportingDetails) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onExternalOfferReportingDetailsResponse(tag, callbackId, billingResult, externalOfferReportingDetails); - } - }); - } + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.createExternalOfferReportingDetailsAsync( + new ExternalOfferReportingDetailsListener() { + @Override + public void onExternalOfferReportingDetailsResponse(@NonNull BillingResult billingResult, @Nullable ExternalOfferReportingDetails externalOfferReportingDetails) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onExternalOfferReportingDetailsResponse(tag, callbackId, billingResult, externalOfferReportingDetails); } - ); + }); } } - }); + ); } public static void isExternalOfferAvailableAsync(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.isExternalOfferAvailableAsync( - new ExternalOfferAvailabilityListener() { - @Override - public void onExternalOfferAvailabilityResponse(@NonNull BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onExternalOfferAvailabilityResponse(tag, callbackId, billingResult); - } - }); - } + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.isExternalOfferAvailableAsync( + new ExternalOfferAvailabilityListener() { + @Override + public void onExternalOfferAvailabilityResponse(@NonNull BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onExternalOfferAvailabilityResponse(tag, callbackId, billingResult); } - ); + }); } } - }); + ); } public static void queryProductDetailsAsync(int tag, int callbackId, String[] productIds, String[] productTypes) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.queryProductDetailsAsync(productIds, productTypes, - new ProductDetailsResponseListener() { - @Override - public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List list) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - int startID = billing.pushProductDetails(list); - GoogleBillingHelper.onProductDetailsResponse(tag, callbackId, billingResult, list, startID); - } - }); - } - }); + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.queryProductDetailsAsync(productIds, productTypes, + new ProductDetailsResponseListener() { + @Override + public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List list) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + int startID = billing.pushProductDetails(list); + GoogleBillingHelper.onProductDetailsResponse(tag, callbackId, billingResult, list, startID); + } + }); } - } - }); + }); } public static void launchBillingFlow(int tag, BillingFlowParams params) { - GlobalObject.runOnUiThread(new Runnable() { - @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.launchBillingFlow(params); + GoogleBilling billing = googleBillings.get(tag); + if (billing != null) { + GlobalObject.runOnUiThread(new Runnable() { + @Override + public void run() { + BillingResult res = billing.launchBillingFlow(params); + Log.i(TAG, String.format("BillingResult: ResponseCode : %d, DebugMessage : %s, ToString: %s", res.getResponseCode(), res.getDebugMessage(), res.toString())); } - } - }); + }); + } } public static void queryPurchasesAsync(int tag, int callbackId, String type) { - GlobalObject.runOnUiThread(new Runnable() { + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.queryPurchasesAsync(type, new PurchasesResponseListener() { @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.queryPurchasesAsync(type, new PurchasesResponseListener() { - @Override - public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List list) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - int startID = billing.pushPurchases(list); - GoogleBillingHelper.onQueryPurchasesResponse(tag, callbackId, billingResult, list, startID); - } - }); - } - }); - } + public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List list) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + int startID = billing.pushPurchases(list); + GoogleBillingHelper.onQueryPurchasesResponse(tag, callbackId, billingResult, list, startID); + } + }); } }); } public static void consumeAsync(int tag, int callbackId, String purchaseToken) { - GlobalObject.runOnUiThread(new Runnable() { + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.consumeAsync(purchaseToken, new ConsumeResponseListener() { @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.consumeAsync(purchaseToken, new ConsumeResponseListener() { - @Override - public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String s) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onConsumeResponse(tag, callbackId, billingResult, s); - } - }); - } - }); - } + public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String s) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onConsumeResponse(tag, callbackId, billingResult, s); + } + }); } }); } public static void acknowledgePurchase(int tag, int callbackId, String purchaseToken) { - GlobalObject.runOnUiThread(new Runnable() { + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.acknowledgePurchase(purchaseToken, new AcknowledgePurchaseResponseListener() { @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.acknowledgePurchase(purchaseToken, new AcknowledgePurchaseResponseListener() { - @Override - public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onAcknowledgePurchaseResponse(tag, callbackId, billingResult); - } - }); - } - }); - } + public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onAcknowledgePurchaseResponse(tag, callbackId, billingResult); + } + }); } }); } public static void getBillingConfigAsync(int tag, int callbackId) { - GlobalObject.runOnUiThread(new Runnable() { + GoogleBilling billing = googleBillings.get(tag); + if (billing == null) { + return; + } + billing.getBillingConfigAsync(new BillingConfigResponseListener() { @Override - public void run() { - GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - billing.getBillingConfigAsync(new BillingConfigResponseListener() { - @Override - public void onBillingConfigResponse(@NonNull BillingResult billingResult, @Nullable BillingConfig billingConfig) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onBillingConfigResponse(tag, callbackId, billingResult, billingConfig); - } - }); - } - }); - }; + public void onBillingConfigResponse(@NonNull BillingResult billingResult, @Nullable BillingConfig billingConfig) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onBillingConfigResponse(tag, callbackId, billingResult, billingConfig); + } + }); } }); } - public static BillingResult showAlternativeBillingOnlyInformationDialog(int tag, int callbackId) { + public static void showAlternativeBillingOnlyInformationDialog(int tag, int callbackId) { GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - return billing.showAlternativeBillingOnlyInformationDialog(new AlternativeBillingOnlyInformationDialogListener(){ - @Override - public void onAlternativeBillingOnlyInformationDialogResponse(@NonNull BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onAlternativeBillingOnlyInformationDialogResponse(tag, callbackId, billingResult); - } - }); - } - }); + if (billing == null) { + return; } - return BillingResult.newBuilder().build(); + GlobalObject.runOnUiThread(new Runnable() { + @Override + public void run() { + BillingResult res = billing.showAlternativeBillingOnlyInformationDialog(new AlternativeBillingOnlyInformationDialogListener() { + @Override + public void onAlternativeBillingOnlyInformationDialogResponse(@NonNull BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onAlternativeBillingOnlyInformationDialogResponse(tag, callbackId, billingResult); + } + }); + } + }); + Log.i(TAG, String.format("BillingResult: ResponseCode : %d, DebugMessage : %s, ToString: %s", res.getResponseCode(), res.getDebugMessage(), res.toString())); + } + }); } - public static BillingResult showExternalOfferInformationDialog(int tag, int callbackId) { + public static void showExternalOfferInformationDialog(int tag, int callbackId) { GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - return billing.showExternalOfferInformationDialog(new ExternalOfferInformationDialogListener() { - @Override - public void onExternalOfferInformationDialogResponse(@NonNull BillingResult billingResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onExternalOfferInformationDialogResponse(tag, callbackId, billingResult); - } - }); - } - }); + if (billing == null) { + return; } - return BillingResult.newBuilder().build(); + GlobalObject.runOnUiThread(new Runnable() { + @Override + public void run() { + BillingResult res = billing.showExternalOfferInformationDialog(new ExternalOfferInformationDialogListener() { + @Override + public void onExternalOfferInformationDialogResponse(@NonNull BillingResult billingResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onExternalOfferInformationDialogResponse(tag, callbackId, billingResult); + } + }); + } + }); + Log.i(TAG, String.format("BillingResult: ResponseCode : %d, DebugMessage : %s, ToString: %s", res.getResponseCode(), res.getDebugMessage(), res.toString())); + } + }); } - public static BillingResult showInAppMessages(int tag, int callbackId, int[] inAppMessageCategoryId) { + public static void showInAppMessages(int tag, int callbackId, int[] inAppMessageCategoryId) { GoogleBilling billing = googleBillings.get(tag); - if (billing != null) { - InAppMessageParams.Builder builder = InAppMessageParams.newBuilder(); - for(int i = 0; i < inAppMessageCategoryId.length; ++i) { - builder.addInAppMessageCategoryToShow(inAppMessageCategoryId[i]); - } - return billing.showInAppMessages(builder.build(), new InAppMessageResponseListener() { - @Override - public void onInAppMessageResponse(@NonNull InAppMessageResult inAppMessageResult) { - CocosHelper.runOnGameThread(new Runnable() { - @Override - public void run() { - GoogleBillingHelper.onInAppMessageResponse(tag, callbackId, inAppMessageResult); - } - }); - } - }); + if (billing == null) { + return; } - return BillingResult.newBuilder().build(); + GlobalObject.runOnUiThread(new Runnable() { + @Override + public void run() { + InAppMessageParams.Builder builder = InAppMessageParams.newBuilder(); + for(int i = 0; i < inAppMessageCategoryId.length; ++i) { + builder.addInAppMessageCategoryToShow(inAppMessageCategoryId[i]); + } + BillingResult res = billing.showInAppMessages(builder.build(), new InAppMessageResponseListener() { + @Override + public void onInAppMessageResponse(@NonNull InAppMessageResult inAppMessageResult) { + CocosHelper.runOnGameThread(new Runnable() { + @Override + public void run() { + GoogleBillingHelper.onInAppMessageResponse(tag, callbackId, inAppMessageResult); + } + }); + } + }); + Log.i(TAG, String.format("BillingResult: ResponseCode : %d, DebugMessage : %s, ToString: %s", res.getResponseCode(), res.getDebugMessage(), res.toString())); + } + }); } } diff --git a/native/vendor/google/billing/GoogleBilling.cpp b/native/vendor/google/billing/GoogleBilling.cpp index 892a97e1f27..f418302a03c 100644 --- a/native/vendor/google/billing/GoogleBilling.cpp +++ b/native/vendor/google/billing/GoogleBilling.cpp @@ -235,34 +235,31 @@ void BillingClient::isExternalOfferAvailableAsync(se::Object* listener) { GoogleBillingHelper::isExternalOfferAvailableAsync(_tag, listenerId); } -BillingResult* BillingClient::showAlternativeBillingOnlyInformationDialog(se::Object* listener) { +void BillingClient::showAlternativeBillingOnlyInformationDialog(se::Object* listener) { if(!listener) { - // Extending the return value of BillingResult.Normal behavior wouldn't get in here. - auto* builder = BillingResult::newBuilder(); - return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build(); + CC_LOG_WARNING("Listener can't be null"); + return; } int listenerId = addListener(listener); - return GoogleBillingHelper::showAlternativeBillingOnlyInformationDialog(_tag, listenerId); + GoogleBillingHelper::showAlternativeBillingOnlyInformationDialog(_tag, listenerId); } -BillingResult* BillingClient::showExternalOfferInformationDialog(se::Object* listener) { +void BillingClient::showExternalOfferInformationDialog(se::Object* listener) { if(!listener) { - // Extending the return value of BillingResult.Normal behavior wouldn't get in here. - auto* builder = BillingResult::newBuilder(); - return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build(); + CC_LOG_WARNING("Listener can't be null"); + return; } int listenerId = addListener(listener); return GoogleBillingHelper::showExternalOfferInformationDialog(_tag, listenerId); } -BillingResult* BillingClient::showInAppMessages(InAppMessageParams* params, se::Object* listener) { +void BillingClient::showInAppMessages(InAppMessageParams* params, se::Object* listener) { if(!params || !listener) { - // Extending the return value of BillingResult.Normal behavior wouldn't get in here. - auto* builder = BillingResult::newBuilder(); - return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build(); + CC_LOG_WARNING("InAppMessageParams and listener can't be null"); + return; } int listenerId = addListener(listener); - return GoogleBillingHelper::showInAppMessages(_tag, listenerId, params->_inAppMessageCategoryIds); + GoogleBillingHelper::showInAppMessages(_tag, listenerId, params->_inAppMessageCategoryIds); } } // namespace cc diff --git a/native/vendor/google/billing/GoogleBilling.h b/native/vendor/google/billing/GoogleBilling.h index 56040848389..c9322591692 100644 --- a/native/vendor/google/billing/GoogleBilling.h +++ b/native/vendor/google/billing/GoogleBilling.h @@ -90,9 +90,9 @@ class CC_DLL BillingClient : public cc::RefCounted { private: friend class BillingClient; friend class JniBilling; - bool _enableAlternativeBillingOnly; - bool _enableExternalOffer; - PendingPurchasesParams* _pendingPurchasesParams; + bool _enableAlternativeBillingOnly{false}; + bool _enableExternalOffer{false}; + PendingPurchasesParams* _pendingPurchasesParams{nullptr}; scopedListener _purchasesUpdatedListener; scopedListener _userChoiceBillingListener; }; @@ -116,9 +116,9 @@ class CC_DLL BillingClient : public cc::RefCounted { void createExternalOfferReportingDetailsAsync(se::Object* listener); void isExternalOfferAvailableAsync(se::Object* listener); BillingResult* isFeatureSupported(const std::string& feature); - BillingResult* showAlternativeBillingOnlyInformationDialog(se::Object* listener); - BillingResult* showExternalOfferInformationDialog(se::Object* listener); - BillingResult* showInAppMessages(InAppMessageParams* params, se::Object* listener); + void showAlternativeBillingOnlyInformationDialog(se::Object* listener); + void showExternalOfferInformationDialog(se::Object* listener); + void showInAppMessages(InAppMessageParams* params, se::Object* listener); private: BillingClient(Builder* builder); ~BillingClient(); diff --git a/native/vendor/google/billing/GoogleBillingHelper.cpp b/native/vendor/google/billing/GoogleBillingHelper.cpp index 233c439d3bc..825f7c164a4 100644 --- a/native/vendor/google/billing/GoogleBillingHelper.cpp +++ b/native/vendor/google/billing/GoogleBillingHelper.cpp @@ -104,7 +104,7 @@ int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) { } void GoogleBillingHelper::removeGoogleBilling(int tag) { - JniHelper::callStaticIntMethod(JCLS_BILLING, "removeGoogleBilling", tag); + JniHelper::callStaticVoidMethod(JCLS_BILLING, "removeGoogleBilling", tag); } void GoogleBillingHelper::removeProductDetails(int tag, int productDetailsID) { @@ -159,25 +159,23 @@ void GoogleBillingHelper::isExternalOfferAvailableAsync(int tag, int callbackId) JniHelper::callStaticVoidMethod(JCLS_BILLING, "isExternalOfferAvailableAsync", tag, callbackId); } -BillingResult* GoogleBillingHelper::showAlternativeBillingOnlyInformationDialog(int tag, int callbackId) { - return cc::JniBilling::callFunctionAndReturnBillingResult("showAlternativeBillingOnlyInformationDialog", tag, callbackId); +void GoogleBillingHelper::showAlternativeBillingOnlyInformationDialog(int tag, int callbackId) { + JniHelper::callStaticVoidMethod(JCLS_BILLING, "showAlternativeBillingOnlyInformationDialog", tag, callbackId); } -BillingResult* GoogleBillingHelper::showExternalOfferInformationDialog(int tag, int callbackId) { - return cc::JniBilling::callFunctionAndReturnBillingResult("showExternalOfferInformationDialog", tag, callbackId); +void GoogleBillingHelper::showExternalOfferInformationDialog(int tag, int callbackId) { + JniHelper::callStaticVoidMethod(JCLS_BILLING, "showExternalOfferInformationDialog", tag, callbackId); } -BillingResult* GoogleBillingHelper::showInAppMessages(int tag, int callbackId, const std::vector& inAppMessageCategoryId) { +void GoogleBillingHelper::showInAppMessages(int tag, int callbackId, const std::vector& inAppMessageCategoryId) { auto* env = JniHelper::getEnv(); cc::JniMethodInfo t; - if (cc::JniHelper::getStaticMethodInfo(t, JCLS_BILLING, "showInAppMessages", "(II[I)Lcom/android/billingclient/api/BillingResult;")) { + if (cc::JniHelper::getStaticMethodInfo(t, JCLS_BILLING, "showInAppMessages", "(II[I)V")) { const int size = inAppMessageCategoryId.size(); jintArray result = env->NewIntArray(size); env->SetIntArrayRegion(result, 0, inAppMessageCategoryId.size(), inAppMessageCategoryId.data()); - jobject obj = t.env->CallStaticObjectMethod(t.classID, t.methodID, tag, callbackId, result); - return cc::JniBilling::toBillingResult(env, obj); + t.env->CallStaticVoidMethod(t.classID, t.methodID, tag, callbackId, result); } - return nullptr; } void GoogleBillingHelper::launchBillingFlow(int tag, BillingFlowParams* params) { diff --git a/native/vendor/google/billing/GoogleBillingHelper.h b/native/vendor/google/billing/GoogleBillingHelper.h index ca504d990c4..00c1c95008f 100644 --- a/native/vendor/google/billing/GoogleBillingHelper.h +++ b/native/vendor/google/billing/GoogleBillingHelper.h @@ -73,9 +73,9 @@ class CC_DLL GoogleBillingHelper { static void isExternalOfferAvailableAsync(int tag, int callbackId); static BillingResult *isFeatureSupported(int tag, const std::string &feature); - static BillingResult *showAlternativeBillingOnlyInformationDialog(int tag, int callbackId); - static BillingResult *showExternalOfferInformationDialog(int tag, int callbackId); - static BillingResult *showInAppMessages(int tag, int callbackId, const std::vector& inAppMessageCategoryId); + static void showAlternativeBillingOnlyInformationDialog(int tag, int callbackId); + static void showExternalOfferInformationDialog(int tag, int callbackId); + static void showInAppMessages(int tag, int callbackId, const std::vector& inAppMessageCategoryId); static void onBillingSetupFinished(JNIEnv *env, jclass clazz, jint tag, jint callbackID, jobject billingResultObj); static void onBillingServiceDisconnected(JNIEnv *env, jclass clazz, jint tag, jint callbackID); diff --git a/native/vendor/google/billing/build-params/BillingFlowParams.h b/native/vendor/google/billing/build-params/BillingFlowParams.h index 6210be72e4c..7c50170b1eb 100644 --- a/native/vendor/google/billing/build-params/BillingFlowParams.h +++ b/native/vendor/google/billing/build-params/BillingFlowParams.h @@ -54,7 +54,7 @@ class CC_DLL BillingFlowParams : public cc::RefCounted { } private: - int _subscriptionReplacementMode; + int _subscriptionReplacementMode{0}; std::string _purchaseToken; std::string _externalTransactionId; }; @@ -67,7 +67,7 @@ class CC_DLL BillingFlowParams : public cc::RefCounted { : _subscriptionReplacementMode(subscriptionReplacementMode), _purchaseToken(purchaseToken), _externalTransactionId(externalTransactionId) { } friend class JniBilling; - int _subscriptionReplacementMode; + int _subscriptionReplacementMode{0}; std::string _purchaseToken; std::string _externalTransactionId; }; diff --git a/native/vendor/google/billing/build-params/PendingPurchasesParams.h b/native/vendor/google/billing/build-params/PendingPurchasesParams.h index 46cca559bc5..22a6c4bf0dc 100644 --- a/native/vendor/google/billing/build-params/PendingPurchasesParams.h +++ b/native/vendor/google/billing/build-params/PendingPurchasesParams.h @@ -35,8 +35,8 @@ class PendingPurchasesParams : public cc::RefCounted { public: class Builder : public cc::RefCounted { private: - bool _enableOneTimeProducts; - bool _enablePrepaidPlans; + bool _enableOneTimeProducts{false}; + bool _enablePrepaidPlans{false}; public: Builder& enableOneTimeProducts() { diff --git a/native/vendor/google/billing/result-values/BillingResult.h b/native/vendor/google/billing/result-values/BillingResult.h index db7794fdbf0..ae6fd521b14 100644 --- a/native/vendor/google/billing/result-values/BillingResult.h +++ b/native/vendor/google/billing/result-values/BillingResult.h @@ -59,10 +59,10 @@ class CC_DLL BillingResult : public cc::RefCounted { return *this; } BillingResult* build() { - auto* p = new BillingResult(); - p->_responseCode = _responseCode; - p->_debugMessage = _debugMessage; - return p; + auto* billingResult = new BillingResult(); + billingResult->_responseCode = _responseCode; + billingResult->_debugMessage = std::move(_debugMessage); + return billingResult; } }; static Builder* newBuilder() { diff --git a/native/vendor/google/billing/result-values/ProductDetails.h b/native/vendor/google/billing/result-values/ProductDetails.h index 54860fdadfc..9059f5e7003 100644 --- a/native/vendor/google/billing/result-values/ProductDetails.h +++ b/native/vendor/google/billing/result-values/ProductDetails.h @@ -77,11 +77,11 @@ class CC_DLL ProductDetails : public cc::RefCounted { } int getRecurrenceMode() const { - return _priceAmountMicros; + return _recurrenceMode; } long getPriceAmountMicros() const { - return _recurrenceMode; + return _priceAmountMicros; } std::string getBillingPeriod() const {