diff --git a/interfaces/kits/js/include/custom_config_napi.h b/interfaces/kits/js/include/custom_config_napi.h index 481bb423519cd92fb702353c8540e30db4f08696..49c6b1df09582f14ab36c7878bc97c730a693083 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 7599649945c6f92d64234185ec9c8c537a108ddd..5e84fe0b2144e04c5ac2587e6274156487363b76 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;