diff --git a/bundle.json b/bundle.json index 0c80f8be60152752633253e2c90e61fa9d2ba9cd..265b5bbf418d9352c2805619d1761617487a5720 100755 --- a/bundle.json +++ b/bundle.json @@ -44,8 +44,7 @@ "hitrace", "graphic_surface", "window_manager", - "openssl", - "graphic_2d" + "openssl" ] }, "build": { diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index ce0f8d70f4e3a312bd8206d4512b01e37cb37640..61b50448b29213b2913e866c8cafb492c5edae4f 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -44,7 +44,6 @@ namespace DistributedInput { // whilte list error code constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001; constexpr int32_t ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL = -61002; - constexpr int32_t ERR_DH_INPUT_WHILTELIST_FILE_PATH_IS_NULL = -61003; // handler error code constexpr int32_t ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL = -63000; diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index 07cb3e88c43ff01f61fc4d44aeee2ff319d69e0f..31c6f1d4c348df2d8864c8b7111c720544bd77a6 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -17,8 +17,6 @@ #include #include -#include -#include #include "config_policy_utils.h" @@ -60,19 +58,34 @@ WhiteListUtil &WhiteListUtil::GetInstance(void) return instance; } -int32_t WhiteListUtil::Init() +bool WhiteListUtil::GetWhiteListCfgFile(std::ifstream &ifs) { char buf[MAX_PATH_LEN] = {0}; char path[PATH_MAX + 1] = {0x00}; char *whiteListFilePath = GetOneCfgFile(WHITELIST_FILE_PATH, buf, MAX_PATH_LEN); + if (whiteListFilePath == nullptr) { + DHLOGE("whiteListFilePath is null."); + return false; + } + if (strlen(whiteListFilePath) == 0 || strlen(whiteListFilePath) > PATH_MAX || realpath(whiteListFilePath, path) == nullptr) { DHLOGE("File connicailization failed."); - return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; + return false; } - std::ifstream inFile(path, std::ios::in | std::ios::binary); - if (!inFile.is_open()) { + + ifs.open(path, std::ios::in | std::ios::binary); + if (!ifs.is_open()) { DHLOGE("WhiteListUtil Init error, file open fail path=%{public}s", path); + return false; + } + return true; +} + +int32_t WhiteListUtil::Init() +{ + std::ifstream ifs; + if (!GetWhiteListCfgFile(ifs)) { return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } @@ -81,7 +94,7 @@ int32_t WhiteListUtil::Init() TYPE_WHITE_LIST_VEC vecWhiteList; std::string line; std::size_t lineNum = 0; - while (getline(inFile, line)) { + while (getline(ifs, line)) { if ((++lineNum > MAX_LINE_NUM) || !IsValidLine(line)) { DHLOGE("whitelist cfg file has too many lines or too complicated. lineNum is %{public}zu", lineNum); break; @@ -106,7 +119,7 @@ int32_t WhiteListUtil::Init() vecCombinationKey.clear(); } } - inFile.close(); + ifs.close(); std::string localNetworkId = GetLocalDeviceInfo().networkId; if (!localNetworkId.empty()) { SyncWhiteList(localNetworkId, vecWhiteList); diff --git a/common/include/white_list_util.h b/common/include/white_list_util.h index f184737d64d1afc68797a176cda094d00299e777..7426aa86ba3d64026cc7214ee12f7b4fa958954e 100644 --- a/common/include/white_list_util.h +++ b/common/include/white_list_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -18,6 +18,8 @@ #include #include +#include +#include #include "constants_dinput.h" @@ -47,7 +49,7 @@ public: int32_t ClearWhiteList(const std::string &deviceId); int32_t ClearWhiteList(void); int32_t GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList); - + bool GetWhiteListCfgFile(std::ifstream &ifs); /* * check is event in white list of deviceId * diff --git a/dfx_utils/BUILD.gn b/dfx_utils/BUILD.gn index 5ed35ceae89a27b7eac26564ce591088ec2e01db..fe8af2de5b8b1b3115a5e309c3d70ecda738945d 100755 --- a/dfx_utils/BUILD.gn +++ b/dfx_utils/BUILD.gn @@ -59,7 +59,6 @@ ohos_shared_library("libdinput_dfx_utils") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "json:nlohmann_json_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 233635b9040bb082cbb398a6361370e8bb0399ad..b0cea8fda5e5546d84051ad8feb14e5dfc67b6e3 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -59,7 +59,7 @@ void DistributedInputClient::RegisterDInputCb::OnResult( DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.end(); ++iter) { - if (iter->devId == devId && iter->dhId == dhId && (iter->callback != nullptr)) { + if (iter->devId == devId && iter->dhId == dhId && iter->callback != nullptr) { iter->callback->OnRegisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.erase(iter); return; @@ -75,7 +75,7 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.end(); ++iter) { - if (iter->devId == devId && iter->dhId == dhId && (iter->callback != nullptr)) { + if (iter->devId == devId && iter->dhId == dhId && iter->callback != nullptr) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.erase(iter); return; diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index 0c659407b4ba33b0f73d6c9a6e0bd8a177c1526d..a8122e3c4909efd97be3b80ad712614032250ea2 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -80,9 +80,7 @@ ohos_shared_library("libdinput_sink") { "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", "eventhandler:libeventhandler", - "graphic_2d:librender_service_base", "graphic_surface:surface", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index 30cb31280e3d304983182854b8d342c707b6e3f3..d13859b5a5bc4ee51867e9fac37ce1f56e1dd0ce 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -458,6 +458,8 @@ private: std::mutex regDisHardwareMutex_; std::mutex prepareMutex_; std::mutex startStopMutex_; + std::mutex startMutex_; + std::mutex stopMutex_; std::mutex simEventMutex_; std::mutex whiteListMutex_; diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 34a2b86793fd2d6a61232a09a87b46c9c5007db4..ad2ea5641512856cef0ec1c2e9f51239cd82520e 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -550,6 +550,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput( } DHLOGI("Start called, deviceId: %{public}s, inputTypes: %{public}d", GetAnonyString(deviceId).c_str(), inputTypes); + std::lock_guard startlock(startMutex_); for (auto iter : staCallbacks_) { if (iter.devId == deviceId && iter.inputTypes == inputTypes) { callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); @@ -594,6 +595,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput( } DHLOGI("Stop called, deviceId: %{public}s, inputTypes: %{public}d", GetAnonyString(deviceId).c_str(), inputTypes); + std::lock_guard stoplock(stopMutex_); for (auto iter : stpCallbacks_) { if (iter.devId == deviceId && iter.inputTypes == inputTypes) { callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); @@ -648,7 +650,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId if (srcId != localNetworkId) { return RelayStartRemoteInputByType(srcId, sinkId, inputTypes, callback); } - + std::lock_guard startlock(startMutex_); DInputClientStartInfo info {sinkId, inputTypes, callback}; staCallbacks_.push_back(info); DeviceMap_[sinkId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON @@ -692,7 +694,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, if (srcId != localNetworkId) { return RelayStopRemoteInputByType(srcId, sinkId, inputTypes, callback); } - + std::lock_guard stoplock(stopMutex_); DInputClientStopInfo info {sinkId, inputTypes, callback}; stpCallbacks_.push_back(info); int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(sinkId, inputTypes); @@ -1285,6 +1287,7 @@ void DistributedInputSourceManager::RunStartCallback( const std::string &devId, const uint32_t &inputTypes, const int32_t &status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + std::lock_guard startlock(startMutex_); for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->inputTypes == inputTypes) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_MSG"); @@ -1299,6 +1302,7 @@ void DistributedInputSourceManager::RunStopCallback( const std::string &devId, const uint32_t &inputTypes, const int32_t &status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); + std::lock_guard stoplock(stopMutex_); for (auto iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->inputTypes == inputTypes) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_STOP_MSG"); @@ -1359,6 +1363,7 @@ void DistributedInputSourceManager::RunRelayStartDhidCallback(const std::string SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec); DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI dhIds:%{public}s, vec-size:%{public}zu", dhids.c_str(), dhidsVec.size()); + std::lock_guard lock(startStopMutex_); bool isCbRun = false; sptr cb = nullptr; for (auto iter = relayStaDhidCallbacks_.begin(); iter != relayStaDhidCallbacks_.end(); ++iter) { @@ -1383,6 +1388,7 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string & { std::vector dhidsVec; SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec); + std::lock_guard lock(startStopMutex_); bool isCbRun = false; sptr cb = nullptr; for (auto iter = relayStpDhidCallbacks_.begin(); iter != relayStpDhidCallbacks_.end(); ++iter) { @@ -1405,6 +1411,7 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string & void DistributedInputSourceManager::RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, uint32_t inputTypes) { + std::lock_guard lock(startStopMutex_); bool isCbRun = false; FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); for (std::vector::iterator iter = @@ -1426,6 +1433,7 @@ void DistributedInputSourceManager::RunRelayStartTypeCallback(const std::string void DistributedInputSourceManager::RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, uint32_t inputTypes) { + std::lock_guard lock(startStopMutex_); bool isCbRun = false; FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); for (std::vector::iterator iter = diff --git a/services/source/transport/BUILD.gn b/services/source/transport/BUILD.gn index f5431b6bf30e638237e5262ba100d8ba09cdc1bf..2d97d2ac536fa4aac11587d2ab43baae5f24c76d 100755 --- a/services/source/transport/BUILD.gn +++ b/services/source/transport/BUILD.gn @@ -64,11 +64,9 @@ ohos_shared_library("libdinput_source_trans") { "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", - "ipc:ipc_core", "json:nlohmann_json_static", "libevdev:libevdev", "samgr:samgr_proxy", diff --git a/services/state/BUILD.gn b/services/state/BUILD.gn index 20e77dfd9a7f2ef5a5015ecb68e492d5733f8ffc..0e831720b9e6705170bc475e6601f9c71d4518c4 100644 --- a/services/state/BUILD.gn +++ b/services/state/BUILD.gn @@ -70,7 +70,6 @@ ohos_shared_library("libdinput_sink_state") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "json:nlohmann_json_static", "libevdev:libevdev", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp index 1426b91f378ecb21b6ce7c90c5d086775b22839a..e76a24a3cdf51b5878bc5dd9dd90c9cb6858379b 100644 --- a/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp +++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/distributed_input_source_transport_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 diff --git a/test/fuzztest/distributedinputtransportbase_fuzzer/distributed_input_transport_base_fuzzer.cpp b/test/fuzztest/distributedinputtransportbase_fuzzer/distributed_input_transport_base_fuzzer.cpp index 24bdce9acec93150880b247ba4ab0ef7c6702d9d..c0c3bbd205ef73d6263cfd307ffeb5bc2d7f5d1d 100644 --- a/test/fuzztest/distributedinputtransportbase_fuzzer/distributed_input_transport_base_fuzzer.cpp +++ b/test/fuzztest/distributedinputtransportbase_fuzzer/distributed_input_transport_base_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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