From a749f5615ec703ebd9e14255878e472d04d341f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=87=AF=E6=98=8E?= Date: Fri, 14 Mar 2025 10:30:22 +0800 Subject: [PATCH] =?UTF-8?q?add=20preload=20list=20check=20Signed-off-by:?= =?UTF-8?q?=20=E8=B0=A2=E5=87=AF=E6=98=8E=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/include/custom_config_napi.h | 1 + interfaces/kits/js/src/custom_config_napi.cpp | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/include/custom_config_napi.h b/interfaces/kits/js/include/custom_config_napi.h index 481bb42..49c6b1d 100644 --- a/interfaces/kits/js/include/custom_config_napi.h +++ b/interfaces/kits/js/include/custom_config_napi.h @@ -33,6 +33,7 @@ public: private: static int GetBundleName(std::string &bundleName); + static bool IsInPreloadList(std::string bundleName); static napi_value NAPIGetChannelId(napi_env env, napi_callback_info info); static napi_value NativeGetChannelId(napi_env env, std::string channelKey); static napi_value CreateNapiStringValue(napi_env env, const char *str); diff --git a/interfaces/kits/js/src/custom_config_napi.cpp b/interfaces/kits/js/src/custom_config_napi.cpp index 43145e0..b4169a0 100644 --- a/interfaces/kits/js/src/custom_config_napi.cpp +++ b/interfaces/kits/js/src/custom_config_napi.cpp @@ -32,6 +32,7 @@ namespace ConfigPolicy { using namespace OHOS::HiviewDFX; static const std::string CHANNEL_ID_PREFIX = "const.channelid."; +static const std::string CUSTOM_PRELOAD_LIST_PARA = "persist.custom.preload.list"; napi_value CustomConfigNapi::Init(napi_env env, napi_value exports) { @@ -54,10 +55,40 @@ int CustomConfigNapi::GetBundleName(std::string &bundleName) return 0; } + bool CustomConfigNapi::IsInPreloadList(std::string bundleName) + { + char *preloadList = CustGetSystemParam(CUSTOM_PRELOAD_LIST_PARA.c_str()); + if (preloadList == nullptr) { + HILOG_WARN(LOG_CORE, "get preload list fail."); + return false; + } + if (preloadList[0] < '0' || preloadList[0] > '9' || preloadList[1] != ',') { + HILOG_ERROR(LOG_CORE, "preload list param format error."); + free(preloadList); + return false; + } + int listlen = preloadList[0] - '0'; + std::string preloadListResult(preloadList + 1); // skip listlen + free(preloadList); + + for (int i = 1; i < listlen; i++) { + std::string tempPreloadListPara = CUSTOM_PRELOAD_LIST_PARA + std::to_string(i); + char *tempList = CustGetSystemParam(tempPreloadListPara.c_str()); + if (tempList == nullptr) { + HILOG_ERROR(LOG_CORE, "preload list len error."); + return false; + } + preloadListResult.append(tempList + 1); // skip listlen + free(tempList); + } + preloadListResult.append(","); + return preloadListResult.find("," + bundleName + ",") != std::string::npos; +} + napi_value CustomConfigNapi::NAPIGetChannelId(napi_env env, napi_callback_info info) { std::string bundleName; - if (GetBundleName(bundleName) != 0 || bundleName.empty()) { + if (GetBundleName(bundleName) != 0 || bundleName.empty() || IsInPreloadList(bundleName)) { return CreateNapiStringValue(env, ""); } std::string channelKey = CHANNEL_ID_PREFIX + bundleName; -- Gitee