diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 8d545bd5127f62e51bd1c956823a610c957ab6f5..d4399137aa2e33ed6303959df602985d0a1cd74e 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -110,6 +110,7 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR = -65039; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SESSION_STATE_CB_IS_NULL = -65040; + constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INJECT_EVENT_CB_IS_NULL = -65041; // handler error code constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000; @@ -177,6 +178,9 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_CLIENT_UNREGISTER_SESSION_STATE_FAIL = -67058; constexpr int32_t ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL = -67059; constexpr int32_t ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL = -67060; + constexpr int32_t ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL = -67061; + constexpr int32_t ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL = -67062; + constexpr int32_t ERR_DH_INPUT_SINK_ENABLE_PERMISSION_CHECK_FAIL = -67063; // Hidump Helper error code constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index 300de42cfe4981d208c7c4eb4986351d393db5d3..819ca787c26c9d609c7853c006c9800505e42102 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -79,7 +79,7 @@ int32_t DistributedInputSinkStub::InitInner(MessageParcel &data, MessageParcel & { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SINK_ENABLE_PERMISSION_CHECK_FAIL; } DHLOGI("DistributedInputSinkStub InitInner start"); int32_t ret = Init(); @@ -94,7 +94,7 @@ int32_t DistributedInputSinkStub::ReleaseInner(MessageParcel &data, MessageParce { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SINK_ENABLE_PERMISSION_CHECK_FAIL; } int32_t ret = Release(); if (!reply.WriteInt32(ret)) { diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index ec8200d3f3cbe4530b0fad053fc8865be28fca8e..8afb6b8e5bc4fabc6934a31429c1d1f867cf8a6f 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -107,7 +107,7 @@ int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::unique_lock lock(operatorMutex_); if (sourceManagerInitFlag_.load()) { @@ -127,7 +127,7 @@ int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParc { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::unique_lock lock(operatorMutex_); if (!sourceManagerInitFlag_.load()) { @@ -147,7 +147,7 @@ int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessagePar { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::string devId = data.ReadString(); std::string dhId = data.ReadString(); @@ -169,7 +169,7 @@ int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageP { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::string devId = data.ReadString(); std::string dhId = data.ReadString(); @@ -190,7 +190,7 @@ int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); @@ -210,7 +210,7 @@ int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &da { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); @@ -230,7 +230,7 @@ int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); @@ -251,7 +251,7 @@ int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, M { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); @@ -272,7 +272,7 @@ int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParce { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -294,7 +294,7 @@ int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -316,7 +316,7 @@ int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -337,7 +337,7 @@ int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParce { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -358,7 +358,7 @@ int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &da { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string sinkId = data.ReadString(); @@ -395,7 +395,7 @@ int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &dat { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string sinkId = data.ReadString(); @@ -432,7 +432,7 @@ int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParce { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -470,7 +470,7 @@ int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); @@ -616,7 +616,7 @@ int32_t DistributedInputSourceStub::HandleRegisterSessionStateCb(MessageParcel & { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { @@ -636,7 +636,7 @@ int32_t DistributedInputSourceStub::HandleUnregisterSessionStateCb(MessageParcel { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_CLIENT_STOP_FAIL; + return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } int32_t ret = UnregisterSessionStateCb(); if (!reply.WriteInt32(ret)) { diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index bd93c557690e68bf8994cdf7648b50b73d0aec70..65b9757be916668c1896d19baf32354554ab4339 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -47,6 +47,8 @@ public: int32_t RegisterInputNodeListener(sptr listener); int32_t UnregisterInputNodeListener(sptr listener); 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); diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index db423e48d7d233073f074a458e804e14752b6b1b..ddae65dcb4676ce8c1823982f1e954733864fb66 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -29,12 +29,14 @@ #include "constants_dinput.h" #include "input_hub.h" +#include "i_session_state_callback.h" #include "virtual_device.h" namespace OHOS { 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_DHID = "dhId"; class DistributedInputNodeManager { public: @@ -64,6 +66,8 @@ public: void UpdateSpecEventFirstStatus(bool status); void UpdateSpecEventState(DhIdState state); void InjectInputEvent(const std::string &dhId, const struct input_event &event); + void RegisterInjectEventCb(sptr callback); + void UnregisterInjectEventCb(); class DInputNodeManagerEventHandler : public AppExecFwk::EventHandler { public: @@ -93,6 +97,7 @@ private: bool IsVirtualDev(int fd); bool GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath); void SetPathForDevMap(const std::string &dhId, 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_; @@ -110,6 +115,7 @@ private: std::shared_ptr callBackHandler_; std::atomic isFirst_; DhIdState specEventState_; + sptr SessionStateCallback_; }; } // 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 ea4a948c7b609760057b2b42291484df1416b11b..f09795d712852280b91bdb762cdbc02f96e75f3c 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -256,6 +256,22 @@ int32_t DistributedInputInject::GetVirtualTouchScreenFd() return inputNodeManager_->GetVirtualTouchScreenFd(); } +int32_t DistributedInputInject::RegisterInjectEventCb(sptr callback) +{ + if (callback == nullptr) { + DHLOGE("RegisterInjectEventCb callback is null."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INJECT_EVENT_CB_IS_NULL; + } + inputNodeManager_->RegisterInjectEventCb(callback); + return DH_SUCCESS; +} + +int32_t DistributedInputInject::UnregisterInjectEventCb() +{ + inputNodeManager_->UnregisterInjectEventCb(); + return DH_SUCCESS; +} + void DistributedInputInject::GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds) { diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index bdde0f5fd0ee3e37c9d8c8a8a7d81e2f91656df0..28889a477121d05b4c36906954f287d4e8921ddb 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -453,6 +453,7 @@ void DistributedInputNodeManager::InjectInputEvent(const std::string &dhId, cons VirtualDevice* device = nullptr; if (GetDevice(dhId, device) < 0) { DHLOGE("could not find the device"); + RunInjectEventCallback(dhId, DINPUT_INJECT_EVENT_FAIL); return; } if (device != nullptr) { @@ -460,6 +461,28 @@ void DistributedInputNodeManager::InjectInputEvent(const std::string &dhId, cons } } +void DistributedInputNodeManager::RegisterInjectEventCb(sptr callback) +{ + DHLOGI("RegisterInjectEventCb"); + SessionStateCallback_ = callback; +} + +void DistributedInputNodeManager::UnregisterInjectEventCb() +{ + DHLOGI("UnregisterInjectEventCb"); + SessionStateCallback_ = nullptr; +} + +void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent) +{ + DHLOGI("RunInjectEventCallback start."); + if (SessionStateCallback_ == nullptr) { + DHLOGE("RunSessionStateCallback SessionStateCallback_ is null."); + return; + } + SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); +} + void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptr &rawEvent) { std::string dhId = rawEvent->descriptor; diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index e1a865675a4938ba0df42db86784122f71136892..a8b2a5ec4546d2d3722920822f2d0163ca0d5f4a 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -1220,11 +1220,13 @@ int32_t DistributedInputSourceManager::RegisterSessionStateCb(sptrOnResult(remoteDevId, sessionState); return; } - DHLOGI("RunSessionStateCallback SessionStateCallback_ is null."); + DHLOGE("RunSessionStateCallback SessionStateCallback_ is null."); } int32_t DistributedInputTransportBase::CountSession(const std::string &remoteDevId)