From 99071bf9db0c252be380d908e26e6375c399e9c4 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Wed, 22 Nov 2023 22:20:40 +0800 Subject: [PATCH 1/3] test commit Signed-off-by: l30054665 --- services/common/include/dinput_sink_manager_callback.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/include/dinput_sink_manager_callback.h b/services/common/include/dinput_sink_manager_callback.h index 0d436cf..8a38ff0 100644 --- a/services/common/include/dinput_sink_manager_callback.h +++ b/services/common/include/dinput_sink_manager_callback.h @@ -27,6 +27,6 @@ public: }; } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS52222 #endif // DISTRIBUTED_SINK_MANAGER_CALLBACK_H -- Gitee From b43ddf51b5a42ac099199dee73e29c84ef584fb4 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Wed, 22 Nov 2023 23:08:09 +0800 Subject: [PATCH 2/3] delete inputtype function Signed-off-by: l30054665 --- common/include/constants_dinput.h | 11 - common/include/input_check_param.cpp | 46 +- common/include/input_check_param.h | 3 - common/include/input_hub.cpp | 44 +- common/include/input_hub.h | 5 +- .../include/i_distributed_source_input.h | 14 - .../include/i_start_d_input_call_back.h | 40 -- frameworks/include/i_stop_d_input_call_back.h | 40 -- .../include/distributed_input_handler.h | 1 - .../src/distributed_input_handler.cpp | 7 - .../distributed_input_handler_test.cpp | 6 +- interfaces/inner_kits/BUILD.gn | 4 - .../include/distributed_input_kit.h | 13 - .../inner_kits/src/distributed_input_kit.cpp | 29 - interfaces/inner_kits/test/unittest/BUILD.gn | 4 - .../unittest/distributed_input_inner_test.cpp | 103 +--- .../unittest/distributed_input_inner_test.h | 18 - .../mock/mock_distributed_input_client.cpp | 24 - .../ipc/include/distributed_input_client.h | 13 - .../include/distributed_input_source_proxy.h | 12 - .../include/distributed_input_source_stub.h | 4 - .../include/start_d_input_call_back_proxy.h | 42 -- .../include/start_d_input_call_back_stub.h | 6 - .../include/stop_d_input_call_back_proxy.h | 42 -- .../ipc/include/stop_d_input_call_back_stub.h | 6 - .../ipc/src/distributed_input_client.cpp | 63 +-- .../src/distributed_input_source_proxy.cpp | 130 ----- .../ipc/src/distributed_input_source_stub.cpp | 98 ---- .../ipc/src/start_d_input_call_back_proxy.cpp | 69 --- .../ipc/src/start_d_input_call_back_stub.cpp | 58 -- .../ipc/src/stop_d_input_call_back_proxy.cpp | 69 --- .../ipc/src/stop_d_input_call_back_stub.cpp | 58 -- .../BUILD.gn | 4 - .../add_white_list_infos_call_back_test.cpp | 39 +- .../add_white_list_infos_call_back_test.h | 26 +- interfaces/ipc/test/clientunittest/BUILD.gn | 4 - .../distributed_input_client_test.cpp | 96 +--- .../distributed_input_client_test.h | 18 - .../dinputsourcecallbackunittest/BUILD.gn | 4 - .../dinput_source_callback_unittest.cpp | 107 +--- .../dinput_source_callback_unittest.h | 32 +- interfaces/ipc/test/ipcunittest/BUILD.gn | 4 - .../distributed_input_ipc_test.cpp | 40 +- .../include/dinput_sink_manager_callback.h | 2 +- .../include/dinput_sink_trans_callback.h | 6 - .../common/include/dinput_softbus_define.h | 1 - .../include/dinput_source_trans_callback.h | 6 - .../include/distributed_input_collector.h | 5 +- .../src/distributed_input_collector.cpp | 29 +- .../distributed_input_collector_test.cpp | 47 +- .../include/distributed_input_sink_manager.h | 10 - .../src/distributed_input_sink_manager.cpp | 210 +------- .../distributed_input_sinkmanager_test.cpp | 10 +- .../distributed_input_sink_transport.h | 4 - .../src/distributed_input_sink_transport.cpp | 65 --- .../distributed_input_sinktrans_test.cpp | 12 +- .../include/distributed_input_inject.h | 3 +- .../include/distributed_input_node_manager.h | 3 +- .../src/distributed_input_inject.cpp | 18 +- .../src/distributed_input_node_manager.cpp | 25 - .../distributed_input_sourceinject_test.cpp | 43 -- services/source/sourcemanager/BUILD.gn | 4 - .../include/dinput_source_listener.h | 8 +- .../dinput_source_manager_event_handler.h | 4 +- .../distributed_input_source_manager.h | 63 --- .../src/dinput_source_listener.cpp | 110 +--- .../dinput_source_manager_event_handler.cpp | 111 +--- .../src/distributed_input_source_manager.cpp | 351 ------------ .../test/sourcemanagerunittest/BUILD.gn | 4 - .../distributed_input_sourcemanager_test.cpp | 503 +----------------- .../distributed_input_sourcemanager_test.h | 18 - .../distributed_input_source_transport.h | 19 - .../distributed_input_source_transport.cpp | 387 -------------- .../distributed_input_sourcetrans_test.cpp | 259 --------- services/state/include/dinput_state.h | 1 + services/state/src/dinput_state.cpp | 5 + .../include/distributed_input_sink_handler.h | 4 - .../src/distributed_input_sink_handler.cpp | 20 - .../mock/mock_distributed_input_client.cpp | 12 - .../mock/mock_distributed_input_client.cpp | 12 - .../distributed_input_kit_fuzzer.cpp | 34 +- 81 files changed, 61 insertions(+), 3823 deletions(-) delete mode 100644 frameworks/include/i_start_d_input_call_back.h delete mode 100644 frameworks/include/i_stop_d_input_call_back.h delete mode 100644 interfaces/ipc/include/start_d_input_call_back_proxy.h delete mode 100644 interfaces/ipc/include/stop_d_input_call_back_proxy.h delete mode 100644 interfaces/ipc/src/start_d_input_call_back_proxy.cpp delete mode 100644 interfaces/ipc/src/start_d_input_call_back_stub.cpp delete mode 100644 interfaces/ipc/src/stop_d_input_call_back_proxy.cpp delete mode 100644 interfaces/ipc/src/stop_d_input_call_back_stub.cpp diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index d7bc53d..25705dc 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -50,17 +50,6 @@ namespace DistributedInput { const uint32_t IPC_VECTOR_MAX_SIZE = 32; const uint32_t SIM_TOUCH_TRACKING_ID = 0x0001; - /* - * Device Type definitions - */ - enum class DInputDeviceType : uint32_t { - NONE = 0x0000, - MOUSE = 0x0001, - KEYBOARD = 0x0002, - TOUCHSCREEN = 0x0004, - TOUCHPAD = MOUSE, - ALL = MOUSE | KEYBOARD | TOUCHSCREEN, - }; const char * const DEVICE_PATH = "/dev/input"; diff --git a/common/include/input_check_param.cpp b/common/include/input_check_param.cpp index af980bd..d2faca8 100644 --- a/common/include/input_check_param.cpp +++ b/common/include/input_check_param.cpp @@ -39,50 +39,6 @@ bool DInputCheckParam::CheckParam(const std::string &deviceId, sptr callback) -{ - if (deviceId.empty() || deviceId.size() > DEV_ID_LENGTH_MAX) { - DHLOGE("CheckParam deviceId is empty or deviceId size too long."); - return false; - } - if (inputTypes > static_cast(DInputDeviceType::ALL) || - inputTypes == static_cast(DInputDeviceType::NONE) || - !(inputTypes & static_cast(DInputDeviceType::ALL))) { - DHLOGE("CheckParam, inputTypes is invalids."); - return false; - } - if (callback == nullptr) { - DHLOGE("CheckParam callback is null."); - return false; - } - return true; -} - -bool DInputCheckParam::CheckParam(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) -{ - if (srcId.empty() || srcId.size() > DEV_ID_LENGTH_MAX) { - DHLOGE("CheckParam srcId is empty or srcId size too long."); - return false; - } - if (sinkId.empty() || sinkId.size() > DEV_ID_LENGTH_MAX) { - DHLOGE("CheckParam sinkId is empty or sinkId size too long."); - return false; - } - if (inputTypes > static_cast(DInputDeviceType::ALL) || - inputTypes == static_cast(DInputDeviceType::NONE) || - !(inputTypes & static_cast(DInputDeviceType::ALL))) { - DHLOGE("CheckParam, inputTypes is invalids."); - return false; - } - if (callback == nullptr) { - DHLOGE("CheckParam callback is null."); - return false; - } - return true; -} - bool DInputCheckParam::CheckParam(const std::string &srcId, const std::string &sinkId, sptr callback) { @@ -194,4 +150,4 @@ bool DInputCheckParam::CheckUnregisterParam(const std::string &devId, const std: } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/include/input_check_param.h b/common/include/input_check_param.h index 1643726..b2f9dc0 100644 --- a/common/include/input_check_param.h +++ b/common/include/input_check_param.h @@ -27,9 +27,6 @@ class DInputCheckParam { public: static DInputCheckParam &GetInstance(void); bool CheckParam(const std::string &deviceId, sptr callback); - bool CheckParam(const std::string &deviceId, const uint32_t &inputTypes, sptr callback); - bool CheckParam(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); bool CheckParam(const std::string &srcId, const std::string &sinkId, sptr callback); bool CheckParam(const std::string &sinkId, const std::vector &dhIds, sptr callback); diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index c3afa22..922df63 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -46,7 +46,7 @@ const std::string MOUSE_NODE_KEY = "mouse"; InputHub::InputHub() : epollFd_(0), iNotifyFd_(0), inputWd_(0), needToScanDevices_(true), nextDeviceId_(1), mPendingEventItems{}, pendingEventCount_(0), pendingEventIndex_(0), pendingINotify_(false), deviceChanged_(false), - inputTypes_(0), isStartCollectEvent_(false), isStartCollectHandler_(false) + isStartCollectEvent_(false), isStartCollectHandler_(false) { Initialize(); } @@ -847,7 +847,6 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) device->identifier.classes = device->classes; - DHLOGI("inputType=%d", inputTypes_.load()); DHLOGI("New device: fd=%d, name='%s', classes=0x%x", fd, device->identifier.name.c_str(), device->classes); @@ -1166,23 +1165,6 @@ void InputHub::SaveAffectDhId(bool isEnable, const std::string &dhId, AffectDhId } } -AffectDhIds InputHub::SetSupportInputType(bool enabled, const uint32_t &inputTypes) -{ - AffectDhIds affDhIds; - inputTypes_ = inputTypes; - DHLOGI("SetSupportInputType: inputTypes=0x%x,", inputTypes_.load()); - std::lock_guard deviceLock(devicesMutex_); - for (const auto &[id, device] : devices_) { - if (device->classes & inputTypes_) { - device->isShare = enabled; - DHLOGW("ByType dhid:%s, isshare:%d", GetAnonyString(device->identifier.descriptor).c_str(), enabled); - SaveAffectDhId(enabled, device->identifier.descriptor, affDhIds); - } - } - - return affDhIds; -} - AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector dhIds) { AffectDhIds affDhIds; @@ -1253,30 +1235,6 @@ void InputHub::GetSharedKeyboardPathsByDhIds(const std::vector &dhI } } -void InputHub::GetDevicesInfoByType(const uint32_t inputTypes, std::map &datas) -{ - uint32_t dhType = 0; - - if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { - dhType |= INPUT_DEVICE_CLASS_CURSOR; - } - - if ((inputTypes & static_cast(DInputDeviceType::KEYBOARD)) != 0) { - dhType |= INPUT_DEVICE_CLASS_KEYBOARD; - } - - if ((inputTypes & static_cast(DInputDeviceType::TOUCHSCREEN)) != 0) { - dhType |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; - } - - std::lock_guard deviceLock(devicesMutex_); - for (const auto &[id, device] : devices_) { - if (device->classes & dhType) { - datas.insert(std::pair(device->fd, device->identifier.descriptor)); - } - } -} - void InputHub::GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas) { for (auto dhId : dhidsVec) { diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 8964fb8..c466a55 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -82,11 +82,9 @@ public: void StopCollectInputHandler(); size_t DeviceIsExists(InputDeviceEvent *buffer, size_t bufferSize); std::vector GetAllInputDevices(); - // return efftive dhids - AffectDhIds SetSupportInputType(bool enabled, const uint32_t &inputTypes); + // return efftive dhids AffectDhIds SetSharingDevices(bool enabled, std::vector dhIds); - void GetDevicesInfoByType(const uint32_t inputTypes, std::map &datas); void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); void GetSharedMousePathByDhId(const std::vector &dhIds, std::string &sharedMousePath, std::string &sharedMouseDhId); @@ -224,7 +222,6 @@ private: std::mutex operationMutex_; std::atomic deviceChanged_; - std::atomic inputTypes_; std::atomic isStartCollectEvent_; std::atomic isStartCollectHandler_; std::unordered_map sharedDHIds_; diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index fbe654a..cffca97 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -27,8 +27,6 @@ #include "i_del_white_list_infos_call_back.h" #include "i_prepare_d_input_call_back.h" #include "i_register_d_input_call_back.h" -#include "i_start_d_input_call_back.h" -#include "i_stop_d_input_call_back.h" #include "i_start_stop_d_inputs_call_back.h" #include "i_start_stop_result_call_back.h" #include "i_unprepare_d_input_call_back.h" @@ -60,18 +58,6 @@ public: virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback) = 0; - virtual int32_t StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) = 0; - - virtual int32_t StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) = 0; - - virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) = 0; - - virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) = 0; - virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) = 0; diff --git a/frameworks/include/i_start_d_input_call_back.h b/frameworks/include/i_start_d_input_call_back.h deleted file mode 100644 index 8c02692..0000000 --- a/frameworks/include/i_start_d_input_call_back.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021-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 I_START_D_INPUT_CALL_BACK_H -#define I_START_D_INPUT_CALL_BACK_H - -#include - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class IStartDInputCallback : public IRemoteBroker { -public: - virtual void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) = 0; - - enum class Message { - RESULT, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartDInputCallback"); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // I_START_D_INPUT_CALL_BACK_H diff --git a/frameworks/include/i_stop_d_input_call_back.h b/frameworks/include/i_stop_d_input_call_back.h deleted file mode 100644 index c54cd1d..0000000 --- a/frameworks/include/i_stop_d_input_call_back.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021-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 I_STOP_D_INPUT_CALL_BACK_H -#define I_STOP_D_INPUT_CALL_BACK_H - -#include - -#include - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class IStopDInputCallback : public IRemoteBroker { -public: - virtual void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) = 0; - - enum class Message { - RESULT, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStopDInputCallback"); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // I_STOP_D_INPUT_CALL_BACK_H diff --git a/inputdevicehandler/include/distributed_input_handler.h b/inputdevicehandler/include/distributed_input_handler.h index 16087a8..59840e6 100644 --- a/inputdevicehandler/include/distributed_input_handler.h +++ b/inputdevicehandler/include/distributed_input_handler.h @@ -47,7 +47,6 @@ public: API_EXPORT void RegisterPluginListener(std::shared_ptr listener) override; API_EXPORT void UnRegisterPluginListener() override; - API_EXPORT void FindDevicesInfoByType(const uint32_t inputTypes, std::map &datas); API_EXPORT void FindDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); private: DistributedInputHandler(); diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 6972463..3da58df 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -95,13 +95,6 @@ int32_t DistributedInputHandler::Initialize() return DH_SUCCESS; } -void DistributedInputHandler::FindDevicesInfoByType(const uint32_t inputTypes, std::map &datas) -{ - if (inputHub_ != nullptr) { - inputHub_->GetDevicesInfoByType(inputTypes, datas); - } -} - void DistributedInputHandler::FindDevicesInfoByDhId( std::vector dhidsVec, std::map &datas) { diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp index 979a5cd..f5e56f6 100644 --- a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp @@ -42,10 +42,8 @@ void DInputHandlerTest::TearDownTestCase() HWTEST_F(DInputHandlerTest, QueryExtraInfo_001, testing::ext::TestSize.Level1) { DistributedInputHandler dInputHandler; - uint32_t inputTypes = static_cast(DInputDeviceType::ALL); std::map datas; std::vector dhidsVec; - dInputHandler.FindDevicesInfoByType(inputTypes, datas); dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas); std::map ret = dInputHandler.QueryExtraInfo(); EXPECT_EQ(0, ret.size()); @@ -55,11 +53,9 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le { DistributedInputHandler dInputHandler; dInputHandler.inputHub_ = nullptr; - uint32_t inputTypes = static_cast(DInputDeviceType::ALL); std::map datas; std::vector dhidsVec; std::string deviceId = "deviceId_test"; - dInputHandler.FindDevicesInfoByType(inputTypes, datas); dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas); dInputHandler.Query(); dInputHandler.StartInputMonitorDeviceThread(deviceId); @@ -81,4 +77,4 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index 0dc7ba2..081edd2 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -71,14 +71,10 @@ ohos_shared_library("libdinput_sdk") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index e0ec439..9594f3b 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -24,8 +24,6 @@ #include "distributed_input_client.h" #include "i_prepare_d_input_call_back.h" #include "i_register_d_input_call_back.h" -#include "i_start_d_input_call_back.h" -#include "i_stop_d_input_call_back.h" #include "i_start_stop_d_inputs_call_back.h" #include "i_start_stop_result_call_back.h" #include "i_unregister_d_input_call_back.h" @@ -46,21 +44,11 @@ public: static int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback); - static int32_t StartRemoteInput( - const std::string &sinkId, const uint32_t &inputTypes, sptr callback); - static int32_t StopRemoteInput( - const std::string &sinkId, const uint32_t &inputTypes, sptr callback); - static int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, sptr callback); static int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, sptr callback); - static int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - static int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - static int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, sptr callback); static int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, @@ -69,7 +57,6 @@ public: static bool IsNeedFilterOut(const std::string &sinkId, const BusinessEvent &event); static bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event); - static DInputServerType IsStartDistributedInput(const uint32_t &inputType); /* * check is dhId sharing to other devices * true: dhId sharing to other device diff --git a/interfaces/inner_kits/src/distributed_input_kit.cpp b/interfaces/inner_kits/src/distributed_input_kit.cpp index 2cdd774..f0c4caf 100644 --- a/interfaces/inner_kits/src/distributed_input_kit.cpp +++ b/interfaces/inner_kits/src/distributed_input_kit.cpp @@ -30,30 +30,6 @@ int32_t DistributedInputKit::UnprepareRemoteInput( return DistributedInputClient::GetInstance().UnprepareRemoteInput(sinkId, callback); } -int32_t DistributedInputKit::StartRemoteInput( - const std::string &sinkId, const uint32_t &inputTypes, sptr callback) -{ - return DistributedInputClient::GetInstance().StartRemoteInput(sinkId, inputTypes, callback); -} - -int32_t DistributedInputKit::StopRemoteInput( - const std::string &sinkId, const uint32_t &inputTypes, sptr callback) -{ - return DistributedInputClient::GetInstance().StopRemoteInput(sinkId, inputTypes, callback); -} - -int32_t DistributedInputKit::StartRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - return DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, inputTypes, callback); -} - -int32_t DistributedInputKit::StopRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - return DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, inputTypes, callback); -} - bool DistributedInputKit::IsNeedFilterOut(const std::string &sinkId, const BusinessEvent &event) { return DistributedInputClient::GetInstance().IsNeedFilterOut(sinkId, event); @@ -64,11 +40,6 @@ bool DistributedInputKit::IsTouchEventNeedFilterOut(const TouchScreenEvent &even return DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); } -DInputServerType DistributedInputKit::IsStartDistributedInput(const uint32_t &inputType) -{ - return DInputServerType::NULL_SERVER_TYPE; -} - bool DistributedInputKit::IsStartDistributedInput(const std::string &dhId) { return DistributedInputClient::GetInstance().IsStartDistributedInput(dhId); diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index c8ca062..e8120ac 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -66,14 +66,10 @@ ohos_unittest("distributed_input_inner_test") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp index f1ae4ca..9dc2b07 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -59,24 +59,6 @@ void DistributedInputInnerTest::TestUnprepareDInputCallback::OnResult( return; } -void DistributedInputInnerTest::TestStartDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - -void DistributedInputInnerTest::TestStopDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - void DistributedInputInnerTest::TestStartStopDInputCallback::OnResultDhids( const std::string &devId, const int32_t &status) { @@ -229,24 +211,6 @@ HWTEST_F(DistributedInputInnerTest, UnprepareRemoteInput04, testing::ext::TestSi EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputInnerTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StartRemoteInput01"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = - DistributedInputKit::StartRemoteInput(deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, StartRemoteInput02, testing::ext::TestSize.Level0) -{ - string deviceId = ""; - sptr callback = nullptr; - int32_t ret = - DistributedInputKit::StartRemoteInput(deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputInnerTest, StartRemoteInput03, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_sink"; @@ -265,26 +229,6 @@ HWTEST_F(DistributedInputInnerTest, StartRemoteInput04, testing::ext::TestSize.L EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputInnerTest, StartRemoteInput05, testing::ext::TestSize.Level0) -{ - string srcId = "StartRemoteInput01-src"; - string sinkId = "StartRemoteInput01-sink"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = - DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, StartRemoteInput06, testing::ext::TestSize.Level0) -{ - string srcId = ""; - string sinkId = ""; - sptr callback = nullptr; - int32_t ret = - DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputInnerTest, StartRemoteInput07, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -305,24 +249,6 @@ HWTEST_F(DistributedInputInnerTest, StartRemoteInput08, testing::ext::TestSize.L EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputInnerTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StopRemoteInput01"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = - DistributedInputKit::StopRemoteInput(deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, StopRemoteInput02, testing::ext::TestSize.Level0) -{ - string deviceId = ""; - sptr callback = nullptr; - int32_t ret = - DistributedInputKit::StopRemoteInput(deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputInnerTest, StopRemoteInput03, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_test"; @@ -341,26 +267,6 @@ HWTEST_F(DistributedInputInnerTest, StopRemoteInput04, testing::ext::TestSize.Le EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputInnerTest, StopRemoteInput05, testing::ext::TestSize.Level0) -{ - string srcId = "StopRemoteInput03-src"; - string sinkId = "StopRemoteInput03-sink"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = - DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, StopRemoteInput06, testing::ext::TestSize.Level0) -{ - string srcId = ""; - string sinkId = ""; - sptr callback = nullptr; - int32_t ret = - DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputInnerTest, StopRemoteInput07, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -438,13 +344,6 @@ HWTEST_F(DistributedInputInnerTest, IsTouchEventNeedFilterOut01, testing::ext::T EXPECT_EQ(false, ret); } -HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput01, testing::ext::TestSize.Level0) -{ - uint32_t flag = 1; - DInputServerType retFlag = DistributedInputKit::IsStartDistributedInput(flag); - EXPECT_EQ(DInputServerType::NULL_SERVER_TYPE, retFlag); -} - HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput02, testing::ext::TestSize.Level0) { std::string dhId = "IsStartDistributedInput02"; @@ -516,4 +415,4 @@ HWTEST_F(DistributedInputInnerTest, UnregisterSimulationEventListener02, testing } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h index a9ab92b..5606bf7 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h @@ -33,8 +33,6 @@ #include "i_distributed_source_input.h" #include "start_stop_d_inputs_call_back_stub.h" #include "prepare_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" #include "simulation_event_listener_stub.h" #include "unprepare_d_input_call_back_stub.h" @@ -66,22 +64,6 @@ public: void OnResult(const std::string &deviceId, const int32_t &status); }; - class TestStartDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestStartDInputCallback() = default; - virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - - class TestStopDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - class TestStartStopDInputCallback : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: diff --git a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp index 81a18cb..c7964e0 100644 --- a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp +++ b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp @@ -139,42 +139,18 @@ int32_t DistributedInputClient::UnprepareRemoteInput( return DH_SUCCESS; } -int32_t DistributedInputClient::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - int32_t DistributedInputClient::StartRemoteInput( const std::string &sinkId, const std::vector &dhIds, sptr callback) { return DH_SUCCESS; } -int32_t DistributedInputClient::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - int32_t DistributedInputClient::StopRemoteInput( const std::string &sinkId, const std::vector &dhIds, sptr callback) { return DH_SUCCESS; } -int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, sptr callback) { diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index c4449ec..245573d 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -66,18 +66,6 @@ public: int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback); - int32_t StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback); - - int32_t StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback); - - int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - - int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback); int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, @@ -183,7 +171,6 @@ private: static std::shared_ptr instance; DInputServerType serverType = DInputServerType::NULL_SERVER_TYPE; - DInputDeviceType inputTypes_ = DInputDeviceType::NONE; std::set> addWhiteListCallbacks_; std::set> delWhiteListCallbacks_; diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index 4824e30..d723e61 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -44,18 +44,6 @@ public: int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback) override; - int32_t StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) override; - - int32_t StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) override; - - int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) override; - - int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) override; - int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) override; diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 19d3aa2..5aa0bd9 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -42,10 +42,6 @@ private: int32_t HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply); int32_t HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply); - int32_t HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply); - int32_t HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply); - int32_t HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply); - int32_t HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/include/start_d_input_call_back_proxy.h b/interfaces/ipc/include/start_d_input_call_back_proxy.h deleted file mode 100644 index 7239628..0000000 --- a/interfaces/ipc/include/start_d_input_call_back_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021-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 START_D_INPUT_CALL_BACK_PROXY_H -#define START_D_INPUT_CALL_BACK_PROXY_H - -#include "i_start_d_input_call_back.h" - -#include - -#include "iremote_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class StartDInputCallbackProxy : public IRemoteProxy { -public: - explicit StartDInputCallbackProxy(const sptr &object); - ~StartDInputCallbackProxy() override; - - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // START_D_INPUT_CALL_BACK_PROXY_H diff --git a/interfaces/ipc/include/start_d_input_call_back_stub.h b/interfaces/ipc/include/start_d_input_call_back_stub.h index 7c3932a..7bdb50a 100644 --- a/interfaces/ipc/include/start_d_input_call_back_stub.h +++ b/interfaces/ipc/include/start_d_input_call_back_stub.h @@ -13,11 +13,6 @@ * limitations under the License. */ -#ifndef START_D_INPUT_CALL_BACK_STUB_H -#define START_D_INPUT_CALL_BACK_STUB_H - -#include "i_start_d_input_call_back.h" - #include #include "iremote_stub.h" @@ -39,4 +34,3 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // START_D_INPUT_CALL_BACK_STUB_H diff --git a/interfaces/ipc/include/stop_d_input_call_back_proxy.h b/interfaces/ipc/include/stop_d_input_call_back_proxy.h deleted file mode 100644 index 67def3c..0000000 --- a/interfaces/ipc/include/stop_d_input_call_back_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021-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 STOP_D_INPUT_CALL_BACK_PROXY_H -#define STOP_D_INPUT_CALL_BACK_PROXY_H - -#include "i_stop_d_input_call_back.h" - -#include - -#include "iremote_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class StopDInputCallbackProxy : public IRemoteProxy { -public: - explicit StopDInputCallbackProxy(const sptr &object); - ~StopDInputCallbackProxy() override; - - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // STOP_D_INPUT_CALL_BACK_PROXY_H diff --git a/interfaces/ipc/include/stop_d_input_call_back_stub.h b/interfaces/ipc/include/stop_d_input_call_back_stub.h index 3649a27..7794ea0 100644 --- a/interfaces/ipc/include/stop_d_input_call_back_stub.h +++ b/interfaces/ipc/include/stop_d_input_call_back_stub.h @@ -13,11 +13,6 @@ * limitations under the License. */ -#ifndef STOP_D_INPUT_CALL_BACK_STUB_H -#define STOP_D_INPUT_CALL_BACK_STUB_H - -#include "i_stop_d_input_call_back.h" - #include #include "iremote_stub.h" @@ -39,4 +34,3 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // STOP_D_INPUT_CALL_BACK_STUB_H diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 6c4107a..d61cf87 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -34,7 +34,7 @@ namespace DistributedHardware { namespace DistributedInput { std::shared_ptr DistributedInputClient::instance(new DistributedInputClient()); DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), - isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false), isGetSinkScreenInfosCbReg(false) + isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false) { DHLOGI("DistributedInputClient init start"); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); @@ -291,7 +291,6 @@ int32_t DistributedInputClient::ReleaseSource() } serverType = DInputServerType::NULL_SERVER_TYPE; - inputTypes_ = DInputDeviceType::NONE; regNodeListener_ = nullptr; unregNodeListener_ = nullptr; regSimulationEventListener_ = nullptr; @@ -311,7 +310,6 @@ int32_t DistributedInputClient::ReleaseSink() return ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL; } serverType = DInputServerType::NULL_SERVER_TYPE; - inputTypes_ = DInputDeviceType::NONE; { std::lock_guard lock(operationMutex_); getSinkScreenInfosCallbacks_.clear(); @@ -402,65 +400,6 @@ int32_t DistributedInputClient::UnprepareRemoteInput(const std::string &deviceId return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback); } -int32_t DistributedInputClient::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - DHLOGI("DinputStart called, deviceId: %s, inputTypes: %d.", GetAnonyString(deviceId).c_str(), inputTypes); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("DinputStart client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - if (!DInputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) { - return ERR_DH_INPUT_CLIENT_START_FAIL; - } - return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(deviceId, inputTypes, callback); -} - -int32_t DistributedInputClient::StopRemoteInput(const std::string &deviceId, const uint32_t &inputTypes, - sptr callback) -{ - DHLOGI("DinputStop called, deviceId: %s, inputTypes: %d.", GetAnonyString(deviceId).c_str(), inputTypes); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("DinputStop client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - if (!DInputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) { - return ERR_DH_INPUT_CLIENT_STOP_FAIL; - } - return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(deviceId, inputTypes, callback); -} - -int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - DHLOGI("DinputStart called, srcId: %s, sinkId: %s, inputTypes: %d.", GetAnonyString(srcId).c_str(), - GetAnonyString(sinkId).c_str(), inputTypes); - - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("DinputStart relay type client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) { - return ERR_DH_INPUT_CLIENT_START_FAIL; - } - return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, inputTypes, callback); -} - -int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - DHLOGI("DinputStop called, srcId: %s, sinkId: %s, inputTypes: %d.", GetAnonyString(srcId).c_str(), - GetAnonyString(sinkId).c_str(), inputTypes); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("DinputStop relay type client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) { - return ERR_DH_INPUT_CLIENT_STOP_FAIL; - } - return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, inputTypes, callback); -} - int32_t DistributedInputClient::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index 8bd4d5d..d2c8c6d 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -174,137 +174,7 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &dev } DHLOGE("UnprepareRemoteInput end, result=%d", result); return result; -} - -int32_t DistributedInputSourceProxy::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - DHLOGI("source proxy StartRemoteInput start"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteString(deviceId)) { - DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_REMOTE_INPUT), data, reply); - if (ret) { - result = reply.ReadInt32(); - } - DHLOGI("source proxy StartRemoteInput end, result:%d.", result); - return result; -} - -int32_t DistributedInputSourceProxy::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteString(deviceId)) { - DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT), data, reply); - if (ret) { - result = reply.ReadInt32(); } - return result; -} - -int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - DHLOGI("source proxy StartRemoteInput start"); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteString(srcId)) { - DHLOGE("DistributedInputSourceProxy write srcId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteString(sinkId)) { - DHLOGE("DistributedInputSourceProxy write sinkId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT), data, - reply); - if (ret) { - result = reply.ReadInt32(); - } - DHLOGI("source proxy StartRemoteInput end, result:%d.", result); - return result; -} - -int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteString(srcId)) { - DHLOGE("DistributedInputSourceProxy write srcId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteString(sinkId)) { - DHLOGE("DistributedInputSourceProxy write sinkId failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT), - data, reply); - if (ret) { - result = reply.ReadInt32(); - } - return result; -} int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 8afb6b8..27f181a 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -45,22 +45,10 @@ void DistributedInputSourceStub::RegRespFunMap() &DistributedInputSourceStub::HandlePrepareRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT)] = &DistributedInputSourceStub::HandleUnprepareRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::START_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStartRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStopRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStartRelayTypeRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStopRelayTypeRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT)] = &DistributedInputSourceStub::HandlePrepareRelayRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT)] = &DistributedInputSourceStub::HandleUnprepareRelayRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStartDhidRemoteInput; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleStopDhidRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT)] = &DistributedInputSourceStub::HandleStartRelayDhidRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT)] = @@ -226,92 +214,6 @@ int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &da return DH_SUCCESS; } -int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string deviceId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleStartRemoteInput failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = StartRemoteInput(deviceId, inputTypes, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleStartRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string deviceId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleStopRemoteInput failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = StopRemoteInput(deviceId, inputTypes, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleStopRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string srcId = data.ReadString(); - std::string sinkId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleStartRelayTypeRemoteInput failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleStartRelayTypeRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string srcId = data.ReadString(); - std::string sinkId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleStopRelayTypeRemoteInput failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleStopRelayTypeRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { diff --git a/interfaces/ipc/src/start_d_input_call_back_proxy.cpp b/interfaces/ipc/src/start_d_input_call_back_proxy.cpp deleted file mode 100644 index 7c06d7b..0000000 --- a/interfaces/ipc/src/start_d_input_call_back_proxy.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021-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 "start_d_input_call_back_proxy.h" - -#include "ipc_types.h" -#include "parcel.h" - -#include "dinput_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StartDInputCallbackProxy::StartDInputCallbackProxy(const sptr &object) - : IRemoteProxy(object) -{ -} - -StartDInputCallbackProxy::~StartDInputCallbackProxy() -{ -} - -void StartDInputCallbackProxy::OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) -{ - sptr remote = Remote(); - if (remote == nullptr) { - return; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("StartDInputCallbackProxy write token valid failed"); - return; - } - if (!data.WriteString(devId)) { - DHLOGE("StartDInputCallbackProxy write devId failed"); - return; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("StartDInputCallbackProxy write inputTypes failed"); - return; - } - if (!data.WriteInt32(status)) { - DHLOGE("StartDInputCallbackProxy write status failed"); - return; - } - int32_t ret = remote->SendRequest( - static_cast(IStartDInputCallback::Message::RESULT), data, reply, option); - if (ret != 0) { - return; - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/ipc/src/start_d_input_call_back_stub.cpp b/interfaces/ipc/src/start_d_input_call_back_stub.cpp deleted file mode 100644 index b9243b1..0000000 --- a/interfaces/ipc/src/start_d_input_call_back_stub.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "start_d_input_call_back_stub.h" - -#include "string_ex.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "dinput_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StartDInputCallbackStub::StartDInputCallbackStub() -{ -} - -StartDInputCallbackStub::~StartDInputCallbackStub() -{ -} - -int32_t StartDInputCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - DHLOGE("StartDInputCallbackStub read token valid failed"); - return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; - } - IStartDInputCallback::Message msgCode = static_cast(code); - switch (msgCode) { - case IStartDInputCallback::Message::RESULT: { - std::string deviceId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - int32_t status = data.ReadInt32(); - OnResult(deviceId, inputTypes, status); - break; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return DH_SUCCESS; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/ipc/src/stop_d_input_call_back_proxy.cpp b/interfaces/ipc/src/stop_d_input_call_back_proxy.cpp deleted file mode 100644 index 8657cd0..0000000 --- a/interfaces/ipc/src/stop_d_input_call_back_proxy.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021-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 "stop_d_input_call_back_proxy.h" - -#include "ipc_types.h" -#include "parcel.h" - -#include "dinput_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StopDInputCallbackProxy::StopDInputCallbackProxy(const sptr &object) - : IRemoteProxy(object) -{ -} - -StopDInputCallbackProxy::~StopDInputCallbackProxy() -{ -} - -void StopDInputCallbackProxy::OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) -{ - sptr remote = Remote(); - if (remote == nullptr) { - return; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("StopDInputCallbackProxy write token valid failed"); - return; - } - if (!data.WriteString(devId)) { - DHLOGE("StopDInputCallbackProxy write devId failed"); - return; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("StopDInputCallbackProxy write inputTypes failed"); - return; - } - if (!data.WriteInt32(status)) { - DHLOGE("StopDInputCallbackProxy write status failed"); - return; - } - int32_t ret = remote->SendRequest( - static_cast(IStopDInputCallback::Message::RESULT), data, reply, option); - if (ret != 0) { - return; - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/ipc/src/stop_d_input_call_back_stub.cpp b/interfaces/ipc/src/stop_d_input_call_back_stub.cpp deleted file mode 100644 index 64f8d5f..0000000 --- a/interfaces/ipc/src/stop_d_input_call_back_stub.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "stop_d_input_call_back_stub.h" - -#include "string_ex.h" - -#include "constants_dinput.h" -#include "dinput_errcode.h" -#include "dinput_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StopDInputCallbackStub::StopDInputCallbackStub() -{ -} - -StopDInputCallbackStub::~StopDInputCallbackStub() -{ -} - -int32_t StopDInputCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - DHLOGE("StopDInputCallbackStub read token valid failed"); - return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; - } - IStopDInputCallback::Message msgCode = static_cast(code); - switch (msgCode) { - case IStopDInputCallback::Message::RESULT: { - std::string deviceId = data.ReadString(); - uint32_t inputTypes = data.ReadUint32(); - int32_t status = data.ReadInt32(); - OnResult(deviceId, inputTypes, status); - break; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return DH_SUCCESS; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/BUILD.gn b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/BUILD.gn index a974bb9..2e18111 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/BUILD.gn +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/BUILD.gn @@ -61,14 +61,10 @@ ohos_unittest("add_white_list_infos_callbackl_test") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "add_white_list_infos_call_back_test.cpp", ] diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp index 6ffb823..5be8f25 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp @@ -122,13 +122,6 @@ int32_t AddWhiteListInfosCallbackTest::TestSimulationEventListenerStub::OnSimula value_ = value; return DH_SUCCESS; } -void AddWhiteListInfosCallbackTest::TestStartDInputCallbackStub::OnResult(const std::string &devId, - const uint32_t &inputTypes, const int32_t &status) -{ - devId_ = devId; - inputTypes_ = inputTypes; - status_ = status; -} void AddWhiteListInfosCallbackTest::TestStartStopDInputsCallbackStub::OnResultDhids(const std::string &devId, const int32_t &status) @@ -153,14 +146,6 @@ void AddWhiteListInfosCallbackTest::TestStartStopResultCallbackStub::OnStop(cons dhIds.swap(dhIds); } -void AddWhiteListInfosCallbackTest::TestStopDInputCallbackStub::OnResult(const std::string &devId, - const uint32_t &inputTypes, const int32_t &status) -{ - devId_ = devId; - inputTypes_ = inputTypes; - status_ = status; -} - int32_t AddWhiteListInfosCallbackTest::TestDistributedInputSinkStub::Init() { return DH_SUCCESS; @@ -298,17 +283,6 @@ HWTEST_F(AddWhiteListInfosCallbackTest, SimulationEventListenerStub01, testing:: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(AddWhiteListInfosCallbackTest, StartDInputCallbackStub01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestStartDInputCallbackStub()); - StartDInputCallbackProxy callBackProxy(callBackStubPtr); - std::string devId = "devId_test"; - uint32_t inputTypes = static_cast(DInputDeviceType::ALL); - int32_t status = 1; - callBackProxy.OnResult(devId, inputTypes, status); - EXPECT_STREQ(devId.c_str(), ((sptr &)callBackStubPtr)->devId_.c_str()); -} - HWTEST_F(AddWhiteListInfosCallbackTest, StartStopDInputsCallbackStub01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStartStopDInputsCallbackStub()); @@ -346,17 +320,6 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StartStopResultCallbackStub02, testing:: EXPECT_STREQ(sinkId.c_str(), ((sptr &)callBackStubPtr)->sinkId_.c_str()); } -HWTEST_F(AddWhiteListInfosCallbackTest, StopDInputCallbackStub01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestStopDInputCallbackStub()); - StopDInputCallbackProxy callBackProxy(callBackStubPtr); - std::string devId = "devId_test"; - uint32_t inputTypes = static_cast(DInputDeviceType::ALL); - int32_t status = 1; - callBackProxy.OnResult(devId, inputTypes, status); - EXPECT_STREQ(devId.c_str(), ((sptr &)callBackStubPtr)->devId_.c_str()); -} - HWTEST_F(AddWhiteListInfosCallbackTest, DistributedInputSinkStub01, testing::ext::TestSize.Level1) { sptr sinkStubPtr(new TestDistributedInputSinkStub()); @@ -385,4 +348,4 @@ HWTEST_F(AddWhiteListInfosCallbackTest, DistributedInputSinkStub01, testing::ext } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h index 624f12c..7722950 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h @@ -33,13 +33,11 @@ #include "simulation_event_listener_proxy.h" #include "simulation_event_listener_stub.h" #include "start_d_input_call_back_proxy.h" -#include "start_d_input_call_back_stub.h" #include "start_stop_d_inputs_call_back_proxy.h" #include "start_stop_d_inputs_call_back_stub.h" #include "start_stop_result_call_back_proxy.h" #include "start_stop_result_call_back_stub.h" #include "stop_d_input_call_back_proxy.h" -#include "stop_d_input_call_back_stub.h" #include "register_d_input_call_back_proxy.h" #include "register_d_input_call_back_stub.h" @@ -130,17 +128,6 @@ public: int32_t value_ = 0; }; - class TestStartDInputCallbackStub : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestStartDInputCallbackStub() = default; - virtual ~TestStartDInputCallbackStub() = default; - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status); - std::string devId_; - uint32_t inputTypes_ = 0; - int32_t status_ = 0; - }; - class TestStartStopDInputsCallbackStub : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: @@ -163,17 +150,6 @@ public: std::vector dhIds_; }; - class TestStopDInputCallbackStub : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallbackStub() = default; - virtual ~TestStopDInputCallbackStub() = default; - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status); - std::string devId_; - uint32_t inputTypes_ = 0; - int32_t status_ = 0; - }; - class TestDistributedInputSinkStub : public OHOS::DistributedHardware::DistributedInput::DistributedInputSinkStub { public: @@ -190,4 +166,4 @@ public: } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -#endif // ADD_WHITE_LIST_INFOS_CALLBACK_TEST_H \ No newline at end of file +#endif // ADD_WHITE_LIST_INFOS_CALLBACK_TEST_H diff --git a/interfaces/ipc/test/clientunittest/BUILD.gn b/interfaces/ipc/test/clientunittest/BUILD.gn index 4a838f5..c75f824 100644 --- a/interfaces/ipc/test/clientunittest/BUILD.gn +++ b/interfaces/ipc/test/clientunittest/BUILD.gn @@ -76,14 +76,10 @@ ohos_unittest("distributed_input_client_test") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp index d08527b..66c9407 100644 --- a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp +++ b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp @@ -97,24 +97,6 @@ void DistributedInputClientTest::TestUnprepareDInputCallback::OnResult( return; } -void DistributedInputClientTest::TestStartDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - -void DistributedInputClientTest::TestStopDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - void DistributedInputClientTest::TestStartStopDInputCallback::OnResultDhids( const std::string &devId, const int32_t &status) { @@ -261,24 +243,6 @@ HWTEST_F(DistributedInputClientTest, UnprepareRemoteInput04, testing::ext::TestS EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL, ret); } -HWTEST_F(DistributedInputClientTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StartRemoteInput01"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputClientTest, StartRemoteInput02, testing::ext::TestSize.Level0) -{ - string deviceId = ""; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); -} - HWTEST_F(DistributedInputClientTest, StartRemoteInput03, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_sink"; @@ -297,26 +261,6 @@ HWTEST_F(DistributedInputClientTest, StartRemoteInput04, testing::ext::TestSize. EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); } -HWTEST_F(DistributedInputClientTest, StartRemoteInput05, testing::ext::TestSize.Level0) -{ - string srcId = "StartRemoteInput01-src"; - string sinkId = "StartRemoteInput01-sink"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputClientTest, StartRemoteInput06, testing::ext::TestSize.Level0) -{ - string srcId = ""; - string sinkId = ""; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); -} - HWTEST_F(DistributedInputClientTest, StartRemoteInput07, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -337,24 +281,6 @@ HWTEST_F(DistributedInputClientTest, StartRemoteInput08, testing::ext::TestSize. EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); } -HWTEST_F(DistributedInputClientTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StopRemoteInput01"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputClientTest, StopRemoteInput02, testing::ext::TestSize.Level0) -{ - string deviceId = ""; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); -} - HWTEST_F(DistributedInputClientTest, StopRemoteInput03, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_test"; @@ -373,26 +299,6 @@ HWTEST_F(DistributedInputClientTest, StopRemoteInput04, testing::ext::TestSize.L EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); } -HWTEST_F(DistributedInputClientTest, StopRemoteInput05, testing::ext::TestSize.Level0) -{ - string srcId = "StopRemoteInput03-src"; - string sinkId = "StopRemoteInput03-sink"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputClientTest, StopRemoteInput06, testing::ext::TestSize.Level0) -{ - string srcId = ""; - string sinkId = ""; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); -} - HWTEST_F(DistributedInputClientTest, StopRemoteInput07, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -469,4 +375,4 @@ HWTEST_F(DistributedInputClientTest, ProcessEvent04, testing::ext::TestSize.Leve } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.h b/interfaces/ipc/test/clientunittest/distributed_input_client_test.h index 09c674b..1b4476f 100644 --- a/interfaces/ipc/test/clientunittest/distributed_input_client_test.h +++ b/interfaces/ipc/test/clientunittest/distributed_input_client_test.h @@ -30,8 +30,6 @@ #include "simulation_event_listener_stub.h" #include "start_stop_d_inputs_call_back_stub.h" #include "prepare_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" #include "simulation_event_listener_stub.h" #include "unprepare_d_input_call_back_stub.h" @@ -77,22 +75,6 @@ public: void OnResult(const std::string &deviceId, const int32_t &status); }; - class TestStartDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestStartDInputCallback() = default; - virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - - class TestStopDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - class TestStartStopDInputCallback : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn b/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn index df58c62..828061e 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn @@ -59,12 +59,8 @@ ohos_unittest("dinput_source_callback_test") { "${ipc_path}/src/register_d_input_call_back_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index 30a8de3..c5260fa 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -106,47 +106,6 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnprepareRemoteI (void)deviceId; (void)callback; return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - (void)deviceId; - (void)inputTypes; - (void)callback; - return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - (void)deviceId; - (void)inputTypes; - (void)callback; - return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( - const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) -{ - (void)srcId; - (void)sinkId; - (void)inputTypes; - (void)callback; - return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( - const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) -{ - (void)srcId; - (void)sinkId; - (void)inputTypes; - (void)callback; - return DH_SUCCESS; -} int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::PrepareRemoteInput( const std::string &srcId, const std::string &sinkId, @@ -315,24 +274,6 @@ void DInputSourceCallBackTest::TestDInputUnprepareCallBack::OnResult( return; } -void DInputSourceCallBackTest::TestDInputStartCallBack::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - -void DInputSourceCallBackTest::TestDInputStopCallBack::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - void DInputSourceCallBackTest::TestVectorStartStopCallBackStub::OnResultDhids(const std::string &devId, const int32_t &status) { @@ -476,29 +417,6 @@ HWTEST_F(DInputSourceCallBackTest, UnprepareRemoteInput02, testing::ext::TestSiz EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DInputSourceCallBackTest, StartRemoteInput01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - const std::string devId = "d6f4s6d4f6"; - uint32_t inputTypes = 1; - sptr callback(new TestDInputStartCallBack()); - int32_t ret = callBackProxy.StartRemoteInput(devId, inputTypes, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DInputSourceCallBackTest, StartRemoteInput02, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - const std::string srcId = "d6f4s6d4f6"; - const std::string sinkId = "5sd45s4d5s4d5"; - uint32_t inputTypes = 1; - sptr callback(new TestDInputStartCallBack()); - int32_t ret = callBackProxy.StartRemoteInput(srcId, sinkId, inputTypes, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DInputSourceCallBackTest, StartRemoteInput03, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestDInputSourceCallBackStub()); @@ -524,29 +442,6 @@ HWTEST_F(DInputSourceCallBackTest, StartRemoteInput04, testing::ext::TestSize.Le EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DInputSourceCallBackTest, StopRemoteInput01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - const std::string devId = "d6f4s6d4f6"; - uint32_t inputTypes = 1; - sptr callback(new TestDInputStopCallBack()); - int32_t ret = callBackProxy.StopRemoteInput(devId, inputTypes, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DInputSourceCallBackTest, StopRemoteInput02, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - const std::string srcId = "d6f4s6d4f6"; - const std::string sinkId = "5sd45s4d5s4d5"; - uint32_t inputTypes = 1; - sptr callback(new TestDInputStopCallBack()); - int32_t ret = callBackProxy.StopRemoteInput(srcId, sinkId, inputTypes, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DInputSourceCallBackTest, StopRemoteInput03, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestDInputSourceCallBackStub()); @@ -638,4 +533,4 @@ HWTEST_F(DInputSourceCallBackTest, UnregisterSimulationEventListener01, testing: } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h index 115babd..b86bca1 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h @@ -26,8 +26,6 @@ #include "input_node_listener_stub.h" #include "prepare_d_input_call_back_stub.h" #include "register_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" #include "unprepare_d_input_call_back_stub.h" #include "unregister_d_input_call_back_stub.h" #include "start_stop_d_inputs_call_back_stub.h" @@ -66,18 +64,6 @@ public: int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback); - int32_t StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback); - - int32_t StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback); - - int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - - int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback); - int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback); @@ -144,22 +130,6 @@ public: void OnResult(const std::string &deviceId, const int32_t &status); }; - class TestDInputStartCallBack : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestDInputStartCallBack() = default; - virtual ~TestDInputStartCallBack() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - - class TestDInputStopCallBack : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestDInputStopCallBack() = default; - virtual ~TestDInputStopCallBack() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - class TestVectorStartStopCallBackStub : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: @@ -207,4 +177,4 @@ public: } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -#endif // DINPUT_SOURCE_CALLBACK_TEST_H \ No newline at end of file +#endif // DINPUT_SOURCE_CALLBACK_TEST_H diff --git a/interfaces/ipc/test/ipcunittest/BUILD.gn b/interfaces/ipc/test/ipcunittest/BUILD.gn index 8314577..cb225fa 100644 --- a/interfaces/ipc/test/ipcunittest/BUILD.gn +++ b/interfaces/ipc/test/ipcunittest/BUILD.gn @@ -68,14 +68,10 @@ ohos_unittest("distributed_input_ipc_test") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp index 12b00e0..0f0f6c7 100644 --- a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp +++ b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp @@ -381,15 +381,6 @@ HWTEST_F(DistributedInputIpcTest, UnprepareRemoteInput01, testing::ext::TestSize EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); } -HWTEST_F(DistributedInputIpcTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StartRemoteInput01"; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - HWTEST_F(DistributedInputIpcTest, StartRemoteInput02, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_sink"; @@ -399,16 +390,6 @@ HWTEST_F(DistributedInputIpcTest, StartRemoteInput02, testing::ext::TestSize.Lev EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); } -HWTEST_F(DistributedInputIpcTest, StartRemoteInput03, testing::ext::TestSize.Level0) -{ - string srcId = "StartRemoteInput01-src"; - string sinkId = "StartRemoteInput01-sink"; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - HWTEST_F(DistributedInputIpcTest, StartRemoteInput04, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -419,15 +400,6 @@ HWTEST_F(DistributedInputIpcTest, StartRemoteInput04, testing::ext::TestSize.Lev EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); } -HWTEST_F(DistributedInputIpcTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - string deviceId = "StopRemoteInput01"; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - HWTEST_F(DistributedInputIpcTest, StopRemoteInput02, testing::ext::TestSize.Level0) { std::string sinkId = "StartRemoteInput_test"; @@ -437,16 +409,6 @@ HWTEST_F(DistributedInputIpcTest, StopRemoteInput02, testing::ext::TestSize.Leve EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); } -HWTEST_F(DistributedInputIpcTest, StopRemoteInput03, testing::ext::TestSize.Level0) -{ - string srcId = "StopRemoteInput03-src"; - string sinkId = "StopRemoteInput03-sink"; - sptr callback = nullptr; - int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( - srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - HWTEST_F(DistributedInputIpcTest, StopRemoteInput04, testing::ext::TestSize.Level0) { string srcId = "StartRemoteInput01-src"; @@ -459,4 +421,4 @@ HWTEST_F(DistributedInputIpcTest, StopRemoteInput04, testing::ext::TestSize.Leve } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/common/include/dinput_sink_manager_callback.h b/services/common/include/dinput_sink_manager_callback.h index 8a38ff0..0d436cf 100644 --- a/services/common/include/dinput_sink_manager_callback.h +++ b/services/common/include/dinput_sink_manager_callback.h @@ -27,6 +27,6 @@ public: }; } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS52222 +} // namespace OHOS #endif // DISTRIBUTED_SINK_MANAGER_CALLBACK_H diff --git a/services/common/include/dinput_sink_trans_callback.h b/services/common/include/dinput_sink_trans_callback.h index d31e250..f194960 100644 --- a/services/common/include/dinput_sink_trans_callback.h +++ b/services/common/include/dinput_sink_trans_callback.h @@ -25,8 +25,6 @@ class DInputSinkTransCallback { public: virtual void OnPrepareRemoteInput(const int32_t &sessionId, const std::string &deviceId) = 0; virtual void OnUnprepareRemoteInput(const int32_t &sessionId) = 0; - virtual void OnStartRemoteInput(const int32_t &sessionId, const uint32_t &inputTypes) = 0; - virtual void OnStopRemoteInput(const int32_t &sessionId, const uint32_t &inputTypes) = 0; virtual void OnStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) = 0; virtual void OnStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) = 0; @@ -38,10 +36,6 @@ public: const std::string &deviceId, const std::string &strDhids) = 0; virtual void OnRelayStopDhidRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, const std::string &deviceId, const std::string &strDhids) = 0; - virtual void OnRelayStartTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, - const std::string &deviceId, uint32_t inputTypes) = 0; - virtual void OnRelayStopTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, - const std::string &deviceId, uint32_t inputTypes) = 0; virtual ~DInputSinkTransCallback() {} }; } // namespace DistributedInput diff --git a/services/common/include/dinput_softbus_define.h b/services/common/include/dinput_softbus_define.h index 2583ca2..6e7140a 100644 --- a/services/common/include/dinput_softbus_define.h +++ b/services/common/include/dinput_softbus_define.h @@ -48,7 +48,6 @@ namespace DistributedInput { #define DINPUT_SOFTBUS_KEY_CMD_TYPE "dinput_softbus_key_cmd_type" #define DINPUT_SOFTBUS_KEY_DEVICE_ID "dinput_softbus_key_device_id" #define DINPUT_SOFTBUS_KEY_SESSION_ID "dinput_softbus_key_session_id" - #define DINPUT_SOFTBUS_KEY_INPUT_TYPE "dinput_softbus_key_input_type" #define DINPUT_SOFTBUS_KEY_VECTOR_DHID "dinput_softbus_key_vector_dhid" #define DINPUT_SOFTBUS_KEY_RESP_VALUE "dinput_softbus_key_resp_value" #define DINPUT_SOFTBUS_KEY_WHITE_LIST "dinput_softbus_key_list_list" diff --git a/services/common/include/dinput_source_trans_callback.h b/services/common/include/dinput_source_trans_callback.h index 58a6487..33213c0 100644 --- a/services/common/include/dinput_source_trans_callback.h +++ b/services/common/include/dinput_source_trans_callback.h @@ -27,8 +27,6 @@ public: bool result) = 0; virtual void OnResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) = 0; virtual void OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) = 0; - virtual void OnResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0; - virtual void OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) = 0; virtual void OnResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0; virtual void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0; virtual void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type, @@ -45,10 +43,6 @@ public: const std::string &dhids) = 0; virtual void OnReceiveRelayStopDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId, const std::string &dhids) = 0; - virtual void OnReceiveRelayStartTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, - uint32_t inputTypes) = 0; - virtual void OnReceiveRelayStopTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId, - uint32_t inputTypes) = 0; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 5d49ef5..9787b60 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -43,7 +43,6 @@ public: void PreInit(); int32_t Init(std::shared_ptr sinkHandler); void Release(); - AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType); AffectDhIds SetSharingDhIds(bool enabled, std::vector dhIds); void GetMouseNodePath(const std::vector &dhIds, std::string &mouseNodePath, std::string &dhid); void GetSharedKeyboardPathsByDhIds(const std::vector &dhIds, @@ -52,7 +51,6 @@ public: bool IsAllDevicesStoped(); int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener); void ReportDhIdSharingState(const AffectDhIds &dhIds); - void GetDeviceInfoByType(const uint32_t inputTypes, std::map &deviceInfo); void ResetSpecEventStatus(); private: @@ -70,7 +68,6 @@ private: bool isStartGetDeviceHandlerThread; std::unique_ptr inputHub_; std::shared_ptr sinkHandler_; - uint32_t inputTypes_; std::mutex sharingDhIdListenerMtx_; std::set> sharingDhIdListeners_; @@ -79,4 +76,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // DISTRIBUTED_INPUT_COLLECTOR_H \ No newline at end of file +#endif // DISTRIBUTED_INPUT_COLLECTOR_H diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 52015c0..e5e8507 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -37,7 +37,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { DistributedInputCollector::DistributedInputCollector() : mEventBuffer{}, collectThreadID_(-1), - isCollectingEvents_(false), isStartGetDeviceHandlerThread(false), inputTypes_(0) + isCollectingEvents_(false), isStartGetDeviceHandlerThread(false) { inputHub_ = std::make_unique(); } @@ -163,23 +163,6 @@ void DistributedInputCollector::StopCollectEventsThread() DHLOGW("DistributedInputCollector::StopCollectEventsThread exit!"); } -AffectDhIds DistributedInputCollector::SetSharingTypes(bool enabled, const uint32_t &inputType) -{ - inputTypes_ = 0; - if ((inputType & static_cast(DInputDeviceType::MOUSE)) != 0 || - (inputType & static_cast(DInputDeviceType::TOUCHPAD)) != 0) { - inputTypes_ |= INPUT_DEVICE_CLASS_CURSOR; - } - if ((inputType & static_cast(DInputDeviceType::KEYBOARD)) != 0) { - inputTypes_ |= INPUT_DEVICE_CLASS_KEYBOARD; - } - if ((inputType & static_cast(DInputDeviceType::TOUCHSCREEN)) != 0) { - inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT | INPUT_DEVICE_CLASS_TOUCH; - } - - return inputHub_->SetSupportInputType(enabled, inputTypes_); -} - void DistributedInputCollector::ReportDhIdSharingState(const AffectDhIds &dhIds) { std::lock_guard lock(sharingDhIdListenerMtx_); @@ -249,16 +232,6 @@ int32_t DistributedInputCollector::RegisterSharingDhIdListener(sptr &deviceInfo) -{ - if (inputHub_ == nullptr) { - DHLOGE("inputHub is nullptr!"); - return; - } - inputHub_->GetDevicesInfoByType(inputTypes, deviceInfo); -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp index 6568284..fe31fc7 100644 --- a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp +++ b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp @@ -67,51 +67,6 @@ HWTEST_F(DistributedInputCollectorTest, Init02, testing::ext::TestSize.Level1) int32_t ret = DistributedInputCollector::GetInstance().Init(eventHandler_); EXPECT_EQ(DH_SUCCESS, ret); } - -HWTEST_F(DistributedInputCollectorTest, IsAllDevicesStoped01, testing::ext::TestSize.Level1) -{ - uint32_t inputTypes = 1; - std::map deviceInfo; - std::vector dhIds; - std::string mouseNodePath = "mouseNodePath_test"; - std::string dhid = "dhid_test"; - DistributedInputCollector::GetInstance().GetDeviceInfoByType(inputTypes, deviceInfo); - DistributedInputCollector::GetInstance().GetMouseNodePath(dhIds, mouseNodePath, dhid); - bool isStop = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); - EXPECT_EQ(true, isStop); -} - -HWTEST_F(DistributedInputCollectorTest, IsAllDevicesStoped02, testing::ext::TestSize.Level1) -{ - DistributedInputCollector::GetInstance().inputHub_ = nullptr; - uint32_t inputTypes = 1; - std::map deviceInfo; - std::vector dhIds; - std::string mouseNodePath = "mouseNodePath_test"; - std::string dhid = "dhid_test"; - DistributedInputCollector::GetInstance().GetDeviceInfoByType(inputTypes, deviceInfo); - DistributedInputCollector::GetInstance().GetMouseNodePath(dhIds, mouseNodePath, dhid); - bool isStop = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); - EXPECT_EQ(false, isStop); -} - -HWTEST_F(DistributedInputCollectorTest, SetSharingTypes01, testing::ext::TestSize.Level1) -{ - DistributedInputCollector::GetInstance().inputHub_ = std::make_unique(); - bool enabled = true; - uint32_t inputType = static_cast(DInputDeviceType::ALL); - - AffectDhIds ret = DistributedInputCollector::GetInstance().SetSharingTypes(enabled, inputType); - EXPECT_EQ(0, ret.sharingDhIds.size()); - std::vector sharingDhIds; - sharingDhIds.push_back("sharingDhId_test"); - std::vector noSharingDhIds; - noSharingDhIds.push_back("noSharingDhId_test"); - AffectDhIds affectDhIds {sharingDhIds, noSharingDhIds}; - DistributedInputCollector::GetInstance().ReportDhIdSharingState(affectDhIds); - DistributedInputCollector::GetInstance().sharingDhIdListeners_.clear(); - DistributedInputCollector::GetInstance().ReportDhIdSharingState(affectDhIds); -} } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/sink/sinkmanager/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h index f51a6d7..e4f70b2 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -69,8 +69,6 @@ public: ~DInputSinkListener() override; void OnPrepareRemoteInput(const int32_t &sessionId, const std::string &deviceId) override; void OnUnprepareRemoteInput(const int32_t &sessionId) override; - void OnStartRemoteInput(const int32_t &sessionId, const uint32_t &inputTypes) override; - void OnStopRemoteInput(const int32_t &sessionId, const uint32_t &inputTypes) override; void OnStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) override; void OnStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) override; @@ -82,10 +80,6 @@ public: const std::string &deviceId, const std::string &strDhids) override; void OnRelayStopDhidRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, const std::string &deviceId, const std::string &strDhids) override; - void OnRelayStartTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, - const std::string &deviceId, uint32_t inputTypes) override; - void OnRelayStopTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, - const std::string &deviceId, uint32_t inputTypes) override; private: DistributedInputSinkManager *sinkManagerObj_; @@ -139,9 +133,6 @@ public: void SetStartTransFlag(const DInputServerType flag); - uint32_t GetInputTypes(); - - void SetInputTypes(const uint32_t &inputTypes); /* * GetEventHandler, get the ui_service manager service's handler. @@ -177,7 +168,6 @@ private: std::shared_ptr handler_; std::mutex mutex_; bool InitAuto(); - DInputDeviceType inputTypes_; sptr projectWindowListener_ = nullptr; std::set sharingDhIds_; std::map> sharingDhIdsMap_; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 34b08a5..bf82e65 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -22,6 +22,7 @@ #include #include "dinput_softbus_define.h" +#include "dinput_state.h" #include "distributed_hardware_fwk_kit.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -51,7 +52,6 @@ DistributedInputSinkManager::DistributedInputSinkManager(int32_t saId, bool runO : SystemAbility(saId, runOnCreate) { DHLOGI("DistributedInputSinkManager ctor!"); - inputTypes_ = DInputDeviceType::NONE; } DistributedInputSinkManager::~DistributedInputSinkManager() @@ -85,13 +85,11 @@ void DistributedInputSinkManager::DInputSinkMgrListener::ResetSinkMgrResStatus() DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedInputSinkManager *manager) { sinkManagerObj_ = manager; - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); DHLOGI("DInputSinkListener init."); } DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener() { - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); sinkManagerObj_ = nullptr; DHLOGI("DInputSinkListener destory."); } @@ -153,14 +151,34 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput( void DistributedInputSinkManager::DInputSinkListener::OnUnprepareRemoteInput(const int32_t &sessionId) { DHLOGI("OnUnprepareRemoteInput called, sessionId: %d", sessionId); - OnStopRemoteInput(sessionId, static_cast(DInputDeviceType::ALL)); - DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); + std::string Dhids; + std::map dhIdStateMap = DInputState::GetInstance().GetGhIdStateMap(); + if (!dhIdStateMap.empty()) + { + for (auto it : dhIdStateMap) + { + if (it.second == DhIdState::THROUGH_OUT) + { + Dhids.append(it.first); + Dhids.append("."); + } + } + if (!Dhids.empty()) + { + Dhids.pop_back(); + } + DHLOGI("GetGhIdStateMap success: %d", GetAnonyString(Dhids).c_str()); + OnStopRemoteInputDhid(sessionId, Dhids); + DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONUNPREPARE; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - std::string smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONUNPREPARE; + jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; + std::string smsg = jsonStr.dump(); + DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg); + } + DHLOGE("GetGhIdStateMap error."); + return; } void DistributedInputSinkManager::DInputSinkListener::OnRelayPrepareRemoteInput(const int32_t &toSrcSessionId, @@ -195,7 +213,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu { DHLOGI("OnRelayUnprepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId, GetAnonyString(deviceId).c_str()); - DistributedInputCollector::GetInstance().SetSharingTypes(false, static_cast(DInputDeviceType::ALL)); DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId); @@ -207,79 +224,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(toSinkSessionId, smsg); } -void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput( - const int32_t &sessionId, const uint32_t &inputTypes) -{ - DHLOGI("OnStartRemoteInput called, sessionId: %d, inputTypes: %u.", sessionId, inputTypes); - // set new session - int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - - sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE - : DInputServerType::NULL_SERVER_TYPE); - - bool result = (startRes == DH_SUCCESS); - nlohmann::json jsonStrSta; - jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTART; - jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result; - std::string smsg = jsonStrSta.dump(); - DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg); - - if (startRes == DH_SUCCESS) { - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes); - AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(true, - sinkManagerObj_->GetInputTypes()); - sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds); - DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds); - } - - bool isMouse = (sinkManagerObj_->GetInputTypes() & static_cast(DInputDeviceType::MOUSE)) != 0; - if (isMouse) { - std::map deviceInfos; - DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast(DInputDeviceType::MOUSE), - deviceInfos); - for (const auto &deviceInfo : deviceInfos) { - DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str()); - std::vector devDhIds; - SplitStringToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, devDhIds); - DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, sessionId); - } - } -} - -void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInput( - const int32_t &sessionId, const uint32_t &inputTypes) -{ - DHLOGI("OnStopRemoteInput called, sessionId: %d, inputTypes: %d, curInputTypes: %d", - sessionId, inputTypes, sinkManagerObj_->GetInputTypes()); - - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - - (sinkManagerObj_->GetInputTypes() & inputTypes)); - AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(false, inputTypes); - std::vector stopIndeedDhIds; - sinkManagerObj_->DeleteStopDhids(sessionId, affDhIds.noSharingDhIds, stopIndeedDhIds); - AffectDhIds stopIndeedOnes; - stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; - DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - std::string smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - - bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); - if (isAllClosed) { - DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); - if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == - ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { - DHLOGI("all session is stop."); - sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - } - } -} - void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) { @@ -338,7 +282,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); if (isAllClosed) { DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { DHLOGI("all session is stop."); @@ -403,93 +346,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput std::string smsg = jsonStr.dump(); DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(toSinkSessionId, smsg); - bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); - if (!isAllClosed) { - DHLOGE("Not all devices are stopped."); - return; - } - DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); - if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == - ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { - DHLOGI("All session is stop."); - sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - } -} - -void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInput(const int32_t &toSrcSessionId, - const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes) -{ - DHLOGI("OnRelayStartTypeRemoteInput called, toSinkSessionId: %d", toSinkSessionId); - // set new session - int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId); - - sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE - : DInputServerType::NULL_SERVER_TYPE); - bool result = (startRes == DH_SUCCESS); - nlohmann::json jsonStrSta; - jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_STARTTYPE; - jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result; - jsonStrSta[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId; - std::string smsg = jsonStrSta.dump(); - DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(toSinkSessionId, smsg); - - if (startRes != DH_SUCCESS) { - DHLOGE("OnRelayStartTypeRemoteInput startSwitch error."); - return; - } - - if (sinkManagerObj_->GetEventHandler() == nullptr) { - DHLOGE("eventhandler is null."); - return; - } - - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes); - AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(true, - sinkManagerObj_->GetInputTypes()); - sinkManagerObj_->StoreStartDhids(toSinkSessionId, affDhIds.sharingDhIds); - DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds); - - bool isMouse = (sinkManagerObj_->GetInputTypes() & static_cast(DInputDeviceType::MOUSE)) != 0; - if (!isMouse) { - DHLOGE("No mouse type."); - return; - } - std::map deviceInfos; - DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast(DInputDeviceType::MOUSE), - deviceInfos); - for (auto deviceInfo : deviceInfos) { - DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str()); - std::vector devDhIds; - SplitStringToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, devDhIds); - DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, toSinkSessionId); - } -} - -void DistributedInputSinkManager::DInputSinkListener::OnRelayStopTypeRemoteInput(const int32_t &toSrcSessionId, - const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes) -{ - DHLOGI("OnRelayStopTypeRemoteInput called, sessionId: %d, inputTypes: %d, curInputTypes: %d", - toSinkSessionId, inputTypes, sinkManagerObj_->GetInputTypes()); - - sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - - (sinkManagerObj_->GetInputTypes() & inputTypes)); - AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingTypes(false, inputTypes); - std::vector stopIndeedDhIds; - sinkManagerObj_->DeleteStopDhids(toSinkSessionId, affDhIds.noSharingDhIds, stopIndeedDhIds); - AffectDhIds stopIndeedOnes; - stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; - DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_STOPTYPE; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId; - std::string smsg = jsonStr.dump(); - DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(toSinkSessionId, smsg); - bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); if (!isAllClosed) { DHLOGE("Not all devices are stopped."); @@ -729,16 +585,6 @@ void DistributedInputSinkManager::SetStartTransFlag(const DInputServerType flag) isStartTrans_ = flag; } -uint32_t DistributedInputSinkManager::GetInputTypes() -{ - return static_cast(inputTypes_); -} - -void DistributedInputSinkManager::SetInputTypes(const uint32_t &inputTypes) -{ - inputTypes_ = static_cast(inputTypes); -} - DistributedInputSinkManager::ProjectWindowListener::ProjectWindowListener(DistributedInputSinkManager *manager) { DHLOGI("ProjectWindowListener ctor!"); diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp index 3e61341..5783c87 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp @@ -117,14 +117,6 @@ HWTEST_F(DistributedInputSinkManagerTest, GetStartTransFlag, testing::ext::TestS EXPECT_EQ(flag, retFlag); } -HWTEST_F(DistributedInputSinkManagerTest, GetInputTypes, testing::ext::TestSize.Level0) -{ - uint32_t inputTypes = static_cast(DInputDeviceType::MOUSE); - sinkManager_->SetInputTypes(inputTypes); - uint32_t retType = sinkManager_->GetInputTypes(); - EXPECT_EQ(inputTypes, retType); -} - HWTEST_F(DistributedInputSinkManagerTest, IsStopDhidOnCmdStillNeed01, testing::ext::TestSize.Level0) { int32_t sessionId = 1; @@ -323,4 +315,4 @@ HWTEST_F(DistributedInputSinkManagerTest, Dump_01, testing::ext::TestSize.Level1 } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/sink/transport/include/distributed_input_sink_transport.h b/services/sink/transport/include/distributed_input_sink_transport.h index e948a1c..00db596 100644 --- a/services/sink/transport/include/distributed_input_sink_transport.h +++ b/services/sink/transport/include/distributed_input_sink_transport.h @@ -79,8 +79,6 @@ private: void RegRespFunMap(); void NotifyPrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyLatency(int32_t sessionId, const nlohmann::json &recMsg); void NotifyStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); void NotifyStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); @@ -89,8 +87,6 @@ private: void NotifyRelayUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyRelayStartDhidRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyRelayStopDhidRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyRelayStartTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyRelayStopTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void RecordEventLog(const std::string &dhId, int32_t type, int32_t code, int32_t value); private: diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index af2aefb..9905d50 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -290,33 +290,6 @@ void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t sessionId callback_->OnUnprepareRemoteInput(sessionId); } -void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START_TYPE deviceId:%s inputTypes:%d .", - GetAnonyString(deviceId).c_str(), inputTypes); - callback_->OnStartRemoteInput(sessionId, inputTypes); -} - -void DistributedInputSinkTransport::NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE deviceId:%s.", GetAnonyString(deviceId).c_str()); - callback_->OnStopRemoteInput(sessionId, inputTypes); -} - void DistributedInputSinkTransport::NotifyLatency(int32_t sessionId, const nlohmann::json &recMsg) { if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID)) { @@ -419,38 +392,6 @@ void DistributedInputSinkTransport::NotifyRelayStopDhidRemoteInput(int32_t sessi callback_->OnRelayStopDhidRemoteInput(toSrcSessionId, sessionId, deviceId, dhids); } -void DistributedInputSinkTransport::NotifyRelayStartTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_SESSION_ID) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - int32_t toSrcSessionId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_TYPE_FOR_REL deviceId:%s.", - GetAnonyString(deviceId).c_str()); - callback_->OnRelayStartTypeRemoteInput(toSrcSessionId, sessionId, deviceId, inputTypes); -} - -void DistributedInputSinkTransport::NotifyRelayStopTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_SESSION_ID) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - int32_t toSrcSessionId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL deviceId:%s.", - GetAnonyString(deviceId).c_str()); - callback_->OnRelayStopTypeRemoteInput(toSrcSessionId, sessionId, deviceId, inputTypes); -} - void DistributedInputSinkTransport::DInputTransbaseSinkListener::NotifySessionClosed(int32_t sessionId) { DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); @@ -466,8 +407,6 @@ void DistributedInputSinkTransport::RegRespFunMap() { memberFuncMap_[TRANS_SOURCE_MSG_PREPARE] = &DistributedInputSinkTransport::NotifyPrepareRemoteInput; memberFuncMap_[TRANS_SOURCE_MSG_UNPREPARE] = &DistributedInputSinkTransport::NotifyUnprepareRemoteInput; - memberFuncMap_[TRANS_SOURCE_MSG_START_TYPE] = &DistributedInputSinkTransport::NotifyStartRemoteInput; - memberFuncMap_[TRANS_SOURCE_MSG_STOP_TYPE] = &DistributedInputSinkTransport::NotifyStopRemoteInput; memberFuncMap_[TRANS_SOURCE_MSG_LATENCY] = &DistributedInputSinkTransport::NotifyLatency; memberFuncMap_[TRANS_SOURCE_MSG_START_DHID] = &DistributedInputSinkTransport::NotifyStartRemoteInputDhid; memberFuncMap_[TRANS_SOURCE_MSG_STOP_DHID] = &DistributedInputSinkTransport::NotifyStopRemoteInputDhid; @@ -478,10 +417,6 @@ void DistributedInputSinkTransport::RegRespFunMap() &DistributedInputSinkTransport::NotifyRelayStartDhidRemoteInput; memberFuncMap_[TRANS_SOURCE_MSG_STOP_DHID_FOR_REL] = &DistributedInputSinkTransport::NotifyRelayStopDhidRemoteInput; - memberFuncMap_[TRANS_SOURCE_MSG_START_TYPE_FOR_REL] = - &DistributedInputSinkTransport::NotifyRelayStartTypeRemoteInput; - memberFuncMap_[TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL] = - &DistributedInputSinkTransport::NotifyRelayStopTypeRemoteInput; } void DistributedInputSinkTransport::HandleData(int32_t sessionId, const std::string &message) diff --git a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp index 6bfa882..560082b 100644 --- a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp +++ b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp @@ -30,13 +30,11 @@ namespace { const int32_t SESSIONID = 1; const int32_t INT_DEVID = 1000; const int32_t INT_VECTORDHIDS = 123; - const uint32_t INPUTTYPE = static_cast(DInputDeviceType::ALL); const std::string DEVID = "umkyu1b165e1be98151891erbe8r91ev"; const std::string DHID = "Input_1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; const std::string SINKID = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; const std::string VECTORDHIDS = "Input_1ds56v18e1v21v8v1erv15r1v8r1j1ty8.Input_145adssphjknnk5877df"; const std::string STR_SESSIONID = "100"; - const std::string STR_INPUTTYPE = "111"; const std::string SOFTBUSCMDTYPE = "softbus_cmd_type"; } @@ -181,15 +179,11 @@ HWTEST_F(DistributedInputSinkTransTest, RespStartRemoteInput01, testing::ext::Te DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); jsonStr11_[DINPUT_SOFTBUS_KEY_SESSION_ID] = STR_SESSIONID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); - jsonStr11_[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = STR_INPUTTYPE; - DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); jsonStr11_[DINPUT_SOFTBUS_KEY_DEVICE_ID] = DEVID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); jsonStr11_[DINPUT_SOFTBUS_KEY_SESSION_ID] = SESSIONID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); - jsonStr11_[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = INPUTTYPE; - DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); jsonStr10_[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_DHID_FOR_REL; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr10_.dump()); @@ -264,15 +258,11 @@ HWTEST_F(DistributedInputSinkTransTest, RespStopRemoteInput01, testing::ext::Tes DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); jsonStr12_[DINPUT_SOFTBUS_KEY_SESSION_ID] = STR_SESSIONID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); - jsonStr12_[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = STR_INPUTTYPE; - DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); jsonStr12_[DINPUT_SOFTBUS_KEY_DEVICE_ID] = DEVID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); jsonStr12_[DINPUT_SOFTBUS_KEY_SESSION_ID] = SESSIONID; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); - jsonStr12_[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = INPUTTYPE; - DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr12_.dump()); jsonStr11_[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; DistributedInputSinkTransport::GetInstance().HandleData(sessionId, jsonStr11_.dump()); @@ -484,4 +474,4 @@ HWTEST_F(DistributedInputSinkTransTest, SendMessage_001, testing::ext::TestSize. } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index d9f3c63..c0e6a40 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -46,7 +46,6 @@ public: int32_t GetVirtualTouchScreenFd(); int32_t RegisterInputNodeListener(sptr listener); int32_t UnregisterInputNodeListener(sptr listener); - int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector &dhIds); int32_t RegisterInjectEventCb(sptr callback); int32_t UnregisterInjectEventCb(); @@ -70,4 +69,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // DISTRIBUTED_INPUT_INJECT_H \ No newline at end of file +#endif // DISTRIBUTED_INPUT_INJECT_H diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 25c4dbc..a857543 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -56,7 +56,6 @@ public: int32_t GetVirtualTouchScreenFd(); int32_t GetDeviceInfo(std::string &deviceId); - void GetDevicesInfoByType(const std::string &networkId, uint32_t inputTypes, std::map &datas); void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); void ProcessInjectEvent(const std::shared_ptr &rawEvent); @@ -118,4 +117,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // DISTRIBUTED_INPUT_INJECT_H \ No newline at end of file +#endif // DISTRIBUTED_INPUT_INJECT_H diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 792ca4a..66fb2c1 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -108,22 +108,6 @@ int32_t DistributedInputInject::UnregisterInputNodeListener(sptr &dhIds) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("the inputNodeListener is nullptr"); - return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; - } - std::map datas; - inputNodeManager_->GetDevicesInfoByType(devId, inputTypes, datas); - for (const auto &data_ : datas) { - dhIds.push_back(data_.second); - } - return DH_SUCCESS; -} - int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) { DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version, @@ -294,4 +278,4 @@ void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &dhId) } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 9fc137e..aeab8e2 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -514,31 +514,6 @@ int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) return DH_SUCCESS; } -void DistributedInputNodeManager::GetDevicesInfoByType(const std::string &networkId, uint32_t inputTypes, - std::map &datas) -{ - uint32_t inputType = 0; - - if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { - inputType |= INPUT_DEVICE_CLASS_CURSOR; - } - - if ((inputTypes & static_cast(DInputDeviceType::KEYBOARD)) != 0) { - inputType |= INPUT_DEVICE_CLASS_KEYBOARD; - } - - if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { - inputType |= INPUT_DEVICE_CLASS_TOUCH; - } - - std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &[id, virdevice] : virtualDeviceMap_) { - if ((virdevice->GetDeviceType() & inputType) && (virdevice->GetNetWorkId() == networkId)) { - datas.insert(std::pair(virdevice->GetDeviceFd(), id)); - } - } -} - void DistributedInputNodeManager::GetDevicesInfoByDhId( std::vector dhidsVec, std::map &datas) { diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index 0c929bb..fef98b8 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -300,33 +300,6 @@ HWTEST_F(DistributedInputSourceInjectTest, UnRegisterInputNodeListener, testing: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceInjectTest, GetDhIdsByInputType_001, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::vector dhIds; - std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - dhIds.push_back(dhId); - std::shared_ptr rawEvent = nullptr; - DistributedInputInject::GetInstance().InputDeviceEventInject(rawEvent); - DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); - int32_t ret = DistributedInputInject::GetInstance().GetDhIdsByInputType(devId, - static_cast(DInputDeviceType::ALL), dhIds); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceInjectTest, GetDhIdsByInputType_002, testing::ext::TestSize.Level1) -{ - DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - std::shared_ptr rawEvent = std::make_shared(); - DistributedInputInject::GetInstance().InputDeviceEventInject(rawEvent); - - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - std::vector dhIds; - int32_t ret = DistributedInputInject::GetInstance().GetDhIdsByInputType(devId, - static_cast(DInputDeviceType::ALL), dhIds); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); -} - HWTEST_F(DistributedInputSourceInjectTest, GenerateVirtualTouchScreenDHId_001, testing::ext::TestSize.Level1) { std::string ret = DistributedInputInject::GetInstance().GenerateVirtualTouchScreenDHId(1, 1860, 980); @@ -397,22 +370,6 @@ HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_003, tes EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceInjectTest, GetVirtualTouchScreenFd_003, testing::ext::TestSize.Level1) -{ - std::string networkId = "umkyu1b165e1be98151891erbe8r91ev"; - uint32_t inputTypes = 1; - std::map datas; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByType(networkId, inputTypes, datas); - - inputTypes = 2; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByType(networkId, inputTypes, datas); - - std::vector dhidsVec; - DistributedInputInject::GetInstance().inputNodeManager_->GetDevicesInfoByDhId(dhidsVec, datas); - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetVirtualTouchScreenFd(); - EXPECT_NE(-1, ret); -} - HWTEST_F(DistributedInputSourceInjectTest, GetDevice_001, testing::ext::TestSize.Level1) { std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index c727c29..5cfd655 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -73,14 +73,10 @@ ohos_shared_library("libdinput_source") { "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", "${ipc_path}/src/start_stop_result_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", diff --git a/services/source/sourcemanager/include/dinput_source_listener.h b/services/source/sourcemanager/include/dinput_source_listener.h index 386da3a..40e4854 100644 --- a/services/source/sourcemanager/include/dinput_source_listener.h +++ b/services/source/sourcemanager/include/dinput_source_listener.h @@ -46,8 +46,6 @@ public: 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, @@ -64,10 +62,6 @@ public: 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: @@ -77,4 +71,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // DINPUT_SOURCE_LISTENER_H \ No newline at end of file +#endif // DINPUT_SOURCE_LISTENER_H diff --git a/services/source/sourcemanager/include/dinput_source_manager_event_handler.h b/services/source/sourcemanager/include/dinput_source_manager_event_handler.h index a7dd636..f952079 100644 --- a/services/source/sourcemanager/include/dinput_source_manager_event_handler.h +++ b/services/source/sourcemanager/include/dinput_source_manager_event_handler.h @@ -50,8 +50,6 @@ private: 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); @@ -74,4 +72,4 @@ private: } // namespace DistributedHardware } // namespace OHOS -#endif // DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H \ No newline at end of file +#endif // DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index a25cb84..f74fc9b 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -73,7 +73,6 @@ const uint32_t DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI = 19; const std::string INPUT_SOURCEMANAGER_KEY_SESSIONID = "sessionId"; const std::string INPUT_SOURCEMANAGER_KEY_DEVID = "deviceId"; const std::string INPUT_SOURCEMANAGER_KEY_HWID = "hardwareId"; -const std::string INPUT_SOURCEMANAGER_KEY_ITP = "inputTypes"; const std::string INPUT_SOURCEMANAGER_KEY_DHID = "dhids"; const std::string INPUT_SOURCEMANAGER_KEY_TYPE = "type"; const std::string INPUT_SOURCEMANAGER_KEY_CODE = "code"; @@ -143,18 +142,6 @@ public: int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback) override; - int32_t StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) override; - - int32_t StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) override; - - int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) override; - - int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, - sptr callback) override; - int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) override; @@ -258,8 +245,6 @@ public: void RunUnregisterCallback(const std::string &devId, const std::string &dhId, const int32_t &status); void RunPrepareCallback(const std::string &devId, const int32_t &status, const std::string &object); void RunUnprepareCallback(const std::string &devId, const int32_t &status); - void RunStartCallback(const std::string &devId, const uint32_t &inputTypes, const int32_t &status); - void RunStopCallback(const std::string &devId, const uint32_t &inputTypes, const int32_t &status); void RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status); void RunStopDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status); @@ -278,9 +263,6 @@ public: int32_t DeleteInputDeviceNodeInfo(const std::string &devId, const std::string &dhId, const std::vector::iterator &it); int32_t UnregCallbackNotify(const std::string &devId, const std::string &dhId); - void SetInputTypesMap(const std::string deviceId, uint32_t value); - uint32_t GetInputTypesMap(const std::string deviceId); - uint32_t GetAllInputTypesMap(); void ClearResourcesStatus(); public: @@ -290,10 +272,6 @@ public: 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 { @@ -321,21 +299,6 @@ private: sptr unpreCallback = nullptr; }; - struct DInputClientStartInfo { - std::string devId; - uint32_t inputTypes; - sptr callback = nullptr; - DInputClientStartInfo(std::string deviceId, uint32_t types, sptr cb) - : devId(deviceId), inputTypes(types), callback(cb) {} - }; - - struct DInputClientStopInfo { - std::string devId; - uint32_t inputTypes; - sptr callback = nullptr; - DInputClientStopInfo(std::string deviceId, uint32_t types, sptr cb) - : devId(deviceId), inputTypes(types), callback(cb) {} - }; // add new prepare/start function struct DInputClientRelayPrepareInfo { std::string srcId; @@ -368,23 +331,6 @@ private: sptr callback = nullptr; }; - struct DInputClientStartTypeInfo { - std::string srcId; - std::string sinkId; - uint32_t inputTypes; - sptr callback = nullptr; - DInputClientStartTypeInfo(std::string sourceId, std::string sinkid, uint32_t types, - sptr cb) : srcId(sourceId), sinkId(sinkid), inputTypes(types), callback(cb) {} - }; - struct DInputClientStopTypeInfo { - std::string srcId; - std::string sinkId; - uint32_t inputTypes; - sptr callback = nullptr; - DInputClientStopTypeInfo(std::string sourceId, std::string sinkid, uint32_t types, - sptr cb) : srcId(sourceId), sinkId(sinkid), inputTypes(types), callback(cb) {} - }; - ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; std::shared_ptr statuslistener_; @@ -394,8 +340,6 @@ private: std::vector unregCallbacks_; std::vector preCallbacks_; std::vector unpreCallbacks_; - std::vector staCallbacks_; - std::vector stpCallbacks_; std::vector staStringCallbacks_; std::vector stpStringCallbacks_; @@ -404,15 +348,12 @@ private: std::vector relayUnpreCallbacks_; std::vector relayStaDhidCallbacks_; std::vector relayStpDhidCallbacks_; - std::vector relayStaTypeCallbacks_; - std::vector relayStpTypeCallbacks_; std::set> addWhiteListCallbacks_; std::set> delWhiteListCallbacks_; std::set> simulationEventCallbacks_; std::map DeviceMap_; - std::map InputTypesMap_; std::shared_ptr runner_; std::shared_ptr handler_; std::shared_ptr callBackHandler_; @@ -429,10 +370,6 @@ private: std::mutex syncNodeInfoMutex_; std::map> syncNodeInfoMap_; - 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, - sptr callback); int32_t RelayPrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback); int32_t RelayUnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, diff --git a/services/source/sourcemanager/src/dinput_source_listener.cpp b/services/source/sourcemanager/src/dinput_source_listener.cpp index 6a84d50..af681ee 100644 --- a/services/source/sourcemanager/src/dinput_source_listener.cpp +++ b/services/source/sourcemanager/src/dinput_source_listener.cpp @@ -177,64 +177,6 @@ void DInputSourceListener::OnResponseRelayUnprepareRemoteInput(int32_t toSrcSess 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) { @@ -463,56 +405,6 @@ void DInputSourceListener::OnReceiveRelayStopDhidResult(int32_t status, 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) { @@ -536,4 +428,4 @@ void DInputSourceListener::RecordEventLog(int64_t when, int32_t type, int32_t co } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp b/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp index 2f84018..162aadb 100644 --- a/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp +++ b/services/source/sourcemanager/src/dinput_source_manager_event_handler.cpp @@ -41,8 +41,6 @@ DInputSourceManagerEventHandler::DInputSourceManagerEventHandler( 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; @@ -59,10 +57,6 @@ DInputSourceManagerEventHandler::DInputSourceManagerEventHandler( &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; } @@ -164,69 +158,6 @@ void DInputSourceManagerEventHandler::NotifyUnprepareCallback(const AppExecFwk:: 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(); @@ -438,46 +369,6 @@ void DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback(const AppExecF 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()); @@ -490,4 +381,4 @@ void DInputSourceManagerEventHandler::ProcessEvent(const AppExecFwk::InnerEvent: } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 56297eb..4275df6 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -180,7 +180,6 @@ int32_t DistributedInputSourceManager::Release() DistributedInputSourceTransport::GetInstance().Release(); inputDevice_.clear(); DeviceMap_.clear(); - InputTypesMap_.clear(); std::shared_ptr jsonArrayMsg = std::make_shared(); nlohmann::json tmpJson; @@ -564,257 +563,6 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput( return DH_SUCCESS; } -int32_t DistributedInputSourceManager::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, deviceId, "Dinput start use call."); - if (!DInputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is failed."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - - DHLOGI("Start called, deviceId: %s, inputTypes: %d", GetAnonyString(deviceId).c_str(), inputTypes); - for (auto iter : staCallbacks_) { - if (iter.devId == deviceId && iter.inputTypes == inputTypes) { - callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in already started."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - - DInputClientStartInfo info {deviceId, inputTypes, callback}; - staCallbacks_.push_back(info); - DeviceMap_[deviceId] = DINPUT_SOURCE_SWITCH_OFF; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(deviceId, inputTypes); - if (ret != DH_SUCCESS) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in transport start"); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - DHLOGE("Start fail."); - for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) { - if (iter->devId == deviceId && iter->inputTypes == inputTypes) { - iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); - staCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, deviceId, "Dinput stop use call"); - if (!DInputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is failed."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - - DHLOGI("Stop called, deviceId: %s, inputTypes: %d", GetAnonyString(deviceId).c_str(), inputTypes); - for (auto iter : stpCallbacks_) { - if (iter.devId == deviceId && iter.inputTypes == inputTypes) { - callback->OnResult(deviceId, inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in already stoped."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - - DInputClientStopInfo info {deviceId, inputTypes, callback}; - stpCallbacks_.push_back(info); - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("Stop fail."); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in transport stop."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (auto iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); ++iter) { - if (iter->devId == deviceId && iter->inputTypes == inputTypes) { - iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); - stpCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "Dinput start use call."); - if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, 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("StartRemoteInput called, srcId: %s, sinkId: %s, inputTypes: %d", GetAnonyString(srcId).c_str(), - GetAnonyString(sinkId).c_str(), inputTypes); - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in get local networkId error."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - if (srcId != localNetworkId) { - return RelayStartRemoteInputByType(srcId, sinkId, inputTypes, callback); - } - for (auto iter : staCallbacks_) { - if (iter.devId == sinkId && iter.inputTypes == inputTypes) { - DHLOGE("StartRemoteInput called, repeat call."); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in already started."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - - DInputClientStartInfo info {sinkId, inputTypes, callback}; - staCallbacks_.push_back(info); - DeviceMap_[sinkId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput(sinkId, inputTypes); - if (ret != DH_SUCCESS) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in transport start."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - DHLOGE("StartRemoteInput called, start fail."); - for (auto it = staCallbacks_.begin(); it != staCallbacks_.end(); ++it) { - if (it->devId == sinkId && it->inputTypes == inputTypes) { - staCallbacks_.erase(it); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "Dinput stop use call."); - if (!DInputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, 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("StopRemoteInput called, srcId: %s, sinkId: %s, inputTypes: %d", GetAnonyString(srcId).c_str(), - GetAnonyString(sinkId).c_str(), inputTypes); - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in get networkId."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - if (srcId != localNetworkId) { - return RelayStopRemoteInputByType(srcId, sinkId, inputTypes, callback); - } - for (auto iter : stpCallbacks_) { - if (iter.devId == sinkId && iter.inputTypes == inputTypes) { - DHLOGE("StopRemoteInput called, repeat call."); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in already stoped."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - - DInputClientStopInfo info {sinkId, inputTypes, callback}; - stpCallbacks_.push_back(info); - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(sinkId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("StopRemoteInput called, stop fail."); - HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in transport stop."); - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (auto it = stpCallbacks_.begin(); it != stpCallbacks_.end(); ++it) { - if (it->devId == sinkId && it->inputTypes == inputTypes) { - stpCallbacks_.erase(it); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::RelayStartRemoteInputByType(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes, sptr callback) -{ - std::lock_guard lock(mutex_); - for (auto iter : relayStaTypeCallbacks_) { - if (iter.srcId == srcId && iter.sinkId == sinkId && iter.inputTypes == inputTypes) { - DHLOGE("Repeat call."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - - DInputClientStartTypeInfo info(srcId, sinkId, inputTypes, callback); - relayStaTypeCallbacks_.push_back(info); - - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStartTypeRequest(srcId, sinkId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, start fail."); - for (auto iter = relayStaTypeCallbacks_.begin(); iter != relayStaTypeCallbacks_.end(); ++iter) { - if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) { - relayStaTypeCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::RelayStopRemoteInputByType( - const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, sptr callback) -{ - std::lock_guard lock(mutex_); - for (auto iter : relayStpTypeCallbacks_) { - if (iter.srcId == srcId && iter.sinkId == sinkId && iter.inputTypes == inputTypes) { - DHLOGE("Repeat call."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - - DInputClientStopTypeInfo info(srcId, sinkId, inputTypes, callback); - relayStpTypeCallbacks_.push_back(info); - - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStopTypeRequest(srcId, sinkId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, start fail."); - for (auto iter = relayStpTypeCallbacks_.begin(); iter != relayStpTypeCallbacks_.end(); ++iter) { - if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) { - relayStpTypeCallbacks_.erase(iter); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - } - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; - } - - return DH_SUCCESS; -} - int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { @@ -1460,34 +1208,6 @@ void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devI DHLOGE("ProcessEvent unparepareCallback is null."); } -void DistributedInputSourceManager::RunStartCallback( - const std::string &devId, const uint32_t &inputTypes, const int32_t &status) -{ - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) { - if (iter->devId == devId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_MSG"); - iter->callback->OnResult(devId, inputTypes, status); - staCallbacks_.erase(iter); - break; - } - } -} - -void DistributedInputSourceManager::RunStopCallback( - const std::string &devId, const uint32_t &inputTypes, const int32_t &status) -{ - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (auto iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); ++iter) { - if (iter->devId == devId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_STOP_MSG"); - iter->callback->OnResult(devId, inputTypes, status); - stpCallbacks_.erase(iter); - break; - } - } -} - void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, const int32_t &status) { @@ -1577,47 +1297,6 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string & } } -void DistributedInputSourceManager::RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, - const int32_t status, uint32_t inputTypes) -{ - bool isCbRun = false; - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - for (std::vector::iterator iter = - relayStaTypeCallbacks_.begin(); iter != relayStaTypeCallbacks_.end(); ++iter) { - if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI"); - iter->callback->OnResult(sinkId, inputTypes, status); - relayStaTypeCallbacks_.erase(iter); - isCbRun = true; - break; - } - } - - if (!isCbRun) { - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI relayStaTypeCallbacks_ is null."); - } -} - -void DistributedInputSourceManager::RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, - const int32_t status, uint32_t inputTypes) -{ - bool isCbRun = false; - FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (std::vector::iterator iter = - relayStpTypeCallbacks_.begin(); iter != relayStpTypeCallbacks_.end(); ++iter) { - if (iter->srcId == srcId && iter->sinkId == sinkId && iter->inputTypes == inputTypes) { - DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI"); - iter->callback->OnResult(sinkId, inputTypes, status); - relayStpTypeCallbacks_.erase(iter); - isCbRun = true; - break; - } - } - - if (!isCbRun) { - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI relayStpTypeCallbacks_ is null."); - } -} void DistributedInputSourceManager::RunKeyStateCallback(const std::string &sinkId, const std::string &dhId, const uint32_t type, const uint32_t code, const uint32_t value) { @@ -1686,24 +1365,6 @@ void DistributedInputSourceManager::SetDeviceMapValue(const std::string deviceId DeviceMap_[deviceId] = value; } -uint32_t DistributedInputSourceManager::GetInputTypesMap(const std::string deviceId) -{ - auto key = InputTypesMap_.find(deviceId); - if (key != InputTypesMap_.end()) { - return InputTypesMap_[deviceId]; - } - return static_cast(DInputDeviceType::NONE); -} - -uint32_t DistributedInputSourceManager::GetAllInputTypesMap() -{ - uint32_t rInputTypes = static_cast(DInputDeviceType::NONE); - for (auto iter = InputTypesMap_.begin(); iter != InputTypesMap_.end(); ++iter) { - rInputTypes |= iter->second; - } - return rInputTypes; -} - void DistributedInputSourceManager::ClearResourcesStatus() { std::lock_guard lock(mutex_); @@ -1711,18 +1372,6 @@ void DistributedInputSourceManager::ClearResourcesStatus() relayUnpreCallbacks_.clear(); } -void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, uint32_t value) -{ - if (value == static_cast(DInputDeviceType::NONE)) { - auto key = InputTypesMap_.find(deviceId); - if (key != InputTypesMap_.end()) { - InputTypesMap_.erase(key); - return; - } - } - InputTypesMap_[deviceId] = value; -} - std::set DistributedInputSourceManager::GetSyncNodeInfo(const std::string &devId) { std::lock_guard lock(syncNodeInfoMutex_); diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 9018a55..03a4b74 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -75,10 +75,6 @@ ohos_unittest("distributed_input_sourcemanager_test") { "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", "${ipc_path}/src/register_d_input_call_back_proxy.cpp", "${ipc_path}/src/register_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_d_input_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_call_back_stub.cpp", - "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", - "${ipc_path}/src/stop_d_input_call_back_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", "${ipc_path}/src/unregister_d_input_call_back_proxy.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 e9c4c2d..8f39a38 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -41,10 +41,6 @@ using namespace std; namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -namespace { - const uint32_t INPUTTYPE = static_cast(DInputDeviceType::ALL); - const uint32_t INPUTTYPE_MOUSE = static_cast(DInputDeviceType::MOUSE); -} void DistributedInputSourceManagerTest::SetUp() { @@ -105,24 +101,6 @@ void DistributedInputSourceManagerTest::TestUnprepareDInputCallback::OnResult( return; } -void DistributedInputSourceManagerTest::TestStartDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - -void DistributedInputSourceManagerTest::TestStopDInputCallback::OnResult( - const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status) -{ - (void)deviceId; - (void)inputTypes; - (void)status; - return; -} - void DistributedInputSourceManagerTest::TestStartStopVectorCallbackStub::OnResultDhids(const std::string &devId, const int32_t &status) { @@ -466,238 +444,6 @@ HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput_03, testing::ex EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); } -/** - * @tc.name: StartRemoteInput - * @tc.desc: verify the function of starting distributed input on InputDeviceType. - * @tc.type: FUNC - * @tc.require: SR000H9J75 - */ -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_02, testing::ext::TestSize.Level1) -{ - std::string devId = ""; - sptr callback(new TestStartDInputCallback()); - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); - devId = "umkyu1b165e1be98151891erbe8r91ev"; - DistributedInputSourceManager::DInputClientStartInfo info {devId, INPUTTYPE, callback}; - sourceManager_->staCallbacks_.push_back(info); - ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); - - ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_03, testing::ext::TestSize.Level1) -{ - std::string devId = "devId_4810input4809_test"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = sourceManager_->StartRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -/** - * @tc.name: StopRemoteInput - * @tc.desc: verify the function of stoping distributed input on InputDeviceType. - * @tc.type: FUNC - * @tc.require: SR000H9J75 - */ -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->StopRemoteInput(devId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_02, testing::ext::TestSize.Level1) -{ - std::string devId = ""; - sptr callback(new TestStopDInputCallback()); - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); - devId = "umkyu1b165e1be98151891erbe8r91ev"; - DistributedInputSourceManager::DInputClientStopInfo info {devId, INPUTTYPE, callback}; - sourceManager_->stpCallbacks_.push_back(info); - ret = sourceManager_->StopRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_03, testing::ext::TestSize.Level1) -{ - sptr callback(new TestStopDInputCallback()); - std::string devId = "devId_4810input4809_test"; - int32_t ret = sourceManager_->StopRemoteInput(devId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -/** - * @tc.name: StartRemoteInput - * @tc.desc: verify the function of starting distributed input on InputDeviceType. - * @tc.type: FUNC - * @tc.require: SR000H9J75 - */ -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_04, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStartDInputCallback()); - int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_05, testing::ext::TestSize.Level1) -{ - std::string srcId = ""; - std::string sinkId = ""; - sptr callback(new TestStartDInputCallback()); - int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); - srcId = "srcId_4810input4809_test"; - sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - DistributedInputSourceManager::DInputClientStartTypeInfo info(srcId, sinkId, INPUTTYPE, callback); - sourceManager_->relayStaTypeCallbacks_.push_back(info); - ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); - srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - DistributedInputSourceManager::DInputClientStartInfo startInfo {sinkId, INPUTTYPE, callback}; - sourceManager_->staCallbacks_.push_back(startInfo); - ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput_06, testing::ext::TestSize.Level1) -{ - sptr callback(new TestStartDInputCallback()); - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "devId_4810input4809_test"; - int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -/** - * @tc.name: StopRemoteInput - * @tc.desc: verify the function of stoping distributed input on InputDeviceType. - * @tc.type: FUNC - * @tc.require: SR000H9J75 - */ -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_04, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStopDInputCallback()); - int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->StopRemoteInput(srcId, sinkId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_05, testing::ext::TestSize.Level1) -{ - std::string srcId = ""; - std::string sinkId = ""; - sptr callback(new TestStopDInputCallback()); - int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, - INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); - srcId = "srcId_4810input4809_test"; - sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - DistributedInputSourceManager::DInputClientStopTypeInfo info(srcId, sinkId, INPUTTYPE, callback); - sourceManager_->relayStpTypeCallbacks_.push_back(info); - ret = sourceManager_->StopRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); - srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - DistributedInputSourceManager::DInputClientStopInfo stopInfo {sinkId, INPUTTYPE, callback}; - sourceManager_->stpCallbacks_.push_back(stopInfo); - ret = sourceManager_->StopRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput_06, testing::ext::TestSize.Level1) -{ - sptr callback(new TestStopDInputCallback()); - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "devId_4810input4809_test"; - int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RelayStartRemoteInputByType_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStartDInputCallback()); - int32_t sessionId = 1; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[srcId] = sessionId; - int32_t ret = sourceManager_->RelayStartRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - sinkId = "sinkId_test"; - ret = sourceManager_->RelayStartRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->RelayStartRemoteInputByType(srcId, sinkId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RelayStartRemoteInputByType_02, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStartDInputCallback()); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - int32_t ret = sourceManager_->RelayStartRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RelayStopRemoteInputByType_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStopDInputCallback()); - int32_t sessionId = 1; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[srcId] = sessionId; - int32_t ret = sourceManager_->RelayStopRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - sinkId = "sinkId_test"; - ret = sourceManager_->RelayStopRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(DH_SUCCESS, ret); - - ret = sourceManager_->RelayStopRemoteInputByType(srcId, sinkId, INPUTTYPE_MOUSE, callback); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, RelayStopRemoteInputByType_02, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - sptr callback(new TestStopDInputCallback()); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - int32_t ret = sourceManager_->RelayStopRemoteInputByType(srcId, sinkId, INPUTTYPE, callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); -} - /** * @tc.name: PrepareRemoteInput * @tc.desc: verify the function of distributing data from any device. @@ -1370,58 +1116,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RunUnprepareCallback_01, testing::ex EXPECT_EQ(1, sourceManager_->unpreCallbacks_.size()); } -HWTEST_F(DistributedInputSourceManagerTest, RunStartCallback_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - int32_t status = 0; - uint32_t inputTypes = 1; - sptr callback(new TestStartDInputCallback()); - DistributedInputSourceManager::DInputClientStartInfo info {devId, inputTypes, callback}; - sourceManager_->staCallbacks_.push_back(info); - sourceManager_->RunStartCallback(devId, inputTypes, status); - EXPECT_EQ(0, sourceManager_->staCallbacks_.size()); - - DistributedInputSourceManager::DInputClientStartInfo startInfo {devId, inputTypes, callback}; - sourceManager_->staCallbacks_.push_back(startInfo); - devId = "devId_20221221_test"; - sourceManager_->RunStartCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->staCallbacks_.size()); - - inputTypes = 3; - sourceManager_->RunStartCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->staCallbacks_.size()); - - devId = "umkyu1b165e1be98151891erbe8r91ev"; - sourceManager_->RunStartCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->staCallbacks_.size()); -} - -HWTEST_F(DistributedInputSourceManagerTest, RunStopCallback_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - int32_t status = 0; - uint32_t inputTypes = 1; - sptr callback(new TestStopDInputCallback()); - DistributedInputSourceManager::DInputClientStopInfo info {devId, inputTypes, callback}; - sourceManager_->stpCallbacks_.push_back(info); - sourceManager_->RunStopCallback(devId, inputTypes, status); - EXPECT_EQ(0, sourceManager_->stpCallbacks_.size()); - - DistributedInputSourceManager::DInputClientStopInfo stopInfo {devId, inputTypes, callback}; - sourceManager_->stpCallbacks_.push_back(stopInfo); - devId = "devId_20221221_test"; - sourceManager_->RunStopCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->stpCallbacks_.size()); - - inputTypes = 3; - sourceManager_->RunStopCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->stpCallbacks_.size()); - - devId = "umkyu1b165e1be98151891erbe8r91ev"; - sourceManager_->RunStopCallback(devId, inputTypes, status); - EXPECT_EQ(1, sourceManager_->stpCallbacks_.size()); -} - HWTEST_F(DistributedInputSourceManagerTest, RunStartDhidCallback_01, testing::ext::TestSize.Level1) { std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; @@ -1534,60 +1228,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RunRelayStopDhidCallback_01, testing EXPECT_EQ(1, sourceManager_->relayStpDhidCallbacks_.size()); } -HWTEST_F(DistributedInputSourceManagerTest, RunRelayStartTypeCallback_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - int32_t status = 0; - uint32_t inputTypes = 1; - sptr callback(new TestStartDInputCallback()); - DistributedInputSourceManager::DInputClientStartTypeInfo info(srcId, sinkId, inputTypes, callback); - sourceManager_->relayStaTypeCallbacks_.push_back(info); - sourceManager_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(0, sourceManager_->relayStaTypeCallbacks_.size()); - - DistributedInputSourceManager::DInputClientStartTypeInfo startInfo(srcId, sinkId, inputTypes, callback); - sourceManager_->relayStaTypeCallbacks_.push_back(startInfo); - srcId = "devId_20221221_test"; - sourceManager_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStaTypeCallbacks_.size()); - - sinkId = "sinkId_20221221_test"; - sourceManager_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStaTypeCallbacks_.size()); - - inputTypes = 3; - sourceManager_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStaTypeCallbacks_.size()); -} - -HWTEST_F(DistributedInputSourceManagerTest, RunRelayStopTypeCallback_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; - int32_t status = 0; - uint32_t inputTypes = 1; - sptr callback(new TestStopDInputCallback()); - DistributedInputSourceManager::DInputClientStopTypeInfo info(srcId, sinkId, inputTypes, callback); - sourceManager_->relayStpTypeCallbacks_.push_back(info); - sourceManager_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(0, sourceManager_->relayStpTypeCallbacks_.size()); - - DistributedInputSourceManager::DInputClientStopTypeInfo stopInfo(srcId, sinkId, inputTypes, callback); - sourceManager_->relayStpTypeCallbacks_.push_back(stopInfo); - srcId = "devId_20221221_test"; - sourceManager_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStpTypeCallbacks_.size()); - - sinkId = "sinkId_20221221_test"; - sourceManager_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStpTypeCallbacks_.size()); - - inputTypes = 3; - sourceManager_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes); - EXPECT_EQ(1, sourceManager_->relayStpTypeCallbacks_.size()); -} - HWTEST_F(DistributedInputSourceManagerTest, RemoveInputDeviceId_01, testing::ext::TestSize.Level1) { std::string deviceId = "umkyu1b165e1be98151891erbe8r91ev"; @@ -1617,31 +1257,6 @@ HWTEST_F(DistributedInputSourceManagerTest, GetDeviceMapAllDevSwitchOff_02, test EXPECT_EQ(false, ret); } -HWTEST_F(DistributedInputSourceManagerTest, GetInputTypesMap_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sourceManager_->InputTypesMap_[devId] = 1; - uint32_t ret = sourceManager_->GetInputTypesMap(devId); - EXPECT_EQ(static_cast(DInputDeviceType::MOUSE), ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, GetAllInputTypesMap_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - sourceManager_->InputTypesMap_[devId] = 1; - uint32_t ret = sourceManager_->GetAllInputTypesMap(); - EXPECT_EQ(static_cast(DInputDeviceType::MOUSE), ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, SetInputTypesMap_01, testing::ext::TestSize.Level1) -{ - std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; - uint32_t value = 0; - sourceManager_->InputTypesMap_[devId] = 1; - sourceManager_->SetInputTypesMap(devId, value); - EXPECT_EQ(true, sourceManager_->InputTypesMap_.empty()); -} - HWTEST_F(DistributedInputSourceManagerTest, GetSyncNodeInfo_01, testing::ext::TestSize.Level1) { std::string userDevId = "umkyu1b165e1be98151891erbe8r91ev"; @@ -1729,32 +1344,6 @@ HWTEST_F(DistributedInputSourceManagerTest, OnResponseUnprepareRemoteInput_01, t EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); } -HWTEST_F(DistributedInputSourceManagerTest, OnResponseStartRemoteInput_01, testing::ext::TestSize.Level1) -{ - std::string deviceId = "djfhskjdhf5465456ds4f654sdf6"; - uint32_t inputTypes = 7; - bool result = true; - callback_->OnResponseStartRemoteInput(deviceId, inputTypes, result); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, OnResponseStopRemoteInput_01, testing::ext::TestSize.Level1) -{ - std::string deviceId = "djfhskjdhf5465456ds4f654sdf6"; - uint32_t inputTypes = 7; - bool result = true; - callback_->OnResponseStopRemoteInput(deviceId, inputTypes, result); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - HWTEST_F(DistributedInputSourceManagerTest, OnResponseStartRemoteInputDhid_01, testing::ext::TestSize.Level1) { std::string deviceId = "djfhskjdhf5465456ds4f654sdf6"; @@ -1862,34 +1451,6 @@ HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStopDhidResult_01, tes EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); } -HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStartTypeResult_01, testing::ext::TestSize.Level1) -{ - int32_t status = 1; - std::string srcId = "djfhskjdhf5465456ds4f654sdf6"; - std::string sinkId = "asd4a65sd46as4da6s4d6asdasdafwebrb"; - uint32_t inputTypes = 7; - callback_->OnReceiveRelayStartTypeResult(status, srcId, sinkId, inputTypes); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStopTypeResult_01, testing::ext::TestSize.Level1) -{ - int32_t status = 1; - std::string srcId = "djfhskjdhf5465456ds4f654sdf6"; - std::string sinkId = "asd4a65sd46as4da6s4d6asdasdafwebrb"; - uint32_t inputTypes = 7; - callback_->OnReceiveRelayStopTypeResult(status, srcId, sinkId, inputTypes); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - HWTEST_F(DistributedInputSourceManagerTest, InitAuto_01, testing::ext::TestSize.Level1) { bool ret = sourceManager_->InitAuto(); @@ -1940,36 +1501,6 @@ HWTEST_F(DistributedInputSourceManagerTest, OnResponseUnprepareRemoteInput_02, t EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); } -HWTEST_F(DistributedInputSourceManagerTest, OnResponseStartRemoteInput_02, testing::ext::TestSize.Level1) -{ - sourceManager_->InitAuto(); - - std::string deviceId = "djfhskjdhf5465456ds4f654sdf6"; - uint32_t inputTypes = 7; - bool result = true; - callback_->OnResponseStartRemoteInput(deviceId, inputTypes, result); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, OnResponseStopRemoteInput_02, testing::ext::TestSize.Level1) -{ - sourceManager_->InitAuto(); - - std::string deviceId = "djfhskjdhf5465456ds4f654sdf6"; - uint32_t inputTypes = 7; - bool result = true; - callback_->OnResponseStopRemoteInput(deviceId, inputTypes, result); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - HWTEST_F(DistributedInputSourceManagerTest, OnResponseStartRemoteInputDhid_02, testing::ext::TestSize.Level1) { sourceManager_->InitAuto(); @@ -2093,38 +1624,6 @@ HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStopDhidResult_02, tes EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); } -HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStartTypeResult_02, testing::ext::TestSize.Level1) -{ - sourceManager_->InitAuto(); - - int32_t status = 1; - std::string srcId = "djfhskjdhf5465456ds4f654sdf6"; - std::string sinkId = "asd4a65sd46as4da6s4d6asdasdafwebrb"; - uint32_t inputTypes = 7; - callback_->OnReceiveRelayStartTypeResult(status, srcId, sinkId, inputTypes); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceManagerTest, OnReceiveRelayStopTypeResult_02, testing::ext::TestSize.Level1) -{ - sourceManager_->InitAuto(); - - int32_t status = 1; - std::string srcId = "djfhskjdhf5465456ds4f654sdf6"; - std::string sinkId = "asd4a65sd46as4da6s4d6asdasdafwebrb"; - uint32_t inputTypes = 7; - callback_->OnReceiveRelayStopTypeResult(status, srcId, sinkId, inputTypes); - - int32_t fd = 1; - std::vector args; - int32_t ret = sourceManager_->Dump(fd, args); - EXPECT_EQ(ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL, ret); -} - HWTEST_F(DistributedInputSourceManagerTest, ParseMessage_01, testing::ext::TestSize.Level1) { DistributedInputSourceManager::StopDScreenListener stopListener; @@ -2188,4 +1687,4 @@ HWTEST_F(DistributedInputSourceManagerTest, ParseMessage_02, testing::ext::TestS } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS 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 c47d5e0..3bcc374 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h @@ -29,8 +29,6 @@ #include "distributed_input_source_manager.h" #include "prepare_d_input_call_back_stub.h" #include "register_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" #include "unprepare_d_input_call_back_stub.h" #include "unregister_d_input_call_back_stub.h" #include "start_stop_d_inputs_call_back_stub.h" @@ -67,22 +65,6 @@ public: void OnResult(const std::string &deviceId, const int32_t &status); }; - class TestStartDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - TestStartDInputCallback() = default; - virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - - class TestStopDInputCallback : public - OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); - }; - class TestStartStopVectorCallbackStub : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index 170bff4..84c8f3a 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -61,8 +61,6 @@ public: int32_t PrepareRemoteInput(const std::string &deviceId); int32_t UnprepareRemoteInput(const std::string &deviceId); - int32_t StartRemoteInput(const std::string &deviceId, const uint32_t &inputTypes); - int32_t StopRemoteInput(const std::string &deviceId, const uint32_t &inputTypes); int32_t LatencyCount(const std::string &deviceId); void StartLatencyCount(const std::string &deviceId); void StartLatencyThread(const std::string &deviceId); @@ -84,8 +82,6 @@ public: const std::vector &dhids); int32_t SendRelayStopDhidRequest(const std::string &srcId, const std::string &sinkId, const std::vector &dhids); - int32_t SendRelayStartTypeRequest(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes); - int32_t SendRelayStopTypeRequest(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes); int32_t GetCurrentSessionId(); private: @@ -94,8 +90,6 @@ private: void SessionClosed(); void NotifyResponsePrepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseUnprepareRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg); @@ -120,19 +114,6 @@ private: void ReceiveRelayStartDhidResult(int32_t sessionId, const nlohmann::json &recMsg); void ReceiveRelayStopDhidResult(int32_t sessionId, const nlohmann::json &recMsg); - void ReceiveSrcTSrcRelayStartType(int32_t sessionId, const nlohmann::json &recMsg); - void ReceiveSrcTSrcRelayStopType(int32_t sessionId, const nlohmann::json &recMsg); - int32_t StartRemoteInputType(int32_t sessionId, const std::string &deviceId, const uint32_t &inputTypes); - int32_t StopRemoteInputType(int32_t sessionId, const std::string &deviceId, const uint32_t &inputTypes); - void NotifyResponseRelayStartTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - void NotifyResponseRelayStopTypeRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); - int32_t NotifyOriginStartTypeResult(int32_t sessionId, const std::string &srcId, const std::string &sinkId, - int32_t status, uint32_t inputTypes); - int32_t NotifyOriginStopTypeResult(int32_t sessionId, const std::string &srcId, const std::string &sinkId, - int32_t status, uint32_t inputTypes); - void ReceiveRelayStartTypeResult(int32_t sessionId, const nlohmann::json &recMsg); - void ReceiveRelayStopTypeResult(int32_t sessionId, const nlohmann::json &recMsg); - void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg); std::string JointDhIds(const std::vector &dhids); void RegRespFunMap(); diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index e0a846e..af00a93 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -72,8 +72,6 @@ void DistributedInputSourceTransport::RegRespFunMap() { memberFuncMap_[TRANS_SINK_MSG_ONPREPARE] = &DistributedInputSourceTransport::NotifyResponsePrepareRemoteInput; memberFuncMap_[TRANS_SINK_MSG_ONUNPREPARE] = &DistributedInputSourceTransport::NotifyResponseUnprepareRemoteInput; - memberFuncMap_[TRANS_SINK_MSG_ONSTART] = &DistributedInputSourceTransport::NotifyResponseStartRemoteInput; - memberFuncMap_[TRANS_SINK_MSG_ONSTOP] = &DistributedInputSourceTransport::NotifyResponseStopRemoteInput; memberFuncMap_[TRANS_SINK_MSG_BODY_DATA] = &DistributedInputSourceTransport::NotifyReceivedEventRemoteInput; memberFuncMap_[TRANS_SINK_MSG_LATENCY] = &DistributedInputSourceTransport::CalculateLatency; memberFuncMap_[TRANS_SINK_MSG_DHID_ONSTART] = &DistributedInputSourceTransport::NotifyResponseStartRemoteInputDhid; @@ -102,18 +100,6 @@ void DistributedInputSourceTransport::RegRespFunMap() &DistributedInputSourceTransport::ReceiveRelayStartDhidResult; memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_STOP_DHID_RESULT] = &DistributedInputSourceTransport::ReceiveRelayStopDhidResult; - memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE] = - &DistributedInputSourceTransport::ReceiveSrcTSrcRelayStartType; - memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE] = - &DistributedInputSourceTransport::ReceiveSrcTSrcRelayStopType; - memberFuncMap_[TRANS_SINK_MSG_ON_RELAY_STARTTYPE] = - &DistributedInputSourceTransport::NotifyResponseRelayStartTypeRemoteInput; - memberFuncMap_[TRANS_SINK_MSG_ON_RELAY_STOPTYPE] = - &DistributedInputSourceTransport::NotifyResponseRelayStopTypeRemoteInput; - memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE_RESULT] = - &DistributedInputSourceTransport::ReceiveRelayStartTypeResult; - memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE_RESULT] = - &DistributedInputSourceTransport::ReceiveRelayStopTypeResult; } void DistributedInputSourceTransport::Release() @@ -340,60 +326,6 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI return DH_SUCCESS; } -int32_t DistributedInputSourceTransport::StartRemoteInputType(int32_t srcTsrcSeId, const std::string &deviceId, - const uint32_t &inputTypes) -{ - int32_t sinkSessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(deviceId); - if (sinkSessionId < 0) { - DHLOGE("StartRemoteInputType error, not find this device:%s.", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("StartRemoteInputType srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_TYPE_FOR_REL; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = srcTsrcSeId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sinkSessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StartRemoteInputType deviceId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("StartRemoteInputType send success, devId:%s, msg:%s.", GetAnonyString(deviceId).c_str(), - SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceTransport::StopRemoteInputType(int32_t srcTsrcSeId, const std::string &deviceId, - const uint32_t &inputTypes) -{ - int32_t sinkSessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(deviceId); - if (sinkSessionId < 0) { - DHLOGE("StopRemoteInputType error, not find this device:%s.", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("StopRemoteInputType srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = srcTsrcSeId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sinkSessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StopRemoteInputType deviceId:%s, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("StopRemoteInputType send success, devId:%s, msg:%s.", GetAnonyString(deviceId).c_str(), - SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - int32_t DistributedInputSourceTransport::SendRelayPrepareRequest(const std::string &srcId, const std::string &sinkId) { int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(srcId); @@ -528,103 +460,6 @@ int32_t DistributedInputSourceTransport::NotifyOriginStopDhidResult(int32_t srcT return DH_SUCCESS; } -int32_t DistributedInputSourceTransport::NotifyOriginStartTypeResult(int32_t srcTsrcSeId, const std::string &srcId, - const std::string &sinkId, int32_t status, uint32_t inputTypes) -{ - std::unique_lock sessionLock(operationMutex_); - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE_RESULT; - jsonStr[DINPUT_SOFTBUS_KEY_SRC_DEV_ID] = srcId; - jsonStr[DINPUT_SOFTBUS_KEY_SINK_DEV_ID] = sinkId; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = status; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(srcTsrcSeId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("NotifyOriginStartTypeResult srcTsrcSeId:%d, smsg:%s, SendMsg error, ret:%d.", - srcTsrcSeId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("NotifyOriginStartTypeResult srcTsrcSeId:%d, smsg:%s.", srcTsrcSeId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceTransport::NotifyOriginStopTypeResult(int32_t srcTsrcSeId, const std::string &srcId, - const std::string &sinkId, int32_t status, uint32_t inputTypes) -{ - std::unique_lock sessionLock(operationMutex_); - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE_RESULT; - jsonStr[DINPUT_SOFTBUS_KEY_SRC_DEV_ID] = srcId; - jsonStr[DINPUT_SOFTBUS_KEY_SINK_DEV_ID] = sinkId; - jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = status; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(srcTsrcSeId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("NotifyOriginStopTypeResult srcTsrcSeId:%d, smsg:%s, SendMsg error, ret:%d.", - srcTsrcSeId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("NotifyOriginStopTypeResult srcTsrcSeId:%d, smsg:%s.", srcTsrcSeId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &deviceId, const uint32_t &inputTypes) -{ - int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(deviceId); - if (sessionId < 0) { - DHLOGE("StartRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("StartRemoteInput sessionId:%d.", sessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_TYPE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", - GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceTransport::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes) -{ - int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(deviceId); - if (sessionId < 0) { - DHLOGE("StopRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("StopRemoteInput sessionId:%d.", sessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_TYPE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", - GetAnonyString(deviceId).c_str(), sessionId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - int32_t DistributedInputSourceTransport::LatencyCount(const std::string &deviceId) { int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(deviceId); @@ -839,58 +674,6 @@ int32_t DistributedInputSourceTransport::SendRelayStopDhidRequest(const std::str return DH_SUCCESS; } -int32_t DistributedInputSourceTransport::SendRelayStartTypeRequest(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes) -{ - int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(srcId); - if (sessionId < 0) { - DHLOGE("SendRelayStartTypeRequest error, not find this device:%s.", GetAnonyString(srcId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("SendRelayStartTypeRequest sessionId:%d.", sessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = sinkId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("SendRelayStartTypeRequest srcId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(srcId).c_str(), sessionId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; - } - DHLOGI("SendRelayStartTypeRequest srcId:%s, sessionId:%d, smsg:%s.", - GetAnonyString(srcId).c_str(), sessionId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceTransport::SendRelayStopTypeRequest(const std::string &srcId, const std::string &sinkId, - const uint32_t &inputTypes) -{ - int32_t sessionId = DistributedInputTransportBase::GetInstance().GetSessionIdByDevId(srcId); - if (sessionId < 0) { - DHLOGE("SendRelayStopTypeRequest error, not find this device:%s.", GetAnonyString(srcId).c_str()); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("SendRelayStopTypeRequest sessionId:%d.", sessionId); - - nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE; - jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = sinkId; - jsonStr[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - std::string smsg = jsonStr.dump(); - int32_t ret = SendMessage(sessionId, smsg); - if (ret != DH_SUCCESS) { - DHLOGE("SendRelayStopTypeRequest srcId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - GetAnonyString(srcId).c_str(), sessionId, SetAnonyId(smsg).c_str(), ret); - return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; - } - DHLOGI("SendRelayStopTypeRequest srcId:%s, sessionId:%d, smsg:%s.", - GetAnonyString(srcId).c_str(), sessionId, SetAnonyId(smsg).c_str()); - return DH_SUCCESS; -} - std::string DistributedInputSourceTransport::JointDhIds(const std::vector &dhids) { if (dhids.size() <= 0) { @@ -958,40 +741,6 @@ void DistributedInputSourceTransport::NotifyResponseUnprepareRemoteInput(int32_t CloseInputSoftbus(deviceId, false); } -void DistributedInputSourceTransport::NotifyResponseStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTART."); - if (!IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE) || - !IsBoolean(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = DistributedInputTransportBase::GetInstance().GetDevIdBySessionId(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTART, deviceId is error."); - return; - } - callback_->OnResponseStartRemoteInput( - deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); -} - -void DistributedInputSourceTransport::NotifyResponseStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ONSTOP."); - if (!IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE) || - !IsBoolean(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = DistributedInputTransportBase::GetInstance().GetDevIdBySessionId(sessionId); - if (deviceId.empty()) { - DHLOGE("OnBytesReceived cmdType TRANS_SINK_MSG_ONSTOP, deviceId is error."); - return; - } - callback_->OnResponseStopRemoteInput( - deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); -} - void DistributedInputSourceTransport::NotifyResponseStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg) { @@ -1331,142 +1080,6 @@ void DistributedInputSourceTransport::ReceiveRelayStopDhidResult(int32_t session callback_->OnReceiveRelayStopDhidResult(status, srcId, sinkId, dhids); } -void DistributedInputSourceTransport::ReceiveSrcTSrcRelayStartType(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE."); - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - int32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - int32_t ret = StartRemoteInputType(sessionId, deviceId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, start fail."); - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - DHLOGE("Could not get local device id."); - return; - } - NotifyOriginStartTypeResult(sessionId, localNetworkId, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD, inputTypes); - } -} - -void DistributedInputSourceTransport::ReceiveSrcTSrcRelayStopType(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE."); - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_DEVICE_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; - int32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - int32_t ret = StopRemoteInputType(sessionId, deviceId, inputTypes); - if (ret != DH_SUCCESS) { - DHLOGE("Can not send message by softbus, start fail."); - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - DHLOGE("Could not get local device id."); - return; - } - NotifyOriginStopTypeResult(sessionId, localNetworkId, deviceId, - ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD, inputTypes); - } -} - -void DistributedInputSourceTransport::NotifyResponseRelayStartTypeRemoteInput(int32_t sessionId, - const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ON_RELAY_STARTTYPE."); - if (!IsInt32(recMsg, DINPUT_SOFTBUS_KEY_SESSION_ID) || - !IsBoolean(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string sinkDevId = DistributedInputTransportBase::GetInstance().GetDevIdBySessionId(sessionId); - if (sinkDevId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ON_RELAY_STARTTYPE, sinkDevId is error."); - return; - } - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - DHLOGE("Could not get local device id."); - return; - } - int32_t srcTsrcSeId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; - bool result = recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - NotifyOriginStartTypeResult(srcTsrcSeId, localNetworkId, sinkDevId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD, inputTypes); -} - -void DistributedInputSourceTransport::NotifyResponseRelayStopTypeRemoteInput(int32_t sessionId, - const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_ON_RELAY_STOPTYPE."); - if (!IsInt32(recMsg, DINPUT_SOFTBUS_KEY_SESSION_ID) || - !IsBoolean(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - std::string sinkDevId = DistributedInputTransportBase::GetInstance().GetDevIdBySessionId(sessionId); - if (sinkDevId.empty()) { - DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ON_RELAY_STOPTYPE, sinkDevId is error."); - return; - } - std::string localNetworkId = GetLocalNetworkId(); - if (localNetworkId.empty()) { - DHLOGE("Could not get local device id."); - return; - } - int32_t srcTsrcSeId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; - bool result = recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - NotifyOriginStopTypeResult(srcTsrcSeId, localNetworkId, sinkDevId, - result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD, inputTypes); -} - -void DistributedInputSourceTransport::ReceiveRelayStartTypeResult(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_TO_SOURCE_MSG_START_TYPE_RESULT."); - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_SRC_DEV_ID) || - !IsString(recMsg, DINPUT_SOFTBUS_KEY_SINK_DEV_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - - std::string srcId = recMsg[DINPUT_SOFTBUS_KEY_SRC_DEV_ID]; - std::string sinkId = recMsg[DINPUT_SOFTBUS_KEY_SINK_DEV_ID]; - int32_t status = recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - callback_->OnReceiveRelayStartTypeResult(status, srcId, sinkId, inputTypes); -} - -void DistributedInputSourceTransport::ReceiveRelayStopTypeResult(int32_t sessionId, const nlohmann::json &recMsg) -{ - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_TO_SOURCE_MSG_STOP_TYPE_RESULT."); - if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_SRC_DEV_ID) || - !IsString(recMsg, DINPUT_SOFTBUS_KEY_SINK_DEV_ID) || - !IsInt32(recMsg, DINPUT_SOFTBUS_KEY_RESP_VALUE) || - !IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_INPUT_TYPE)) { - DHLOGE("The key is invaild."); - return; - } - - std::string srcId = recMsg[DINPUT_SOFTBUS_KEY_SRC_DEV_ID]; - std::string sinkId = recMsg[DINPUT_SOFTBUS_KEY_SINK_DEV_ID]; - int32_t status = recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]; - uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - callback_->OnReceiveRelayStopTypeResult(status, srcId, sinkId, inputTypes); -} - void DistributedInputSourceTransport::DInputTransbaseSourceListener::HandleSessionData(int32_t sessionId, const std::string &message) { 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 25c8d5f..1ec6d40 100644 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp +++ b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp @@ -137,22 +137,6 @@ HWTEST_F(DistributedInputSourceTransTest, UnprepareRemoteInput_04, testing::ext: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceTransTest, StartRemoteInput03, testing::ext::TestSize.Level0) { std::string deviceId = ""; @@ -191,40 +175,6 @@ HWTEST_F(DistributedInputSourceTransTest, StartRemoteInputDhids_02, testing::ext EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); } -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInputType_01, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 1; - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInputType(srcTsrcSeId, deviceId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StartRemoteInputType_02, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 1; - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().StartRemoteInputType(srcTsrcSeId, deviceId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInput01, testing::ext::TestSize.Level0) -{ - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInput02, testing::ext::TestSize.Level0) -{ - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput( - deviceId, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceTransTest, StopRemoteInput03, testing::ext::TestSize.Level0) { std::string deviceId = ""; @@ -261,24 +211,6 @@ HWTEST_F(DistributedInputSourceTransTest, StopRemoteInputDhids_02, testing::ext: EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); } -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInputType_01, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 1; - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInputType(srcTsrcSeId, deviceId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, StopRemoteInputType_02, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 1; - std::string deviceId = ""; - int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInputType(srcTsrcSeId, deviceId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); -} - HWTEST_F(DistributedInputSourceTransTest, NotifyOriginPrepareResult01, testing::ext::TestSize.Level0) { std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; @@ -321,26 +253,6 @@ HWTEST_F(DistributedInputSourceTransTest, NotifyOriginStopDhidResult01, testing: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceTransTest, NotifyOriginStartTypeResult_01, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 2; - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginStartTypeResult(srcTsrcSeId, srcId, - sinkId, DH_SUCCESS, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, NotifyOriginStopTypeResult_01, testing::ext::TestSize.Level1) -{ - int32_t srcTsrcSeId = 2; - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginStopTypeResult(srcTsrcSeId, srcId, - sinkId, DH_SUCCESS, static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceTransTest, SendRelayPrepareRequest_01, testing::ext::TestSize.Level1) { std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; @@ -384,15 +296,6 @@ HWTEST_F(DistributedInputSourceTransTest, SendRelayStartDhidRequest_01, testing: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceTransTest, SendRelayStartTypeRequest_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStartTypeRequest(srcId, sinkId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceTransTest, SendRelayStopDhidRequest_01, testing::ext::TestSize.Level1) { std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; @@ -403,15 +306,6 @@ HWTEST_F(DistributedInputSourceTransTest, SendRelayStopDhidRequest_01, testing:: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceTransTest, SendRelayStopTypeRequest_01, testing::ext::TestSize.Level1) -{ - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStopTypeRequest(srcId, sinkId, - static_cast(DInputDeviceType::ALL)); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceTransTest, LatencyCount01, testing::ext::TestSize.Level0) { std::string deviceId = "deviceId"; @@ -456,34 +350,6 @@ HWTEST_F(DistributedInputSourceTransTest, SendRelayStopDhidRequest_02, testing:: EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); } -HWTEST_F(DistributedInputSourceTransTest, SendRelayStartTypeRequest_02, testing::ext::TestSize.Level1) -{ - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::vector dhids; - dhids.push_back("Input_1ds56v18e1v21v8v1erv15r1v8r1j1ty8"); - int32_t sessionId = -1; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[srcId] = sessionId; - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStartTypeRequest(srcId, sinkId, - static_cast(DInputDeviceType::ALL)); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, SendRelayStopTypeRequest_02, testing::ext::TestSize.Level1) -{ - std::string srcId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - std::string sinkId = "networkidc08647073e02e7a78f09473aa122ff57fc81c00"; - std::vector dhids; - dhids.push_back("Input_1ds56v18e1v21v8v1erv15r1v8r1j1ty8"); - int32_t sessionId = -1; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[srcId] = sessionId; - int32_t ret = DistributedInputSourceTransport::GetInstance().SendRelayStopTypeRequest(srcId, sinkId, - static_cast(DInputDeviceType::ALL)); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); -} - HWTEST_F(DistributedInputSourceTransTest, JointDhIds01, testing::ext::TestSize.Level0) { std::vector dhids; @@ -560,50 +426,6 @@ HWTEST_F(DistributedInputSourceTransTest, NotifyResponseUnprepareRemoteInput01, EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); } -HWTEST_F(DistributedInputSourceTransTest, NotifyResponseStartRemoteInput01, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 0; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = "false"; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type"; - DistributedInputSourceTransport::GetInstance().NotifyResponseStartRemoteInput(sessionId, recMsg); - - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - DistributedInputSourceTransport::GetInstance().NotifyResponseStartRemoteInput(sessionId, recMsg); - - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().NotifyResponseStartRemoteInput(sessionId, recMsg); - std::string remoteId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[remoteId] = sessionId; - DistributedInputSourceTransport::GetInstance().NotifyResponseStartRemoteInput(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); -} - -HWTEST_F(DistributedInputSourceTransTest, NotifyResponseStopRemoteInput01, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 0; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = "false"; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type"; - DistributedInputSourceTransport::GetInstance().NotifyResponseStopRemoteInput(sessionId, recMsg); - - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - DistributedInputSourceTransport::GetInstance().NotifyResponseStopRemoteInput(sessionId, recMsg); - - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().NotifyResponseStopRemoteInput(sessionId, recMsg); - std::string remoteId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[remoteId] = sessionId; - DistributedInputSourceTransport::GetInstance().NotifyResponseStopRemoteInput(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); -} - HWTEST_F(DistributedInputSourceTransTest, NotifyResponseStartRemoteInputDhid01, testing::ext::TestSize.Level0) { int32_t sessionId = 0; @@ -904,87 +726,6 @@ HWTEST_F(DistributedInputSourceTransTest, ReceiveRelayStopDhidResult01, testing: EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); } -HWTEST_F(DistributedInputSourceTransTest, ReceiveSrcTSrcRelayStartType01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1; - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID] = 1; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type_test"; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStartType(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStartType(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStartType(sessionId, recMsg); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStartType(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, ReceiveSrcTSrcRelayStopType01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1; - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID] = 1; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type_test"; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStopType(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStopType(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStopType(sessionId, recMsg); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[deviceId] = sessionId; - DistributedInputSourceTransport::GetInstance().ReceiveSrcTSrcRelayStopType(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, NotifyResponseRelayStartTypeRemoteInput01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = "false"; - recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID] = "1"; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type_test"; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStartTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStartTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStartTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStartTypeRemoteInput(sessionId, recMsg); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear(); - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStartTypeRemoteInput(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); -} - -HWTEST_F(DistributedInputSourceTransTest, NotifyResponseRelayStopTypeRemoteInput01, testing::ext::TestSize.Level1) -{ - int32_t sessionId = 1; - std::string deviceId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591"; - nlohmann::json recMsg; - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = "false"; - recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID] = "1"; - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = "input_type_test"; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStopTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStopTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStopTypeRemoteInput(sessionId, recMsg); - recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = 1; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStopTypeRemoteInput(sessionId, recMsg); - DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[deviceId] = sessionId; - DistributedInputSourceTransport::GetInstance().NotifyResponseRelayStopTypeRemoteInput(sessionId, recMsg); - std::string message(MSG_MAX_SIZE + 1, 'a'); - int32_t ret = DistributedInputSourceTransport::GetInstance().SendMessage(sessionId, message); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE, ret); -} - HWTEST_F(DistributedInputSourceTransTest, HandleData01, testing::ext::TestSize.Level1) { int32_t sessionId = 1; diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index 5dfa229..26e0df1 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -45,6 +45,7 @@ public: int32_t RecordDhIds(const std::vector &dhIds, DhIdState state, const int32_t sessionId); int32_t RemoveDhIds(const std::vector &dhIds); DhIdState GetStateByDhid(const std::string &dhId); + std::map GetGhIdStateMap(); void AddKeyDownState(struct RawEvent event); void RemoveKeyDownState(struct RawEvent event); diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index fae078f..b82e459 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -94,6 +94,11 @@ DhIdState DInputState::GetStateByDhid(const std::string &dhId) return dhIdStateMap_[dhId]; } +std::map DInputState::GetGhIdStateMap() +{ + return dhIdStateMap_; +} + void DInputState::SimulateEventInjectToSrc(const int32_t sessionId, const std::vector &dhIds) { DHLOGI("SimulateEventInject enter, sessionId %d, dhIds size %d", sessionId, dhIds.size()); diff --git a/sinkhandler/include/distributed_input_sink_handler.h b/sinkhandler/include/distributed_input_sink_handler.h index 01171b3..d20ec32 100644 --- a/sinkhandler/include/distributed_input_sink_handler.h +++ b/sinkhandler/include/distributed_input_sink_handler.h @@ -41,10 +41,6 @@ public: int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void OnRemoteSinkSvrDied(const wptr &remote); void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); - int32_t RegisterPrivacyResources(std::shared_ptr listener) override; - int32_t PauseDistributedHardware(const std::string &networkId) override; - int32_t ResumeDistributedHardware(const std::string &networkId) override; - int32_t StopDistributedHardware(const std::string &networkId) override; public: class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub { diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index be4eeca..13ff24f 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -155,26 +155,6 @@ void DistributedInputSinkHandler::OnRemoteSinkSvrDied(const wptr dInputSinkProxy_ = nullptr; } -int32_t DistributedInputSinkHandler::RegisterPrivacyResources(std::shared_ptr listener) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputSinkHandler::PauseDistributedHardware(const std::string &networkId) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputSinkHandler::ResumeDistributedHardware(const std::string &networkId) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputSinkHandler::StopDistributedHardware(const std::string &networkId) -{ - return DH_SUCCESS; -} - IDistributedHardwareSink *GetSinkHardwareHandler() { return &DistributedInputSinkHandler::GetInstance(); diff --git a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp index 8a5e798..1f88d12 100644 --- a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -122,18 +122,6 @@ int32_t DistributedInputClient::UnprepareRemoteInput( return DH_SUCCESS; } -int32_t DistributedInputClient::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputClient::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - bool DistributedInputClient::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) { return true; diff --git a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp index ae72613..c7cd856 100644 --- a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -123,18 +123,6 @@ int32_t DistributedInputClient::UnprepareRemoteInput( return DH_SUCCESS; } -int32_t DistributedInputClient::StartRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputClient::StopRemoteInput( - const std::string &deviceId, const uint32_t &inputTypes, sptr callback) -{ - return DH_SUCCESS; -} - bool DistributedInputClient::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) { return true; diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp index 30217ec..978e4ff 100644 --- a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp +++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp @@ -31,8 +31,6 @@ #include "i_distributed_sink_input.h" #include "i_distributed_source_input.h" #include "prepare_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" #include "unprepare_d_input_call_back_stub.h" namespace OHOS { @@ -61,30 +59,6 @@ public: }; }; -class TestStartDInputCallback : -public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { -public: - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) - { - (void)devId; - (void)inputTypes; - (void)status; - }; -}; - -class TestStopDInputCallback : -public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { -public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) - { - (void)devId; - (void)inputTypes; - (void)status; - }; -}; - class TestIStartStopDInputsCallback : public OHOS::DistributedHardware ::DistributedInput::IStartStopDInputsCallback { public: @@ -122,12 +96,9 @@ void StartRemoteInputFuzzTest(const uint8_t *data, size_t size) std::string srcId = "123"; std::string sinkId = "456"; - uint32_t inputTypes = *(reinterpret_cast(data)); std::vector dhIds= {}; OHOS::sptr startCb(new (std::nothrow) TestStartDInputCallback()); OHOS::sptr stopCb(new (std::nothrow) TestStopDInputCallback()); - DistributedInput::DistributedInputKit::StartRemoteInput(sinkId, inputTypes, startCb); - DistributedInput::DistributedInputKit::StartRemoteInput(srcId, sinkId, inputTypes, startCb); OHOS::sptr callback(new (std::nothrow) TestIStartStopDInputsCallback()); DistributedInput::DistributedInputKit::StartRemoteInput(sinkId, dhIds, callback); DistributedInput::DistributedInputKit::StartRemoteInput(srcId, sinkId, dhIds, callback); @@ -158,12 +129,9 @@ void StopRemoteInputFuzzTest(const uint8_t* data, size_t size) std::string srcId = "123"; std::string sinkId = "456"; - uint32_t inputTypes = *(reinterpret_cast(data)); std::vector dhIds = {}; OHOS::sptr startCb(new (std::nothrow) TestStartDInputCallback()); OHOS::sptr stopCb(new (std::nothrow) TestStopDInputCallback()); - DistributedInput::DistributedInputKit::StopRemoteInput(sinkId, inputTypes, stopCb); - DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, inputTypes, stopCb); OHOS::sptr callback(new (std::nothrow) TestIStartStopDInputsCallback()); DistributedInput::DistributedInputKit::StopRemoteInput(sinkId, dhIds, callback); DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, dhIds, callback); @@ -196,4 +164,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::DistributedHardware::StopRemoteInputFuzzTest(data, size); OHOS::DistributedHardware::IsTouchEventNeedFilterOutFuzzTest(data, size); return 0; -} \ No newline at end of file +} -- Gitee From fa08d055e33021d11bd26ef00347b83d9f4218d8 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 24 Nov 2023 20:35:57 +0800 Subject: [PATCH 3/3] change dinput Signed-off-by: l30054665 --- .vscode/settings.json | 3 + common/include/constants_dinput.h | 8 +- common/include/dinput_errcode.h | 5 - common/include/dinput_ipc_interface_code.h | 2 - common/include/input_hub.cpp | 32 ++- common/include/input_hub.h | 5 +- .../include/i_distributed_source_input.h | 4 - .../include/distributed_input_handler.h | 3 +- .../src/distributed_input_handler.cpp | 25 +- .../distributed_input_handler_test.cpp | 5 +- .../include/distributed_input_kit.h | 2 - .../inner_kits/src/distributed_input_kit.cpp | 10 - .../unittest/distributed_input_inner_test.cpp | 28 -- .../mock/mock_distributed_input_client.cpp | 10 - .../ipc/include/distributed_input_client.h | 3 - .../include/distributed_input_source_proxy.h | 4 - .../include/distributed_input_source_stub.h | 3 - .../include/start_d_input_call_back_stub.h | 36 --- .../ipc/include/stop_d_input_call_back_stub.h | 36 --- .../ipc/src/distributed_input_client.cpp | 60 +---- .../src/distributed_input_source_proxy.cpp | 78 +----- .../ipc/src/distributed_input_source_stub.cpp | 58 +---- .../add_white_list_infos_call_back_test.h | 4 +- .../dinput_source_callback_unittest.cpp | 54 +--- .../dinput_source_callback_unittest.h | 4 - .../distributed_input_ipc_test.cpp | 28 -- .../common/include/dinput_softbus_define.h | 1 + .../include/dinput_source_trans_callback.h | 1 + .../include/distributed_input_sink_manager.h | 4 +- .../src/distributed_input_sink_manager.cpp | 42 +-- .../distributed_input_sinkmanager_test.cpp | 26 -- .../distributed_input_sink_transport.h | 2 + .../src/distributed_input_sink_transport.cpp | 40 +++ .../include/distributed_input_inject.h | 18 +- .../include/distributed_input_node_manager.h | 55 ++-- .../src/distributed_input_inject.cpp | 98 ++----- .../src/distributed_input_node_manager.cpp | 207 ++++++++------- .../source/inputinject/src/virtual_device.cpp | 4 +- .../distributed_input_sourceinject_test.cpp | 242 ++++++++---------- .../include/dinput_source_listener.h | 1 + .../distributed_input_source_manager.h | 15 +- .../src/dinput_source_listener.cpp | 22 +- .../src/distributed_input_source_manager.cpp | 115 +-------- .../distributed_input_sourcemanager_test.cpp | 52 ---- .../distributed_input_source_transport.h | 4 +- .../distributed_input_source_transport.cpp | 42 ++- services/state/src/dinput_state.cpp | 60 +++-- .../include/distributed_input_sink_handler.h | 4 + .../src/distributed_input_sink_handler.cpp | 20 ++ .../distributed_input_kit_fuzzer.cpp | 4 - utils/include/dinput_utils_tool.h | 1 + utils/src/dinput_utils_tool.cpp | 11 + 52 files changed, 531 insertions(+), 1070 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 interfaces/ipc/include/start_d_input_call_back_stub.h delete mode 100644 interfaces/ipc/include/stop_d_input_call_back_stub.h diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..70e34ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 25705dc..37d1b5c 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -48,7 +48,6 @@ namespace DistributedInput { const uint32_t SCREEN_MSG_MAX = 40 * 1024 * 1024; const uint32_t AUTH_SESSION_SIDE_SERVER = 0; const uint32_t IPC_VECTOR_MAX_SIZE = 32; - const uint32_t SIM_TOUCH_TRACKING_ID = 0x0001; const char * const DEVICE_PATH = "/dev/input"; @@ -126,6 +125,13 @@ namespace DistributedInput { const std::string DINPUT_SPLIT_COMMA = ", "; + const char VIR_NODE_SPLIT_CHAR = '|'; + const std::string VIR_NODE_SPLIT = "|"; + const std::string VIR_NODE_PID_SPLIT = "/"; + const uint32_t VIR_NODE_PHY_LEN = 3; + const uint32_t VIR_NODE_PHY_DEVID_IDX = 1; + const uint32_t VIR_NODE_PHY_DHID_IDX = 2; + const std::string SOURCE_DEVICE_ID = "sourceDevId"; const std::string SINK_DEVICE_ID = "sinkDevId"; diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index d439913..8cfa95c 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -152,13 +152,8 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL = -67032; constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL = -67033; constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WHITELIST_FAIL = -67034; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_NODE_LISTENER_FAIL = -67035; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_NODE_LISTENER_FAIL = -67036; constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL = -67037; constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL = -67038; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_SYNC_NODE_FAIL = -67039; - constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_REGISTER_NODE_LISTENER_FAIL = -67040; - constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_NODE_LISTENER_FAIL = -67041; constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL = -67042; constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL = -67043; constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67044; diff --git a/common/include/dinput_ipc_interface_code.h b/common/include/dinput_ipc_interface_code.h index e49f127..43d8db4 100644 --- a/common/include/dinput_ipc_interface_code.h +++ b/common/include/dinput_ipc_interface_code.h @@ -40,8 +40,6 @@ enum class IDInputSourceInterfaceCode : uint32_t { STOP_RELAY_DHID_REMOTE_INPUT = 0xf011U, REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT = 0xf013U, REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT = 0xf014U, - REGISTER_NODE_LISTENER = 0xf015U, - UNREGISTER_NODE_LISTENER = 0xf016U, REGISTER_SIMULATION_EVENT_LISTENER = 0xf017U, UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018U, SYNC_NODE_INFO_REMOTE_INPUT = 0xf019U, diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 922df63..049695e 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -44,7 +44,7 @@ const uint32_t SLEEP_TIME_US = 100 * 1000; const std::string MOUSE_NODE_KEY = "mouse"; } -InputHub::InputHub() : epollFd_(0), iNotifyFd_(0), inputWd_(0), needToScanDevices_(true), nextDeviceId_(1), +InputHub::InputHub() : epollFd_(0), iNotifyFd_(0), inputWd_(0), needToScanDevices_(true), mPendingEventItems{}, pendingEventCount_(0), pendingEventIndex_(0), pendingINotify_(false), deviceChanged_(false), isStartCollectEvent_(false), isStartCollectHandler_(false) { @@ -1427,20 +1427,36 @@ void InputHub::SavePressedKeyState(const InputHub::Device *dev, int32_t keyCode) dev->identifier.descriptor.c_str()); } -void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState) +bool InputHub::IsLengthExceeds(const unsigned long *keyState, const unsigned long len, int keyIndex) +{ + if (len < (keyIndex / LONG_BITS) + 1) { + DHLOGE("Length exceeds for key index: %d", keyIndex); + return true; + } + return false; +} + +void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len) { // If device is a mouse, record the mouse pressed key. if ((dev->classes & INPUT_DEVICE_CLASS_CURSOR) != 0) { + if (IsLengthExceeds(keyState, len, BTN_LEFT)) { + return; + } int mouseLeftBtnState = BitIsSet(keyState, BTN_LEFT); if (mouseLeftBtnState != 0) { SavePressedKeyState(dev, BTN_LEFT); } - + if (IsLengthExceeds(keyState, len, BTN_RIGHT)) { + return; + } int mouseRightBtnState = BitIsSet(keyState, BTN_RIGHT); if (mouseRightBtnState != 0) { SavePressedKeyState(dev, BTN_RIGHT); } - + if (IsLengthExceeds(keyState, len, BTN_MIDDLE)) { + return; + } int mouseMidBtnState = BitIsSet(keyState, BTN_MIDDLE); if (mouseMidBtnState != 0) { SavePressedKeyState(dev, BTN_MIDDLE); @@ -1450,6 +1466,9 @@ void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned l // If device is a keyboard, record all the pressed keys. if ((dev->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0) { for (int32_t keyIndex = 0; keyIndex < KEY_MAX; keyIndex++) { + if (IsLengthExceeds(keyState, len, keyIndex)) { + return; + } if (BitIsSet(keyState, keyIndex) != 0) { SavePressedKeyState(dev, keyIndex); } @@ -1458,6 +1477,9 @@ void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned l // If device is a touchscreen or touchpad, record the touch event. if ((dev->classes & INPUT_DEVICE_CLASS_TOUCH) != 0 || (dev->classes & INPUT_DEVICE_CLASS_TOUCH_MT) != 0) { + if (IsLengthExceeds(keyState, len, BTN_TOUCH)) { + return; + } int btnTouchState = BitIsSet(keyState, BTN_TOUCH); if (btnTouchState != 0) { SavePressedKeyState(dev, BTN_TOUCH); @@ -1482,7 +1504,7 @@ void InputHub::CheckTargetDevicesState(std::vector targetDevi std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS)); continue; } - CheckTargetKeyState(dev, keyState); + CheckTargetKeyState(dev, keyState, NLONGS(KEY_CNT)); break; } } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index c466a55..bab6a79 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -95,7 +95,8 @@ public: void RecordDeviceStates(); void CheckTargetDevicesState(std::vector targetDevices); - void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState); + bool IsLengthExceeds(const unsigned long *keyState, const unsigned long len, int keyIndex); + void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len); void SavePressedKeyState(const Device *dev, int32_t keyCode); void ClearDeviceStates(); private: @@ -210,9 +211,7 @@ private: std::set skipDevicePaths_; std::atomic needToScanDevices_; - std::string deviceId_; std::string touchDescriptor; - std::atomic nextDeviceId_; // The array of pending epoll events and the index of the next event to be handled. struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index cffca97..f583f1e 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -78,11 +78,7 @@ public: virtual int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback) = 0; virtual int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback) = 0; - virtual int32_t RegisterInputNodeListener(sptr listener) = 0; - virtual int32_t UnregisterInputNodeListener(sptr listener) = 0; - virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, - const std::string &nodeDesc) = 0; virtual int32_t RegisterSimulationEventListener(sptr listener) = 0; virtual int32_t UnregisterSimulationEventListener(sptr listener) = 0; virtual int32_t RegisterSessionStateCb(sptr callback) = 0; diff --git a/inputdevicehandler/include/distributed_input_handler.h b/inputdevicehandler/include/distributed_input_handler.h index 59840e6..6aeb012 100644 --- a/inputdevicehandler/include/distributed_input_handler.h +++ b/inputdevicehandler/include/distributed_input_handler.h @@ -52,7 +52,6 @@ private: DistributedInputHandler(); ~DistributedInputHandler(); void StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); - int32_t GetDeviceInfo(std::string &deviceId); std::shared_ptr m_listener; bool InitCollectEventsThread(); void NotifyHardWare(int iCnt); @@ -61,7 +60,7 @@ private: bool isCollectingEvents_; bool isStartCollectEventThread; static void *CollectEventsThread(void *param); - void StartInputMonitorDeviceThread(const std::string deviceId); + void StartInputMonitorDeviceThread(); void StopInputMonitorDeviceThread(); // The event queue. diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 3da58df..9c99d3c 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -142,21 +142,6 @@ void DistributedInputHandler::UnRegisterPluginListener() this->m_listener = nullptr; } -int32_t DistributedInputHandler::GetDeviceInfo(std::string &deviceId) -{ - std::unique_lock my_lock(operationMutex_); - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo("ohos.dhardware", localNode.get()); - if (retCode != 0) { - DHLOGE("Could not get device id."); - return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL; - } - - deviceId = localNode->networkId; - DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); - return DH_SUCCESS; -} - bool DistributedInputHandler::InitCollectEventsThread() { pthread_attr_t attr; @@ -183,15 +168,12 @@ void *DistributedInputHandler::CollectEventsThread(void *param) DHLOGE("CollectEventsThread setname failed."); } DistributedInputHandler *pThis = reinterpret_cast(param); - - std::string deviceId; - pThis->GetDeviceInfo(deviceId); - pThis->StartInputMonitorDeviceThread(deviceId); + pThis->StartInputMonitorDeviceThread(); DHLOGI("DistributedInputHandler::CollectEventsThread exist!"); return nullptr; } -void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId) +void DistributedInputHandler::StartInputMonitorDeviceThread() { if (inputHub_ == nullptr) { DHLOGE("inputHub_ not initialized"); @@ -219,7 +201,8 @@ void DistributedInputHandler::NotifyHardWare(int iCnt) if (this->m_listener != nullptr) { std::string hdInfo; StructTransJson(mEventBuffer[iCnt].deviceInfo, hdInfo); - this->m_listener->PluginHardware(mEventBuffer[iCnt].deviceInfo.descriptor, hdInfo); + std::string subtype = "input"; + this->m_listener->PluginHardware(mEventBuffer[iCnt].deviceInfo.descriptor, hdInfo, subtype); } break; case DeviceType::DEVICE_REMOVED: diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp index f5e56f6..a458f17 100644 --- a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp @@ -55,10 +55,9 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le dInputHandler.inputHub_ = nullptr; std::map datas; std::vector dhidsVec; - std::string deviceId = "deviceId_test"; dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas); dInputHandler.Query(); - dInputHandler.StartInputMonitorDeviceThread(deviceId); + dInputHandler.StartInputMonitorDeviceThread(); InputDevice inputDevice; dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED; @@ -73,7 +72,7 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le std::map ret = dInputHandler.QueryExtraInfo(); EXPECT_EQ(0, ret.size()); dInputHandler.inputHub_ = std::make_unique(); - dInputHandler.StartInputMonitorDeviceThread(deviceId); + dInputHandler.StartInputMonitorDeviceThread(); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index 9594f3b..b8979e0 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -64,8 +64,6 @@ public: */ static bool IsStartDistributedInput(const std::string &dhId); - static int32_t RegisterInputNodeListener(sptr listener); - static int32_t UnregisterInputNodeListener(sptr listener); static int32_t RegisterSimulationEventListener(sptr listener); static int32_t UnregisterSimulationEventListener(sptr listener); diff --git a/interfaces/inner_kits/src/distributed_input_kit.cpp b/interfaces/inner_kits/src/distributed_input_kit.cpp index f0c4caf..6668825 100644 --- a/interfaces/inner_kits/src/distributed_input_kit.cpp +++ b/interfaces/inner_kits/src/distributed_input_kit.cpp @@ -81,16 +81,6 @@ int32_t DistributedInputKit::StopRemoteInput(const std::string &srcId, const std return DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback); } -int32_t DistributedInputKit::RegisterInputNodeListener(sptr listener) -{ - return DistributedInputClient::GetInstance().RegisterInputNodeListener(listener); -} - -int32_t DistributedInputKit::UnregisterInputNodeListener(sptr listener) -{ - return DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener); -} - int32_t DistributedInputKit::RegisterSimulationEventListener(sptr listener) { return DistributedInputClient::GetInstance().RegisterSimulationEventListener(listener); diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp index 9dc2b07..45e14e8 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -358,34 +358,6 @@ HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput03, testing::ext::Tes EXPECT_EQ(true, ret); } -HWTEST_F(DistributedInputInnerTest, RegisterInputNodeListener01, testing::ext::TestSize.Level0) -{ - sptr listener(new TestInputNodeListener()); - int32_t ret = DistributedInputKit::RegisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, RegisterInputNodeListener02, testing::ext::TestSize.Level0) -{ - sptr listener = nullptr; - int32_t ret = DistributedInputKit::RegisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, UnregisterInputNodeListener01, testing::ext::TestSize.Level0) -{ - sptr listener(new TestInputNodeListener()); - int32_t ret = DistributedInputKit::UnregisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputInnerTest, UnregisterInputNodeListener02, testing::ext::TestSize.Level0) -{ - sptr listener = nullptr; - int32_t ret = DistributedInputKit::UnregisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputInnerTest, RegisterSimulationEventListener01, testing::ext::TestSize.Level0) { sptr listener(new TestSimulationEventListenerStub()); diff --git a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp index c7964e0..015345f 100644 --- a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp +++ b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp @@ -194,16 +194,6 @@ bool DistributedInputClient::IsStartDistributedInput(const std::string &dhId) return true; } -int32_t DistributedInputClient::RegisterInputNodeListener(sptr listener) -{ - return DH_SUCCESS; -} - -int32_t DistributedInputClient::UnregisterInputNodeListener(sptr listener) -{ - return DH_SUCCESS; -} - int32_t DistributedInputClient::RegisterSimulationEventListener(sptr listener) { return DH_SUCCESS; diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 245573d..f7a6b8b 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -89,9 +89,6 @@ public: int32_t NotifyStartDScreen(const std::string &networkId, const std::string &srcDevId, const uint64_t srcWinId); int32_t NotifyStopDScreen(const std::string &networkId, const std::string &srcScreenInfoKey); - int32_t RegisterInputNodeListener(sptr listener); - int32_t UnregisterInputNodeListener(sptr listener); - int32_t RegisterSimulationEventListener(sptr listener); int32_t UnregisterSimulationEventListener(sptr listener); diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index d723e61..a9657d7 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -64,11 +64,7 @@ public: int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback) override; int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback) override; - int32_t RegisterInputNodeListener(sptr listener) override; - int32_t UnregisterInputNodeListener(sptr listener) override; - int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, - const std::string &nodeDesc) override; int32_t RegisterSimulationEventListener(sptr listener) override; int32_t UnregisterSimulationEventListener(sptr listener) override; diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 5aa0bd9..d58e8e1 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -50,9 +50,6 @@ private: int32_t HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply); - int32_t HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply); - int32_t HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply); - int32_t HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/include/start_d_input_call_back_stub.h b/interfaces/ipc/include/start_d_input_call_back_stub.h deleted file mode 100644 index 7bdb50a..0000000 --- a/interfaces/ipc/include/start_d_input_call_back_stub.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 - -#include "iremote_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class StartDInputCallbackStub : public IRemoteStub { -public: - StartDInputCallbackStub(); - ~StartDInputCallbackStub() override; - - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - DISALLOW_COPY_AND_MOVE(StartDInputCallbackStub); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - diff --git a/interfaces/ipc/include/stop_d_input_call_back_stub.h b/interfaces/ipc/include/stop_d_input_call_back_stub.h deleted file mode 100644 index 7794ea0..0000000 --- a/interfaces/ipc/include/stop_d_input_call_back_stub.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 - -#include "iremote_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class StopDInputCallbackStub : public IRemoteStub { -public: - StopDInputCallbackStub(); - ~StopDInputCallbackStub() override; - - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - DISALLOW_COPY_AND_MOVE(StopDInputCallbackStub); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index d61cf87..e249918 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -34,7 +34,7 @@ namespace DistributedHardware { namespace DistributedInput { std::shared_ptr DistributedInputClient::instance(new DistributedInputClient()); DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), - isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false) + isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false), isGetSinkScreenInfosCbReg(false) { DHLOGI("DistributedInputClient init start"); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); @@ -160,7 +160,6 @@ void DistributedInputClient::CheckSourceRegisterCallback() isSimulationEventCbReg.load()); CheckWhiteListCallback(); - CheckNodeMonitorCallback(); CheckKeyStateCallback(); } @@ -223,19 +222,6 @@ void DistributedInputClient::CheckWhiteListCallback() } } -void DistributedInputClient::CheckNodeMonitorCallback() -{ - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("CheckNodeMonitorCallback client get source proxy fail"); - return; - } - if (!isNodeMonitorCbReg && regNodeListener_ != nullptr) { - DHLOGI("CheckNodeMonitorCallback need continue register regNodeListener_."); - DInputSAManager::GetInstance().dInputSourceProxy_->RegisterInputNodeListener(regNodeListener_); - isNodeMonitorCbReg = true; - } -} - void DistributedInputClient::CheckKeyStateCallback() { if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { @@ -519,50 +505,6 @@ bool DistributedInputClient::IsStartDistributedInput(const std::string &dhId) return sharingDhIds_.find(dhId) != sharingDhIds_.end(); } -int32_t DistributedInputClient::RegisterInputNodeListener(sptr listener) -{ - DHLOGI("RegisterInputNodeListener called"); - if (listener == nullptr) { - DHLOGE("RegisterInputNodeListener param error, client fail"); - return ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL; - } - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("RegisterInputNodeListener proxy error, client fail"); - isNodeMonitorCbReg = false; - regNodeListener_ = listener; - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - - int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterInputNodeListener(listener); - if (ret == DH_SUCCESS) { - isNodeMonitorCbReg = true; - } else { - isNodeMonitorCbReg = false; - regNodeListener_ = listener; - DHLOGE("RegisterInputNodeListener Failed, ret = %d", ret); - } - return ret; -} - -int32_t DistributedInputClient::UnregisterInputNodeListener(sptr listener) -{ - DHLOGI("UnregisterInputNodeListener called"); - if (listener == nullptr) { - DHLOGE("UnregisterInputNodeListener param error, client fail"); - return ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL; - } - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("UnregisterInputNodeListener proxy error, client fail"); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - - int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterInputNodeListener(listener); - if (ret != DH_SUCCESS) { - DHLOGE("DInputSAManager UnregisterInputNodeListener Failed, ret = %d", ret); - } - return ret; -} - int32_t DistributedInputClient::RegisterSimulationEventListener(sptr listener) { DHLOGI("RegisterSimulationEventListener called Simulation Event Listener Register."); diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index d2c8c6d..43f13af 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -174,7 +174,7 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &dev } DHLOGE("UnprepareRemoteInput end, result=%d", result); return result; - } +} int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) @@ -450,82 +450,6 @@ int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr listener) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_NODE_LISTENER_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER), - data, reply); - if (ret) { - result = reply.ReadInt32(); - } - return result; -} - -int32_t DistributedInputSourceProxy::UnregisterInputNodeListener(sptr listener) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_NODE_LISTENER_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER), - data, reply); - if (ret) { - result = reply.ReadInt32(); - } - return result; -} - -int32_t DistributedInputSourceProxy::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, - const std::string &nodeDesc) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSourceProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteString(userDevId)) { - DHLOGE("write SyncNodeInfoRemoteInput userDevId to parcel failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteString(dhid)) { - DHLOGE("write SyncNodeInfoRemoteInput dhid to parcel failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - if (!data.WriteString(nodeDesc)) { - DHLOGE("write SyncNodeInfoRemoteInput nodeDesc to parcel failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SOURCE_PROXY_SYNC_NODE_FAIL; - bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT), - data, reply); - if (ret) { - result = reply.ReadInt32(); - } - DHLOGI("SyncNodeInfoRemoteInput end, result=%d", result); - return result; -} - int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr listener) { MessageParcel data; diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 27f181a..961b504 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -57,16 +57,10 @@ void DistributedInputSourceStub::RegRespFunMap() &DistributedInputSourceStub::HandleRegisterAddWhiteListCallback; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT)] = &DistributedInputSourceStub::HandleRegisterDelWhiteListCallback; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER)] = - &DistributedInputSourceStub::HandleRegisterInputNodeListener; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER)] = - &DistributedInputSourceStub::HandleUnRegisterInputNodeListener; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER)] = &DistributedInputSourceStub::HandleRegisterSimulationEventListener; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER)] = &DistributedInputSourceStub::HandleUnregisterSimulationEventListener; - memberFuncMap_[static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT)] = - &DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB)] = &DistributedInputSourceStub::HandleRegisterSessionStateCb; memberFuncMap_[static_cast(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB)] = @@ -406,20 +400,6 @@ int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel return DH_SUCCESS; } -int32_t DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply) -{ - std::string userDevId = data.ReadString(); - std::string dhid = data.ReadString(); - std::string nodeDesc = data.ReadString(); - - int32_t ret = SyncNodeInfoRemoteInput(userDevId, dhid, nodeDesc); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleSyncNodeInfoRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - int32_t DistributedInputSourceStub::HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); @@ -450,38 +430,6 @@ int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessagePa return DH_SUCCESS; } -int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply) -{ - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleRegisterInputNodeListener failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = RegisterInputNodeListener(callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleRegisterInputNodeListener write ret failed"); - return ERR_DH_INPUT_SOURCE_STUB_REGISTER_NODE_LISTENER_FAIL; - } - - return DH_SUCCESS; -} - -int32_t DistributedInputSourceStub::HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply) -{ - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("HandleUnRegisterInputNodeListener failed, callback is nullptr."); - return ERR_DH_INPUT_POINTER_NULL; - } - int32_t ret = RegisterInputNodeListener(callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("HandleUnRegisterInputNodeListener write ret failed"); - return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_NODE_LISTENER_FAIL; - } - - return DH_SUCCESS; -} - int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); @@ -556,7 +504,13 @@ int32_t DistributedInputSourceStub::OnRemoteRequest( DHLOGE("DistributedInputSourceStub read token valid failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } + if (code == static_cast(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT)) { + DHLOGI("Receive Register DInput cmd"); + } + if (code == static_cast(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT)) { + DHLOGI("Receive UnRegister DInput cmd"); + } if (code == static_cast(IDInputSourceInterfaceCode::INIT)) { return HandleInitDistributedHardware(reply); } else if (code == static_cast(IDInputSourceInterfaceCode::RELEASE)) { diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h index 7722950..807decc 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.h @@ -32,12 +32,12 @@ #include "sharing_dhid_listener_stub.h" #include "simulation_event_listener_proxy.h" #include "simulation_event_listener_stub.h" -#include "start_d_input_call_back_proxy.h" + #include "start_stop_d_inputs_call_back_proxy.h" #include "start_stop_d_inputs_call_back_stub.h" #include "start_stop_result_call_back_proxy.h" #include "start_stop_result_call_back_stub.h" -#include "stop_d_input_call_back_proxy.h" + #include "register_d_input_call_back_proxy.h" #include "register_d_input_call_back_stub.h" diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index c5260fa..7825005 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -106,6 +106,7 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnprepareRemoteI (void)deviceId; (void)callback; return DH_SUCCESS; +} int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::PrepareRemoteInput( const std::string &srcId, const std::string &sinkId, @@ -183,30 +184,6 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterDelWhite return DH_SUCCESS; } -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterInputNodeListener( - sptr listener) -{ - (void)listener; - return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterInputNodeListener( - sptr listener) -{ - (void)listener; - return DH_SUCCESS; -} - -int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::SyncNodeInfoRemoteInput( - const std::string &userDevId, const std::string &dhid, - const std::string &nodeDesc) -{ - (void)userDevId; - (void)dhid; - (void)nodeDesc; - return DH_SUCCESS; -} - int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterSimulationEventListener( sptr listener) { @@ -485,35 +462,6 @@ HWTEST_F(DInputSourceCallBackTest, RegisterDelWhiteListCallback01, testing::ext: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DInputSourceCallBackTest, RegisterInputNodeListener01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - sptr listener(new TestDInputNodeListenerCallBack()); - int32_t ret = callBackProxy.RegisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DInputSourceCallBackTest, UnregisterInputNodeListener01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - sptr listener(new TestDInputNodeListenerCallBack()); - int32_t ret = callBackProxy.UnregisterInputNodeListener(listener); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DInputSourceCallBackTest, SyncNodeInfoRemoteInput01, testing::ext::TestSize.Level1) -{ - sptr callBackStubPtr(new TestDInputSourceCallBackStub()); - DistributedInputSourceProxy callBackProxy(callBackStubPtr); - const std::string userDevId = "a4sd654q8w7e9qwe"; - const std::string dhid = "Input_sd65f46df46s54f"; - const std::string nodeDesc = "65d4f6s54f6sd4f665d4sf6"; - int32_t ret = callBackProxy.SyncNodeInfoRemoteInput(userDevId, dhid, nodeDesc); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DInputSourceCallBackTest, RegisterSimulationEventListener01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestDInputSourceCallBackStub()); diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h index b86bca1..4854f39 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h @@ -84,11 +84,7 @@ public: int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback); int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback); - int32_t RegisterInputNodeListener(sptr listener); - int32_t UnregisterInputNodeListener(sptr listener); - int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, - const std::string &nodeDesc); int32_t RegisterSimulationEventListener(sptr listener); int32_t UnregisterSimulationEventListener(sptr listener); int32_t RegisterSessionStateCb(sptr callback); diff --git a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp index 0f0f6c7..a2314f9 100644 --- a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp +++ b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp @@ -213,34 +213,6 @@ HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput03, testing::ext::TestS EXPECT_EQ(false, ret); } -HWTEST_F(DistributedInputIpcTest, RegisterInputNodeListener01, testing::ext::TestSize.Level1) -{ - sptr listener = nullptr; - int32_t ret = DistributedInputClient::GetInstance().RegisterInputNodeListener(listener); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL, ret); -} - -HWTEST_F(DistributedInputIpcTest, RegisterInputNodeListener02, testing::ext::TestSize.Level1) -{ - sptr listener(new TestInputNodeListener()); - int32_t ret = DistributedInputClient::GetInstance().RegisterInputNodeListener(listener); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - -HWTEST_F(DistributedInputIpcTest, UnregisterInputNodeListener01, testing::ext::TestSize.Level1) -{ - sptr listener = nullptr; - int32_t ret = DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL, ret); -} - -HWTEST_F(DistributedInputIpcTest, UnregisterInputNodeListener02, testing::ext::TestSize.Level1) -{ - sptr listener(new TestInputNodeListener()); - int32_t ret = DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener); - EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); -} - HWTEST_F(DistributedInputIpcTest, RegisterSimulationEventListener01, testing::ext::TestSize.Level1) { sptr listener = nullptr; diff --git a/services/common/include/dinput_softbus_define.h b/services/common/include/dinput_softbus_define.h index 6e7140a..f8e903f 100644 --- a/services/common/include/dinput_softbus_define.h +++ b/services/common/include/dinput_softbus_define.h @@ -87,6 +87,7 @@ namespace DistributedInput { const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPDHID = 25; const uint32_t TRANS_SINK_MSG_ON_RELAY_STARTTYPE = 26; const uint32_t TRANS_SINK_MSG_ON_RELAY_STOPTYPE = 27; + const uint32_t TRANS_SINK_MSG_KEY_STATE_BATCH = 28; // src or sink const uint32_t TRANS_MSG_SRC_SINK_SPLIT = 30; diff --git a/services/common/include/dinput_source_trans_callback.h b/services/common/include/dinput_source_trans_callback.h index 33213c0..f2f5747 100644 --- a/services/common/include/dinput_source_trans_callback.h +++ b/services/common/include/dinput_source_trans_callback.h @@ -31,6 +31,7 @@ public: virtual void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) = 0; virtual void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type, const uint32_t code, const uint32_t value) = 0; + virtual void OnResponseKeyStateBatch(const std::string deviceId, const std::string &object) = 0; virtual void OnReceivedEventRemoteInput(const std::string deviceId, const std::string &object) = 0; virtual void OnResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result, diff --git a/services/sink/sinkmanager/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h index e4f70b2..d71613d 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -133,7 +133,6 @@ public: void SetStartTransFlag(const DInputServerType flag); - /* * GetEventHandler, get the ui_service manager service's handler. * @@ -176,11 +175,10 @@ private: /* * Stop dhids on cmd, * stoDhIds: dhIds on cmd - * stopIndeedDhIds: dhId that no session (retmote node) need, stop capture event. + * stopIndeedDhIds: dhId that need stop capture event. */ void DeleteStopDhids(int32_t sessionId, const std::vector stopDhIds, std::vector &stopIndeedDhIds); - bool IsStopDhidOnCmdStillNeed(int32_t sessionId, const std::string &stopDhId); }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index bf82e65..3adf769 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -153,18 +153,14 @@ void DistributedInputSinkManager::DInputSinkListener::OnUnprepareRemoteInput(con DHLOGI("OnUnprepareRemoteInput called, sessionId: %d", sessionId); std::string Dhids; std::map dhIdStateMap = DInputState::GetInstance().GetGhIdStateMap(); - if (!dhIdStateMap.empty()) - { - for (auto it : dhIdStateMap) - { - if (it.second == DhIdState::THROUGH_OUT) - { + if (!dhIdStateMap.empty()) { + for (auto it : dhIdStateMap) { + if (it.second == DhIdState::THROUGH_OUT) { Dhids.append(it.first); Dhids.append("."); } } - if (!Dhids.empty()) - { + if (!Dhids.empty()) { Dhids.pop_back(); } DHLOGI("GetGhIdStateMap success: %d", GetAnonyString(Dhids).c_str()); @@ -213,7 +209,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu { DHLOGI("OnRelayUnprepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId, GetAnonyString(deviceId).c_str()); - DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId); nlohmann::json jsonStr; @@ -359,24 +354,6 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput } } -bool DistributedInputSinkManager::IsStopDhidOnCmdStillNeed(int32_t sessionId, const std::string &stopDhId) -{ - for (auto sessionDhid : sharingDhIdsMap_) { - if (sessionDhid.first == sessionId) { - DHLOGW("IsStopDhidOnCmdStillNeed sessionId=%d is self, ignore.", sessionId); - continue; - } - for (auto dhid : sessionDhid.second) { - if (stopDhId == dhid) { - DHLOGI("IsStopDhidOnCmdStillNeed stopDhId=%s is find in session: %d", GetAnonyString(stopDhId).c_str(), - sessionDhid.first); - return true; - } - } - } - DHLOGW("IsStopDhidOnCmdStillNeed stopDhId=%s is not find.", GetAnonyString(stopDhId).c_str()); - return false; -} void DistributedInputSinkManager::DeleteStopDhids(int32_t sessionId, const std::vector stopDhIds, std::vector &stopIndeedDhIds) @@ -397,13 +374,10 @@ void DistributedInputSinkManager::DeleteStopDhids(int32_t sessionId, const std:: } else { DHLOGI("DeleteStopDhids sessionId=%d after has dhid.size=%d.", sessionId, sharingDhIdsMap_[sessionId].size()); } - // find which dhid can be stop - for (auto tmp : stopDhIds) { - bool isFind = IsStopDhidOnCmdStillNeed(sessionId, tmp); - if (!isFind) { - stopIndeedDhIds.push_back(tmp); - sharingDhIds_.erase(tmp); - } + + stopIndeedDhIds.assign(stopDhIds.begin(), stopDhIds.end()); + for (auto &id : stopDhIds) { + sharingDhIds_.erase(id); } } diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp index 5783c87..2fcac66 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp @@ -117,31 +117,6 @@ HWTEST_F(DistributedInputSinkManagerTest, GetStartTransFlag, testing::ext::TestS EXPECT_EQ(flag, retFlag); } -HWTEST_F(DistributedInputSinkManagerTest, IsStopDhidOnCmdStillNeed01, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 1; - std::vector dhIds; - dhIds.push_back("Input_123123123123"); - dhIds.push_back("Input_456456456456"); - dhIds.push_back("Input_789789789789"); - sinkManager_->StoreStartDhids(100, dhIds); - std::set dhIdSet; - dhIdSet.insert("Input_123123123123"); - sinkManager_->sharingDhIdsMap_[sessionId] = dhIdSet; - sinkManager_->StoreStartDhids(sessionId, dhIds); - std::string stopDhId = "Input_123123123123"; - bool ret = sinkManager_->IsStopDhidOnCmdStillNeed(sessionId, stopDhId); - EXPECT_EQ(true, ret); -} - -HWTEST_F(DistributedInputSinkManagerTest, IsStopDhidOnCmdStillNeed02, testing::ext::TestSize.Level0) -{ - int32_t sessionId = 1000; - std::string stopDhId = "Input_123123123123"; - bool ret = sinkManager_->IsStopDhidOnCmdStillNeed(sessionId, stopDhId); - EXPECT_EQ(false, ret); -} - HWTEST_F(DistributedInputSinkManagerTest, DeleteStopDhids01, testing::ext::TestSize.Level0) { int32_t sessionId = 1; @@ -157,7 +132,6 @@ HWTEST_F(DistributedInputSinkManagerTest, DeleteStopDhids01, testing::ext::TestS EXPECT_EQ(0, sinkManager_->sharingDhIdsMap_.size()); } - HWTEST_F(DistributedInputSinkManagerTest, GetSinkScreenInfosCbackSize01, testing::ext::TestSize.Level0) { uint32_t ret = sinkManager_->GetSinkScreenInfosCbackSize(); diff --git a/services/sink/transport/include/distributed_input_sink_transport.h b/services/sink/transport/include/distributed_input_sink_transport.h index 00db596..de9b050 100644 --- a/services/sink/transport/include/distributed_input_sink_transport.h +++ b/services/sink/transport/include/distributed_input_sink_transport.h @@ -60,6 +60,7 @@ public: int32_t RespLatency(const int32_t sessionId, std::string &smsg); void SendKeyStateNodeMsg(const int32_t sessionId, const std::string &dhId, uint32_t type, const uint32_t btnCode, int32_t value); + void SendKeyStateNodeMsgBatch(const int32_t sessionId, const std::vector &events); class DInputSinkEventHandler : public AppExecFwk::EventHandler { public: @@ -89,6 +90,7 @@ private: void NotifyRelayStopDhidRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void RecordEventLog(const std::string &dhId, int32_t type, int32_t code, int32_t value); + void RecordEventLog(const std::vector &events); private: std::string mySessionName_; std::shared_ptr eventHandler_; diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index 9905d50..67a2052 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -225,6 +225,46 @@ void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId, RecordEventLog(dhId, type, btnCode, value); } +void DistributedInputSinkTransport::SendKeyStateNodeMsgBatch(const int32_t sessionId, + const std::vector &events) +{ + if (sessionId <= 0) { + DHLOGE("SendKeyStateNodeMsgBatch error, sessionId <= 0."); + return; + } + DHLOGI("SendKeyStateNodeMsgBatch sessionId: %d, event size: %d ", sessionId, events.size()); + + int64_t currentTimeNs = GetCurrentTime() * 1000LL; + std::shared_ptr eventsJsonArr = std::make_shared(); + for (const auto &ev : events) { + nlohmann::json tmpJson; + tmpJson[INPUT_KEY_WHEN] = currentTimeNs; + tmpJson[INPUT_KEY_TYPE] = ev.type; + tmpJson[INPUT_KEY_CODE] = ev.code; + tmpJson[INPUT_KEY_VALUE] = ev.value; + tmpJson[INPUT_KEY_DESCRIPTOR] = ev.descriptor; + tmpJson[INPUT_KEY_PATH] = ev.path; + eventsJsonArr->push_back(tmpJson); + } + + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_KEY_STATE_BATCH; + jsonStr[DINPUT_SOFTBUS_KEY_INPUT_DATA] = eventsJsonArr->dump(); + std::string msg = jsonStr.dump(); + int32_t ret = SendMessage(sessionId, msg); + if (ret != DH_SUCCESS) { + DHLOGE("SendKeyStateNodeMsgBatch error, SendMessage fail."); + } + RecordEventLog(events); +} + +void DistributedInputSinkTransport::RecordEventLog(const std::vector &events) +{ + for (auto &ev : events) { + RecordEventLog(ev.descriptor, ev.type, ev.code, ev.value); + } +} + void DistributedInputSinkTransport::RecordEventLog(const std::string &dhId, int32_t type, int32_t code, int32_t value) { std::string eventType; diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index c0e6a40..a4534b8 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -34,7 +34,7 @@ public: int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const std::string ¶meters); int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId); - int32_t RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize); + int32_t RegisterDistributedEvent(const std::string &devId, const std::vector &events); int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); void StartInjectThread(); void StopInjectThread(); @@ -42,28 +42,20 @@ public: const uint32_t sourceWinHeight); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); - int32_t RegisterInputNodeListener(sptr listener); - int32_t UnregisterInputNodeListener(sptr listener); int32_t RegisterInjectEventCb(sptr callback); int32_t UnregisterInjectEventCb(); - void NotifyNodeMgrScanVirNode(const std::string &dhId); - void InputDeviceEventInject(const std::shared_ptr &rawEvent); - void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); - void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId, - const std::string &sinkNodeDesc); - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds); + void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); + void GetVirtualKeyboardPaths(const std::string &devId, const std::vector &dhIds, + std::vector &virKeyboardPaths); private: DistributedInputInject(); ~DistributedInputInject(); std::unique_ptr inputNodeManager_; std::mutex inputNodeManagerMutex_; - std::set> inputNodeListeners_; - std::mutex inputNodeListenersMutex_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index a857543..e28b0e8 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -37,7 +37,19 @@ namespace DistributedHardware { namespace DistributedInput { constexpr uint32_t DINPUT_NODE_MANAGER_SCAN_ALL_NODE = 1; constexpr uint32_t DINPUT_INJECT_EVENT_FAIL = 2; +const std::string INPUT_NODE_DEVID = "devId"; const std::string INPUT_NODE_DHID = "dhId"; +/** + * @brief the unique id for the input peripheral. + * left is device networkid, right is dhId in that device. + */ +using DhUniqueID = std::pair; +/** + * @brief a batch events form one device + * left: device networid where these events from + * right: the event batch + */ +using EventBatch = std::pair>; class DistributedInputNodeManager { public: DistributedInputNodeManager(); @@ -45,23 +57,28 @@ public: int32_t OpenDevicesNode(const std::string &devId, const std::string &dhId, const std::string ¶meters); - int32_t GetDevice(const std::string &dhId, VirtualDevice *&device); - void ReportEvent(const RawEvent rawEvent); - int32_t CloseDeviceLocked(const std::string &dhId); + int32_t GetDevice(const std::string &devId, const std::string &dhId, VirtualDevice *&device); + void ReportEvent(const std::string &devId, const std::vector &events); + int32_t CloseDeviceLocked(const std::string &devId, const std::string &dhId); void StartInjectThread(); void StopInjectThread(); int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); - int32_t RemoveVirtualTouchScreenNode(const std::string &dhId); + int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId); int32_t GetVirtualTouchScreenFd(); - int32_t GetDeviceInfo(std::string &deviceId); - void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); - void ProcessInjectEvent(const std::shared_ptr &rawEvent); - - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds); - void NotifyNodeMgrScanVirNode(const std::string &dhId); + void ProcessInjectEvent(const EventBatch &events); + + /** + * @brief Get the Virtual Keyboard Paths By Dh Ids object + * + * @param dhKeys list for device identify({networkId, dhId}) + * @param virKeyboardPaths the matched keyboard device + * @param virKeyboardDhIds matched keyboard device identify + */ + void GetVirtualKeyboardPaths(const std::vector &dhUniqueIds, + std::vector &virKeyboardPaths); + void NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId); void RegisterInjectEventCb(sptr callback); void UnregisterInjectEventCb(); @@ -82,7 +99,7 @@ public: }; private: - void AddDeviceLocked(const std::string &dhId, std::unique_ptr device); + void AddDeviceLocked(const std::string &networkId, const std::string &dhId, std::unique_ptr device); int32_t CreateHandle(const InputDevice &inputDevice, const std::string &devId, const std::string &dhId); void ParseInputDeviceJson(const std::string &str, InputDevice &pBuf); void ParseInputDevice(const nlohmann::json &inputDeviceJson, InputDevice &pBuf); @@ -90,15 +107,15 @@ private: void ParseInputDeviceEvents(const nlohmann::json &inputDeviceJson, InputDevice &pBuf); void InjectEvent(); - void ScanSinkInputDevices(const std::string &dhId); - void OpenInputDevice(const std::string &devicePath, const std::string &dhId); + void ScanSinkInputDevices(const std::string &devId, const std::string &dhId); + bool MatchAndSavePhysicalPath(const std::string &devicePath, const std::string &devId, const std::string &dhId); bool IsVirtualDev(int fd); - bool GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath); - void SetPathForDevMap(const std::string &dhId, const std::string &devicePath); + bool GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnqueId, std::string &physicalPath); + void SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath); void RunInjectEventCallback(const std::string &dhId, const uint32_t injectEvent); - /* the key is dhId, and the value is virtualDevice */ - std::map> virtualDeviceMap_; + /* the key is {networkId, dhId}, and the value is virtualDevice */ + std::map> virtualDeviceMap_; std::mutex virtualDeviceMapMutex_; std::atomic isInjectThreadCreated_; std::atomic isInjectThreadRunning_; @@ -106,7 +123,7 @@ private: std::thread eventInjectThread_; std::mutex injectThreadMutex_; std::condition_variable conditionVariable_; - std::queue> injectQueue_; + std::queue injectQueue_; std::unique_ptr inputHub_; int32_t virtualTouchScreenFd_; std::once_flag callOnceFlag_; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 66fb2c1..8f53ecf 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -61,12 +61,7 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string &d return ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL; } - std::string srcDevId; - inputNodeManager_->GetDeviceInfo(srcDevId); - DHLOGI("RegisterDistributedHardware called, device type = source, source networkId = %s, sink networkId = %s", - GetAnonyString(srcDevId).c_str(), GetAnonyString(devId).c_str()); - - SyncNodeOnlineInfo(srcDevId, devId, dhId, GetNodeDesc(parameters)); + DHLOGI("RegisterDistributedHardware success"); return DH_SUCCESS; } @@ -79,32 +74,12 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string DHLOGE("the DistributedInputNodeManager is null\n"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - if (inputNodeManager_->CloseDeviceLocked(dhId) < 0) { + if (inputNodeManager_->CloseDeviceLocked(devId, dhId) < 0) { DHLOGE("delete virtual device error\n"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL; } - std::string srcDevId; - inputNodeManager_->GetDeviceInfo(srcDevId); - - DHLOGI("UnregisterDistributedHardware called, device = %s, dhId = %s, OnNodeOffLine", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - SyncNodeOfflineInfo(srcDevId, devId, dhId); - - return DH_SUCCESS; -} - -int32_t DistributedInputInject::RegisterInputNodeListener(sptr listener) -{ - std::lock_guard lock(inputNodeListenersMutex_); - this->inputNodeListeners_.insert(listener); - return DH_SUCCESS; -} - -int32_t DistributedInputInject::UnregisterInputNodeListener(sptr listener) -{ - std::lock_guard lock(inputNodeListenersMutex_); - this->inputNodeListeners_.erase(listener); + DHLOGI("UnregisterDistributedHardware success"); return DH_SUCCESS; } @@ -135,53 +110,16 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st return DH_SUCCESS; } -void DistributedInputInject::InputDeviceEventInject(const std::shared_ptr &rawEvent) -{ - std::lock_guard lock(inputNodeManagerMutex_); - if (inputNodeManager_ == nullptr) { - DHLOGE("the inputNodeListener is nullptr"); - return; - } - if (rawEvent == nullptr) { - DHLOGE("the rawEvent is nullptr"); - return; - } - inputNodeManager_->ProcessInjectEvent(rawEvent); -} - -void DistributedInputInject::SyncNodeOnlineInfo(const std::string &srcDevId, - const std::string &sinkDevId, const std::string &sinkNodeId, const std::string &sinkNodeDesc) -{ - std::lock_guard lock(inputNodeListenersMutex_); - DHLOGI("SyncVirNodeOnlineInfo, srcId: %s, sinkId: %s, dhId: %s", GetAnonyString(srcDevId).c_str(), - GetAnonyString(sinkDevId).c_str(), GetAnonyString(sinkNodeId).c_str()); - for (const auto &listener : inputNodeListeners_) { - listener->OnNodeOnLine(srcDevId, sinkDevId, sinkNodeId, sinkNodeDesc); - } -} - -void DistributedInputInject::SyncNodeOfflineInfo(const std::string &srcDevId, - const std::string &sinkDevId, const std::string &sinkNodeId) -{ - std::lock_guard lock(inputNodeListenersMutex_); - DHLOGI("SyncVirNodeOfflineInfo, srcId: %s, sinkId: %s, dhId: %s", GetAnonyString(srcDevId).c_str(), - GetAnonyString(sinkDevId).c_str(), GetAnonyString(sinkNodeId).c_str()); - for (const auto &listener : inputNodeListeners_) { - listener->OnNodeOffLine(srcDevId, sinkDevId, sinkNodeId); - } -} - -int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize) +int32_t DistributedInputInject::RegisterDistributedEvent(const std::string &devId, + const std::vector &events) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("the DistributedInputNodeManager is null"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - DHLOGI("RegisterDistributedEvent start %zu\n", bufferSize); - for (size_t i = 0; i < bufferSize; i++) { - inputNodeManager_->ReportEvent(buffer[i]); - } + + inputNodeManager_->ReportEvent(devId, events); return DH_SUCCESS; } @@ -220,14 +158,14 @@ int32_t DistributedInputInject::CreateVirtualTouchScreenNode(const std::string & return inputNodeManager_->CreateVirtualTouchScreenNode(devId, dhId, srcWinId, sourcePhyWidth, sourcePhyHeight); } -int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &dhId) +int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; } - return inputNodeManager_->RemoveVirtualTouchScreenNode(dhId); + return inputNodeManager_->RemoveVirtualTouchScreenNode(devId, dhId); } int32_t DistributedInputInject::GetVirtualTouchScreenFd() @@ -256,26 +194,32 @@ int32_t DistributedInputInject::UnregisterInjectEventCb() return DH_SUCCESS; } -void DistributedInputInject::GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds) +void DistributedInputInject::GetVirtualKeyboardPaths(const std::string &devId, + const std::vector &dhIds, std::vector &virKeyboardPaths) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return; } - inputNodeManager_->GetVirtualKeyboardPathsByDhIds(dhIds, virKeyboardPaths, virKeyboardDhIds); + std::vector dhUniqIds; + std::for_each(dhIds.begin(), dhIds.end(), + [&devId, &dhUniqIds](std::string dhId) { + DhUniqueID id = {devId, dhId}; + dhUniqIds.push_back(id); + }); + inputNodeManager_->GetVirtualKeyboardPaths(dhUniqIds, virKeyboardPaths); } -void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &dhId) +void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("inputNodeManager is nullptr"); return; } - inputNodeManager_->NotifyNodeMgrScanVirNode(dhId); + inputNodeManager_->NotifyNodeMgrScanVirNode(devId, dhId); } } // namespace DistributedInput } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index aeab8e2..2c59710 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -152,13 +152,17 @@ void DistributedInputNodeManager::ParseInputDeviceEvents(const nlohmann::json &i } } -void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &dhId) +void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &devId, const std::string &dhId) { - DHLOGI("ScanSinkInputDevices enter, dhId %s.", dhId.c_str()); + DHLOGI("ScanSinkInputDevices enter, deviceId: %s, dhId: %s.", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::vector vecInputDevPath; ScanInputDevicesPath(DEVICE_PATH, vecInputDevPath); for (auto &tempPath: vecInputDevPath) { - OpenInputDevice(tempPath, dhId); + if (MatchAndSavePhysicalPath(tempPath, devId, dhId)) { + DHLOGI("Set physical path success"); + break; + } } } @@ -197,15 +201,17 @@ void DistributedInputNodeManager::DInputNodeManagerEventHandler::ScanAllNode( std::shared_ptr dataMsg = event->GetSharedObject(); auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); + std::string devId = innerMsg[INPUT_NODE_DEVID]; std::string devicedhId = innerMsg[INPUT_NODE_DHID]; - nodeManagerObj_->ScanSinkInputDevices(devicedhId); + nodeManagerObj_->ScanSinkInputDevices(devId, devicedhId); } -void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &dhId) +void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &devId, const std::string &dhId) { DHLOGI("NotifyNodeMgrScanVirNode enter."); std::shared_ptr jsonArrayMsg = std::make_shared(); nlohmann::json tmpJson; + tmpJson[INPUT_NODE_DEVID] = devId; tmpJson[INPUT_NODE_DHID] = dhId; jsonArrayMsg->push_back(tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get( @@ -232,7 +238,7 @@ bool DistributedInputNodeManager::IsVirtualDev(int fd) return true; } -bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath) +bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnqueId, std::string &physicalPath) { char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { @@ -242,23 +248,32 @@ bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string &dhId, std: buffer[sizeof(buffer) - 1] = '\0'; physicalPath = buffer; - DHLOGD("GetDevDhIdByFd physicalPath %s.", physicalPath.c_str()); - dhId = physicalPath.substr(physicalPath.find(DH_ID_PREFIX)); - if (dhId.size() == 0) { - DHLOGE("Get dev dhid failed."); + DHLOGD("GetDevDhUniqueIdByFd physicalPath %s.", physicalPath.c_str()); + std::vector phyPathVec; + SplitStringToVector(physicalPath, VIR_NODE_SPLIT_CHAR, phyPathVec); + if (phyPathVec.size() != VIR_NODE_PHY_LEN) { + DHLOGE("The physical path is invalid"); return false; } - DHLOGD("Device dhId %s.", GetAnonyString(dhId).c_str()); + std::string devId = phyPathVec[VIR_NODE_PHY_DEVID_IDX]; + std::string dhId = phyPathVec[VIR_NODE_PHY_DHID_IDX]; + if (devId.empty() || dhId.empty()) { + DHLOGE("Get dev deviceid and dhid failed."); + return false; + } + dhUnqueId.first = devId; + dhUnqueId.second = dhId; + DHLOGD("Device deviceid: %s, dhId %s.", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return true; } -void DistributedInputNodeManager::SetPathForDevMap(const std::string &dhId, const std::string &devicePath) +void DistributedInputNodeManager::SetPathForVirDev(const DhUniqueID &dhUniqueId, const std::string &devicePath) { std::lock_guard lock(virtualDeviceMapMutex_); auto iter = virtualDeviceMap_.begin(); while (iter != virtualDeviceMap_.end()) { - DHLOGD("Virtual device map dhid %s.", iter->first.c_str()); - if (dhId.compare(iter->first) == 0) { + DHLOGD("Check Virtual device, deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str()); + if (iter->first == dhUniqueId) { DHLOGD("Found the virtual device, set path :%s", devicePath.c_str()); iter->second->SetPath(devicePath); break; @@ -267,45 +282,59 @@ void DistributedInputNodeManager::SetPathForDevMap(const std::string &dhId, cons } } -void DistributedInputNodeManager::OpenInputDevice(const std::string &devicePath, const std::string &dhId) +bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &devicePath, + const std::string &devId, const std::string &dhId) { DHLOGI("Opening input device path: %s", devicePath.c_str()); - std::string curDhId; + DhUniqueID curDhUniqueId; std::string physicalPath; int fd = OpenInputDeviceFdByPath(devicePath); if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); - return; + return false; } if (!IsVirtualDev(fd)) { DHLOGE("The dev not virtual, devicePath %s.", devicePath.c_str()); - return; + CloseFd(fd); + return false; } - if (!GetDevDhIdByFd(fd, curDhId, physicalPath) || dhId != curDhId) { - DHLOGE("This is not same dev, curDhId %s.", devicePath.c_str()); - return; + if (!GetDevDhUniqueIdByFd(fd, curDhUniqueId, physicalPath)) { + DHLOGE("Get unique id failed, device path %s.", devicePath.c_str()); + CloseFd(fd); + return false; + } + + DHLOGD("This opening node deviceId: %s, dhId: %s, to match node deviceId: %s, dhId: %s", + GetAnonyString(curDhUniqueId.first).c_str(), GetAnonyString(curDhUniqueId.second).c_str(), + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + + if (curDhUniqueId.first != devId || curDhUniqueId.second != dhId) { + DHLOGW("It is not the target vir node, skip it."); + CloseFd(fd); + return false; } - DHLOGD("curDhId %s.", GetAnonyString(curDhId).c_str()); - SetPathForDevMap(curDhId, devicePath); + + SetPathForVirDev(curDhUniqueId, devicePath); + CloseFd(fd); + return true; } -void DistributedInputNodeManager::GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, - std::vector &virKeyboardPaths, std::vector &virKeyboardDhIds) +void DistributedInputNodeManager::GetVirtualKeyboardPaths(const std::vector &dhUniqueIds, + std::vector &virKeyboardPaths) { std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &dhId : dhIds) { + for (const auto &dhUniqueId : dhUniqueIds) { auto iter = virtualDeviceMap_.begin(); while (iter != virtualDeviceMap_.end()) { if (iter->second == nullptr) { DHLOGE("device is nullptr"); continue; } - if ((iter->first.compare(dhId) == 0) && + if ((iter->first == dhUniqueId) && ((iter->second->GetClasses() & INPUT_DEVICE_CLASS_KEYBOARD) != 0)) { - DHLOGI("Found vir keyboard path %s, dhid %s", iter->second->GetPath().c_str(), - GetAnonyString(dhId).c_str()); + DHLOGI("Found vir keyboard path %s, deviceId %s, dhid %s", iter->second->GetPath().c_str(), + GetAnonyString(dhUniqueId.first).c_str(), GetAnonyString(dhUniqueId.second).c_str()); virKeyboardPaths.push_back(iter->second->GetPath()); - virKeyboardDhIds.push_back(dhId); } iter++; } @@ -325,7 +354,7 @@ int32_t DistributedInputNodeManager::CreateHandle(const InputDevice &inputDevice DHLOGE("could not create new virtual device\n"); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } - AddDeviceLocked(inputDevice.descriptor, std::move(virtualDevice)); + AddDeviceLocked(devId, inputDevice.descriptor, std::move(virtualDevice)); return DH_SUCCESS; } @@ -344,14 +373,14 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } virtualTouchScreenFd_ = device->GetDeviceFd(); - AddDeviceLocked(dhId, std::move(device)); + AddDeviceLocked(devId, dhId, std::move(device)); DHLOGI("CreateVirtualTouchScreenNode end, dhId: %s", GetAnonyString(dhId).c_str()); return DH_SUCCESS; } -int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &dhId) +int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId) { - return CloseDeviceLocked(dhId); + return CloseDeviceLocked(devId, dhId); } int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd() @@ -359,34 +388,43 @@ int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd() return virtualTouchScreenFd_; } -void DistributedInputNodeManager::AddDeviceLocked(const std::string &dhId, std::unique_ptr device) +void DistributedInputNodeManager::AddDeviceLocked(const std::string &networkId, const std::string &dhId, + std::unique_ptr device) { - DHLOGI("dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("AddDeviceLocked deviceId=%s, dhId=%s", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); - auto [dev_it, inserted] = virtualDeviceMap_.insert_or_assign(dhId, std::move(device)); + auto [dev_it, inserted] = virtualDeviceMap_.insert_or_assign( + {networkId, dhId}, std::move(device)); if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", GetAnonyString(dhId).c_str()); + DHLOGI("Device exists, deviceId=%s, dhId=%s, replaced. \n", + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); } } -int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId) +int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &devId, const std::string &dhId) { - DHLOGI("CloseDeviceLocked called, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called, deviceId=%s, dhId=%s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); - std::map>::iterator iter = virtualDeviceMap_.find(dhId); + DhUniqueID dhUniqueId = {devId, dhId}; + std::map>::iterator iter = virtualDeviceMap_.find(dhUniqueId); if (iter != virtualDeviceMap_.end()) { - DHLOGI("CloseDeviceLocked called success, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called success, deviceId=%s, dhId=%s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); virtualDeviceMap_.erase(iter); return DH_SUCCESS; } - DHLOGE("CloseDeviceLocked called failure, dhId=%s", GetAnonyString(dhId).c_str()); + DHLOGE("CloseDeviceLocked called failure, deviceId=%s, dhId=%s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } -int32_t DistributedInputNodeManager::GetDevice(const std::string &dhId, VirtualDevice *&device) +int32_t DistributedInputNodeManager::GetDevice(const std::string &devId, const std::string &dhId, + VirtualDevice *&device) { std::lock_guard lock(virtualDeviceMapMutex_); - auto iter = virtualDeviceMap_.find(dhId); + auto iter = virtualDeviceMap_.find({devId, dhId}); if (iter != virtualDeviceMap_.end()) { device = iter->second.get(); return DH_SUCCESS; @@ -420,10 +458,10 @@ void DistributedInputNodeManager::StopInjectThread() } } -void DistributedInputNodeManager::ReportEvent(const RawEvent rawEvent) +void DistributedInputNodeManager::ReportEvent(const std::string &devId, const std::vector &events) { std::lock_guard lockGuard(injectThreadMutex_); - injectQueue_.push(std::make_shared(rawEvent)); + injectQueue_.push({devId, events}); conditionVariable_.notify_all(); } @@ -435,7 +473,7 @@ void DistributedInputNodeManager::InjectEvent() } DHLOGI("start"); while (isInjectThreadRunning_.load()) { - std::shared_ptr event = nullptr; + EventBatch events; { std::unique_lock waitEventLock(injectThreadMutex_); conditionVariable_.wait(waitEventLock, @@ -443,16 +481,12 @@ void DistributedInputNodeManager::InjectEvent() if (injectQueue_.empty()) { continue; } - event = injectQueue_.front(); + events = injectQueue_.front(); injectQueue_.pop(); } - if (event == nullptr) { - DHLOGD("event is null!"); - continue; - } DHLOGD("process event, inject queue size: %zu", injectQueue_.size()); - ProcessInjectEvent(event); + ProcessInjectEvent(events); } DHLOGI("end"); } @@ -479,51 +513,26 @@ void DistributedInputNodeManager::RunInjectEventCallback(const std::string &dhId SessionStateCallback_->OnResult(dhId, DINPUT_INJECT_EVENT_FAIL); } -void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptr &rawEvent) -{ - std::string dhId = rawEvent->descriptor; - struct input_event event = { - .type = rawEvent->type, - .code = rawEvent->code, - .value = rawEvent->value - }; - DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", - GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); - VirtualDevice* device = nullptr; - if (GetDevice(dhId, device) < 0) { - DHLOGE("could not find the device"); - return; - } - if (device != nullptr) { - device->InjectInputEvent(event); - } -} - -int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &deviceId) -{ - std::unique_lock my_lock(operationMutex_); - auto localNode = std::make_unique(); - int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get()); - if (retCode != 0) { - DHLOGE("Could not get device id."); - return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL; - } - - deviceId = localNode->networkId; - DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); - return DH_SUCCESS; -} - -void DistributedInputNodeManager::GetDevicesInfoByDhId( - std::vector dhidsVec, std::map &datas) -{ - for (auto dhId : dhidsVec) { - std::lock_guard lock(virtualDeviceMapMutex_); - for (const auto &[id, virdevice] : virtualDeviceMap_) { - if (id == dhId) { - datas.insert(std::pair(virdevice->GetDeviceFd(), id)); - break; - } +void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events) +{ + std::string deviceId = events.first; + for (const auto &rawEvent : events.second) { + std::string dhId = rawEvent.descriptor; + struct input_event event = { + .type = rawEvent.type, + .code = rawEvent.code, + .value = rawEvent.value + }; + DHLOGI("InjectEvent deviceId: %s, dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", + GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str(), + event.type, event.code, event.value, rawEvent.when); + VirtualDevice* device = nullptr; + if (GetDevice(deviceId, dhId, device) < 0) { + DHLOGE("could not find the device"); + return; + } + if (device != nullptr) { + device->InjectInputEvent(event); } } } diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index 799890e..f75dcbf 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -110,8 +110,8 @@ void VirtualDevice::SetABSInfo(struct uinput_user_dev &inputUserDev, const Input bool VirtualDevice::SetPhys(const std::string &deviceName, const std::string &dhId) { std::string phys; - phys.append(deviceName).append(pid_).append("/").append(pid_).append("|") - .append(netWorkId_).append("|").append(dhId); + phys.append(deviceName).append(pid_).append(VIR_NODE_PID_SPLIT).append(pid_).append(VIR_NODE_SPLIT) + .append(netWorkId_).append(VIR_NODE_SPLIT).append(dhId); if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) { return false; diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index fef98b8..43f2c16 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -160,146 +160,132 @@ HWTEST_F(DistributedInputSourceInjectTest, UnregisterDistributedHardware_002, te HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent01, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 1; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 2; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 1; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - event += 1; - - event->when = 3; - event->type = EV_KEY; - event->code = KEY_D; - event->value = 0; - event->descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); + RawEvent event1 = { + .when = 0, + .type = EV_KEY, + .code = KEY_D, + .value = 1, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" + }; + RawEvent event2 = { + .when = 1, + .type = EV_KEY, + .code = KEY_D, + .value = 0, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" + }; + RawEvent event3 = { + .when = 2, + .type = EV_KEY, + .code = KEY_D, + .value = 1, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" + }; + RawEvent event4 = { + .when = 3, + .type = EV_KEY, + .code = KEY_D, + .value = 0, + .descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d" + }; + std::vector writeBuffer = { event1, event2, event3, event4 }; + DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); DistributedInputInject::GetInstance().StartInjectThread(); DistributedInputInject::GetInstance().StopInjectThread(); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent02, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 1; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 2; - event->type = EV_REL; - event->code = REL_X; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - event += 1; - - event->when = 3; - event->type = EV_REL; - event->code = REL_Y; - event->value = 2; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - event->when = 4; - event->type = EV_SYN; - event->code = SYN_REPORT; - event->value = 0; - event->descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + RawEvent event1 = { + .when = 0, + .type = EV_REL, + .code = REL_X, + .value = 2, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" + }; + RawEvent event2 = { + .when = 1, + .type = EV_REL, + .code = REL_Y, + .value = 2, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" + }; + RawEvent event3 = { + .when = 2, + .type = EV_REL, + .code = REL_X, + .value = 3, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" + }; + RawEvent event4 = { + .when = 3, + .type = EV_REL, + .code = REL_Y, + .value = 3, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" + }; + RawEvent event5 = { + .when = 4, + .type = EV_SYN, + .code = SYN_REPORT, + .value = 0, + .descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18" + }; + std::vector writeBuffer = { event1, event2, event3, event4, event5 }; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent03, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - RawEvent* event = writeBuffer; - - event->when = 0; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 1; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 1; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 2; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 2; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 3; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - event += 1; - - event->when = 3; - event->type = EV_ABS; - event->code = ABS_X; - event->value = 4; - event->descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + RawEvent event1 = { + .when = 0, + .type = EV_ABS, + .code = ABS_X, + .value = 1, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" + }; + RawEvent event2 = { + .when = 1, + .type = EV_ABS, + .code = ABS_X, + .value = 2, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" + }; + RawEvent event3 = { + .when = 2, + .type = EV_ABS, + .code = ABS_X, + .value = 3, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" + }; + RawEvent event4 = { + .when = 3, + .type = EV_ABS, + .code = ABS_X, + .value = 4, + .descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8" + }; + std::vector writeBuffer = { event1, event2, event3, event4 }; + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent04, testing::ext::TestSize.Level1) { - struct RawEvent writeBuffer[4]; - size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); + std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18"; + std::vector writeBuffer(4); DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); + int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); } -HWTEST_F(DistributedInputSourceInjectTest, RegisterInputNodeListener, testing::ext::TestSize.Level1) -{ - inputNodelistener_ = (std::make_unique()).release(); - int32_t ret = DistributedInputInject::GetInstance().RegisterInputNodeListener(inputNodelistener_); - EXPECT_EQ(DH_SUCCESS, ret); -} - -HWTEST_F(DistributedInputSourceInjectTest, UnRegisterInputNodeListener, testing::ext::TestSize.Level1) -{ - int32_t ret = DistributedInputInject::GetInstance().UnregisterInputNodeListener(inputNodelistener_); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSourceInjectTest, GenerateVirtualTouchScreenDHId_001, testing::ext::TestSize.Level1) { std::string ret = DistributedInputInject::GetInstance().GenerateVirtualTouchScreenDHId(1, 1860, 980); @@ -323,8 +309,9 @@ HWTEST_F(DistributedInputSourceInjectTest, GetVirtualTouchScreenFd_001, testing: HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_001, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(DH_SUCCESS, ret); } @@ -339,9 +326,10 @@ HWTEST_F(DistributedInputSourceInjectTest, CreateVirtualTouchScreenNode_002, tes HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_002, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; DistributedInputInject::GetInstance().inputNodeManager_ = nullptr; - int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret); } @@ -365,16 +353,18 @@ HWTEST_F(DistributedInputSourceInjectTest, CreateVirtualTouchScreenNode_003, tes HWTEST_F(DistributedInputSourceInjectTest, RemoveVirtualTouchScreenNode_003, testing::ext::TestSize.Level1) { + std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->RemoveVirtualTouchScreenNode(dhId); + int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->RemoveVirtualTouchScreenNode(devId, dhId); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSourceInjectTest, GetDevice_001, testing::ext::TestSize.Level1) { + std::string deviceId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; VirtualDevice* device = nullptr; - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDevice(dhId, device); + int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDevice(deviceId, dhId, device); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_GET_DEVICE_FAIL, ret); } @@ -415,14 +405,6 @@ HWTEST_F(DistributedInputSourceInjectTest, OpenDevicesNode_002, testing::ext::Te ret = DistributedInputInject::GetInstance().inputNodeManager_->OpenDevicesNode(devId, dhIdtest, param); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL, ret); } - -HWTEST_F(DistributedInputSourceInjectTest, GetDeviceInfo_001, testing::ext::TestSize.Level1) -{ - std::string deviceId = ""; - DistributedInputInject::GetInstance().inputNodeManager_->InjectEvent(); - int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDeviceInfo(deviceId); - EXPECT_EQ(DH_SUCCESS, ret); -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/sourcemanager/include/dinput_source_listener.h b/services/source/sourcemanager/include/dinput_source_listener.h index 40e4854..0312441 100644 --- a/services/source/sourcemanager/include/dinput_source_listener.h +++ b/services/source/sourcemanager/include/dinput_source_listener.h @@ -50,6 +50,7 @@ public: 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 OnResponseKeyStateBatch(const std::string deviceId, const std::string &event) 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; diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index f74fc9b..d298a9d 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -162,11 +162,7 @@ public: int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback) override; int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback) override; - int32_t RegisterInputNodeListener(sptr listener) override; - int32_t UnregisterInputNodeListener(sptr listener) override; - int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId, - const std::string &nodeDesc) override; int32_t RegisterSimulationEventListener(sptr listener) override; int32_t UnregisterSimulationEventListener(sptr listener) override; @@ -216,9 +212,6 @@ public: void OnMessage(const DHTopic topic, const std::string &message) override; - private: - void DeleteNodeInfoAndNotify(const std::string &offlineDevId); - private: DistributedInputSourceManager *sourceManagerContext_; }; @@ -367,8 +360,6 @@ private: sptr deviceOfflineListener_ = nullptr; std::mutex valMutex_; - std::mutex syncNodeInfoMutex_; - std::map> syncNodeInfoMap_; int32_t RelayPrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback); @@ -379,11 +370,7 @@ private: int32_t RelayStopRemoteInputByDhid(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, sptr callback); bool IsStringDataSame(const std::vector &oldDhIds, std::vector newDhIds); - void DeleteNodeInfoAndNotify(const std::string &offlineDevId); - void SendExistVirNodeInfos(sptr listener); - std::set GetSyncNodeInfo(const std::string &devId); - void UpdateSyncNodeInfo(const std::string &devId, const std::string &dhId, const std::string &nodeDesc); - void DeleteSyncNodeInfo(const std::string &devId); + void UnregisterDHFwkPublisher(); }; } // namespace DistributedInput diff --git a/services/source/sourcemanager/src/dinput_source_listener.cpp b/services/source/sourcemanager/src/dinput_source_listener.cpp index af681ee..0eed823 100644 --- a/services/source/sourcemanager/src/dinput_source_listener.cpp +++ b/services/source/sourcemanager/src/dinput_source_listener.cpp @@ -267,24 +267,31 @@ void DInputSourceListener::OnResponseKeyState(const std::string deviceId, sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } -void DInputSourceListener::OnReceivedEventRemoteInput( - const std::string deviceId, const std::string &event) + +void DInputSourceListener::OnResponseKeyStateBatch(const std::string deviceId, const std::string &event) +{ + DHLOGI("OnResponseKeyStateBatch events, deviceId: %s.", GetAnonyString(deviceId).c_str()); + OnReceivedEventRemoteInput(deviceId, event); +} + +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]; + size_t jsonSize = inputData.size(); + DHLOGI("OnReceivedEventRemoteInput called, deviceId: %s, json size:%d.", + GetAnonyString(deviceId).c_str(), jsonSize); + + std::vector mEventBuffer(jsonSize); int idx = 0; for (auto it = inputData.begin(); it != inputData.end(); ++it) { nlohmann::json oneData = (*it); @@ -304,7 +311,8 @@ void DInputSourceListener::OnReceivedEventRemoteInput( oneData[INPUT_KEY_VALUE], oneData[INPUT_KEY_PATH]); ++idx; } - DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize); + + DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, mEventBuffer); } void DInputSourceListener::OnReceiveRelayPrepareResult(int32_t status, diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 4275df6..5bc905e 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -300,17 +300,8 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st // 4.notify source distributedfwk register hardware success callback->OnResult(devId, dhId, DH_SUCCESS); - // 5. notify remote side that this side is registerd remote dhid - sptr cli = DInputSourceSACliMgr::GetInstance().GetRemoteCli(devId); - if (cli == nullptr) { - DHLOGE("Get Remote DInput Source Proxy return null"); - return DH_SUCCESS; - } - - cli->SyncNodeInfoRemoteInput(GetLocalNetworkId(), dhId, GetNodeDesc(parameters)); - - // 6. Notify node mgr to scan vir dev node info - DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(dhId); + // 5. Notify node mgr to scan vir dev node info + DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(devId, dhId); return DH_SUCCESS; } @@ -895,41 +886,6 @@ int32_t DistributedInputSourceManager::RegisterDelWhiteListCallback(sptr listener) -{ - DHLOGI("RegisterInputNodeListener."); - if (listener == nullptr) { - DHLOGE("RegisterInputNodeListener callback is null."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR; - } - DistributedInputInject::GetInstance().RegisterInputNodeListener(listener); - SendExistVirNodeInfos(listener); - return DH_SUCCESS; -} - -int32_t DistributedInputSourceManager::UnregisterInputNodeListener(sptr listener) -{ - DHLOGI("UnregisterInputNodeListener."); - if (listener == nullptr) { - DHLOGE("UnregisterInputNodeListener callback is null."); - return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR; - } - DistributedInputInject::GetInstance().UnregisterInputNodeListener(listener); - return DH_SUCCESS; -} - -void DistributedInputSourceManager::SendExistVirNodeInfos(sptr listener) -{ - DHLOGI("SendExistVirNodeInfos call"); - std::lock_guard lock(operationMutex_); - DevInfo localDevInfo = GetLocalDeviceInfo(); - for (const auto &node : inputDevice_) { - DHLOGI("Send Exist Vir Node: srcId: %s, sinkId: %s, dhId: %s", GetAnonyString(localDevInfo.networkId).c_str(), - GetAnonyString(node.devId).c_str(), GetAnonyString(node.dhId).c_str()); - listener->OnNodeOnLine(localDevInfo.networkId, node.devId, node.dhId, node.nodeDesc); - } -} - int32_t DistributedInputSourceManager::RegisterSimulationEventListener(sptr listener) { DHLOGI("RegisterSimulationEventListener called."); @@ -971,16 +927,6 @@ int32_t DistributedInputSourceManager::UnregisterSessionStateCb() return DH_SUCCESS; } -int32_t DistributedInputSourceManager::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId, - const std::string &nodeDesc) -{ - // store info - UpdateSyncNodeInfo(userDevId, dhId, nodeDesc); - // notify multimodal - DistributedInputInject::GetInstance().SyncNodeOnlineInfo(userDevId, GetLocalNetworkId(), dhId, nodeDesc); - return DH_SUCCESS; -} - int32_t DistributedInputSourceManager::RelayPrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { @@ -1313,7 +1259,8 @@ void DistributedInputSourceManager::RunKeyStateCallback(const std::string &sinkI mEventBuffer.code = code; mEventBuffer.value = value; mEventBuffer.descriptor = dhId; - DistributedInputInject::GetInstance().RegisterDistributedEvent(&mEventBuffer, DINPUT_SOURCE_WRITE_EVENT_SIZE); + std::vector eventBuffers = {mEventBuffer}; + DistributedInputInject::GetInstance().RegisterDistributedEvent(sinkId, eventBuffers); return; } @@ -1372,34 +1319,6 @@ void DistributedInputSourceManager::ClearResourcesStatus() relayUnpreCallbacks_.clear(); } -std::set DistributedInputSourceManager::GetSyncNodeInfo(const std::string &devId) -{ - std::lock_guard lock(syncNodeInfoMutex_); - if (syncNodeInfoMap_.find(devId) == syncNodeInfoMap_.end()) { - DHLOGI("syncNodeInfoMap find not the key: %s", GetAnonyString(devId).c_str()); - return {}; - } - return syncNodeInfoMap_[devId]; -} - -void DistributedInputSourceManager::UpdateSyncNodeInfo(const std::string &userDevId, const std::string &dhId, - const std::string &nodeDesc) -{ - std::lock_guard lock(syncNodeInfoMutex_); - if (syncNodeInfoMap_.find(userDevId) == syncNodeInfoMap_.end()) { - DHLOGI("syncNodeInfoMap has not the key: %s, So create this entry", GetAnonyString(userDevId).c_str()); - std::set syncNodeInfo; - syncNodeInfoMap_[userDevId] = syncNodeInfo; - } - syncNodeInfoMap_[userDevId].insert({userDevId, dhId, nodeDesc}); -} - -void DistributedInputSourceManager::DeleteSyncNodeInfo(const std::string &devId) -{ - std::lock_guard lock(syncNodeInfoMutex_); - syncNodeInfoMap_.erase(devId); -} - void DistributedInputSourceManager::StartDScreenListener::OnMessage(const DHTopic topic, const std::string &message) { DHLOGI("StartDScreenListener OnMessage!"); @@ -1532,7 +1451,7 @@ void DistributedInputSourceManager::StopDScreenListener::OnMessage(const DHTopic SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(screenInfoKey); int32_t removeNodeRes = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode( - srcScreenInfo.sourcePhyId); + sourceDevId, srcScreenInfo.sourcePhyId); if (removeNodeRes != DH_SUCCESS) { DHLOGE("Remove virtual touch screen node failed!"); return; @@ -1590,26 +1509,6 @@ void DistributedInputSourceManager::DeviceOfflineListener::OnMessage(const DHTop DHLOGE("this message is empty"); return; } - DeleteNodeInfoAndNotify(message); -} - -void DistributedInputSourceManager::DeviceOfflineListener::DeleteNodeInfoAndNotify(const std::string &offlineDevId) -{ - DHLOGI("DeviceOfflineListener DeleteNodeInfoAndNotify!"); - if (sourceManagerContext_ == nullptr) { - DHLOGE("sourceManagerContext is nullptr!"); - return; - } - std::set nodeSet = sourceManagerContext_->GetSyncNodeInfo(offlineDevId); - std::string localNetWorkId = GetLocalNetworkId(); - for (const auto &node : nodeSet) { - DHLOGI("DeleteNodeInfoAndNotify device: %s, dhId: %s", GetAnonyString(offlineDevId).c_str(), - GetAnonyString(node.dhId).c_str()); - // Notify multimodal - DistributedInputInject::GetInstance().SyncNodeOfflineInfo(offlineDevId, localNetWorkId, node.dhId); - } - // Delete info - sourceManagerContext_->DeleteSyncNodeInfo(offlineDevId); } DistributedInputSourceManager::DScreenSourceSvrRecipient::DScreenSourceSvrRecipient(const std::string &srcDevId, @@ -1631,9 +1530,9 @@ void DistributedInputSourceManager::DScreenSourceSvrRecipient::OnRemoteDied(cons } std::string screenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcDevId_, srcWinId_); SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(screenInfoKey); - + std::string sourceDevId = GetLocalNetworkId(); int32_t removeNodeRes = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode( - srcScreenInfo.sourcePhyId); + sourceDevId, srcScreenInfo.sourcePhyId); if (removeNodeRes != DH_SUCCESS) { DHLOGE("Remove virtual touch screen node failed!"); return; diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp index 8f39a38..b210a88 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -41,7 +41,6 @@ using namespace std; namespace OHOS { namespace DistributedHardware { namespace DistributedInput { - void DistributedInputSourceManagerTest::SetUp() { sourceManager_ = new DistributedInputSourceManager(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true); @@ -819,16 +818,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDelWhiteListCallback02, test EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSourceManagerTest, RegisterInputNodeListener_01, testing::ext::TestSize.Level1) -{ - sptr callback = nullptr; - int32_t ret = sourceManager_->RegisterInputNodeListener(callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR, ret); - - ret = sourceManager_->UnregisterInputNodeListener(callback); - EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR, ret); -} - HWTEST_F(DistributedInputSourceManagerTest, RegisterSimulationEventListener_01, testing::ext::TestSize.Level1) { sptr callback = nullptr; @@ -1257,47 +1246,6 @@ HWTEST_F(DistributedInputSourceManagerTest, GetDeviceMapAllDevSwitchOff_02, test EXPECT_EQ(false, ret); } -HWTEST_F(DistributedInputSourceManagerTest, GetSyncNodeInfo_01, testing::ext::TestSize.Level1) -{ - std::string userDevId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "input_slkdiek3kddkeojfe"; - std::string nodeDesc = "input_deviceid:umkyu1b165e1be98151891erbe8r91ev, input_dhid:slkdiek3kddkeojfe"; - sourceManager_->syncNodeInfoMap_[userDevId].insert({userDevId, dhId, nodeDesc}); - std::string devId = "sd6f4s6d5f46s5d4f654564sdfdfsdfsdfd55"; - sourceManager_->GetSyncNodeInfo(devId); - EXPECT_EQ(1, sourceManager_->GetSyncNodeInfo(userDevId).size()); -} - -HWTEST_F(DistributedInputSourceManagerTest, UpdateSyncNodeInfo_01, testing::ext::TestSize.Level1) -{ - std::string userDevId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "input_slkdiek3kddkeojfe"; - std::string nodeDesc = "input_deviceid:umkyu1b165e1be98151891erbe8r91ev, input_dhid:slkdiek3kddkeojfe"; - sourceManager_->syncNodeInfoMap_[userDevId].insert({userDevId, dhId, nodeDesc}); - sourceManager_->UpdateSyncNodeInfo(userDevId, dhId, nodeDesc); - EXPECT_EQ(1, sourceManager_->syncNodeInfoMap_.size()); -} - -HWTEST_F(DistributedInputSourceManagerTest, UpdateSyncNodeInfo_02, testing::ext::TestSize.Level1) -{ - std::string userDevId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "input_slkdiek3kddkeojfe"; - std::string nodeDesc = "input_deviceid:umkyu1b165e1be98151891erbe8r91ev, input_dhid:slkdiek3kddkeojfe"; - sourceManager_->syncNodeInfoMap_.clear(); - sourceManager_->UpdateSyncNodeInfo(userDevId, dhId, nodeDesc); - EXPECT_EQ(1, sourceManager_->syncNodeInfoMap_.size()); -} - -HWTEST_F(DistributedInputSourceManagerTest, DeleteSyncNodeInfo_01, testing::ext::TestSize.Level1) -{ - std::string userDevId = "umkyu1b165e1be98151891erbe8r91ev"; - std::string dhId = "input_slkdiek3kddkeojfe"; - std::string nodeDesc = "input_deviceid:umkyu1b165e1be98151891erbe8r91ev, input_dhid:slkdiek3kddkeojfe"; - sourceManager_->syncNodeInfoMap_[userDevId].insert({userDevId, dhId, nodeDesc}); - sourceManager_->DeleteSyncNodeInfo(userDevId); - EXPECT_EQ(0, sourceManager_->syncNodeInfoMap_.size()); -} - HWTEST_F(DistributedInputSourceManagerTest, Dump_01, testing::ext::TestSize.Level1) { int32_t fd = 1; diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index 84c8f3a..030b57c 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -93,6 +93,7 @@ private: void NotifyResponseStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg); void NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg); + void NotifyResponseKeyStateBatch(int32_t sessionId, const nlohmann::json &recMsg); void NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void ReceiveSrcTSrcRelayPrepare(int32_t sessionId, const nlohmann::json &recMsg); void ReceiveSrcTSrcRelayUnprepare(int32_t sessionId, const nlohmann::json &recMsg); @@ -116,9 +117,10 @@ private: void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg); std::string JointDhIds(const std::vector &dhids); + std::vector SplitDhIdString(const std::string &dhIdsString); void RegRespFunMap(); - void ResetKeyboardKeyState(const std::vector &dhids); + void ResetKeyboardKeyState(const std::string &deviceId, const std::vector &dhids); private: std::mutex operationMutex_; std::set sessionIdSet_; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index af00a93..25b16ff 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -39,7 +39,9 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { - +namespace { + const char DHID_SPLIT = '.'; +} DistributedInputSourceTransport::~DistributedInputSourceTransport() { DHLOGI("Dtor DistributedInputSourceTransport"); @@ -77,6 +79,7 @@ void DistributedInputSourceTransport::RegRespFunMap() memberFuncMap_[TRANS_SINK_MSG_DHID_ONSTART] = &DistributedInputSourceTransport::NotifyResponseStartRemoteInputDhid; memberFuncMap_[TRANS_SINK_MSG_DHID_ONSTOP] = &DistributedInputSourceTransport::NotifyResponseStopRemoteInputDhid; memberFuncMap_[TRANS_SINK_MSG_KEY_STATE] = &DistributedInputSourceTransport::NotifyResponseKeyState; + memberFuncMap_[TRANS_SINK_MSG_KEY_STATE_BATCH] = &DistributedInputSourceTransport::NotifyResponseKeyStateBatch; memberFuncMap_[TRANS_SOURCE_TO_SOURCE_MSG_PREPARE] = &DistributedInputSourceTransport::ReceiveSrcTSrcRelayPrepare; memberFuncMap_[TRANS_SINK_MSG_ON_RELAY_PREPARE] = &DistributedInputSourceTransport::NotifyResponseRelayPrepareRemoteInput; @@ -308,6 +311,8 @@ int32_t DistributedInputSourceTransport::StopRemoteInputDhids(int32_t srcTsrcSeI return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; } DHLOGI("StopRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId); + std::vector dhIdsVec = SplitDhIdString(dhids); + ResetKeyboardKeyState(deviceId, dhIdsVec); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID_FOR_REL; @@ -584,13 +589,13 @@ int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &dev return DH_SUCCESS; } -void DistributedInputSourceTransport::ResetKeyboardKeyState(const std::vector &dhids) +void DistributedInputSourceTransport::ResetKeyboardKeyState(const std::string &deviceId, + const std::vector &dhids) { std::vector keyboardNodePaths; - std::vector keyboardNodeDhIds; - DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); + DistributedInputInject::GetInstance().GetVirtualKeyboardPaths(deviceId, dhids, keyboardNodePaths); DHLOGI("Try reset keyboard states, dhIds: %s, nodePaths: %s", - GetString(keyboardNodeDhIds).c_str(), GetString(keyboardNodePaths).c_str()); + GetString(dhids).c_str(), GetString(keyboardNodePaths).c_str()); ResetVirtualDevicePressedKeys(keyboardNodePaths); } @@ -603,7 +608,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; } DHLOGI("StopRemoteInput sessionId:%d.", sessionId); - ResetKeyboardKeyState(dhids); + ResetKeyboardKeyState(deviceId, dhids); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; @@ -679,10 +684,17 @@ std::string DistributedInputSourceTransport::JointDhIds(const std::vector DistributedInputSourceTransport::SplitDhIdString(const std::string &dhIdsString) +{ + std::vector dhIdsVec; + SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec); + return dhIdsVec; +} + int32_t DistributedInputSourceTransport::SendMessage(int32_t sessionId, std::string &message) { return DistributedInputTransportBase::GetInstance().SendMsg(sessionId, message); @@ -796,6 +808,22 @@ void DistributedInputSourceTransport::NotifyResponseKeyState(int32_t sessionId, recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE]); } +void DistributedInputSourceTransport::NotifyResponseKeyStateBatch(int32_t sessionId, const nlohmann::json &recMsg) +{ + DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE_BATCH."); + if (!IsString(recMsg, DINPUT_SOFTBUS_KEY_INPUT_DATA)) { + DHLOGE("The DINPUT_SOFTBUS_KEY_INPUT_DATA is invalid"); + return; + } + std::string deviceId = DistributedInputTransportBase::GetInstance().GetDevIdBySessionId(sessionId); + if (deviceId.empty()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE_BATCH, deviceId is error."); + return; + } + std::string inputDataStr = recMsg[DINPUT_SOFTBUS_KEY_INPUT_DATA]; + callback_->OnResponseKeyStateBatch(deviceId, inputDataStr); +} + void DistributedInputSourceTransport::NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) { DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA."); diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index b82e459..8a3338f 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -135,35 +135,41 @@ void DInputState::SimulateEventInjectToSrc(const int32_t sessionId, const std::v void DInputState::SimulateBtnTouchEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) { - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_ABS, ABS_MT_TRACKING_ID, SIM_TOUCH_TRACKING_ID); + int32_t simTrackingId = GetRandomInt32(); + std::vector simEvents; + RawEvent touchTrackingIdEv = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + simEvents.push_back(touchTrackingIdEv); + std::pair absPos = GetAndClearABSPosition(event.descriptor); if (absPos.first != -1) { - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_ABS, ABS_MT_POSITION_X, absPos.first); + RawEvent absMTXEv = { event.when, EV_ABS, ABS_MT_POSITION_X, absPos.first, dhId, event.path }; + simEvents.push_back(absMTXEv); } if (absPos.second != -1) { - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_ABS, ABS_MT_POSITION_Y, absPos.second); + RawEvent absMTYEv = { event.when, EV_ABS, ABS_MT_POSITION_Y, absPos.second, dhId, event.path }; + simEvents.push_back(absMTYEv); } - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_KEY, event.code, KEY_DOWN_STATE); - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE); + RawEvent keyDownEv = { event.when, EV_KEY, event.code, KEY_DOWN_STATE, dhId, event.path }; + simEvents.push_back(keyDownEv); + RawEvent fingerEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE, dhId, event.path }; + simEvents.push_back(fingerEv); if (absPos.first != -1) { - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_ABS, ABS_X, absPos.first); + RawEvent absXEv = { event.when, EV_ABS, ABS_X, absPos.first, dhId, event.path }; + simEvents.push_back(absXEv); } if (absPos.second != -1) { - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_ABS, ABS_Y, absPos.second); + RawEvent absYEv = { event.when, EV_ABS, ABS_Y, absPos.second, dhId, event.path }; + simEvents.push_back(absYEv); } - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_MSC, MSC_TIMESTAMP, 0x0); - DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId, - EV_SYN, SYN_REPORT, 0x0); + + RawEvent mscEv = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + simEvents.push_back(mscEv); + RawEvent sycReportEv = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + simEvents.push_back(sycReportEv); + + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(sessionId, simEvents); } void DInputState::SimulateNormalEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) @@ -230,14 +236,26 @@ void DInputState::CheckAndSetLongPressedKeyOrder(struct RawEvent event) std::lock_guard mapLock(keyDownStateMapMtx_); auto iter = keyDownStateMap_.find(event.descriptor); if (iter == keyDownStateMap_.end()) { + DHLOGI("Find new pressed key, save it, node id: %s, type: %d, key code: %d, value: %d", + event.descriptor.c_str(), event.type, event.code, event.value); + keyDownStateMap_[event.descriptor].push_back(event); return; } auto evIter = std::find(keyDownStateMap_[event.descriptor].begin(), keyDownStateMap_[event.descriptor].end(), event); - // If not find the cache key on pressing, or it is already the last one, just return - if (evIter == keyDownStateMap_[event.descriptor].end() || - evIter == (keyDownStateMap_[event.descriptor].end() - 1)) { + // If not find the cache key on pressing, save it + if (evIter == keyDownStateMap_[event.descriptor].end()) { + DHLOGI("Find new pressed key, save it, node id: %s, type: %d, key code: %d, value: %d", + event.descriptor.c_str(), event.type, event.code, event.value); + keyDownStateMap_[event.descriptor].push_back(event); + return; + } + + // it is already the last one, just return + if (evIter == (keyDownStateMap_[event.descriptor].end() - 1)) { + DHLOGI("Pressed key already last one, node id: %s, type: %d, key code: %d, value: %d", + event.descriptor.c_str(), event.type, event.code, event.value); return; } diff --git a/sinkhandler/include/distributed_input_sink_handler.h b/sinkhandler/include/distributed_input_sink_handler.h index d20ec32..01171b3 100644 --- a/sinkhandler/include/distributed_input_sink_handler.h +++ b/sinkhandler/include/distributed_input_sink_handler.h @@ -41,6 +41,10 @@ public: int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void OnRemoteSinkSvrDied(const wptr &remote); void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); + int32_t RegisterPrivacyResources(std::shared_ptr listener) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; public: class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub { diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index 13ff24f..be4eeca 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -155,6 +155,26 @@ void DistributedInputSinkHandler::OnRemoteSinkSvrDied(const wptr dInputSinkProxy_ = nullptr; } +int32_t DistributedInputSinkHandler::RegisterPrivacyResources(std::shared_ptr listener) +{ + return DH_SUCCESS; +} + +int32_t DistributedInputSinkHandler::PauseDistributedHardware(const std::string &networkId) +{ + return DH_SUCCESS; +} + +int32_t DistributedInputSinkHandler::ResumeDistributedHardware(const std::string &networkId) +{ + return DH_SUCCESS; +} + +int32_t DistributedInputSinkHandler::StopDistributedHardware(const std::string &networkId) +{ + return DH_SUCCESS; +} + IDistributedHardwareSink *GetSinkHardwareHandler() { return &DistributedInputSinkHandler::GetInstance(); diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp index 978e4ff..33028a6 100644 --- a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp +++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp @@ -97,8 +97,6 @@ void StartRemoteInputFuzzTest(const uint8_t *data, size_t size) std::string srcId = "123"; std::string sinkId = "456"; std::vector dhIds= {}; - OHOS::sptr startCb(new (std::nothrow) TestStartDInputCallback()); - OHOS::sptr stopCb(new (std::nothrow) TestStopDInputCallback()); OHOS::sptr callback(new (std::nothrow) TestIStartStopDInputsCallback()); DistributedInput::DistributedInputKit::StartRemoteInput(sinkId, dhIds, callback); DistributedInput::DistributedInputKit::StartRemoteInput(srcId, sinkId, dhIds, callback); @@ -130,8 +128,6 @@ void StopRemoteInputFuzzTest(const uint8_t* data, size_t size) std::string srcId = "123"; std::string sinkId = "456"; std::vector dhIds = {}; - OHOS::sptr startCb(new (std::nothrow) TestStartDInputCallback()); - OHOS::sptr stopCb(new (std::nothrow) TestStopDInputCallback()); OHOS::sptr callback(new (std::nothrow) TestIStartStopDInputsCallback()); DistributedInput::DistributedInputKit::StopRemoteInput(sinkId, dhIds, callback); DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, dhIds, callback); diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 3176520..b41e564 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -65,6 +65,7 @@ void ScanInputDevicesPath(const std::string &dirName, std::vector & void ResetVirtualDevicePressedKeys(const std::vector &nodePaths); std::string GetString(const std::vector &vec); +int32_t GetRandomInt32(); } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 9eb87b7..bb0b59c 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -15,8 +15,11 @@ #include "dinput_utils_tool.h" +#include #include #include +#include + #include #include #include @@ -439,6 +442,14 @@ std::string GetString(const std::vector &vec) retStr += "]"; return retStr; } + +int32_t GetRandomInt32() +{ + std::default_random_engine engine(time(nullptr)); + + std::uniform_int_distribution distribution(0, INT32_MAX); + return distribution(engine); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee