diff --git a/common/include/dinput_sa_process_state.cpp b/common/include/dinput_sa_process_state.cpp new file mode 100644 index 0000000..abb4949 --- /dev/null +++ b/common/include/dinput_sa_process_state.cpp @@ -0,0 +1,66 @@ +/* + * 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 "dinput_sa_process_state.h" + +#include + +#include "distributed_hardware_log.h" + +#include "constants_dinput.h" +#include "hisysevent_util.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +enum DInputSAState : uint32_t { + DINPUT_SA_EXIT_STATE_START = 0, + DINPUT_SA_EXIT_STATE_STOP = 1 +}; + +DInputSAState g_sinkSAState = DINPUT_SA_EXIT_STATE_START; +DInputSAState g_sourceSAState = DINPUT_SA_EXIT_STATE_START; +std::mutex g_saProcessState; + +void SetSinkProcessExit() +{ + DHLOGI("set sink process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sinkSAState = DINPUT_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DINPUT_SA_EXIT_STATE_START || g_sinkSAState == DINPUT_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput sink sa exit success."); + exit(0); +} + +void SetSourceProcessExit() +{ + DHLOGI("set sources process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sourceSAState = DINPUT_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DINPUT_SA_EXIT_STATE_START || g_sinkSAState == DINPUT_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput source sa exit success."); + exit(0); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/common/include/dinput_sa_process_state.h b/common/include/dinput_sa_process_state.h new file mode 100644 index 0000000..ae48f91 --- /dev/null +++ b/common/include/dinput_sa_process_state.h @@ -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. + */ + +#ifndef DINPUT_SA_PROCESS_STATE_H +#define DINPUT_SA_PROCESS_STATE_H + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +void SetSinkProcessExit(); +void SetSourceProcessExit(); +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS +#endif // DINPUT_SA_PROCESS_STATE_H \ No newline at end of file diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 7585e7b..df0fea6 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -588,8 +588,8 @@ std::string InputHub::StringPrintf(const char* format, ...) const va_list ap; va_start(ap, format); std::string result; - size_t ret = vsnprintf_s(space, sizeof(space), sizeof(space) - 1, format, ap); - if (ret >= DH_SUCCESS && ret < sizeof(space)) { + int32_t ret = vsnprintf_s(space, sizeof(space), sizeof(space) - 1, format, ap); + if (ret >= DH_SUCCESS && (size_t)ret < sizeof(space)) { result = space; } else { return "the buffer is overflow!"; diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index d88a719..464284b 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libdinput_sink") { "src/distributed_input_sink_event_handler.cpp", "${ipc_path}/src/distributed_input_sink_stub.cpp", "${common_path}/include/white_list_util.cpp", + "${common_path}/include/dinput_sa_process_state.cpp", "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", ] @@ -68,6 +69,7 @@ ohos_shared_library("libdinput_sink") { "safwk:system_ability_fwk", "hiviewdfx_hilog_native:libhilog", "samgr_standard:samgr_proxy", + "hisysevent_native:libhisysevent", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 5cad6da..7ef2b57 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -28,6 +28,7 @@ #include "distributed_input_sink_transport.h" #include "dinput_errcode.h" +#include "dinput_sa_process_state.h" #include "dinput_utils_tool.h" #include "hidumper.h" #include "white_list_util.h" @@ -300,7 +301,7 @@ int32_t DistributedInputSinkManager::Release() serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; DHLOGI("exit dinput sink sa."); - exit(0); + SetSinkProcessExit(); return DH_SUCCESS; } diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn index d94db35..6dd8625 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("distributed_input_sinkmanager_test") { sources = [ "${common_path}/include/white_list_util.cpp", "${common_path}/include/input_hub.cpp", + "${common_path}/include/dinput_sa_process_state.cpp", "//foundation/distributedhardware/distributed_input/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp", "//foundation/distributedhardware/distributed_input/services/sink/transport/src/distributed_input_sink_switch.cpp", "//foundation/distributedhardware/distributed_input/services/sink/transport/src/distributed_input_sink_transport.cpp", @@ -91,6 +92,7 @@ ohos_unittest("distributed_input_sinkmanager_test") { "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/BUILD.gn b/services/source/sourcemanager/BUILD.gn index dff027e..d6cb9fe 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libdinput_source") { "src/distributed_input_source_manager.cpp", "src/distributed_input_source_event_handler.cpp", "${common_path}/include/white_list_util.cpp", + "${common_path}/include/dinput_sa_process_state.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index b6510ad..3488539 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 "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_hitrace.h" +#include "dinput_sa_process_state.h" #include "distributed_input_inject.h" #include "distributed_input_source_transport.h" #include "hisysevent_util.h" @@ -535,7 +536,7 @@ int32_t DistributedInputSourceManager::Release() serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; DHLOGI("exit dinput source sa."); - exit(0); + SetSourceProcessExit(); return DH_SUCCESS; } diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 35c57d0..be7e46a 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_manager.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp", "distributed_input_sourcemanager_test.cpp", + "${common_path}/include/dinput_sa_process_state.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_inject.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_node_manager.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_device.cpp", diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index bfef14a..610ffd7 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -74,8 +74,6 @@ 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/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp index f68e0ca..e96d9eb 100644 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ b/sourcehandler/src/distributed_input_source_handler.cpp @@ -73,8 +73,6 @@ 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(); }