From 8fae1c518a7eeea4ca445708dfe17bc249fefa49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=87=AF=E6=98=8E?= Date: Fri, 17 Jan 2025 10:41:58 +0800 Subject: [PATCH] =?UTF-8?q?DFX=E4=BA=8B=E4=BB=B6=E6=89=93=E7=82=B9?= =?UTF-8?q?=E6=B2=BB=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谢凯明 --- interfaces/kits/cj/src/config_policy_ffi.cpp | 14 +++++----- interfaces/kits/js/src/config_policy_napi.cpp | 26 ++++++++++++------- interfaces/kits/js/src/custom_config_napi.cpp | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/interfaces/kits/cj/src/config_policy_ffi.cpp b/interfaces/kits/cj/src/config_policy_ffi.cpp index 6997cd8..8f28bb7 100644 --- a/interfaces/kits/cj/src/config_policy_ffi.cpp +++ b/interfaces/kits/cj/src/config_policy_ffi.cpp @@ -67,13 +67,13 @@ extern "C" { dirList.push_back(cfgDir->paths[i]); } } + FreeCfgDirList(cfgDir); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "CJ_GetCfgDirList", "CfgDirList is nullptr."); } ret.data.head = MallocCStringArr(dirList); ret.data.size = static_cast(ret.data.head == nullptr ? 0 : dirList.size()); - - FreeCfgDirList(cfgDir); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirList", ""); LOGI("CJ_GetCfgDirList ok"); return ret; } @@ -93,13 +93,13 @@ extern "C" { fileList.push_back(cfgFiles->paths[i]); } } + FreeCfgFiles(cfgFiles); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "CJ_GetCfgFiles", "CfgFiles is nullptr."); } ret.data.head = MallocCStringArr(fileList); ret.data.size = static_cast(ret.data.head == nullptr ? 0 : fileList.size()); - - FreeCfgFiles(cfgFiles); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); return ret; } @@ -113,11 +113,11 @@ extern "C" { if (filePath == nullptr) { LOGI("GetOneCfgFileEx result is nullptr."); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "CJ_GetOneCfgFile", "CfgFile path is nullptr."); return ret; } else { LOGI("GetOneCfgFile return [%{public}s]", filePath); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); size_t pathLen = strlen(filePath) + 1; ret.data = static_cast(malloc(sizeof(char) * pathLen)); if (ret.data == nullptr) { diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index c07d572..dfefac5 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -299,10 +299,10 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) asyncCallbackInfo->followMode_, asyncCallbackInfo->extra_.c_str()); if (filePath == nullptr) { HILOG_DEBUG(LOG_CORE, "GetOneCfgFileEx result is nullptr."); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getOneCfgFile", "CfgFile path is nullptr."); } else { asyncCallbackInfo->pathValue_ = std::string(filePath); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { napi_value result; NAPI_CALL(env, napi_create_string_utf8(env, context.pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); @@ -318,10 +318,10 @@ napi_value ConfigPolicyNapi::NativeGetOneCfgFileSync(napi_env env, std::shared_p context->followMode_, context->extra_.c_str()); if (filePath == nullptr) { HILOG_DEBUG(LOG_CORE, "GetOneCfgFileEx result is nullptr."); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getOneCfgFileSync", "CfgFile path is nullptr."); } else { context->pathValue_ = std::string(filePath); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFileSync", ""); napi_value result = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, context->pathValue_.c_str(), NAPI_AUTO_LENGTH, &result)); return result; @@ -345,9 +345,10 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) } } FreeCfgFiles(cfgFiles); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getCfgFiles", "CfgFiles is nullptr."); } CreateArraysValueFunc(*asyncCallbackInfo); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); } napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr context) @@ -362,8 +363,9 @@ napi_value ConfigPolicyNapi::NativeGetCfgFilesSync(napi_env env, std::shared_ptr } } FreeCfgFiles(cfgFiles); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getCfgFilesSync", "CfgFiles is nullptr."); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFilesSync", ""); return CreateArraysValue(env, context); } @@ -377,14 +379,17 @@ void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) ConfigAsyncContext *asyncCallbackInfo = static_cast(data); CfgDir *cfgDir = GetCfgDirList(); - for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { - if (cfgDir != nullptr && cfgDir->paths[i] != nullptr) { - asyncCallbackInfo->paths_.push_back(cfgDir->paths[i]); + if (cfgDir != nullptr) { + for (size_t i = 0; i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (cfgDir->paths[i] != nullptr) { + asyncCallbackInfo->paths_.push_back(cfgDir->paths[i]); + } } + FreeCfgDirList(cfgDir); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getCfgDirList", "CfgDirList is nullptr."); } - FreeCfgDirList(cfgDir); CreateArraysValueFunc(*asyncCallbackInfo); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirList", ""); } napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_ptr context) @@ -398,8 +403,9 @@ napi_value ConfigPolicyNapi::NativeGetCfgDirListSync(napi_env env, std::shared_p } } FreeCfgDirList(cfgDir); + } else { + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getCfgDirListSync", "CfgDirList is nullptr."); } - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirListSync", ""); return CreateArraysValue(env, context); } diff --git a/interfaces/kits/js/src/custom_config_napi.cpp b/interfaces/kits/js/src/custom_config_napi.cpp index 7599649..43145e0 100644 --- a/interfaces/kits/js/src/custom_config_napi.cpp +++ b/interfaces/kits/js/src/custom_config_napi.cpp @@ -85,10 +85,10 @@ char *CustomConfigNapi::CustGetSystemParam(const char *name) napi_value CustomConfigNapi::NativeGetChannelId(napi_env env, std::string channelKey) { char *channelId = CustGetSystemParam(channelKey.c_str()); - ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getChannelId", ""); napi_value result = nullptr; if (channelId == nullptr) { HILOG_WARN(LOG_CORE, "get channelId failed."); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_FAILED, "getChannelId", "ChannelId is nullptr."); return CreateNapiStringValue(env, ""); } result = CreateNapiStringValue(env, channelId); -- Gitee