From 5bacc96c55729cf2017f6ac51aee90b012b8b1c2 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 21 Sep 2023 11:25:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=95=BF=E6=8C=89=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E5=AF=B9=E7=AB=AF=E4=BA=8B=E4=BB=B6=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- common/include/constants_dinput.h | 12 ++++ .../include/distributed_input_inject.h | 2 + .../include/distributed_input_node_manager.h | 5 ++ .../src/distributed_input_inject.cpp | 20 +++++++ .../src/distributed_input_node_manager.cpp | 60 ++++++++++++++++--- .../distributed_input_source_manager.h | 1 + .../src/distributed_input_source_manager.cpp | 7 +++ services/state/include/dinput_state.h | 11 +--- services/state/src/dinput_state.cpp | 8 ++- 9 files changed, 107 insertions(+), 19 deletions(-) diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index d4deb46..7c401a6 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -39,6 +39,8 @@ namespace DistributedInput { const char INPUT_STRING_SPLIT_POINT = '.'; const uint32_t KEY_DOWN_STATE = 1; const uint32_t KEY_UP_STATE = 0; + const uint32_t KEY_LONGPRESS_STATE = 2; + const uint32_t KEY_OTHER_TYPE = 5; const uint32_t READ_SLEEP_TIME_MS = 50; const uint32_t READ_RETRY_MAX = 5; const uint32_t DH_ID_LENGTH_MAX = 256; @@ -320,6 +322,16 @@ namespace DistributedInput { OPENED = 0x02, CLOSING = 0x03, }; + + /* + * This enumeration class represents the two states of the peropheral: + * THROUGH_IN : The state indicates the peripheral takes effect on the local device. + * THROUGH_OUT : The state indicates that the peripheral takes effect at the remote device. + */ + enum class DhidState { + THROUGH_IN = 0, + THROUGH_OUT, + }; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 397e348..e7cc455 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -55,6 +55,8 @@ public: const std::string &sinkNodeDesc); void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &shareDhidsPaths, std::vector &shareDhIds); + void UpdateSpecEventFirstStatus(bool status); + void UpdateSpecEventState(DhidState state); 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 86c38ad..01bd2d0 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -61,6 +61,9 @@ public: void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &shareDhidsPaths, std::vector &shareDhIds); void NotifyNodeMgrScanVirNode(const std::string &dhId); + void UpdateSpecEventFirstStatus(bool status); + void UpdateSpecEventState(DhidState state); + void InjectInputEvent(const std::string &dhId, const struct input_event &event); class DInputNodeManagerEventHandler : public AppExecFwk::EventHandler { public: @@ -105,6 +108,8 @@ private: int32_t virtualTouchScreenFd_; std::once_flag callOnceFlag_; std::shared_ptr callBackHandler_; + std::atomic isFirst_; + DhidState specEventState_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 9db0504..51df1cf 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -276,6 +276,26 @@ void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &dhId) } inputNodeManager_->NotifyNodeMgrScanVirNode(dhId); } + +void DistributedInputInject::UpdateSpecEventFirstStatus(bool status) +{ + std::lock_guard lock(inputNodeManagerMutex_); + if (inputNodeManager_ == nullptr) { + DHLOGE("inputNodeManager is nullptr"); + return; + } + inputNodeManager_->UpdateSpecEventFirstStatus(status); +} + +void DistributedInputInject::UpdateSpecEventState(DhidState state) +{ + std::lock_guard lock(inputNodeManagerMutex_); + if (inputNodeManager_ == nullptr) { + DHLOGE("inputNodeManager is nullptr"); + return; + } + inputNodeManager_->UpdateSpecEventState(state); +} } // 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 710f870..f3ea292 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -32,7 +32,8 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { DistributedInputNodeManager::DistributedInputNodeManager() : isInjectThreadCreated_(false), - isInjectThreadRunning_(false), inputHub_(std::make_unique()), virtualTouchScreenFd_(UN_INIT_FD_VALUE) + isInjectThreadRunning_(false), inputHub_(std::make_unique()), virtualTouchScreenFd_(UN_INIT_FD_VALUE), + isFirst_(false), specEventState_(DhidState::THROUGH_OUT) { DHLOGI("DistributedInputNodeManager ctor"); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); @@ -179,6 +180,18 @@ void DistributedInputNodeManager::DInputNodeManagerEventHandler::ScanAllNode( nodeManagerObj_->ScanSinkInputDevices(devicedhId); } +void DistributedInputNodeManager::UpdateSpecEventFirstStatus(bool status) +{ + DHLOGI("UpdateSpecEventFirstStatus enter, status is %d", status); + isFirst_.store(status); +} + +void DistributedInputNodeManager::UpdateSpecEventState(DhidState state) +{ + DHLOGI("UpdateSpecEventState enter."); + specEventState_ = state; +} + void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &dhId) { DHLOGI("NotifyNodeMgrScanVirNode enter."); @@ -435,6 +448,18 @@ void DistributedInputNodeManager::InjectEvent() DHLOGI("end"); } +void InjectInputEvent(const std::string &dhId, const struct input_event &event) +{ + 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 std::shared_ptr &rawEvent) { std::string dhId = rawEvent->descriptor; @@ -445,14 +470,33 @@ void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptrwhen); - VirtualDevice* device = nullptr; - if (GetDevice(dhId, device) < 0) { - DHLOGE("could not find the device"); - return; - } - if (device != nullptr) { - device->InjectInputEvent(event); + if (event.type == EV_KEY) { + if (event.value == KEY_UP_STATE) { + UpdateSpecEventFirstStatus(false); + } + + if (event.value == KEY_LONGPRESS_STATE && !isFirst_.load() && specEventState_ == DhidState::THROUGH_IN) { + struct input_event inputEvent = { + .type = event.type, + .code = event.code, + .value = KEY_DOWN_STATE + }; + DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", + GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); + InjectInputEvent(dhId, inputEvent); + + inputEvent = { + .type = KEY_OTHER_TYPE, + .code = 0, + .value = 0 + }; + DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", + GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); + InjectInputEvent(dhId, inputEvent); + UpdateSpecEventFirstStatus(true); + } } + InjectInputEvent(dhId, event); } int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index 6e783d0..dfad600 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -283,6 +283,7 @@ public: uint32_t GetInputTypesMap(const std::string deviceId); uint32_t GetAllInputTypesMap(); void ClearResourcesStatus(); + void UpdateSpecEventStatus(); public: void RunRelayPrepareCallback(const std::string &srcId, const std::string &sinkId, const 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 aaf0344..4f7c99a 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -79,6 +79,7 @@ void DistributedInputSourceManager::DInputSrcMgrListener::ResetSrcMgrResStatus() return; } sourceManagerObj_->ClearResourcesStatus(); + sourceManagerObj_->UpdateSpecEventStatus(); } void DistributedInputSourceManager::OnStart() @@ -1709,6 +1710,12 @@ void DistributedInputSourceManager::ClearResourcesStatus() relayUnpreCallbacks_.clear(); } +void DistributedInputSourceManager::UpdateSpecEventStatus() +{ + DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); + DistributedInputInject::GetInstance().UpdateSpecEventState(DhidState::THROUGH_OUT); +} + void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, uint32_t value) { if (value == static_cast(DInputDeviceType::NONE)) { diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index 8dd9b49..0b8f3c0 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -20,20 +20,11 @@ #include #include #include +#include "constants_dinput.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -/* - * This enumeration class represents the two states of the peropheral: - * THROUGH_IN : The state indicates the peripheral takes effect on the local device. - * THROUGH_OUT : The state indicates that the peripheral takes effect at the remote device. -*/ -enum class DhidState { - THROUGH_IN = 0, - THROUGH_OUT, -}; - class DInputState { public: static DInputState &GetInstance() diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 7dc5290..bd86304 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -63,6 +63,13 @@ int32_t DInputState::RecordDhids(const std::vector &dhids, DhidStat if (state == DhidState::THROUGH_OUT) { CreateSpecialEventInjectThread(sessionId, dhids); + DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); + DistributedInputInject::GetInstance().UpdateSpecEventState(state); + } + + if (state == DhidState::THROUGH_IN) { + DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); + DistributedInputInject::GetInstance().UpdateSpecEventState(state); } return DH_SUCCESS; } @@ -141,7 +148,6 @@ void DInputState::SpecEventInject(const int32_t &sessionId, std::vector keyboardNodePaths; std::vector keyboardNodeDhIds; - DistributedInputCollector::GetInstance().GetShareKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); size_t len = keyboardNodePaths.size(); for (size_t i = 0; i < len; ++i) { -- Gitee From 58709291eb45bc5663063e60b9ec8591ec226311 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Fri, 22 Sep 2023 10:10:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=95=BF=E6=8C=89=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E5=AF=B9=E7=AB=AF=E4=BA=8B=E4=BB=B6=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../source/inputinject/src/distributed_input_node_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index f3ea292..51b1e63 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -448,7 +448,7 @@ void DistributedInputNodeManager::InjectEvent() DHLOGI("end"); } -void InjectInputEvent(const std::string &dhId, const struct input_event &event) +void DistributedInputNodeManager::InjectInputEvent(const std::string &dhId, const struct input_event &event) { VirtualDevice* device = nullptr; if (GetDevice(dhId, device) < 0) { -- Gitee From 6249dcdfff918856c16b4b3556eceaef114fd1e4 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Mon, 25 Sep 2023 11:28:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=95=BF=E6=8C=89=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E5=AF=B9=E7=AB=AF=E4=BA=8B=E4=BB=B6=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- services/state/src/dinput_state.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 95740cd..6c19bca 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -64,14 +64,11 @@ int32_t DInputState::RecordDhIds(const std::vector &dhIds, DhIdStat if (state == DhIdState::THROUGH_OUT) { CreateSpecialEventInjectThread(sessionId, dhIds); - DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); - DistributedInputInject::GetInstance().UpdateSpecEventState(state); } - if (state == DhIdState::THROUGH_IN) { - DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); - DistributedInputInject::GetInstance().UpdateSpecEventState(state); - } + DistributedInputInject::GetInstance().UpdateSpecEventFirstStatus(false); + DistributedInputInject::GetInstance().UpdateSpecEventState(state); + return DH_SUCCESS; } -- Gitee