From 0fec767bd99fbdbfe212f4aef889dcfd75dc1e6e Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Thu, 12 Dec 2024 16:06:25 +0800 Subject: [PATCH] Optimized code --- .../google/billing/GoogleBillingHelper.java | 6 +- .../vendor/google/billing/GoogleBilling.cpp | 8 ++- .../google/billing/GoogleBillingHelper.cpp | 68 +++++++++---------- native/vendor/google/billing/JniBilling.cpp | 10 +-- native/vendor/google/billing/JniBilling.h | 10 +-- .../build-params/AcknowledgePurchaseParams.h | 9 ++- .../billing/build-params/BillingFlowParams.h | 64 ++++++++++------- .../billing/build-params/ConsumeParams.h | 9 ++- .../build-params/GetBillingConfigParams.h | 4 +- .../billing/build-params/InAppMessageParams.h | 13 ++-- .../build-params/PendingPurchasesParams.h | 17 +++-- .../build-params/QueryProductDetailsParams.h | 33 ++++----- .../build-params/QueryPurchasesParams.h | 9 ++- .../billing/result-values/BillingConfig.h | 2 +- .../billing/result-values/BillingResult.h | 4 +- .../billing/result-values/ProductDetails.h | 1 + 16 files changed, 132 insertions(+), 135 deletions(-) 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 0f918209c0b..599ba1df080 100644 --- a/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java +++ b/native/cocos/platform/android/java/vendor/google/billing/GoogleBillingHelper.java @@ -172,14 +172,14 @@ public static void removeProductDetails(int tag, int productDetailsId) { public static void removePurchase(int tag, int purchaseID) { GoogleBilling billing = googleBillings.get(tag); if (billing != null) { - billing.removeProductDetails(purchaseID); + billing.removePurchase(purchaseID); } } - public static ProductDetails getPurchase(int tag, int purchaseId) { + public static Purchase getPurchase(int tag, int purchaseId) { GoogleBilling billing = googleBillings.get(tag); if (billing != null) { - return billing.getProductDetails(purchaseId); + return billing.getPurchase(purchaseId); } return null; } diff --git a/native/vendor/google/billing/GoogleBilling.cpp b/native/vendor/google/billing/GoogleBilling.cpp index 3f1dcbef424..a2c7c4b6f07 100644 --- a/native/vendor/google/billing/GoogleBilling.cpp +++ b/native/vendor/google/billing/GoogleBilling.cpp @@ -135,13 +135,15 @@ bool BillingClient::isReady() const { void BillingClient::queryProductDetailsAsync(QueryProductDetailsParams* params, se::Object* listener) { int listenerId = addListener(listener); - std::vector productIDs; + std::vector productIds; std::vector productTypes; + productIds.reserve(16); + productTypes.reserve(16); for (auto product : params->_productList) { - productIDs.push_back(product->_productID); + productIds.push_back(product->_productId); productTypes.push_back(product->_productType); } - GoogleBillingHelper::queryProductDetailsAsync(_tag, listenerId, productIDs, productTypes); + GoogleBillingHelper::queryProductDetailsAsync(_tag, listenerId, productIds, productTypes); } void BillingClient::launchBillingFlow(BillingFlowParams* params) { diff --git a/native/vendor/google/billing/GoogleBillingHelper.cpp b/native/vendor/google/billing/GoogleBillingHelper.cpp index 62c33284601..233c439d3bc 100644 --- a/native/vendor/google/billing/GoogleBillingHelper.cpp +++ b/native/vendor/google/billing/GoogleBillingHelper.cpp @@ -34,12 +34,12 @@ #include "cocos/bindings/manual/jsb_conversions.h" #include "cocos/bindings/manual/jsb_global_init.h" #include "vendor/google/billing/GoogleBilling.h" -#include "vendor/google/billing/JniBilling.h" #include "vendor/google/billing/GoogleBillingManager.h" -#include "vendor/google/billing/result-values/Purchase.h" +#include "vendor/google/billing/JniBilling.h" #include "vendor/google/billing/build-params/AcknowledgePurchaseParams.h" -#include "vendor/google/billing/result-values/ProductDetails.h" #include "vendor/google/billing/build-params/ConsumeParams.h" +#include "vendor/google/billing/result-values/ProductDetails.h" +#include "vendor/google/billing/result-values/Purchase.h" namespace { #ifndef JCLS_BILLING @@ -48,7 +48,7 @@ namespace { }; // namespace namespace cc { - +namespace { void invokeJsCallback(se::Object* obj, const char* jsFunctionName, const se::ValueArray& args) { if (!obj) { return; @@ -63,7 +63,7 @@ void invokeJsCallback(se::Object* obj, const char* jsFunctionName, const se::Val } template -void callJSfunc(se::Object* obj, const char* jsFunctionName, Args&&... inargs) { // NOLINT(readability-identifier-naming) +void callJSfunc(se::Object* obj, const char* jsFunctionName, Args&&... inargs) { // NOLINT(readability-identifier-naming) if (!se::ScriptEngine::getInstance()->isValid()) { return; } @@ -90,6 +90,7 @@ template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, Billing template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, AlternativeBillingOnlyReportingDetails*&&); template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, ExternalOfferReportingDetails*&&); template void callJSfunc(se::Object* obj, const char*, InAppMessageResult*&&); +} // namespace int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) { int tag = JniHelper::callStaticIntMethod(JCLS_BILLING, "newTag"); @@ -103,7 +104,7 @@ int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) { } void GoogleBillingHelper::removeGoogleBilling(int tag) { - JniHelper::callStaticIntMethod(JCLS_BILLING, "removeGoogleBilling", tag); + JniHelper::callStaticIntMethod(JCLS_BILLING, "removeGoogleBilling", tag); } void GoogleBillingHelper::removeProductDetails(int tag, int productDetailsID) { @@ -114,7 +115,6 @@ void GoogleBillingHelper::removePurchase(int tag, int purchaseID) { JniHelper::callStaticVoidMethod(JCLS_BILLING, "removePurchase", tag, purchaseID); } - void GoogleBillingHelper::startConnection(int tag, int callbackId) { JniHelper::callStaticVoidMethod(JCLS_BILLING, "startConnection", tag, callbackId); } @@ -135,7 +135,7 @@ void GoogleBillingHelper::queryProductDetailsAsync(int tag, int callbackId, cons JniHelper::callStaticVoidMethod(JCLS_BILLING, "queryProductDetailsAsync", tag, callbackId, productIds, productTypes); } -void GoogleBillingHelper::queryPurchasesAsync(int tag, int callbackId, const std::string& productType) { +void GoogleBillingHelper::queryPurchasesAsync(int tag, int callbackId, const std::string& productType) { JniHelper::callStaticVoidMethod(JCLS_BILLING, "queryPurchasesAsync", tag, callbackId, productType); } @@ -173,12 +173,7 @@ BillingResult* GoogleBillingHelper::showInAppMessages(int tag, int callbackId, c if (cc::JniHelper::getStaticMethodInfo(t, JCLS_BILLING, "showInAppMessages", "(II[I)Lcom/android/billingclient/api/BillingResult;")) { const int size = inAppMessageCategoryId.size(); jintArray result = env->NewIntArray(size); - jint* buf = new jint[size]; - for (int i = 0; i < size; ++i) { - buf[i] = inAppMessageCategoryId[i]; - } - env->SetIntArrayRegion(result, 0, size, buf); - delete[] buf; + 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); } @@ -224,7 +219,7 @@ void GoogleBillingHelper::onBillingServiceDisconnected(JNIEnv* env, jclass clazz auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { cc::callJSfunc(it->second.get(), "onBillingServiceDisconnected"); billingClient->_listeners.erase(it); } @@ -232,15 +227,15 @@ void GoogleBillingHelper::onBillingServiceDisconnected(JNIEnv* env, jclass clazz } void GoogleBillingHelper::onProductDetailsResponse(JNIEnv* env, jclass clazz, - jint tag, - jint callbackId, - jobject billingResultObj, - jobject productDetailsListObj, - jint startID) { + jint tag, + jint callbackId, + jobject billingResultObj, + jobject productDetailsListObj, + jint startID) { auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); std::vector productDetailsList = cc::JniBilling::toProductDetailList(env, productDetailsListObj, tag, startID); cc::callJSfunc(it->second.get(), "onProductDetailsResponse", billingResult, productDetailsList); @@ -250,10 +245,10 @@ void GoogleBillingHelper::onProductDetailsResponse(JNIEnv* env, jclass clazz, } void GoogleBillingHelper::onPurchasesUpdated(JNIEnv* env, jclass clazz, - jint tag, - jobject billingResultObj, - jobject purchasesListObj, - jint startID) { + jint tag, + jobject billingResultObj, + jobject purchasesListObj, + jint startID) { auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient && billingClient->_purchasesUpdatedListener) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); @@ -265,21 +260,21 @@ void GoogleBillingHelper::onPurchasesUpdated(JNIEnv* env, jclass clazz, } } - void GoogleBillingHelper::userSelectedAlternativeBilling(JNIEnv *env, jclass clazz, jint tag, jobject userChoiceDetailsObj) { +void GoogleBillingHelper::userSelectedAlternativeBilling(JNIEnv* env, jclass clazz, jint tag, jobject userChoiceDetailsObj) { auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient && billingClient->_userChoiceBillingListener) { auto* userChoiceDetails = cc::JniBilling::toUserChoiceDetails(env, userChoiceDetailsObj); cc::callJSfunc(billingClient->_userChoiceBillingListener.get(), "userSelectedAlternativeBilling", userChoiceDetails); } - } +} void GoogleBillingHelper::onConsumeResponse(JNIEnv* env, jclass clazz, jint tag, jint callbackId, jobject billingResultObj, jstring purchaseToken) { auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { - auto *billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); - cc::callJSfunc(it->second.get(), "onConsumeResponse", billingResult, cc::StringUtils::getStringUTFCharsJNI(env,static_cast(purchaseToken))); + if (it != billingClient->_listeners.end()) { + auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); + cc::callJSfunc(it->second.get(), "onConsumeResponse", billingResult, cc::StringUtils::getStringUTFCharsJNI(env, static_cast(purchaseToken))); billingClient->_listeners.erase(it); } } @@ -293,7 +288,7 @@ void GoogleBillingHelper::onQueryPurchasesResponse(JNIEnv* env, jclass clazz, ji auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); std::vector purchasesList = cc::JniBilling::toPurchaseList(env, purchasesListObj, tag, startID); cc::callJSfunc(it->second.get(), "onQueryPurchasesResponse", billingResult, purchasesList); @@ -306,7 +301,7 @@ void GoogleBillingHelper::onBillingConfigResponse(JNIEnv* env, jclass clazz, jin auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); cc::BillingConfig* billingConfig = nullptr; if (billingConfigObj) { @@ -322,7 +317,7 @@ void GoogleBillingHelper::onAlternativeBillingOnlyTokenResponse(JNIEnv* env, jcl auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); cc::AlternativeBillingOnlyReportingDetails* toAlternativeBillingOnlyReporting = nullptr; if (alternativeBillingOnlyReportingDetailsObj) { @@ -338,7 +333,7 @@ void GoogleBillingHelper::onExternalOfferReportingDetailsResponse(JNIEnv* env, j auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); cc::ExternalOfferReportingDetails* externalOfferReportingDetails = nullptr; if (externalOfferReportingDetailsObj) { @@ -370,7 +365,7 @@ void GoogleBillingHelper::onInAppMessageResponse(JNIEnv* env, jclass clazz, jint auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* inAppMessageResult = cc::JniBilling::toInAppMessageResult(env, inAppMessageResultObj); cc::callJSfunc(it->second.get(), "onInAppMessageResponse", inAppMessageResult); billingClient->_listeners.erase(it); @@ -382,7 +377,7 @@ void GoogleBillingHelper::responseOnlyWithBillingResult(const std::string& funct auto* billingClient = GoogleBillingManager::getInstance()->getBillingClient(tag); if (billingClient) { auto it = billingClient->_listeners.find(callbackId); - if(it != billingClient->_listeners.end()) { + if (it != billingClient->_listeners.end()) { auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj); cc::callJSfunc(it->second.get(), functionName.c_str(), billingResult); billingClient->_listeners.erase(it); @@ -390,5 +385,4 @@ void GoogleBillingHelper::responseOnlyWithBillingResult(const std::string& funct } } - } // namespace cc diff --git a/native/vendor/google/billing/JniBilling.cpp b/native/vendor/google/billing/JniBilling.cpp index e1722d0704a..36634d785ad 100644 --- a/native/vendor/google/billing/JniBilling.cpp +++ b/native/vendor/google/billing/JniBilling.cpp @@ -360,7 +360,7 @@ BillingResult* JniBilling::callFunctionAndReturnBillingResult(const std::string& return nullptr; } -jobject JniBilling::newSubscriptionUpdateParamsObject(BillingFlowParams::SubscriptionUpdateParams* params) { +jobject JniBilling::newSubscriptionUpdateParamsObject(const BillingFlowParams::SubscriptionUpdateParams* params) { if(!params) { return nullptr; } @@ -383,7 +383,7 @@ jobject JniBilling::newSubscriptionUpdateParamsObject(BillingFlowParams::Subscri return env->CallObjectMethod(builder, buildMethodIdMethodId); } -jobject JniBilling::newProductDetailsParamsObject(int tag, BillingFlowParams::ProductDetailsParams* params) { +jobject JniBilling::newProductDetailsParamsObject(int tag, const BillingFlowParams::ProductDetailsParams* params) { auto* env = JniHelper::getEnv(); cc::JniMethodInfo t; cc::JniHelper::getStaticMethodInfo(t, "com/android/billingclient/api/BillingFlowParams$ProductDetailsParams", "newBuilder", "()Lcom/android/billingclient/api/BillingFlowParams$ProductDetailsParams$Builder;"); @@ -419,7 +419,7 @@ jobject JniBilling::newProductDetailsParamsListObject(int tag, std::vectorCallObjectMethod(builder, buildMethodId); } -jobject JniBilling::newPendingPurchasesParamsObject(PendingPurchasesParams* params) { +jobject JniBilling::newPendingPurchasesParamsObject(const PendingPurchasesParams* params) { auto* env = JniHelper::getEnv(); cc::JniMethodInfo t; cc::JniHelper::getStaticMethodInfo(t, "com/android/billingclient/api/PendingPurchasesParams", "newBuilder", "()Lcom/android/billingclient/api/PendingPurchasesParams$Builder;"); @@ -487,7 +487,7 @@ jobject JniBilling::newUserChoiceBillingListenerObj(int tag) { return newCustomListenerObject(tag, "BillingClientUserChoiceBillingListener"); } -jobject JniBilling::newBillingClientBuilderObject(int tag, BillingClient::Builder* params) { +jobject JniBilling::newBillingClientBuilderObject(int tag, const BillingClient::Builder* params) { auto* env = JniHelper::getEnv(); cc::JniMethodInfo t; auto *javaGameActivity = cc::JniHelper::getActivity(); diff --git a/native/vendor/google/billing/JniBilling.h b/native/vendor/google/billing/JniBilling.h index bd49a503e2d..556b2f920b4 100644 --- a/native/vendor/google/billing/JniBilling.h +++ b/native/vendor/google/billing/JniBilling.h @@ -67,16 +67,16 @@ class CC_DLL JniBilling { static UserChoiceDetails* toUserChoiceDetails(JNIEnv* env, jobject obj); - static jobject newBillingFlowParamsObject(int tag, BillingFlowParams* params); - static jobject newBillingClientBuilderObject(int tag, BillingClient::Builder* params); + static jobject newBillingFlowParamsObject(int tag, const BillingFlowParams* params); + static jobject newBillingClientBuilderObject(int tag, const BillingClient::Builder* params); private: - static jobject newSubscriptionUpdateParamsObject(BillingFlowParams::SubscriptionUpdateParams* params); - static jobject newProductDetailsParamsObject(int tag, BillingFlowParams::ProductDetailsParams* params); + static jobject newSubscriptionUpdateParamsObject(const BillingFlowParams::SubscriptionUpdateParams* params); + static jobject newProductDetailsParamsObject(int tag, const BillingFlowParams::ProductDetailsParams* params); static jobject newProductDetailsParamsListObject(int tag, std::vector listParams); static jobject newPurchaseUpdateListenerObject(int tag); static jobject newUserChoiceBillingListenerObj(int tag); - static jobject newPendingPurchasesParamsObject(PendingPurchasesParams* params); + static jobject newPendingPurchasesParamsObject(const PendingPurchasesParams* params); static jobject newCustomListenerObject(int tag, const std::string& functionName); }; diff --git a/native/vendor/google/billing/build-params/AcknowledgePurchaseParams.h b/native/vendor/google/billing/build-params/AcknowledgePurchaseParams.h index bb84b83b510..58656634bc1 100644 --- a/native/vendor/google/billing/build-params/AcknowledgePurchaseParams.h +++ b/native/vendor/google/billing/build-params/AcknowledgePurchaseParams.h @@ -30,9 +30,9 @@ #include "base/RefCounted.h" namespace cc { -class AcknowledgePurchaseParams { +class AcknowledgePurchaseParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: Builder& setPurchaseToken(const std::string& purchaseToken) { _purchaseToken = purchaseToken; @@ -40,7 +40,7 @@ class AcknowledgePurchaseParams { } AcknowledgePurchaseParams* build() { - return new AcknowledgePurchaseParams(_purchaseToken); + return new AcknowledgePurchaseParams(std::move(_purchaseToken)); } private: @@ -56,8 +56,7 @@ class AcknowledgePurchaseParams { } private: - AcknowledgePurchaseParams(const std::string& purchaseToken) { - _purchaseToken = purchaseToken; + AcknowledgePurchaseParams(const std::string&& purchaseToken): _purchaseToken(purchaseToken) { } std::string _purchaseToken; diff --git a/native/vendor/google/billing/build-params/BillingFlowParams.h b/native/vendor/google/billing/build-params/BillingFlowParams.h index a41932885e3..6210be72e4c 100644 --- a/native/vendor/google/billing/build-params/BillingFlowParams.h +++ b/native/vendor/google/billing/build-params/BillingFlowParams.h @@ -31,11 +31,11 @@ #include "vendor/google/billing/result-values/ProductDetails.h" namespace cc { -class CC_DLL BillingFlowParams { +class CC_DLL BillingFlowParams : public cc::RefCounted { public: - class SubscriptionUpdateParams { + class SubscriptionUpdateParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: Builder& setOldPurcchaseToken(const std::string& purchaseToken) { _purchaseToken = purchaseToken; @@ -50,7 +50,7 @@ class CC_DLL BillingFlowParams { return *this; } SubscriptionUpdateParams* build() { - return new SubscriptionUpdateParams(_subscriptionReplacementMode, _purchaseToken, _externalTransactionId); + return new SubscriptionUpdateParams(_subscriptionReplacementMode, std::move(_purchaseToken), std::move(_externalTransactionId)); } private: @@ -63,10 +63,8 @@ class CC_DLL BillingFlowParams { } private: - SubscriptionUpdateParams(int subscriptionReplacementMode, const std::string& purchaseToken, const std::string& externalTransactionId) { - _subscriptionReplacementMode = subscriptionReplacementMode; - _purchaseToken = purchaseToken; - _externalTransactionId = externalTransactionId; + SubscriptionUpdateParams(int subscriptionReplacementMode, const std::string&& purchaseToken, const std::string&& externalTransactionId) + : _subscriptionReplacementMode(subscriptionReplacementMode), _purchaseToken(purchaseToken), _externalTransactionId(externalTransactionId) { } friend class JniBilling; int _subscriptionReplacementMode; @@ -74,20 +72,35 @@ class CC_DLL BillingFlowParams { std::string _externalTransactionId; }; - class ProductDetailsParams { + class ProductDetailsParams : public cc::RefCounted { public: - class Builder { + ~ProductDetailsParams() { + if (_productDetails) { + _productDetails->release(); + } + _productDetails = nullptr; + } + class Builder : public cc::RefCounted { public: + ~Builder() { + if (_productDetails) { + _productDetails->release(); + } + _productDetails = nullptr; + } Builder& setOfferToken(const std::string& offerToken) { _offerToken = offerToken; return *this; } Builder& setProductDetails(ProductDetails* productDetails) { _productDetails = productDetails; + if (_productDetails) { + _productDetails->addRef(); + } return *this; } ProductDetailsParams* build() { - return new ProductDetailsParams(_offerToken, _productDetails); + return new ProductDetailsParams(std::move(_offerToken), _productDetails); } private: @@ -100,16 +113,17 @@ class CC_DLL BillingFlowParams { private: friend class JniBilling; - ProductDetailsParams(std::string offerToken, ProductDetails* productDetails) { - _offerToken = offerToken; - _productDetails = productDetails; + ProductDetailsParams(const std::string&& offerToken, ProductDetails* productDetails) : _offerToken(offerToken), _productDetails(productDetails) { + if (_productDetails) { + _productDetails->addRef(); + } } std::string _offerToken; ProductDetails* _productDetails{nullptr}; }; - class Builder { + class Builder : public cc::RefCounted { public: Builder& setIsOfferPersonalized(bool isOfferPersonalized) { _isOfferPersonalized = isOfferPersonalized; @@ -132,7 +146,11 @@ class CC_DLL BillingFlowParams { return *this; } BillingFlowParams* build() { - return new BillingFlowParams(_isOfferPersonalized, _obfuscatedAccountid, _obfuscatedProfileId, _productDetailsParamsList, _subscriptionUpdateParams); + return new BillingFlowParams(_isOfferPersonalized, + std::move(_obfuscatedAccountid), + std::move(_obfuscatedProfileId), + std::move(_productDetailsParamsList), + _subscriptionUpdateParams); } private: @@ -151,15 +169,11 @@ class CC_DLL BillingFlowParams { friend class GoogleBillingHelper; friend class JniBilling; BillingFlowParams(bool isOfferPersonalized, - const std::string& obfuscatedAccountid, - const std::string& obfuscatedProfileId, - const std::vector& productDetailsParamsList, - SubscriptionUpdateParams* subscriptionUpdateParams) { - _isOfferPersonalized = isOfferPersonalized; - _obfuscatedAccountid = obfuscatedAccountid; - _obfuscatedProfileId = obfuscatedProfileId; - _productDetailsParamsList = productDetailsParamsList; - _subscriptionUpdateParams = subscriptionUpdateParams; + const std::string&& obfuscatedAccountid, + const std::string&& obfuscatedProfileId, + const std::vector&& productDetailsParamsList, + SubscriptionUpdateParams* subscriptionUpdateParams) + : _isOfferPersonalized(isOfferPersonalized), _obfuscatedAccountid(obfuscatedAccountid), _obfuscatedProfileId(obfuscatedProfileId), _productDetailsParamsList(productDetailsParamsList), _subscriptionUpdateParams(subscriptionUpdateParams) { } bool _isOfferPersonalized{false}; std::string _obfuscatedAccountid; diff --git a/native/vendor/google/billing/build-params/ConsumeParams.h b/native/vendor/google/billing/build-params/ConsumeParams.h index 0210d6f14e2..9dbf5f03a39 100644 --- a/native/vendor/google/billing/build-params/ConsumeParams.h +++ b/native/vendor/google/billing/build-params/ConsumeParams.h @@ -31,9 +31,9 @@ namespace cc { -class ConsumeParams { +class ConsumeParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: Builder& setPurchaseToken(const std::string& purchaseToken) { _purchaseToken = purchaseToken; @@ -41,7 +41,7 @@ class ConsumeParams { } ConsumeParams* build() { - return new ConsumeParams(_purchaseToken); + return new ConsumeParams(std::move(_purchaseToken)); } private: @@ -57,8 +57,7 @@ class ConsumeParams { } private: - ConsumeParams(const std::string& purchaseToken) { - _purchaseToken = purchaseToken; + ConsumeParams(const std::string&& purchaseToken) : _purchaseToken(purchaseToken) { } std::string _purchaseToken; diff --git a/native/vendor/google/billing/build-params/GetBillingConfigParams.h b/native/vendor/google/billing/build-params/GetBillingConfigParams.h index 4fc7f82232b..32906960e86 100644 --- a/native/vendor/google/billing/build-params/GetBillingConfigParams.h +++ b/native/vendor/google/billing/build-params/GetBillingConfigParams.h @@ -31,9 +31,9 @@ namespace cc { -class GetBillingConfigParams { +class GetBillingConfigParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: GetBillingConfigParams* build() { return new GetBillingConfigParams(); diff --git a/native/vendor/google/billing/build-params/InAppMessageParams.h b/native/vendor/google/billing/build-params/InAppMessageParams.h index 107778d263f..4a39357e763 100644 --- a/native/vendor/google/billing/build-params/InAppMessageParams.h +++ b/native/vendor/google/billing/build-params/InAppMessageParams.h @@ -31,22 +31,22 @@ namespace cc { -class InAppMessageParams { +class InAppMessageParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: Builder& addAllInAppMessageCategoriesToShow() { - this->_inAppMessageCategoryIds.push_back(2); + _inAppMessageCategoryIds.push_back(2); return *this; } Builder& addInAppMessageCategoryToShow(int inAppMessageCategoryId) { - this->_inAppMessageCategoryIds.push_back(inAppMessageCategoryId); + _inAppMessageCategoryIds.push_back(inAppMessageCategoryId); return *this; } InAppMessageParams* build() { - return new InAppMessageParams(this->_inAppMessageCategoryIds); + return new InAppMessageParams(std::move(_inAppMessageCategoryIds)); } private: @@ -58,8 +58,7 @@ class InAppMessageParams { } private: - InAppMessageParams(const std::vector& inAppMessageCategoryIds) { - this->_inAppMessageCategoryIds = inAppMessageCategoryIds; + InAppMessageParams(const std::vector&& inAppMessageCategoryIds):_inAppMessageCategoryIds(inAppMessageCategoryIds) { } friend class BillingClient; std::vector _inAppMessageCategoryIds; diff --git a/native/vendor/google/billing/build-params/PendingPurchasesParams.h b/native/vendor/google/billing/build-params/PendingPurchasesParams.h index d8c077f0dad..46cca559bc5 100644 --- a/native/vendor/google/billing/build-params/PendingPurchasesParams.h +++ b/native/vendor/google/billing/build-params/PendingPurchasesParams.h @@ -31,27 +31,27 @@ namespace cc { -class PendingPurchasesParams { +class PendingPurchasesParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { private: bool _enableOneTimeProducts; bool _enablePrepaidPlans; public: Builder& enableOneTimeProducts() { - this->_enableOneTimeProducts = true; + _enableOneTimeProducts = true; return *this; } Builder& enablePrepaidPlans() { - this->_enablePrepaidPlans = true; + _enablePrepaidPlans = true; return *this; } PendingPurchasesParams* build() { - if (!this->_enableOneTimeProducts) { + if (!_enableOneTimeProducts) { return nullptr; } - return new PendingPurchasesParams(this->_enableOneTimeProducts, this->_enablePrepaidPlans); + return new PendingPurchasesParams(_enableOneTimeProducts, _enablePrepaidPlans); } }; @@ -60,9 +60,8 @@ class PendingPurchasesParams { } private: - PendingPurchasesParams(bool enableOneTimeProducts, bool enablePrepaidPlans) { - this->_enableOneTimeProducts = enableOneTimeProducts; - this->_enablePrepaidPlans = enablePrepaidPlans; + PendingPurchasesParams(bool enableOneTimeProducts, bool enablePrepaidPlans) + :_enableOneTimeProducts(enableOneTimeProducts), _enablePrepaidPlans(enablePrepaidPlans) { } private: diff --git a/native/vendor/google/billing/build-params/QueryProductDetailsParams.h b/native/vendor/google/billing/build-params/QueryProductDetailsParams.h index 430ecdd9cee..35b7efb2ad1 100644 --- a/native/vendor/google/billing/build-params/QueryProductDetailsParams.h +++ b/native/vendor/google/billing/build-params/QueryProductDetailsParams.h @@ -30,29 +30,26 @@ #include "base/RefCounted.h" namespace cc { -class QueryProductDetailsParams { +class QueryProductDetailsParams : public cc::RefCounted { public: class Product { public: - class Builder { + class Builder : public cc::RefCounted { private: - std::string _productID; + std::string _productId; std::string _productType; public: - Builder& setProductId(const std::string& productID) { - this->_productID = productID; + Builder& setProductId(const std::string& productId) { + _productId = productId; return *this; } Builder& setProductType(const std::string& productType) { - this->_productType = productType; + _productType = productType; return *this; } Product* build() { - if (_productID.empty()) { - } else if (_productType.empty()) { - } - return new Product(_productID, _productType); + return new Product(std::move(_productId), std::move(_productType)); } }; @@ -61,17 +58,15 @@ class QueryProductDetailsParams { } private: - Product(const std::string& productID, const std::string& productType) { - this->_productID = productID; - this->_productType = productType; + Product(const std::string& productId, const std::string& productType) : _productId(productId), _productType(productType) { } private: friend class BillingClient; - std::string _productID; + std::string _productId; std::string _productType; }; - class Builder { + class Builder : public cc::RefCounted { private: std::vector _productList; @@ -82,10 +77,7 @@ class QueryProductDetailsParams { } QueryProductDetailsParams* build() { - if (this->_productList.empty()) { - return nullptr; - } - return new QueryProductDetailsParams(this->_productList); + return new QueryProductDetailsParams(std::move(_productList)); } }; @@ -94,8 +86,7 @@ class QueryProductDetailsParams { } private: - QueryProductDetailsParams(const std::vector& productLists) { - _productList = productLists; + QueryProductDetailsParams(const std::vector&& productLists) : _productList(productLists) { } private: diff --git a/native/vendor/google/billing/build-params/QueryPurchasesParams.h b/native/vendor/google/billing/build-params/QueryPurchasesParams.h index 588d3ed5957..f25869ecdd6 100644 --- a/native/vendor/google/billing/build-params/QueryPurchasesParams.h +++ b/native/vendor/google/billing/build-params/QueryPurchasesParams.h @@ -31,9 +31,9 @@ namespace cc { -class QueryPurchasesParams { +class QueryPurchasesParams : public cc::RefCounted { public: - class Builder { + class Builder : public cc::RefCounted { public: Builder& setProductType(const std::string& productType) { _productType = productType; @@ -41,7 +41,7 @@ class QueryPurchasesParams { } QueryPurchasesParams* build() { - return new QueryPurchasesParams(_productType); + return new QueryPurchasesParams(std::move(_productType)); } private: @@ -53,8 +53,7 @@ class QueryPurchasesParams { } private: - QueryPurchasesParams(const std::string& productType) { - _productType = productType; + QueryPurchasesParams(const std::string& productType): _productType(productType) { } friend class BillingClient; std::string _productType; diff --git a/native/vendor/google/billing/result-values/BillingConfig.h b/native/vendor/google/billing/result-values/BillingConfig.h index d3c8deb6f02..28a38b06632 100644 --- a/native/vendor/google/billing/result-values/BillingConfig.h +++ b/native/vendor/google/billing/result-values/BillingConfig.h @@ -36,7 +36,7 @@ class CC_DLL BillingConfig : public cc::RefCounted { std::string getCountryCode() const { return _countryCode; } - static BillingConfig* forCountryCode(const std::string countryCode) { + static BillingConfig* forCountryCode(const std::string& countryCode) { return new BillingConfig(countryCode); } diff --git a/native/vendor/google/billing/result-values/BillingResult.h b/native/vendor/google/billing/result-values/BillingResult.h index 81c55176851..db7794fdbf0 100644 --- a/native/vendor/google/billing/result-values/BillingResult.h +++ b/native/vendor/google/billing/result-values/BillingResult.h @@ -43,14 +43,14 @@ class CC_DLL BillingResult : public cc::RefCounted { std::string toString() const { return _toString; } - class Builder { + class Builder : public cc::RefCounted { private: int _responseCode{0}; std::string _debugMessage; std::string _toStr; public: - Builder& setDebugMessage(const std::string debugMsg) { + Builder& setDebugMessage(const std::string& debugMsg) { _debugMessage = debugMsg; return *this; } diff --git a/native/vendor/google/billing/result-values/ProductDetails.h b/native/vendor/google/billing/result-values/ProductDetails.h index da50317bb60..54860fdadfc 100644 --- a/native/vendor/google/billing/result-values/ProductDetails.h +++ b/native/vendor/google/billing/result-values/ProductDetails.h @@ -121,6 +121,7 @@ class CC_DLL ProductDetails : public cc::RefCounted { friend class JniBilling; std::vector _pricingPhaseList; }; + class SubscriptionOfferDetails { public: ~SubscriptionOfferDetails() {