From 75da50f1e68ad7aa27bc1f38c7b17b900b2a44fe Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 1 Dec 2023 21:12:58 +0800 Subject: [PATCH 1/8] add device id mark for virtual driver Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 2 +- common/include/input_hub.h | 2 - .../include/distributed_input_inject.h | 13 +- .../include/distributed_input_node_manager.h | 56 +++-- .../src/distributed_input_inject.cpp | 70 ++---- .../src/distributed_input_node_manager.cpp | 228 +++++++++--------- .../distributed_input_sourceinject_test.cpp | 52 +--- .../src/dinput_source_listener.cpp | 2 +- .../src/distributed_input_source_manager.cpp | 11 +- .../distributed_input_source_transport.h | 2 +- .../distributed_input_source_transport.cpp | 12 +- 11 files changed, 187 insertions(+), 263 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 4f08970..d6d7201 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -44,7 +44,7 @@ const uint32_t SLEEP_TIME_US = 100 * 1000; const std::string MOUSE_NODE_KEY = "mouse"; } -InputHub::InputHub() : epollFd_(0), iNotifyFd_(0), inputWd_(0), needToScanDevices_(true), nextDeviceId_(1), +InputHub::InputHub() : epollFd_(0), iNotifyFd_(0), inputWd_(0), needToScanDevices_(true), mPendingEventItems{}, pendingEventCount_(0), pendingEventIndex_(0), pendingINotify_(false), deviceChanged_(false), inputTypes_(0), isStartCollectEvent_(false), isStartCollectHandler_(false) { diff --git a/common/include/input_hub.h b/common/include/input_hub.h index d702e2d..83ff337 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -213,9 +213,7 @@ private: std::set skipDevicePaths_; std::atomic needToScanDevices_; - std::string deviceId_; std::string touchDescriptor; - std::atomic nextDeviceId_; // The array of pending epoll events and the index of the next event to be handled. struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 7bb5028..2055e99 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -34,8 +34,7 @@ public: int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const std::string ¶meters); int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId); - int32_t RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize); - int32_t RegisterDistributedEvent(const std::vector &events); + int32_t RegisterDistributedEvent(const std::string deviceId, const std::vector &events); int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); void StartInjectThread(); void StopInjectThread(); @@ -43,16 +42,14 @@ public: const uint32_t sourceWinHeight); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); - int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector &dhIds); int32_t RegisterInjectEventCb(sptr callback); int32_t UnregisterInjectEventCb(); - void NotifyNodeMgrScanVirNode(const std::string &dhId); - void InputDeviceEventInject(const std::shared_ptr &rawEvent); - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds); + void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); + void GetVirtualKeyboardPaths(const std::string &deviceId, const std::vector &dhIds, + std::vector &virKeyboardPaths); private: DistributedInputInject(); ~DistributedInputInject(); diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 9f5ead5..a684c47 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -37,7 +37,19 @@ namespace DistributedHardware { namespace DistributedInput { constexpr uint32_t DINPUT_NODE_MANAGER_SCAN_ALL_NODE = 1; constexpr uint32_t DINPUT_INJECT_EVENT_FAIL = 2; +const std::string INPUT_NODE_DEVID = "devId"; const std::string INPUT_NODE_DHID = "dhId"; +/** + * @brief the unique id for the input peripheral. + * left is device networkid, right is dhId in that device. + */ +using DhUniqueID = std::pair; +/** + * @brief a batch events form one device + * left: device networid where these events from + * right: the event batch + */ +using EventBatch = std::pair>; class DistributedInputNodeManager { public: DistributedInputNodeManager(); @@ -45,25 +57,29 @@ public: int32_t OpenDevicesNode(const std::string &devId, const std::string &dhId, const std::string ¶meters); - int32_t GetDevice(const std::string &dhId, VirtualDevice *&device); - void ReportEvent(const RawEvent rawEvent); - void ReportEvent(const std::vector &events); - int32_t CloseDeviceLocked(const std::string &dhId); + int32_t GetDevice(const std::string &networkId, const std::string &dhId, VirtualDevice *&device); + void ReportEvent(const std::string deviceId, const std::vector &events); + int32_t CloseDeviceLocked(const std::string &networkId, const std::string &dhId); void StartInjectThread(); void StopInjectThread(); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); int32_t GetDeviceInfo(std::string &deviceId); - void GetDevicesInfoByType(const std::string &networkId, uint32_t inputTypes, std::map &datas); - void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); - void ProcessInjectEvent(const std::shared_ptr &rawEvent); - - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds); - void NotifyNodeMgrScanVirNode(const std::string &dhId); + void ProcessInjectEvent(const EventBatch &events); + + /** + * @brief Get the Virtual Keyboard Paths By Dh Ids object + * + * @param dhKeys list for device identify({networkId, dhId}) + * @param virKeyboardPaths the matched keyboard device + * @param virKeyboardDhIds matched keyboard device identify + */ + void GetVirtualKeyboardPaths(const std::vector &dhUniqueIds, + std::vector &virKeyboardPaths); + void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); void RegisterInjectEventCb(sptr callback); void UnregisterInjectEventCb(); @@ -84,7 +100,7 @@ public: }; private: - void AddDeviceLocked(const std::string &dhId, std::unique_ptr device); + void AddDeviceLocked(const std::string &networkId, const std::string &dhId, std::unique_ptr device); int32_t CreateHandle(const InputDevice &inputDevice, const std::string &devId, const std::string &dhId); void ParseInputDeviceJson(const std::string &str, InputDevice &pBuf); void ParseInputDevice(const nlohmann::json &inputDeviceJson, InputDevice &pBuf); @@ -92,15 +108,15 @@ private: void ParseInputDeviceEvents(const nlohmann::json &inputDeviceJson, InputDevice &pBuf); void InjectEvent(); - void ScanSinkInputDevices(const std::string &dhId); - void OpenInputDevice(const std::string &devicePath, const std::string &dhId); + void ScanSinkInputDevices(const std::string &deviceId, const std::string &dhId); + bool MatchAndSavePhysicalPath(const std::string &devicePath, const std::string &deviceId, const std::string &dhId); bool IsVirtualDev(int fd); - bool GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath); - void SetPathForDevMap(const std::string &dhId, const std::string &devicePath); + bool GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnqueId, std::string &physicalPath); + void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); - /* the key is dhId, and the value is virtualDevice */ - std::map> virtualDeviceMap_; + /* the key is {networkId, dhId}, and the value is virtualDevice */ + std::map> virtualDeviceMap_; std::mutex virtualDeviceMapMutex_; std::atomic isInjectThreadCreated_; std::atomic isInjectThreadRunning_; @@ -108,7 +124,7 @@ private: std::thread eventInjectThread_; std::mutex injectThreadMutex_; std::condition_variable conditionVariable_; - std::queue> injectQueue_; + std::queue injectQueue_; std::unique_ptr inputHub_; int32_t virtualTouchScreenFd_; std::once_flag callOnceFlag_; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index d506584..1abbe2b 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -74,7 +74,7 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string DHLOGE("the DistributedInputNodeManager is null\n"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - if (inputNodeManager_->CloseDeviceLocked(dhId) < 0) { + if (inputNodeManager_->CloseDeviceLocked(devId, dhId) < 0) { DHLOGE("delete virtual device error\n"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL; } @@ -83,22 +83,6 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string return DH_SUCCESS; } -int32_t DistributedInputInject::GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, - std::vector &dhIds) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("the inputNodeListener is nullptr"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - std::map datas; - inputNodeManager_->GetDevicesInfoByType(devId, inputTypes, datas); - for (const auto &data_ : datas) { - dhIds.push_back(data_.second); - } - return DH_SUCCESS; -} - int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) { DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version, @@ -126,35 +110,7 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st return DH_SUCCESS; } -void DistributedInputInject::InputDeviceEventInject(const std::shared_ptr &rawEvent) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("the inputNodeListener is nullptr"); - return; - } - if (rawEvent == nullptr) { - DHLOGE("the rawEvent is nullptr"); - return; - } - inputNodeManager_->ProcessInjectEvent(rawEvent); -} - -int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("the DistributedInputNodeManager is null"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - - for (size_t i = 0; i < bufferSize; i++) { - inputNodeManager_->ReportEvent(buffer[i]); - } - return DH_SUCCESS; -} - -int32_t DistributedInputInject::RegisterDistributedEvent(const std::vector &events) +int32_t DistributedInputInject::RegisterDistributedEvent(const std::string deviceId, const std::vector &events) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { @@ -162,7 +118,7 @@ int32_t DistributedInputInject::RegisterDistributedEvent(const std::vectorReportEvent(events); + inputNodeManager_->ReportEvent(deviceId, events); return DH_SUCCESS; } @@ -201,14 +157,14 @@ int32_t DistributedInputInject::CreateVirtualTouchScreenNode(const std::string & return inputNodeManager_->CreateVirtualTouchScreenNode(devId, dhId, srcWinId, sourcePhyWidth, sourcePhyHeight); } -int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &dhId) +int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - return inputNodeManager_->RemoveVirtualTouchScreenNode(dhId); + return inputNodeManager_->RemoveVirtualTouchScreenNode(deviceId, dhId); } int32_t DistributedInputInject::GetVirtualTouchScreenFd() @@ -237,25 +193,31 @@ int32_t DistributedInputInject::UnregisterInjectEventCb() return DH_SUCCESS; } -void DistributedInputInject::GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds) +void DistributedInputInject::GetVirtualKeyboardPaths(const std::string &deviceId, + const std::vector &dhIds, std::vector &virKeyboardPaths) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return; } - inputNodeManager_->GetVirtualKeyboardPathsByDhIds(dhIds, virKeyboardPaths, virKeyboardDhIds); + std::vector dhUniqIds; + std::for_each(dhIds.begin(), dhIds.end(), + [&deviceId, &dhUniqIds](std::string dhId) { + DhUniqueID id = {deviceId, dhId}; + dhUniqIds.push_back(id); + }); + inputNodeManager_->GetVirtualKeyboardPaths(dhUniqIds, virKeyboardPaths); } -void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &dhId) +void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return; } - inputNodeManager_->NotifyNodeMgrScanVirNode(dhId); + inputNodeManager_->NotifyNodeMgrScanVirNode(devId, dhId); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 4e195d6..83dce47 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -152,13 +152,17 @@ void DistributedInputNodeManager::ParseInputDeviceEvents(const nlohmann::json &i } } -void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &dhId) +void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &deviceId, const std::string &dhId) { - DHLOGI("ScanSinkInputDevices enter, dhId %s.", dhId.c_str()); + DHLOGI("ScanSinkInputDevices enter, deviceId:%s, dhId %s.", + GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); std::vector vecInputDevPath; ScanInputDevicesPath(DEVICE_PATH, vecInputDevPath); for (auto &tempPath: vecInputDevPath) { - OpenInputDevice(tempPath, dhId); + if (MatchAndSavePhysicalPath(tempPath, deviceId, dhId)) { + DHLOGI("Set physical path success"); + break; + } } } @@ -197,15 +201,17 @@ void DistributedInputNodeManager::DInputNodeManagerEventHandler::ScanAllNode( std::shared_ptr dataMsg = event->GetSharedObject(); auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); + std::string devId = innerMsg[INPUT_NODE_DEVID]; std::string devicedhId = innerMsg[INPUT_NODE_DHID]; - nodeManagerObj_->ScanSinkInputDevices(devicedhId); + nodeManagerObj_->ScanSinkInputDevices(devId, devicedhId); } -void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &dhId) +void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId) { DHLOGI("NotifyNodeMgrScanVirNode enter."); std::shared_ptr jsonArrayMsg = std::make_shared(); nlohmann::json tmpJson; + tmpJson[INPUT_NODE_DEVID] = devId; tmpJson[INPUT_NODE_DHID] = dhId; jsonArrayMsg->push_back(tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( @@ -232,7 +238,7 @@ bool DistributedInputNodeManager::IsVirtualDev(int fd) return true; } -bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath) +bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnqueId, std::string &physicalPath) { char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { @@ -242,23 +248,32 @@ bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string &dhId, std: buffer[sizeof(buffer) - 1] = '\0'; physicalPath = buffer; - DHLOGD("GetDevDhIdByFd physicalPath %s.", physicalPath.c_str()); - dhId = physicalPath.substr(physicalPath.find(DH_ID_PREFIX)); - if (dhId.size() == 0) { - DHLOGE("Get dev dhid failed."); + DHLOGD("GetDevDhUniqueIdByFd physicalPath %s.", physicalPath.c_str()); + std::vector phyPathVec; + SplitStringToVector(physicalPath, '|', phyPathVec); + if (phyPathVec.size() != 3) { + DHLOGE("The physical path is invalid"); + return false; + } + std::string deviceId = phyPathVec[1]; + std::string dhId = phyPathVec[2]; + if (deviceId.empty() || dhId.empty()) { + DHLOGE("Get dev deviceid and dhid failed."); return false; } - DHLOGD("Device dhId %s.", GetAnonyString(dhId).c_str()); + dhUnqueId.first = deviceId; + dhUnqueId.second = dhId; + DHLOGD("Device deviceid: %s, dhId %s.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); return true; } -void DistributedInputNodeManager::SetPathForDevMap(const std::string &dhId, const std::string &devicePath) +void DistributedInputNodeManager::SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath) { std::lock_guard lock(virtualDeviceMapMutex_); auto iter = virtualDeviceMap_.begin(); while (iter != virtualDeviceMap_.end()) { - DHLOGD("Virtual device map dhid %s.", iter->first.c_str()); - if (dhId.compare(iter->first) == 0) { + DHLOGD("Check Virtual device deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str()); + if (iter->first == dhUniqueId) { DHLOGD("Found the virtual device, set path :%s", devicePath.c_str()); iter->second->SetPath(devicePath); break; @@ -267,45 +282,59 @@ void DistributedInputNodeManager::SetPathForDevMap(const std::string &dhId, cons } } -void DistributedInputNodeManager::OpenInputDevice(const std::string &devicePath, const std::string &dhId) +bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &devicePath, + const std::string &deviceId, const std::string &dhId) { DHLOGI("Opening input device path: %s", devicePath.c_str()); - std::string curDhId; + DhUniqueID curDhUniqueId; std::string physicalPath; int fd = OpenInputDeviceFdByPath(devicePath); if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); - return; + return false; } if (!IsVirtualDev(fd)) { DHLOGE("The dev not virtual, devicePath %s.", devicePath.c_str()); - return; + CloseFd(fd); + return false; } - if (!GetDevDhIdByFd(fd, curDhId, physicalPath) || dhId != curDhId) { - DHLOGE("This is not same dev, curDhId %s.", devicePath.c_str()); - return; + if (!GetDevDhUniqueIdByFd(fd, curDhUniqueId, physicalPath)) { + DHLOGE("Get unique id failed, device path %s.", devicePath.c_str()); + CloseFd(fd); + return false; + } + + DHLOGD("This opening node deviceId: %s, dhId %s, to match node deviceId: %s, dhId: %s", + GetAnonyString(curDhUniqueId.first).c_str(), GetAnonyString(curDhUniqueId.second).c_str(), + GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); + + if (curDhUniqueId.first != deviceId || curDhUniqueId.second != dhId) { + DHLOGW("It is not the target vir node, skip it."); + CloseFd(fd); + return false; } - DHLOGD("curDhId %s.", GetAnonyString(curDhId).c_str()); - SetPathForDevMap(curDhId, devicePath); + + SetPathForVirDev(curDhUniqueId, devicePath); + CloseFd(fd); + return true; } -void DistributedInputNodeManager::GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds) +void DistributedInputNodeManager::GetVirtualKeyboardPaths(const std::vector &dhUniqueIds, + std::vector &virKeyboardPaths) { std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &dhId : dhIds) { + for (const auto &dhUniqueId : dhUniqueIds) { auto iter = virtualDeviceMap_.begin(); while (iter != virtualDeviceMap_.end()) { if (iter->second == nullptr) { DHLOGE("device is nullptr"); continue; } - if ((iter->first.compare(dhId) == 0) && + if ((iter->first == dhUniqueId) && ((iter->second->GetClasses() & INPUT_DEVICE_CLASS_KEYBOARD) != 0)) { - DHLOGI("Found vir keyboard path %s, dhid %s", iter->second->GetPath().c_str(), - GetAnonyString(dhId).c_str()); + DHLOGI("Found vir keyboard path %s, deviceId %s, dhid %s", iter->second->GetPath().c_str(), + GetAnonyString(dhUniqueId.first).c_str(), GetAnonyString(dhUniqueId.second).c_str()); virKeyboardPaths.push_back(iter->second->GetPath()); - virKeyboardDhIds.push_back(dhId); } iter++; } @@ -325,7 +354,7 @@ int32_t DistributedInputNodeManager::CreateHandle(const InputDevice &inputDevice DHLOGE("could not create new virtual device\n"); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } - AddDeviceLocked(inputDevice.descriptor, std::move(virtualDevice)); + AddDeviceLocked(devId, inputDevice.descriptor, std::move(virtualDevice)); return DH_SUCCESS; } @@ -344,14 +373,14 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } virtualTouchScreenFd_ = device->GetDeviceFd(); - AddDeviceLocked(dhId, std::move(device)); + AddDeviceLocked(devId, dhId, std::move(device)); DHLOGI("CreateVirtualTouchScreenNode end, dhId: %s", GetAnonyString(dhId).c_str()); return DH_SUCCESS; } -int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &dhId) +int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId) { - return CloseDeviceLocked(dhId); + return CloseDeviceLocked(deviceId, dhId); } int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd() @@ -359,34 +388,43 @@ int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd() return virtualTouchScreenFd_; } -void DistributedInputNodeManager::AddDeviceLocked(const std::string &dhId, std::unique_ptr device) +void DistributedInputNodeManager::AddDeviceLocked(const std::string &networkId, const std::string &dhId, + std::unique_ptr device) { - DHLOGI("dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("AddDeviceLocked deviceId=%s, dhId=%s", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); - auto [dev_it, inserted] = virtualDeviceMap_.insert_or_assign(dhId, std::move(device)); + auto [dev_it, inserted] = virtualDeviceMap_.insert_or_assign( + {networkId, dhId}, std::move(device)); if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", GetAnonyString(dhId).c_str()); + DHLOGI("Device exists, deviceId=%s, dhId=%s, replaced. \n", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); } } -int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId) +int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &networkId, const std::string &dhId) { - DHLOGI("CloseDeviceLocked called, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called, deviceId=%s, dhId=%s", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); - std::map>::iterator iter = virtualDeviceMap_.find(dhId); + DhUniqueID dhUniqueId = {networkId, dhId}; + std::map>::iterator iter = virtualDeviceMap_.find(dhUniqueId); if (iter != virtualDeviceMap_.end()) { - DHLOGI("CloseDeviceLocked called success, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called success, deviceId=%s, dhId=%s", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); virtualDeviceMap_.erase(iter); return DH_SUCCESS; } - DHLOGE("CloseDeviceLocked called failure, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGE("CloseDeviceLocked called failure, deviceId=%s, dhId=%s", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } -int32_t DistributedInputNodeManager::GetDevice(const std::string &dhId, VirtualDevice *&device) +int32_t DistributedInputNodeManager::GetDevice(const std::string &networkId, const std::string &dhId, + VirtualDevice *&device) { std::lock_guard lock(virtualDeviceMapMutex_); - auto iter = virtualDeviceMap_.find(dhId); + auto iter = virtualDeviceMap_.find({networkId, dhId}); if (iter != virtualDeviceMap_.end()) { device = iter->second.get(); return DH_SUCCESS; @@ -420,19 +458,10 @@ void DistributedInputNodeManager::StopInjectThread() } } -void DistributedInputNodeManager::ReportEvent(const RawEvent rawEvent) -{ - std::lock_guard lockGuard(injectThreadMutex_); - injectQueue_.push(std::make_shared(rawEvent)); - conditionVariable_.notify_all(); -} - -void DistributedInputNodeManager::ReportEvent(const std::vector &events) +void DistributedInputNodeManager::ReportEvent(const std::string deviceId, const std::vector &events) { std::lock_guard lockGuard(injectThreadMutex_); - for (auto ev : events) { - injectQueue_.push(std::make_shared(ev)); - } + injectQueue_.push({deviceId, events}); conditionVariable_.notify_all(); } @@ -444,7 +473,7 @@ void DistributedInputNodeManager::InjectEvent() } DHLOGI("start"); while (isInjectThreadRunning_.load()) { - std::shared_ptr event = nullptr; + EventBatch events; { std::unique_lock waitEventLock(injectThreadMutex_); conditionVariable_.wait(waitEventLock, @@ -452,16 +481,12 @@ void DistributedInputNodeManager::InjectEvent() if (injectQueue_.empty()) { continue; } - event = injectQueue_.front(); + events = injectQueue_.front(); injectQueue_.pop(); } - if (event == nullptr) { - DHLOGD("event is null!"); - continue; - } DHLOGD("process event, inject queue size: %zu", injectQueue_.size()); - ProcessInjectEvent(event); + ProcessInjectEvent(events); } DHLOGI("end"); } @@ -488,23 +513,27 @@ void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); } -void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptr &rawEvent) -{ - std::string dhId = rawEvent->descriptor; - struct input_event event = { - .type = rawEvent->type, - .code = rawEvent->code, - .value = rawEvent->value - }; - DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", - GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); - VirtualDevice* device = nullptr; - if (GetDevice(dhId, device) < 0) { - DHLOGE("could not find the device"); - return; - } - if (device != nullptr) { - device->InjectInputEvent(event); +void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) +{ + std::string deviceId = events.first; + for (const auto &rawEvent : events.second) { + std::string dhId = rawEvent.descriptor; + struct input_event event = { + .type = rawEvent.type, + .code = rawEvent.code, + .value = rawEvent.value + }; + DHLOGI("InjectEvent deviceId: %s, dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", + GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str(), + event.type, event.code, event.value, rawEvent.when); + VirtualDevice* device = nullptr; + if (GetDevice(deviceId, dhId, device) < 0) { + DHLOGE("could not find the device"); + return; + } + if (device != nullptr) { + device->InjectInputEvent(event); + } } } @@ -522,45 +551,6 @@ int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); return DH_SUCCESS; } - -void DistributedInputNodeManager::GetDevicesInfoByType(const std::string &networkId, uint32_t inputTypes, - std::map &datas) -{ - uint32_t inputType = 0; - - if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { - inputType |= INPUT_DEVICE_CLASS_CURSOR; - } - - if ((inputTypes & static_cast(DInputDeviceType::KEYBOARD)) != 0) { - inputType |= INPUT_DEVICE_CLASS_KEYBOARD; - } - - if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { - inputType |= INPUT_DEVICE_CLASS_TOUCH; - } - - std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &[id, virdevice] : virtualDeviceMap_) { - if ((virdevice->GetDeviceType() & inputType) && (virdevice->GetNetWorkId() == networkId)) { - datas.insert(std::pair(virdevice->GetDeviceFd(), id)); - } - } -} - -void DistributedInputNodeManager::GetDevicesInfoByDhId( - std::vector dhidsVec, std::map &datas) -{ - for (auto dhId : dhidsVec) { - std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &[id, virdevice] : virtualDeviceMap_) { - if (id == dhId) { - datas.insert(std::pair(virdevice->GetDeviceFd(), id)); - break; - } - } - } -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index 598f7a7..476caaf 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -287,33 +287,6 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent04, testing:: EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); } -HWTEST_F(DistributedInputSourceInjectTest, GetDhIdsByInputType_001, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::vector dhIds; - std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - dhIds.push_back(dhId); - std::shared_ptr rawEvent = nullptr; - DistributedInputInject::GetInstance().InputDeviceEventInject(rawEvent); - DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); - int32_t ret = DistributedInputInject::GetInstance().GetDhIdsByInputType(devId, - static_cast(DInputDeviceType::ALL), dhIds); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceInjectTest, GetDhIdsByInputType_002, testing::ext::TestSize.Level1) -{ - DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - std::shared_ptr rawEvent = std::make_shared(); - DistributedInputInject::GetInstance().InputDeviceEventInject(rawEvent); - - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::vector dhIds; - int32_t ret = DistributedInputInject::GetInstance().GetDhIdsByInputType(devId, - static_cast(DInputDeviceType::ALL), dhIds); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); -} - HWTEST_F(DistributedInputSourceInjectTest, GenerateVirtualTouchScreenDHId_001, testing::ext::TestSize.Level1) { std::string ret = DistributedInputInject::GetInstance().GenerateVirtualTouchScreenDHId(1, 1860, 980); @@ -337,8 +310,9 @@ HWTEST_F(DistributedInputSourceInjectTest, GetVirtualTouchScreenFd_001, testing: HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_001, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(DH_SUCCESS, ret); } @@ -353,9 +327,10 @@ HWTEST_F(DistributedInputSourceInjectTest, CreateVirtualTouchScreenNode_002, tes HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_002, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); } @@ -379,27 +354,12 @@ HWTEST_F(DistributedInputSourceInjectTest, CreateVirtualTouchScreenNode_003, tes HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_003, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceInjectTest, GetVirtualTouchScreenFd_003, testing::ext::TestSize.Level1) -{ - std::string networkId = "umkyu1b165e1be98151891erbe8r91ev"; - uint32_t inputTypes = 1; - std::map datas; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByType(networkId, inputTypes, datas); - - inputTypes = 2; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByType(networkId, inputTypes, datas); - - std::vector dhidsVec; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByDhId(dhidsVec, datas); - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetVirtualTouchScreenFd(); - EXPECT_NE(-1, ret); -} - HWTEST_F(DistributedInputSourceInjectTest, GetDevice_001, testing::ext::TestSize.Level1) { std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; diff --git a/services/source/sourcemanager/src/dinput_source_listener.cpp b/services/source/sourcemanager/src/dinput_source_listener.cpp index 1553424..5aadc16 100644 --- a/services/source/sourcemanager/src/dinput_source_listener.cpp +++ b/services/source/sourcemanager/src/dinput_source_listener.cpp @@ -370,7 +370,7 @@ void DInputSourceListener::OnReceivedEventRemoteInput(const std::string deviceId ++idx; } - DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer); + DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, mEventBuffer); } void DInputSourceListener::OnReceiveRelayPrepareResult(int32_t status, diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index a0fbb8a..48f4c2d 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -302,7 +302,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st callback->OnResult(devId, dhId, DH_SUCCESS); // 5. Notify node mgr to scan vir dev node info - DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(dhId); + DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(devId, dhId); return DH_SUCCESS; } @@ -1580,7 +1580,8 @@ void DistributedInputSourceManager::RunKeyStateCallback(const std::string &sinkI mEventBuffer.code = code; mEventBuffer.value = value; mEventBuffer.descriptor = dhId; - DistributedInputInject::GetInstance().RegisterDistributedEvent(&mEventBuffer, DINPUT_SOURCE_WRITE_EVENT_SIZE); + std::vector eventBuffers = {mEventBuffer}; + DistributedInputInject::GetInstance().RegisterDistributedEvent(sinkId, eventBuffers); return; } @@ -1801,7 +1802,7 @@ void DistributedInputSourceManager::StopDScreenListener::OnMessage(const DHTopic SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(screenInfoKey); int32_t removeNodeRes = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode( - srcScreenInfo.sourcePhyId); + sourceDevId, srcScreenInfo.sourcePhyId); if (removeNodeRes != DH_SUCCESS) { DHLOGE("Remove virtual touch screen node failed!"); return; @@ -1880,9 +1881,9 @@ void DistributedInputSourceManager::DScreenSourceSvrRecipient::OnRemoteDied(cons } std::string screenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcDevId_, srcWinId_); SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(screenInfoKey); - + std::string sourceDevId = GetLocalNetworkId(); int32_t removeNodeRes = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode( - srcScreenInfo.sourcePhyId); + sourceDevId, srcScreenInfo.sourcePhyId); if (removeNodeRes != DH_SUCCESS) { DHLOGE("Remove virtual touch screen node failed!"); return; diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index 6441f19..88bcba6 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -139,7 +139,7 @@ private: std::vector SplitDhIdString(const std::string &dhIdsString); void RegRespFunMap(); - void ResetKeyboardKeyState(const std::vector &dhids); + void ResetKeyboardKeyState(const std::string &deviceId, const std::vector &dhids); private: std::mutex operationMutex_; std::set sessionIdSet_; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 5bd4c31..031f10c 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -326,7 +326,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI } DHLOGI("StopRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); std::vector dhIdsVec = SplitDhIdString(dhids); - ResetKeyboardKeyState(dhIdsVec); + ResetKeyboardKeyState(deviceId, dhIdsVec); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; @@ -754,13 +754,13 @@ int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &dev return DH_SUCCESS; } -void DistributedInputSourceTransport::ResetKeyboardKeyState(const std::vector &dhids) +void DistributedInputSourceTransport::ResetKeyboardKeyState(const std::string &deviceId, + const std::vector &dhids) { std::vector keyboardNodePaths; - std::vector keyboardNodeDhIds; - DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); + DistributedInputInject::GetInstance().GetVirtualKeyboardPaths(deviceId, dhids, keyboardNodePaths); DHLOGI("Try reset keyboard states, dhIds: %s, nodePaths: %s", - GetString(keyboardNodeDhIds).c_str(), GetString(keyboardNodePaths).c_str()); + GetString(dhids).c_str(), GetString(keyboardNodePaths).c_str()); ResetVirtualDevicePressedKeys(keyboardNodePaths); } @@ -773,7 +773,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; } DHLOGI("StopRemoteInput sessionId:%d.", sessionId); - ResetKeyboardKeyState(dhids); + ResetKeyboardKeyState(deviceId, dhids); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; -- Gitee From 84da6979a6d352305f01ca028391002b512932cb Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 10:22:32 +0800 Subject: [PATCH 2/8] add Signed-off-by: hwzhangchuang --- .../src/distributed_input_inject.cpp | 3 +- .../src/distributed_input_node_manager.cpp | 4 +- .../distributed_input_sourceinject_test.cpp | 210 +++++++++--------- 3 files changed, 109 insertions(+), 108 deletions(-) diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 1abbe2b..8dd6eed 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -110,7 +110,8 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st return DH_SUCCESS; } -int32_t DistributedInputInject::RegisterDistributedEvent(const std::string deviceId, const std::vector &events) +int32_t DistributedInputInject::RegisterDistributedEvent(const std::string deviceId, + const std::vector &events) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 83dce47..7af4ea6 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -424,7 +424,7 @@ int32_t DistributedInputNodeManager::GetDevice(const std::string &networkId, con VirtualDevice *&device) { std::lock_guard lock(virtualDeviceMapMutex_); - auto iter = virtualDeviceMap_.find({networkId, dhId}); + auto iter = virtualDeviceMap_.find({ networkId, dhId }); if (iter != virtualDeviceMap_.end()) { device = iter->second.get(); return DH_SUCCESS; @@ -461,7 +461,7 @@ void DistributedInputNodeManager::StopInjectThread() void DistributedInputNodeManager::ReportEvent(const std::string deviceId, const std::vector &events) { std::lock_guard lockGuard(injectThreadMutex_); - injectQueue_.push({deviceId, events}); + injectQueue_.push({ deviceId, events }); conditionVariable_.notify_all(); } diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index 476caaf..d670f44 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -160,130 +160,129 @@ HWTEST_F(DistributedInputSourceInjectTest, UnregisterDistributedHardware_002, te HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent01, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 1; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 2; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 3; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); + RawEvent event1 = { + .when = 0, + .type = EV_KEy, + .code = KEY_D, + .value = 1, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + }; + RawEvent event2 = { + .when = 1, + .type = EV_KEy, + .code = KEY_D, + .value = 0, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + }; + RawEvent event3 = { + .when = 2, + .type = EV_KEy, + .code = KEY_D, + .value = 1, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + }; + RawEvent event4 = { + .when = 3, + .type = EV_KEy, + .code = KEY_D, + .value = 0, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + }; + std::vector writeBuffer = { event1, event2, event3, event4 }; + DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); DistributedInputInject::GetInstance().StartInjectThread(); DistributedInputInject::GetInstance().StopInjectThread(); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + std::string deviceId = "deviceId123"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent02, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 1; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 2; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 3; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - event->when = 4; - event->type = EV_SYN; - event->code = SYN_REPORT; - event->value = 0; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + RawEvent event1 = { + .when = 0, + .type = EV_REL, + .code = REL_X, + .value = 2, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + }; + RawEvent event2 = { + .when = 1, + .type = EV_REL, + .code = REL_Y, + .value = 2, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + }; + RawEvent event3 = { + .when = 2, + .type = EV_REL, + .code = REL_X, + .value = 3, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + }; + RawEvent event4 = { + .when = 3, + .type = EV_REL, + .code = REL_Y, + .value = 3, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + }; + RawEvent event5 = { + .when = 4, + .type = EV_SYN, + .code = SYN_REPORT, + .value = 0, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + }; + std::vector writeBuffer = { event1, event2, event3, event4, event5}; + std::string deviceId = "deviceId123"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent03, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 1; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 1; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 2; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 2; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 3; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 3; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 4; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + RawEvent event1 = { + .when = 0, + .type = EV_ABS, + .code = ABS_X, + .value = 1, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + }; + RawEvent event2 = { + .when = 1, + .type = EV_ABS, + .code = ABS_X, + .value = 2, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + }; + RawEvent event3 = { + .when = 2, + .type = EV_ABS, + .code = ABS_X, + .value = 3, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + }; + RawEvent event4 = { + .when = 3, + .type = EV_ABS, + .code = ABS_X, + .value = 4, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + }; + std::vector writeBuffer = { event1, event2, event3, event4 }; + std::string deviceId = "deviceId123"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent04, testing::ext::TestSize.Level1) { + std::string deviceId = "deviceId123"; struct RawEvent writeBuffer[4]; - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); } @@ -362,9 +361,10 @@ HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_003, tes HWTEST_F(DistributedInputSourceInjectTest, GetDevice_001, testing::ext::TestSize.Level1) { + std::string deviceId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; VirtualDevice* device = nullptr; - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDevice(dhId, device); + int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDevice(deviceId, dhId, device); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL, ret); } -- Gitee From 7f30af76613df1b05a9eb4b194c8df89c8accdb2 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 10:35:25 +0800 Subject: [PATCH 3/8] modify format Signed-off-by: hwzhangchuang --- .../include/distributed_input_inject.h | 6 ++-- .../include/distributed_input_node_manager.h | 10 +++--- .../src/distributed_input_inject.cpp | 14 ++++---- .../src/distributed_input_node_manager.cpp | 34 +++++++++---------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 2055e99..cb4951a 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -34,7 +34,7 @@ public: int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const std::string ¶meters); int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId); - int32_t RegisterDistributedEvent(const std::string deviceId, const std::vector &events); + int32_t RegisterDistributedEvent(const std::string &devId, const std::vector &events); int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); void StartInjectThread(); void StopInjectThread(); @@ -42,13 +42,13 @@ public: const uint32_t sourceWinHeight); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); int32_t RegisterInjectEventCb(sptr callback); int32_t UnregisterInjectEventCb(); void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); - void GetVirtualKeyboardPaths(const std::string &deviceId, const std::vector &dhIds, + void GetVirtualKeyboardPaths(const std::string &devId, const std::vector &dhIds, std::vector &virKeyboardPaths); private: DistributedInputInject(); diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index a684c47..3c733a6 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -58,16 +58,16 @@ public: int32_t OpenDevicesNode(const std::string &devId, const std::string &dhId, const std::string ¶meters); int32_t GetDevice(const std::string &networkId, const std::string &dhId, VirtualDevice *&device); - void ReportEvent(const std::string deviceId, const std::vector &events); + void ReportEvent(const std::string &devId, const std::vector &events); int32_t CloseDeviceLocked(const std::string &networkId, const std::string &dhId); void StartInjectThread(); void StopInjectThread(); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); - int32_t GetDeviceInfo(std::string &deviceId); + int32_t GetDeviceInfo(std::string &devId); void ProcessInjectEvent(const EventBatch &events); /** @@ -108,8 +108,8 @@ private: void ParseInputDeviceEvents(const nlohmann::json &inputDeviceJson, InputDevice &pBuf); void InjectEvent(); - void ScanSinkInputDevices(const std::string &deviceId, const std::string &dhId); - bool MatchAndSavePhysicalPath(const std::string &devicePath, const std::string &deviceId, const std::string &dhId); + void ScanSinkInputDevices(const std::string &devId, const std::string &dhId); + bool MatchAndSavePhysicalPath(const std::string &devicePath, const std::string &devId, const std::string &dhId); bool IsVirtualDev(int fd); bool GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnqueId, std::string &physicalPath); void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 8dd6eed..8f53ecf 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -110,7 +110,7 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st return DH_SUCCESS; } -int32_t DistributedInputInject::RegisterDistributedEvent(const std::string deviceId, +int32_t DistributedInputInject::RegisterDistributedEvent(const std::string &devId, const std::vector &events) { std::lock_guard lock(inputNodeManagerMutex_); @@ -119,7 +119,7 @@ int32_t DistributedInputInject::RegisterDistributedEvent(const std::string devic return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - inputNodeManager_->ReportEvent(deviceId, events); + inputNodeManager_->ReportEvent(devId, events); return DH_SUCCESS; } @@ -158,14 +158,14 @@ int32_t DistributedInputInject::CreateVirtualTouchScreenNode(const std::string & return inputNodeManager_->CreateVirtualTouchScreenNode(devId, dhId, srcWinId, sourcePhyWidth, sourcePhyHeight); } -int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId) +int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - return inputNodeManager_->RemoveVirtualTouchScreenNode(deviceId, dhId); + return inputNodeManager_->RemoveVirtualTouchScreenNode(devId, dhId); } int32_t DistributedInputInject::GetVirtualTouchScreenFd() @@ -194,7 +194,7 @@ int32_t DistributedInputInject::UnregisterInjectEventCb() return DH_SUCCESS; } -void DistributedInputInject::GetVirtualKeyboardPaths(const std::string &deviceId, +void DistributedInputInject::GetVirtualKeyboardPaths(const std::string &devId, const std::vector &dhIds, std::vector &virKeyboardPaths) { std::lock_guard lock(inputNodeManagerMutex_); @@ -204,8 +204,8 @@ void DistributedInputInject::GetVirtualKeyboardPaths(const std::string &deviceId } std::vector dhUniqIds; std::for_each(dhIds.begin(), dhIds.end(), - [&deviceId, &dhUniqIds](std::string dhId) { - DhUniqueID id = {deviceId, dhId}; + [&devId, &dhUniqIds](std::string dhId) { + DhUniqueID id = {devId, dhId}; dhUniqIds.push_back(id); }); inputNodeManager_->GetVirtualKeyboardPaths(dhUniqIds, virKeyboardPaths); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 7af4ea6..520eebc 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -152,14 +152,14 @@ void DistributedInputNodeManager::ParseInputDeviceEvents(const nlohmann::json &i } } -void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &deviceId, const std::string &dhId) +void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &devId, const std::string &dhId) { DHLOGI("ScanSinkInputDevices enter, deviceId:%s, dhId %s.", - GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::vector vecInputDevPath; ScanInputDevicesPath(DEVICE_PATH, vecInputDevPath); for (auto &tempPath: vecInputDevPath) { - if (MatchAndSavePhysicalPath(tempPath, deviceId, dhId)) { + if (MatchAndSavePhysicalPath(tempPath, devId, dhId)) { DHLOGI("Set physical path success"); break; } @@ -255,15 +255,15 @@ bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnq DHLOGE("The physical path is invalid"); return false; } - std::string deviceId = phyPathVec[1]; + std::string devId = phyPathVec[1]; std::string dhId = phyPathVec[2]; - if (deviceId.empty() || dhId.empty()) { + if (devId.empty() || dhId.empty()) { DHLOGE("Get dev deviceid and dhid failed."); return false; } - dhUnqueId.first = deviceId; + dhUnqueId.first = devId; dhUnqueId.second = dhId; - DHLOGD("Device deviceid: %s, dhId %s.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); + DHLOGD("Device deviceid: %s, dhId %s.", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return true; } @@ -283,7 +283,7 @@ void DistributedInputNodeManager::SetPathForVirDev(const DhUniqueID &dhUniqueId, } bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &devicePath, - const std::string &deviceId, const std::string &dhId) + const std::string &devId, const std::string &dhId) { DHLOGI("Opening input device path: %s", devicePath.c_str()); DhUniqueID curDhUniqueId; @@ -306,9 +306,9 @@ bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &de DHLOGD("This opening node deviceId: %s, dhId %s, to match node deviceId: %s, dhId: %s", GetAnonyString(curDhUniqueId.first).c_str(), GetAnonyString(curDhUniqueId.second).c_str(), - GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - if (curDhUniqueId.first != deviceId || curDhUniqueId.second != dhId) { + if (curDhUniqueId.first != devId || curDhUniqueId.second != dhId) { DHLOGW("It is not the target vir node, skip it."); CloseFd(fd); return false; @@ -378,9 +378,9 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str return DH_SUCCESS; } -int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &deviceId, const std::string &dhId) +int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId) { - return CloseDeviceLocked(deviceId, dhId); + return CloseDeviceLocked(devId, dhId); } int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd() @@ -458,10 +458,10 @@ void DistributedInputNodeManager::StopInjectThread() } } -void DistributedInputNodeManager::ReportEvent(const std::string deviceId, const std::vector &events) +void DistributedInputNodeManager::ReportEvent(const std::string &devId, const std::vector &events) { std::lock_guard lockGuard(injectThreadMutex_); - injectQueue_.push({ deviceId, events }); + injectQueue_.push({ devId, events }); conditionVariable_.notify_all(); } @@ -537,7 +537,7 @@ void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) } } -int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) +int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &devId) { std::unique_lock my_lock(operationMutex_); auto localNode = std::make_unique(); @@ -547,8 +547,8 @@ int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL; } - deviceId = localNode->networkId; - DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); + devId = localNode->networkId; + DHLOGI("device id is %s", GetAnonyString(devId).c_str()); return DH_SUCCESS; } } // namespace DistributedInput -- Gitee From 18ba38cd43c61655eda65c4085f96b77a510af36 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 10:41:44 +0800 Subject: [PATCH 4/8] add Signed-off-by: hwzhangchuang --- .../inputinject/include/distributed_input_node_manager.h | 4 ++-- .../inputinject/src/distributed_input_node_manager.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 3c733a6..defc5bb 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -57,9 +57,9 @@ public: int32_t OpenDevicesNode(const std::string &devId, const std::string &dhId, const std::string ¶meters); - int32_t GetDevice(const std::string &networkId, const std::string &dhId, VirtualDevice *&device); + int32_t GetDevice(const std::string &devId, const std::string &dhId, VirtualDevice *&device); void ReportEvent(const std::string &devId, const std::vector &events); - int32_t CloseDeviceLocked(const std::string &networkId, const std::string &dhId); + int32_t CloseDeviceLocked(const std::string &devId, const std::string &dhId); void StartInjectThread(); void StopInjectThread(); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 520eebc..53e638d 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -402,12 +402,12 @@ void DistributedInputNodeManager::AddDeviceLocked(const std::string &networkId, } } -int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &networkId, const std::string &dhId) +int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &devId, const std::string &dhId) { DHLOGI("CloseDeviceLocked called, deviceId=%s, dhId=%s", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); - DhUniqueID dhUniqueId = {networkId, dhId}; + DhUniqueID dhUniqueId = {devId, dhId}; std::map>::iterator iter = virtualDeviceMap_.find(dhUniqueId); if (iter != virtualDeviceMap_.end()) { DHLOGI("CloseDeviceLocked called success, deviceId=%s, dhId=%s", @@ -420,11 +420,11 @@ int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &networ return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } -int32_t DistributedInputNodeManager::GetDevice(const std::string &networkId, const std::string &dhId, +int32_t DistributedInputNodeManager::GetDevice(const std::string &devId, const std::string &dhId, VirtualDevice *&device) { std::lock_guard lock(virtualDeviceMapMutex_); - auto iter = virtualDeviceMap_.find({ networkId, dhId }); + auto iter = virtualDeviceMap_.find({ devId, dhId }); if (iter != virtualDeviceMap_.end()) { device = iter->second.get(); return DH_SUCCESS; -- Gitee From 107b3cf189e1298f9877a0dc0857b75efed12ebf Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 11:11:51 +0800 Subject: [PATCH 5/8] add Signed-off-by: hwzhangchuang --- common/include/constants_dinput.h | 6 +++ .../include/distributed_input_handler.h | 3 +- .../src/distributed_input_handler.cpp | 22 +------- .../include/distributed_input_node_manager.h | 1 - .../src/distributed_input_node_manager.cpp | 29 +++------- .../source/inputinject/src/virtual_device.cpp | 4 +- .../distributed_input_sourceinject_test.cpp | 54 ++++++++----------- 7 files changed, 41 insertions(+), 78 deletions(-) diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 4543d32..af2e06c 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -136,6 +136,12 @@ namespace DistributedInput { const std::string DINPUT_SPLIT_COMMA = ", "; + const char VIR_NODE_SPLIT = '|'; + const char VIR_NODE_PID_SPLIT = '/'; + const uint32_t VIR_NODE_PHY_LEN = 3; + const uint32_t VIR_NODE_PHY_DEVID_IDX = 1; + const uint32_t VIR_NODE_PHY_DHID_IDX = 2; + const std::string SOURCE_DEVICE_ID = "sourceDevId"; const std::string SINK_DEVICE_ID = "sinkDevId"; diff --git a/inputdevicehandler/include/distributed_input_handler.h b/inputdevicehandler/include/distributed_input_handler.h index 16087a8..c41d095 100644 --- a/inputdevicehandler/include/distributed_input_handler.h +++ b/inputdevicehandler/include/distributed_input_handler.h @@ -53,7 +53,6 @@ private: DistributedInputHandler(); ~DistributedInputHandler(); void StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); - int32_t GetDeviceInfo(std::string &deviceId); std::shared_ptr m_listener; bool InitCollectEventsThread(); void NotifyHardWare(int iCnt); @@ -62,7 +61,7 @@ private: bool isCollectingEvents_; bool isStartCollectEventThread; static void *CollectEventsThread(void *param); - void StartInputMonitorDeviceThread(const std::string deviceId); + void StartInputMonitorDeviceThread(); void StopInputMonitorDeviceThread(); // The event queue. diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 6972463..8cb619c 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -149,21 +149,6 @@ void DistributedInputHandler::UnRegisterPluginListener() this->m_listener = nullptr; } -int32_t DistributedInputHandler::GetDeviceInfo(std::string &deviceId) -{ - std::unique_lock my_lock(operationMutex_); - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo("ohos.dhardware", localNode.get()); - if (retCode != 0) { - DHLOGE("Could not get device id."); - return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL; - } - - deviceId = localNode->networkId; - DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); - return DH_SUCCESS; -} - bool DistributedInputHandler::InitCollectEventsThread() { pthread_attr_t attr; @@ -190,15 +175,12 @@ void *DistributedInputHandler::CollectEventsThread(void *param) DHLOGE("CollectEventsThread setname failed."); } DistributedInputHandler *pThis = reinterpret_cast(param); - - std::string deviceId; - pThis->GetDeviceInfo(deviceId); - pThis->StartInputMonitorDeviceThread(deviceId); + pThis->StartInputMonitorDeviceThread(); DHLOGI("DistributedInputHandler::CollectEventsThread exist!"); return nullptr; } -void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId) +void DistributedInputHandler::StartInputMonitorDeviceThread() { if (inputHub_ == nullptr) { DHLOGE("inputHub_ not initialized"); diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index defc5bb..ace7b0e 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -67,7 +67,6 @@ public: int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); - int32_t GetDeviceInfo(std::string &devId); void ProcessInjectEvent(const EventBatch &events); /** diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 53e638d..c9e6c76 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -154,7 +154,7 @@ void DistributedInputNodeManager::ParseInputDeviceEvents(const nlohmann::json &i void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &devId, const std::string &dhId) { - DHLOGI("ScanSinkInputDevices enter, deviceId:%s, dhId %s.", + DHLOGI("ScanSinkInputDevices enter, deviceId: %s, dhId: %s.", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::vector vecInputDevPath; ScanInputDevicesPath(DEVICE_PATH, vecInputDevPath); @@ -250,13 +250,13 @@ bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnq DHLOGD("GetDevDhUniqueIdByFd physicalPath %s.", physicalPath.c_str()); std::vector phyPathVec; - SplitStringToVector(physicalPath, '|', phyPathVec); - if (phyPathVec.size() != 3) { + SplitStringToVector(physicalPath, VIR_NODE_SPLIT, phyPathVec); + if (phyPathVec.size() != VIR_NODE_PHY_LEN) { DHLOGE("The physical path is invalid"); return false; } - std::string devId = phyPathVec[1]; - std::string dhId = phyPathVec[2]; + std::string devId = phyPathVec[VIR_NODE_PHY_DEVID_IDX]; + std::string dhId = phyPathVec[VIR_NODE_PHY_DHID_IDX]; if (devId.empty() || dhId.empty()) { DHLOGE("Get dev deviceid and dhid failed."); return false; @@ -272,7 +272,7 @@ void DistributedInputNodeManager::SetPathForVirDev(const DhUniqueID &dhUniqueId, std::lock_guard lock(virtualDeviceMapMutex_); auto iter = virtualDeviceMap_.begin(); while (iter != virtualDeviceMap_.end()) { - DHLOGD("Check Virtual device deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str()); + DHLOGD("Check Virtual device, deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str()); if (iter->first == dhUniqueId) { DHLOGD("Found the virtual device, set path :%s", devicePath.c_str()); iter->second->SetPath(devicePath); @@ -304,7 +304,7 @@ bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &de return false; } - DHLOGD("This opening node deviceId: %s, dhId %s, to match node deviceId: %s, dhId: %s", + DHLOGD("This opening node deviceId: %s, dhId: %s, to match node deviceId: %s, dhId: %s", GetAnonyString(curDhUniqueId.first).c_str(), GetAnonyString(curDhUniqueId.second).c_str(), GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); @@ -536,21 +536,6 @@ void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) } } } - -int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &devId) -{ - std::unique_lock my_lock(operationMutex_); - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get()); - if (retCode != 0) { - DHLOGE("Could not get device id."); - return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL; - } - - devId = localNode->networkId; - DHLOGI("device id is %s", GetAnonyString(devId).c_str()); - return DH_SUCCESS; -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index 799890e..f75dcbf 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -110,8 +110,8 @@ void VirtualDevice::SetABSInfo(struct uinput_user_dev &inputUserDev, const Input bool VirtualDevice::SetPhys(const std::string &deviceName, const std::string &dhId) { std::string phys; - phys.append(deviceName).append(pid_).append("/").append(pid_).append("|") - .append(netWorkId_).append("|").append(dhId); + phys.append(deviceName).append(pid_).append(VIR_NODE_PID_SPLIT).append(pid_).append(VIR_NODE_SPLIT) + .append(netWorkId_).append(VIR_NODE_SPLIT).append(dhId); if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) { return false; diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index d670f44..43f2c16 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -162,38 +162,38 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent01, testing:: { RawEvent event1 = { .when = 0, - .type = EV_KEy, + .type = EV_KEY, .code = KEY_D, .value = 1, - .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" }; RawEvent event2 = { .when = 1, - .type = EV_KEy, + .type = EV_KEY, .code = KEY_D, .value = 0, - .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" }; RawEvent event3 = { .when = 2, - .type = EV_KEy, + .type = EV_KEY, .code = KEY_D, .value = 1, - .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" }; RawEvent event4 = { .when = 3, - .type = EV_KEy, + .type = EV_KEY, .code = KEY_D, .value = 0, - .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" }; std::vector writeBuffer = { event1, event2, event3, event4 }; DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); DistributedInputInject::GetInstance().StartInjectThread(); DistributedInputInject::GetInstance().StopInjectThread(); - std::string deviceId = "deviceId123"; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } @@ -205,38 +205,38 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent02, testing:: .type = EV_REL, .code = REL_X, .value = 2, - .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" }; RawEvent event2 = { .when = 1, .type = EV_REL, .code = REL_Y, .value = 2, - .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" }; RawEvent event3 = { .when = 2, .type = EV_REL, .code = REL_X, .value = 3, - .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" }; RawEvent event4 = { .when = 3, .type = EV_REL, .code = REL_Y, .value = 3, - .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" }; RawEvent event5 = { .when = 4, .type = EV_SYN, .code = SYN_REPORT, .value = 0, - .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" }; - std::vector writeBuffer = { event1, event2, event3, event4, event5}; - std::string deviceId = "deviceId123"; + std::vector writeBuffer = { event1, event2, event3, event4, event5 }; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } @@ -248,39 +248,39 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent03, testing:: .type = EV_ABS, .code = ABS_X, .value = 1, - .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" }; RawEvent event2 = { .when = 1, .type = EV_ABS, .code = ABS_X, .value = 2, - .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" }; RawEvent event3 = { .when = 2, .type = EV_ABS, .code = ABS_X, .value = 3, - .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" }; RawEvent event4 = { .when = 3, .type = EV_ABS, .code = ABS_X, .value = 4, - .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" }; std::vector writeBuffer = { event1, event2, event3, event4 }; - std::string deviceId = "deviceId123"; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent04, testing::ext::TestSize.Level1) { - std::string deviceId = "deviceId123"; - struct RawEvent writeBuffer[4]; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; + std::vector writeBuffer(4); DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); @@ -405,14 +405,6 @@ HWTEST_F(DistributedInputSourceInjectTest, OpenDevicesNode_002, testing::ext::Te ret = DistributedInputInject::GetInstance().inputNodeManager_->OpenDevicesNode(devId, dhIdtest, param); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL, ret); } - -HWTEST_F(DistributedInputSourceInjectTest, GetDeviceInfo_001, testing::ext::TestSize.Level1) -{ - std::string deviceId = ""; - DistributedInputInject::GetInstance().inputNodeManager_->InjectEvent(); - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDeviceInfo(deviceId); - EXPECT_EQ(DH_SUCCESS, ret); -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -- Gitee From f6da8a5e4ea32cd001dfbd921e086dbd1d2f803d Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 11:58:08 +0800 Subject: [PATCH 6/8] add Signed-off-by: hwzhangchuang --- common/include/constants_dinput.h | 5 +++-- .../inputinject/src/distributed_input_node_manager.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index af2e06c..f4b2a44 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -136,8 +136,9 @@ namespace DistributedInput { const std::string DINPUT_SPLIT_COMMA = ", "; - const char VIR_NODE_SPLIT = '|'; - const char VIR_NODE_PID_SPLIT = '/'; + const char VIR_NODE_SPLIT_CHAR = '|'; + const std::string VIR_NODE_SPLIT = "|"; + const std::string VIR_NODE_PID_SPLIT = "/"; const uint32_t VIR_NODE_PHY_LEN = 3; const uint32_t VIR_NODE_PHY_DEVID_IDX = 1; const uint32_t VIR_NODE_PHY_DHID_IDX = 2; diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index c9e6c76..1250881 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -250,7 +250,7 @@ bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnq DHLOGD("GetDevDhUniqueIdByFd physicalPath %s.", physicalPath.c_str()); std::vector phyPathVec; - SplitStringToVector(physicalPath, VIR_NODE_SPLIT, phyPathVec); + SplitStringToVector(physicalPath, VIR_NODE_SPLIT_CHAR, phyPathVec); if (phyPathVec.size() != VIR_NODE_PHY_LEN) { DHLOGE("The physical path is invalid"); return false; @@ -405,18 +405,18 @@ void DistributedInputNodeManager::AddDeviceLocked(const std::string &networkId, int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &devId, const std::string &dhId) { DHLOGI("CloseDeviceLocked called, deviceId=%s, dhId=%s", - GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); DhUniqueID dhUniqueId = {devId, dhId}; std::map>::iterator iter = virtualDeviceMap_.find(dhUniqueId); if (iter != virtualDeviceMap_.end()) { DHLOGI("CloseDeviceLocked called success, deviceId=%s, dhId=%s", - GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); virtualDeviceMap_.erase(iter); return DH_SUCCESS; } DHLOGE("CloseDeviceLocked called failure, deviceId=%s, dhId=%s", - GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } -- Gitee From 1f26536ad00990327d9d450cbbbf299d6c4b040b Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 11:59:59 +0800 Subject: [PATCH 7/8] add Signed-off-by: hwzhangchuang --- .../source/inputinject/src/distributed_input_node_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 1250881..2c59710 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -424,7 +424,7 @@ int32_t DistributedInputNodeManager::GetDevice(const std::string &devId, const s VirtualDevice *&device) { std::lock_guard lock(virtualDeviceMapMutex_); - auto iter = virtualDeviceMap_.find({ devId, dhId }); + auto iter = virtualDeviceMap_.find({devId, dhId}); if (iter != virtualDeviceMap_.end()) { device = iter->second.get(); return DH_SUCCESS; @@ -461,7 +461,7 @@ void DistributedInputNodeManager::StopInjectThread() void DistributedInputNodeManager::ReportEvent(const std::string &devId, const std::vector &events) { std::lock_guard lockGuard(injectThreadMutex_); - injectQueue_.push({ devId, events }); + injectQueue_.push({devId, events}); conditionVariable_.notify_all(); } -- Gitee From 405c9cb0952feafd71628acf92d3466f069c61eb Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 2 Dec 2023 15:08:37 +0800 Subject: [PATCH 8/8] add Signed-off-by: hwzhangchuang --- .../test/inputhandlertest/distributed_input_handler_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp index 979a5cd..bcf713b 100644 --- a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp @@ -58,11 +58,10 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le uint32_t inputTypes = static_cast(DInputDeviceType::ALL); std::map datas; std::vector dhidsVec; - std::string deviceId = "deviceId_test"; dInputHandler.FindDevicesInfoByType(inputTypes, datas); dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas); dInputHandler.Query(); - dInputHandler.StartInputMonitorDeviceThread(deviceId); + dInputHandler.StartInputMonitorDeviceThread(); InputDevice inputDevice; dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED; @@ -77,7 +76,7 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le std::map ret = dInputHandler.QueryExtraInfo(); EXPECT_EQ(0, ret.size()); dInputHandler.inputHub_ = std::make_unique(); - dInputHandler.StartInputMonitorDeviceThread(deviceId); + dInputHandler.StartInputMonitorDeviceThread(); } } // namespace DistributedInput } // namespace DistributedHardware -- Gitee