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 d73b278d1fc..8d345243c0a 100644 --- a/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java +++ b/native/cocos/platform/android/java/vendor/google/billing/GoogleBilling.java @@ -61,7 +61,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.List; import java.util.Map; -public class GoogleBilling { +public final class GoogleBilling { private static final String TAG = GoogleBilling.class.getSimpleName(); private Map _productDetails = new HashMap<>(); 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 a3db032a644..0f918209c0b 100644 --- a/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java +++ b/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java @@ -59,7 +59,7 @@ of this software and associated documentation files (the "Software"), to deal import android.util.SparseArray; import com.android.billingclient.api.BillingClientStateListener; -public class GoogleBillingHelper { +public final class GoogleBillingHelper { private static SparseArray googleBillings = new SparseArray(); private static int billingTag = 0; @@ -77,7 +77,7 @@ public void run() { }); } - public static int removeBillingClient(int tag) { + public static int removeGoogleBilling(int tag) { final int index = billingTag; GlobalObject.runOnUiThread(new Runnable() { @Override @@ -129,30 +129,30 @@ public void run() { } } - public static native void onBillingSetupFinished(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onBillingServiceDisconnected(int tag, int callbackId); - public static native void onProductDetailsResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull List productDetailsList, int startID); - public static native void onPurchasesUpdated(int tag, @NonNull BillingResult billingResult, @Nullable List purchasesList, int startID); - public static native void userSelectedAlternativeBilling(int tag, @NonNull UserChoiceDetails userChoiceDetails); - public static native void onQueryPurchasesResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull List purchasesList, int startID); - public static native void onConsumeResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull String purchaseToken); - public static native void onAcknowledgePurchaseResponse(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onBillingConfigResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @Nullable BillingConfig billingConfig); - - public static native void onAlternativeBillingOnlyTokenResponse(int tag, int callbackId, @NonNull BillingResult billingResult, + private static native void onBillingSetupFinished(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onBillingServiceDisconnected(int tag, int callbackId); + private static native void onProductDetailsResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull List productDetailsList, int startID); + private static native void onPurchasesUpdated(int tag, @NonNull BillingResult billingResult, @Nullable List purchasesList, int startID); + private static native void userSelectedAlternativeBilling(int tag, @NonNull UserChoiceDetails userChoiceDetails); + private static native void onQueryPurchasesResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull List purchasesList, int startID); + private static native void onConsumeResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @NonNull String purchaseToken); + private static native void onAcknowledgePurchaseResponse(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onBillingConfigResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @Nullable BillingConfig billingConfig); + + private static native void onAlternativeBillingOnlyTokenResponse(int tag, int callbackId, @NonNull BillingResult billingResult, @Nullable AlternativeBillingOnlyReportingDetails alternativeBillingOnlyReportingDetails); - public static native void onAlternativeBillingOnlyAvailabilityResponse(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onAlternativeBillingOnlyAvailabilityResponse(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onExternalOfferReportingDetailsResponse( + private static native void onExternalOfferReportingDetailsResponse( int tag, int callbackId, @NonNull BillingResult billingResult, @Nullable ExternalOfferReportingDetails externalOfferReportingDetails ); - public static native void onExternalOfferAvailabilityResponse(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onExternalOfferInformationDialogResponse(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onAlternativeBillingOnlyInformationDialogResponse(int tag, int callbackId, @NonNull BillingResult billingResult); - public static native void onInAppMessageResponse(int tag, int callbackId, @NonNull InAppMessageResult inAppMessageResult); + private static native void onExternalOfferAvailabilityResponse(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onExternalOfferInformationDialogResponse(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onAlternativeBillingOnlyInformationDialogResponse(int tag, int callbackId, @NonNull BillingResult billingResult); + private static native void onInAppMessageResponse(int tag, int callbackId, @NonNull InAppMessageResult inAppMessageResult); public static ProductDetails getProductDetailsObject(int tag, int productDetailsID) { GoogleBilling billing = googleBillings.get(tag); diff --git a/native/tools/swig-config/android/google_billing.i b/native/tools/swig-config/android/google_billing.i new file mode 100644 index 00000000000..96c333127bd --- /dev/null +++ b/native/tools/swig-config/android/google_billing.i @@ -0,0 +1,71 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// audio at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") billing + +// Disable some swig warnings, find warning number reference here ( https://www.swig.org/Doc4.1/Warnings.html ) +#pragma SWIG nowarn=503,302,401,317,402 + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "vendor/google/billing/GoogleBilling.h" +#include "vendor/google/billing/build-params/AcknowledgePurchaseParams.h" +#include "vendor/google/billing/build-params/BillingFlowParams.h" +#include "vendor/google/billing/build-params/ConsumeParams.h" +#include "vendor/google/billing/build-params/GetBillingConfigParams.h" +#include "vendor/google/billing/build-params/InAppMessageParams.h" +#include "vendor/google/billing/build-params/PendingPurchasesParams.h" +#include "vendor/google/billing/build-params/QueryProductDetailsParams.h" +#include "vendor/google/billing/build-params/QueryPurchasesParams.h" + +#include "vendor/google/billing/result-values/AccountIdentifiers.h" +#include "vendor/google/billing/result-values/AlternativeBillingOnlyReportingDetails.h" +#include "vendor/google/billing/result-values/BillingConfig.h" +#include "vendor/google/billing/result-values/BillingResult.h" +#include "vendor/google/billing/result-values/ExternalOfferReportingDetails.h" +#include "vendor/google/billing/result-values/InAppMessageResult.h" +#include "vendor/google/billing/result-values/Purchase.h" +#include "vendor/google/billing/result-values/ProductDetails.h" +#include "vendor/google/billing/result-values/UserChoiceDetails.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_google_billing_auto.h" +%} + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "vendor/google/billing/result-values/AccountIdentifiers.h" +%include "vendor/google/billing/result-values/AlternativeBillingOnlyReportingDetails.h" +%include "vendor/google/billing/result-values/BillingConfig.h" +%include "vendor/google/billing/result-values/BillingResult.h" +%include "vendor/google/billing/result-values/ExternalOfferReportingDetails.h" +%include "vendor/google/billing/result-values/InAppMessageResult.h" +%include "vendor/google/billing/result-values/Purchase.h" +%include "vendor/google/billing/result-values/ProductDetails.h" +%include "vendor/google/billing/result-values/UserChoiceDetails.h" + +%include "vendor/google/billing/build-params/AcknowledgePurchaseParams.h" +%include "vendor/google/billing/build-params/BillingFlowParams.h" +%include "vendor/google/billing/build-params/ConsumeParams.h" +%include "vendor/google/billing/build-params/GetBillingConfigParams.h" +%include "vendor/google/billing/build-params/InAppMessageParams.h" +%include "vendor/google/billing/build-params/PendingPurchasesParams.h" +%include "vendor/google/billing/build-params/QueryProductDetailsParams.h" +%include "vendor/google/billing/build-params/QueryPurchasesParams.h" + +%include "vendor/google/billing/GoogleBilling.h" + + diff --git a/native/vendor/google/billing/GoogleBilling.cpp b/native/vendor/google/billing/GoogleBilling.cpp index cfaf99c9429..17036101d97 100644 --- a/native/vendor/google/billing/GoogleBilling.cpp +++ b/native/vendor/google/billing/GoogleBilling.cpp @@ -70,8 +70,8 @@ BillingClient::BillingClient(Builder* builder) { BillingClient::~BillingClient() { CC_ASSERT(_tag >= 0); - GoogleBillingHelper::removeBillingClient(_tag); - GoogleBillingManager::getInstance()->removeBillingClient(_tag); + GoogleBillingHelper::removeGoogleBilling(_tag); + GoogleBillingManager::getInstance()->removeGoogleBilling(_tag); } void BillingClient::startConnection(se::Object* listener) { diff --git a/native/vendor/google/billing/GoogleBillingHelper.cpp b/native/vendor/google/billing/GoogleBillingHelper.cpp index 5d5de54b54c..0d3fbab9511 100644 --- a/native/vendor/google/billing/GoogleBillingHelper.cpp +++ b/native/vendor/google/billing/GoogleBillingHelper.cpp @@ -102,8 +102,8 @@ int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) { return tag; } -void GoogleBillingHelper::removeBillingClient(int tag) { - JniHelper::callStaticIntMethod(JCLS_BILLING, "removeBillingClient", tag); +void GoogleBillingHelper::removeGoogleBilling(int tag) { + JniHelper::callStaticIntMethod(JCLS_BILLING, "removeGoogleBilling", tag); } void GoogleBillingHelper::removeProductDetails(int tag, int productDetailsID) { diff --git a/native/vendor/google/billing/GoogleBillingHelper.h b/native/vendor/google/billing/GoogleBillingHelper.h index 174ab81619c..d98b23e9a3b 100644 --- a/native/vendor/google/billing/GoogleBillingHelper.h +++ b/native/vendor/google/billing/GoogleBillingHelper.h @@ -52,7 +52,7 @@ class AcknowledgePurchaseParams; class CC_DLL GoogleBillingHelper { public: static int createGoogleBilling(BillingClient::Builder* builder); - static void removeBillingClient(int tag); + static void removeGoogleBilling(int tag); static void removeProductDetails(int tag, int productDetailsID); static void removePurchase(int tag, int purchaseID); static void startConnection(int tag, int callbackID); diff --git a/native/vendor/google/billing/GoogleBillingManager.h b/native/vendor/google/billing/GoogleBillingManager.h index 612810e1b77..7b3411d4a31 100644 --- a/native/vendor/google/billing/GoogleBillingManager.h +++ b/native/vendor/google/billing/GoogleBillingManager.h @@ -43,7 +43,7 @@ class CC_DLL GoogleBillingManager { _billingClients.insert(std::make_pair(tag, client)); } - void removeBillingClient(int tag) { + void removeGoogleBilling(int tag) { auto it = _billingClients.find(tag); if(it != _billingClients.end()) { _billingClients.erase(it); diff --git a/vendor/google/billing/billing.ts b/vendor/google/billing/billing.ts index 035aa95e2c2..3973d33c413 100644 --- a/vendor/google/billing/billing.ts +++ b/vendor/google/billing/billing.ts @@ -30,25 +30,24 @@ declare const jsb: any; export namespace google { export namespace billing { - export const BillingClient = JSB ? jsb.BillingClient : null; - export const BillingResult = JSB ? jsb.BillingResult : null; + export const BillingClient = JSB ? jsb.BillingClient : null as unknown as typeof jsb.BillingClient; + export const BillingResult = JSB ? jsb.BillingResult : null as unknown as typeof jsb.BillingResult; - export const PendingPurchasesParams = JSB ? jsb.PendingPurchasesParams : null; + export const PendingPurchasesParams = JSB ? jsb.PendingPurchasesParams : null as unknown as typeof jsb.PendingPurchasesParams; // export const ProductDetailsParams = jsb.ProductDetailsParams; - export const QueryProductDetailsParams = JSB ? jsb.QueryProductDetailsParams : null; + export const QueryProductDetailsParams = JSB ? jsb.QueryProductDetailsParams : null as unknown as typeof jsb.QueryProductDetailsParams; - export const Product = JSB ? jsb.Product : null; - export const BillingFlowParams = JSB ? jsb.BillingFlowParams : null; + export const Product = JSB ? jsb.Product : null as unknown as typeof jsb.Product; + export const BillingFlowParams = JSB ? jsb.BillingFlowParams : null as unknown as typeof jsb.BillingFlowParams; - export const ConsumeParams = JSB ? jsb.ConsumeParams : null; - export const AcknowledgePurchaseParams = JSB ? jsb.AcknowledgePurchaseParams : null; - export const QueryPurchasesParams = JSB ? jsb.QueryPurchasesParams : null; - export const InAppMessageParams = JSB ? jsb.InAppMessageParams : null; - export const GetBillingConfigParams = JSB ? jsb.GetBillingConfigParams : null; + export const ConsumeParams = JSB ? jsb.ConsumeParams : null as unknown as typeof jsb.ConsumeParams; + export const AcknowledgePurchaseParams = JSB ? jsb.AcknowledgePurchaseParams : null as unknown as typeof jsb.AcknowledgePurchaseParams; + export const QueryPurchasesParams = JSB ? jsb.QueryPurchasesParams : null as unknown as typeof jsb.QueryPurchasesParams; + export const InAppMessageParams = JSB ? jsb.InAppMessageParams : null as unknown as typeof jsb.InAppMessageParams; + export const GetBillingConfigParams = JSB ? jsb.GetBillingConfigParams : null as unknown as typeof jsb.GetBillingConfigParams; } } - export declare namespace google { export namespace billing { export type UserChoiceDetails = jsb.UserChoiceDetails;