From bc5172c2d72db11afec1ddf7caff4863ae90bf96 Mon Sep 17 00:00:00 2001 From: xxxx Date: Thu, 16 Jun 2022 17:07:35 +0800 Subject: [PATCH] Description:hisysevent Match-id-2d40d31cf78d1173cad26bebaf9cf5050e43ce88 --- bundle.json | 6 +- dfx_utils/BUILD.gn | 62 ++++++++++ dfx_utils/include/hisysevent_util.h | 59 ++++++++++ dfx_utils/src/hisysevent_util.cpp | 108 ++++++++++++++++++ distributedinput.gni | 2 + hisysevent.yaml | 105 +++++++++++++++++ services/source/sourcemanager/BUILD.gn | 3 + .../src/distributed_input_source_manager.cpp | 68 +++++++++++ .../test/sourcemanagerunittest/BUILD.gn | 3 + sinkhandler/BUILD.gn | 3 + .../src/distributed_input_sink_handler.cpp | 5 + .../src/load_d_input_sink_callback.cpp | 3 + sinkhandler/test/unittest/BUILD.gn | 3 + sourcehandler/BUILD.gn | 3 + .../src/distributed_input_source_handler.cpp | 5 + .../src/load_d_input_source_callback.cpp | 3 + sourcehandler/test/unittest/BUILD.gn | 3 + 17 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 dfx_utils/BUILD.gn create mode 100644 dfx_utils/include/hisysevent_util.h create mode 100644 dfx_utils/src/hisysevent_util.cpp create mode 100644 hisysevent.yaml diff --git a/bundle.json b/bundle.json index 7ecf22d..67f9fa2 100644 --- a/bundle.json +++ b/bundle.json @@ -23,6 +23,9 @@ ], "rom":"2000k", "ram":"6M", + "hisysevent_config": [ + "//foundation/distributedhardware/distributed_input/hisysevent.yaml" + ], "deps":{ "components":[ "appexecfwk_standard", @@ -55,7 +58,8 @@ "//foundation/distributedhardware/distributed_input/services/sink/inputcollector:libdinput_collector", "//foundation/distributedhardware/distributed_input/sourcehandler:libdinput_source_handler", "//foundation/distributedhardware/distributed_input/sinkhandler:libdinput_sink_handler", - "//foundation/distributedhardware/distributed_input/inputdevicehandler:libdinput_handler" + "//foundation/distributedhardware/distributed_input/inputdevicehandler:libdinput_handler", + "//foundation/distributedhardware/distributed_input/dfx_utils:libdinput_dfx_utils" ], "inner_kits":[ { diff --git a/dfx_utils/BUILD.gn b/dfx_utils/BUILD.gn new file mode 100644 index 0000000..06cbebf --- /dev/null +++ b/dfx_utils/BUILD.gn @@ -0,0 +1,62 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/distributedhardware/distributed_input/distributedinput.gni") + +ohos_shared_library("libdinput_dfx_utils") { + include_dirs = [ + "include", + "${common_path}/include", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${frameworks_path}/include", + "${dfx_utils_path}/include", + ] + + sources = [ + "src/hisysevent_util.cpp", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"distributedinputdfxutil\"", + "LOG_DOMAIN=0xD004100", + ] + + deps = [ + "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", + "//utils/native/base:utils", + "${fwk_utils_path}:distributedhardwareutils", + "//third_party/openssl:libcrypto_static", + ] + + external_deps = [ + "ipc:ipc_core", + "safwk:system_ability_fwk", + "hiviewdfx_hilog_native:libhilog", + "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", + ] + + cflags_cc = [ "-DHILOG_ENABLE" ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_input" + +} diff --git a/dfx_utils/include/hisysevent_util.h b/dfx_utils/include/hisysevent_util.h new file mode 100644 index 0000000..5c0f0a5 --- /dev/null +++ b/dfx_utils/include/hisysevent_util.h @@ -0,0 +1,59 @@ +/* + * 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_DISTRIBUTED_INPUT_HISYSEVENT_UTILS_H +#define OHOS_DISTRIBUTED_INPUT_HISYSEVENT_UTILS_H + +#include +#include "single_instance.h" +#include "hisysevent.h" +#include "constants_dinput.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +const std::string DINPUT_INIT = "DINPUT_INIT"; +const std::string DINPUT_REGISTER = "DINPUT_REGISTER"; +const std::string DINPUT_PREPARE = "DINPUT_PREPARE"; +const std::string DINPUT_START_USE = "DINPUT_START_USE"; +const std::string DINPUT_STOP_USE = "DINPUT_STOP_USE"; +const std::string DINPUT_UNPREPARE = "DINPUT_UNPREPARE"; +const std::string DINPUT_UNREGISTER = "DINPUT_UNREGISTER"; +const std::string DINPUT_EXIT = "DINPUT_EXIT"; +const std::string DINPUT_INIT_FAIL = "DINPUT_INIT_FAIL"; +const std::string DINPUT_REGISTER_FAIL = "DINPUT_REGISTER_FAIL"; +const std::string DINPUT_OPT_FAIL = "DINPUT_OPT_FAIL"; +const std::string DINPUT_UNREGISTER_FAIL = "DINPUT_UNREGISTER_FAIL"; + +class HisyseventUtil { +DECLARE_SINGLE_INSTANCE_BASE(HisyseventUtil); +public: + void SysEventWriteBehavior(std::string status, std::string msg); + void SysEventWriteBehavior(std::string status, std::string devId, std::string msg); + void SysEventWriteBehavior(std::string status, std::string devId, std::string dhId, std::string msg); + void SysEventWriteFault(std::string status, std::string msg); + void SysEventWriteFault(std::string status, std::string devId, int32_t errorCode, std::string msg); + void SysEventWriteFault(std::string status, std::string devId, std::string dhId, int32_t errorCode, + std::string msg); + +private: + HisyseventUtil() = default; + ~HisyseventUtil() = default; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DISTRIBUTED_INPUT_HISYSEVENT_UTILS_H \ No newline at end of file diff --git a/dfx_utils/src/hisysevent_util.cpp b/dfx_utils/src/hisysevent_util.cpp new file mode 100644 index 0000000..a1e5850 --- /dev/null +++ b/dfx_utils/src/hisysevent_util.cpp @@ -0,0 +1,108 @@ +/* + * 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_util.h" + +#include "anonymous_string.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +IMPLEMENT_SINGLE_INSTANCE(HisyseventUtil); + +void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} + +void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string devId, std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "DEVID", GetAnonyString(devId), + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} + +void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string devId, std::string dhId, std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "DEVID", GetAnonyString(devId), + "DHID", GetAnonyString(dhId), + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} + +void HisyseventUtil::SysEventWriteFault(std::string status, std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} + +void HisyseventUtil::SysEventWriteFault(std::string status, std::string devId, int32_t errorCode, std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + "DEVID", GetAnonyString(devId), + "ERROR_CODE", errorCode, + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} + +void HisyseventUtil::SysEventWriteFault(std::string status, std::string devId, std::string dhId, int32_t errorCode, + std::string msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT, + status, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + "DEVID", GetAnonyString(devId), + "DHID", GetAnonyString(dhId), + "ERROR_CODE", errorCode, + "MSG", msg); + if (res != SUCCESS) { + DHLOGE("Write HiSysEvent error, res:%d", res); + } +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/distributedinput.gni b/distributedinput.gni index e45cc55..2a6d432 100644 --- a/distributedinput.gni +++ b/distributedinput.gni @@ -19,6 +19,8 @@ common_path = "${distributedinput_path}/common" utils_path = "${distributedinput_path}/utils" +dfx_utils_path = "${distributedinput_path}/dfx_utils" + services_source_path = "${distributedinput_path}/services/source" services_sink_path = "${distributedinput_path}/services/sink" diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 0000000..5fd9dc2 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,105 @@ +# 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. + +##################################################### +# below is the format of defining event # +##################################################### +#domain: domain name. [Only one domain name can be defined at the top] +# +#author: the author name who defined this event. +#date: the date when this event was defined, format is YYYY-MM-DD. +#logged: source file which refer to this event. +#usage: the usage of this event. +#//Define event name and event properties. +#@EVENT_NAME: the event definition part begin. +# // __BASE is used for defining the basic info of the event. +# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR. +# // "level" optional values are: CRITICAL, MINOR. +# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space. +# // "desc" full description of this event. +# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}. +# // follow the __BASE block, each line defines a parameter of this event. +# // "type" optional values are: INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING. +# // "arrsize" of the parameter is an array, set a non-zero value. +# // "desc" full description of this parameter. + +##################################################### +# Example of some hiviewdfx events definition # +##################################################### + +domain: DISTINPUT + +DINPUT_INIT: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput sa init} + MSG: {type: STRING, desc: dinput sa init info} + +DINPUT_REGISTER: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput register dhardware} + DEVID: {type: STRING, desc: network id} + DHID: {type: STRING, desc: hardware id} + MSG: {type: STRING, desc: dinput register dhardware info} + +DINPUT_PREPARE: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput prepare start} + DEVID: {type: STRING, desc: network id} + MSG: {type: STRING, desc: dinput prepare start info} + +DINPUT_START_USE: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput start use} + DEVID: {type: STRING, desc: network id} + MSG: {type: STRING, desc: dinput start info} + +DINPUT_STOP_USE: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput stop use} + DEVID: {type: STRING, desc: network id} + MSG: {type: STRING, desc: dinput stop info} + +DINPUT_UNPREPARE: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput unprepare} + DEVID: {type: STRING, desc: network id} + MSG: {type: STRING, desc: dinput unprepare info} + +DINPUT_UNREGISTER: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput unregister} + DEVID: {type: STRING, desc: network id} + DHID: {type: STRING, desc: hardware id} + MSG: {type: STRING, desc: dinput unregister info} + +DINPUT_EXIT: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dinput server exit} + MSG: {type: STRING, desc: dinput server exit info} + +DINPUT_INIT_FAIL: + __BASE: {type: FAULT, level: CRITICAL, desc: dinput sa start fail occured} + ERROR_CODE: {type: INT32, desc: the return error code} + MSG: {type: STRING, desc: dinput sa start fail info} + +DINPUT_REGISTER_FAIL: + __BASE: {type: FAULT, level: CRITICAL, desc: dinput register fail occured} + DEVID: {type: STRING, desc: network id} + DHID: {type: STRING, desc: hardware id} + ERROR_CODE: {type: INT32, desc: the return error code} + MSG: {type: STRING, desc: dinput register fail info} + +DINPUT_OPT_FAIL: + __BASE: {type: FAULT, level: CRITICAL, desc: dinput operate fail occured} + DEVID: {type: STRING, desc: network id} + ERROR_CODE: {type: INT32, desc: the return error code} + MSG: {type: STRING, desc: dinput operate fail info} + +DINPUT_UNREGISTER_FAIL: + __BASE: {type: FAULT, level: CRITICAL, desc: dinput unregister fail occured} + DEVID: {type: STRING, desc: network id} + DHID: {type: STRING, desc: hardware id} + ERROR_CODE: {type: INT32, desc: the return error code} + MSG: {type: STRING, desc: dinput unregister fail info} diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index c37c8a4..4280de4 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("libdinput_source") { "${service_common}/include", "${services_source_path}/inputinject/include", "${services_source_path}/transport/include", + "${dfx_utils_path}/include", "//third_party/json/include", ] @@ -77,6 +78,7 @@ ohos_shared_library("libdinput_source") { "${fwk_utils_path}:distributedhardwareutils", "//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -84,6 +86,7 @@ ohos_shared_library("libdinput_source") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index d3d8012..263f47b 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -28,6 +28,7 @@ #include "dinput_errcode.h" #include "distributed_input_inject.h" #include "distributed_input_source_transport.h" +#include "hisysevent_util.h" #include "white_list_util.h" namespace OHOS { @@ -532,6 +533,7 @@ int32_t DistributedInputSourceManager::Release() int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters, sptr callback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_REGISTER, devId, dhId, "dinput register call."); DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); @@ -539,6 +541,9 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st DHLOGE( "%s called, deviceId: %s callback is null.", __func__, GetAnonyString(devId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, + "dinput register distributed hardware failed callback is nullptr."); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; } @@ -560,6 +565,9 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st // 2.create input node int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedHardware(devId, dhId, parameters); if (ret != DH_SUCCESS) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, + "dinput register distributed hardware failed in create input node."); DHLOGE("%s called, create node fail.", __func__); for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { @@ -657,10 +665,14 @@ int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, co int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, sptr callback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNREGISTER, devId, dhId, "dinput unregister call"); DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (callback == nullptr) { DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(devId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, + "dinput unregister distributed hardware failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } @@ -675,6 +687,9 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); if (it == inputDevice_.end()) { DHLOGE("%s called, deviceId: %s is not exist.", __func__, GetAnonyString(devId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, + "dinput unregister distributed hardware failed in deviceId is not exist"); for (std::vector::iterator iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { if (iter->devId == devId && iter->dhId == dhId) { @@ -689,6 +704,9 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: // 1.remove input node if (RemoveInputNode(devId, dhId) != DH_SUCCESS) { callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, + "dinput unregister distributed hardware failed in remove input node"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } @@ -696,6 +714,9 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: inputDevice_.erase(it); if (DeleteDevice(devId, dhId) != DH_SUCCESS) { callback->OnResult(devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, + "dinput unregister distributed hardware failed in delete device"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } @@ -707,21 +728,32 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& deviceId, sptr callback, sptr addWhiteListCallback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_PREPARE, deviceId, + "dinput prepare remote input call"); DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); if (callback == nullptr) { DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, + "dinput prepare remote input call failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } for (auto iter : preCallbacks_) { if (iter.devId == deviceId) { callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, + "dinput prepare remote input call failed in already prepared"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } } int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(deviceId); if (ret != DH_SUCCESS) { DHLOGE("Open softbus session fail."); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, + "dinput prepare distributed hardware failed in open softbus"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } DInputClientPrepareInfo info; @@ -732,6 +764,9 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); if (ret != DH_SUCCESS) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, + "dinput prepare remote input call failed in transport prepare"); DHLOGE("Can not send message by softbus, prepare fail."); for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { if (iter->devId == deviceId) { @@ -749,16 +784,24 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& deviceId, sptr callback, sptr delWhiteListCallback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNPREPARE, deviceId, + "dinput unprepare remote input call"); DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); if (callback == nullptr) { DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, + "dinput unprepare remote input call failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; } for (auto iter : unpreCallbacks_) { if (iter.devId == deviceId) { callback->OnResult(deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, + "dinput unprepare remote input call failed in already unprepared"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; } } @@ -772,6 +815,9 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); if (ret != DH_SUCCESS) { DHLOGE("Can not send message by softbus, unprepare fail."); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, + "dinput unprepare remote input call failed in transport unprepare"); for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { if (iter->devId == deviceId) { iter->unpreCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL); @@ -788,16 +834,24 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d int32_t DistributedInputSourceManager::StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, deviceId, + "dinput start use call"); DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (callback == nullptr) { DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, + "dinput start use call failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } for (auto iter : staCallbacks_) { if (iter.devId == deviceId && iter.inputTypes == inputTypes) { callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, + "dinput start use call failed in already started"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } } @@ -811,6 +865,9 @@ int32_t DistributedInputSourceManager::StartRemoteInput( DeviceMap_[deviceId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, inputTypes); if (ret != DH_SUCCESS) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, + "dinput start use call failed in transport start"); DHLOGE("%s called, start fail.", __func__); for (std::vector::iterator iter = staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) { @@ -829,16 +886,24 @@ int32_t DistributedInputSourceManager::StartRemoteInput( int32_t DistributedInputSourceManager::StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, deviceId, + "dinput stop use call"); DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (callback == nullptr) { DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, + "dinput stop use call failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } for (auto iter : stpCallbacks_) { if (iter.devId == deviceId && iter.inputTypes == inputTypes) { callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, + "dinput stop use call failed in already stoped"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } } @@ -852,6 +917,9 @@ int32_t DistributedInputSourceManager::StopRemoteInput( int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, inputTypes); if (ret != DH_SUCCESS) { DHLOGE("%s called, stop fail.", __func__); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, + "dinput stop use call failed in transport stop"); for (std::vector::iterator iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) { if (iter->devId == deviceId && iter->inputTypes == inputTypes) { diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 8fdf8af..466261f 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", "${services_source_path}/inputinject/include", "${services_source_path}/transport/include", + "${dfx_utils_path}/include", ] sources = [ @@ -104,6 +105,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "${fwk_utils_path}:distributedhardwareutils", "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -111,6 +113,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/sinkhandler/BUILD.gn b/sinkhandler/BUILD.gn index ac996fc..865a399 100644 --- a/sinkhandler/BUILD.gn +++ b/sinkhandler/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("libdinput_sink_handler") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", + "${dfx_utils_path}/include", ] sources = [ @@ -50,6 +51,7 @@ ohos_shared_library("libdinput_sink_handler") { "${fwk_utils_path}:distributedhardwareutils", "${innerkits_path}:libdinput_sdk", "${services_sink_path}/sinkmanager:libdinput_sink", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -57,6 +59,7 @@ ohos_shared_library("libdinput_sink_handler") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index e0d23fc..ab9ee93 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -18,6 +18,7 @@ #include "distributed_hardware_log.h" #include "dinput_errcode.h" +#include "hisysevent_util.h" #include "i_distributed_sink_input.h" #include "load_d_input_sink_callback.h" @@ -42,6 +43,8 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string ¶ms) return ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL; } sptr loadCallback = new LoadDInputSinkCallback(params); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_INIT, + "dinput sink LoadSystemAbility call"); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, loadCallback); if (ret != ERR_OK) { DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", @@ -71,6 +74,8 @@ void DistributedInputSinkHandler::FinishStartSA(const std::string ¶ms, const int32_t DistributedInputSinkHandler::ReleaseSink() { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, + "dinput exit sink sa release."); return DistributedInputClient::GetInstance().ReleaseSink(); } diff --git a/sinkhandler/src/load_d_input_sink_callback.cpp b/sinkhandler/src/load_d_input_sink_callback.cpp index 82ef4f8..af29494 100644 --- a/sinkhandler/src/load_d_input_sink_callback.cpp +++ b/sinkhandler/src/load_d_input_sink_callback.cpp @@ -16,6 +16,7 @@ #include "distributed_hardware_log.h" #include "distributed_input_sink_handler.h" +#include "hisysevent_util.h" #include "load_d_input_sink_callback.h" namespace OHOS { @@ -37,6 +38,8 @@ void LoadDInputSinkCallback::OnLoadSystemAbilitySuccess( void LoadDInputSinkCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_INIT_FAIL, + "dinput sink LoadSystemAbility call failed."); DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId); } } diff --git a/sinkhandler/test/unittest/BUILD.gn b/sinkhandler/test/unittest/BUILD.gn index c3bef73..9065592 100644 --- a/sinkhandler/test/unittest/BUILD.gn +++ b/sinkhandler/test/unittest/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("distributed_input_sink_handler_test") { "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", "//third_party/json/include", + "${dfx_utils_path}/include", ] sources = [ @@ -71,6 +72,7 @@ ohos_unittest("distributed_input_sink_handler_test") { "${fwk_utils_path}:distributedhardwareutils", "${innerkits_path}:libdinput_sdk", "${services_source_path}/sourcemanager:libdinput_source", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -78,6 +80,7 @@ ohos_unittest("distributed_input_sink_handler_test") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/sourcehandler/BUILD.gn b/sourcehandler/BUILD.gn index c75703b..d917dab 100644 --- a/sourcehandler/BUILD.gn +++ b/sourcehandler/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("libdinput_source_handler") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", + "${dfx_utils_path}/include", ] sources = [ @@ -50,6 +51,7 @@ ohos_shared_library("libdinput_source_handler") { "${fwk_utils_path}:distributedhardwareutils", "${innerkits_path}:libdinput_sdk", "${services_source_path}/sourcemanager:libdinput_source", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -57,6 +59,7 @@ ohos_shared_library("libdinput_source_handler") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp index 0e0e27e..4ced2ae 100644 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ b/sourcehandler/src/distributed_input_source_handler.cpp @@ -18,6 +18,7 @@ #include "distributed_hardware_log.h" #include "dinput_errcode.h" +#include "hisysevent_util.h" #include "i_distributed_source_input.h" #include "load_d_input_source_callback.h" @@ -41,6 +42,8 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string ¶ms) return ERR_DH_INPUT_SINK_HANDLER_INIT_SOURCE_SA_FAIL; } sptr loadCallback = new LoadDInputSourceCallback(params); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_INIT, + "dinput init source sa start."); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, loadCallback); if (ret != ERR_OK) { DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", @@ -70,6 +73,8 @@ void DistributedInputSourceHandler::FinishStartSA(const std::string ¶ms, con int32_t DistributedInputSourceHandler::ReleaseSource() { + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, + "dinput exit source sa release."); return DistributedInputClient::GetInstance().ReleaseSource(); } diff --git a/sourcehandler/src/load_d_input_source_callback.cpp b/sourcehandler/src/load_d_input_source_callback.cpp index 815f4da..4da9655 100644 --- a/sourcehandler/src/load_d_input_source_callback.cpp +++ b/sourcehandler/src/load_d_input_source_callback.cpp @@ -18,6 +18,7 @@ #include "distributed_hardware_log.h" #include "distributed_input_source_handler.h" +#include "hisysevent_util.h" namespace OHOS { namespace DistributedHardware { @@ -39,6 +40,8 @@ void LoadDInputSourceCallback::OnLoadSystemAbilitySuccess( void LoadDInputSourceCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_INIT_FAIL, + "dinput source LoadSystemAbility call failed."); } } } diff --git a/sourcehandler/test/unittest/BUILD.gn b/sourcehandler/test/unittest/BUILD.gn index 29ae476..6ccb9bf 100644 --- a/sourcehandler/test/unittest/BUILD.gn +++ b/sourcehandler/test/unittest/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("distributed_input_source_handler_test") { "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", "//third_party/json/include", + "${dfx_utils_path}/include", ] sources = [ @@ -71,6 +72,7 @@ ohos_unittest("distributed_input_source_handler_test") { "${fwk_utils_path}:distributedhardwareutils", "${innerkits_path}:libdinput_sdk", "${services_source_path}/sourcemanager:libdinput_source", + "${dfx_utils_path}:libdinput_dfx_utils", ] external_deps = [ @@ -78,6 +80,7 @@ ohos_unittest("distributed_input_source_handler_test") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ]