From ae136d65e20490cc840e7ea25f4277d4bf1630e6 Mon Sep 17 00:00:00 2001 From: qq_35015309 <1257369706@qq.com> Date: Sat, 28 Feb 2026 15:27:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E9=94=81=E4=BF=9D=E6=8A=A4=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E8=B5=8B=E5=80=BC=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qq_35015309 <1257369706@qq.com> --- frameworks/js/napi/ads/include/ad_load_service.h | 1 + frameworks/js/napi/ads/src/ad_load_service.cpp | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/ads/include/ad_load_service.h b/frameworks/js/napi/ads/include/ad_load_service.h index 9d9f167..6459d5d 100644 --- a/frameworks/js/napi/ads/include/ad_load_service.h +++ b/frameworks/js/napi/ads/include/ad_load_service.h @@ -54,6 +54,7 @@ private: bool ConnectAdKit(const sptr &data, const sptr &callback, int32_t loadAdType); void GetConfigItem(const char *path, AdServiceElementName &adServiceElementName); + bool IsConfigEmpty(AdServiceElementName &adServiceElementName); static std::mutex lock_; static std::mutex configLock_; static sptr instance_; diff --git a/frameworks/js/napi/ads/src/ad_load_service.cpp b/frameworks/js/napi/ads/src/ad_load_service.cpp index 0621aba..486f9f5 100644 --- a/frameworks/js/napi/ads/src/ad_load_service.cpp +++ b/frameworks/js/napi/ads/src/ad_load_service.cpp @@ -114,7 +114,7 @@ void AdLoadService::GetAdServiceElement(AdServiceElementName &adServiceElementNa ErrCode AdLoadService::LoadAd(const std::string &request, const std::string &options, const sptr &callback, int32_t loadAdType) { - if (adServiceElementName_.bundleName.empty() || adServiceElementName_.extensionName.empty()) { + if (IsConfigEmpty(adServiceElementName_)) { std::lock_guard autoLock(configLock_); ADS_HILOGW(OHOS::Cloud::ADS_MODULE_JS_NAPI, "adServiceElementName is null, read from config"); GetAdServiceElement(adServiceElementName_); @@ -138,7 +138,7 @@ int32_t AdLoadService::RequestAdBody(const std::string &request, const std::stri const sptr &callback) { ADS_HILOGW(OHOS::Cloud::ADS_MODULE_JS_NAPI, "enter RequestAdBody"); - if (adServiceElementName_.bundleName.empty() || adServiceElementName_.extensionName.empty()) { + if (IsConfigEmpty(adServiceElementName_)) { std::lock_guard autoLock(configLock_); ADS_HILOGW(OHOS::Cloud::ADS_MODULE_JS_NAPI, "adServiceElementName is null, read from config"); GetAdServiceElement(adServiceElementName_); @@ -163,8 +163,19 @@ int32_t AdLoadService::RequestAdBody(const std::string &request, const std::stri return Cloud::ERR_SEND_OK; } +bool AdLoadService::IsConfigEmpty(AdServiceElementName &adServiceElementName) +{ + std::lock_guard autoLock(configLock_); + return adServiceElementName.bundleName.empty() || adServiceElementName.extensionName.empty() || + adServiceElementName.apiServiceName.empty(); +} + void AdLoadService::GetConfigItem(const char *path, AdServiceElementName &adServiceElementName) { + if (!IsConfigEmpty(adServiceElementName)) { + return; + } + std::lock_guard autoLock(configLock_); std::ifstream inFile(path, std::ios::in); if (!inFile.is_open()) { ADS_HILOGW(OHOS::Cloud::ADS_MODULE_JS_NAPI, "Open file error.");