From 9ff347a69cbf242f3babc6fd833fc8c67f55c2cd Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 16:11:58 +0800 Subject: [PATCH 1/7] sim touchpad up Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 13 +++++ common/include/input_hub.h | 1 + .../src/distributed_input_sink_manager.cpp | 4 +- services/state/include/dinput_state.h | 12 +++++ services/state/src/dinput_state.cpp | 48 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index afbbecb..7de764f 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -201,6 +201,12 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) return event - buffer; } +bool InputHub::IsTouchPad(Device *device) +{ + return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) && + IsTouchPad(device->identifier)); +} + bool InputHub::IsTouchPad(const InputDevice &inputDevice) { std::string dhName = inputDevice.name; @@ -254,6 +260,13 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { DInputState::GetInstance().RefreshABSPosition(event.descriptor, -1, event.value); } + + if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && + !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { + DHLOGI("Find touchpad UP state that not down effective at sink side, dhId: %s", + event.descriptor.c_str()); + DInputState::GetInstance().SimulateTouchPadUpState(event.descriptor, event); + } DHLOGD("RecordDeviceChangeStates end."); } } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 83ff337..9e6e64c 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -151,6 +151,7 @@ private: bool ContainsNonZeroByte(const uint8_t *array, uint32_t startIndex, uint32_t endIndex); int64_t ProcessEventTimestamp(const input_event &event); bool IsTouchPad(const InputDevice &inputDevice); + bool IsTouchPad(Device *device); /* * this macro is used to tell if "bit" is set in "array" diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index b4ade68..d600479 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -320,7 +320,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, sessionId); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", sessionId); @@ -387,7 +387,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, toSinkSessionId); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", toSinkSessionId); diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index 5dfa229..5b217ff 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -16,6 +16,7 @@ #ifndef DISTRIBUTED_INPUT_STATE_BASE_H #define DISTRIBUTED_INPUT_STATE_BASE_H +#include #include #include #include @@ -64,6 +65,16 @@ public: void RefreshABSPosition(const std::string &dhId, int32_t absX, int32_t absY); std::pair GetAndClearABSPosition(const std::string &dhId); + + void SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event); + /** + * @brief check is one device in down state + * + * @param dhId the dhid + * @return true in down state + * @return false NOT in down state + */ + bool IsDhIdDown(const std::string &dhId); private: DInputState() = default; ~DInputState(); @@ -82,6 +93,7 @@ private: std::mutex absPosMtx_; // Record abs x/y of touchpad std::unordered_map> absPositionsMap_; + std::atomic lastSessionId_ {0}; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 846b5e2..9c29850 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -70,6 +70,7 @@ int32_t DInputState::RecordDhIds(const std::vector &dhIds, DhIdStat if (state == DhIdState::THROUGH_OUT) { SimulateEventInjectToSrc(sessionId, dhIds); } + lastSessionId_ = sessionId; return DH_SUCCESS; } @@ -167,6 +168,46 @@ void DInputState::SimulateBtnTouchEvent(const int32_t sessionId, const std::stri DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(sessionId, simEvents); } +void DInputState::SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event) +{ + DHLOGI("Sinmulate touch pad UP state to source, dhId: %s", dhId.c_str()); + int32_t simTrackingId = 0xffffffff; + std::vector simEvents; + RawEvent touchTrackingIdEv1 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + simEvents.push_back(touchTrackingIdEv1); + + RawEvent btnToolFingerDownEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE, dhId, event.path }; + simEvents.push_back(btnToolFingerDownEv); + + RawEvent btnToolDoubleTapUpEv = { event.when, EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE, dhId, event.path }; + simEvents.push_back(btnToolDoubleTapUpEv); + + RawEvent mscEv1 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + simEvents.push_back(mscEv1); + + RawEvent sycReportEv1 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + simEvents.push_back(sycReportEv1); + + RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path }; + simEvents.push_back(btnMouseUpEv); + + RawEvent touchTrackingIdEv2 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + simEvents.push_back(touchTrackingIdEv2); + + RawEvent btnTouchUpEv = { event.when, EV_KEY, BTN_TOUCH, KEY_UP_STATE, dhId, event.path }; + simEvents.push_back(btnTouchUpEv); + + RawEvent btnToolFingerUpEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE, dhId, event.path }; + simEvents.push_back(btnToolFingerDownEv); + + RawEvent mscEv2 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + simEvents.push_back(mscEv2); + + RawEvent sycReportEv2 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + simEvents.push_back(sycReportEv2); + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); +} + void DInputState::SimulateNormalEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) { DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, @@ -200,6 +241,13 @@ std::pair DInputState::GetAndClearABSPosition(const std::strin return absPos; } +bool DInputState::IsDhIdDown(const std::string &dhId) +{ + std::lock_guard mapLock(keyDownStateMapMtx_); + auto iter = keyDownStateMap_.find(dhId); + return iter != keyDownStateMap_.end(); +} + void DInputState::AddKeyDownState(struct RawEvent event) { std::lock_guard mapLock(keyDownStateMapMtx_); From 85cc6313a3fc040734b01f5e0df01868f7f46b29 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 16:30:05 +0800 Subject: [PATCH 2/7] add Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 7de764f..1db2a6f 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -204,7 +204,7 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) bool InputHub::IsTouchPad(Device *device) { return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) && - IsTouchPad(device->identifier)); + IsTouchPad(device->identifier); } bool InputHub::IsTouchPad(const InputDevice &inputDevice) From 41ccaf64efd44a51e9d274ef8113679d655885bd Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 21:44:01 +0800 Subject: [PATCH 3/7] add Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 13 -- common/include/input_hub.h | 1 - .../src/distributed_input_sink_manager.cpp | 4 +- .../include/distributed_input_inject.h | 1 + .../include/distributed_input_node_manager.h | 20 ++ .../inputinject/include/virtual_device.h | 1 + .../src/distributed_input_inject.cpp | 11 + .../src/distributed_input_node_manager.cpp | 197 ++++++++++++++++++ .../source/inputinject/src/virtual_device.cpp | 5 + .../distributed_input_source_transport.cpp | 2 + services/state/include/dinput_state.h | 12 -- services/state/src/dinput_state.cpp | 48 ----- 12 files changed, 239 insertions(+), 76 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 1db2a6f..afbbecb 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -201,12 +201,6 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) return event - buffer; } -bool InputHub::IsTouchPad(Device *device) -{ - return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) && - IsTouchPad(device->identifier); -} - bool InputHub::IsTouchPad(const InputDevice &inputDevice) { std::string dhName = inputDevice.name; @@ -260,13 +254,6 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { DInputState::GetInstance().RefreshABSPosition(event.descriptor, -1, event.value); } - - if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && - !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { - DHLOGI("Find touchpad UP state that not down effective at sink side, dhId: %s", - event.descriptor.c_str()); - DInputState::GetInstance().SimulateTouchPadUpState(event.descriptor, event); - } DHLOGD("RecordDeviceChangeStates end."); } } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 9e6e64c..83ff337 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -151,7 +151,6 @@ private: bool ContainsNonZeroByte(const uint8_t *array, uint32_t startIndex, uint32_t endIndex); int64_t ProcessEventTimestamp(const input_event &event); bool IsTouchPad(const InputDevice &inputDevice); - bool IsTouchPad(Device *device); /* * this macro is used to tell if "bit" is set in "array" diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index d600479..b4ade68 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -320,7 +320,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, sessionId); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", sessionId); @@ -387,7 +387,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, toSinkSessionId); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", toSinkSessionId); diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index cb4951a..c03fd82 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -50,6 +50,7 @@ public: void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); void GetVirtualKeyboardPaths(const std::string &devId, const std::vector &dhIds, std::vector &virKeyboardPaths); + void ResetTouchPadBtnMouseState(const std::string &deviceId, const std::vector &dhIds); 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 ace7b0e..9e3aec0 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -68,6 +68,7 @@ public: int32_t GetVirtualTouchScreenFd(); void ProcessInjectEvent(const EventBatch &events); + void ResetTouchPadBtnMouseState(const std::string &deviceId, const std::vector &dhIds); /** * @brief Get the Virtual Keyboard Paths By Dh Ids object @@ -114,6 +115,18 @@ private: void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); + void RecordEvents(const RawEvent &event, const VirtualDevice* device); + bool IsTouchPad(const std::string &deviceName); + + void AddBtnMouseDownState(int32_t fd); + void RemoveBtnMouseDownState(int32_t fd); + void RecordChangeEventLog(const RawEvent &event); + void RefreshABSPosition(int32_t fd, int32_t absX, int32_t absY); + void ClearCachedState(int32_t fd); + + void SimulateTouchPadUpState(const std::string &deviceId, const std::string &dhId, + int32_t fd, int32_t dx, int32_t dy); + /* the key is {networkId, dhId}, and the value is virtualDevice */ std::map> virtualDeviceMap_; std::mutex virtualDeviceMapMutex_; @@ -129,6 +142,13 @@ private: std::once_flag callOnceFlag_; std::shared_ptr callBackHandler_; sptr SessionStateCallback_; + + std::mutex absPosMtx_; + // Record abs x/y of touchpad, {fd, {dx, dy}} + std::unordered_map> absPositionsMap_; + + std::mutex downBtnMouseFdsMtx_; + std::set downTouchPadBtnMouseFds_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/include/virtual_device.h b/services/source/inputinject/include/virtual_device.h index bcec29e..e92b477 100644 --- a/services/source/inputinject/include/virtual_device.h +++ b/services/source/inputinject/include/virtual_device.h @@ -50,6 +50,7 @@ public: int32_t GetDeviceFd(); uint16_t GetDeviceType(); + std::string GetDeviceName(); private: int32_t fd_ = -1; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 8f53ecf..719882b 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -220,6 +220,17 @@ void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &devId, } inputNodeManager_->NotifyNodeMgrScanVirNode(devId, dhId); } + +void DistributedInputInject::ResetTouchPadBtnMouseState(const std::string &deviceId, + const std::vector &dhIds) +{ + std::lock_guard lock(inputNodeManagerMutex_); + if (inputNodeManager_ == nullptr) { + DHLOGE("ResetTouchPadBtnMouseState inputNodeManager is nullptr"); + return; + } + inputNodeManager_->ResetTouchPadBtnMouseState(deviceId, dhIds); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index a429a98..34953f8 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -513,6 +513,202 @@ void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); } +bool DistributedInputNodeManager::IsTouchPad(const std::string &deviceName) +{ + DHLOGD("device name is %s.", deviceName.c_str()); + transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower); + if (deviceName.find(DH_TOUCH_PAD) == std::string::npos) { + return false; + } + return true; +} + +void DistributedInputNodeManager::AddBtnMouseDownState(int32_t fd) +{ + std::lock_guard mapLock(downBtnMouseFdsMtx_); + downTouchPadBtnMouseFds_.insert(fd); +} + +void DistributedInputNodeManager::RemoveBtnMouseDownState(int32_t fd) +{ + std::lock_guard mapLock(downBtnMouseFdsMtx_); + downTouchPadBtnMouseFds_.erase(fd); +} + +void DistributedInputNodeManager::ClearCachedState(int32_t fd) +{ + std::lock_guard lock(absPosMtx_); + absPositionsMap_.erase(fd); + + std::lock_guard mapLock(downBtnMouseFdsMtx_); + downTouchPadBtnMouseFds_.erase(fd); +} + +void DistributedInputNodeManager::RecordEvents(const RawEvent &event, const VirtualDevice* device) +{ + bool isTouchEvent = false; + if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && + IsTouchPad(device->GetDeviceName())) { + isTouchEvent = true; + } + + if (!isTouchEvent) { + return; + } + + if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_X || event.code == ABS_X)) { + RefreshABSPosition(device->GetDeviceFd(), event.value, -1); + } + + if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { + RefreshABSPosition(device->GetDeviceFd(), -1, event.value); + } + + // Deal btn mouse state + if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_DOWN_STATE) { + AddBtnMouseDownState(event); + RecordChangeEventLog(event); + } + + if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE) { + RemoveBtnMouseDownState(event); + RecordChangeEventLog(event); + } +} + +void DistributedInputNodeManager::RecordChangeEventLog(const RawEvent &event) +{ + std::string eventType = ""; + switch (event.type) { + case EV_KEY: + eventType = "EV_KEY"; + break; + case EV_REL: + eventType = "EV_REL"; + break; + case EV_ABS: + eventType = "EV_ABS"; + break; + case EV_SYN: + eventType = "EV_SYN"; + break; + default: + eventType = "other type " + std::to_string(event.type); + break; + } + DHLOGI("6.E2E-Test Sink collect change event, EventType: %s, Code: %d, Value: %d, Path: %s, descriptor: %s," + "When:%" PRId64 "", eventType.c_str(), event.code, event.value, event.path.c_str(), + GetAnonyString(event.descriptor).c_str(), event.when); +} + +void DistributedInputNodeManager::RefreshABSPosition(int32_t fd, int32_t absX, int32_t absY) +{ + std::lock_guard lock(absPosMtx_); + if (absX != -1) { + absPositionsMap_[fd].first = absX; + } + + if (absY != -1) { + absPositionsMap_[fd].second = absY; + } +} + +void DistributedInputNodeManager::ResetTouchPadBtnMouseState(const std::string &deviceId, + const std::vector &dhIds) +{ + VirtualDevice* device = nullptr; + bool isTouchPad = false; + for (auto const &dhId : dhIds) { + if (GetDevice(deviceId, dhId, device) < 0 || device == nullptr) { + DHLOGE("could not find the device"); + continue; + } + + if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || + (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && + IsTouchPad(device->GetDeviceName())) { + isTouchPad = true; + } + + if (!isTouchPad) { + continue; + } + + int32_t fd = device->GetDeviceFd(); + + DHLOGI("Find the touchpad stopped, try reset it's state, deviceId: %s, dhId: %s, fd: %d", + deviceId.c_str(), dhId.c_str(), fd); + int32_t dx = -1; + int32_t dy = -1; + { + std::lock_guard lock(downBtnMouseFdsMtx_); + if (downTouchPadBtnMouseFds_.count(fd) == 0) { + continue; + } else { + downTouchPadBtnMouseFds_.erase(fd); + DHLOGI("Find this touchpad fd should reset, fd: %d", fd); + } + } + + { + std::lock_guard lock(absPosMtx_); + if (absPositionsMap_.count(fd) == 0) { + DHLOGE("Find touch pad need reset, but CAN NOT find dx,dy"); + dx = 0; + dy = 0; + } else { + dx = absPositionsMap_[fd].first; + dy = absPositionsMap_[fd].second; + absPositionsMap_.erase(fd); + } + } + SimulateTouchPadUpState(deviceId, dhId, fd, dx, dy); + } +} + +void DistributedInputNodeManager::SimulateTouchPadUpState(const std::string &deviceId, const std::string &dhId, + int32_t fd, int32_t dx, int32_t dy) +{ + DHLOGI("Sinmulate touch pad UP state events, deviceId: %s, dhId: %s, fd: %d, dx: %d, dy: %d", + deviceId.c_str(), dhId.c_str(), fd, dx, dy); + int32_t simTrackingId = 0xffffffff; + input_event touchTrackingIdEv1 = { EV_ABS, ABS_MT_TRACKING_ID, simTrackingId }; + input_event btnToolFingerDownEv = { EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE }; + input_event btnToolDoubleTapUpEv = { EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE }; + input_event mscEv1 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; + input_event sycReportEv1 = { EV_SYN, SYN_REPORT, 0x0 }; + + input_event absMtPosX1 = { EV_ABS, ABS_MT_POSITION_X, dx }; + input_event absMtPosY1 = { EV_ABS, ABS_MT_POSITION_Y, dy }; + input_event absPosX1 = { EV_ABS, ABS_X, dx }; + input_event absPosY1 = { EV_ABS, ABS_Y, dy }; + input_event mscEv2 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; + input_event sycReportEv2 = { EV_SYN, SYN_REPORT, 0x0 }; + + input_event absMtPosX2 = { EV_ABS, ABS_MT_POSITION_X, dx }; + input_event absMtPosY2 = { EV_ABS, ABS_MT_POSITION_Y, dy }; + input_event btnMouseUpEv = { EV_KEY, BTN_MOUSE, KEY_UP_STATE }; + input_event absPosX2 = { EV_ABS, ABS_X, dx }; + input_event absPosY2 = { EV_ABS, ABS_Y, dy }; + input_event mscEv3 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; + input_event sycReportEv3 = { EV_SYN, SYN_REPORT, 0x0 }; + + input_event touchTrackingIdEv2 = { EV_ABS, ABS_MT_TRACKING_ID, simTrackingId }; + input_event btnTouchUpEv = { EV_KEY, BTN_TOUCH, KEY_UP_STATE }; + input_event btnToolFingerUpEv = { EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE }; + input_event mscEv4 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; + input_event sycReportEv4 = { EV_SYN, SYN_REPORT, 0x0 }; + + std::vector simEvents = { + touchTrackingIdEv1, btnToolFingerDownEv, btnToolDoubleTapUpEv, mscEv1, sycReportEv1, + absMtPosX1, absMtPosY1, absPosX1, absPosY1, mscEv2, sycReportEv2, + absMtPosX2, absMtPosY2, btnMouseUpEv, absPosX2, absPosY2, mscEv3, sycReportEv3, + touchTrackingIdEv2, btnTouchUpEv, btnToolFingerUpEv, mscEv4, sycReportEv4 }; + for (auto &event : simEvents) { + WriteEventToDevice(fd, event); + } +} + void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) { std::string deviceId = events.first; @@ -532,6 +728,7 @@ void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) return; } if (device != nullptr) { + RecordEvents(rawEvent, device); device->InjectInputEvent(event); } } diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index f75dcbf..498bc0f 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -211,6 +211,11 @@ uint16_t VirtualDevice::GetClasses() return classes_; } +std::string VirtualDevice::GetDeviceName() +{ + return deviceName_; +} + void VirtualDevice::RecordEventLog(const input_event &event) { std::string eventType = ""; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 48fd7a7..1ab15f7 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -328,6 +328,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI DHLOGI("StopRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); std::vector dhIdsVec = SplitDhIdString(dhids); ResetKeyboardKeyState(deviceId, dhIdsVec); + ResetTouchPadBtnMouseState(deviceId, dhIdsVec); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; @@ -775,6 +776,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi } DHLOGI("StopRemoteInput sessionId:%d.", sessionId); ResetKeyboardKeyState(deviceId, dhids); + ResetTouchPadBtnMouseState(deviceId, dhids); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index 5b217ff..5dfa229 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -16,7 +16,6 @@ #ifndef DISTRIBUTED_INPUT_STATE_BASE_H #define DISTRIBUTED_INPUT_STATE_BASE_H -#include #include #include #include @@ -65,16 +64,6 @@ public: void RefreshABSPosition(const std::string &dhId, int32_t absX, int32_t absY); std::pair GetAndClearABSPosition(const std::string &dhId); - - void SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event); - /** - * @brief check is one device in down state - * - * @param dhId the dhid - * @return true in down state - * @return false NOT in down state - */ - bool IsDhIdDown(const std::string &dhId); private: DInputState() = default; ~DInputState(); @@ -93,7 +82,6 @@ private: std::mutex absPosMtx_; // Record abs x/y of touchpad std::unordered_map> absPositionsMap_; - std::atomic lastSessionId_ {0}; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 9c29850..846b5e2 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -70,7 +70,6 @@ int32_t DInputState::RecordDhIds(const std::vector &dhIds, DhIdStat if (state == DhIdState::THROUGH_OUT) { SimulateEventInjectToSrc(sessionId, dhIds); } - lastSessionId_ = sessionId; return DH_SUCCESS; } @@ -168,46 +167,6 @@ void DInputState::SimulateBtnTouchEvent(const int32_t sessionId, const std::stri DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(sessionId, simEvents); } -void DInputState::SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event) -{ - DHLOGI("Sinmulate touch pad UP state to source, dhId: %s", dhId.c_str()); - int32_t simTrackingId = 0xffffffff; - std::vector simEvents; - RawEvent touchTrackingIdEv1 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; - simEvents.push_back(touchTrackingIdEv1); - - RawEvent btnToolFingerDownEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE, dhId, event.path }; - simEvents.push_back(btnToolFingerDownEv); - - RawEvent btnToolDoubleTapUpEv = { event.when, EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE, dhId, event.path }; - simEvents.push_back(btnToolDoubleTapUpEv); - - RawEvent mscEv1 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; - simEvents.push_back(mscEv1); - - RawEvent sycReportEv1 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; - simEvents.push_back(sycReportEv1); - - RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path }; - simEvents.push_back(btnMouseUpEv); - - RawEvent touchTrackingIdEv2 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; - simEvents.push_back(touchTrackingIdEv2); - - RawEvent btnTouchUpEv = { event.when, EV_KEY, BTN_TOUCH, KEY_UP_STATE, dhId, event.path }; - simEvents.push_back(btnTouchUpEv); - - RawEvent btnToolFingerUpEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE, dhId, event.path }; - simEvents.push_back(btnToolFingerDownEv); - - RawEvent mscEv2 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; - simEvents.push_back(mscEv2); - - RawEvent sycReportEv2 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; - simEvents.push_back(sycReportEv2); - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); -} - void DInputState::SimulateNormalEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) { DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, @@ -241,13 +200,6 @@ std::pair DInputState::GetAndClearABSPosition(const std::strin return absPos; } -bool DInputState::IsDhIdDown(const std::string &dhId) -{ - std::lock_guard mapLock(keyDownStateMapMtx_); - auto iter = keyDownStateMap_.find(dhId); - return iter != keyDownStateMap_.end(); -} - void DInputState::AddKeyDownState(struct RawEvent event) { std::lock_guard mapLock(keyDownStateMapMtx_); From 757bd932e264f6822204b13143937763ac6ec861 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 22:26:34 +0800 Subject: [PATCH 4/7] add Signed-off-by: hwzhangchuang --- .../include/distributed_input_node_manager.h | 2 +- .../src/distributed_input_node_manager.cpp | 58 +++++++++---------- .../distributed_input_source_transport.cpp | 4 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 9e3aec0..c37973c 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -115,7 +115,7 @@ private: void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); - void RecordEvents(const RawEvent &event, const VirtualDevice* device); + void RecordEvents(const RawEvent &event, VirtualDevice* device); bool IsTouchPad(const std::string &deviceName); void AddBtnMouseDownState(int32_t fd); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 34953f8..b664a1a 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -544,7 +544,7 @@ void DistributedInputNodeManager::ClearCachedState(int32_t fd) downTouchPadBtnMouseFds_.erase(fd); } -void DistributedInputNodeManager::RecordEvents(const RawEvent &event, const VirtualDevice* device) +void DistributedInputNodeManager::RecordEvents(const RawEvent &event, VirtualDevice* device) { bool isTouchEvent = false; if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && @@ -566,12 +566,12 @@ void DistributedInputNodeManager::RecordEvents(const RawEvent &event, const Virt // Deal btn mouse state if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_DOWN_STATE) { - AddBtnMouseDownState(event); + AddBtnMouseDownState(device->GetDeviceFd()); RecordChangeEventLog(event); } if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE) { - RemoveBtnMouseDownState(event); + RemoveBtnMouseDownState(device->GetDeviceFd()); RecordChangeEventLog(event); } } @@ -617,7 +617,7 @@ void DistributedInputNodeManager::ResetTouchPadBtnMouseState(const std::string & const std::vector &dhIds) { VirtualDevice* device = nullptr; - bool isTouchPad = false; + bool isTouchPadDevice = false; for (auto const &dhId : dhIds) { if (GetDevice(deviceId, dhId, device) < 0 || device == nullptr) { DHLOGE("could not find the device"); @@ -627,10 +627,10 @@ void DistributedInputNodeManager::ResetTouchPadBtnMouseState(const std::string & if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && IsTouchPad(device->GetDeviceName())) { - isTouchPad = true; + isTouchPadDevice = true; } - if (!isTouchPad) { + if (!isTouchPadDevice) { continue; } @@ -672,32 +672,32 @@ void DistributedInputNodeManager::SimulateTouchPadUpState(const std::string &dev DHLOGI("Sinmulate touch pad UP state events, deviceId: %s, dhId: %s, fd: %d, dx: %d, dy: %d", deviceId.c_str(), dhId.c_str(), fd, dx, dy); int32_t simTrackingId = 0xffffffff; - input_event touchTrackingIdEv1 = { EV_ABS, ABS_MT_TRACKING_ID, simTrackingId }; - input_event btnToolFingerDownEv = { EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE }; - input_event btnToolDoubleTapUpEv = { EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE }; - input_event mscEv1 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; - input_event sycReportEv1 = { EV_SYN, SYN_REPORT, 0x0 }; + input_event touchTrackingIdEv1 = { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = simTrackingId }; + input_event btnToolFingerDownEv = { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = KEY_DOWN_STATE }; + input_event btnToolDoubleTapUpEv = { .type = EV_KEY, .code = BTN_TOOL_DOUBLETAP, .value = KEY_UP_STATE }; + input_event mscEv1 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; + input_event sycReportEv1 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - input_event absMtPosX1 = { EV_ABS, ABS_MT_POSITION_X, dx }; - input_event absMtPosY1 = { EV_ABS, ABS_MT_POSITION_Y, dy }; - input_event absPosX1 = { EV_ABS, ABS_X, dx }; - input_event absPosY1 = { EV_ABS, ABS_Y, dy }; - input_event mscEv2 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; - input_event sycReportEv2 = { EV_SYN, SYN_REPORT, 0x0 }; + input_event absMtPosX1 = { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = dx }; + input_event absMtPosY1 = { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = dy }; + input_event absPosX1 = { .type = EV_ABS, .code = ABS_X, .value = dx }; + input_event absPosY1 = { .type = EV_ABS, .code = ABS_Y, .value = dy }; + input_event mscEv2 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; + input_event sycReportEv2 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - input_event absMtPosX2 = { EV_ABS, ABS_MT_POSITION_X, dx }; - input_event absMtPosY2 = { EV_ABS, ABS_MT_POSITION_Y, dy }; - input_event btnMouseUpEv = { EV_KEY, BTN_MOUSE, KEY_UP_STATE }; - input_event absPosX2 = { EV_ABS, ABS_X, dx }; - input_event absPosY2 = { EV_ABS, ABS_Y, dy }; - input_event mscEv3 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; - input_event sycReportEv3 = { EV_SYN, SYN_REPORT, 0x0 }; + input_event absMtPosX2 = { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = dx }; + input_event absMtPosY2 = { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = dy }; + input_event btnMouseUpEv = { .type = EV_KEY, .code = BTN_MOUSE, .value = KEY_UP_STATE }; + input_event absPosX2 = { .type = EV_ABS, .code = ABS_X, .value = dx }; + input_event absPosY2 = { .type = EV_ABS, .code = ABS_Y, .value = dy }; + input_event mscEv3 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; + input_event sycReportEv3 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - input_event touchTrackingIdEv2 = { EV_ABS, ABS_MT_TRACKING_ID, simTrackingId }; - input_event btnTouchUpEv = { EV_KEY, BTN_TOUCH, KEY_UP_STATE }; - input_event btnToolFingerUpEv = { EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE }; - input_event mscEv4 = { EV_MSC, MSC_TIMESTAMP, 0x0 }; - input_event sycReportEv4 = { EV_SYN, SYN_REPORT, 0x0 }; + input_event touchTrackingIdEv2 = { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = simTrackingId }; + input_event btnTouchUpEv = { .type = EV_KEY, .code = BTN_TOUCH, .value = KEY_UP_STATE }; + input_event btnToolFingerUpEv = { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = KEY_UP_STATE }; + input_event mscEv4 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; + input_event sycReportEv4 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; std::vector simEvents = { touchTrackingIdEv1, btnToolFingerDownEv, btnToolDoubleTapUpEv, mscEv1, sycReportEv1, diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 1ab15f7..3d62004 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -328,7 +328,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI DHLOGI("StopRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); std::vector dhIdsVec = SplitDhIdString(dhids); ResetKeyboardKeyState(deviceId, dhIdsVec); - ResetTouchPadBtnMouseState(deviceId, dhIdsVec); + DistributedInputInject::GetInstance().ResetTouchPadBtnMouseState(deviceId, dhIdsVec); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; @@ -776,7 +776,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi } DHLOGI("StopRemoteInput sessionId:%d.", sessionId); ResetKeyboardKeyState(deviceId, dhids); - ResetTouchPadBtnMouseState(deviceId, dhids); + DistributedInputInject::GetInstance().ResetTouchPadBtnMouseState(deviceId, dhids); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; From c572c95594f979b138bcb3c7eaa0efb2b676ce89 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 22:33:20 +0800 Subject: [PATCH 5/7] add Signed-off-by: hwzhangchuang --- utils/include/dinput_utils_tool.h | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 15ab0ad..8d0df4f 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -58,6 +58,7 @@ int OpenInputDeviceFdByPath(const std::string &devicePath); std::string ConvertErrNo(); void ScanInputDevicesPath(const std::string &dirName, std::vector &vecInputDevPath); +void WriteEventToDevice(const int fd, const input_event &event); /** * If we pressed the sink keyboard while mouse pass throuth from source to sink, we need reset the virtual keyboard * key states at the source side. From b997959660b373d60aacde6fe796372d65ab6a73 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Fri, 8 Dec 2023 22:55:38 +0800 Subject: [PATCH 6/7] add Signed-off-by: hwzhangchuang --- .../source/inputinject/include/distributed_input_node_manager.h | 2 +- .../source/inputinject/src/distributed_input_node_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index c37973c..a624c41 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -116,7 +116,7 @@ private: void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); void RecordEvents(const RawEvent &event, VirtualDevice* device); - bool IsTouchPad(const std::string &deviceName); + bool IsTouchPad(std::string deviceName); void AddBtnMouseDownState(int32_t fd); void RemoveBtnMouseDownState(int32_t fd); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index b664a1a..748bd73 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -513,7 +513,7 @@ void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); } -bool DistributedInputNodeManager::IsTouchPad(const std::string &deviceName) +bool DistributedInputNodeManager::IsTouchPad(std::string deviceName) { DHLOGD("device name is %s.", deviceName.c_str()); transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower); From 6347b3cc4ac90b924d65d7930957929de37f17e2 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 9 Dec 2023 12:40:59 +0800 Subject: [PATCH 7/7] add Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 13 ++ common/include/input_hub.h | 1 + .../src/distributed_input_sink_manager.cpp | 4 +- .../include/distributed_input_inject.h | 1 - .../include/distributed_input_node_manager.h | 20 -- .../inputinject/include/virtual_device.h | 1 - .../src/distributed_input_inject.cpp | 11 - .../src/distributed_input_node_manager.cpp | 197 ------------------ .../source/inputinject/src/virtual_device.cpp | 5 - .../distributed_input_source_transport.cpp | 2 - services/state/include/dinput_state.h | 11 + services/state/src/dinput_state.cpp | 51 +++++ utils/include/dinput_utils_tool.h | 1 - 13 files changed, 78 insertions(+), 240 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index afbbecb..aa8dc8a 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -201,6 +201,12 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) return event - buffer; } +bool InputHub::IsTouchPad(Device *device) +{ + return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) && + IsTouchPad(device->identifier); +} + bool InputHub::IsTouchPad(const InputDevice &inputDevice) { std::string dhName = inputDevice.name; @@ -254,6 +260,13 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { DInputState::GetInstance().RefreshABSPosition(event.descriptor, -1, event.value); } + + if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && + !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { + DHLOGI("Find touchpad UP state that not down effective at sink side, dhId: %s", + event.descriptor.c_str()); + DInputState::GetInstance().SimulateTouchPadUpState(event.descriptor, event); + } DHLOGD("RecordDeviceChangeStates end."); } } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 83ff337..9e6e64c 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -151,6 +151,7 @@ private: bool ContainsNonZeroByte(const uint8_t *array, uint32_t startIndex, uint32_t endIndex); int64_t ProcessEventTimestamp(const input_event &event); bool IsTouchPad(const InputDevice &inputDevice); + bool IsTouchPad(Device *device); /* * this macro is used to tell if "bit" is set in "array" diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index b4ade68..d600479 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -320,7 +320,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, sessionId); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", sessionId); @@ -387,7 +387,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1); + DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, toSinkSessionId); if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { DHLOGE("All dhid stop sharing, sessionId: %d is closed.", toSinkSessionId); diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index c03fd82..cb4951a 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -50,7 +50,6 @@ public: void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); void GetVirtualKeyboardPaths(const std::string &devId, const std::vector &dhIds, std::vector &virKeyboardPaths); - void ResetTouchPadBtnMouseState(const std::string &deviceId, const std::vector &dhIds); 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 a624c41..ace7b0e 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -68,7 +68,6 @@ public: int32_t GetVirtualTouchScreenFd(); void ProcessInjectEvent(const EventBatch &events); - void ResetTouchPadBtnMouseState(const std::string &deviceId, const std::vector &dhIds); /** * @brief Get the Virtual Keyboard Paths By Dh Ids object @@ -115,18 +114,6 @@ private: void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); - void RecordEvents(const RawEvent &event, VirtualDevice* device); - bool IsTouchPad(std::string deviceName); - - void AddBtnMouseDownState(int32_t fd); - void RemoveBtnMouseDownState(int32_t fd); - void RecordChangeEventLog(const RawEvent &event); - void RefreshABSPosition(int32_t fd, int32_t absX, int32_t absY); - void ClearCachedState(int32_t fd); - - void SimulateTouchPadUpState(const std::string &deviceId, const std::string &dhId, - int32_t fd, int32_t dx, int32_t dy); - /* the key is {networkId, dhId}, and the value is virtualDevice */ std::map> virtualDeviceMap_; std::mutex virtualDeviceMapMutex_; @@ -142,13 +129,6 @@ private: std::once_flag callOnceFlag_; std::shared_ptr callBackHandler_; sptr SessionStateCallback_; - - std::mutex absPosMtx_; - // Record abs x/y of touchpad, {fd, {dx, dy}} - std::unordered_map> absPositionsMap_; - - std::mutex downBtnMouseFdsMtx_; - std::set downTouchPadBtnMouseFds_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/include/virtual_device.h b/services/source/inputinject/include/virtual_device.h index e92b477..bcec29e 100644 --- a/services/source/inputinject/include/virtual_device.h +++ b/services/source/inputinject/include/virtual_device.h @@ -50,7 +50,6 @@ public: int32_t GetDeviceFd(); uint16_t GetDeviceType(); - std::string GetDeviceName(); private: int32_t fd_ = -1; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 719882b..8f53ecf 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -220,17 +220,6 @@ void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &devId, } inputNodeManager_->NotifyNodeMgrScanVirNode(devId, dhId); } - -void DistributedInputInject::ResetTouchPadBtnMouseState(const std::string &deviceId, - const std::vector &dhIds) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("ResetTouchPadBtnMouseState inputNodeManager is nullptr"); - return; - } - inputNodeManager_->ResetTouchPadBtnMouseState(deviceId, dhIds); -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 748bd73..a429a98 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -513,202 +513,6 @@ void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); } -bool DistributedInputNodeManager::IsTouchPad(std::string deviceName) -{ - DHLOGD("device name is %s.", deviceName.c_str()); - transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower); - if (deviceName.find(DH_TOUCH_PAD) == std::string::npos) { - return false; - } - return true; -} - -void DistributedInputNodeManager::AddBtnMouseDownState(int32_t fd) -{ - std::lock_guard mapLock(downBtnMouseFdsMtx_); - downTouchPadBtnMouseFds_.insert(fd); -} - -void DistributedInputNodeManager::RemoveBtnMouseDownState(int32_t fd) -{ - std::lock_guard mapLock(downBtnMouseFdsMtx_); - downTouchPadBtnMouseFds_.erase(fd); -} - -void DistributedInputNodeManager::ClearCachedState(int32_t fd) -{ - std::lock_guard lock(absPosMtx_); - absPositionsMap_.erase(fd); - - std::lock_guard mapLock(downBtnMouseFdsMtx_); - downTouchPadBtnMouseFds_.erase(fd); -} - -void DistributedInputNodeManager::RecordEvents(const RawEvent &event, VirtualDevice* device) -{ - bool isTouchEvent = false; - if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && - IsTouchPad(device->GetDeviceName())) { - isTouchEvent = true; - } - - if (!isTouchEvent) { - return; - } - - if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_X || event.code == ABS_X)) { - RefreshABSPosition(device->GetDeviceFd(), event.value, -1); - } - - if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { - RefreshABSPosition(device->GetDeviceFd(), -1, event.value); - } - - // Deal btn mouse state - if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_DOWN_STATE) { - AddBtnMouseDownState(device->GetDeviceFd()); - RecordChangeEventLog(event); - } - - if (event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE) { - RemoveBtnMouseDownState(device->GetDeviceFd()); - RecordChangeEventLog(event); - } -} - -void DistributedInputNodeManager::RecordChangeEventLog(const RawEvent &event) -{ - std::string eventType = ""; - switch (event.type) { - case EV_KEY: - eventType = "EV_KEY"; - break; - case EV_REL: - eventType = "EV_REL"; - break; - case EV_ABS: - eventType = "EV_ABS"; - break; - case EV_SYN: - eventType = "EV_SYN"; - break; - default: - eventType = "other type " + std::to_string(event.type); - break; - } - DHLOGI("6.E2E-Test Sink collect change event, EventType: %s, Code: %d, Value: %d, Path: %s, descriptor: %s," - "When:%" PRId64 "", eventType.c_str(), event.code, event.value, event.path.c_str(), - GetAnonyString(event.descriptor).c_str(), event.when); -} - -void DistributedInputNodeManager::RefreshABSPosition(int32_t fd, int32_t absX, int32_t absY) -{ - std::lock_guard lock(absPosMtx_); - if (absX != -1) { - absPositionsMap_[fd].first = absX; - } - - if (absY != -1) { - absPositionsMap_[fd].second = absY; - } -} - -void DistributedInputNodeManager::ResetTouchPadBtnMouseState(const std::string &deviceId, - const std::vector &dhIds) -{ - VirtualDevice* device = nullptr; - bool isTouchPadDevice = false; - for (auto const &dhId : dhIds) { - if (GetDevice(deviceId, dhId, device) < 0 || device == nullptr) { - DHLOGE("could not find the device"); - continue; - } - - if (((device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH_MT) || - (device->GetClasses() & INPUT_DEVICE_CLASS_TOUCH)) && - IsTouchPad(device->GetDeviceName())) { - isTouchPadDevice = true; - } - - if (!isTouchPadDevice) { - continue; - } - - int32_t fd = device->GetDeviceFd(); - - DHLOGI("Find the touchpad stopped, try reset it's state, deviceId: %s, dhId: %s, fd: %d", - deviceId.c_str(), dhId.c_str(), fd); - int32_t dx = -1; - int32_t dy = -1; - { - std::lock_guard lock(downBtnMouseFdsMtx_); - if (downTouchPadBtnMouseFds_.count(fd) == 0) { - continue; - } else { - downTouchPadBtnMouseFds_.erase(fd); - DHLOGI("Find this touchpad fd should reset, fd: %d", fd); - } - } - - { - std::lock_guard lock(absPosMtx_); - if (absPositionsMap_.count(fd) == 0) { - DHLOGE("Find touch pad need reset, but CAN NOT find dx,dy"); - dx = 0; - dy = 0; - } else { - dx = absPositionsMap_[fd].first; - dy = absPositionsMap_[fd].second; - absPositionsMap_.erase(fd); - } - } - SimulateTouchPadUpState(deviceId, dhId, fd, dx, dy); - } -} - -void DistributedInputNodeManager::SimulateTouchPadUpState(const std::string &deviceId, const std::string &dhId, - int32_t fd, int32_t dx, int32_t dy) -{ - DHLOGI("Sinmulate touch pad UP state events, deviceId: %s, dhId: %s, fd: %d, dx: %d, dy: %d", - deviceId.c_str(), dhId.c_str(), fd, dx, dy); - int32_t simTrackingId = 0xffffffff; - input_event touchTrackingIdEv1 = { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = simTrackingId }; - input_event btnToolFingerDownEv = { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = KEY_DOWN_STATE }; - input_event btnToolDoubleTapUpEv = { .type = EV_KEY, .code = BTN_TOOL_DOUBLETAP, .value = KEY_UP_STATE }; - input_event mscEv1 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; - input_event sycReportEv1 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - - input_event absMtPosX1 = { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = dx }; - input_event absMtPosY1 = { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = dy }; - input_event absPosX1 = { .type = EV_ABS, .code = ABS_X, .value = dx }; - input_event absPosY1 = { .type = EV_ABS, .code = ABS_Y, .value = dy }; - input_event mscEv2 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; - input_event sycReportEv2 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - - input_event absMtPosX2 = { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = dx }; - input_event absMtPosY2 = { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = dy }; - input_event btnMouseUpEv = { .type = EV_KEY, .code = BTN_MOUSE, .value = KEY_UP_STATE }; - input_event absPosX2 = { .type = EV_ABS, .code = ABS_X, .value = dx }; - input_event absPosY2 = { .type = EV_ABS, .code = ABS_Y, .value = dy }; - input_event mscEv3 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; - input_event sycReportEv3 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - - input_event touchTrackingIdEv2 = { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = simTrackingId }; - input_event btnTouchUpEv = { .type = EV_KEY, .code = BTN_TOUCH, .value = KEY_UP_STATE }; - input_event btnToolFingerUpEv = { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = KEY_UP_STATE }; - input_event mscEv4 = { .type = EV_MSC, .code = MSC_TIMESTAMP, .value = 0x0 }; - input_event sycReportEv4 = { .type = EV_SYN, .code = SYN_REPORT, .value = 0x0 }; - - std::vector simEvents = { - touchTrackingIdEv1, btnToolFingerDownEv, btnToolDoubleTapUpEv, mscEv1, sycReportEv1, - absMtPosX1, absMtPosY1, absPosX1, absPosY1, mscEv2, sycReportEv2, - absMtPosX2, absMtPosY2, btnMouseUpEv, absPosX2, absPosY2, mscEv3, sycReportEv3, - touchTrackingIdEv2, btnTouchUpEv, btnToolFingerUpEv, mscEv4, sycReportEv4 }; - for (auto &event : simEvents) { - WriteEventToDevice(fd, event); - } -} - void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) { std::string deviceId = events.first; @@ -728,7 +532,6 @@ void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) return; } if (device != nullptr) { - RecordEvents(rawEvent, device); device->InjectInputEvent(event); } } diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index 498bc0f..f75dcbf 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -211,11 +211,6 @@ uint16_t VirtualDevice::GetClasses() return classes_; } -std::string VirtualDevice::GetDeviceName() -{ - return deviceName_; -} - void VirtualDevice::RecordEventLog(const input_event &event) { std::string eventType = ""; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 3d62004..48fd7a7 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -328,7 +328,6 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI DHLOGI("StopRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); std::vector dhIdsVec = SplitDhIdString(dhids); ResetKeyboardKeyState(deviceId, dhIdsVec); - DistributedInputInject::GetInstance().ResetTouchPadBtnMouseState(deviceId, dhIdsVec); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; @@ -776,7 +775,6 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi } DHLOGI("StopRemoteInput sessionId:%d.", sessionId); ResetKeyboardKeyState(deviceId, dhids); - DistributedInputInject::GetInstance().ResetTouchPadBtnMouseState(deviceId, dhids); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index 5dfa229..d16a9f9 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -64,6 +64,16 @@ public: void RefreshABSPosition(const std::string &dhId, int32_t absX, int32_t absY); std::pair GetAndClearABSPosition(const std::string &dhId); + + void SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event); + /** + * @brief check is one device in down state + * + * @param dhId the dhid + * @return true in down state + * @return false NOT in down state + */ + bool IsDhIdDown(const std::string &dhId); private: DInputState() = default; ~DInputState(); @@ -82,6 +92,7 @@ private: std::mutex absPosMtx_; // Record abs x/y of touchpad std::unordered_map> absPositionsMap_; + std::atomic lastSessionId_ {0}; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 846b5e2..470c4f7 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -70,6 +70,7 @@ int32_t DInputState::RecordDhIds(const std::vector &dhIds, DhIdStat if (state == DhIdState::THROUGH_OUT) { SimulateEventInjectToSrc(sessionId, dhIds); } + lastSessionId_ = sessionId; return DH_SUCCESS; } @@ -167,6 +168,49 @@ void DInputState::SimulateBtnTouchEvent(const int32_t sessionId, const std::stri DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(sessionId, simEvents); } +void DInputState::SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event) +{ + std::pair touchPos = GetAndClearABSPosition(dhId); + int32_t dx = touchPos.first; + int32_t dy = touchPos.second; + DHLOGI("Sinmulate touch pad UP state to source, dhId: %s, dx: %d, dy: %d", dhId.c_str(), dx, dy); + int32_t simTrackingId = GetRandomInt32(); + RawEvent touchTrackingIdEv1 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + RawEvent btnToolFingerDownEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE, dhId, event.path }; + RawEvent btnToolDoubleTapUpEv = { event.when, EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE, dhId, event.path }; + RawEvent mscEv1 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + RawEvent sycReportEv1 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + RawEvent absMtSlot = { event.when, EV_ABS, ABS_MT_SLOT, 0x0, dhId, event.path }; + RawEvent absMtPosX1 = { event.when, EV_ABS, ABS_MT_POSITION_X, dx, dhId, event.path }; + RawEvent absMtPosY1 = { event.when, EV_ABS, ABS_MT_POSITION_Y, dy, dhId, event.path }; + RawEvent absPosX1 = { event.when, EV_ABS, ABS_X, dx, dhId, event.path }; + RawEvent absPosY1 = { event.when, EV_ABS, ABS_Y, dy, dhId, event.path }; + RawEvent mscEv2 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + RawEvent sycReportEv2 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + RawEvent absMtPosX2 = { event.when, EV_ABS, ABS_MT_POSITION_X, dx, dhId, event.path }; + RawEvent absMtPosY2 = { event.when, EV_ABS, ABS_MT_POSITION_Y, dy, dhId, event.path }; + RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path }; + RawEvent absPosX2 = { event.when, EV_ABS, ABS_X, dx, dhId, event.path }; + RawEvent absPosY2 = { event.when, EV_ABS, ABS_Y, dy, dhId, event.path }; + RawEvent mscEv3 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + RawEvent sycReportEv3 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + RawEvent touchTrackingIdEv2 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + RawEvent btnTouchUpEv = { event.when, EV_KEY, BTN_TOUCH, KEY_UP_STATE, dhId, event.path }; + RawEvent btnToolFingerUpEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE, dhId, event.path }; + RawEvent mscEv4 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + RawEvent sycReportEv4 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + std::vector simEvents = { + touchTrackingIdEv1, btnToolFingerDownEv, btnToolDoubleTapUpEv, mscEv1, sycReportEv1, + absMtSlot, absMtPosX1, absMtPosY1, absPosX1, absPosY1, mscEv2, sycReportEv2, + absMtPosX2, absMtPosY2, btnMouseUpEv, absPosX2, absPosY2, mscEv3, sycReportEv3, + touchTrackingIdEv2, btnTouchUpEv, btnToolFingerUpEv, mscEv4, sycReportEv4 }; + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); +} + void DInputState::SimulateNormalEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) { DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, @@ -200,6 +244,13 @@ std::pair DInputState::GetAndClearABSPosition(const std::strin return absPos; } +bool DInputState::IsDhIdDown(const std::string &dhId) +{ + std::lock_guard mapLock(keyDownStateMapMtx_); + auto iter = keyDownStateMap_.find(dhId); + return iter != keyDownStateMap_.end(); +} + void DInputState::AddKeyDownState(struct RawEvent event) { std::lock_guard mapLock(keyDownStateMapMtx_); diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 8d0df4f..15ab0ad 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -58,7 +58,6 @@ int OpenInputDeviceFdByPath(const std::string &devicePath); std::string ConvertErrNo(); void ScanInputDevicesPath(const std::string &dirName, std::vector &vecInputDevPath); -void WriteEventToDevice(const int fd, const input_event &event); /** * If we pressed the sink keyboard while mouse pass throuth from source to sink, we need reset the virtual keyboard * key states at the source side.