From 957219bb92d7f91d39746885f65a450a78d5506d Mon Sep 17 00:00:00 2001 From: xxxx Date: Tue, 23 Aug 2022 18:30:22 +0800 Subject: [PATCH] Description: add input funcs part II Match-id-29b54c981942d34dd7daee7e9130d99a158def3f --- common/include/constants_dinput.h | 6 + common/include/dinput_errcode.h | 81 +- common/include/dinput_struct_data.cpp | 57 + common/include/dinput_struct_data.h | 38 + common/include/idinput_dbg_itf.h | 35 + common/include/input_hub.cpp | 133 +- common/include/input_hub.h | 18 +- common/include/white_list_util.cpp | 15 +- dfx_utils/BUILD.gn | 1 + dfx_utils/src/hidumper.cpp | 4 +- .../include/i_distributed_source_input.h | 62 +- frameworks/include/i_input_node_listener.h | 42 + .../include/i_simulation_event_listener.h | 40 + .../include/i_start_stop_d_inputs_call_back.h | 40 + .../include/i_start_stop_result_call_back.h | 45 + inputdevicehandler/BUILD.gn | 1 + .../include/distributed_input_handler.h | 20 +- .../src/distributed_input_handler.cpp | 41 +- interfaces/inner_kits/BUILD.gn | 11 + .../include/distributed_input_kit.h | 37 +- .../inner_kits/src/distributed_input_kit.cpp | 88 +- interfaces/inner_kits/test/unittest/BUILD.gn | 9 + .../unittest/distributed_input_inner_test.cpp | 80 ++ .../mock/mock_distributed_input_client.cpp | 12 + interfaces/ipc/include/dinput_sa_manager.h | 14 +- .../ipc/include/distributed_input_client.h | 62 +- .../include/distributed_input_sink_proxy.h | 1 - .../include/distributed_input_source_proxy.h | 40 +- .../include/distributed_input_source_stub.h | 15 + .../ipc/include/input_node_listener_proxy.h | 47 + .../ipc/include/input_node_listener_stub.h | 42 + .../include/simulation_event_listener_proxy.h | 43 + .../include/simulation_event_listener_stub.h | 42 + .../start_stop_d_inputs_call_back_proxy.h | 41 + .../start_stop_d_inputs_call_back_stub.h | 40 + .../start_stop_result_call_back_proxy.h | 45 + .../start_stop_result_call_back_stub.h | 41 + interfaces/ipc/src/dinput_sa_manager.cpp | 20 +- .../ipc/src/distributed_input_client.cpp | 408 +++++- .../ipc/src/distributed_input_sink_proxy.cpp | 1 + .../ipc/src/distributed_input_sink_stub.cpp | 2 +- .../src/distributed_input_source_proxy.cpp | 519 +++++++- .../ipc/src/distributed_input_source_stub.cpp | 299 ++++- .../ipc/src/input_node_listener_proxy.cpp | 104 ++ .../ipc/src/input_node_listener_stub.cpp | 62 + .../src/simulation_event_listener_proxy.cpp | 72 ++ .../src/simulation_event_listener_stub.cpp | 58 + .../start_stop_d_inputs_call_back_proxy.cpp | 65 + .../start_stop_d_inputs_call_back_stub.cpp | 54 + .../src/start_stop_result_call_back_proxy.cpp | 124 ++ .../src/start_stop_result_call_back_stub.cpp | 74 ++ .../include/dinput_sink_trans_callback.h | 3 + .../common/include/dinput_softbus_define.h | 17 +- .../include/dinput_source_trans_callback.h | 4 + .../include/distributed_input_collector.h | 5 +- .../src/distributed_input_collector.cpp | 22 +- .../include/distributed_input_sink_manager.h | 19 +- .../src/distributed_input_sink_manager.cpp | 272 +++- .../distributed_input_sinkmanager_test.cpp | 7 + .../distributed_input_sink_transport.h | 7 +- .../src/distributed_input_sink_transport.cpp | 116 +- .../distributed_input_sinktrans_test.cpp | 6 + services/source/inputinject/BUILD.gn | 7 + .../include/distributed_input_inject.h | 16 + .../include/distributed_input_node_manager.h | 6 +- .../inputinject/include/virtual_device.h | 12 +- .../src/distributed_input_inject.cpp | 93 +- .../src/distributed_input_node_manager.cpp | 69 +- .../source/inputinject/src/virtual_device.cpp | 50 +- .../test/sourceinjectunittest/BUILD.gn | 2 + services/source/sourcemanager/BUILD.gn | 15 + .../distributed_input_source_manager.h | 166 ++- .../distributed_input_source_sa_cli_mgr.h | 60 + .../src/distributed_input_source_manager.cpp | 1151 ++++++++++++++++- .../distributed_input_source_sa_cli_mgr.cpp | 165 +++ .../test/sourcemanagerunittest/BUILD.gn | 4 + .../distributed_input_sourcemanager_test.cpp | 295 ++++- .../distributed_input_sourcemanager_test.h | 30 + services/source/transport/BUILD.gn | 3 + .../distributed_input_source_transport.h | 6 + .../distributed_input_source_transport.cpp | 130 +- .../test/sourcetransunittest/BUILD.gn | 3 + .../distributed_input_sourcetrans_test.cpp | 6 + .../distributed_input_kit_fuzzer.cpp | 48 +- .../BUILD.gn | 3 + utils/include/dinput_utils_tool.h | 1 + utils/src/dinput_sa_process_state.cpp | 4 +- utils/src/dinput_utils_tool.cpp | 12 + 88 files changed, 5734 insertions(+), 352 deletions(-) create mode 100644 common/include/dinput_struct_data.cpp create mode 100644 common/include/dinput_struct_data.h create mode 100644 common/include/idinput_dbg_itf.h create mode 100644 frameworks/include/i_input_node_listener.h create mode 100644 frameworks/include/i_simulation_event_listener.h create mode 100644 frameworks/include/i_start_stop_d_inputs_call_back.h create mode 100644 frameworks/include/i_start_stop_result_call_back.h create mode 100644 interfaces/ipc/include/input_node_listener_proxy.h create mode 100644 interfaces/ipc/include/input_node_listener_stub.h create mode 100644 interfaces/ipc/include/simulation_event_listener_proxy.h create mode 100644 interfaces/ipc/include/simulation_event_listener_stub.h create mode 100644 interfaces/ipc/include/start_stop_d_inputs_call_back_proxy.h create mode 100644 interfaces/ipc/include/start_stop_d_inputs_call_back_stub.h create mode 100644 interfaces/ipc/include/start_stop_result_call_back_proxy.h create mode 100644 interfaces/ipc/include/start_stop_result_call_back_stub.h create mode 100644 interfaces/ipc/src/input_node_listener_proxy.cpp create mode 100644 interfaces/ipc/src/input_node_listener_stub.cpp create mode 100644 interfaces/ipc/src/simulation_event_listener_proxy.cpp create mode 100644 interfaces/ipc/src/simulation_event_listener_stub.cpp create mode 100644 interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp create mode 100644 interfaces/ipc/src/start_stop_d_inputs_call_back_stub.cpp create mode 100644 interfaces/ipc/src/start_stop_result_call_back_proxy.cpp create mode 100644 interfaces/ipc/src/start_stop_result_call_back_stub.cpp create mode 100644 services/source/sourcemanager/include/distributed_input_source_sa_cli_mgr.h create mode 100644 services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 96dc3cd..0864056 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -31,7 +31,13 @@ namespace DistributedInput { #define INPUT_KEY_PATH "path" #define VIRTUAL_DEVICE_NAME "Hos Distributed Virtual Device " +#define LONG_BITS (sizeof(long) * 8) +#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) + const char INPUT_STRING_SPLIT_POINT = '.'; + const uint32_t KEY_DOWN_STATE = 1; + const uint32_t READ_SLEEP_TIME_MS = 50; + const uint32_t READ_RETRY_MAX = 5; /* * Device Type definitions */ diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 76d5da2..7f68557 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -59,7 +59,11 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL = -64009; constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESP_LATENCY_FAIL = -64010; constexpr int32_t ERR_DH_INPUT_SERVER_SINK_SCREEN_INFO_IS_EMPTY = -64011; - + constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL = -64012; + constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANS_START_FAIL = -64013; + constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANS_STOP_FAIL = -64014; + constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_START_MSG_IS_BAD = -64015; + constexpr int32_t ERR_DH_INPUT_SERVER_SINK_MANAGER_STOP_MSG_IS_BAD = -64016; // service source error code constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL = -65000; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_UNREGISTER_FAIL = -65001; @@ -97,6 +101,9 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD = -65033; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_LATENCY_FAIL = -65034; constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_VIRTUAL_SCREEN_NODE_IS_INVALID = -65035; + constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR = -65036; + constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037; + constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038; // handler error code constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000; @@ -112,33 +119,51 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL = -67006; constexpr int32_t ERR_DH_INPUT_CLIENT_START_FAIL = -67007; constexpr int32_t ERR_DH_INPUT_CLIENT_STOP_FAIL = -67008; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_INIT_FAIL = -67009; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL = -67010; - constexpr int32_t ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL = -67011; - constexpr int32_t ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL = -67012; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL = -67013; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL = -67014; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL = -67015; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL = -67016; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL = -67017; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL = -67018; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL = -67019; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL = -67020; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL = -67021; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL = -67022; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL = -67023; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_FAIL = -67024; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL = -67025; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL = -67026; - constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL = -67027; - constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67028; - constexpr int32_t ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL = -67029; - constexpr int32_t ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL = -67030; - constexpr int32_t ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL = -67035; - constexpr int32_t ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL = -67036; - constexpr int32_t ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL = -67037; - constexpr int32_t ERR_DH_INPUT_RPC_REPLY_FAIL = -67038; - constexpr int32_t ERR_DH_INPUT_SA_REQUEST_CODE_INVALID = -67039; + constexpr int32_t ERR_DH_INPUT_CLIENT_REG_START_STOP_CB_FAIL = -67009; + constexpr int32_t ERR_DH_INPUT_CLIENT_UNREG_START_STOP_CB_FAIL = -67010; + constexpr int32_t ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL = -67011; + constexpr int32_t ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL = -67012; + constexpr int32_t ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL = -67013; + constexpr int32_t ERR_DH_INPUT_SINK_PROXY_INIT_FAIL = -67014; + constexpr int32_t ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL = -67015; + constexpr int32_t ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL = -67016; + constexpr int32_t ERR_DH_INPUT_SINK_STUB_ON_REMOTE_REQUEST_FAIL = -67017; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL = -67018; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL = -67019; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WRITE_MSG_FAIL = -67020; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL = -67021; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_WRITE_MSG_FAIL = -67022; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL = -67023; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_WRITE_MSG_FAIL = -67024; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL = -67025; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_WRITE_MSG_FAIL = -67026; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL = -67027; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_WRITE_MSG_FAIL = -67028; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_START_FAIL = -67029; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_WRITE_MSG_FAIL = -67030; + constexpr int32_t ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL = -67031; + 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; + constexpr int32_t ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL = -67045; + constexpr int32_t ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL = -67046; + constexpr int32_t ERR_DH_INPUT_IPC_READ_VALID_FAIL = -67047; + constexpr int32_t ERR_DH_INPUT_IPC_WRITE_VALID_FAIL = -67048; + constexpr int32_t ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL = -67049; + constexpr int32_t ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL = -67050; + constexpr int32_t ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL = -67051; + constexpr int32_t ERR_DH_INPUT_RPC_REPLY_FAIL = -67052; + constexpr int32_t ERR_DH_INPUT_SA_REQUEST_CODE_INVALID = -67053; // Hidump Helper error code constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; diff --git a/common/include/dinput_struct_data.cpp b/common/include/dinput_struct_data.cpp new file mode 100644 index 0000000..ad3c6c1 --- /dev/null +++ b/common/include/dinput_struct_data.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 "dinput_struct_data.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +StringDeviceData::StringDeviceData() : dhname_(""), status(0) {} + +bool StringDeviceData::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(dhname_)) { + DHLOGE("StringDeviceData-Marshalling write dhname_ failed"); + return false; + } + if (!parcel.WriteInt32(status)) { + DHLOGE("StringDeviceData-Marshalling write status failed"); + return false; + } + return true; +} + +sptr StringDeviceData::Unmarshalling(Parcel &parcel) +{ + sptr ptr = (std::make_unique()).release(); + if (ptr == nullptr) { + DHLOGE("StringDeviceData-Unmarshalling create ptr is null."); + return nullptr; + } + + if (!parcel.ReadString(ptr->dhname_)) { + DHLOGE("StringDeviceData-Unmarshalling read dhname_ failed."); + return nullptr; + } + if (!parcel.ReadInt32(ptr->status)) { + DHLOGE("StringDeviceData-Unmarshalling read status failed."); + return nullptr; + } + return ptr; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/common/include/dinput_struct_data.h b/common/include/dinput_struct_data.h new file mode 100644 index 0000000..ab51f45 --- /dev/null +++ b/common/include/dinput_struct_data.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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. + */ + +#ifndef D_INPUT_STRUCT_DATA_H +#define D_INPUT_STRUCT_DATA_H + +#include +#include "parcel.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class StringDeviceData : public Parcelable { +public: + std::string dhname_; + int32_t status; // 0 is success, -1 is error. + StringDeviceData(); + ~StringDeviceData() = default; + bool Marshalling(Parcel &parcel) const override; + static sptr Unmarshalling(Parcel &parcel); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // D_INPUT_STRUCT_DATA_H diff --git a/common/include/idinput_dbg_itf.h b/common/include/idinput_dbg_itf.h new file mode 100644 index 0000000..66e8a81 --- /dev/null +++ b/common/include/idinput_dbg_itf.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 OHOS_DINPUT_DBG_ITF_H +#define OHOS_DINPUT_DBG_ITF_H + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +const std::string GET_DBG_ITF_FUNC = "GetDBGItf"; +class IDInputDBGItf { +public: + virtual int32_t Init() = 0; +}; +extern "C" __attribute__((visibility("default"))) IDInputDBGItf* GetDBGItf(); +} +} +} + +#endif \ No newline at end of file diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index d29092d..2fc49aa 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -184,6 +184,9 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize) if (!device) { continue; } + if (!device->isShare) { + continue; + } if (eventItem.events & EPOLLIN) { event += CollectEvent(event, capacity, device, readBuffer, count); @@ -204,7 +207,7 @@ size_t InputHub::CollectEvent(RawEvent* buffer, size_t& capacity, Device* device const size_t count) { std::vector needFilted(capacity, false); - if (device->classes == INPUT_DEVICE_CLASS_TOUCH_MT) { + if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) { HandleTouchScreenEvent(readBuffer, count, needFilted, device); } @@ -551,11 +554,16 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask); // See if this is a multi-touch touchscreen device. - if (TestBit(BTN_TOUCH, device->keyBitmask) - && TestBit(ABS_MT_POSITION_X, device->absBitmask) - && TestBit(ABS_MT_POSITION_Y, device->absBitmask)) { + if (TestBit(BTN_TOUCH, device->keyBitmask) && + TestBit(ABS_MT_POSITION_X, device->absBitmask) && + TestBit(ABS_MT_POSITION_Y, device->absBitmask)) { QueryLocalTouchScreenInfo(fd); - device->classes |= INPUT_DEVICE_CLASS_TOUCH_MT; + device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; + } else if (TestBit(BTN_TOUCH, device->keyBitmask) && + TestBit(ABS_X, device->absBitmask) && + TestBit(ABS_Y, device->absBitmask)) { + QueryLocalTouchScreenInfo(fd); + device->classes |= INPUT_DEVICE_CLASS_TOUCH; } // See if this is a cursor device such as a trackball or mouse. @@ -585,9 +593,14 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } - DHLOGI("New device: fd=%d, name='%s', classes=0x%x,", - fd, device->identifier.name.c_str(), device->classes); device->identifier.classes = device->classes; + if (device->classes & inputTypes_) { + device->isShare = true; + } + DHLOGI("inputType=%d", inputTypes_.load()); + DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d", + fd, device->identifier.name.c_str(), device->classes, device->isShare); + AddDeviceLocked(std::move(device)); return DH_SUCCESS; } @@ -883,9 +896,7 @@ InputHub::Device* InputHub::GetSupportDeviceByFd(int fd) std::unique_lock deviceLock(devicesMutex_); for (const auto& [id, device] : devices_) { if (device->fd == fd) { - if (IsSupportInputTypes(device->classes)) { - return device.get(); - } + return device.get(); } } return nullptr; @@ -926,10 +937,110 @@ bool InputHub::IsSupportInputTypes(uint32_t classes) { return classes & inputTypes_; } -void InputHub::SetSupportInputType(const uint32_t& inputTypes) + +void InputHub::SetSupportInputType(const uint32_t &inputTypes) { inputTypes_ = inputTypes; DHLOGI("SetSupportInputType: inputTypes=0x%x,", inputTypes_.load()); + std::unique_lock deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->classes & inputTypes_) { + device->isShare = true; + } else { + device->isShare = false; + } + } +} + +void InputHub::GetDeviceDhIdByFd(int32_t fd, std::string &dhId) +{ + std::unique_lock deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->fd == fd) { + dhId = device->identifier.descriptor; + return; + } + } + dhId.clear(); +} + +void InputHub::SetSharingDevices(bool enabled, std::vector dhIds) +{ + std::unique_lock deviceLock(devicesMutex_); + for (auto dhId : dhIds) { + for (const auto &[id, device] : devices_) { + if (device->identifier.descriptor == dhId) { + device->isShare = enabled; + DHLOGW("dhid:%s, isshare:%d,", device->identifier.descriptor.c_str(), enabled); + break; + } + } + } +} + +void InputHub::GetShareMousePathByDhId(std::vector dhIds, std::string &path, std::string &dhId) +{ + DHLOGI("GetShareMousePathByDhId: devices_.size:%d,", devices_.size()); + std::unique_lock deviceLock(devicesMutex_); + for (auto dhId_ : dhIds) { + for (const auto &[id, device] : devices_) { + DHLOGI("descriptor:%s, isShare[%d], type[%d]", device->identifier.descriptor.c_str(), + device->isShare, device->classes); + if ((device->identifier.descriptor == dhId_) && + ((device->classes & INPUT_DEVICE_CLASS_CURSOR) != 0)) { + dhId = dhId_; + path = device->path; + return; // return First shared mouse + } + } + } +} + +void InputHub::GetDevicesInfoByType(int32_t inputTypes, std::map &datas) +{ + uint32_t input_types_ = 0; + + if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_CURSOR; + } + + if ((inputTypes & static_cast(DInputDeviceType::KEYBOARD)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_KEYBOARD; + } + + if ((inputTypes & static_cast(DInputDeviceType::TOUCHSCREEN)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; + } + + std::unique_lock deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->classes & input_types_) { + datas.insert(std::pair(device->fd, device->identifier.descriptor)); + } + } +} + +void InputHub::GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas) +{ + for (auto dhId : dhidsVec) { + std::unique_lock deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->identifier.descriptor == dhId) { + datas.insert(std::pair(device->fd, dhId)); + } + } + } +} + +bool InputHub::GetAllDevicesStoped() +{ + std::unique_lock deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->isShare) { + return false; + } + } + return true; } void InputHub::RecordEventLog(const RawEvent* event) diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 2514a6a..fb847cd 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -40,8 +41,15 @@ public: void StopCollectInputHandler(); size_t DeviceIsExists(InputDeviceEvent* event, size_t capacity); std::vector GetAllInputDevices(); - void SetSupportInputType(const uint32_t& inputType); + void SetSupportInputType(const uint32_t &inputType); + void SetSharingDevices(bool enabled, std::vector dhIds); + void GetDeviceDhIdByFd(int32_t fd, std::string &dhId); + void GetDevicesInfoByType(int32_t inputTypes, std::map &datas); + void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); + void GetShareMousePathByDhId(std::vector dhIds, std::string &path, std::string &dhId); + bool GetAllDevicesStoped(); void ScanInputDevices(const std::string& dirname); + private: struct Device { Device* next; @@ -54,11 +62,11 @@ private: uint8_t absBitmask[(ABS_MAX + 1) / 8]; uint8_t relBitmask[(REL_MAX + 1) / 8]; - Device(int fd, int32_t id, const std::string& path, - const InputDevice& identifier); + Device(int fd, int32_t id, const std::string& path, const InputDevice& identifier); ~Device(); void Close(); bool enabled; // initially true + bool isShare; int32_t Enable(); int32_t Disable(); bool HasValidFd() const; @@ -104,7 +112,9 @@ private: bool ContainsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex); int64_t ProcessEventTimestamp(const input_event& event); - /* this macro is used to tell if "bit" is set in "array" + + /* + * this macro is used to tell if "bit" is set in "array" * it selects a byte from the array, and does a boolean AND * operation with a byte that only has the relevant bit set. * eg. to check for the 12th bit, we do (array[1] & 1<<4) diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index c082acb..282c7d0 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -60,7 +60,7 @@ int32_t WhiteListUtil::Init() std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary); if (!inFile.is_open()) { // file open error - DHLOGE("%s error, file open fail path=%s", __func__, whiteListFilePath); + DHLOGE("WhiteListUtil Init error, file open fail path=%s", whiteListFilePath); return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } @@ -70,8 +70,7 @@ int32_t WhiteListUtil::Init() std::string line; while (getline(inFile, line)) { - DHLOGI("%s called success, line=%s", __func__, line.c_str()); - + DHLOGI("read whitelist cfg, line=%s", line.c_str()); vecKeyCode.clear(); vecCombinationKey.clear(); @@ -117,7 +116,7 @@ int32_t WhiteListUtil::Init() int32_t WhiteListUtil::UnInit(void) { - DHLOGI("%s called", __func__); + DHLOGI("WhiteListUtil UnInit called"); ClearWhiteList(); return DH_SUCCESS; } @@ -230,7 +229,7 @@ int32_t WhiteListUtil::ClearWhiteList(void) int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList) { - DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); + DHLOGI("GetWhiteList start, deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); TYPE_DEVICE_WHITE_LIST_MAP::const_iterator iter = mapDeviceWhiteList_.find(deviceId); @@ -271,17 +270,17 @@ std::string WhiteListUtil::GetBusinessEventHash(const BusinessEvent &event) bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) { - DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); + DHLOGI("IsNeedFilterOut start, deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); if (combKeysHashMap_.empty()) { - DHLOGE("%s called, white list is empty!", __func__); + DHLOGE("IsNeedFilterOut error, white list is empty!"); return false; } auto iter = combKeysHashMap_.find(deviceId); if (iter == combKeysHashMap_.end()) { - DHLOGE("%s called, not find by deviceId!", __func__); + DHLOGE("IsNeedFilterOut error, not find by deviceId!"); return false; } diff --git a/dfx_utils/BUILD.gn b/dfx_utils/BUILD.gn index ca3740e..b78e120 100755 --- a/dfx_utils/BUILD.gn +++ b/dfx_utils/BUILD.gn @@ -27,6 +27,7 @@ ohos_shared_library("libdinput_dfx_utils") { "${fwk_utils_path}/include", "${frameworks_path}/include", "${dfx_utils_path}/include", + "${service_common}/include", ] sources = [ diff --git a/dfx_utils/src/hidumper.cpp b/dfx_utils/src/hidumper.cpp index 360d052..38dd5dd 100644 --- a/dfx_utils/src/hidumper.cpp +++ b/dfx_utils/src/hidumper.cpp @@ -19,6 +19,7 @@ #include "distributed_hardware_log.h" #include "dinput_errcode.h" +#include "dinput_softbus_define.h" namespace OHOS { namespace DistributedHardware { @@ -28,7 +29,6 @@ namespace { const std::string ARGS_HELP = "-h"; const std::string ARGS_NODE_INFO = "-nodeinfo"; const std::string ARGS_SESSION_INFO = "-sessioninfo"; - const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput"; const std::map ARGS_MAP = { {ARGS_HELP, HiDumperFlag::GET_HELP}, @@ -129,7 +129,7 @@ void HiDumper::DeleteNodeInfo(const std::string& deviceId, const std::string& dh } } -int32_t HiDumper::GetSessionInfo(std::string &result) +int32_t HiDumper::GetSessionInfo(std::string& result) { DHLOGI("GetSessionInfo Dump."); std::lock_guard lock(sessionMutex_); diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index 3b92d43..8bfd5c8 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -17,6 +17,7 @@ #define I_DISTRIBUTED_SOURCE_INPUT_H #include +#include #include "iremote_broker.h" #include "iremote_object.h" @@ -29,8 +30,12 @@ #include "i_start_d_input_call_back.h" #include "i_start_d_input_server_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" #include "i_unregister_d_input_call_back.h" +#include "i_input_node_listener.h" +#include "i_simulation_event_listener.h" namespace OHOS { namespace DistributedHardware { @@ -51,13 +56,9 @@ public: const std::string& devId, const std::string& dhId, sptr callback) = 0; - virtual int32_t PrepareRemoteInput( - const std::string& deviceId, sptr callback, - sptr addWhiteListCallback) = 0; + virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr callback) = 0; - virtual int32_t UnprepareRemoteInput( - const std::string& deviceId, sptr callback, - sptr delWhiteListCallback) = 0; + 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; @@ -65,9 +66,43 @@ public: 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; + + virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) = 0; + + virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) = 0; + + virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) = 0; + + virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) = 0; + + virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) = 0; + virtual int32_t IsStartDistributedInput( const uint32_t& inputType, sptr callback) = 0; + 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; + enum class MessageCode { INIT = 0xf001, RELEASE = 0xf002, @@ -78,6 +113,21 @@ public: START_REMOTE_INPUT = 0xf007, STOP_REMOTE_INPUT = 0xf008, ISSTART_REMOTE_INPUT = 0xf009, + PREPARE_RELAY_REMOTE_INPUT = 0xf00a, + UNPREPARE_RELAY_REMOTE_INPUT = 0xf00b, + START_RELAY_TYPE_REMOTE_INPUT = 0xf00c, + STOP_RELAY_TYPE_REMOTE_INPUT = 0xf00d, + START_DHID_REMOTE_INPUT = 0xf00e, + STOP_DHID_REMOTE_INPUT = 0xf00f, + START_RELAY_DHID_REMOTE_INPUT = 0xf010, + STOP_RELAY_DHID_REMOTE_INPUT = 0xf011, + REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT = 0xf013, + REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT = 0xf014, + REGISTER_NODE_LISTENER = 0xf015, + UNREGISTER_NODE_LISTENER = 0xf016, + REGISTER_SIMULATION_EVENT_LISTENER = 0xf017, + UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018, + SYNC_NODE_INFO_REMOTE_INPUT = 0xf019, }; }; } // namespace DistributedInput diff --git a/frameworks/include/i_input_node_listener.h b/frameworks/include/i_input_node_listener.h new file mode 100644 index 0000000..c839778 --- /dev/null +++ b/frameworks/include/i_input_node_listener.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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. + */ + +#ifndef I_INPUT_NODE_LISTENER_H +#define I_INPUT_NODE_LISTENER_H + +#include + +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class InputNodeListener : public IRemoteBroker { +public: + virtual void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc) = 0; + + virtual void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId) = 0; + + enum class Message { RESULT_ON, RESULT_OFF }; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.InputNodeListener"); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // I_INPUT_NODE_LISTENER_H diff --git a/frameworks/include/i_simulation_event_listener.h b/frameworks/include/i_simulation_event_listener.h new file mode 100644 index 0000000..623efd1 --- /dev/null +++ b/frameworks/include/i_simulation_event_listener.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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. + */ + +#ifndef I_SIMULATION_EVENT_LISTENER_H +#define I_SIMULATION_EVENT_LISTENER_H + +#include + +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class ISimulationEventListener : public IRemoteBroker { +public: + virtual int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) = 0; + + enum class Message { + RESULT_ON, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.ISimulationEventListener"); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // I_SIMULATION_EVENT_LISTENER_H \ No newline at end of file diff --git a/frameworks/include/i_start_stop_d_inputs_call_back.h b/frameworks/include/i_start_stop_d_inputs_call_back.h new file mode 100644 index 0000000..fe714c5 --- /dev/null +++ b/frameworks/include/i_start_stop_d_inputs_call_back.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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. + */ + +#ifndef I_START_STOP_D_INPUTS_CALL_BACK_H +#define I_START_STOP_D_INPUTS_CALL_BACK_H + +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class IStartStopDInputsCallback : public IRemoteBroker { +public: + virtual void OnResultDhids(const std::string &devId, const int32_t &status) = 0; + + enum class Message { + RESULT_STRING, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartStopDInputsCallback"); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // I_START_STOP_D_INPUTS_CALL_BACK_H diff --git a/frameworks/include/i_start_stop_result_call_back.h b/frameworks/include/i_start_stop_result_call_back.h new file mode 100644 index 0000000..8890247 --- /dev/null +++ b/frameworks/include/i_start_stop_result_call_back.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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. + */ + +#ifndef I_START_STOP_RESULT_CALL_BACK_H +#define I_START_STOP_RESULT_CALL_BACK_H + +#include +#include +#include +#include "dinput_struct_data.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class IStartStopResultCallback : public IRemoteBroker { +public: + virtual void OnStart(const std::string &srcId, const std::string &sinkId, + std::vector &dhIds) = 0; + virtual void OnStop(const std::string &srcId, const std::string &sinkId, + std::vector &dhIds) = 0; + + enum class Message { + RESULT_START, + RESULT_STOP, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartStopResultCallback"); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // I_START_STOP_RESULT_CALL_BACK_H diff --git a/inputdevicehandler/BUILD.gn b/inputdevicehandler/BUILD.gn index a2eb9bf..4e9e4ca 100755 --- a/inputdevicehandler/BUILD.gn +++ b/inputdevicehandler/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("libdinput_handler") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", + "${service_common}/include", "${frameworks_path}/include", "${utils_path}/include", "//third_party/json/include", diff --git a/inputdevicehandler/include/distributed_input_handler.h b/inputdevicehandler/include/distributed_input_handler.h index 1678a7f..9af7833 100644 --- a/inputdevicehandler/include/distributed_input_handler.h +++ b/inputdevicehandler/include/distributed_input_handler.h @@ -30,19 +30,25 @@ #include "constants_dinput.h" #include "input_hub.h" +#ifndef API_EXPORT +#define API_EXPORT __attribute__((visibility("default"))) +#endif + namespace OHOS { namespace DistributedHardware { namespace DistributedInput { class DistributedInputHandler : public IHardwareHandler { DECLARE_SINGLE_INSTANCE_BASE(DistributedInputHandler); public: - virtual int32_t Initialize() override; - virtual std::vector Query() override; - virtual std::map QueryExtraInfo() override; - virtual bool IsSupportPlugin() override; - virtual void RegisterPluginListener(std::shared_ptr listener) override; - virtual void UnRegisterPluginListener() override; + API_EXPORT virtual int32_t Initialize() override; + API_EXPORT virtual std::vector Query() override; + API_EXPORT virtual std::map QueryExtraInfo() override; + API_EXPORT virtual bool IsSupportPlugin() override; + API_EXPORT virtual void RegisterPluginListener(std::shared_ptr listener) override; + API_EXPORT virtual void UnRegisterPluginListener() override; + API_EXPORT void FindDevicesInfoByType(int32_t inputTypes, std::map &datas); + API_EXPORT void FindDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); private: DistributedInputHandler(); ~DistributedInputHandler(); @@ -69,7 +75,7 @@ private: #ifdef __cplusplus extern "C" { #endif -__attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); +API_EXPORT IHardwareHandler* GetHardwareHandler(); #ifdef __cplusplus } #endif diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index c92705c..5482625 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -33,6 +33,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" +#include "dinput_softbus_define.h" #include "softbus_bus_center.h" namespace OHOS { @@ -40,8 +41,7 @@ namespace DistributedHardware { namespace DistributedInput { IMPLEMENT_SINGLE_INSTANCE(DistributedInputHandler); DistributedInputHandler::DistributedInputHandler() - : collectThreadID_(-1), isCollectingEvents_(false), - isStartCollectEventThread(false) + : collectThreadID_(-1), isCollectingEvents_(false), isStartCollectEventThread(false) { inputHub_ = std::make_unique(); this->m_listener = nullptr; @@ -82,15 +82,33 @@ int32_t DistributedInputHandler::Initialize() return DH_SUCCESS; } +void DistributedInputHandler::FindDevicesInfoByType(int32_t inputTypes, std::map &datas) +{ + if (inputHub_ != nullptr) { + inputHub_->GetDevicesInfoByType(inputTypes, datas); + } +} + +void DistributedInputHandler::FindDevicesInfoByDhId( + std::vector dhidsVec, std::map &datas) +{ + if (inputHub_ != nullptr) { + inputHub_->GetDevicesInfoByDhId(dhidsVec, datas); + } +} + std::vector DistributedInputHandler::Query() { std::vector retInfos; - std::vector vecInput = inputHub_->GetAllInputDevices(); - for (auto iter : vecInput) { - DHItem item; - item.dhId = iter.descriptor; - StructTransJson(iter, item.attrs); - retInfos.push_back(item); + + if (inputHub_ != nullptr) { + std::vector vecInput = inputHub_->GetAllInputDevices(); + for (auto iter : vecInput) { + DHItem item; + item.dhId = iter.descriptor; + StructTransJson(iter, item.attrs); + retInfos.push_back(item); + } } return retInfos; @@ -142,8 +160,7 @@ bool DistributedInputHandler::InitCollectEventsThread() collectThreadID_ = -1; int32_t ret = pthread_create(&collectThreadID_, &attr, CollectEventsThread, this); if (ret != 0) { - DHLOGE( - "DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret); + DHLOGE("DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret); pthread_attr_destroy(&attr); collectThreadID_ = -1; isCollectingEvents_ = false; @@ -165,6 +182,10 @@ void *DistributedInputHandler::CollectEventsThread(void *param) void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId) { + if (inputHub_ == nullptr) { + DHLOGE("inputHub_ not initialized"); + return; + } while (isCollectingEvents_) { size_t count = inputHub_->StartCollectInputHandler(mEventBuffer, INPUT_DEVICE_BUFFER_SIZE); if (count > 0) { diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index 7131c3f..dc59316 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -34,8 +34,10 @@ ohos_shared_library("libdinput_sdk") { "${fwk_interfaces_path}/include", "${fwk_interfaces_path}/include/ipc", ] + sources = [ "${common_path}/include/white_list_util.cpp", + "${common_path}/include/dinput_struct_data.cpp", "${innerkits_path}/src/distributed_input_kit.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", @@ -47,6 +49,10 @@ ohos_shared_library("libdinput_sdk") { "${ipc_path}/src/distributed_input_sink_stub.cpp", "${ipc_path}/src/distributed_input_source_proxy.cpp", "${ipc_path}/src/distributed_input_source_stub.cpp", + "${ipc_path}/src/input_node_listener_proxy.cpp", + "${ipc_path}/src/input_node_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", "${ipc_path}/src/register_d_input_call_back_proxy.cpp", @@ -55,6 +61,10 @@ ohos_shared_library("libdinput_sdk") { "${ipc_path}/src/start_d_input_call_back_stub.cpp", "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", "${ipc_path}/src/start_d_input_server_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", @@ -64,6 +74,7 @@ ohos_shared_library("libdinput_sdk") { ] deps = [ + "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "${fwk_utils_path}:distributedhardwareutils", "${utils_path}:libdinput_utils", "${fwk_interfaces_path}:libdhfwk_sdk", diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index 65fa616..db8a56f 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -17,6 +17,7 @@ #define DISTRIBUTED_INPUT_KIT_H #include +#include #include "distributed_hardware_log.h" @@ -25,6 +26,8 @@ #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" #include "i_prepare_d_input_call_back.h" #include "i_unprepare_d_input_call_back.h" @@ -35,21 +38,43 @@ namespace DistributedInput { class DistributedInputKit { public: - static int32_t PrepareRemoteInput(const std::string& deviceId, sptr callback); + static int32_t PrepareRemoteInput(const std::string& sinkId, sptr callback); + static int32_t UnprepareRemoteInput(const std::string& sinkId, sptr callback); - static int32_t UnprepareRemoteInput(const std::string& deviceId, sptr callback); + static int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback); + static int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback); static int32_t StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback); - + const std::string& sinkId, const uint32_t& inputTypes, sptr callback); static int32_t StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback); + const std::string& sinkId, const uint32_t& inputTypes, sptr callback); - static bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); + 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, + const std::vector &dhIds, sptr callback); + + static bool IsNeedFilterOut(const std::string &sinkId, const BusinessEvent &event); static bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event); static DInputServerType IsStartDistributedInput(const uint32_t& inputType); + + static int32_t RegisterInputNodeListener(sptr listener); + static int32_t UnregisterInputNodeListener(sptr listener); + static int32_t RegisterSimulationEventListener(sptr listener); + static int32_t UnregisterSimulationEventListener(sptr listener); }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/inner_kits/src/distributed_input_kit.cpp b/interfaces/inner_kits/src/distributed_input_kit.cpp index 729fd5c..5101aad 100644 --- a/interfaces/inner_kits/src/distributed_input_kit.cpp +++ b/interfaces/inner_kits/src/distributed_input_kit.cpp @@ -19,32 +19,44 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { int32_t DistributedInputKit::PrepareRemoteInput( - const std::string& deviceId, sptr callback) + const std::string& sinkId, sptr callback) { - return DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback); + return DistributedInputClient::GetInstance().PrepareRemoteInput(sinkId, callback); } int32_t DistributedInputKit::UnprepareRemoteInput( - const std::string& deviceId, sptr callback) + const std::string& sinkId, sptr callback) { - return DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback); + return DistributedInputClient::GetInstance().UnprepareRemoteInput(sinkId, callback); } int32_t DistributedInputKit::StartRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) + const std::string& sinkId, const uint32_t& inputTypes, sptr callback) { - return DistributedInputClient::GetInstance().StartRemoteInput(deviceId, inputTypes, callback); + return DistributedInputClient::GetInstance().StartRemoteInput(sinkId, inputTypes, callback); } int32_t DistributedInputKit::StopRemoteInput( - const std::string& deviceId, const uint32_t& inputTypes, sptr callback) + const std::string& sinkId, const uint32_t& inputTypes, sptr callback) { - return DistributedInputClient::GetInstance().StopRemoteInput(deviceId, inputTypes, callback); + return DistributedInputClient::GetInstance().StopRemoteInput(sinkId, inputTypes, callback); } -bool DistributedInputKit::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) +int32_t DistributedInputKit::StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const uint32_t &inputTypes, sptr callback) { - return DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event); + 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); } bool DistributedInputKit::IsTouchEventNeedFilterOut(const TouchScreenEvent &event) @@ -56,6 +68,62 @@ DInputServerType DistributedInputKit::IsStartDistributedInput(const uint32_t& in { return DistributedInputClient::GetInstance().IsStartDistributedInput(inputType); } + +int32_t DistributedInputKit::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + return DistributedInputClient::GetInstance().PrepareRemoteInput(srcId, sinkId, callback); +} + +int32_t DistributedInputKit::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + return DistributedInputClient::GetInstance().UnprepareRemoteInput(srcId, sinkId, callback); +} + +int32_t DistributedInputKit::StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + return DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback); +} + +int32_t DistributedInputKit::StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + return DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback); +} + +int32_t DistributedInputKit::StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + return DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback); +} + +int32_t DistributedInputKit::StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + 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); +} + +int32_t DistributedInputKit::UnregisterSimulationEventListener(sptr listener) +{ + return DistributedInputClient::GetInstance().UnregisterSimulationEventListener(listener); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index b72a904..48e21b3 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -49,18 +49,27 @@ ohos_unittest("distributed_input_inner_test") { sources = [ "${common_path}/include/white_list_util.cpp", + "${common_path}/include/dinput_struct_data.cpp", "${innerkits_path}/src/distributed_input_kit.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/distributed_input_source_proxy.cpp", + "${ipc_path}/src/input_node_listener_proxy.cpp", + "${ipc_path}/src/input_node_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", "${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/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", 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 7aa9bfb..3692ae1 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -224,6 +224,46 @@ 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 = new TestStartDInputCallback(); + 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 = "StartRemoteInput03-src"; + string sinkId = "StartRemoteInput03-sink"; + sptr callback = nullptr; + int32_t ret = + DistributedInputKit::StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DistributedInputInnerTest, StartRemoteInput08, 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, StopRemoteInput01, testing::ext::TestSize.Level0) { string deviceId = "StopRemoteInput01"; @@ -260,6 +300,46 @@ 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 = new TestStopDInputCallback(); + 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 = "StopRemoteInput03-src"; + string sinkId = "StopRemoteInput03-sink"; + sptr callback = nullptr; + int32_t ret = + DistributedInputKit::StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DistributedInputInnerTest, StopRemoteInput08, 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, IsNeedFilterOut01, testing::ext::TestSize.Level0) { string deviceId = "IsNeedFilterOut01"; 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 47c0f53..8f6b35f 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 @@ -149,6 +149,18 @@ int32_t DistributedInputClient::StopRemoteInput( 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; +} + bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) { return true; diff --git a/interfaces/ipc/include/dinput_sa_manager.h b/interfaces/ipc/include/dinput_sa_manager.h index b1f507c..3bb9918 100644 --- a/interfaces/ipc/include/dinput_sa_manager.h +++ b/interfaces/ipc/include/dinput_sa_manager.h @@ -26,10 +26,12 @@ #include "idistributed_hardware_source.h" #include "idistributed_hardware_sink.h" +#include "event_handler.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +const uint32_t DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG = 1; class DInputSAManager { DECLARE_SINGLE_INSTANCE_BASE(DInputSAManager); public: @@ -40,12 +42,13 @@ public: bool GetDInputSinkProxy(); bool HasDInputSinkProxy(); bool SetDInputSinkProxy(const sptr &remoteObject); + void RegisterEventHandler(std::shared_ptr handler); public: -class SystemAbilityListener : public SystemAbilityStatusChangeStub { -public: - void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + class SystemAbilityListener : public SystemAbilityStatusChangeStub { + public: + void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; }; private: @@ -59,10 +62,13 @@ public: std::atomic isSubscribeSinkSAChangeListener = false; std::mutex sinkMutex_; std::mutex sourceMutex_; + std::mutex handlerMutex_; sptr dInputSourceProxy_ = nullptr; sptr dInputSinkProxy_ = nullptr; sptr saListenerCallback = nullptr; + + std::shared_ptr eventHandler_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 5f14217..99f4bb8 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -28,10 +28,12 @@ #include "register_d_input_call_back_stub.h" #include "start_d_input_server_call_back_stub.h" #include "unregister_d_input_call_back_stub.h" +#include "start_stop_d_inputs_call_back_stub.h" #include "dinput_sa_manager.h" #include "idistributed_hardware_source.h" #include "idistributed_hardware_sink.h" +#include "event_handler.h" namespace OHOS { namespace DistributedHardware { @@ -66,16 +68,47 @@ public: int32_t StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback); - bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); + 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, + sptr callback); + + int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback); + int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback); + + int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, + sptr callback); + int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, + sptr callback); + + bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event); DInputServerType IsStartDistributedInput(const uint32_t& inputType); 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); + + void CheckRegisterCallback(); + void CheckWhiteListCallback(); + void CheckNodeMonitorCallback(); + void CheckKeyStateCallback(); + void CheckStartStopResultCallback(); + public: class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { public: @@ -112,6 +145,14 @@ public: void OnResult(const std::string &deviceId); }; + class DInputClientEventHandler : public AppExecFwk::EventHandler { + public: + DInputClientEventHandler(const std::shared_ptr &runner); + ~DInputClientEventHandler() {} + + void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + }; + private: DistributedInputClient(); bool IsJsonData(std::string strData) const; @@ -127,8 +168,21 @@ private: sptr sinkTypeCallback = nullptr; sptr sourceTypeCallback = nullptr; - sptr addWhiteListCallback = nullptr; - sptr delWhiteListCallback = nullptr; + sptr addWhiteListCallback_ = nullptr; + sptr delWhiteListCallback_ = nullptr; + sptr regNodeListener_ = nullptr; + sptr unregNodeListener_ = nullptr; + sptr regSimulationEventListener_ = nullptr; + sptr unregSimulationEventListener_ = nullptr; + + std::shared_ptr eventHandler_; + + bool isAddWhiteListCbReg; + bool isDelWhiteListCbReg; + bool isNodeMonitorCbReg; + bool isNodeMonitorCbUnreg; + bool isSimulationEventCbReg; + bool isSimulationEventCbUnreg; struct DHardWareFwkRegistInfo { std::string devId; diff --git a/interfaces/ipc/include/distributed_input_sink_proxy.h b/interfaces/ipc/include/distributed_input_sink_proxy.h index 3e6c8b8..b34cf7b 100644 --- a/interfaces/ipc/include/distributed_input_sink_proxy.h +++ b/interfaces/ipc/include/distributed_input_sink_proxy.h @@ -40,7 +40,6 @@ public: const uint32_t& inputType, sptr callback) override; virtual int32_t NotifyStartDScreen(const SrcScreenInfo& srcScreenRemoteCtrlInfo) override; - virtual int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override; private: diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index d7c110b..c3a315d 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -42,11 +42,9 @@ public: virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, sptr callback) override; - virtual int32_t PrepareRemoteInput(const std::string& deviceId, - sptr callback, sptr addWhiteListCallback) override; + virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr callback) override; - virtual int32_t UnprepareRemoteInput(const std::string& deviceId, - sptr callback, sptr delWhiteListCallback) override; + virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback) override; virtual int32_t StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; @@ -54,9 +52,43 @@ public: virtual int32_t StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; + virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) override; + + virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) override; + + virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) override; + + virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) override; + + virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) override; + virtual int32_t IsStartDistributedInput( const uint32_t& inputType, sptr callback) override; + virtual int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback) override; + virtual int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback) override; + virtual int32_t RegisterInputNodeListener(sptr listener) override; + virtual int32_t UnregisterInputNodeListener(sptr listener) override; + + virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, + const std::string &nodeDesc) override; + virtual int32_t RegisterSimulationEventListener(sptr listener) override; + virtual int32_t UnregisterSimulationEventListener(sptr listener) override; + private: bool SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 5fe64a0..7267686 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -42,7 +42,22 @@ private: 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); + int32_t HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply); + int32_t HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply); + int32_t HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply); int32_t HandleIsStartDistributedInput(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); DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub); }; } // namespace DistributedInput diff --git a/interfaces/ipc/include/input_node_listener_proxy.h b/interfaces/ipc/include/input_node_listener_proxy.h new file mode 100644 index 0000000..3c9a0ee --- /dev/null +++ b/interfaces/ipc/include/input_node_listener_proxy.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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. + */ + +#ifndef INPUT_NODE_LISTENER_PROXY_H +#define INPUT_NODE_LISTENER_PROXY_H + +#include "i_input_node_listener.h" + +#include + +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class InputNodeListenerProxy : public IRemoteProxy { +public: + explicit InputNodeListenerProxy(const sptr &object); + + virtual ~InputNodeListenerProxy() override; + + virtual void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc) override; + + virtual void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // INPUT_NODE_LISTENER_PROXY_H diff --git a/interfaces/ipc/include/input_node_listener_stub.h b/interfaces/ipc/include/input_node_listener_stub.h new file mode 100644 index 0000000..37a8c29 --- /dev/null +++ b/interfaces/ipc/include/input_node_listener_stub.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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. + */ + +#ifndef INPUT_NODE_LISTENER_STUB_H +#define INPUT_NODE_LISTENER_STUB_H + +#include "i_input_node_listener.h" + +#include + +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class InputNodeListenerStub : public IRemoteStub { +public: + InputNodeListenerStub(); + virtual ~InputNodeListenerStub() override; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(InputNodeListenerStub); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // INPUT_NODE_LISTENER_STUB_H diff --git a/interfaces/ipc/include/simulation_event_listener_proxy.h b/interfaces/ipc/include/simulation_event_listener_proxy.h new file mode 100644 index 0000000..28a801e --- /dev/null +++ b/interfaces/ipc/include/simulation_event_listener_proxy.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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. + */ + +#ifndef SIMULATION_EVENT_LISTENER_PROXY_H +#define SIMULATION_EVENT_LISTENER_PROXY_H + +#include "i_simulation_event_listener.h" + +#include + +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class SimulationEventListenerProxy : public IRemoteProxy { +public: + explicit SimulationEventListenerProxy(const sptr &object); + + virtual ~SimulationEventListenerProxy() override; + + virtual int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // SIMULATION_EVENT_LISTENER_PROXY_H diff --git a/interfaces/ipc/include/simulation_event_listener_stub.h b/interfaces/ipc/include/simulation_event_listener_stub.h new file mode 100644 index 0000000..aa1c608 --- /dev/null +++ b/interfaces/ipc/include/simulation_event_listener_stub.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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. + */ + +#ifndef SIMULATION_EVENT_LISTENER_STUB_H +#define SIMULATION_EVENT_LISTENER_STUB_H + +#include "i_simulation_event_listener.h" + +#include + +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class SimulationEventListenerStub : public IRemoteStub { +public: + SimulationEventListenerStub(); + virtual ~SimulationEventListenerStub() override; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(SimulationEventListenerStub); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // SIMULATION_EVENT_LISTENER_STUB_H diff --git a/interfaces/ipc/include/start_stop_d_inputs_call_back_proxy.h b/interfaces/ipc/include/start_stop_d_inputs_call_back_proxy.h new file mode 100644 index 0000000..6511f18 --- /dev/null +++ b/interfaces/ipc/include/start_stop_d_inputs_call_back_proxy.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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. + */ + +#ifndef START_STOP_D_INPUTS_CALL_BACK_PROXY_H +#define START_STOP_D_INPUTS_CALL_BACK_PROXY_H + +#include "i_start_stop_d_inputs_call_back.h" + +#include +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class StartStopDInputsCallbackProxy : public IRemoteProxy { +public: + explicit StartStopDInputsCallbackProxy(const sptr &object); + virtual ~StartStopDInputsCallbackProxy() override; + + virtual void OnResultDhids(const std::string &devId, const int32_t &status) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // START_STOP_D_INPUTS_CALL_BACK_PROXY_H diff --git a/interfaces/ipc/include/start_stop_d_inputs_call_back_stub.h b/interfaces/ipc/include/start_stop_d_inputs_call_back_stub.h new file mode 100644 index 0000000..3993bbe --- /dev/null +++ b/interfaces/ipc/include/start_stop_d_inputs_call_back_stub.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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. + */ + +#ifndef START_STOP_D_INPUTS_CALL_BACK_STUB_H +#define START_STOP_D_INPUTS_CALL_BACK_STUB_H + +#include "i_start_stop_d_inputs_call_back.h" + +#include +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class StartStopDInputsCallbackStub : public IRemoteStub { +public: + StartStopDInputsCallbackStub(); + virtual ~StartStopDInputsCallbackStub() override; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(StartStopDInputsCallbackStub); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS +#endif // START_STOP_D_INPUTS_CALL_BACK_STUB_H diff --git a/interfaces/ipc/include/start_stop_result_call_back_proxy.h b/interfaces/ipc/include/start_stop_result_call_back_proxy.h new file mode 100644 index 0000000..296d62f --- /dev/null +++ b/interfaces/ipc/include/start_stop_result_call_back_proxy.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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. + */ + +#ifndef START_STOP_RESULT_CALL_BACK_PROXY_H +#define START_STOP_RESULT_CALL_BACK_PROXY_H + +#include "i_start_stop_result_call_back.h" + +#include + +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class StartStopResultCallbackProxy : public IRemoteProxy { +public: + explicit StartStopResultCallbackProxy(const sptr &object); + virtual ~StartStopResultCallbackProxy() override; + + virtual void OnStart(const std::string &srcId, const std::string &sinkId, + std::vector &dhIds) override; + virtual void OnStop(const std::string &srcId, const std::string &sinkId, + std::vector &dhIds) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // START_STOP_RESULT_CALL_BACK_PROXY_H diff --git a/interfaces/ipc/include/start_stop_result_call_back_stub.h b/interfaces/ipc/include/start_stop_result_call_back_stub.h new file mode 100644 index 0000000..d307798 --- /dev/null +++ b/interfaces/ipc/include/start_stop_result_call_back_stub.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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. + */ + +#ifndef START_STOP_RESULT_CALL_BACK_STUB_H +#define START_STOP_RESULT_CALL_BACK_STUB_H + +#include "i_start_stop_result_call_back.h" + +#include + +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class StartStopResultCallbackStub : public IRemoteStub { +public: + StartStopResultCallbackStub(); + virtual ~StartStopResultCallbackStub() override; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(StartStopResultCallbackStub); +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS +#endif // START_STOP_RESULT_CALL_BACK_STUB_H diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index d16af5d..29280f5 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -26,7 +26,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { IMPLEMENT_SINGLE_INSTANCE(DInputSAManager); - +const uint32_t DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME = 50; // million seconds void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) { @@ -45,6 +45,14 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb { if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) { DInputSAManager::GetInstance().dInputSourceSAOnline.store(true); + std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); + if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { + DHLOGI("SendEvent DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG"); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG, systemAbilityId); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, + AppExecFwk::EventQueue::Priority::IMMEDIATE); + } } else if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { DInputSAManager::GetInstance().dInputSinkSAOnline.store(true); } @@ -85,6 +93,12 @@ void DInputSAManager::Init() } } +void DInputSAManager::RegisterEventHandler(std::shared_ptr handler) +{ + std::lock_guard lock(handlerMutex_); + eventHandler_ = handler; +} + bool DInputSAManager::GetDInputSourceProxy() { if (!isSubscribeSrcSAChangeListener.load()) { @@ -116,12 +130,12 @@ bool DInputSAManager::GetDInputSourceProxy() } sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityManager) { DHLOGE("get system ability manager failed."); return false; } - DHLOGI("%s try get sa: %d", __func__, DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); + + DHLOGI("try get sa: %d", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); sptr remoteObject = systemAbilityManager->GetSystemAbility( DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); if (!remoteObject) { diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 07e113e..9dedbca 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -25,6 +25,7 @@ #include "dinput_context.h" #include "dinput_errcode.h" #include "dinput_utils_tool.h" +#include "distributed_input_source_proxy.h" #include "softbus_bus_center.h" #include "white_list_util.h" @@ -32,10 +33,16 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { std::shared_ptr DistributedInputClient::instance(new DistributedInputClient()); - -DistributedInputClient::DistributedInputClient() +DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), + isNodeMonitorCbReg(false), isNodeMonitorCbUnreg(false), + isSimulationEventCbReg(false), isSimulationEventCbUnreg(false) { + DHLOGI("DistributedInputClient init start"); + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + eventHandler_ = std::make_shared(runner); + DInputSAManager::GetInstance().RegisterEventHandler(eventHandler_); DInputSAManager::GetInstance().Init(); + DHLOGI("DistributedInputClient init end."); } DistributedInputClient &DistributedInputClient::GetInstance() @@ -102,6 +109,104 @@ void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& de DistributedInputClient::GetInstance().DelWhiteListInfos(deviceId); } +DistributedInputClient::DInputClientEventHandler::DInputClientEventHandler( + const std::shared_ptr &runner) + : AppExecFwk::EventHandler(runner) +{ +} + +void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + uint32_t eventId = event->GetInnerEventId(); + DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%d.", eventId); + if (eventId == DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG) { + DistributedInputClient::GetInstance().CheckRegisterCallback(); + } else { + DHLOGE("DInputClientEventHandler ProcessEvent error, because eventId is unkonwn."); + } + DHLOGI("DInputClientEventHandler ProcessEvent end"); +} + +void DistributedInputClient::CheckRegisterCallback() +{ + DHLOGI("CheckRegisterCallback called, awl[%d], dwl[%d], rnm[%d], unm[%d], rmd[%d], umd[%d]", + isAddWhiteListCbReg, isDelWhiteListCbReg, isNodeMonitorCbReg, isNodeMonitorCbUnreg, isSimulationEventCbReg, + isSimulationEventCbUnreg); + + CheckWhiteListCallback(); + CheckNodeMonitorCallback(); + CheckKeyStateCallback(); +} + +void DistributedInputClient::CheckWhiteListCallback() +{ + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("CheckWhiteListCallback client get source proxy fail"); + return; + } + if (!isAddWhiteListCbReg) { + if (addWhiteListCallback_ == nullptr) { + addWhiteListCallback_ = new (std::nothrow) AddWhiteListInfosCb(); + } + int32_t ret = + DInputSAManager::GetInstance().dInputSourceProxy_->RegisterAddWhiteListCallback(addWhiteListCallback_); + if (ret == DH_SUCCESS) { + isAddWhiteListCbReg = true; + } else { + DHLOGE("CheckWhiteListCallback client RegisterAddWhiteListCallback fail"); + } + } + if (!isDelWhiteListCbReg) { + if (delWhiteListCallback_ == nullptr) { + delWhiteListCallback_ = new (std::nothrow) DelWhiteListInfosCb(); + } + int32_t ret = + DInputSAManager::GetInstance().dInputSourceProxy_->RegisterDelWhiteListCallback(delWhiteListCallback_); + if (ret == DH_SUCCESS) { + isDelWhiteListCbReg = true; + } else { + DHLOGE("CheckWhiteListCallback client RegisterDelWhiteListCallback fail"); + } + } +} + +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; + } + + if (!isNodeMonitorCbUnreg && unregNodeListener_ != nullptr) { + DHLOGI("CheckNodeMonitorCallback need continue register unregNodeListener_."); + DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterInputNodeListener(unregNodeListener_); + isNodeMonitorCbUnreg = true; + } +} + +void DistributedInputClient::CheckKeyStateCallback() +{ + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("CheckKeyStateCallback client get source proxy fail"); + return; + } + if (!isSimulationEventCbReg && regSimulationEventListener_ != nullptr) { + DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(regSimulationEventListener_); + isSimulationEventCbReg = true; + } + + if (!isSimulationEventCbUnreg && unregSimulationEventListener_ != nullptr) { + DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSimulationEventListener( + unregSimulationEventListener_); + isSimulationEventCbUnreg = true; + } +} + int32_t DistributedInputClient::InitSource() { if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { @@ -128,9 +233,14 @@ int32_t DistributedInputClient::ReleaseSource() inputTypes_ = DInputDeviceType::NONE; sinkTypeCallback = nullptr; sourceTypeCallback = nullptr; - addWhiteListCallback = nullptr; - delWhiteListCallback = nullptr; + addWhiteListCallback_ = nullptr; + delWhiteListCallback_ = nullptr; + regNodeListener_ = nullptr; + unregNodeListener_ = nullptr; + regSimulationEventListener_ = nullptr; + unregSimulationEventListener_ = nullptr; WhiteListUtil::GetInstance().ClearWhiteList(); + return DInputSAManager::GetInstance().dInputSourceProxy_->Release(); } @@ -149,8 +259,8 @@ int32_t DistributedInputClient::ReleaseSink() int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters, const std::shared_ptr& callback) { - DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); + DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("RegisterDistributedHardware client fail"); @@ -183,7 +293,8 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::shared_ptr& callback) { - DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + DHLOGI("UnregisterDistributedHardware called, deviceId: %s, dhId: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("UnregisterDistributedHardware client fail"); @@ -216,7 +327,7 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& int32_t DistributedInputClient::PrepareRemoteInput( const std::string& deviceId, sptr callback) { - DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); + DHLOGI("PrepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str()); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("PrepareRemoteInput client fail"); @@ -227,15 +338,13 @@ int32_t DistributedInputClient::PrepareRemoteInput( return ERR_DH_INPUT_CLIENT_PREPARE_FAIL; } - addWhiteListCallback = new(std::nothrow) AddWhiteListInfosCb(); - return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(deviceId, callback, - addWhiteListCallback); + return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(deviceId, callback); } int32_t DistributedInputClient::UnprepareRemoteInput(const std::string& deviceId, sptr callback) { - DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); + DHLOGI("UnprepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str()); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("PrepareRemoteInput client fail"); @@ -243,19 +352,18 @@ int32_t DistributedInputClient::UnprepareRemoteInput(const std::string& deviceId } if (deviceId.empty() || callback == nullptr) { + DHLOGE("UnprepareRemoteInput param error, client fail"); return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL; } - delWhiteListCallback = new(std::nothrow) DelWhiteListInfosCb(); - return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback, - delWhiteListCallback); + return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback); } int32_t DistributedInputClient::StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); - + DHLOGI("StartRemoteInput called, deviceId: %s, inputTypes: %d", + GetAnonyString(deviceId).c_str(), inputTypes); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("StartRemoteInput client fail"); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; @@ -265,17 +373,17 @@ int32_t DistributedInputClient::StartRemoteInput( inputTypes > static_cast(DInputDeviceType::ALL) || inputTypes == static_cast(DInputDeviceType::NONE) || !(inputTypes & static_cast(DInputDeviceType::ALL))) { + DHLOGE("StartRemoteInput param error, client fail"); 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("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); - + DHLOGI("StopRemoteInput called, deviceId: %s, inputTypes: %d", + GetAnonyString(deviceId).c_str(), inputTypes); if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { DHLOGE("StopRemoteInput client fail"); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; @@ -285,15 +393,168 @@ int32_t DistributedInputClient::StopRemoteInput(const std::string& deviceId, con inputTypes > static_cast(DInputDeviceType::ALL) || inputTypes == static_cast(DInputDeviceType::NONE) || !(inputTypes & static_cast(DInputDeviceType::ALL))) { + DHLOGE("StopRemoteInput param error, client fail"); 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("StartRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StartRemoteInput relay type client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (srcId.empty() || sinkId.empty() || callback == nullptr || + inputTypes > static_cast(DInputDeviceType::ALL) || + inputTypes == static_cast(DInputDeviceType::NONE) || + !(inputTypes & static_cast(DInputDeviceType::ALL))) { + DHLOGE("StartRemoteInput relay type param error, client fail"); + 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("StopRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StopRemoteInput relay type client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (srcId.empty() || sinkId.empty() || callback == nullptr || + inputTypes > static_cast(DInputDeviceType::ALL) || + inputTypes == static_cast(DInputDeviceType::NONE) || + !(inputTypes & static_cast(DInputDeviceType::ALL))) { + DHLOGE("StopRemoteInput relay type param error, client fail"); + 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) +{ + DHLOGI("PrepareRemoteInput relay called, srcId: %s, sinkId: %s", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("PrepareRemoteInput relay proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + if (srcId.empty() || sinkId.empty() || callback == nullptr) { + DHLOGE("PrepareRemoteInput relay param error, client fail"); + return ERR_DH_INPUT_CLIENT_PREPARE_FAIL; + } + return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(srcId, sinkId, callback); +} + +int32_t DistributedInputClient::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + DHLOGI("UnprepareRemoteInput relay called, srcId: %s, sinkId: %s", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("UnprepareRemoteInput relay proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (srcId.empty() || sinkId.empty() || callback == nullptr) { + DHLOGE("UnprepareRemoteInput relay param error, client fail"); + return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL; + } + return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(srcId, sinkId, callback); +} + +int32_t DistributedInputClient::StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + DHLOGI("StartRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str()); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StartRemoteInput dhid proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) { + DHLOGE("StartRemoteInput dhid param error, client fail"); + return ERR_DH_INPUT_CLIENT_START_FAIL; + } + + return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(sinkId, dhIds, callback); +} + +int32_t DistributedInputClient::StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + DHLOGI("StopRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str()); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StopRemoteInput dhid proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) { + DHLOGE("StopRemoteInput dhid param error, client fail"); + return ERR_DH_INPUT_CLIENT_STOP_FAIL; + } + + return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(sinkId, dhIds, callback); +} + +int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + DHLOGI("StartRemoteInput relay by dhid called, srcId: %s, sinkId: %s", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StartRemoteInput proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) { + DHLOGE("StartRemoteInput param error, client fail"); + return ERR_DH_INPUT_CLIENT_START_FAIL; + } + + return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, dhIds, callback); +} + +int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + DHLOGI("StopRemoteInput relay by dhid called, srcId: %s, sinkId: %s", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("StopRemoteInput proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) { + DHLOGE("StopRemoteInput param error, client fail"); + return ERR_DH_INPUT_CLIENT_STOP_FAIL; + } + + return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, dhIds, callback); +} + bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) { - DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); + DHLOGI("IsNeedFilterOut called, deviceId: %s", GetAnonyString(deviceId).c_str()); return WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event); } @@ -313,7 +574,8 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) { - DHLOGI("%s called, inputType: %d, inputTypes: %d, ", __func__, inputType, static_cast(inputTypes_)); + DHLOGI("IsStartDistributedInput called, inputType: %d, current inputTypes: %d", + inputType, static_cast(inputTypes_)); int32_t retSource = 0; int32_t retSink = 0; @@ -343,6 +605,106 @@ DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& } } +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"); + isNodeMonitorCbUnreg = false; + unregNodeListener_ = listener; + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterInputNodeListener(listener); + if (ret == DH_SUCCESS) { + isNodeMonitorCbUnreg = true; + } else { + isNodeMonitorCbUnreg = false; + unregNodeListener_ = listener; + DHLOGE("DInputSAManager UnregisterInputNodeListener Failed, ret = %d", ret); + } + return ret; +} + +int32_t DistributedInputClient::RegisterSimulationEventListener(sptr listener) +{ + DHLOGI("RegisterSimulationEventListener called Simulation Event Listener Register."); + if (listener == nullptr) { + DHLOGE("RegisterSimulationEventListener param error"); + return ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL; + } + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("RegisterSimulationEventListener proxy error, client fail"); + isSimulationEventCbReg = false; + regSimulationEventListener_ = listener; + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); + if (ret == DH_SUCCESS) { + isSimulationEventCbReg = true; + } else { + isSimulationEventCbReg = false; + regSimulationEventListener_ = listener; + DHLOGE("RegisterSimulationEventListener Failed, ret = %d", ret); + } + return ret; +} + +int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr listener) +{ + DHLOGI("UnregisterSimulationEventListener called Simulation Event Listener UnRegister."); + if (listener == nullptr) { + DHLOGE("UnregisterSimulationEventListener param error"); + return ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL; + } + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("UnregisterSimulationEventListener proxy error, client fail"); + isSimulationEventCbUnreg = false; + unregSimulationEventListener_ = listener; + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSimulationEventListener(listener); + if (ret == DH_SUCCESS) { + isSimulationEventCbUnreg = true; + } else { + isSimulationEventCbUnreg = false; + unregSimulationEventListener_ = listener; + DHLOGE("UnregisterSimulationEventListener Failed, ret = %d", ret); + } + return ret; +} + bool DistributedInputClient::IsJsonData(std::string strData) const { if (strData[0] != '{') { @@ -419,7 +781,7 @@ int32_t DistributedInputClient::NotifyStopDScreen(const std::string &networkId, sptr DistributedInputClient::GetRemoteDInput(const std::string &networkId) const { - DHLOGI("start, networkId = %s", GetAnonyString(networkId).c_str()); + DHLOGI("GetRemoteDInput start, networkId = %s", GetAnonyString(networkId).c_str()); if (networkId.empty()) { DHLOGE("networkId is empty"); return nullptr; diff --git a/interfaces/ipc/src/distributed_input_sink_proxy.cpp b/interfaces/ipc/src/distributed_input_sink_proxy.cpp index c1cc3fb..ffc5aa3 100644 --- a/interfaces/ipc/src/distributed_input_sink_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_sink_proxy.cpp @@ -19,6 +19,7 @@ #include "distributed_hardware_log.h" #include "dinput_errcode.h" +#include "dinput_utils_tool.h" namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index 33baab3..7e1be41 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -58,7 +58,7 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel & int32_t DistributedInputSinkStub::InitInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) { - DHLOGI("start"); + DHLOGI("DistributedInputSinkStub InitInner start"); int32_t ret = Init(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSinkStub write ret failed"); diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index bdbda45..02fa33f 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -71,19 +71,19 @@ int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::stri } if (!data.WriteString(devId)) { DHLOGE("DistributedInputSourceProxy write devId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteString(dhId)) { DHLOGE("DistributedInputSourceProxy write dhId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteString(parameters)) { DHLOGE("DistributedInputSourceProxy write parameters failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL; @@ -104,15 +104,15 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st } if (!data.WriteString(devId)) { DHLOGE("DistributedInputSourceProxy write devId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteString(dhId)) { DHLOGE("DistributedInputSourceProxy write dhId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL; @@ -124,8 +124,7 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st } int32_t DistributedInputSourceProxy::PrepareRemoteInput( - const std::string& deviceId, sptr callback, - sptr addWhiteListCallback) + const std::string &deviceId, sptr callback) { MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { @@ -134,28 +133,25 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput( } if (!data.WriteString(deviceId)) { DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write addWhiteListCallback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } + MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL; bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_REMOTE_INPUT, data, reply); if (ret) { result = reply.ReadInt32(); } + DHLOGI("PrepareRemoteInput end, result:%d", result); return result; } -int32_t DistributedInputSourceProxy::UnprepareRemoteInput( - const std::string& deviceId, sptr callback, - sptr delWhiteListCallback) +int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &deviceId, + sptr callback) { MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { @@ -164,15 +160,11 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput( } if (!data.WriteString(deviceId)) { DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) { - DHLOGE("DistributedInputSourceProxy write delWhiteListCallback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL; @@ -180,12 +172,14 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput( if (ret) { result = reply.ReadInt32(); } + 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"); @@ -193,15 +187,15 @@ int32_t DistributedInputSourceProxy::StartRemoteInput( } if (!data.WriteString(deviceId)) { DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteUint32(inputTypes)) { DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; @@ -209,6 +203,7 @@ int32_t DistributedInputSourceProxy::StartRemoteInput( if (ret) { result = reply.ReadInt32(); } + DHLOGI("source proxy StartRemoteInput end, result:%d.", result); return result; } @@ -222,15 +217,15 @@ int32_t DistributedInputSourceProxy::StopRemoteInput( } if (!data.WriteString(deviceId)) { DHLOGE("DistributedInputSourceProxy write deviceId failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteUint32(inputTypes)) { DHLOGE("DistributedInputSourceProxy write inputTypes failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; @@ -241,6 +236,295 @@ int32_t DistributedInputSourceProxy::StopRemoteInput( 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(IDistributedSourceInput::MessageCode::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(IDistributedSourceInput::MessageCode::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) +{ + 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("Write PrepareRemoteInput relay srcid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteString(sinkId)) { + DHLOGE("Write PrepareRemoteInput relay sinkid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write PrepareRemoteInput relay callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("PrepareRemoteInput relay result:%d", result); + return result; +} + +int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + 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("Write UnprepareRemoteInput relay srcid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteString(sinkId)) { + DHLOGE("Write UnprepareRemoteInput relay sinkid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write UnprepareRemoteInput relay callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("UnprepareRemoteInput relay result:%d", result); + return result; +} + +int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + 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(sinkId)) { + DHLOGE("Write StartRemoteInput dhid sinkId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("Write StartRemoteInput dhid size to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("Write StartRemoteInput dhid dhid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write StartRemoteInput dhid callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("Source proxy StartRemoteInput dhid end, result:%d.", result); + return result; +} + +int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + 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(sinkId)) { + DHLOGE("Write StopRemoteInput dhid sinkId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("Write StopRemoteInput dhid size to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("Write StopRemoteInput dhid dhid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write StopRemoteInput dhid callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("Source proxy StopRemoteInput dhid end, result:%d.", result); + return result; +} + +int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("DistributedInputSourceProxy relay dhid write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteString(srcId)) { + DHLOGE("Write StartRemoteInput relay dhid srcId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteString(sinkId)) { + DHLOGE("Write StartRemoteInput relay dhid sinkId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("Write StartRemoteInput relay dhid size to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("Write StartRemoteInput relay dhid dhid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write StartRemoteInput relay dhid callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("Source proxy StartRemoteInput relay dhid end, result:%d.", result); + return result; +} + +int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, 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("Write StopRemoteInput relay dhid srcId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + if (!data.WriteString(sinkId)) { + DHLOGE("Write StopRemoteInput relay dhid sinkId to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("Write StopRemoteInput relay dhid size to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("Write StopRemoteInput relay dhid dhid to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + DHLOGE("Write StopRemoteInput relay dhid callback to parcel failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + DHLOGI("Source proxy StopRemoteInput relay dhid end, result:%d.", result); + return result; +} + int32_t DistributedInputSourceProxy::IsStartDistributedInput( const uint32_t& inputType, sptr callback) { @@ -251,11 +535,11 @@ int32_t DistributedInputSourceProxy::IsStartDistributedInput( } if (!data.WriteUint32(inputType)) { DHLOGE("DistributedInputSourceProxy write inputType failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } if (!data.WriteRemoteObject(callback->AsObject())) { DHLOGE("DistributedInputSourceProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_IS_START_INPUT_FAIL; @@ -266,16 +550,183 @@ int32_t DistributedInputSourceProxy::IsStartDistributedInput( return result; } -bool DistributedInputSourceProxy::SendRequest( - const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply) +int32_t DistributedInputSourceProxy::RegisterAddWhiteListCallback(sptr addWhiteListCallback) +{ + if (addWhiteListCallback == nullptr) { + DHLOGE("DistributedInputSourceProxy addWhiteListCallback is null."); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("DistributedInputSourceProxy write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteRemoteObject(addWhiteListCallback->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_WHITELIST_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + +int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr delWhiteListCallback) +{ + if (delWhiteListCallback == nullptr) { + DHLOGE("DistributedInputSourceProxy delWhiteListCallback is null."); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("DistributedInputSourceProxy write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteRemoteObject(delWhiteListCallback->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_WHITELIST_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + +int32_t DistributedInputSourceProxy::RegisterInputNodeListener(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(IDistributedSourceInput::MessageCode::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(IDistributedSourceInput::MessageCode::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(IDistributedSourceInput::MessageCode::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; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("RegisterSimulationEventListener write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + + if (!data.WriteRemoteObject(listener->AsObject())) { + DHLOGE("RegisterSimulationEventListener write callback failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_SIMULATION_EVENT_LISTENER, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + +int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr listener) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("UnregisterSimulationEventListener write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + + if (!data.WriteRemoteObject(listener->AsObject())) { + DHLOGE("UnregisterSimulationEventListener write callback failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL; + bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNREGISTER_SIMULATION_EVENT_LISTENER, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + +bool DistributedInputSourceProxy::SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, + MessageParcel &reply) { sptr remote = Remote(); if (remote == nullptr) { + DHLOGE("DistributedInputSourceProxy SendRequest remote is null."); return false; } MessageOption option(MessageOption::TF_SYNC); int32_t result = remote->SendRequest(static_cast(code), data, reply, option); if (result != DH_SUCCESS) { + DHLOGE("DistributedInputSourceProxy SendRequest error, result:%d.", result); return false; } return true; diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 7641643..bf3482f 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -79,13 +79,10 @@ int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageP int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); - sptr callback = - iface_cast(data.ReadRemoteObject()); - sptr addCallback = - iface_cast(data.ReadRemoteObject()); - int32_t ret = PrepareRemoteInput(deviceId, callback, addCallback); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = PrepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub prepareRemoteInput write ret failed"); + DHLOGE("HandlePrepareRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; @@ -94,14 +91,11 @@ int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string deviceId = data.ReadString(); - sptr callback = - iface_cast(data.ReadRemoteObject()); - sptr delCallback = - iface_cast(data.ReadRemoteObject()); - int32_t ret = UnprepareRemoteInput(deviceId, callback, delCallback); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = UnprepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub unprepareRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + DHLOGE("HandleUnprepareRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } @@ -114,7 +108,7 @@ int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, int32_t ret = StartRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub startRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } @@ -127,7 +121,143 @@ int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, M int32_t ret = StopRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub stopRemoteInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + uint32_t inputTypes = data.ReadUint32(); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("DistributedInputSourceStub write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + uint32_t inputTypes = data.ReadUint32(); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("DistributedInputSourceStub write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = PrepareRemoteInput(srcId, sinkId, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandlePrepareRelayRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = UnprepareRemoteInput(srcId, sinkId, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleUnprepareRelayRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string sinkId = data.ReadString(); + + std::vector tempVector; + uint32_t vecSize = data.ReadUint32(); + for (uint32_t i = 0; i < vecSize; i++) { + std::string dhid = data.ReadString(); + tempVector.push_back(dhid); + } + + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StartRemoteInput(sinkId, tempVector, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleStartDhidRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string sinkId = data.ReadString(); + + std::vector tempVector; + uint32_t vecSize = data.ReadUint32(); + for (uint32_t i = 0; i < vecSize; i++) { + std::string dhid = data.ReadString(); + tempVector.push_back(dhid); + } + + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StopRemoteInput(sinkId, tempVector, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleStopDhidRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + + std::vector tempVector; + uint32_t vecSize = data.ReadUint32(); + for (uint32_t i = 0; i < vecSize; i++) { + std::string dhid = data.ReadString(); + tempVector.push_back(dhid); + } + + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StartRemoteInput(srcId, sinkId, tempVector, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleStartRelayDhidRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply) +{ + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + + std::vector tempVector; + uint32_t vecSize = data.ReadUint32(); + for (uint32_t i = 0; i < vecSize; i++) { + std::string dhid = data.ReadString(); + tempVector.push_back(dhid); + } + + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = StopRemoteInput(srcId, sinkId, tempVector, callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleStopRelayDhidRemoteInput write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } @@ -139,13 +269,101 @@ int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel int32_t ret = IsStartDistributedInput(inputType, callback); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub isStartDistributedInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } -int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) +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()); + int32_t ret = RegisterAddWhiteListCallback(callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleRegisterAddWhiteListCallback write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGI("HandleRegisterDelWhiteListCallback callback is null"); + } + + int32_t ret = RegisterDelWhiteListCallback(callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleRegisterDelWhiteListCallback write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = iface_cast(data.ReadRemoteObject()); + 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()); + 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()); + int32_t ret = RegisterSimulationEventListener(callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleRegisterSimulationEventListener write ret failed, ret = %d", ret); + return ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL; + } + + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = iface_cast(data.ReadRemoteObject()); + int32_t ret = UnregisterSimulationEventListener(callback); + if (!reply.WriteInt32(ret)) { + DHLOGE("HandleUnregisterSimulationEventListener write ret failed, ret = %d", ret); + return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL; + } + + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { if (data.ReadInterfaceToken() != GetDescriptor()) { DHLOGE("DistributedInputSourceStub read token valid failed"); @@ -176,6 +394,51 @@ int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel case static_cast(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT): { return HandleStopRemoteInput(data, reply); } + case static_cast(IDistributedSourceInput::MessageCode::START_RELAY_TYPE_REMOTE_INPUT): { + return HandleStartRelayTypeRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::STOP_RELAY_TYPE_REMOTE_INPUT): { + return HandleStopRelayTypeRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT): { + return HandlePrepareRelayRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT): { + return HandleUnprepareRelayRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT): { + return HandleStartDhidRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT): { + return HandleStopDhidRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT): { + return HandleStartRelayDhidRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT): { + return HandleStopRelayDhidRemoteInput(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): { + return HandleRegisterAddWhiteListCallback(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): { + return HandleRegisterDelWhiteListCallback(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::REGISTER_NODE_LISTENER): { + return HandleRegisterInputNodeListener(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_NODE_LISTENER): { + return HandleUnRegisterInputNodeListener(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::REGISTER_SIMULATION_EVENT_LISTENER): { + return HandleRegisterSimulationEventListener(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_SIMULATION_EVENT_LISTENER): { + return HandleUnregisterSimulationEventListener(data, reply); + } + case static_cast(IDistributedSourceInput::MessageCode::SYNC_NODE_INFO_REMOTE_INPUT): { + return HandleSyncNodeInfoRemoteInput(data, reply); + } case static_cast(IDistributedSourceInput::MessageCode::ISSTART_REMOTE_INPUT): { return HandleIsStartDistributedInput(data, reply); } diff --git a/interfaces/ipc/src/input_node_listener_proxy.cpp b/interfaces/ipc/src/input_node_listener_proxy.cpp new file mode 100644 index 0000000..e136f6c --- /dev/null +++ b/interfaces/ipc/src/input_node_listener_proxy.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 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 "input_node_listener_proxy.h" + +#include "distributed_hardware_log.h" +#include "ipc_types.h" +#include "parcel.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +InputNodeListenerProxy::InputNodeListenerProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +InputNodeListenerProxy::~InputNodeListenerProxy() {} + +void InputNodeListenerProxy::OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc) +{ + sptr remote = Remote(); + if (remote == nullptr) { + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("InputNodeListenerProxy write token valid failed"); + return; + } + if (!data.WriteString(srcDevId)) { + DHLOGE("InputNodeListenerProxy write srcDevId failed"); + return; + } + if (!data.WriteString(sinkDevId)) { + DHLOGE("InputNodeListenerProxy write sinkDevId failed"); + return; + } + if (!data.WriteString(sinkNodeId)) { + DHLOGE("InputNodeListenerProxy write sinkNodeId failed"); + return; + } + if (!data.WriteString(sinkNodeDesc)) { + DHLOGE("InputNodeListenerProxy write sinkNodeDesc failed"); + return; + } + int32_t ret = remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_ON), data, reply, option); + if (ret != 0) { + return; + } +} + +void InputNodeListenerProxy::OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("InputNodeListenerProxy write token valid failed"); + return; + } + if (!data.WriteString(srcDevId)) { + DHLOGE("InputNodeListenerProxy write srcDevId failed"); + return; + } + if (!data.WriteString(sinkDevId)) { + DHLOGE("InputNodeListenerProxy write sinkDevId failed"); + return; + } + if (!data.WriteString(sinkNodeId)) { + DHLOGE("InputNodeListenerProxy write sinkNodeId failed"); + return; + } + int32_t ret = + remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_OFF), data, reply, option); + if (ret != 0) { + return; + } +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/input_node_listener_stub.cpp b/interfaces/ipc/src/input_node_listener_stub.cpp new file mode 100644 index 0000000..2f20cfc --- /dev/null +++ b/interfaces/ipc/src/input_node_listener_stub.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 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 "input_node_listener_stub.h" + +#include "distributed_hardware_log.h" +#include "string_ex.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +InputNodeListenerStub::InputNodeListenerStub() {} + +InputNodeListenerStub::~InputNodeListenerStub() {} + +int32_t InputNodeListenerStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + DHLOGE("InputNodeListenerStub read token valid failed"); + return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; + } + InputNodeListener::Message msgCode = static_cast(code); + switch (msgCode) { + case InputNodeListener::Message::RESULT_ON: { + std::string srcDevId = data.ReadString(); + std::string sinkDevId = data.ReadString(); + std::string sinkNodeId = data.ReadString(); + std::string sinkNodeDesc = data.ReadString(); + OnNodeOnLine(srcDevId, sinkDevId, sinkNodeId, sinkNodeDesc); + break; + } + case InputNodeListener::Message::RESULT_OFF: { + std::string srcDevId = data.ReadString(); + std::string sinkDevId = data.ReadString(); + std::string sinkNodeId = data.ReadString(); + OnNodeOffLine(srcDevId, sinkDevId, sinkNodeId); + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return DH_SUCCESS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/simulation_event_listener_proxy.cpp b/interfaces/ipc/src/simulation_event_listener_proxy.cpp new file mode 100644 index 0000000..ff4b7c3 --- /dev/null +++ b/interfaces/ipc/src/simulation_event_listener_proxy.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 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 "simulation_event_listener_proxy.h" + +#include "distributed_hardware_log.h" +#include "dinput_errcode.h" +#include "ipc_types.h" +#include "parcel.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +SimulationEventListenerProxy::SimulationEventListenerProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +SimulationEventListenerProxy::~SimulationEventListenerProxy() {} + +int32_t SimulationEventListenerProxy::OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) +{ + int32_t result = ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("SimulationEventListenerProxy get remote failed"); + return result; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("SimulationEventListenerProxy write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteInt32(type)) { + DHLOGE("SimulationEventListenerProxy write type failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteInt32(code)) { + DHLOGE("SimulationEventListenerProxy write code failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteInt32(value)) { + DHLOGE("SimulationEventListenerProxy write value failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + int32_t ret = + remote->SendRequest(static_cast(ISimulationEventListener::Message::RESULT_ON), data, reply, option); + if (ret == DH_SUCCESS) { + result = reply.ReadInt32(); + } else { + DHLOGE("SimulationEventListenerProxy SendRequest error:%d", ret); + } + return result; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/simulation_event_listener_stub.cpp b/interfaces/ipc/src/simulation_event_listener_stub.cpp new file mode 100644 index 0000000..5287b94 --- /dev/null +++ b/interfaces/ipc/src/simulation_event_listener_stub.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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 "simulation_event_listener_stub.h" + +#include "distributed_hardware_log.h" +#include "string_ex.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +SimulationEventListenerStub::SimulationEventListenerStub() {} + +SimulationEventListenerStub::~SimulationEventListenerStub() {} + +int32_t SimulationEventListenerStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + DHLOGE("SimulationEventListenerStub read token valid failed"); + return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; + } + ISimulationEventListener::Message msgCode = static_cast(code); + switch (msgCode) { + case ISimulationEventListener::Message::RESULT_ON: { + uint32_t eventType = data.ReadInt32(); + uint32_t eventCode = data.ReadInt32(); + int32_t eventValue = data.ReadInt32(); + int32_t ret = OnSimulationEvent(eventType, eventCode, eventValue); + if (!reply.WriteInt32(ret)) { + DHLOGE("DistributedInputSourceStub write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return DH_SUCCESS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp b/interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp new file mode 100644 index 0000000..703c621 --- /dev/null +++ b/interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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_stop_d_inputs_call_back_proxy.h" + +#include "ipc_types.h" +#include "parcel.h" + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +StartStopDInputsCallbackProxy::StartStopDInputsCallbackProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +StartStopDInputsCallbackProxy::~StartStopDInputsCallbackProxy() {} + +void StartStopDInputsCallbackProxy::OnResultDhids(const std::string &devId, const int32_t &status) +{ + sptr remote = Remote(); + if (remote == nullptr) { + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("StartStopDInputsCallbackProxy write token valid failed"); + return; + } + if (!data.WriteString(devId)) { + DHLOGE("StartStopDInputsCallbackProxy write devId valid failed"); + return; + } + if (!data.WriteInt32(status)) { + DHLOGE("StartStopDInputsCallbackProxy write status valid failed"); + return; + } + int32_t ret = remote->SendRequest(static_cast(IStartStopDInputsCallback::Message::RESULT_STRING), + data, reply, option); + if (ret != 0) { + DHLOGE("OnResultDhids error, ret = %d", ret); + return; + } + DHLOGE("OnResultDhids success."); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/start_stop_d_inputs_call_back_stub.cpp b/interfaces/ipc/src/start_stop_d_inputs_call_back_stub.cpp new file mode 100644 index 0000000..36f403f --- /dev/null +++ b/interfaces/ipc/src/start_stop_d_inputs_call_back_stub.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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_stop_d_inputs_call_back_stub.h" + +#include "string_ex.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +StartStopDInputsCallbackStub::StartStopDInputsCallbackStub() {} + +StartStopDInputsCallbackStub::~StartStopDInputsCallbackStub() {} + +int32_t StartStopDInputsCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string descriptor = data.ReadInterfaceToken(); + if (descriptor != IStartStopDInputsCallback::GetDescriptor()) { + return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR; + } + IStartStopDInputsCallback::Message msgCode = static_cast(code); + switch (msgCode) { + case IStartStopDInputsCallback::Message::RESULT_STRING: { + std::string devId = data.ReadString(); + int32_t status = data.ReadInt32(); + DHLOGW("OnResultDhids received."); + OnResultDhids(devId, 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/start_stop_result_call_back_proxy.cpp b/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp new file mode 100644 index 0000000..f1b23fe --- /dev/null +++ b/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 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 "ipc_types.h" +#include "parcel.h" + +#include "dinput_errcode.h" +#include "distributed_hardware_log.h" +#include "start_stop_result_call_back_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +StartStopResultCallbackProxy::StartStopResultCallbackProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +StartStopResultCallbackProxy::~StartStopResultCallbackProxy() {} + +void StartStopResultCallbackProxy::OnStart( + const std::string &srcId, const std::string &sinkId, std::vector &dhIds) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("StartStopResultCallbackProxy get IRemoteObject failed"); + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("StartStopResultCallbackProxy write token valid failed"); + return; + } + if (!data.WriteString(srcId)) { + DHLOGE("StartStopResultCallbackProxy write srcId valid failed"); + return; + } + if (!data.WriteString(sinkId)) { + DHLOGE("StartStopResultCallbackProxy write sinkId valid failed"); + return; + } + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("StartStopResultCallbackProxy write devData size valid failed"); + return; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("StartStopResultCallbackProxy write devData valid failed"); + return; + } + } + + int32_t ret = + remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_START), data, reply, option); + if (ret != 0) { + DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret); + return; + } + DHLOGE("OnStart success."); +} + +void StartStopResultCallbackProxy::OnStop( + const std::string &srcId, const std::string &sinkId, std::vector &dhIds) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("StartStopResultCallbackProxy get IRemoteObject failed"); + return; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("StartStopResultCallbackProxy write token valid failed"); + return; + } + if (!data.WriteString(srcId)) { + DHLOGE("StartStopResultCallbackProxy write srcId valid failed"); + return; + } + if (!data.WriteString(sinkId)) { + DHLOGE("StartStopResultCallbackProxy write sinkId valid failed"); + return; + } + + if (!data.WriteUint32(dhIds.size())) { + DHLOGE("StartStopResultCallbackProxy write devData size valid failed"); + return; + } + for (auto it = dhIds.begin(); it != dhIds.end(); ++it) { + if (!data.WriteString(*it)) { + DHLOGE("StartStopResultCallbackProxy write devData valid failed"); + return; + } + } + + int32_t ret = + remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_STOP), data, reply, option); + if (ret != 0) { + DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret); + return; + } + DHLOGE("OnStop success."); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/start_stop_result_call_back_stub.cpp b/interfaces/ipc/src/start_stop_result_call_back_stub.cpp new file mode 100644 index 0000000..c756149 --- /dev/null +++ b/interfaces/ipc/src/start_stop_result_call_back_stub.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 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_stop_result_call_back_stub.h" + +#include "string_ex.h" + +#include "constants_dinput.h" +#include "dinput_errcode.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +StartStopResultCallbackStub::StartStopResultCallbackStub() {} + +StartStopResultCallbackStub::~StartStopResultCallbackStub() {} + +int32_t StartStopResultCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string descriptor = data.ReadInterfaceToken(); + if (descriptor != IStartStopResultCallback::GetDescriptor()) { + return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR; + } + IStartStopResultCallback::Message msgCode = static_cast(code); + switch (msgCode) { + case IStartStopResultCallback::Message::RESULT_START: { + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + + uint32_t size = data.ReadUint32(); + std::vector dhIds; + for (uint32_t i = 0; i < size; i++) { + std::string dhId = data.ReadString(); + dhIds.push_back(dhId); + } + DHLOGW("OnStart received."); + OnStart(srcId, sinkId, dhIds); + break; + } + case IStartStopResultCallback::Message::RESULT_STOP: { + std::string srcId = data.ReadString(); + std::string sinkId = data.ReadString(); + uint32_t size = data.ReadUint32(); + std::vector dhIds; + for (uint32_t i = 0; i < size; i++) { + std::string dhId = data.ReadString(); + dhIds.push_back(dhId); + } + DHLOGW("OnStop received."); + OnStop(srcId, sinkId, dhIds); + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return DH_SUCCESS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/common/include/dinput_sink_trans_callback.h b/services/common/include/dinput_sink_trans_callback.h index 2f17451..9e8bf34 100644 --- a/services/common/include/dinput_sink_trans_callback.h +++ b/services/common/include/dinput_sink_trans_callback.h @@ -27,6 +27,9 @@ public: 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; virtual ~DInputSinkTransCallback() {} }; } // namespace DistributedInput diff --git a/services/common/include/dinput_softbus_define.h b/services/common/include/dinput_softbus_define.h index 2a28621..97a8565 100644 --- a/services/common/include/dinput_softbus_define.h +++ b/services/common/include/dinput_softbus_define.h @@ -50,9 +50,14 @@ namespace DistributedInput { #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" #define DINPUT_SOFTBUS_KEY_INPUT_DATA "dinput_softbus_key_input_data" + #define DINPUT_SOFTBUS_KEY_KEYSTATE_DHID "dinput_softbus_key_keystate_dhid" + #define DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE "dinput_softbus_key_keystate_type" + #define DINPUT_SOFTBUS_KEY_KEYSTATE_CODE "dinput_softbus_key_keystate_code" + #define DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE "dinput_softbus_key_keystate_value" // json value const uint32_t TRANS_SINK_MSG_ONPREPARE = 1; @@ -61,11 +66,17 @@ namespace DistributedInput { const uint32_t TRANS_SINK_MSG_ONSTOP = 4; const uint32_t TRANS_SINK_MSG_BODY_DATA = 5; const uint32_t TRANS_SINK_MSG_LATENCY = 6; + const uint32_t TRANS_SINK_MSG_DHID_ONSTART = 7; + const uint32_t TRANS_SINK_MSG_DHID_ONSTOP = 8; + const uint32_t TRANS_SINK_MSG_KEY_STATE = 9; + const uint32_t TRANS_SOURCE_MSG_PREPARE = 11; const uint32_t TRANS_SOURCE_MSG_UNPREPARE = 12; - const uint32_t TRANS_SOURCE_MSG_START = 13; - const uint32_t TRANS_SOURCE_MSG_STOP = 14; - const uint32_t TRANS_SOURCE_MSG_LATENCY = 15; + const uint32_t TRANS_SOURCE_MSG_START_TYPE = 13; + const uint32_t TRANS_SOURCE_MSG_STOP_TYPE = 14; + const uint32_t TRANS_SOURCE_MSG_START_DHID = 15; + const uint32_t TRANS_SOURCE_MSG_STOP_DHID = 16; + const uint32_t TRANS_SOURCE_MSG_LATENCY = 17; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/common/include/dinput_source_trans_callback.h b/services/common/include/dinput_source_trans_callback.h index c355bf2..fbcb7ec 100644 --- a/services/common/include/dinput_source_trans_callback.h +++ b/services/common/include/dinput_source_trans_callback.h @@ -29,6 +29,10 @@ public: 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, + const uint32_t code, const uint32_t value) = 0; virtual void onReceivedEventRemoteInput(const std::string deviceId, const std::string &object) = 0; }; } // namespace DistributedInput diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 81e9c06..4382c04 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -37,7 +37,10 @@ public: static DistributedInputCollector &GetInstance(); int32_t Init(std::shared_ptr sinkHandler); void Release(); - void SetInputTypes(const uint32_t& inputType); + void SetSharingTypes(const uint32_t &inputType); + void SetSharingDhIds(bool enabled, std::vector dhIds); + void GetMouseNodePath(std::vector dhIds, std::string &mouseNodePath, std::string &dhid); + bool GetAllDevicesStoped(); private: DistributedInputCollector(); diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index fb46999..9d72e2c 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ void *DistributedInputCollector::CollectEventsThread(void *param) void DistributedInputCollector::StartCollectEventsThread() { while (isCollectingEvents_) { + memset_s(&mEventBuffer, sizeof(mEventBuffer), 0, sizeof(mEventBuffer)); size_t count = inputHub_->StartCollectInputEvents(mEventBuffer, INPUT_EVENT_BUFFER_SIZE); if (count > 0) { DHLOGI("Count: %zu", count); @@ -138,7 +140,7 @@ void DistributedInputCollector::StopCollectEventsThread() DHLOGW("DistributedInputCollector::StopCollectEventsThread exit!"); } -void DistributedInputCollector::SetInputTypes(const uint32_t& inputType) +void DistributedInputCollector::SetSharingTypes(const uint32_t &inputType) { inputTypes_ = 0; if ((inputType & static_cast(DInputDeviceType::MOUSE)) != 0) { @@ -148,7 +150,7 @@ void DistributedInputCollector::SetInputTypes(const uint32_t& inputType) inputTypes_ |= INPUT_DEVICE_CLASS_KEYBOARD; } if ((inputType & static_cast(DInputDeviceType::TOUCHSCREEN)) != 0) { - inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT; + inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT | INPUT_DEVICE_CLASS_TOUCH; } inputHub_->SetSupportInputType(inputTypes_); @@ -158,6 +160,22 @@ void DistributedInputCollector::Release() { StopCollectEventsThread(); } + +void DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector dhIds) +{ + inputHub_->SetSharingDevices(enabled, dhIds); +} + +void DistributedInputCollector::GetMouseNodePath( + std::vector dhIds, std::string &mouseNodePath, std::string &dhid) +{ + inputHub_->GetShareMousePathByDhId(dhIds, mouseNodePath, dhid); +} + +bool DistributedInputCollector::GetAllDevicesStoped() +{ + return inputHub_->GetAllDevicesStoped(); +} } // namespace DistributedInput } // namespace DistributedHardware } // 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 cd65aec..22a19d5 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -18,7 +18,8 @@ #include #include - +#include +#include #include #include @@ -54,8 +55,18 @@ public: void onUnprepareRemoteInput(const int32_t& sessionId); void onStartRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes); void onStopRemoteInput(const int32_t& sessionId, const uint32_t& inputTypes); + void onStartRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids); + void onStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids); + private: DistributedInputSinkManager *sinkManagerObj_; + static inline int bit_is_set(const unsigned long *array, int bit) + { + return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS))); + } + void SleepTimeMs(); + void StringSplitToSet(const std::string &str, const char split, std::set &vecStr); + void CheckKeyState(const int32_t &sessionId, const std::string &strDhids); }; class ProjectWindowListener : public PublisherListenerStub { @@ -123,9 +134,15 @@ private: std::shared_ptr runner_; std::shared_ptr handler_; + std::mutex mutex_; bool InitAuto(); DInputDeviceType inputTypes_; sptr projectWindowListener_ = nullptr; + std::set sharingDhIds_; + std::map> sharingDhIdsMap_; + void StoreStartDhids(int32_t sessionId, const std::set &dhIds); + void DeleteStopDhids(int32_t sessionId, const std::set delDhIds, std::vector &stopDhIds); + bool IsDeleteDhidExist(int32_t sessionId, const std::string &delstr); }; } // 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 db68d78..f52eb95 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -15,9 +15,16 @@ #include "distributed_input_sink_manager.h" +#include +#include +#include +#include + #include "anonymous_string.h" +#include "dinput_softbus_define.h" #include "distributed_hardware_fwk_kit.h" #include "distributed_hardware_log.h" + #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "nlohmann/json.hpp" @@ -132,30 +139,11 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession(); DHLOGI("onStartRemoteInput called, curSessionId:%s, new sessionId: %s", GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(sessionId).c_str()); + // set new session + int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - int32_t startRes = DH_SUCCESS; - if (curSessionId == sessionId) { - DHLOGI("sessionId switch state is true, need not switch"); - } else { - DHLOGI("sessionId switch state is false, need to switch"); - int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - - sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? - DInputServerType::SINK_SERVER_TYPE : - DInputServerType::NULL_SERVER_TYPE); - - if ((curSessionId != ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) && (startRes == DH_SUCCESS)) { - DHLOGI("notify curSessionId:%s Interrupted.", GetAnonyInt32(curSessionId).c_str()); - nlohmann::json jsonStrStp; - jsonStrStp[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; - jsonStrStp[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; - jsonStrStp[DINPUT_SOFTBUS_KEY_RESP_VALUE] = false; - std::string smsgStp = jsonStrStp.dump(); - DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(curSessionId, smsgStp); - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); - } - } + sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE + : DInputServerType::NULL_SERVER_TYPE); bool result = (startRes == DH_SUCCESS) ? true : false; nlohmann::json jsonStrSta; @@ -163,13 +151,12 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( jsonStrSta[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result; std::string smsgSta = jsonStrSta.dump(); - DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta); // add the input type if (startRes == DH_SUCCESS) { sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); + DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes()); } IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback(); @@ -189,7 +176,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - (sinkManagerObj_->GetInputTypes() & inputTypes)); - DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes()); + DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes()); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; @@ -198,8 +185,9 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( std::string smsg = jsonStr.dump(); DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - if (sinkManagerObj_->GetInputTypes() == static_cast(DInputDeviceType::NONE)) { - DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId); + bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped(); + if (isAllClosed) { + DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { DHLOGI("all session is stop."); @@ -216,6 +204,219 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( } } +void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInputDhid(const int32_t &sessionId, + const std::string &strDhids) +{ + int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession(); + DHLOGE("onStartRemoteInputDhid called, curSessionId:%s, new sessionId: %s", + GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(sessionId).c_str()); + // set new session + int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); + bool result = (startRes == DH_SUCCESS) ? true : false; + nlohmann::json jsonStrSta; + jsonStrSta[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTART; + jsonStrSta[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids; + jsonStrSta[DINPUT_SOFTBUS_KEY_RESP_VALUE] = result; + std::string smsgSta = jsonStrSta.dump(); + DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsgSta); + + if (startRes != DH_SUCCESS) { + DHLOGE("onStartRemoteInputDhid StartSwitch error."); + return; + } + + if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { + DHLOGW("onStartRemoteInputDhid called, this is the only session."); + } + + CheckKeyState(sessionId, strDhids); + // add the dhids + if (startRes == DH_SUCCESS) { + std::set setStr; + StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr); + sinkManagerObj_->StoreStartDhids(sessionId, setStr); + std::vector vecStr; + vecStr.assign(setStr.begin(), setStr.end()); + DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr); + } +} + +void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(const int32_t &sessionId, + const std::string &strDhids) +{ + DHLOGI("onStopRemoteInputDhid called, sessionId: %s", GetAnonyInt32(sessionId).c_str()); + std::vector stopStr; + std::set setStr; + StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr); + sinkManagerObj_->DeleteStopDhids(sessionId, setStr, stopStr); + DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopStr); + DHLOGE("onStopRemoteInputDhid called, sessionId: %d is closed.", sessionId); + DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId); + + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTOP; + jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strDhids; + jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; + std::string smsg = jsonStr.dump(); + DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); + + bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped(); + 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("onStartRemoteInput called, all session is stop."); + sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); + } + } +} + +void DistributedInputSinkManager::DInputSinkListener::StringSplitToSet(const std::string &str, const char split, + std::set &vecStr) +{ + if (str.empty()) { + DHLOGE("param str is error."); + return; + } + std::string strTmp = str + split; + size_t pos = strTmp.find(split); + while (pos != strTmp.npos) { + std::string matchTmp = strTmp.substr(0, pos); + vecStr.insert(matchTmp); + strTmp = strTmp.substr(pos + 1, strTmp.size()); + pos = strTmp.find(split); + } +} + +void DistributedInputSinkManager::DInputSinkListener::SleepTimeMs() +{ + std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS)); +} + +void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_t &sessionId, + const std::string &strDhids) +{ + std::set setStr; + StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr); + std::string mouseNodePath; + std::string dhid; + std::vector vecStr; + vecStr.assign(setStr.begin(), setStr.end()); + DistributedInputCollector::GetInstance().GetMouseNodePath(vecStr, mouseNodePath, dhid); + if (mouseNodePath.empty()) { + DHLOGE("mouse Node Path is empty."); + return; + } + + int fd = open(mouseNodePath.c_str(), O_RDONLY | O_NONBLOCK); + if (fd < 0) { + DHLOGE("open mouse Node Path error:", errno); + return; + } + DHLOGI("mouse Node Path fd: %d", fd); + + uint32_t count = 0; + int rc = 0; + int keyVal = 0; + unsigned long keystate[NLONGS(KEY_CNT)] = { 0 }; + while (true) { + if (count > READ_RETRY_MAX) { + break; + } + // Query all key state + rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate); + if (rc < 0) { + DHLOGE("read all key state failed, rc: ", rc); + SleepTimeMs(); + continue; + } + + keyVal = bit_is_set(keystate, BTN_LEFT); + if (keyVal != 0) { + DHLOGI("mouse left button is down."); + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_KEY_STATE; + jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID] = dhid; + jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE] = EV_KEY; + jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE] = BTN_LEFT; + jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE] = KEY_DOWN_STATE; + std::string smsg = jsonStr.dump(); + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, smsg); + break; + } + SleepTimeMs(); + count += 1; + } + if (fd > 0) { + close(fd); + } +} + +bool DistributedInputSinkManager::IsDeleteDhidExist(int32_t sessionId, const std::string &delstr) +{ + for (auto sessionDhid : sharingDhIdsMap_) { + if (sessionDhid.first == sessionId) { + DHLOGW("IsDeleteDhidExist sessionId=%d is self, ignore.", sessionId); + continue; + } + for (auto dhid : sessionDhid.second) { + if (delstr == dhid) { + DHLOGI("IsDeleteDhidExist delstr=%s is find.", delstr.c_str()); + return true; + } + } + } + DHLOGW("IsDeleteDhidExist delstr=%s is not find.", delstr.c_str()); + return false; +} + +void DistributedInputSinkManager::DeleteStopDhids(int32_t sessionId, const std::set delDhIds, + std::vector &stopDhIds) +{ + std::lock_guard lock(mutex_); + if (sharingDhIdsMap_.count(sessionId) <= 0) { + DHLOGE("DeleteStopDhids sessionId:%d is not exist.", sessionId); + return; + } + DHLOGI("DeleteStopDhids sessionId=%d before has dhid.size=%d, delDhIds.size=%d.", sessionId, + sharingDhIdsMap_[sessionId].size(), delDhIds.size()); + for (auto delstr : delDhIds) { + sharingDhIdsMap_[sessionId].erase(delstr); + } + if (sharingDhIdsMap_[sessionId].size() == 0) { + sharingDhIdsMap_.erase(sessionId); + DHLOGI("DeleteStopDhids sessionId=%d is delete.", sessionId); + } else { + DHLOGI("DeleteStopDhids sessionId=%d after has dhid.size=%d.", sessionId, sharingDhIdsMap_[sessionId].size()); + } + // find which dhid can be stop + bool isFind = false; + for (auto tmp : delDhIds) { + isFind = IsDeleteDhidExist(sessionId, tmp); + if (!isFind) { + stopDhIds.push_back(tmp); + sharingDhIds_.erase(tmp); + } + } +} + +void DistributedInputSinkManager::StoreStartDhids(int32_t sessionId, const std::set &dhIds) +{ + std::set tmpDhids; + std::lock_guard lock(mutex_); + if (sharingDhIdsMap_.count(sessionId) > 0) { + tmpDhids = sharingDhIdsMap_[sessionId]; + } + DHLOGI("StoreStartDhids start tmpDhids.size=%d, add dhIds.size=%d.", tmpDhids.size(), dhIds.size()); + for (auto iter : dhIds) { + tmpDhids.insert(iter); + sharingDhIds_.insert(iter); + } + sharingDhIdsMap_[sessionId] = tmpDhids; + DHLOGI("StoreStartDhids end tmpDhids.size=%d", tmpDhids.size()); +} + void DistributedInputSinkManager::OnStart() { if (serviceRunningState_ == ServiceSinkRunningState::STATE_RUNNING) { @@ -229,7 +430,9 @@ void DistributedInputSinkManager::OnStart() } serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING; runner_->Run(); - /* Publish service maybe failed, so we need call this function at the last, + + /* + * Publish service maybe failed, so we need call this function at the last, * so it can't affect the TDD test program. */ bool ret = Publish(this); @@ -304,6 +507,12 @@ int32_t DistributedInputSinkManager::Release() // 2.close all session DistributedInputSinkTransport::GetInstance().CloseAllSession(); + { + std::lock_guard lock(mutex_); + sharingDhIds_.clear(); + sharingDhIdsMap_.clear(); + } + // 3.notify callback servertype SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); IStartDInputServerCallback *startServerCB = GetStartDInputServerCback(); @@ -389,6 +598,11 @@ DistributedInputSinkManager::ProjectWindowListener::~ProjectWindowListener() void DistributedInputSinkManager::ProjectWindowListener::OnMessage(const DHTopic topic, const std::string& message) { + DHLOGI("ProjectWindowListener OnMessage!"); + if (topic != DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO) { + DHLOGE("this topic is wrong, %d", static_cast(topic)); + return; + } std::string srcDeviceId = ""; uint64_t srcWinId = 0; SinkScreenInfo sinkScreenInfo = {}; 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 1b02fe3..5966f1d 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp @@ -19,6 +19,7 @@ #include "iservice_registry.h" #include "system_ability_definition.h" +#include "dinput_errcode.h" using namespace testing::ext; using namespace OHOS::DistributedHardware::DistributedInput; @@ -42,6 +43,12 @@ void DistributedInputSinkManagerTest::SetUpTestCase() void DistributedInputSinkManagerTest::TearDownTestCase() { } + +HWTEST_F(DistributedInputSinkManagerTest, Init01, testing::ext::TestSize.Level0) +{ + int32_t ret = sinkManager_->Init(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL, ret); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/sink/transport/include/distributed_input_sink_transport.h b/services/sink/transport/include/distributed_input_sink_transport.h index 547f49d..6458fd2 100644 --- a/services/sink/transport/include/distributed_input_sink_transport.h +++ b/services/sink/transport/include/distributed_input_sink_transport.h @@ -46,6 +46,7 @@ public: int32_t RespStartRemoteInput(const int32_t sessionId, std::string &smsg); int32_t RespStopRemoteInput(const int32_t sessionId, std::string &smsg); int32_t RespLatency(const int32_t sessionId, std::string &smsg); + void SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg); int32_t OnSessionOpened(int32_t sessionId, int32_t result); void OnSessionClosed(int32_t sessionId); @@ -62,6 +63,8 @@ public: std::shared_ptr GetEventHandler(); void CloseAllSession(); + int32_t GetSessionIdByNetId(const std::string &srcId); + void GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId); private: int32_t SendMessage(int32_t sessionId, std::string &message); @@ -71,9 +74,11 @@ private: 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); private: - std::string deviceId_; + std::map sessionDevMap_; // source networkId, sessionId 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 e325d03..ffe4112 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -26,6 +26,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_low_latency.h" +#include "dinput_softbus_define.h" #include "dinput_utils_tool.h" #include "hidumper.h" #include "session.h" @@ -34,17 +35,17 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -DistributedInputSinkTransport::DistributedInputSinkTransport() +DistributedInputSinkTransport::DistributedInputSinkTransport() : sessionDevMap_({}), mySessionName_("") { std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); eventHandler_ = std::make_shared(runner); - mySessionName_ = ""; DHLOGI("DistributedInputSinkTransport eventHandler_"); } DistributedInputSinkTransport::~DistributedInputSinkTransport() { DHLOGI("~DistributedInputSinkTransport"); + sessionDevMap_.clear(); (void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str()); } @@ -209,8 +210,7 @@ int32_t DistributedInputSinkTransport::RespStartRemoteInput( } } -int32_t DistributedInputSinkTransport::RespStopRemoteInput( - const int32_t sessionId, std::string &smsg) +int32_t DistributedInputSinkTransport::RespStopRemoteInput(const int32_t sessionId, std::string &smsg) { if (sessionId > 0) { DHLOGI("RespStopRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); @@ -243,9 +243,22 @@ int32_t DistributedInputSinkTransport::RespLatency(const int32_t sessionId, std: return DH_SUCCESS; } +void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg) +{ + if (sessionId <= 0) { + DHLOGE("SendKeyStateNodeMsg error, sessionId <= 0."); + return; + } + DHLOGI("SendKeyStateNodeMsg sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); + int32_t ret = SendMessage(sessionId, smsg); + if (ret != DH_SUCCESS) { + DHLOGE("SendKeyStateNodeMsg error, SendMessage fail."); + } +} + int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::string &message) { - DHLOGI("start SendMessage"); + DHLOGD("start SendMessage"); if (message.size() > MSG_MAX_SIZE) { DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE"); return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL; @@ -267,6 +280,27 @@ int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::strin return ret; } +int32_t DistributedInputSinkTransport::GetSessionIdByNetId(const std::string &srcId) +{ + std::map::iterator it = sessionDevMap_.find(srcId); + if (it != sessionDevMap_.end()) { + return it->second; + } + DHLOGE("get session id failed, srcId = %s", GetAnonyString(srcId).c_str()); + return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_GET_SESSIONID_FAIL; +} + +void DistributedInputSinkTransport::GetDeviceIdBySessionId(int32_t sessionId, std::string &srcId) +{ + for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) { + if (sessionId == iter->second) { + srcId = iter->first; + return; + } + } + srcId = ""; +} + int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result) { if (result != DH_SUCCESS) { @@ -287,17 +321,19 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_ char peerDevId[DEVICE_ID_SIZE_MAX] = ""; int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); + DHLOGE("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } // get other device session name ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get my peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); + DHLOGE("get my peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); if (ret != DH_SUCCESS) { - DHLOGI("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); + DHLOGE("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); + } else { + sessionDevMap_[peerDevId] = sessionId; } DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s", mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str()); @@ -319,6 +355,12 @@ void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId) if (ret != DH_SUCCESS) { DHLOGI("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } + for (auto iter = sessionDevMap_.begin(); iter != sessionDevMap_.end(); iter++) { + if (iter->second == sessionId) { + sessionDevMap_.erase(iter); + break; + } + } DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); HiDumper::GetInstance().SetSessionStatus(std::string(peerDevId), SessionStatus::CLOSED); HiDumper::GetInstance().DeleteSessionInfo(std::string(peerDevId)); @@ -381,12 +423,12 @@ void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t sessionId void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) { if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START, data type error."); + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_TYPE, data type error."); 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 deviceId:%s inputTypes:%d .", + DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START_TYPE deviceId:%s inputTypes:%d .", GetAnonyString(deviceId).c_str(), inputTypes); callback_->onStartRemoteInput(sessionId, inputTypes); } @@ -394,12 +436,12 @@ void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, co void DistributedInputSinkTransport::NotifyStopRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) { if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string()) { - DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP, data type is error."); + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_TYPE, data type is error."); 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 deviceId:%s.", GetAnonyString(deviceId).c_str()); + DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE deviceId:%s.", GetAnonyString(deviceId).c_str()); callback_->onStopRemoteInput(sessionId, inputTypes); } @@ -422,6 +464,44 @@ void DistributedInputSinkTransport::NotifyLatency(int32_t sessionId, const nlohm RespLatency(sessionId, smsg); } +void DistributedInputSinkTransport::NotifyStartRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg) +{ + if (!recMsg.contains(DINPUT_SOFTBUS_KEY_DEVICE_ID) || + !recMsg.contains(DINPUT_SOFTBUS_KEY_VECTOR_DHID)) { + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_DHID, key not exist."); + return; + } + if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string() || + !recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID].is_string()) { + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_START_DHID, data type error."); + return; + } + std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; + std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; + DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_DHID deviceId:%s .", + GetAnonyString(deviceId).c_str()); + callback_->onStartRemoteInputDhid(sessionId, strTmp); +} + +void DistributedInputSinkTransport::NotifyStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg) +{ + if (!recMsg.contains(DINPUT_SOFTBUS_KEY_DEVICE_ID) || + !recMsg.contains(DINPUT_SOFTBUS_KEY_VECTOR_DHID)) { + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_DHID, key not exist."); + return; + } + if (!recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID].is_string() || + !recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID].is_string()) { + DHLOGE("OnBytesReceived cmdType TRANS_SOURCE_MSG_STOP_DHID, data type is error."); + return; + } + std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; + std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; + DHLOGE("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_DHID deviceId:%s.", + GetAnonyString(deviceId).c_str()); + callback_->onStopRemoteInputDhid(sessionId, strTmp); +} + void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const std::string& message) { if (callback_ == nullptr) { @@ -455,11 +535,11 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s NotifyUnprepareRemoteInput(sessionId, recMsg); break; } - case TRANS_SOURCE_MSG_START: { + case TRANS_SOURCE_MSG_START_TYPE: { NotifyStartRemoteInput(sessionId, recMsg); break; } - case TRANS_SOURCE_MSG_STOP: { + case TRANS_SOURCE_MSG_STOP_TYPE: { NotifyStopRemoteInput(sessionId, recMsg); break; } @@ -467,6 +547,14 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s NotifyLatency(sessionId, recMsg); break; } + case TRANS_SOURCE_MSG_START_DHID: { + NotifyStartRemoteInputDhid(sessionId, recMsg); + break; + } + case TRANS_SOURCE_MSG_STOP_DHID: { + NotifyStopRemoteInputDhid(sessionId, recMsg); + break; + } default: DHLOGE("OnBytesReceived cmdType is undefined."); break; 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 9a8afb5..e646b48 100644 --- a/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp +++ b/services/sink/transport/test/sinktransunittest/distributed_input_sinktrans_test.cpp @@ -38,6 +38,12 @@ void DistributedInputSinkTransTest::TearDownTestCase() { } +HWTEST_F(DistributedInputSinkTransTest, Init, testing::ext::TestSize.Level0) +{ + int32_t ret = DistributedInputSinkTransport::GetInstance().Init(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL, ret); +} + HWTEST_F(DistributedInputSinkTransTest, RespPrepareRemoteInput01, testing::ext::TestSize.Level1) { int32_t sessionId = -1; diff --git a/services/source/inputinject/BUILD.gn b/services/source/inputinject/BUILD.gn index 1b3ac65..53fe379 100644 --- a/services/source/inputinject/BUILD.gn +++ b/services/source/inputinject/BUILD.gn @@ -19,17 +19,20 @@ ohos_shared_library("libdinput_inject") { include_dirs = [ "include", "${common_path}/include", + "${frameworks_path}/include", "//commonlibrary/c_utils/base/include", "//utils/system/safwk/native/include", "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", + "${service_common}/include", "//third_party/json/include", "${dfx_utils_path}/include", "${utils_path}/include", "${fwk_interfaces_path}/include", "${fwk_interfaces_path}/include/ipc", + "${distributedinput_path}/inputdevicehandler/include", ] sources = [ @@ -41,6 +44,7 @@ ohos_shared_library("libdinput_inject") { "src/virtual_mouse.cpp", "src/virtual_touchpad.cpp", "src/virtual_touchscreen.cpp", + "${common_path}/include/dinput_struct_data.cpp", ] defines = [ @@ -56,6 +60,7 @@ ohos_shared_library("libdinput_inject") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//third_party/openssl:libcrypto_static", "${fwk_interfaces_path}:libdhfwk_sdk", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ @@ -64,6 +69,8 @@ ohos_shared_library("libdinput_inject") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 6c3f980..e6448a9 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -17,10 +17,14 @@ #define DISTRIBUTED_INPUT_INJECT_H #include +#include #include #include "constants_dinput.h" +#include "distributed_input_handler.h" #include "distributed_input_node_manager.h" +#include "dinput_struct_data.h" +#include "i_input_node_listener.h" namespace OHOS { namespace DistributedHardware { @@ -43,12 +47,24 @@ public: int32_t RemoveVirtualTouchScreenNode(const std::string& dhId); 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); + + void InputDeviceEventInject(const std::shared_ptr &rawEvent); + void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId, + const std::string &sinkNodeDesc); + void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); + private: DistributedInputInject(); ~DistributedInputInject(); std::unique_ptr inputNodeManager_; std::mutex inputNodeManagerMutex_; + std::set> inputNodeListeners_; + std::mutex inputNodeListenersMutex_; // The event queue. static const int EVENT_BUFFER_SIZE = 16; diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 6720790..5df7787 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -49,12 +49,16 @@ public: int32_t RemoveVirtualTouchScreenNode(const std::string& dhId); int32_t GetVirtualTouchScreenFd(); + int32_t GetDeviceInfo(std::string &deviceId); + void GetDevicesInfoByType(const std::string &networkId, int32_t inputTypes, std::map &datas); + void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); + void ProcessInjectEvent(const std::shared_ptr &rawEvent); + private: void AddDeviceLocked(const std::string& dhId, std::unique_ptr device); int32_t CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId); void stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf); void InjectEvent(); - void ProcessInjectEvent(const std::shared_ptr &rawEvent); /* the key is dhId, and the value is virtualDevice */ std::map> virtualDeviceMap_; diff --git a/services/source/inputinject/include/virtual_device.h b/services/source/inputinject/include/virtual_device.h index 94861e6..6864d3e 100644 --- a/services/source/inputinject/include/virtual_device.h +++ b/services/source/inputinject/include/virtual_device.h @@ -38,11 +38,14 @@ public: virtual ~VirtualDevice(); bool DoIoctl(int32_t fd, int32_t request, const uint32_t value); bool CreateKey(); - bool SetPhys(const std::string deviceName); - bool SetUp(const std::string& devId, const std::string& dhId); - bool InjectInputEvent(const input_event& event); + bool SetPhys(const std::string deviceName, std::string dhId); + bool SetUp(const std::string &devId, const std::string &dhId); + bool InjectInputEvent(const input_event &event); void SetNetWorkId(const std::string netWorkId); - int32_t GetFd(); + std::string GetNetWorkId(); + + int32_t GetDeviceFd(); + int32_t GetDeviceType(); protected: VirtualDevice(); @@ -59,6 +62,7 @@ protected: const uint16_t vendorId_; const uint16_t productId_; const uint16_t version_; + const uint16_t classes_; struct uinput_user_dev dev_ {}; struct uinput_abs_setup absTemp_ = {}; std::vector absInit_; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 0f55848..90d8bbb 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -51,8 +51,8 @@ DistributedInputInject &DistributedInputInject::GetInstance() int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters) { - DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); + DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("the DistributedInputNodeManager is null\n"); @@ -62,13 +62,20 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& d DHLOGE("create virtual device error\n"); 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)); return DH_SUCCESS; } int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId) { - DHLOGI("%s called, deviceId: %s, dhId: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + DHLOGI("UnregisterDistributedHardware called, deviceId: %s, dhId: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { DHLOGE("the DistributedInputNodeManager is null\n"); @@ -78,10 +85,48 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string& 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::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) +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); + return DH_SUCCESS; +} + +int32_t DistributedInputInject::GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, + std::vector &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, GetAnonyString(pBuf.descriptor).c_str()); @@ -102,7 +147,43 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::st return DH_SUCCESS; } -int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize) +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) { std::lock_guard lock(inputNodeManagerMutex_); if (inputNodeManager_ == nullptr) { diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index b65f983..50bc573 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -25,8 +25,11 @@ #include "distributed_hardware_log.h" #include "nlohmann/json.hpp" +#include "softbus_bus_center.h" + #include "dinput_context.h" #include "dinput_errcode.h" +#include "dinput_softbus_define.h" #include "virtual_keyboard.h" #include "virtual_mouse.h" #include "virtual_touchpad.h" @@ -88,12 +91,12 @@ int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std:: device = std::make_unique(event); } else if (event.classes & INPUT_DEVICE_CLASS_CURSOR) { device = std::make_unique(event); - } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) { - device = std::make_unique(event); } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH_MT) { inputHub_->ScanInputDevices(DEVICE_PATH); LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo; device = std::make_unique(event, info, info.absMtPositionXMax, info.absMtPositionYMax); + } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) { + device = std::make_unique(event); } else { DHLOGW("could not find the deviceType\n"); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; @@ -132,7 +135,7 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } - virtualTouchScreenFd_ = device->GetFd(); + virtualTouchScreenFd_ = device->GetDeviceFd(); AddDeviceLocked(dhId, std::move(device)); DHLOGI("CreateVirtualTouchScreenNode end, dhId: %s", GetAnonyString(dhId).c_str()); return DH_SUCCESS; @@ -160,15 +163,15 @@ void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std:: int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId) { - DHLOGI("%s called, dhId=%s", __func__, GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called, dhId=%s", GetAnonyString(dhId).c_str()); std::lock_guard lock(virtualDeviceMapMutex_); std::map>::iterator iter = virtualDeviceMap_.find(dhId); if (iter != virtualDeviceMap_.end()) { - DHLOGI("%s called success, dhId=%s", __func__, GetAnonyString(dhId).c_str()); + DHLOGI("CloseDeviceLocked called success, dhId=%s", GetAnonyString(dhId).c_str()); virtualDeviceMap_.erase(iter); return DH_SUCCESS; } - DHLOGE("%s called failure, dhId=%s", __func__, GetAnonyString(dhId).c_str()); + DHLOGE("CloseDeviceLocked called failure, dhId=%s", GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } @@ -255,6 +258,60 @@ void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptrInjectInputEvent(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::GetDevicesInfoByType(const std::string &networkId, int32_t inputTypes, + std::map &datas) +{ + uint32_t input_types_ = 0; + + if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_CURSOR; + } + + if ((inputTypes & static_cast(DInputDeviceType::KEYBOARD)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_KEYBOARD; + } + + if ((inputTypes & static_cast(DInputDeviceType::MOUSE)) != 0) { + input_types_ |= INPUT_DEVICE_CLASS_TOUCH; + } + + std::lock_guard lock(virtualDeviceMapMutex_); + for (const auto &[id, virdevice] : virtualDeviceMap_) { + if ((virdevice->GetDeviceType() & input_types_) && (virdevice->GetNetWorkId() == networkId)) { + datas.insert(std::pair(virdevice->GetDeviceFd(), id)); + } + } +} + +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; + } + } + } +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index eb6de3b..13f7140 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -20,18 +20,19 @@ #include "anonymous_string.h" #include "distributed_hardware_log.h" +#include "constants_dinput.h" #include "hidumper.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { VirtualDevice::VirtualDevice() - : deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0) + : deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0), classes_(0) { } -VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_( - event.name), busType_(event.bus), vendorId_(event.vendor), productId_(event.product), version_(event.version) +VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_(event.name), busType_(event.bus), + vendorId_(event.vendor), productId_(event.product), version_(event.version), classes_(event.classes) { } @@ -48,7 +49,7 @@ bool VirtualDevice::DoIoctl(int32_t fd, int32_t request, const uint32_t value) { int32_t rc = ioctl(fd, request, value); if (rc < 0) { - DHLOGE("%s ioctl failed", __func__); + DHLOGE("ioctl failed"); return false; } return true; @@ -59,8 +60,7 @@ bool VirtualDevice::CreateKey() auto fun = [&](int32_t uiSet, const std::vector& list) -> bool { for (uint32_t evt_type : list) { if (!DoIoctl(fd_, uiSet, evt_type)) { - DHLOGE( - "%s Error setting event type: %u", __func__, evt_type); + DHLOGE("Error setting event type: %u", evt_type); return false; } } @@ -82,10 +82,11 @@ bool VirtualDevice::CreateKey() return true; } -bool VirtualDevice::SetPhys(const std::string deviceName) +bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId) { std::string phys; - phys.append(deviceName).append(pid_).append("/").append(pid_).append("|").append(netWorkId_); + phys.append(deviceName).append(pid_).append("/").append(pid_).append("|") + .append(netWorkId_).append("|").append(dhId); if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) { return false; @@ -96,34 +97,33 @@ bool VirtualDevice::SetPhys(const std::string deviceName) bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId) { fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK); - DHLOGI("open fd %d", fd_); if (fd_ < 0) { - DHLOGE("Failed to open uinput %s", __func__); + DHLOGE("Failed to open uinput"); return false; } deviceName_ = VIRTUAL_DEVICE_NAME + deviceName_; if (strncpy_s(dev_.name, sizeof(dev_.name), deviceName_.c_str(), deviceName_.size()) != 0) { return false; - }; + } HiDumper::GetInstance().SaveNodeInfo(devId, deviceName_, dhId); dev_.id.bustype = busType_; dev_.id.vendor = vendorId_; dev_.id.product = productId_; dev_.id.version = version_; - if (!SetPhys(deviceName_)) { - DHLOGE("Failed to set PHYS! %s", __func__); + if (!SetPhys(deviceName_, dhId)) { + DHLOGE("Failed to set PHYS!"); return false; } if (!CreateKey()) { - DHLOGE("Failed to create KeyValue %s", __func__); + DHLOGE("Failed to create KeyValue"); return false; } if (write(fd_, &dev_, sizeof(dev_)) < 0) { - DHLOGE("Unable to set input device info: %s", __func__); + DHLOGE("Unable to set input device info"); return false; } @@ -131,14 +131,14 @@ bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId) DHLOGE( "fd = %d, ioctl(fd_, UI_DEV_CREATE) = %d", fd_, ioctl(fd_, UI_DEV_CREATE)); - DHLOGE("Unable to create input device : %s", __func__); + DHLOGE("Unable to create input device"); return false; } DHLOGI("create fd %d", fd_); char sysfs_device_name[16]; if (ioctl(fd_, UI_GET_SYSNAME(sizeof(sysfs_device_name)), sysfs_device_name) < 0) { - DHLOGE("Unable to get input device name: %s", __func__); + DHLOGE("Unable to get input device name"); } DHLOGI("get input device name: %s, fd: %d", GetAnonyString(sysfs_device_name).c_str(), fd_); return true; @@ -161,12 +161,12 @@ bool VirtualDevice::InjectInputEvent(const input_event& event) void VirtualDevice::SetNetWorkId(const std::string netWorkId) { DHLOGI("SetNetWorkId %s\n", GetAnonyString(netWorkId).c_str()); - netWorkId_.append(netWorkId); + netWorkId_ = netWorkId; } -int32_t VirtualDevice::GetFd() +std::string VirtualDevice::GetNetWorkId() { - return fd_; + return netWorkId_; } void VirtualDevice::RecordEventLog(const input_event& event) @@ -189,6 +189,16 @@ void VirtualDevice::RecordEventLog(const input_event& event) DHLOGD("4.E2E-Test Source write event into input driver, EventType: %s, Code: %d, Value: %d, Sec: %ld, Sec1: %ld", eventType.c_str(), event.code, event.value, event.input_event_sec, event.input_event_usec); } + +int32_t VirtualDevice::GetDeviceFd() +{ + return fd_; +} + +int32_t VirtualDevice::GetDeviceType() +{ + return classes_; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn b/services/source/inputinject/test/sourceinjectunittest/BUILD.gn index 95e402b..dc401cc 100755 --- a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn +++ b/services/source/inputinject/test/sourceinjectunittest/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("distributed_input_inner_sourceinject_test") { "${utils_path}/include", "${fwk_interfaces_path}/include", "${fwk_interfaces_path}/include/ipc", + "${distributedinput_path}/inputdevicehandler/include", ] sources = [ @@ -83,6 +84,7 @@ ohos_unittest("distributed_input_inner_sourceinject_test") { "//foundation/communication/dsoftbus/sdk:softbus_client", "//third_party/openssl:libcrypto_static", "${fwk_interfaces_path}:libdhfwk_sdk", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index 305b124..f7058b2 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -41,10 +41,12 @@ ohos_shared_library("libdinput_source") { "${low_latency_path}/include", "${fwk_interfaces_path}/include", "${fwk_interfaces_path}/include/ipc", + "${distributedinput_path}/inputdevicehandler/include", ] sources = [ "${common_path}/include/white_list_util.cpp", + "${common_path}/include/dinput_struct_data.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", @@ -63,12 +65,21 @@ ohos_shared_library("libdinput_source") { "${ipc_path}/src/start_d_input_server_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/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/input_node_listener_proxy.cpp", + "${ipc_path}/src/input_node_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_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", "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", "src/distributed_input_source_event_handler.cpp", "src/distributed_input_source_manager.cpp", + "src/distributed_input_source_sa_cli_mgr.cpp", ] defines = [ @@ -94,13 +105,17 @@ ohos_shared_library("libdinput_source") { ] external_deps = [ + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", + "eventhandler:libeventhandler", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "dsoftbus:softbus_client", ] cflags_cc = [ "-DHILOG_ENABLE" ] diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index a46de8c..5cd3f32 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -33,8 +33,10 @@ #include "constants_dinput.h" #include "dinput_source_trans_callback.h" #include "distributed_input_node_manager.h" -#include "distributed_input_source_stub.h" #include "distributed_input_source_event_handler.h" +#include "distributed_input_source_sa_cli_mgr.h" +#include "distributed_input_source_stub.h" +#include "idinput_dbg_itf.h" namespace OHOS { namespace DistributedHardware { @@ -48,15 +50,44 @@ const uint32_t DINPUT_SOURCE_MANAGER_PREPARE_MSG = 3; const uint32_t DINPUT_SOURCE_MANAGER_UNPREPARE_MSG = 4; const uint32_t DINPUT_SOURCE_MANAGER_START_MSG = 5; const uint32_t DINPUT_SOURCE_MANAGER_STOP_MSG = 6; -const uint32_t DINPUT_SOURCE_MANAGER_RECEIVE_DATA_MSG = 7; -const uint32_t DINPUT_SOURCE_MANAGER_STARTSERVER_MSG = 8; +const uint32_t DINPUT_SOURCE_MANAGER_START_DHID_MSG = 7; +const uint32_t DINPUT_SOURCE_MANAGER_STOP_DHID_MSG = 8; +const uint32_t DINPUT_SOURCE_MANAGER_RECEIVE_DATA_MSG = 9; +const uint32_t DINPUT_SOURCE_MANAGER_STARTSERVER_MSG = 10; +const uint32_t DINPUT_SOURCE_MANAGER_KEY_STATE_MSG = 11; 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"; +const std::string INPUT_SOURCEMANAGER_KEY_VALUE = "value"; +const std::string INPUT_SOURCEMANAGER_KEY_FROM_START_DHID = "fromStartDhid"; const std::string INPUT_SOURCEMANAGER_KEY_RESULT = "result"; const std::string INPUT_SOURCEMANAGER_KEY_WHITELIST = "whitelist"; const uint32_t DINPUT_SOURCE_SWITCH_OFF = 0; const uint32_t DINPUT_SOURCE_SWITCH_ON = 1; +const uint32_t DINPUT_SOURCE_WRITE_EVENT_SIZE = 1; + +// Node Info that registerd by remote node +typedef struct BeRegNodeInfo { + // source node network id + std::string srcId; + // sink node dh id + std::string dhId; + // node desc on sink node + std::string nodeDesc; + + bool operator==(const BeRegNodeInfo &node) + { + return (srcId == node.srcId) && (dhId == node.dhId) && (nodeDesc == node.nodeDesc); + } + + bool operator<(const BeRegNodeInfo &node) const + { + return (srcId + dhId + nodeDesc).compare(node.srcId + node.dhId + node.nodeDesc) < 0; + } +} BeRegNodeInfo; class DistributedInputSourceManager : public SystemAbility, public DistributedInputSourceStub { DECLARE_SYSTEM_ABILITY(DistributedInputSourceManager) @@ -64,10 +95,11 @@ class DistributedInputSourceManager : public SystemAbility, public DistributedIn typedef struct InputDeviceId { std::string devId; std::string dhId; + std::string nodeDesc; bool operator==(const InputDeviceId &inputId) { - return (devId == inputId.devId) && (dhId == inputId.dhId); + return (devId == inputId.devId) && (dhId == inputId.dhId) && (nodeDesc == inputId.nodeDesc); } } InputDeviceId; @@ -89,11 +121,9 @@ public: virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, sptr callback) override; - virtual int32_t PrepareRemoteInput(const std::string& deviceId, - sptr callback, sptr addWhiteListCallback) override; + virtual int32_t PrepareRemoteInput(const std::string &deviceId, sptr callback) override; - virtual int32_t UnprepareRemoteInput(const std::string& deviceId, - sptr callback, sptr delWhiteListCallback) override; + virtual int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback) override; virtual int32_t StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; @@ -101,8 +131,41 @@ public: virtual int32_t StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) override; + virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) override; + + virtual int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) override; + + virtual int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) override; + + virtual int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback) override; + + virtual int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) override; + + virtual int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) override; + virtual int32_t IsStartDistributedInput( const uint32_t& inputType, sptr callback) override; + virtual int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback) override; + virtual int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback) override; + virtual int32_t RegisterInputNodeListener(sptr listener) override; + virtual int32_t UnregisterInputNodeListener(sptr listener) override; + + virtual int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhId, + const std::string &nodeDesc) override; + virtual int32_t RegisterSimulationEventListener(sptr listener) override; + virtual int32_t UnregisterSimulationEventListener(sptr listener) override; int32_t Dump(int32_t fd, const std::vector& args) override; @@ -115,6 +178,10 @@ public: void onResponseUnprepareRemoteInput(const std::string deviceId, bool result); void onResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result); void onResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result); + void onResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result); + void onResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result); + void onResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type, + const uint32_t code, const uint32_t value); void onReceivedEventRemoteInput(const std::string deviceId, const std::string &event); void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string& path); @@ -136,6 +203,9 @@ public: void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event); void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event); void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event); + void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event); void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event); DistributedInputSourceManager *sourceManagerObj_; @@ -162,6 +232,19 @@ public: int32_t ParseMessage(const std::string& message, std::string& sinkDevId, uint64_t& sourceWinId); }; + class DeviceOfflineListener : public PublisherListenerStub { + public: + DeviceOfflineListener(DistributedInputSourceManager* srcManagerContext); + ~DeviceOfflineListener(); + void OnMessage(const DHTopic topic, const std::string &message); + + private: + void DeleteNodeInfoAndNotify(const std::string& offlineDevId); + + private: + DistributedInputSourceManager* sourceManagerContext_; + }; + std::shared_ptr GetCallbackEventHandler() { return callBackHandler_; @@ -187,6 +270,11 @@ public: 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); + void RunKeyStateCallback(const std::string &sinkId, const std::string &dhId, const uint32_t type, + const uint32_t code, const uint32_t value); + IStartDInputServerCallback* GetStartDInputServerCback(); DInputServerType GetStartTransFlag(); void SetStartTransFlag(const DInputServerType flag); @@ -201,7 +289,6 @@ public: uint32_t GetAllInputTypesMap(); private: - struct DInputClientRegistInfo { std::string devId; std::string dhId; @@ -217,30 +304,45 @@ private: struct DInputClientPrepareInfo { std::string devId; sptr preCallback = nullptr; - sptr addWhiteListCallback = nullptr; - DInputClientPrepareInfo(std::string deviceId, sptr prepareCallback, - sptr addWhiteListCallback) : devId(deviceId), preCallback(prepareCallback), - addWhiteListCallback(addWhiteListCallback) {} + DInputClientPrepareInfo(std::string deviceId, sptr prepareCallback) + : devId(deviceId), preCallback(prepareCallback) {} }; struct DInputClientUnprepareInfo { std::string devId; sptr unpreCallback = nullptr; - sptr delWhiteListCallback = 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 DInputClientStartDhidInfo { + std::string srcId; + std::string sinkId; + std::vector dhIds; + sptr callback = nullptr; + }; + struct DInputClientStopDhidInfo { + std::string srcId; + std::string sinkId; + std::vector dhIds; + sptr callback = nullptr; + }; + ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; std::shared_ptr statuslistener_; @@ -253,6 +355,13 @@ private: std::vector stpCallbacks_; sptr startServerCallback_ = nullptr; + std::vector staStringCallbacks_; + std::vector stpStringCallbacks_; + + sptr addWhiteListCallback_ = nullptr; + sptr delWhiteListCallback_ = nullptr; + std::set> simulationEventCallbacks_; + std::map DeviceMap_; std::map InputTypesMap_; std::shared_ptr runner_; @@ -261,9 +370,38 @@ private: std::vector inputDevice_; bool InitAuto(); void handleStartServerCallback(const std::string& devId); + std::mutex mutex_; std::mutex operationMutex_; sptr startDScreenListener_ = nullptr; sptr stopDScreenListener_ = nullptr; + sptr deviceOfflineListener_ = nullptr; + + std::mutex valMutex_; + 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, + sptr callback); + int32_t RelayStartRemoteInputByDhid(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback); + 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 StringSplitToVector(const std::string &str, const char split, std::vector &vecStr); + 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); + +private: + IDInputDBGItf* dinputDbgItfPtr_ = nullptr; + void InitDinputDBG(); }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/sourcemanager/include/distributed_input_source_sa_cli_mgr.h b/services/source/sourcemanager/include/distributed_input_source_sa_cli_mgr.h new file mode 100644 index 0000000..8594502 --- /dev/null +++ b/services/source/sourcemanager/include/distributed_input_source_sa_cli_mgr.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 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. + */ + +#ifndef OHOS_DISTRIBUTED_INPUT_SOURCE_SA_CLI_MGR_H +#define OHOS_DISTRIBUTED_INPUT_SOURCE_SA_CLI_MGR_H + +#include +#include +#include +#include + +#include "event_handler.h" + +#include "i_distributed_source_input.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DInputSourceSACliMgr { +DECLARE_SINGLE_INSTANCE_BASE(DInputSourceSACliMgr); +public: + DInputSourceSACliMgr(); + virtual ~DInputSourceSACliMgr(); + + sptr GetRemoteCli(const std::string &deviceId); + +private: + class RemoteCliDeathRecipient : public IRemoteObject::DeathRecipient { + public: + void OnRemoteDied(const wptr& remote) override; + }; + sptr remoteCliDeathRcv; + sptr GetRemoteCliFromCache(const std::string &devId); + void AddRemoteCli(const std::string &devId, sptr object); + void DeleteRemoteCli(const std::string &devId); + void DeleteRemoteCli(const sptr object); + void ProcRemoteCliDied(const sptr& remote); + +private: + std::mutex remoteCliLock; + std::map> remoteCliMap; + std::shared_ptr dinputMgrHandler_; +}; +} +} +} +#endif \ No newline at end of file diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 28dc9db..3f03e06 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -16,14 +16,18 @@ #include "distributed_input_source_manager.h" #include +#include +#include #include "anonymous_string.h" #include "distributed_hardware_log.h" +#include "dinput_softbus_define.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "nlohmann/json.hpp" #include "system_ability_definition.h" #include "string_ex.h" +#include "softbus_bus_center.h" #include "constants_dinput.h" #include "dinput_errcode.h" @@ -33,13 +37,23 @@ #include "distributed_hardware_fwk_kit.h" #include "distributed_input_client.h" #include "distributed_input_inject.h" +#include "distributed_input_source_proxy.h" #include "distributed_input_source_transport.h" #include "dinput_utils_tool.h" #include "hisysevent_util.h" #include "hidumper.h" #include "ipublisher_listener.h" +#include "idinput_dbg_itf.h" #include "white_list_util.h" +#ifdef __LP64__ +const std::string LIB_LOAD_PATH = "/system/lib64/libdinput_dbg_itf.z.so"; +#else +const std::string LIB_LOAD_PATH = "/system/lib/libdinput_dbg_itf.z.so"; +#endif + +using GetDInputDBGItfFunc = OHOS::DistributedHardware::DistributedInput::IDInputDBGItf* (*)(); + namespace OHOS { namespace DistributedHardware { namespace DistributedInput { @@ -217,6 +231,106 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } +void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteInputDhid( + const std::string deviceId, const std::string &dhids, bool result) +{ + DHLOGI("onResponseStartRemoteInputDhid called, deviceId: %s, result: %d.", + GetAnonyString(deviceId).c_str(), result); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("onResponseStartRemoteInputDhid sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("onResponseStartRemoteInputDhid GetCallbackEventHandler is null."); + sourceManagerObj_->RunStartDhidCallback(deviceId, dhids, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + return; + } + if (result) { + sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); + } + + std::shared_ptr jsonArrayMsg = std::make_shared(); + if (jsonArrayMsg == nullptr) { + DHLOGE("onResponseStartRemoteInputDhid jsonArrayMsg is null."); + return; + } + + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_START_DHID_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteInputDhid( + const std::string deviceId, const std::string &dhids, bool result) +{ + DHLOGI("onResponseStopRemoteInputDhid called, deviceId: %s, result: %d.", + GetAnonyString(deviceId).c_str(), result); + + if (sourceManagerObj_ == nullptr) { + DHLOGE("onResponseStopRemoteInputDhid sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("onResponseStopRemoteInputDhid GetCallbackEventHandler is null."); + sourceManagerObj_->RunStopDhidCallback(deviceId, dhids, + ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); + return; + } + std::shared_ptr jsonArrayMsg = std::make_shared(); + if (jsonArrayMsg == nullptr) { + DHLOGE("onResponseStartRemoteInputDhid jsonArrayMsg is null."); + return; + } + + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids; + tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_STOP_DHID_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + +void DistributedInputSourceManager::DInputSourceListener::onResponseKeyState(const std::string deviceId, + const std::string &dhid, const uint32_t type, const uint32_t code, const uint32_t value) +{ + DHLOGI("onResponseMouseDown called, deviceId: %s, dhid: %s.", GetAnonyString(deviceId).c_str(), + GetAnonyString(dhid).c_str()); + if (sourceManagerObj_ == nullptr) { + DHLOGE("onResponseMouseDown sourceManagerObj_ is null."); + return; + } + if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) { + DHLOGE("onResponseMouseDown GetCallbackEventHandler is null."); + sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, type, code, value); + return; + } + std::shared_ptr jsonArrayMsg = std::make_shared(); + if (jsonArrayMsg == nullptr) { + DHLOGE("onResponseMouseDown jsonArrayMsg is null."); + return; + } + + nlohmann::json tmpJson; + tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; + tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhid; + tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = type; + tmpJson[INPUT_SOURCEMANAGER_KEY_CODE] = code; + tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = value; + jsonArrayMsg->push_back(tmpJson); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_KEY_STATE_MSG, jsonArrayMsg, 0); + sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); +} + void DistributedInputSourceManager::DInputSourceListener::onReceivedEventRemoteInput( const std::string deviceId, const std::string &event) { @@ -255,7 +369,9 @@ void DistributedInputSourceManager::OnStart() } serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING; runner_->Run(); - /* Publish service maybe failed, so we need call this function at the last, + + /* + * Publish service maybe failed, so we need call this function at the last, * so it can't affect the TDD test program. */ bool ret = Publish(this); @@ -430,6 +546,57 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopC result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); } +void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartDhidCallback( + const AppExecFwk::InnerEvent::Pointer &event) +{ + DHLOGI("ProcessEvent NotifyStartDhidCallback()"); + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *(it); + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + if (sourceManagerObj_ != nullptr) { + sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); + } +} + +void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopDhidCallback( + const AppExecFwk::InnerEvent::Pointer &event) +{ + DHLOGI("ProcessEvent NotifyStopDhidCallback()"); + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *(it); + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; + + if (sourceManagerObj_ != nullptr) { + sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr, + result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); + } +} + +void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyKeyStateCallback( + const AppExecFwk::InnerEvent::Pointer &event) +{ + DHLOGI("ProcessEvent NotifyKeyStateCallback()"); + std::shared_ptr dataMsg = event->GetSharedObject(); + nlohmann::json::iterator it = dataMsg->begin(); + nlohmann::json innerMsg = *(it); + std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; + std::string dhid = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; + uint32_t keyType = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE]; + uint32_t keyCode = innerMsg[INPUT_SOURCEMANAGER_KEY_CODE]; + uint32_t keyValue = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE]; + if (sourceManagerObj_ != nullptr) { + sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue); + } +} + void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStartServerCallback( const AppExecFwk::InnerEvent::Pointer &event) { @@ -476,6 +643,18 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::ProcessEven NotifyStopCallback(event); break; } + case DINPUT_SOURCE_MANAGER_START_DHID_MSG: { + NotifyStartDhidCallback(event); + break; + } + case DINPUT_SOURCE_MANAGER_STOP_DHID_MSG: { + NotifyStopDhidCallback(event); + break; + } + case DINPUT_SOURCE_MANAGER_KEY_STATE_MSG: { + NotifyKeyStateCallback(event); + break; + } case DINPUT_SOURCE_MANAGER_STARTSERVER_MSG: { NotifyStartServerCallback(event); break; @@ -515,11 +694,46 @@ int32_t DistributedInputSourceManager::Init() } startDScreenListener_ = new StartDScreenListener; stopDScreenListener_ = new StopDScreenListener; + deviceOfflineListener_ = new DeviceOfflineListener(this); dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, startDScreenListener_); dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_STOP_DSCREEN, stopDScreenListener_); + dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_DEV_OFFLINE, deviceOfflineListener_); + + DHLOGI("Try InitDinputDBG"); + InitDinputDBG(); return DH_SUCCESS; } +void DistributedInputSourceManager::InitDinputDBG() +{ + char path[PATH_MAX + 1] = {0x00}; + if (LIB_LOAD_PATH.length() > PATH_MAX || realpath(LIB_LOAD_PATH.c_str(), path) == nullptr) { + DHLOGE("File canonicalization failed"); + return; + } + + void *pHandler = dlopen(path, RTLD_LAZY | RTLD_NODELETE); + if (pHandler == nullptr) { + DHLOGE("%s handler load failed, failed reason : %s", path, dlerror()); + return; + } + + GetDInputDBGItfFunc getDinputDBGItfFunc = (GetDInputDBGItfFunc)dlsym(pHandler, GET_DBG_ITF_FUNC.c_str()); + if (getDinputDBGItfFunc == nullptr) { + DHLOGE("get getDinputDBGItfFunc is null, failed reason : %s", dlerror()); + return; + } + + dinputDbgItfPtr_ = getDinputDBGItfFunc(); + if (dinputDbgItfPtr_ == nullptr) { + DHLOGE("Get DInput DBG iterface error"); + return; + } + + DHLOGE("Init DInput DBG interface"); + dinputDbgItfPtr_->Init(); +} + int32_t DistributedInputSourceManager::Release() { DHLOGI("exit"); @@ -531,7 +745,7 @@ int32_t DistributedInputSourceManager::Release() DHLOGI("Release() devId[%s] dhId[%s]", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId); if (ret != DH_SUCCESS) { - DHLOGW("%s called, remove node fail.", __func__); + DHLOGW("DistributedInputSourceManager Release called, remove node fail."); } } @@ -561,11 +775,18 @@ int32_t DistributedInputSourceManager::Release() serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START; std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); - if (dhFwkKit != nullptr && startDScreenListener_ != nullptr && stopDScreenListener_ != nullptr) { - DHLOGI("UnPublish StartDScreenListener and StopDScreenListener"); + if (dhFwkKit != nullptr && startDScreenListener_ != nullptr) { + DHLOGI("UnPublish StartDScreenListener"); dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, startDScreenListener_); + } + if (dhFwkKit != nullptr && stopDScreenListener_ != nullptr) { + DHLOGI("UnPublish StopDScreenListener"); dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_STOP_DSCREEN, stopDScreenListener_); } + if (dhFwkKit != nullptr && deviceOfflineListener_ != nullptr) { + DHLOGI("UnPublish DeviceOfflineListener"); + dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_DEV_OFFLINE, deviceOfflineListener_); + } DHLOGI("exit dinput source sa."); SetSourceProcessExit(); return DH_SUCCESS; @@ -575,12 +796,10 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st const std::string& parameters, sptr callback) { HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_REGISTER, devId, dhId, "dinput register call."); - DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); + DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); if (callback == nullptr) { - DHLOGE( - "%s called, deviceId: %s callback is null.", - __func__, GetAnonyString(devId).c_str()); + DHLOGE("RegisterDistributedHardware called, deviceId: %s callback is null.", GetAnonyString(devId).c_str()); HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, "dinput register distributed hardware failed callback is nullptr."); @@ -595,7 +814,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st info.callback = callback; regCallbacks_.push_back(info); - InputDeviceId inputDeviceId {devId, dhId}; + InputDeviceId inputDeviceId {devId, dhId, GetNodeDesc(parameters)}; DHLOGI("RegisterDistributedHardware deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); @@ -612,7 +831,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, "dinput register distributed hardware failed in create input node."); - DHLOGE("%s called, create node fail.", __func__); + DHLOGE("RegisterDistributedHardware called, create node fail."); for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { if (iter->devId == devId && iter->dhId == dhId) { @@ -631,6 +850,15 @@ 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 ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; + } + + cli->SyncNodeInfoRemoteInput(GetLocalNetworkId(), dhId, GetNodeDesc(parameters)); return DH_SUCCESS; } @@ -674,7 +902,7 @@ int32_t DistributedInputSourceManager::RemoveInputNode(const std::string& devId, { int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId); if (ret != DH_SUCCESS) { - DHLOGE("%s called, remove node fail.", __func__); + DHLOGE("RemoveInputNode called, remove node fail."); for (std::vector::iterator iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { if (iter->devId == devId && iter->dhId == dhId) { @@ -771,8 +999,8 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: return DH_SUCCESS; } -int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& deviceId, - sptr callback, sptr addWhiteListCallback) +int32_t DistributedInputSourceManager::PrepareRemoteInput( + const std::string &deviceId, sptr callback) { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_PREPARE, deviceId, "dinput prepare call"); @@ -803,7 +1031,7 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } - DInputClientPrepareInfo info(deviceId, callback, addWhiteListCallback); + DInputClientPrepareInfo info(deviceId, callback); preCallbacks_.push_back(info); ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(deviceId); @@ -825,8 +1053,8 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& dev return DH_SUCCESS; } -int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& deviceId, - sptr callback, sptr delWhiteListCallback) +int32_t DistributedInputSourceManager::UnprepareRemoteInput( + const std::string &deviceId, sptr callback) { StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK); HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNPREPARE, deviceId, "dinput unprepare call"); @@ -853,7 +1081,6 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d DInputClientUnprepareInfo info; info.devId = deviceId; info.unpreCallback = callback; - info.delWhiteListCallback = delWhiteListCallback; unpreCallbacks_.push_back(info); int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(deviceId); @@ -900,10 +1127,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput( } } - DInputClientStartInfo info; - info.devId = deviceId; - info.inputTypes = inputTypes; - info.callback = callback; + DInputClientStartInfo info(deviceId, inputTypes, callback); staCallbacks_.push_back(info); DeviceMap_[deviceId] = DINPUT_SOURCE_SWITCH_OFF; // when sink device start success,set DINPUT_SOURCE_SWITCH_ON @@ -952,10 +1176,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput( } } - DInputClientStopInfo info; - info.devId = deviceId; - info.inputTypes = inputTypes; - info.callback = callback; + DInputClientStopInfo info(deviceId, inputTypes, callback); stpCallbacks_.push_back(info); int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(deviceId, inputTypes); @@ -978,6 +1199,498 @@ int32_t DistributedInputSourceManager::StopRemoteInput( 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"); + 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()) { + DHLOGE("StartRemoteInput called, Could not get local device id."); + 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; + } + DHLOGI("StartRemoteInput called, device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGI("StartRemoteInput called, relay start to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayStartRemoteInputByType(srcId, sinkId, inputTypes, callback); + } + + for (auto iter : staCallbacks_) { + if (iter.devId == sinkId && iter.inputTypes == inputTypes) { + DHLOGE("StartRemoteInput called, srcId: %s, sinkId: %s repeat call.", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + 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 (std::vector::iterator 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"); + 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()) { + DHLOGE("StopRemoteInput called, Could not get local device id."); + 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; + } + DHLOGI("StopRemoteInput called, device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGI("StopRemoteInput called, relay start to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayStopRemoteInputByType(srcId, sinkId, inputTypes, callback); + } + + for (auto iter : stpCallbacks_) { + if (iter.devId == sinkId && iter.inputTypes == inputTypes) { + DHLOGE("StopRemoteInput called, srcId: %s, sinkId: %s repeat call.", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + 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 (std::vector::iterator 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_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + DHLOGE("try get sa: %d from %s", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, GetAnonyString(srcId).c_str()); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("Could not get remoteObject."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("new proxy Object fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + return dInputSourceProxy->StartRemoteInput(srcId, sinkId, inputTypes, callback); +} + +int32_t DistributedInputSourceManager::RelayStopRemoteInputByType( + const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, sptr callback) +{ + std::lock_guard lock(mutex_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + DHLOGE("try get sa: %d from %s", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, GetAnonyString(srcId).c_str()); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("Could not get remoteObject."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("new proxy Object fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + return dInputSourceProxy->StopRemoteInput(srcId, sinkId, inputTypes, callback); +} + +int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + if (srcId.empty() || sinkId.empty()) { + DHLOGE("srcId: %d or sinkId: %d is empty.", srcId.empty(), sinkId.empty()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + if (callback == nullptr) { + DHLOGE("srcId: %s, sinkId: %s callback is null.", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + DHLOGI("srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGE("relay prepare to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayPrepareRemoteInput(srcId, sinkId, callback); + } + // current device is source device + for (auto iter : preCallbacks_) { + if (iter.devId == sinkId) { + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + } + int32_t ret = DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(sinkId); + if (ret != DH_SUCCESS) { + DHLOGE("Open softbus session fail ret=%d.", ret); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + DInputClientPrepareInfo info(sinkId, callback); + preCallbacks_.push_back(info); + + ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(sinkId); + if (ret != DH_SUCCESS) { + DHLOGE("Can not send message by softbus, prepare fail."); + for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { + if (iter->devId == sinkId) { + preCallbacks_.erase(iter); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + } + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + + return DH_SUCCESS; +} + +int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + if (srcId.empty() || sinkId.empty()) { + DHLOGE("srcId: %d or sinkId: %d is empty.", srcId.empty(), sinkId.empty()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + if (callback == nullptr) { + DHLOGE("srcId: %s, sinkId: %s callback is null.", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + DHLOGI("srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), + GetAnonyString(sinkId).c_str()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + DHLOGI("device local localNetworkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGE("relay unprepare to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayUnprepareRemoteInput(srcId, sinkId, callback); + } + + // current device is source device + for (auto iter : unpreCallbacks_) { + if (iter.devId == sinkId) { + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + } + + DInputClientUnprepareInfo info; + info.devId = sinkId; + info.unpreCallback = callback; + unpreCallbacks_.push_back(info); + + int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(sinkId); + if (ret != DH_SUCCESS) { + DHLOGE("Can not send message by softbus, unprepare fail."); + for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { + if (iter->devId == sinkId) { + unpreCallbacks_.erase(iter); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + } + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + return DH_SUCCESS; +} + +bool DistributedInputSourceManager::IsStringDataSame(const std::vector &oldDhIds, + std::vector newDhIds) +{ + if (oldDhIds.size() != newDhIds.size()) { + DHLOGI("Size is not same, return false."); + return false; + } + bool isSame = true; + for (auto oDhid : oldDhIds) { + std::vector::iterator it = find(newDhIds.begin(), newDhIds.end(), oDhid); + if (it == newDhIds.end()) { + isSame = false; + break; + } + } + DHLOGI("IsSame: %d.", isSame); + return isSame; +} + +int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "dinput start use call"); + DHLOGI("sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in get networkId"); + FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + + // current device is source device + for (auto iter : staStringCallbacks_) { + if (iter.sinkId == sinkId && IsStringDataSame(iter.dhIds, dhIds)) { + 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); + DHLOGE("sinkId: %s, repeat call.", GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + } + + DInputClientStartDhidInfo info; + info.srcId = localNetworkId; + info.sinkId = sinkId; + info.dhIds = dhIds; + info.callback = callback; + staStringCallbacks_.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, dhIds); + 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 start fail."); + for (std::vector::iterator iter = staStringCallbacks_.begin(); + iter != staStringCallbacks_.end(); iter++) { + if (iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { + staStringCallbacks_.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 &sinkId, const std::vector &dhIds, + sptr callback) +{ + StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "dinput stop use call"); + DHLOGI("sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + 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; + } + DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + for (auto iter : stpStringCallbacks_) { + if (iter.sinkId == sinkId && IsStringDataSame(iter.dhIds, dhIds)) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in already stop"); + FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); + DHLOGE("sinkId: %s, repeat call.", GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + } + + DInputClientStopDhidInfo info; + info.srcId = localNetworkId; + info.sinkId = sinkId; + info.dhIds = dhIds; + info.callback = callback; + stpStringCallbacks_.push_back(info); + + int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(sinkId, dhIds); + if (ret != DH_SUCCESS) { + 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); + DHLOGE("StopRemoteInput stop fail."); + for (std::vector::iterator iter = stpStringCallbacks_.begin(); + iter != stpStringCallbacks_.end(); iter++) { + if (iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { + stpStringCallbacks_.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 std::vector &dhIds, sptr callback) +{ + StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "dinput start use call"); + DHLOGI("srcId: %s, sinkId: %s, dhids size: %d", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in get networkId"); + FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGI("relay start to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayStartRemoteInputByDhid(srcId, sinkId, dhIds, callback); + } + + // current device is source device + for (auto iter : staStringCallbacks_) { + if (iter.srcId == srcId && iter.sinkId == sinkId && IsStringDataSame(iter.dhIds, dhIds)) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in already start"); + FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); + DHLOGE("sinkId: %s, repeat call.", GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + } + + DInputClientStartDhidInfo info{srcId, sinkId, dhIds, callback}; + staStringCallbacks_.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, dhIds); + 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 start fail."); + for (std::vector::iterator iter = staStringCallbacks_.begin(); + iter != staStringCallbacks_.end(); iter++) { + if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { + staStringCallbacks_.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 &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); + HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "dinput stop use call"); + DHLOGI("srcId: %s, sinkId: %s, vector.string.size: %d", + GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size()); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + 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; + } + DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str()); + if (srcId != localNetworkId) { + DHLOGI("relay stop to srcId: %s", GetAnonyString(srcId).c_str()); + return RelayStopRemoteInputByDhid(srcId, sinkId, dhIds, callback); + } + + for (auto iter : stpStringCallbacks_) { + if (iter.srcId == srcId && iter.sinkId == sinkId && IsStringDataSame(iter.dhIds, dhIds)) { + HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, + ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in already stop"); + FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); + DHLOGE("sinkId: %s, repeat call.", GetAnonyString(sinkId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + } + + DInputClientStopDhidInfo info; + info.srcId = srcId; + info.sinkId = sinkId; + info.dhIds = dhIds; + info.callback = callback; + stpStringCallbacks_.push_back(info); + + int32_t ret = DistributedInputSourceTransport::GetInstance().StopRemoteInput(sinkId, dhIds); + if (ret != DH_SUCCESS) { + 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); + DHLOGE("StopRemoteInput stop fail."); + for (std::vector::iterator iter = stpStringCallbacks_.begin(); + iter != stpStringCallbacks_.end(); iter++) { + if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { + stpStringCallbacks_.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::IsStartDistributedInput( const uint32_t& inputType, sptr callback) { @@ -996,6 +1709,198 @@ int32_t DistributedInputSourceManager::IsStartDistributedInput( } } +int32_t DistributedInputSourceManager::RegisterAddWhiteListCallback(sptr callback) +{ + DHLOGI("RegisterAddWhiteListCallback called."); + if (callback == nullptr) { + DHLOGE("RegisterAddWhiteListCallback callback is null."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR; + } + std::lock_guard lock(valMutex_); + addWhiteListCallback_ = callback; + return DH_SUCCESS; +} + +int32_t DistributedInputSourceManager::RegisterDelWhiteListCallback(sptr callback) +{ + DHLOGI("RegisterDelWhiteListCallback called."); + if (callback == nullptr) { + DHLOGE("RegisterDelWhiteListCallback callback is null."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR; + } + std::lock_guard lock(valMutex_); + delWhiteListCallback_ = callback; + return DH_SUCCESS; +} + +int32_t DistributedInputSourceManager::RegisterInputNodeListener(sptr listener) +{ + DHLOGI("RegisterInputNodeListener, addr: %p", &listener); + DistributedInputInject::GetInstance().RegisterInputNodeListener(listener); + SendExistVirNodeInfos(listener); + return DH_SUCCESS; +} + +int32_t DistributedInputSourceManager::UnregisterInputNodeListener(sptr listener) +{ + DHLOGI("UnregisterInputNodeListener, addr: %p", &listener); + 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."); + if (listener == nullptr) { + DHLOGE("RegisterSimulationEventListener callback is null."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR; + } + std::lock_guard lock(valMutex_); + this->simulationEventCallbacks_.insert(listener); + return DH_SUCCESS; +} + +int32_t DistributedInputSourceManager::UnregisterSimulationEventListener(sptr listener) +{ + DHLOGI("UnregisterSimulationEventListener called."); + if (listener == nullptr) { + DHLOGE("UnregisterSimulationEventListener callback is null."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR; + } + std::lock_guard lock(valMutex_); + this->simulationEventCallbacks_.erase(listener); + 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) +{ + std::lock_guard lock(mutex_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + + DHLOGI("try get sa: %d from device:%s.", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, + GetAnonyString(srcId).c_str()); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("get remoteObject error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("dInputSourceProxy error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; + } + + return dInputSourceProxy->PrepareRemoteInput(sinkId, callback); +} + +int32_t DistributedInputSourceManager::RelayUnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + std::lock_guard lock(mutex_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + + DHLOGI("try get sa: %d", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("get remoteObject error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("dInputSourceProxy error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; + } + + return dInputSourceProxy->UnprepareRemoteInput(sinkId, callback); +} + +int32_t DistributedInputSourceManager::RelayStartRemoteInputByDhid(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + std::lock_guard lock(mutex_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + DHLOGI("try get sa: %d from %s", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, + GetAnonyString(srcId).c_str()); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("remoteObject error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("dInputSourceProxy error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; + } + + return dInputSourceProxy->StartRemoteInput(srcId, sinkId, dhIds, callback); +} + +int32_t DistributedInputSourceManager::RelayStopRemoteInputByDhid(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + std::lock_guard lock(mutex_); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + DHLOGE("get sa fail."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + DHLOGI("try get sa: %d from %s", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, + GetAnonyString(srcId).c_str()); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, srcId); + if (!remoteObject) { + DHLOGE("get remoteObject error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + sptr dInputSourceProxy(new DistributedInputSourceProxy(remoteObject)); + if (!dInputSourceProxy) { + DHLOGE("dInputSourceProxy error."); + return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; + } + + return dInputSourceProxy->StopRemoteInput(srcId, sinkId, dhIds, callback); +} + void DistributedInputSourceManager::RunRegisterCallback( const std::string& devId, const std::string& dhId, const int32_t& status) { @@ -1039,8 +1944,12 @@ void DistributedInputSourceManager::RunPrepareCallback( if (iter->devId == devId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG"); iter->preCallback->OnResult(devId, status); - iter->addWhiteListCallback->OnResult(devId, object); preCallbacks_.erase(iter); + if (addWhiteListCallback_ == nullptr) { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG addWhiteListCallback is null."); + return; + } + addWhiteListCallback_->OnResult(devId, object); return; } } @@ -1048,8 +1957,7 @@ void DistributedInputSourceManager::RunPrepareCallback( DHLOGE("ProcessEvent parepareCallback is null."); } -void DistributedInputSourceManager::RunUnprepareCallback( - const std::string& devId, const int32_t& status) +void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devId, const int32_t &status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK); for (std::vector::iterator iter = @@ -1057,8 +1965,12 @@ void DistributedInputSourceManager::RunUnprepareCallback( if (iter->devId == devId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG"); iter->unpreCallback->OnResult(devId, status); - iter->delWhiteListCallback->OnResult(devId); unpreCallbacks_.erase(iter); + if (delWhiteListCallback_ == nullptr) { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG delWhiteListCallback is null."); + return; + } + delWhiteListCallback_->OnResult(devId); return; } } @@ -1070,34 +1982,113 @@ 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 (std::vector::iterator iter = - staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) { + for (std::vector::iterator 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); - return; + break; } } - - DHLOGE("ProcessEvent startCallback is null."); } 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 (std::vector::iterator iter = - stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) { + for (std::vector::iterator 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); - return; + break; } } +} - DHLOGE("ProcessEvent stopCallback is null."); +void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sinkId, const std::string &dhIds, + const int32_t &status) +{ + std::vector dhidsVec; + StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec); + DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_DHID_MSG dhIds:%s, vec-size:%d", dhIds.c_str(), dhidsVec.size()); + std::string localNetWorkId = GetLocalNetworkId(); + if (localNetWorkId.empty()) { + DHLOGE("Could not get local device id."); + return; + } + + for (std::vector::iterator iter = staStringCallbacks_.begin(); + iter != staStringCallbacks_.end(); iter++) { + if (iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { + continue; + } + iter->callback->OnResultDhids(sinkId, status); + staStringCallbacks_.erase(iter); + break; + } +} + +void DistributedInputSourceManager::RunStopDhidCallback(const std::string &sinkId, const std::string &dhIds, + const int32_t &status) +{ + std::vector dhidsVec; + StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec); + std::string localNetworkId = GetLocalNetworkId(); + if (localNetworkId.empty()) { + DHLOGE("Could not get local device id."); + return; + } + + for (std::vector::iterator iter = stpStringCallbacks_.begin(); + iter != stpStringCallbacks_.end(); iter++) { + if (iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { + continue; + } + iter->callback->OnResultDhids(sinkId, status); + stpStringCallbacks_.erase(iter); + break; + } +} + +void DistributedInputSourceManager::RunKeyStateCallback(const std::string &sinkId, const std::string &dhId, + const uint32_t type, const uint32_t code, const uint32_t value) +{ + // 1.notify multiinput + std::lock_guard lock(valMutex_); + for (const auto &cb : simulationEventCallbacks_) { + cb->OnSimulationEvent(type, code, value); + } + + DHLOGI("ProcessEvent notify multimodal OnSimulationEvent success."); + // 2.if return success, write to virtulnode + RawEvent mEventBuffer; + mEventBuffer.type = type; + mEventBuffer.code = code; + mEventBuffer.value = value; + mEventBuffer.descriptor = dhId; + DistributedInputInject::GetInstance().RegisterDistributedEvent(&mEventBuffer, DINPUT_SOURCE_WRITE_EVENT_SIZE); + return; +} + +void DistributedInputSourceManager::StringSplitToVector(const std::string &str, const char split, + std::vector &vecStr) +{ + if (str.empty()) { + DHLOGE("StringSplitToVector param str is error."); + return; + } + std::string strTmp = str + split; + size_t pos = strTmp.find(split); + while (pos != strTmp.npos) { + std::string matchTmp = strTmp.substr(0, pos); + vecStr.push_back(matchTmp); + + strTmp = strTmp.substr(pos + 1, strTmp.size()); + pos = strTmp.find(split); + } } IStartDInputServerCallback* DistributedInputSourceManager::GetStartDInputServerCback() @@ -1153,7 +2144,6 @@ void DistributedInputSourceManager::SetDeviceMapValue(const std::string deviceId DeviceMap_[deviceId] = value; } - uint32_t DistributedInputSourceManager::GetInputTypesMap(const std::string deviceId) { std::map::iterator key = InputTypesMap_.find(deviceId); @@ -1185,6 +2175,34 @@ void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, InputTypesMap_[deviceId] = value; } +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::DInputSourceListener::RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string &path) { @@ -1220,6 +2238,10 @@ DistributedInputSourceManager::StartDScreenListener::~StartDScreenListener() void DistributedInputSourceManager::StartDScreenListener::OnMessage(const DHTopic topic, const std::string& message) { DHLOGI("StartDScreenListener OnMessage!"); + if (topic != DHTopic::TOPIC_START_DSCREEN) { + DHLOGE("this topic is wrong, %d", static_cast(topic)); + return; + } std::string sinkDevId = ""; SrcScreenInfo srcScreenInfo = {}; int32_t parseRes = ParseMessage(message, sinkDevId, srcScreenInfo); @@ -1326,6 +2348,10 @@ DistributedInputSourceManager::StopDScreenListener::~StopDScreenListener() void DistributedInputSourceManager::StopDScreenListener::OnMessage(const DHTopic topic, const std::string& message) { DHLOGI("StopDScreenListener OnMessage!"); + if (topic != DHTopic::TOPIC_STOP_DSCREEN) { + DHLOGE("this topic is wrong, %d", static_cast(topic)); + return; + } std::string sinkDevId = ""; uint64_t sourceWinId = 0; int32_t parseRes = ParseMessage(message, sinkDevId, sourceWinId); @@ -1380,6 +2406,51 @@ int32_t DistributedInputSourceManager::StopDScreenListener::ParseMessage(const s return DH_SUCCESS; } +DistributedInputSourceManager::DeviceOfflineListener::DeviceOfflineListener( + DistributedInputSourceManager* srcManagerContext) +{ + DHLOGI("DeviceOfflineListener ctor!"); + sourceManagerContext_ = srcManagerContext; +} + +DistributedInputSourceManager::DeviceOfflineListener::~DeviceOfflineListener() +{ + DHLOGI("DeviceOfflineListener dtor!"); +} + +void DistributedInputSourceManager::DeviceOfflineListener::OnMessage(const DHTopic topic, const std::string &message) +{ + DHLOGI("DeviceOfflineListener OnMessage!"); + if (topic != DHTopic::TOPIC_DEV_OFFLINE) { + DHLOGE("this topic is wrong, %d", static_cast(topic)); + return; + } + if (message.empty()) { + 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); +} + int32_t DistributedInputSourceManager::Dump(int32_t fd, const std::vector& args) { DHLOGI("DistributedInputSourceManager Dump."); diff --git a/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp b/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp new file mode 100644 index 0000000..21c7aac --- /dev/null +++ b/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 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 "distributed_input_source_sa_cli_mgr.h" + +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +#include "distributed_hardware_log.h" +#include "anonymous_string.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +IMPLEMENT_SINGLE_INSTANCE(DInputSourceSACliMgr); +DInputSourceSACliMgr::DInputSourceSACliMgr() +{ + DHLOGI("Ctor DInputSourceSACliMgr"); + remoteCliDeathRcv = new RemoteCliDeathRecipient(); + + auto dinputMgrRunner = AppExecFwk::EventRunner::Create("DInputMgrHandler"); + if (!dinputMgrRunner) { + DHLOGE("DInputSourceSACliMgr, dinputMgrRunner is null!"); + return; + } + dinputMgrHandler_ = std::make_shared(dinputMgrRunner); + if (!dinputMgrHandler_) { + DHLOGE("DInputSourceSACliMgr, dinputMgrHandler_ is null!"); + } +} + +DInputSourceSACliMgr::~DInputSourceSACliMgr() +{ + DHLOGI("Dtor DInputSourceSACliMgr"); +} + +void DInputSourceSACliMgr::RemoteCliDeathRecipient::OnRemoteDied(const wptr& remote) +{ + DHLOGI("RemoteCliDeathRecipient::OnRemoteDied received died notify!"); + sptr diedRemote = remote.promote(); + if (diedRemote == nullptr) { + DHLOGE("RemoteCliDeathRecipient::OnRemoteDied promote failedy!"); + return; + } + + DInputSourceSACliMgr::GetInstance().ProcRemoteCliDied(diedRemote); +} + +sptr DInputSourceSACliMgr::GetRemoteCli(const std::string &deviceId) +{ + if (deviceId.empty()) { + DHLOGE("DInputSourceSACliMgr::GetRemoteCli deviceId is empty"); + return nullptr; + } + DHLOGI("DInputSourceSACliMgr::GetRemoteCli remote deviceid is %{public}s", GetAnonyString(deviceId).c_str()); + auto remoteCli = GetRemoteCliFromCache(deviceId); + if (remoteCli != nullptr) { + DHLOGD("VirtualHardwareManager::GetRemoteCli get from cache!"); + return remoteCli; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + DHLOGE("GetRemoteCli failed to connect to systemAbilityMgr!"); + return nullptr; + } + + auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, deviceId); + if (object == nullptr) { + DHLOGE("GetRemoteCli failed get remote Cli %{public}s", GetAnonyString(deviceId).c_str()); + return nullptr; + } + + AddRemoteCli(deviceId, object); + return iface_cast(object); +} + +sptr DInputSourceSACliMgr::GetRemoteCliFromCache(const std::string &devId) +{ + std::lock_guard lock(remoteCliLock); + auto iter = remoteCliMap.find(devId); + if (iter != remoteCliMap.end()) { + return iter->second; + } + return nullptr; +} + +void DInputSourceSACliMgr::AddRemoteCli(const std::string &devId, sptr object) +{ + if (devId.empty() || (object == nullptr)) { + DHLOGW("DInputSourceSACliMgr::AddRemoteCli param error! devId=%{public}s", GetAnonyString(devId).c_str()); + return; + } + + DHLOGI("DInputSourceSACliMgr::AddRemoteCli devId=%{public}s", GetAnonyString(devId).c_str()); + object->AddDeathRecipient(remoteCliDeathRcv); + + std::lock_guard lock(remoteCliLock); + auto item = remoteCliMap.find(devId); + if ((item != remoteCliMap.end()) && item->second != nullptr) { + item->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv); + } + remoteCliMap[devId] = iface_cast(object); +} + +void DInputSourceSACliMgr::DeleteRemoteCli(const std::string &devId) +{ + DHLOGI("DInputSourceSACliMgr::DeleteRemoteCli devId=%{public}s", GetAnonyString(devId).c_str()); + std::lock_guard lock(remoteCliLock); + auto item = remoteCliMap.find(devId); + if (item == remoteCliMap.end()) { + DHLOGI("DInputSourceSACliMgr::DeleteRemoteCli not found device"); + return; + } + + if (item->second != nullptr) { + item->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv); + } + remoteCliMap.erase(item); +} + +void DInputSourceSACliMgr::DeleteRemoteCli(const sptr remote) +{ + std::lock_guard lock(remoteCliLock); + auto iter = std::find_if(remoteCliMap.begin(), remoteCliMap.end(), [&]( + const std::pair> &item)->bool { + return item.second->AsObject() == remote; + }); + if (iter == remoteCliMap.end()) { + DHLOGI("VirtualHardwareManager::DeleteRemoteCli not found remote object"); + return; + } + + DHLOGI("VirtualHardwareManager::DeleteRemoteCli remote.devId=%{public}s", GetAnonyString(iter->first).c_str()); + if (iter->second != nullptr) { + iter->second->AsObject()->RemoveDeathRecipient(remoteCliDeathRcv); + } + remoteCliMap.erase(iter); +} + +void DInputSourceSACliMgr::ProcRemoteCliDied(const sptr& remote) +{ + auto remoteCliDiedProc = [this, remote]() { + DeleteRemoteCli(remote); + }; + if (!(dinputMgrHandler_ && dinputMgrHandler_->PostTask(remoteCliDiedProc))) { + DHLOGE("DInputSourceSACliMgr::OnRemoteDied PostTask fail"); + } +} +} +} +} \ No newline at end of file diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 6acf51e..2c8ba51 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "${ipc_path}/src", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/include", "//foundation/distributedhardware/distributed_input/frameworks/include", + "//foundation/distributedhardware/distributed_input/inputdevicehandler/include", "//commonlibrary/c_utils/base/include", "//utils/system/safwk/native/include", "${common_path}/include", @@ -56,6 +57,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { ] sources = [ + "${common_path}/include/dinput_struct_data.cpp", "${common_path}/include/input_hub.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", @@ -88,6 +90,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_manager.cpp", + "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp", "//foundation/distributedhardware/distributed_input/services/source/transport/src/distributed_input_source_transport.cpp", "distributed_input_sourcemanager_test.cpp", ] @@ -121,6 +124,7 @@ ohos_unittest("distributed_input_sourcemanager_test") { "//third_party/openssl:libcrypto_static", "${fwk_interfaces_path}:libdhfwk_sdk", "${innerkits_path}:libdinput_sdk", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ 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 6a2eec9..60d3e77 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -105,6 +105,14 @@ void DistributedInputSourceManagerTest::TestStopDInputCallback::OnResult( return; } +void DistributedInputSourceManagerTest::TestStartStopVectorCallbackStub::OnResultDhids(const std::string &devId, + const int32_t &status) +{ + (void)devId; + (void)status; + return; +} + void DistributedInputSourceManagerTest::TestAddWhiteListInfosCb::OnResult( const std::string &deviceId, const std::string &strJson) { @@ -120,6 +128,43 @@ void DistributedInputSourceManagerTest::TestDelWhiteListInfosCb::OnResult( return; } +void DistributedInputSourceManagerTest::TestStartStopResultCb::OnStart(const std::string &srcId, + const std::string &sinkId, std::vector &devData) +{ + (void)srcId; + (void)sinkId; + (void)devData; + return; +} + +void DistributedInputSourceManagerTest::TestStartStopResultCb::OnStop(const std::string &srcId, + const std::string &sinkId, std::vector &devData) +{ + (void)srcId; + (void)sinkId; + (void)devData; + return; +} + +void DistributedInputSourceManagerTest::TestInputNodeListenerCb::OnNodeOnLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId, const std::string sinkNodeDesc) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + (void)sinkNodeDesc; + return; +} + +void DistributedInputSourceManagerTest::TestInputNodeListenerCb::OnNodeOffLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + return; +} + int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const { nlohmann::json tmpJson; @@ -139,6 +184,12 @@ int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pB return DH_SUCCESS; } +HWTEST_F(DistributedInputSourceManagerTest, Init01, testing::ext::TestSize.Level0) +{ + int32_t ret = sourceManager_->Init(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL, ret); +} + HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testing::ext::TestSize.Level0) { InputDevice pBuffer; @@ -211,8 +262,7 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput01, testing::ext:: { std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; sptr callback = new TestPrepareDInputCallback(); - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); + int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); } @@ -220,8 +270,7 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput02, testing::ext:: { std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; sptr callback; - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); + int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); } @@ -229,8 +278,34 @@ HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput03, testing::ext:: { std::string devId = ""; sptr callback = new TestPrepareDInputCallback(); - sptr addWhiteListCallback = new TestAddWhiteListInfosCb(); - int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback, addWhiteListCallback); + int32_t ret = sourceManager_->PrepareRemoteInput(devId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback = new TestPrepareDInputCallback(); + int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput05, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback; + int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, PrepareRemoteInput06, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = new TestPrepareDInputCallback(); + int32_t ret = sourceManager_->PrepareRemoteInput(srcId, sinkId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); } @@ -258,6 +333,68 @@ HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput03, testing::ext::Te EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); } +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback = new TestStartDInputCallback(); + int32_t ret = + sourceManager_->StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput05, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback; + int32_t ret = + sourceManager_->StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput06, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = new TestStartDInputCallback(); + int32_t ret = + sourceManager_->StartRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput10, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + std::vector dhIds; + dhIds.push_back("Input_slkdiek3kddkeojfe"); + sptr callback = new TestStartStopVectorCallbackStub(); + int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput11, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + std::vector dhIds; + sptr callback; + int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StartRemoteInput12, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + std::vector dhIds; + dhIds.push_back("Input_sldkjfldsjf234mdwswo"); + sptr callback = new TestStartStopVectorCallbackStub(); + int32_t ret = sourceManager_->StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput01, testing::ext::TestSize.Level0) { std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; @@ -282,12 +419,73 @@ HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput03, testing::ext::Tes EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); } +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91ev"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback = new TestStopDInputCallback(); + int32_t ret = + sourceManager_->StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput05, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = new TestStopDInputCallback(); + int32_t ret = + sourceManager_->StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput06, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91ev"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback; + int32_t ret = + sourceManager_->StopRemoteInput(srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput10, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + std::vector dhIds; + dhIds.push_back("Input_slkdiek3kddkeojfe"); + sptr callback = new TestStartStopVectorCallbackStub(); + int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput11, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + std::vector dhIds; + sptr callback; + int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, StopRemoteInput12, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + std::vector dhIds; + dhIds.push_back("Input_sldkjfldsjf234mdwswo"); + sptr callback = new TestStartStopVectorCallbackStub(); + int32_t ret = sourceManager_->StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0) { std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; sptr callback = new TestUnprepareDInputCallback(); - sptr delWhiteListCallback = new TestDelWhiteListInfosCb(); - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); + int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); } @@ -295,8 +493,7 @@ HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput02, testing::ext { std::string devId = ""; sptr callback = new TestUnprepareDInputCallback(); - sptr delWhiteListCallback = new TestDelWhiteListInfosCb(); - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); + int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); } @@ -304,8 +501,34 @@ HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput03, testing::ext { std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; sptr callback; - sptr delWhiteListCallback; - int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback, delWhiteListCallback); + int32_t ret = sourceManager_->UnprepareRemoteInput(devId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback = new TestUnprepareDInputCallback(); + int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput05, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = new TestUnprepareDInputCallback(); + int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, UnprepareRemoteInput06, testing::ext::TestSize.Level0) +{ + std::string srcId = "umkyu1b165e1be98151891erbe8r91eb"; + std::string sinkId = "umkyu1b165e1be98151891erbe8r91ev"; + sptr callback; + int32_t ret = sourceManager_->UnprepareRemoteInput(srcId, sinkId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); } @@ -335,6 +558,48 @@ HWTEST_F(DistributedInputSourceManagerTest, UnregisterDistributedHardware03, tes int32_t ret = sourceManager_->UnregisterDistributedHardware(devId, dhId, callback); EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret); } -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file + +HWTEST_F(DistributedInputSourceManagerTest, RegisterAddWhiteListCallback01, testing::ext::TestSize.Level0) +{ + sptr callback; + int32_t ret = sourceManager_->RegisterAddWhiteListCallback(callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, RegisterAddWhiteListCallback02, testing::ext::TestSize.Level0) +{ + sptr callback = new TestAddWhiteListInfosCb(); + int32_t ret = sourceManager_->RegisterAddWhiteListCallback(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, RegisterDelWhiteListCallback01, testing::ext::TestSize.Level0) +{ + sptr callback; + int32_t ret = sourceManager_->RegisterDelWhiteListCallback(callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, RegisterDelWhiteListCallback02, testing::ext::TestSize.Level0) +{ + sptr callback = new TestDelWhiteListInfosCb(); + int32_t ret = sourceManager_->RegisterDelWhiteListCallback(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, RegisterInputNodeListener01, testing::ext::TestSize.Level0) +{ + sptr callback = new TestInputNodeListenerCb(); + int32_t ret = sourceManager_->RegisterInputNodeListener(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DistributedInputSourceManagerTest, UnRegisterInputNodeListener01, testing::ext::TestSize.Level0) +{ + sptr callback = new TestInputNodeListenerCb(); + int32_t ret = sourceManager_->UnregisterInputNodeListener(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} +} +} +} 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 bf1469a..f59778a 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h @@ -33,6 +33,9 @@ #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" +#include "start_stop_result_call_back_stub.h" +#include "input_node_listener_stub.h" namespace OHOS { namespace DistributedHardware { @@ -76,6 +79,14 @@ public: void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); }; + class TestStartStopVectorCallbackStub + : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + public: + TestStartStopVectorCallbackStub() = default; + virtual ~TestStartStopVectorCallbackStub() = default; + void OnResultDhids(const std::string &devId, const int32_t &status); + }; + class TestRegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { public: TestRegisterDInputCb() = default; @@ -104,6 +115,25 @@ public: void OnResult(const std::string &deviceId); }; + class TestStartStopResultCb : public OHOS::DistributedHardware::DistributedInput::StartStopResultCallbackStub { + public: + TestStartStopResultCb() = default; + virtual ~TestStartStopResultCb() = default; + void OnStart(const std::string &srcId, const std::string &sinkId, std::vector &devData); + void OnStop(const std::string &srcId, const std::string &sinkId, std::vector &devData); + }; + + class TestInputNodeListenerCb : public OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { + public: + TestInputNodeListenerCb() = default; + virtual ~TestInputNodeListenerCb() = default; + void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc); + + void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId); + }; + private: int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const; DistributedInputSourceManager* sourceManager_; diff --git a/services/source/transport/BUILD.gn b/services/source/transport/BUILD.gn index c38a689..7a78404 100755 --- a/services/source/transport/BUILD.gn +++ b/services/source/transport/BUILD.gn @@ -34,6 +34,8 @@ ohos_shared_library("libdinput_source_trans") { "${dfx_utils_path}/include", "${utils_path}/include", "${low_latency_path}/include", + "${frameworks_path}/include", + "${distributedinput_path}/inputdevicehandler/include", ] sources = [ "src/distributed_input_source_transport.cpp" ] @@ -57,6 +59,7 @@ ohos_shared_library("libdinput_source_trans") { "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index bfe0523..87783a9 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -54,6 +54,9 @@ public: void StartLatencyThread(const std::string& deviceId); void StopLatencyThread(); + int32_t StartRemoteInput(const std::string &deviceId, const std::vector &dhids); + int32_t StopRemoteInput(const std::string &deviceId, const std::vector &dhids); + int32_t OnSessionOpened(int32_t sessionId, int32_t result); void OnSessionClosed(int32_t sessionId); void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); @@ -69,6 +72,9 @@ private: 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); void NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg); diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 450c769..c689290 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -297,7 +297,7 @@ int32_t DistributedInputSourceTransport::StartRemoteInput( if (sessionDevMap_.count(deviceId) > 0) { int32_t sessionId = sessionDevMap_[deviceId]; nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START; + 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; @@ -325,7 +325,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput( if (sessionDevMap_.count(deviceId) > 0) { int32_t sessionId = sessionDevMap_[deviceId]; nlohmann::json jsonStr; - jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP; + 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; @@ -410,6 +410,72 @@ void DistributedInputSourceTransport::StopLatencyThread() DHLOGI("end"); } +int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &deviceId, + const std::vector &dhids) +{ + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.count(deviceId) == 0) { + DHLOGE("StartRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; + } + int32_t sessionId = sessionDevMap_[deviceId]; + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_DHID; + jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; + jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; + std::string strTmp = ""; + for (auto iter : dhids) { + strTmp = strTmp + iter + "."; + } + if (!strTmp.empty()) { + strTmp.erase(strTmp.end() - 1); // delete the last '.' char + } + jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp; + std::string smsg = jsonStr.dump(); + int32_t ret = SendMsg(sessionId, smsg); + if (ret != DH_SUCCESS) { + DHLOGE("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); + return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; + } + DHLOGI("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", GetAnonyString(deviceId).c_str(), + GetAnonyInt32(sessionId).c_str(), smsg.c_str()); + return DH_SUCCESS; +} + +int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &deviceId, + const std::vector &dhids) +{ + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.count(deviceId) == 0) { + DHLOGE("StopRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); + return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; + } + int32_t sessionId = sessionDevMap_[deviceId]; + nlohmann::json jsonStr; + jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; + jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; + jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; + std::string strTmp = ""; + for (auto iter : dhids) { + strTmp = strTmp + iter + "."; + } + if (!strTmp.empty()) { + strTmp.erase(strTmp.end() - 1); // delete the last '.' char + } + jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp; + std::string smsg = jsonStr.dump(); + int32_t ret = SendMsg(sessionId, smsg); + if (ret != DH_SUCCESS) { + DHLOGE("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); + return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; + } + DHLOGI("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", GetAnonyString(deviceId).c_str(), + GetAnonyInt32(sessionId).c_str(), smsg.c_str()); + return DH_SUCCESS; +} + std::string DistributedInputSourceTransport::FindDeviceBySession(int32_t sessionId) { std::unique_lock sessionLock(operationMutex_); @@ -553,6 +619,52 @@ void DistributedInputSourceTransport::NotifyResponseStopRemoteInput(int32_t sess deviceId, recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); } +void DistributedInputSourceTransport::NotifyResponseStartRemoteInputDhid(int32_t sessionId, + const nlohmann::json &recMsg) +{ + DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART."); + if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART, data type is error."); + return; + } + std::string deviceId = FindDeviceBySession(sessionId); + if (deviceId.empty()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTART, deviceId is error."); + return; + } + callback_->onResponseStartRemoteInputDhid( + deviceId, recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); +} + +void DistributedInputSourceTransport::NotifyResponseStopRemoteInputDhid(int32_t sessionId, const nlohmann::json &recMsg) +{ + DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP."); + if (!recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE].is_boolean()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP, data type is error."); + return; + } + std::string deviceId = FindDeviceBySession(sessionId); + if (deviceId.empty()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_DHID_ONSTOP, deviceId is error."); + return; + } + callback_->onResponseStopRemoteInputDhid( + deviceId, recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID], recMsg[DINPUT_SOFTBUS_KEY_RESP_VALUE]); +} + +void DistributedInputSourceTransport::NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg) +{ + DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE."); + std::string deviceId = FindDeviceBySession(sessionId); + if (deviceId.empty()) { + DHLOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_KEY_STATE, deviceId is error."); + return; + } + callback_->onResponseKeyState(deviceId, recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID], + recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE], recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE], + recMsg[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE]); +} + void DistributedInputSourceTransport::NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg) { DHLOGI("OnBytesReceived cmdType is TRANS_SINK_MSG_BODY_DATA."); @@ -622,6 +734,18 @@ void DistributedInputSourceTransport::HandleSessionData(int32_t sessionId, const CalculateLatency(sessionId, recMsg); break; } + case TRANS_SINK_MSG_DHID_ONSTART: { + NotifyResponseStartRemoteInputDhid(sessionId, recMsg); + break; + } + case TRANS_SINK_MSG_DHID_ONSTOP: { + NotifyResponseStopRemoteInputDhid(sessionId, recMsg); + break; + } + case TRANS_SINK_MSG_KEY_STATE: { + NotifyResponseKeyState(sessionId, recMsg); + break; + } default: { DHLOGE("OnBytesReceived cmdType is undefined."); break; @@ -688,7 +812,7 @@ int32_t DistributedInputSourceTransport::GetCurrentSessionId() // send message by sessionId (channel opened) int32_t DistributedInputSourceTransport::SendMsg(int32_t sessionId, std::string &message) { - DHLOGI("start SendMsg"); + DHLOGD("start SendMsg"); if (message.size() > MSG_MAX_SIZE) { DHLOGE("SendMessage error: message.size() > MSG_MAX_SIZE"); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_SENDMESSSAGE; diff --git a/services/source/transport/test/sourcetransunittest/BUILD.gn b/services/source/transport/test/sourcetransunittest/BUILD.gn index 7b4c836..1c982de 100755 --- a/services/source/transport/test/sourcetransunittest/BUILD.gn +++ b/services/source/transport/test/sourcetransunittest/BUILD.gn @@ -43,6 +43,8 @@ ohos_unittest("distributed_input_sourcetrans_test") { "${dfx_utils_path}/include", "${utils_path}/include", "${low_latency_path}/include", + "${frameworks_path}/include", + "${distributedinput_path}/inputdevicehandler/include", ] sources = [ @@ -73,6 +75,7 @@ ohos_unittest("distributed_input_sourcetrans_test") { "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ 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 7596299..58c2450 100644 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp +++ b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp @@ -38,6 +38,12 @@ void DistributedInputSourceTransTest::TearDownTestCase() { } +HWTEST_F(DistributedInputSourceTransTest, Init, testing::ext::TestSize.Level0) +{ + int32_t ret = DistributedInputSourceTransport::GetInstance().Init(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL, ret); +} + HWTEST_F(DistributedInputSourceTransTest, PrepareRemoteInput01, testing::ext::TestSize.Level0) { std::string deviceId = ""; diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp index b38fdd1..62b3712 100644 --- a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp +++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.cpp @@ -85,6 +85,21 @@ public: }; }; +class TestIStartStopDInputsCallback : public OHOS::DistributedHardware + ::DistributedInput::IStartStopDInputsCallback { +public: + virtual void OnResultDhids(const std::string &devId, const int32_t &status) override + { + (void)devId; + (void)status; + }; + + virtual sptr AsObject() override + { + return nullptr; + } +}; + void PrepareInputFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { @@ -105,13 +120,16 @@ void StartRemoteInputFuzzTest(const uint8_t* data, size_t size) return; } - std::string dhId(reinterpret_cast(data), size); + std::string srcId = "123"; + std::string sinkId = "456"; uint32_t inputTypes = *(reinterpret_cast(data)); - - OHOS::sptr startCb = new(std::nothrow) TestStartDInputCallback(); - OHOS::sptr stopCb = new(std::nothrow) TestStopDInputCallback(); - DistributedInput::DistributedInputKit::StartRemoteInput(dhId, inputTypes, startCb); - DistributedInput::DistributedInputKit::StopRemoteInput(dhId, inputTypes, stopCb); + std::vector dhIds= {}; + OHOS::sptr startCb = new (std::nothrow) TestStartDInputCallback(); + OHOS::sptr stopCb = new (std::nothrow) TestStopDInputCallback(); + DistributedInput::DistributedInputKit::StartRemoteInput(srcId, sinkId, inputTypes, startCb); + DistributedInput::DistributedInputKit::StopRemoteInput(srcId, sinkId, inputTypes, stopCb); + OHOS::sptr callback = new (std::nothrow) TestIStartStopDInputsCallback(); + DistributedInput::DistributedInputKit::StartRemoteInput(sinkId, dhIds, callback); } void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size) @@ -131,6 +149,23 @@ void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size) DistributedInput::DistributedInputKit::IsNeedFilterOut(deviceId, event); } +void StopRemoteInputFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + 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); +} void IsTouchEventNeedFilterOutFuzzTest(const uint8_t* data, size_t size) { @@ -156,6 +191,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::PrepareInputFuzzTest(data, size); OHOS::DistributedHardware::StartRemoteInputFuzzTest(data, size); OHOS::DistributedHardware::IsNeedFilterOutFuzzTest(data, size); + OHOS::DistributedHardware::StopRemoteInputFuzzTest(data, size); OHOS::DistributedHardware::IsTouchEventNeedFilterOutFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn index e9e8365..f2f470f 100755 --- a/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn +++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn @@ -41,6 +41,8 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") { "${utils_path}/include", "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter", "${low_latency_path}/include", + "${frameworks_path}/include", + "${distributedinput_path}/inputdevicehandler/include", ] cflags = [ @@ -64,6 +66,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") { "//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", "//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans", + "${distributedinput_path}/inputdevicehandler:libdinput_handler", ] external_deps = [ diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 56cee5b..d9a1153 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -41,6 +41,7 @@ bool IsString(const nlohmann::json& jsonObj, const std::string& key); bool IsInt32(const nlohmann::json& jsonObj, const std::string& key); bool IsUint32(const nlohmann::json& jsonObj, const std::string& key); bool IsUint64(const nlohmann::json& jsonObj, const std::string& key); +std::string GetNodeDesc(std::string parameters); } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dinput_sa_process_state.cpp b/utils/src/dinput_sa_process_state.cpp index 3c8caef..77be265 100644 --- a/utils/src/dinput_sa_process_state.cpp +++ b/utils/src/dinput_sa_process_state.cpp @@ -49,7 +49,7 @@ void SetSinkProcessExit() #ifdef DINPUT_LOW_LATENCY DInputLowLatency::GetInstance().DisableSinkLowLatency(); #endif - exit(0); + _Exit(0); } void SetSourceProcessExit() @@ -66,7 +66,7 @@ void SetSourceProcessExit() #ifdef DINPUT_LOW_LATENCY DInputLowLatency::GetInstance().DisableSourceLowLatency(); #endif - exit(0); + _Exit(0); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 97d00e6..8770177 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -127,6 +127,18 @@ bool IsUint64(const nlohmann::json& jsonObj, const std::string& key) DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid"); return res; } + +std::string GetNodeDesc(std::string parameters) +{ + nlohmann::json parObj = nlohmann::json::parse(parameters); + std::string nodeName = "N/A"; + int32_t classes = -1; + if (parObj.find("name") != parObj.end() && parObj.find("classes") != parObj.end()) { + nodeName = parObj.at("name").get(); + classes = parObj.at("classes").get(); + } + return "{ NodeName: " + nodeName + ", classes: " + std::to_string(classes) + " }"; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file