diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index c02dc2823c182babe5ba990e36c51e9a532f8616..8d545bd5127f62e51bd1c956823a610c957ab6f5 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -109,7 +109,7 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037; 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_SRC_MGR_SESSION_STATE_CB_IS_NULL = -65040; + constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SESSION_STATE_CB_IS_NULL = -65040; // handler error code constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000; diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index fc08cb902ce7791ec70d852ff4ad1f3e3e2969d8..6ead0d0b554a1da734375723928ee19a565a14c7 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -569,7 +569,7 @@ int32_t DistributedInputSourceStub::OnRemoteRequest( } else { auto iter = memberFuncMap_.find(code); if (iter != memberFuncMap_.end()) { - DistributedInputSourceFunc &func = iter->second; + const DistributedInputSourceFunc &func = iter->second; return (this->*func)(data, reply); } } diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index 121b29e7645d0322747aab70d72af6ddcc2021e7..fc10ad8fd48e04c8d7375172182a0d749ace28c2 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -251,7 +251,6 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSessio return DH_SUCCESS; } - int32_t UnregisterSessionStateCb(); void DInputSourceCallBackTest::TestDInputSourceCallBackStub::OnResult(const std::string &deviceId, const std::string &strJson) { diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index 457afcb467e076e5d7600dfd68ffaf33ba753925..fc1defbae331c5d63bb6f1f0f560aba8eaec20ea 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -77,6 +77,8 @@ ohos_shared_library("libdinput_source") { "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", + "src/dinput_source_listener.cpp", + "src/dinput_source_manager_event_handler.cpp", "src/distributed_input_source_event_handler.cpp", "src/distributed_input_source_manager.cpp", "src/distributed_input_source_sa_cli_mgr.cpp", diff --git a/services/source/sourcemanager/include/dinput_source_listener.h b/services/source/sourcemanager/include/dinput_source_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..386da3ae4b2f4c02f6a89d60b4773d376c890487 --- /dev/null +++ b/services/source/sourcemanager/include/dinput_source_listener.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DINPUT_SOURCE_LISTENER_H +#define DINPUT_SOURCE_LISTENER_H + +#include +#include +#include + +#include +#include + +#include "event_handler.h" +#include "ipublisher_listener.h" +#include "publisher_listener_stub.h" +#include "singleton.h" + +#include "constants_dinput.h" +#include "dinput_context.h" +#include "dinput_source_manager_callback.h" +#include "dinput_source_trans_callback.h" +#include "distributed_input_source_manager.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DistributedInputSourceManager; +class DInputSourceListener : public DInputSourceTransCallback { +public: + explicit DInputSourceListener(DistributedInputSourceManager *manager); + virtual ~DInputSourceListener(); + void OnResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId, + bool result) override; + void OnResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) override; + void OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) override; + void OnResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override; + void OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override; + void OnResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override; + void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override; + void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type, + const uint32_t code, const uint32_t value) override; + void OnReceivedEventRemoteInput(const std::string deviceId, const std::string &event) override; + void OnResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result, + const std::string &object) override; + void OnResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) override; + + void OnReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) override; + void OnReceiveRelayUnprepareResult(int32_t status, const std::string &srcId, + const std::string &sinkId) override; + void OnReceiveRelayStartDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId, + const std::string &dhids) override; + void OnReceiveRelayStopDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId, + const std::string &dhids) override; + void OnReceiveRelayStartTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, + uint32_t inputTypes) override; + void OnReceiveRelayStopTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, + uint32_t inputTypes) override; + void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string &path); + +private: + DistributedInputSourceManager *sourceManagerObj_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // DINPUT_SOURCE_LISTENER_H \ No newline at end of file diff --git a/services/source/sourcemanager/include/dinput_source_manager_event_handler.h b/services/source/sourcemanager/include/dinput_source_manager_event_handler.h new file mode 100644 index 0000000000000000000000000000000000000000..d7ed0c06f0f1972ed29125d0d258657abb6a9ce3 --- /dev/null +++ b/services/source/sourcemanager/include/dinput_source_manager_event_handler.h @@ -0,0 +1,78 @@ + +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H +#define DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H + +#include +#include +#include + +#include +#include + +#include "event_handler.h" +#include "ipublisher_listener.h" +#include "publisher_listener_stub.h" +#include "singleton.h" + +#include "constants_dinput.h" +#include "dinput_context.h" +#include "dinput_source_manager_callback.h" +#include "dinput_source_trans_callback.h" +#include "distributed_input_source_manager.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DistributedInputSourceManager; +class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler { +public: + DInputSourceManagerEventHandler(const std::shared_ptr &runner, + DistributedInputSourceManager *manager); + ~DInputSourceManagerEventHandler() override; + + void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; +private: + void NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event); + + using SourceEventFunc = void (DInputSourceManagerEventHandler::*)( + const AppExecFwk::InnerEvent::Pointer &event); + std::map eventFuncMap_; + DistributedInputSourceManager *sourceManagerObj_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H \ No newline at end of file diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index b7913377e94228db79f5c9cdd57e75781bf60f7a..6e783d05d98323fd3a2743d646d94c8693a7b578 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -39,10 +39,14 @@ #include "distributed_input_source_sa_cli_mgr.h" #include "distributed_input_source_stub.h" #include "dinput_state.h" +#include "dinput_source_listener.h" +#include "dinput_source_manager_event_handler.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +class DInputSourceListener; +class DInputSourceManagerEventHandler; using EventRunner = OHOS::AppExecFwk::EventRunner; using EventHandler = OHOS::AppExecFwk::EventHandler; enum class ServiceSourceRunningState { STATE_NOT_START, STATE_RUNNING }; @@ -189,42 +193,6 @@ public: sptr callback); int32_t Dump(int32_t fd, const std::vector &args) override; - class DInputSourceListener : public DInputSourceTransCallback { - public: - explicit DInputSourceListener(DistributedInputSourceManager *manager); - virtual ~DInputSourceListener(); - void OnResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId, - bool result) override; - void OnResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) override; - void OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) override; - void OnResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override; - void OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override; - void OnResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override; - void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override; - void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type, - const uint32_t code, const uint32_t value) override; - void OnReceivedEventRemoteInput(const std::string deviceId, const std::string &event) override; - void OnResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result, - const std::string &object) override; - void OnResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) override; - - void OnReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) override; - void OnReceiveRelayUnprepareResult(int32_t status, const std::string &srcId, - const std::string &sinkId) override; - void OnReceiveRelayStartDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId, - const std::string &dhids) override; - void OnReceiveRelayStopDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId, - const std::string &dhids) override; - void OnReceiveRelayStartTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, - uint32_t inputTypes) override; - void OnReceiveRelayStopTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, - uint32_t inputTypes) override; - void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string &path); - - private: - DistributedInputSourceManager *sourceManagerObj_; - }; - class DInputSrcMgrListener : public DInputSourceManagerCallback { public: explicit DInputSrcMgrListener(DistributedInputSourceManager *manager); @@ -234,43 +202,10 @@ public: DistributedInputSourceManager *sourceManagerObj_; }; - class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler { - public: - DInputSourceManagerEventHandler(const std::shared_ptr &runner, - DistributedInputSourceManager *manager); - ~DInputSourceManagerEventHandler() override; - - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; - private: - void NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event); - void NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event); - - using SourceEventFunc = void (DInputSourceManagerEventHandler::*)( - const AppExecFwk::InnerEvent::Pointer &event); - std::map eventFuncMap_; - DistributedInputSourceManager *sourceManagerObj_; - }; - class StartDScreenListener : public PublisherListenerStub { public: - StartDScreenListener(); - ~StartDScreenListener() override; + StartDScreenListener() = default; + ~StartDScreenListener() = default; void OnMessage(const DHTopic topic, const std::string &message) override; private: @@ -280,8 +215,8 @@ public: class StopDScreenListener : public PublisherListenerStub { public: - StopDScreenListener(); - ~StopDScreenListener() override; + StopDScreenListener() = default; + ~StopDScreenListener() = default; void OnMessage(const DHTopic topic, const std::string &message) override; private: @@ -291,7 +226,7 @@ public: class DeviceOfflineListener : public PublisherListenerStub { public: explicit DeviceOfflineListener(DistributedInputSourceManager *srcManagerContext); - ~DeviceOfflineListener() override; + ~DeviceOfflineListener() = default; void OnMessage(const DHTopic topic, const std::string &message) override; @@ -305,7 +240,7 @@ public: class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient { public: DScreenSourceSvrRecipient(const std::string &srcDevId, const std::string &sinkDevId, const uint64_t srcWinId); - ~DScreenSourceSvrRecipient() override; + ~DScreenSourceSvrRecipient() = default; void OnRemoteDied(const wptr &remote) override; private: @@ -349,6 +284,18 @@ public: uint32_t GetAllInputTypesMap(); void ClearResourcesStatus(); +public: + void RunRelayPrepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t status); + void RunRelayUnprepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t status); + void RunRelayStartDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, + const std::string &dhids); + void RunRelayStopDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, + const std::string &dhids); + void RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, + uint32_t inputTypes); + void RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status, + uint32_t inputTypes); + private: struct DInputClientRegistInfo { std::string devId; @@ -441,7 +388,7 @@ private: ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; - std::shared_ptr statuslistener_; + std::shared_ptr statuslistener_; std::shared_ptr srcMgrListener_; std::vector regCallbacks_; @@ -483,17 +430,6 @@ private: std::mutex syncNodeInfoMutex_; std::map> syncNodeInfoMap_; - void RunRelayPrepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status); - void RunRelayUnprepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status); - void RunRelayStartDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status, - const std::string &dhids); - void RunRelayStopDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status, - const std::string &dhids); - void RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status, - uint32_t inputTypes); - void RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status, - uint32_t inputTypes); - int32_t RelayStartRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, sptr callback); int32_t RelayStopRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, diff --git a/services/source/sourcemanager/src/dinput_source_listener.cpp b/services/source/sourcemanager/src/dinput_source_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..29b87dde0937a4e16a3db310b96ceb5eac4b8f5e --- /dev/null +++ b/services/source/sourcemanager/src/dinput_source_listener.cpp @@ -0,0 +1,540 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dinput_source_listener.h" + +#include +#include +#include + +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "string_ex.h" + +#include "ipublisher_listener.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" +#include "dinput_log.h" +#include "dinput_utils_tool.h" +#include "dinput_softbus_define.h" +#include "distributed_input_inject.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +DInputSourceListener::DInputSourceListener(DistributedInputSourceManager *manager) +{ + sourceManagerObj_ = manager; + DHLOGI("DInputSourceListener init."); +} + +DInputSourceListener::~DInputSourceListener() +{ + sourceManagerObj_ = nullptr; + DHLOGI("DInputSourceListener destory."); +} + +void DInputSourceListener::OnResponseRegisterDistributedHardware( + const std::string deviceId, const std::string dhId, bool result) +{ + DHLOGI("OnResponseRegisterDistributedHardware called, deviceId: %s, " + "result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponseRegisterDistributedHardware sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + sourceManagerObj_->RunRegisterCallback(deviceId, dhId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + DHLOGE("OnResponseRegisterDistributedHardware GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_RIGISTER_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponsePrepareRemoteInput(const std::string deviceId, + bool result, const std::string &object) +{ + DHLOGI("OnResponsePrepareRemoteInput called, deviceId: %s, result: %s.", + GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponsePrepareRemoteInput sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + sourceManagerObj_->RunPrepareCallback(deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object); + DHLOGE("OnResponsePrepareRemoteInput GetCallbackEventHandler is null."); + return; + } + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_PREPARE_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) +{ + DHLOGI("OnResponseUnprepareRemoteInput called, deviceId: %s, " + "result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponseUnprepareRemoteInput sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + sourceManagerObj_->RunUnprepareCallback(deviceId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + DHLOGE("OnResponseUnprepareRemoteInput GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_UNPREPARE_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseRelayPrepareRemoteInput(int32_t toSrcSessionId, + const std::string &deviceId, bool result, const std::string &object) +{ + DHLOGI("OnResponseRelayPrepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object; + tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseRelayUnprepareRemoteInput(int32_t toSrcSessionId, + const std::string &deviceId, bool result) +{ + DHLOGI("OnResponseRelayUnprepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseStartRemoteInput( + const std::string deviceId, const uint32_t inputTypes, bool result) +{ + DHLOGI("OnResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.", + GetAnonyString(deviceId).c_str(), inputTypes, result ? "success" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + sourceManagerObj_->RunStartCallback(deviceId, inputTypes, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + DHLOGE("GetCallbackEventHandler is null."); + return; + } + if (result) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_START_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) +{ + DHLOGI("OnResponseStopRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.", + GetAnonyString(deviceId).c_str(), inputTypes, result ? "true" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponseStopRemoteInput sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("OnResponseStopRemoteInput GetCallbackEventHandler is null."); + sourceManagerObj_->RunStopCallback(deviceId, inputTypes, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( + DINPUT_SOURCE_MANAGER_STOP_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseStartRemoteInputDhid( + const std::string deviceId, const std::string &dhids, bool result) +{ + DHLOGI("OnResponseStartRemoteInputDhid called, deviceId: %s, result: %s.", + GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponseStartRemoteInputDhid sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("OnResponseStartRemoteInputDhid GetCallbackEventHandler is null."); + sourceManagerObj_->RunStartDhidCallback(deviceId, dhids, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + return; + } + if (result) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); + } + + std::vector vecStr; + StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, vecStr); + DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_IN, -1); + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_START_DHID_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseStopRemoteInputDhid( + const std::string deviceId, const std::string &dhids, bool result) +{ + DHLOGI("OnResponseStopRemoteInputDhid called, deviceId: %s, result: %s.", + GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("OnResponseStopRemoteInputDhid sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("OnResponseStopRemoteInputDhid GetCallbackEventHandler is null."); + sourceManagerObj_->RunStopDhidCallback(deviceId, dhids, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_STOP_DHID_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnResponseKeyState(const std::string deviceId, + const std::string &dhid, const uint32_t type, const uint32_t code, const uint32_t value) +{ + DHLOGI("OnResponseKeyState called, deviceId: %s, dhid: %s.", GetAnonyString(deviceId).c_str(), + GetAnonyString(dhid).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, type, code, value); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhid; + tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = type; + tmpJson[INPUT_SOURCEMANAGER_KEY_CODE] = code; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = value; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_KEY_STATE_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceivedEventRemoteInput( + const std::string deviceId, const std::string &event) +{ + nlohmann::json inputData = nlohmann::json::parse(event, nullptr, false); + if (inputData.is_discarded()) { + DHLOGE("inputData parse failed!"); + return; + } + size_t jsonSize = inputData.size(); + DHLOGI("OnReceivedEventRemoteInput called, deviceId: %s, json size:%d.", + GetAnonyString(deviceId).c_str(), jsonSize); + + if (!inputData.is_array()) { + DHLOGE("inputData not vector!"); + return; + } + + RawEvent mEventBuffer[jsonSize]; + int idx = 0; + for (auto it = inputData.begin(); it != inputData.end(); ++it) { + nlohmann::json oneData = (*it); + if (!IsInt64(oneData, INPUT_KEY_WHEN) || !IsUInt32(oneData, INPUT_KEY_TYPE) || + !IsUInt32(oneData, INPUT_KEY_CODE) || !IsInt32(oneData, INPUT_KEY_VALUE) || + !IsString(oneData, INPUT_KEY_DESCRIPTOR) || !IsString(oneData, INPUT_KEY_PATH)) { + DHLOGE("The key is invaild."); + continue; + } + mEventBuffer[idx].when = oneData[INPUT_KEY_WHEN]; + mEventBuffer[idx].type = oneData[INPUT_KEY_TYPE]; + mEventBuffer[idx].code = oneData[INPUT_KEY_CODE]; + mEventBuffer[idx].value = oneData[INPUT_KEY_VALUE]; + mEventBuffer[idx].descriptor = oneData[INPUT_KEY_DESCRIPTOR]; + mEventBuffer[idx].path = oneData[INPUT_KEY_PATH]; + RecordEventLog(oneData[INPUT_KEY_WHEN], oneData[INPUT_KEY_TYPE], oneData[INPUT_KEY_CODE], + oneData[INPUT_KEY_VALUE], oneData[INPUT_KEY_PATH]); + ++idx; + } + DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize); +} + +void DInputSourceListener::OnReceiveRelayPrepareResult(int32_t status, + const std::string &srcId, const std::string &sinkId) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceiveRelayUnprepareResult(int32_t status, + const std::string &srcId, const std::string &sinkId) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceiveRelayStartDhidResult(int32_t status, + const std::string &srcId, const std::string &sinkId, const std::string &dhids) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceiveRelayStopDhidResult(int32_t status, + const std::string &srcId, const std::string &sinkId, const std::string &dhids) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceiveRelayStartTypeResult(int32_t status, + const std::string &srcId, const std::string &sinkId, uint32_t inputTypes) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::OnReceiveRelayStopTypeResult(int32_t status, + const std::string &srcId, const std::string &sinkId, uint32_t inputTypes) +{ + DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("sourceManagerObj is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("GetCallbackEventHandler is null."); + return; + } + + auto jsonArrayMsg = std::make_shared(); + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; + tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; + tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DInputSourceListener::RecordEventLog(int64_t when, int32_t type, int32_t code, + int32_t value, const std::string &path) +{ + std::string eventType = ""; + switch (type) { + case EV_KEY: + eventType = "EV_KEY"; + break; + case EV_REL: + eventType = "EV_REL"; + break; + case EV_ABS: + eventType = "EV_ABS"; + break; + default: + eventType = "other type"; + break; + } + DHLOGD("3.E2E-Test Source softBus receive event, EventType: %s, Code: %d, Value: %d, Path: %s, When: %" PRId64 "", + eventType.c_str(), code, value, path.c_str(), when); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp b/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f84018f3ed1a4e2a9fe5911749c552d0d9bafe1 --- /dev/null +++ b/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp @@ -0,0 +1,493 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dinput_source_manager_event_handler.h" + +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "string_ex.h" + +#include "distributed_hardware_fwk_kit.h" +#include "ipublisher_listener.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" +#include "dinput_log.h" +#include "dinput_utils_tool.h" +#include "dinput_softbus_define.h" +#include "distributed_input_source_transport.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +DInputSourceManagerEventHandler::DInputSourceManagerEventHandler( + const std::shared_ptr &runner, DistributedInputSourceManager *manager) + : AppExecFwk::EventHandler(runner) +{ + eventFuncMap_[DINPUT_SOURCE_MANAGER_RIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyRegisterCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyUnregisterCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_PREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyPrepareCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_UNPREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyUnprepareCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_START_MSG] = &DInputSourceManagerEventHandler::NotifyStartCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_MSG] = &DInputSourceManagerEventHandler::NotifyStopCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_START_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStartDhidCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStopDhidCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_KEY_STATE_MSG] = &DInputSourceManagerEventHandler::NotifyKeyStateCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_STARTSERVER_MSG] = &DInputSourceManagerEventHandler::NotifyStartServerCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN] = + &DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN] = + &DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayPrepareCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback; + eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI] = + &DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback; + + sourceManagerObj_ = manager; +} + +DInputSourceManagerEventHandler::~DInputSourceManagerEventHandler() +{ + eventFuncMap_.clear(); + sourceManagerObj_ = nullptr; +} + +void DInputSourceManagerEventHandler::NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_HWID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + DistributedInputSourceManager::InputDeviceId inputDeviceId {deviceId, dhId}; + std::vector tmpInputDevId = sourceManagerObj_->GetInputDeviceId(); + // Find out if the dh exists + auto devIt = std::find(tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId); + if (devIt != tmpInputDevId.end()) { + if (result == false) { + sourceManagerObj_->RemoveInputDeviceId(deviceId, dhId); + } + } else { + DHLOGW("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG the " + "devId: %s, dhId: %s is bad data.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); + } + + sourceManagerObj_->RunRegisterCallback(deviceId, dhId, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_HWID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + if (result) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); + } + sourceManagerObj_->RunUnregisterCallback(deviceId, dhId, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_WHITELIST)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST]; + + sourceManagerObj_->RunPrepareCallback(deviceId, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object); +} + +void DInputSourceManagerEventHandler::NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + if (result) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); + } + sourceManagerObj_->RunUnprepareCallback(deviceId, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_ITP) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + DHLOGI("Start DInput Recv Callback ret: %s, devId: %s, inputTypes: %d", + result ? "true" : "false", GetAnonyString(deviceId).c_str(), inputTypes); + if (result) { + sourceManagerObj_->SetInputTypesMap( + deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) | inputTypes); + } + sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ? + DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); + sourceManagerObj_->RunStartCallback(deviceId, inputTypes, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_ITP) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + DHLOGI("Stop DInput Recv Callback ret: %B, devId: %s, inputTypes: %d", + result, GetAnonyString(deviceId).c_str(), inputTypes); + if (result && (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)) { + sourceManagerObj_->SetInputTypesMap( + deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) - + (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)); + } + + if (sourceManagerObj_->GetInputTypesMap(deviceId) == 0) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); + } + + // DeviceMap_ all sink device switch is off,call isstart's callback + bool isAllDevSwitchOff = sourceManagerObj_->GetDeviceMapAllDevSwitchOff(); + if (isAllDevSwitchOff) { + DHLOGI("All Dev Switch Off"); + sourceManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); + } + sourceManagerObj_->RunStopCallback(deviceId, inputTypes, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); +} + +void DInputSourceManagerEventHandler::NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_CODE) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhid = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + uint32_t keyType = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; + uint32_t keyCode = innerMsg[INPUT_SOURCEMANAGER_KEY_CODE]; + uint32_t keyValue = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + + sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue); +} + +void DInputSourceManagerEventHandler::NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + auto it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + DInputServerType startTransFlag = DInputServerType(serType); + sourceManagerObj_->SetStartTransFlag(startTransFlag); +} + + +void DInputSourceManagerEventHandler::NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + + sourceManagerObj_->RunRelayPrepareCallback(srcId, sinkId, status); +} + +void DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + + sourceManagerObj_->RunRelayUnprepareCallback(srcId, sinkId, status); +} + +void DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_WHITELIST) || + !IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_SESSIONID)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST]; + int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID]; + DHLOGI("Device whitelist object: %s", object.c_str()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + return; + } + + // notify to origin sourcesa result. + int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginPrepareResult(toSrcSessionId, + localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD); + if (ret != DH_SUCCESS) { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN notify is fail."); + return; + } + sourceManagerObj_->RunWhiteListCallback(deviceId, object); +} + +void DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) || + !IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) || + !IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_SESSIONID)) { + DHLOGE("The key is invaild."); + return ; + } + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID]; + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + return; + } + + // notify to origin sourcesa result. + int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginUnprepareResult(toSrcSessionId, + localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD); + if (ret != DH_SUCCESS) { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN notify is fail."); + return; + } +} + +void DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + + sourceManagerObj_->RunRelayStartDhidCallback(srcId, sinkId, status, dhids); +} + +void DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + + sourceManagerObj_->RunRelayStopDhidCallback(srcId, sinkId, status, dhids); +} + +void DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; + + sourceManagerObj_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); +} + +void DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event) +{ + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *it; + if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) || + !IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) || + !IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE)) { + DHLOGE("The key is invaild."); + return ; + } + int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; + std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; + uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; + + sourceManagerObj_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); +} + +void DInputSourceManagerEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + auto iter = eventFuncMap_.find(event->GetInnerEventId()); + if (iter == eventFuncMap_.end()) { + DHLOGE("Event Id %d is undefined.", event->GetInnerEventId()); + return; + } + SourceEventFunc &func = iter->second; + (this->*func)(event); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index ab0839ce3bf2bda5c2279427871f5706e8321263..aaf0344ddcb4b3121ae00fe34f499f2ea69acba8 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -15,12 +15,6 @@ #include "distributed_input_source_manager.h" -#include -#include -#include -#include - -#include "dinput_softbus_define.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "nlohmann/json.hpp" @@ -41,6 +35,7 @@ #include "distributed_input_source_proxy.h" #include "distributed_input_source_transport.h" #include "distributed_input_transport_base.h" +#include "dinput_softbus_define.h" #include "hisysevent_util.h" #include "hidumper.h" #include "input_check_param.h" @@ -64,477 +59,6 @@ DistributedInputSourceManager::~DistributedInputSourceManager() stopDScreenListener_ = nullptr; } -DistributedInputSourceManager::DInputSourceListener::DInputSourceListener(DistributedInputSourceManager *manager) -{ - sourceManagerObj_ = manager; - DHLOGI("DInputSourceListener init."); -} - -DistributedInputSourceManager::DInputSourceListener::~DInputSourceListener() -{ - sourceManagerObj_ = nullptr; - DHLOGI("DInputSourceListener destory."); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseRegisterDistributedHardware( - const std::string deviceId, const std::string dhId, bool result) -{ - DHLOGI("OnResponseRegisterDistributedHardware called, deviceId: %s, " - "result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponseRegisterDistributedHardware sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunRegisterCallback(deviceId, dhId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("OnResponseRegisterDistributedHardware GetCallbackEventHandler is null."); - return; - } - - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_RIGISTER_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponsePrepareRemoteInput(const std::string deviceId, - bool result, const std::string &object) -{ - DHLOGI("OnResponsePrepareRemoteInput called, deviceId: %s, result: %s.", - GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponsePrepareRemoteInput sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunPrepareCallback(deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object); - DHLOGE("OnResponsePrepareRemoteInput GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_PREPARE_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseUnprepareRemoteInput( - const std::string deviceId, bool result) -{ - DHLOGI("OnResponseUnprepareRemoteInput called, deviceId: %s, " - "result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponseUnprepareRemoteInput sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunUnprepareCallback(deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("OnResponseUnprepareRemoteInput GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_UNPREPARE_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseRelayPrepareRemoteInput(int32_t toSrcSessionId, - const std::string &deviceId, bool result, const std::string &object) -{ - DHLOGI("OnResponseRelayPrepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object; - tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseRelayUnprepareRemoteInput(int32_t toSrcSessionId, - const std::string &deviceId, bool result) -{ - DHLOGI("OnResponseRelayUnprepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseStartRemoteInput( - const std::string deviceId, const uint32_t inputTypes, bool result) -{ - DHLOGI("OnResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.", - GetAnonyString(deviceId).c_str(), inputTypes, result ? "success" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - sourceManagerObj_->RunStartCallback(deviceId, inputTypes, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - DHLOGE("GetCallbackEventHandler is null."); - return; - } - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); - } - - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_START_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseStopRemoteInput( - const std::string deviceId, const uint32_t inputTypes, bool result) -{ - DHLOGI("OnResponseStopRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.", - GetAnonyString(deviceId).c_str(), inputTypes, result ? "true" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponseStopRemoteInput sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("OnResponseStopRemoteInput GetCallbackEventHandler is null."); - sourceManagerObj_->RunStopCallback(deviceId, inputTypes, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( - DINPUT_SOURCE_MANAGER_STOP_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseStartRemoteInputDhid( - const std::string deviceId, const std::string &dhids, bool result) -{ - DHLOGI("OnResponseStartRemoteInputDhid called, deviceId: %s, result: %s.", - GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponseStartRemoteInputDhid sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("OnResponseStartRemoteInputDhid GetCallbackEventHandler is null."); - sourceManagerObj_->RunStartDhidCallback(deviceId, dhids, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - return; - } - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); - } - - std::vector vecStr; - StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, vecStr); - DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_IN, -1); - - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_START_DHID_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseStopRemoteInputDhid( - const std::string deviceId, const std::string &dhids, bool result) -{ - DHLOGI("OnResponseStopRemoteInputDhid called, deviceId: %s, result: %s.", - GetAnonyString(deviceId).c_str(), result ? "success" : "failed"); - - if (sourceManagerObj_ == nullptr) { - DHLOGE("OnResponseStopRemoteInputDhid sourceManagerObj_ is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("OnResponseStopRemoteInputDhid GetCallbackEventHandler is null."); - sourceManagerObj_->RunStopDhidCallback(deviceId, dhids, - ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; - tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_STOP_DHID_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnResponseKeyState(const std::string deviceId, - const std::string &dhid, const uint32_t type, const uint32_t code, const uint32_t value) -{ - DHLOGI("OnResponseKeyState called, deviceId: %s, dhid: %s.", GetAnonyString(deviceId).c_str(), - GetAnonyString(dhid).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, type, code, value); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; - tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhid; - tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = type; - tmpJson[INPUT_SOURCEMANAGER_KEY_CODE] = code; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = value; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_KEY_STATE_MSG, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceivedEventRemoteInput( - const std::string deviceId, const std::string &event) -{ - nlohmann::json inputData = nlohmann::json::parse(event, nullptr, false); - if (inputData.is_discarded()) { - DHLOGE("inputData parse failed!"); - return; - } - size_t jsonSize = inputData.size(); - DHLOGI("OnReceivedEventRemoteInput called, deviceId: %s, json size:%d.", - GetAnonyString(deviceId).c_str(), jsonSize); - - if (!inputData.is_array()) { - DHLOGE("inputData not vector!"); - return; - } - - RawEvent mEventBuffer[jsonSize]; - int idx = 0; - for (auto it = inputData.begin(); it != inputData.end(); ++it) { - nlohmann::json oneData = (*it); - if (!IsInt64(oneData, INPUT_KEY_WHEN) || !IsUInt32(oneData, INPUT_KEY_TYPE) || - !IsUInt32(oneData, INPUT_KEY_CODE) || !IsInt32(oneData, INPUT_KEY_VALUE) || - !IsString(oneData, INPUT_KEY_DESCRIPTOR) || !IsString(oneData, INPUT_KEY_PATH)) { - DHLOGE("The key is invaild."); - continue; - } - mEventBuffer[idx].when = oneData[INPUT_KEY_WHEN]; - mEventBuffer[idx].type = oneData[INPUT_KEY_TYPE]; - mEventBuffer[idx].code = oneData[INPUT_KEY_CODE]; - mEventBuffer[idx].value = oneData[INPUT_KEY_VALUE]; - mEventBuffer[idx].descriptor = oneData[INPUT_KEY_DESCRIPTOR]; - mEventBuffer[idx].path = oneData[INPUT_KEY_PATH]; - RecordEventLog(oneData[INPUT_KEY_WHEN], oneData[INPUT_KEY_TYPE], oneData[INPUT_KEY_CODE], - oneData[INPUT_KEY_VALUE], oneData[INPUT_KEY_PATH]); - ++idx; - } - DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayPrepareResult(int32_t status, - const std::string &srcId, const std::string &sinkId) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayUnprepareResult(int32_t status, - const std::string &srcId, const std::string &sinkId) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayStartDhidResult(int32_t status, - const std::string &srcId, const std::string &sinkId, const std::string &dhids) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayStopDhidResult(int32_t status, - const std::string &srcId, const std::string &sinkId, const std::string &dhids) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayStartTypeResult(int32_t status, - const std::string &srcId, const std::string &sinkId, uint32_t inputTypes) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - -void DistributedInputSourceManager::DInputSourceListener::OnReceiveRelayStopTypeResult(int32_t status, - const std::string &srcId, const std::string &sinkId, uint32_t inputTypes) -{ - DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); - if (sourceManagerObj_ == nullptr) { - DHLOGE("sourceManagerObj is null."); - return; - } - if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { - DHLOGE("GetCallbackEventHandler is null."); - return; - } - std::shared_ptr jsonArrayMsg = std::make_shared(); - nlohmann::json tmpJson; - tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId; - tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId; - tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status; - tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes; - jsonArrayMsg->push_back(tmpJson); - AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI, jsonArrayMsg, 0); - sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); -} - DistributedInputSourceManager::DInputSrcMgrListener::DInputSrcMgrListener(DistributedInputSourceManager *manager) { sourceManagerObj_ = manager; @@ -579,7 +103,6 @@ void DistributedInputSourceManager::OnStart() if (!ret) { return; } - DHLOGI("DistributedInputSourceManager start success."); } @@ -589,380 +112,14 @@ bool DistributedInputSourceManager::InitAuto() if (runner_ == nullptr) { return false; } - handler_ = std::make_shared(runner_); DHLOGI("init success"); - std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); - callBackHandler_ = std::make_shared(runner, this); - + callBackHandler_ = std::make_shared(runner, this); return true; } -DistributedInputSourceManager::DInputSourceManagerEventHandler::DInputSourceManagerEventHandler( - const std::shared_ptr &runner, DistributedInputSourceManager *manager) - : AppExecFwk::EventHandler(runner) -{ - eventFuncMap_[DINPUT_SOURCE_MANAGER_RIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyRegisterCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyUnregisterCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_PREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyPrepareCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_UNPREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyUnprepareCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_START_MSG] = &DInputSourceManagerEventHandler::NotifyStartCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_MSG] = &DInputSourceManagerEventHandler::NotifyStopCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_START_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStartDhidCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStopDhidCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_KEY_STATE_MSG] = &DInputSourceManagerEventHandler::NotifyKeyStateCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_STARTSERVER_MSG] = &DInputSourceManagerEventHandler::NotifyStartServerCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN] = - &DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN] = - &DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayPrepareCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback; - eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI] = - &DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback; - - sourceManagerObj_ = manager; -} - -DistributedInputSourceManager::DInputSourceManagerEventHandler::~DInputSourceManagerEventHandler() -{ - eventFuncMap_.clear(); - sourceManagerObj_ = nullptr; -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegisterCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - InputDeviceId inputDeviceId {deviceId, dhId}; - std::vector tmpInputDevId = sourceManagerObj_->GetInputDeviceId(); - // Find out if the dh exists - auto devIt = std::find(tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId); - if (devIt != tmpInputDevId.end()) { - if (result == false) { - sourceManagerObj_->RemoveInputDeviceId(deviceId, dhId); - } - } else { - DHLOGW("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG the " - "devId: %s, dhId: %s is bad data.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); - } - - sourceManagerObj_->RunRegisterCallback(deviceId, dhId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnregisterCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); - } - sourceManagerObj_->RunUnregisterCallback(deviceId, dhId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST]; - - sourceManagerObj_->RunPrepareCallback(deviceId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnprepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - if (result) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); - } - sourceManagerObj_->RunUnprepareCallback(deviceId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - DHLOGI("Start DInput Recv Callback ret: %s, devId: %s, inputTypes: %d", - result ? "true" : "false", GetAnonyString(deviceId).c_str(), inputTypes); - if (result) { - sourceManagerObj_->SetInputTypesMap( - deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) | inputTypes); - } - sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ? - DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); - sourceManagerObj_->RunStartCallback(deviceId, inputTypes, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - DHLOGI("Stop DInput Recv Callback ret: %B, devId: %s, inputTypes: %d", - result, GetAnonyString(deviceId).c_str(), inputTypes); - if (result && (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)) { - sourceManagerObj_->SetInputTypesMap( - deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) - - (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)); - } - - if (sourceManagerObj_->GetInputTypesMap(deviceId) == 0) { - sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF); - } - - // DeviceMap_ all sink device switch is off,call isstart's callback - bool isAllDevSwitchOff = sourceManagerObj_->GetDeviceMapAllDevSwitchOff(); - if (isAllDevSwitchOff) { - DHLOGI("All Dev Switch Off"); - sourceManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - } - sourceManagerObj_->RunStopCallback(deviceId, inputTypes, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartDhidCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopDhidCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - - sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyKeyStateCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - std::string dhid = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; - uint32_t keyType = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; - uint32_t keyCode = innerMsg[INPUT_SOURCEMANAGER_KEY_CODE]; - uint32_t keyValue = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - - sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartServerCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - auto it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - DInputServerType startTransFlag = DInputServerType(serType); - sourceManagerObj_->SetStartTransFlag(startTransFlag); -} - - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayPrepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - - sourceManagerObj_->RunRelayPrepareCallback(srcId, sinkId, status); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - - sourceManagerObj_->RunRelayUnprepareCallback(srcId, sinkId, status); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST]; - int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID]; - DHLOGI("Device whitelist object: %s", object.c_str()); - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - return; - } - - // notify to origin sourcesa result. - int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginPrepareResult(toSrcSessionId, - localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD); - if (ret != DH_SUCCESS) { - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN notify is fail."); - return; - } - sourceManagerObj_->RunWhiteListCallback(deviceId, object); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; - bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; - int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID]; - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - return; - } - - // notify to origin sourcesa result. - int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginUnprepareResult(toSrcSessionId, - localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD); - if (ret != DH_SUCCESS) { - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN notify is fail."); - return; - } -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; - - sourceManagerObj_->RunRelayStartDhidCallback(srcId, sinkId, status, dhids); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; - - sourceManagerObj_->RunRelayStopDhidCallback(srcId, sinkId, status, dhids); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; - - sourceManagerObj_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback( - const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); - nlohmann::json innerMsg = *(it); - int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; - std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID]; - std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID]; - uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; - - sourceManagerObj_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); -} - -void DistributedInputSourceManager::DInputSourceManagerEventHandler::ProcessEvent( - const AppExecFwk::InnerEvent::Pointer &event) -{ - auto iter = eventFuncMap_.find(event->GetInnerEventId()); - if (iter == eventFuncMap_.end()) { - DHLOGE("Event Id %d is undefined.", event->GetInnerEventId()); - return; - } - SourceEventFunc &func = iter->second; - (this->*func)(event); -} - void DistributedInputSourceManager::OnStop() { DHLOGI("stop service"); @@ -984,12 +141,10 @@ int32_t DistributedInputSourceManager::Init() statuslistener_ = std::make_shared(this); DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_); - srcMgrListener_ = std::make_shared(this); DistributedInputTransportBase::GetInstance().RegisterSourceManagerCallback(srcMgrListener_); serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING; - std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); if (dhFwkKit == nullptr) { DHLOGE("dhFwkKit obtain fail!"); @@ -1007,7 +162,6 @@ int32_t DistributedInputSourceManager::Init() DHLOGE("DInputState init fail!"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL; } - return DH_SUCCESS; } @@ -1103,19 +257,17 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st const std::string ¶meters, sptr callback) { HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_REGISTER, devId, dhId, "dinput register call."); - DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); if (!CheckRegisterParam(devId, dhId, parameters, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, "Dinputregister failed callback is nullptr."); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; } + DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); std::lock_guard lock(operationMutex_); DInputClientRegistInfo info {devId, dhId, callback}; regCallbacks_.push_back(info); InputDeviceId inputDeviceId {devId, dhId, GetNodeDesc(parameters)}; - DHLOGI("RegisterDistributedHardware deviceId: %s, dhId: %s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); // 1.Find out if the dh exists auto it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); @@ -1128,8 +280,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedHardware(devId, dhId, parameters); if (ret != DH_SUCCESS) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, - "dinput register distributed hardware failed in create input node."); + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, "Dinputregister failed in create input node."); DHLOGE("RegisterDistributedHardware called, create node fail."); for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); ++iter) { @@ -1246,7 +397,6 @@ int32_t DistributedInputSourceManager::CheckDeviceIsExists(const std::string &de } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } - return DH_SUCCESS; } @@ -1287,20 +437,17 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: sptr callback) { HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNREGISTER, devId, dhId, "dinput unregister call"); - DHLOGI("Unregister called, deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (!CheckUnregisterParam(devId, dhId, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, "dinput unregister failed in callback is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } - + DHLOGI("Unregister called, deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(operationMutex_); DInputClientUnregistInfo info {devId, dhId, callback}; unregCallbacks_.push_back(info); InputDeviceId inputDeviceId {devId, dhId}; - DHLOGI("Unregister deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - auto it = inputDevice_.begin(); if (CheckDeviceIsExists(devId, dhId, inputDeviceId, it) != DH_SUCCESS) { DHLOGE("Unregister deviceId: %s is not exist.", GetAnonyString(devId).c_str()); @@ -1372,7 +519,6 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput( } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } - return DH_SUCCESS; } @@ -1415,7 +561,6 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput( } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; } - return DH_SUCCESS; } @@ -1460,7 +605,6 @@ int32_t DistributedInputSourceManager::StartRemoteInput( } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } - return DH_SUCCESS; } @@ -1504,7 +648,6 @@ int32_t DistributedInputSourceManager::StopRemoteInput( } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } - return DH_SUCCESS; } @@ -1675,13 +818,13 @@ int32_t DistributedInputSourceManager::RelayStopRemoteInputByType( int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { - DHLOGI("Dinput prepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, "Dinput prepare param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } + DHLOGI("Dinput prepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; @@ -1714,20 +857,19 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &src } return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } - return DH_SUCCESS; } int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { - DHLOGI("Dinput unprepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, "Dinput unprepare param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; } + DHLOGI("Dinput unprepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; @@ -1783,13 +925,13 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &sinkI { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "dinput start use call"); - DHLOGI("Dinput start, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); if (!DInputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } + DHLOGI("Dinput start, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, @@ -1834,13 +976,13 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &sinkId { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "dinput stop use call"); - DHLOGI("Dinput stop, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); if (!DInputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } + DHLOGI("Dinput stop, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, @@ -1882,13 +1024,13 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "Dinput start use call."); - DHLOGI("Dinput start, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } + DHLOGI("Dinput start, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, @@ -1934,14 +1076,14 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "Dinput stop use call."); - DHLOGI("Dinput stop, srcId: %s, sinkId: %s, vector.string.size: %d", - GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size()); if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is failed."); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } + DHLOGI("Dinput stop, srcId: %s, sinkId: %s, vector.string.size: %d", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size()); std::string localNetworkId = GetLocalNetworkId(); if (localNetworkId.empty()) { HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, @@ -2068,7 +1210,7 @@ int32_t DistributedInputSourceManager::RegisterSessionStateCb(sptr dhidsVec; StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec); @@ -2420,7 +1554,7 @@ void DistributedInputSourceManager::RunRelayStartDhidCallback(const std::string } void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string &srcId, const std::string &sinkId, - const int32_t &status, const std::string &dhids) + const int32_t status, const std::string &dhids) { std::vector dhidsVec; StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec); @@ -2442,7 +1576,7 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string & } void DistributedInputSourceManager::RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, - const int32_t &status, uint32_t inputTypes) + const int32_t status, uint32_t inputTypes) { bool isCbRun = false; FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); @@ -2463,7 +1597,7 @@ void DistributedInputSourceManager::RunRelayStartTypeCallback(const std::string } void DistributedInputSourceManager::RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, - const int32_t &status, uint32_t inputTypes) + const int32_t status, uint32_t inputTypes) { bool isCbRun = false; FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); @@ -2615,38 +1749,6 @@ void DistributedInputSourceManager::DeleteSyncNodeInfo(const std::string &devId) syncNodeInfoMap_.erase(devId); } -void DistributedInputSourceManager::DInputSourceListener::RecordEventLog(int64_t when, int32_t type, int32_t code, - int32_t value, const std::string &path) -{ - std::string eventType = ""; - switch (type) { - case EV_KEY: - eventType = "EV_KEY"; - break; - case EV_REL: - eventType = "EV_REL"; - break; - case EV_ABS: - eventType = "EV_ABS"; - break; - default: - eventType = "other type"; - break; - } - DHLOGD("3.E2E-Test Source softBus receive event, EventType: %s, Code: %d, Value: %d, Path: %s, When: %" PRId64 "", - eventType.c_str(), code, value, path.c_str(), when); -} - -DistributedInputSourceManager::StartDScreenListener::StartDScreenListener() -{ - DHLOGI("StartDScreenListener ctor!"); -} - -DistributedInputSourceManager::StartDScreenListener::~StartDScreenListener() -{ - DHLOGI("StartDScreenListener dtor!"); -} - void DistributedInputSourceManager::StartDScreenListener::OnMessage(const DHTopic topic, const std::string &message) { DHLOGI("StartDScreenListener OnMessage!"); @@ -2758,16 +1860,6 @@ int32_t DistributedInputSourceManager::StartDScreenListener::UpdateSrcScreenInfo return DInputContext::GetInstance().UpdateSrcScreenInfo(srcScreenInfoKey, srcScreenInfo); } -DistributedInputSourceManager::StopDScreenListener::StopDScreenListener() -{ - DHLOGI("StopDScreenListener ctor!"); -} - -DistributedInputSourceManager::StopDScreenListener::~StopDScreenListener() -{ - DHLOGI("StopDScreenListener dtor!"); -} - void DistributedInputSourceManager::StopDScreenListener::OnMessage(const DHTopic topic, const std::string &message) { DHLOGI("StopDScreenListener OnMessage!"); @@ -2836,11 +1928,6 @@ DistributedInputSourceManager::DeviceOfflineListener::DeviceOfflineListener( sourceManagerContext_ = srcManagerContext; } -DistributedInputSourceManager::DeviceOfflineListener::~DeviceOfflineListener() -{ - DHLOGI("DeviceOfflineListener dtor!"); -} - void DistributedInputSourceManager::DeviceOfflineListener::OnMessage(const DHTopic topic, const std::string &message) { DHLOGI("DeviceOfflineListener OnMessage!"); @@ -2883,11 +1970,6 @@ DistributedInputSourceManager::DScreenSourceSvrRecipient::DScreenSourceSvrRecipi this->srcWinId_ = srcWinId; } -DistributedInputSourceManager::DScreenSourceSvrRecipient::~DScreenSourceSvrRecipient() -{ - DHLOGI("DScreenStatusListener dtor!"); -} - void DistributedInputSourceManager::DScreenSourceSvrRecipient::OnRemoteDied(const wptr &remote) { DHLOGI("DScreenStatusListener OnRemoveSystemAbility"); diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 9ec9226c5752121a9da93f72a5376129b95ddb5c..46761e9b3a75d02dea0097f6fb25346f9d5dc4e0 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_input/distributedinput.gni") +import("../../../../../distributedinput.gni") module_out_path = "distributed_input/source_manager" @@ -86,6 +85,8 @@ ohos_unittest("distributed_input_sourcemanager_test") { "${services_source_path}/inputinject/src/distributed_input_inject.cpp", "${services_source_path}/inputinject/src/distributed_input_node_manager.cpp", "${services_source_path}/inputinject/src/virtual_device.cpp", + "${services_source_path}/sourcemanager/src/dinput_source_listener.cpp", + "${services_source_path}/sourcemanager/src/dinput_source_manager_event_handler.cpp", "${services_source_path}/sourcemanager/src/distributed_input_source_event_handler.cpp", "${services_source_path}/sourcemanager/src/distributed_input_source_manager.cpp", "${services_source_path}/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp", diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp index 7921c96acb179988f58df215aca442108e243cdf..e9c4c2d871e9bdb43e42cfb4a76f12fb33df98fb 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -49,7 +49,7 @@ namespace { void DistributedInputSourceManagerTest::SetUp() { sourceManager_ = new DistributedInputSourceManager(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true); - statuslistener_ = std::make_shared(sourceManager_); + statuslistener_ = std::make_shared(sourceManager_); DistributedInputSourceManagerTest::RegisterSourceRespCallback(statuslistener_); } diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h index c1f1804fef63c35b650f1df85cdf1ba4bb275da4..c47d5e0981e5ca0cba7fe60b6e2baf601d990f0c 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h @@ -39,6 +39,7 @@ #include "simulation_event_listener_stub.h" #include "dinput_source_trans_callback.h" +#include "dinput_source_listener.h" namespace OHOS { namespace DistributedHardware { @@ -156,7 +157,7 @@ public: private: int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) const; DistributedInputSourceManager* sourceManager_; - std::shared_ptr statuslistener_; + std::shared_ptr statuslistener_; std::shared_ptr callback_; }; } // namespace DistributedInput diff --git a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp index a985a71522943770998de176e275a30b74af6634..25c8d5f263c2501deb3780535245a1c9640ea5de 100644 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp +++ b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp @@ -524,8 +524,8 @@ HWTEST_F(DistributedInputSourceTransTest, NotifyResponsePrepareRemoteInput03, te std::string remoteId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[remoteId] = sessionId; DistributedInputSourceManager srcMgr(4810, false); - std::shared_ptr srcListener = - std::make_shared(&srcMgr); + std::shared_ptr srcListener = + std::make_shared(&srcMgr); DistributedInputSourceTransport::GetInstance().callback_ = srcListener; DistributedInputSourceTransport::GetInstance().NotifyResponsePrepareRemoteInput(sessionId, recMsg); std::string message(MSG_MAX_SIZE + 1, 'a');