From ef0d706fa9d0ae8b100761eb6bbf34fd130284a7 Mon Sep 17 00:00:00 2001 From: huangke11 Date: Sat, 2 Jul 2022 14:07:40 +0800 Subject: [PATCH] =?UTF-8?q?dfx=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangke11 --- bundle.json | 3 ++ frameworks/dfx/hisysevent.yaml | 27 +++++++++++ .../hisysevent_adapter/hisysevent_adapter.cpp | 45 +++++++++++++++++++ .../hisysevent_adapter/hisysevent_adapter.h | 32 +++++++++++++ interfaces/kits/js/BUILD.gn | 7 ++- interfaces/kits/js/src/config_policy_napi.cpp | 4 ++ 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 frameworks/dfx/hisysevent.yaml create mode 100644 frameworks/dfx/hisysevent_adapter/hisysevent_adapter.cpp create mode 100644 frameworks/dfx/hisysevent_adapter/hisysevent_adapter.h diff --git a/bundle.json b/bundle.json index 3491b3e..64a1cd8 100644 --- a/bundle.json +++ b/bundle.json @@ -15,6 +15,9 @@ "syscap": [ "SystemCapability.Customization.ConfigPolicy" ], "features": [], "adapted_system_type": [ "standard", "small" ], + "hisysevent_config": [ + "//base/customization/config_policy/frameworks/dfx/hisysevent.yaml" + ], "rom": "", "ram": "", "deps": { diff --git a/frameworks/dfx/hisysevent.yaml b/frameworks/dfx/hisysevent.yaml new file mode 100644 index 0000000..200d9e0 --- /dev/null +++ b/frameworks/dfx/hisysevent.yaml @@ -0,0 +1,27 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +domain: CUST_CONFIG + +# config_policy failed event + +CONFIG_POLICY_FAILED: + __BASE: {type: FAULT, level: CRITICAL, tag: cfgFail, desc: config policy failed} + APINAME: {type: STRING, desc: api name} + MSG: {type: STRING, desc: error message} + +# config_policy statistic event + +CONFIG_POLICY_EVENT: + __BASE: {type: STATISTIC, level: MINOR, tag: cfgEvent, desc: get config policy func} + APINAME: {type: STRING, desc: api name} diff --git a/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.cpp b/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.cpp new file mode 100644 index 0000000..f486dd8 --- /dev/null +++ b/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "hisysevent_adapter.h" + +#include "hisysevent.h" +#include "hilog/log.h" + +namespace OHOS { +namespace Customization { +namespace ConfigPolicy { +using namespace OHOS::HiviewDFX; +static constexpr HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "ReportConfigPolicyEvent" }; +const std::string DOMAIN_STR = std::string(HiSysEvent::Domain::CUSTOMIZATION_CONFIG); + +void ReportConfigPolicyEvent(ReportType reportType, const std::string &apiName, const std::string &msgInfo) +{ + int ret; + if (reportType == ReportType::CONFIG_POLICY_FAILED) { + ret = HiSysEvent::Write(DOMAIN_STR, "CONFIG_POLICY_FAILED", HiSysEvent::EventType::FAULT, "APINAME", apiName, + "MSG", msgInfo); + } else { + ret = + HiSysEvent::Write(DOMAIN_STR, "CONFIG_POLICY_EVENT", HiSysEvent::EventType::STATISTIC, "APINAME", apiName); + } + + if (ret != 0) { + HiLog::Error(LABEL, "hisysevent write failed! ret %{public}d, apiName %{public}s, errMsg %{public}s", ret, + apiName.c_str(), msgInfo.c_str()); + } +} +} // namespace ConfigPolicy +} // namespace Customization +} // namespace OHOS diff --git a/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.h b/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.h new file mode 100644 index 0000000..ec9a1a2 --- /dev/null +++ b/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_CONFIG_POLICY_DFX_HISYSEVENT_ADAPTER_H +#define OHOS_CONFIG_POLICY_DFX_HISYSEVENT_ADAPTER_H + +#include + +namespace OHOS { +namespace Customization { +namespace ConfigPolicy { +enum class ReportType { + CONFIG_POLICY_FAILED = 0, + CONFIG_POLICY_EVENT, +}; +void ReportConfigPolicyEvent(ReportType reportType, const std::string &apiName, const std::string &msgInfo); +} // namespace ConfigPolicy +} // namespace Customization +} // namespace OHOS +#endif // OHOS_CONFIG_POLICY_DFX_HISYSEVENT_ADAPTER_H diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index bc0e432..2640cea 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -18,12 +18,17 @@ ohos_shared_library("configpolicy") { "//base/customization/config_policy/interfaces/inner_api/include", "//third_party/bounds_checking_function/include", "//base/customization/config_policy/interfaces/kits/js/include", + "//base/customization/config_policy/frameworks/dfx/hisysevent_adapter", ] - sources = [ "src/config_policy_napi.cpp" ] + sources = [ + "//base/customization/config_policy/frameworks/dfx/hisysevent_adapter/hisysevent_adapter.cpp", + "src/config_policy_napi.cpp", + ] deps = [ "//base/customization/config_policy/frameworks/config_policy:configpolicy_util" ] external_deps = [ + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", ] diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 070a881..f7878c2 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -19,6 +19,7 @@ #include "hilog/log.h" #include "config_policy_utils.h" +#include "hisysevent_adapter.h" namespace OHOS { namespace Customization { @@ -164,6 +165,7 @@ void ConfigPolicyNapi::NativeGetOneCfgFile(napi_env env, void *data) char outBuf[MAX_PATH_LEN] = {0}; GetOneCfgFile(asyncCallbackInfo->relPath_.c_str(), outBuf, MAX_PATH_LEN); asyncCallbackInfo->pathValue_ = std::string(outBuf); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getOneCfgFile", ""); asyncCallbackInfo->createValueFunc_ = [](napi_env env, ConfigAsyncContext &context) -> napi_value { napi_value result; napi_status status = napi_create_string_utf8(env, context.pathValue_.c_str(), NAPI_AUTO_LENGTH, &result); @@ -191,6 +193,7 @@ void ConfigPolicyNapi::NativeGetCfgFiles(napi_env env, void *data) } FreeCfgFiles(cfgFiles); CreateArraysValueFunc(*asyncCallbackInfo); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgFiles", ""); } void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) @@ -209,6 +212,7 @@ void ConfigPolicyNapi::NativeGetCfgDirList(napi_env env, void *data) } FreeCfgDirList(cfgDir); CreateArraysValueFunc(*asyncCallbackInfo); + ReportConfigPolicyEvent(ReportType::CONFIG_POLICY_EVENT, "getCfgDirList", ""); } void ConfigPolicyNapi::CreateArraysValueFunc(ConfigAsyncContext &asyncCallbackInfo) -- Gitee