diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 7f68557..ad32c82 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -164,6 +164,8 @@ namespace DistributedInput { 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; + constexpr int32_t ERR_DH_INPUT_SINK_PROXY_REGISTER_SHARING_DHID_LISTENER_FAIL = -67054; + constexpr int32_t ERR_DH_INPUT_SINK_STUB_REGISTER_SHARING_DHID_LISTENER_FAIL = -67055; // Hidump Helper error code constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 7b19bac..4fe9f87 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -938,18 +938,30 @@ bool InputHub::IsSupportInputTypes(uint32_t classes) return classes & inputTypes_; } -void InputHub::SetSupportInputType(const uint32_t &inputTypes) +void InputHub::SaveAffectDhId(bool isEnable, const std::string &dhId, AffectDhIds &affDhIds) { + if (isEnable) { + affDhIds.sharingDhIds.push_back(dhId); + } else { + affDhIds.noSharingDhIds.push_back(dhId); + } +} + +AffectDhIds InputHub::SetSupportInputType(bool enabled, const uint32_t &inputTypes) +{ + AffectDhIds affDhIds; 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; + device->isShare = enabled; + DHLOGW("ByType dhid:%s, isshare:%d", device->identifier.descriptor.c_str(), enabled); + SaveAffectDhId(enabled, device->identifier.descriptor, affDhIds); } } + + return affDhIds; } void InputHub::GetDeviceDhIdByFd(int32_t fd, std::string &dhId) @@ -964,18 +976,22 @@ void InputHub::GetDeviceDhIdByFd(int32_t fd, std::string &dhId) dhId.clear(); } -void InputHub::SetSharingDevices(bool enabled, std::vector dhIds) +AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector dhIds) { + AffectDhIds affDhIds; 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); + DHLOGW("dhid:%s, isshare:%d", device->identifier.descriptor.c_str(), enabled); + SaveAffectDhId(enabled, device->identifier.descriptor, affDhIds); break; } } } + + return affDhIds; } void InputHub::GetShareMousePathByDhId(std::vector dhIds, std::string &path, std::string &dhId) diff --git a/common/include/input_hub.h b/common/include/input_hub.h index ef08dca..176439c 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -31,6 +31,11 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +struct AffectDhIds { + std::vector sharingDhIds; + std::vector noSharingDhIds; +}; + class InputHub { public: InputHub(); @@ -41,8 +46,10 @@ public: void StopCollectInputHandler(); size_t DeviceIsExists(InputDeviceEvent* event, size_t capacity); std::vector GetAllInputDevices(); - void SetSupportInputType(const uint32_t &inputType); - void SetSharingDevices(bool enabled, std::vector dhIds); + // return efftive dhids + AffectDhIds SetSupportInputType(bool enabled, const uint32_t &inputType); + // return efftive dhids + AffectDhIds 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); @@ -130,6 +137,10 @@ private: bool CheckTouchPointRegion(struct input_event readBuffer[], const AbsInfo& absInfo, Device* device); size_t CollectEvent(RawEvent* buffer, size_t& capacity, Device* device, struct input_event readBuffer[], const size_t count); + /* + * isEnable: true for sharing dhid, false for no sharing dhid + */ + void SaveAffectDhId(bool isEnable, const std::string &dhId, AffectDhIds &affDhIds); int epollFd_; int iNotifyFd_; diff --git a/frameworks/include/i_distributed_sink_input.h b/frameworks/include/i_distributed_sink_input.h index 8734b5b..6684265 100644 --- a/frameworks/include/i_distributed_sink_input.h +++ b/frameworks/include/i_distributed_sink_input.h @@ -23,7 +23,8 @@ #include "constants_dinput.h" #include "dinput_context.h" -#include "i_start_d_input_server_call_back.h" +#include "i_distributed_sink_input.h" +#include "i_sharing_dhid_listener.h" namespace OHOS { namespace DistributedHardware { @@ -33,16 +34,13 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IDistributedSinkInput"); /* - * Init, Release and IsStartDistributedInput are IPC interface, + * Init and Release are IPC interface, * which are used for interacting by dhareware and dinput */ virtual int32_t Init() = 0; virtual int32_t Release() = 0; - virtual int32_t IsStartDistributedInput( - const uint32_t& inputType, sptr callback) = 0; - /* * NotifyStartDScreen and NotifyStopDScreen are RPC interface, * which are used for interacting by dinput source and dinput sink @@ -51,12 +49,14 @@ public: virtual int32_t NotifyStopDScreen(const std::string &srcScreenInfoKey) = 0; + virtual int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener) = 0; + enum { INIT = 0xf011U, RELEASE = 0xf012U, - IS_START_REMOTE_INPUT = 0xf013U, - NOTIFY_START_DSCREEN = 0xf014U, - NOTIFY_STOP_DSCREEN = 0xf015U, + NOTIFY_START_DSCREEN = 0xf013U, + NOTIFY_STOP_DSCREEN = 0xf014U, + REGISTER_SHARING_DHID_LISTENER = 0xf015U, }; }; } // namespace DistributedInput diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index 8bfd5c8..7e6ea62 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -28,7 +28,6 @@ #include "i_prepare_d_input_call_back.h" #include "i_register_d_input_call_back.h" #include "i_start_d_input_call_back.h" -#include "i_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" @@ -90,9 +89,6 @@ public: 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; @@ -112,7 +108,6 @@ public: UNPREPARE_REMOTE_INPUT = 0xf006, 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, diff --git a/frameworks/include/i_start_d_input_server_call_back.h b/frameworks/include/i_sharing_dhid_listener.h similarity index 68% rename from frameworks/include/i_start_d_input_server_call_back.h rename to frameworks/include/i_sharing_dhid_listener.h index 7396283..13c9aff 100644 --- a/frameworks/include/i_start_d_input_server_call_back.h +++ b/frameworks/include/i_sharing_dhid_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,30 +13,30 @@ * limitations under the License. */ -#ifndef I_START_D_INPUT_SERVER_CALL_BACK_H -#define I_START_D_INPUT_SERVER_CALL_BACK_H +#ifndef I_SHARING_DHID_LISTENER_H +#define I_SHARING_DHID_LISTENER_H #include #include -#include "constants_dinput.h" - namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -class IStartDInputServerCallback : public IRemoteBroker { +class ISharingDhIdListener : public IRemoteBroker { public: - virtual void OnResult(const int32_t& status, const uint32_t& inputTypes) = 0; + virtual int32_t OnSharing(std::string dhId) = 0; + virtual int32_t OnNoSharing(std::string dhId) = 0; enum class Message { - RESULT, + SHARING, + NO_SHARING }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IStartDInputServerCallback"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.ISharingDhIdListener"); }; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -#endif // I_START_D_INPUT_SERVER_CALL_BACK_H +#endif // I_SHARING_DHID_LISTENER_H \ No newline at end of file diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index dc59316..1124d9b 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -51,16 +51,16 @@ ohos_shared_library("libdinput_sdk") { "${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", "${ipc_path}/src/register_d_input_call_back_stub.cpp", + "${ipc_path}/src/sharing_dhid_listener_proxy.cpp", + "${ipc_path}/src/sharing_dhid_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", "${ipc_path}/src/start_d_input_call_back_proxy.cpp", "${ipc_path}/src/start_d_input_call_back_stub.cpp", - "${ipc_path}/src/start_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", diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index db8a56f..27261b9 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -70,6 +70,12 @@ public: static bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event); static DInputServerType IsStartDistributedInput(const uint32_t& inputType); + /* + * check is dhId sharing to other devices + * true: dhId sharing to other device + * false: dhId NOT sharing to other device + */ + static bool IsStartDistributedInput(const std::string& dhId); static int32_t RegisterInputNodeListener(sptr listener); static int32_t UnregisterInputNodeListener(sptr listener); diff --git a/interfaces/inner_kits/src/distributed_input_kit.cpp b/interfaces/inner_kits/src/distributed_input_kit.cpp index 5101aad..480fe7f 100644 --- a/interfaces/inner_kits/src/distributed_input_kit.cpp +++ b/interfaces/inner_kits/src/distributed_input_kit.cpp @@ -66,7 +66,12 @@ bool DistributedInputKit::IsTouchEventNeedFilterOut(const TouchScreenEvent &even DInputServerType DistributedInputKit::IsStartDistributedInput(const uint32_t& inputType) { - return DistributedInputClient::GetInstance().IsStartDistributedInput(inputType); + return DInputServerType::NULL_SERVER_TYPE; +} + +bool DistributedInputKit::IsStartDistributedInput(const std::string& dhId) +{ + return DistributedInputClient::GetInstance().IsStartDistributedInput(dhId); } int32_t DistributedInputKit::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index 48e21b3..108e2d2 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -58,10 +58,12 @@ ohos_unittest("distributed_input_inner_test") { "${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/sharing_dhid_listener_proxy.cpp", + "${ipc_path}/src/sharing_dhid_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", "${ipc_path}/src/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", 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 3692ae1..177689a 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -402,30 +402,6 @@ HWTEST_F(DistributedInputInnerTest, IsTouchEventNeedFilterOut01, testing::ext::T ret = DistributedInputKit::IsTouchEventNeedFilterOut(event); EXPECT_EQ(false, ret); } - -HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput1, testing::ext::TestSize.Level0) -{ - DistributedInputClient::GetInstance().ReleaseSource(); - DistributedInputClient::GetInstance().InitSink(); - DInputServerType ret = DistributedInputKit::IsStartDistributedInput(static_cast(DInputDeviceType::ALL)); - - if (ret == DInputServerType::NULL_SERVER_TYPE) { - EXPECT_EQ(DH_SUCCESS, 0); - } else { - EXPECT_EQ(DH_SUCCESS, -1); - } -} - -HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput2, testing::ext::TestSize.Level0) -{ - DInputServerType ret = DistributedInputKit::IsStartDistributedInput(static_cast(DInputDeviceType::ALL)); - - if (ret == DInputServerType::NULL_SERVER_TYPE) { - EXPECT_EQ(DH_SUCCESS, 0); - } else { - EXPECT_EQ(DH_SUCCESS, -1); - } -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file 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 8f6b35f..acd35af 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 @@ -65,20 +65,6 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( } } -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = DInputDeviceType::NONE; - } -} - void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) { nlohmann::json inputData = nlohmann::json::parse(strJson); @@ -182,11 +168,6 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e return false; } -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) -{ - return serverType; -} - bool DistributedInputClient::IsJsonData(std::string strData) const { return true; diff --git a/interfaces/ipc/include/dinput_sa_manager.h b/interfaces/ipc/include/dinput_sa_manager.h index 3bb9918..8178d6e 100644 --- a/interfaces/ipc/include/dinput_sa_manager.h +++ b/interfaces/ipc/include/dinput_sa_manager.h @@ -31,7 +31,10 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -const uint32_t DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG = 1; +const uint32_t DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG = 1; +const uint32_t DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG = 2; +const uint32_t DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG = 3; +const uint32_t DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG = 4; class DInputSAManager { DECLARE_SINGLE_INSTANCE_BASE(DInputSAManager); public: diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 99f4bb8..314030d 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -21,19 +21,21 @@ #include #include +#include "event_handler.h" + #include "add_white_list_infos_call_back_stub.h" #include "del_white_list_infos_call_back_stub.h" #include "i_distributed_source_input.h" #include "i_distributed_sink_input.h" +#include "i_sharing_dhid_listener.h" #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 "sharing_dhid_listener_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 { @@ -92,7 +94,7 @@ public: bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event); - DInputServerType IsStartDistributedInput(const uint32_t& inputType); + bool IsStartDistributedInput(const std::string& dhId); 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); @@ -103,12 +105,15 @@ public: int32_t RegisterSimulationEventListener(sptr listener); int32_t UnregisterSimulationEventListener(sptr listener); - void CheckRegisterCallback(); + void CheckSourceRegisterCallback(); void CheckWhiteListCallback(); void CheckNodeMonitorCallback(); void CheckKeyStateCallback(); void CheckStartStopResultCallback(); + void CheckSinkRegisterCallback(); + void CheckSharingDhIdsCallback(); + public: class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { public: @@ -124,13 +129,6 @@ public: void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status); }; - class StartDInputServerCb : public OHOS::DistributedHardware::DistributedInput::StartDInputServerCallbackStub { - public: - StartDInputServerCb() = default; - virtual ~StartDInputServerCb() = default; - void OnResult(const int32_t& status, const uint32_t& inputTypes); - }; - class AddWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::AddWhiteListInfosCallbackStub { public: AddWhiteListInfosCb() = default; @@ -145,6 +143,14 @@ public: void OnResult(const std::string &deviceId); }; + class SharingDhIdListenerCb : public OHOS::DistributedHardware::DistributedInput::SharingDhIdListenerStub { + public: + SharingDhIdListenerCb() = default; + virtual ~SharingDhIdListenerCb() = default; + int32_t OnSharing(std::string dhId); + int32_t OnNoSharing(std::string dhId); + }; + class DInputClientEventHandler : public AppExecFwk::EventHandler { public: DInputClientEventHandler(const std::shared_ptr &runner); @@ -166,23 +172,21 @@ private: DInputServerType serverType = DInputServerType::NULL_SERVER_TYPE; DInputDeviceType inputTypes_ = DInputDeviceType::NONE; - sptr sinkTypeCallback = nullptr; - sptr sourceTypeCallback = nullptr; sptr addWhiteListCallback_ = nullptr; sptr delWhiteListCallback_ = nullptr; sptr regNodeListener_ = nullptr; sptr unregNodeListener_ = nullptr; sptr regSimulationEventListener_ = nullptr; sptr unregSimulationEventListener_ = nullptr; + sptr sharingDhIdListener_ = nullptr; std::shared_ptr eventHandler_; - bool isAddWhiteListCbReg; - bool isDelWhiteListCbReg; - bool isNodeMonitorCbReg; - bool isNodeMonitorCbUnreg; - bool isSimulationEventCbReg; - bool isSimulationEventCbUnreg; + std::atomic isAddWhiteListCbReg; + std::atomic isDelWhiteListCbReg; + std::atomic isNodeMonitorCbReg; + std::atomic isSimulationEventCbReg; + std::atomic isSharingDhIdsReg; struct DHardWareFwkRegistInfo { std::string devId; @@ -199,6 +203,10 @@ private: std::vector dHardWareFwkRstInfos; std::vector dHardWareFwkUnRstInfos; std::mutex operationMutex_; + + std::mutex sharingDhIdsMtx_; + // sharing local dhids + std::set sharingDhIds_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/include/distributed_input_sink_proxy.h b/interfaces/ipc/include/distributed_input_sink_proxy.h index b34cf7b..ffaf1ff 100644 --- a/interfaces/ipc/include/distributed_input_sink_proxy.h +++ b/interfaces/ipc/include/distributed_input_sink_proxy.h @@ -22,6 +22,8 @@ #include "iremote_proxy.h" +#include "i_sharing_dhid_listener.h" + namespace OHOS { namespace DistributedHardware { namespace DistributedInput { @@ -36,12 +38,11 @@ public: virtual int32_t Release() override; - virtual int32_t IsStartDistributedInput( - const uint32_t& inputType, sptr callback) override; - virtual int32_t NotifyStartDScreen(const SrcScreenInfo& srcScreenRemoteCtrlInfo) override; virtual int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override; + virtual int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener) override; + private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/include/distributed_input_sink_stub.h b/interfaces/ipc/include/distributed_input_sink_stub.h index dc806ba..a72c4cd 100644 --- a/interfaces/ipc/include/distributed_input_sink_stub.h +++ b/interfaces/ipc/include/distributed_input_sink_stub.h @@ -37,12 +37,12 @@ public: int32_t ReleaseInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t IsStartDistributedInputInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t NotifyStartDScreenInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t NotifyStopDScreenInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); + int32_t RegisterSharingDhIdListenerInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); + private: DISALLOW_COPY_AND_MOVE(DistributedInputSinkStub); using DistributedInputSinkFunc = int32_t (DistributedInputSinkStub::*)(MessageParcel &data, MessageParcel &reply, diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index c3a315d..959c77a 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -76,9 +76,6 @@ public: 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; diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 7267686..3819ceb 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -50,7 +50,6 @@ private: 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); diff --git a/interfaces/ipc/include/start_d_input_server_call_back_proxy.h b/interfaces/ipc/include/sharing_dhid_listener_proxy.h similarity index 56% rename from interfaces/ipc/include/start_d_input_server_call_back_proxy.h rename to interfaces/ipc/include/sharing_dhid_listener_proxy.h index 819aeaf..c9f974c 100644 --- a/interfaces/ipc/include/start_d_input_server_call_back_proxy.h +++ b/interfaces/ipc/include/sharing_dhid_listener_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef START_D_INPUT_SERVER_CALL_BACK_PROXY_H -#define START_D_INPUT_SERVER_CALL_BACK_PROXY_H +#ifndef SHARING_DHID_LISTENER_PROXY_H +#define SHARING_DHID_LISTENER_PROXY_H -#include "i_start_d_input_server_call_back.h" +#include "i_sharing_dhid_listener.h" #include @@ -25,19 +25,20 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -class StartDInputServerCallbackProxy : public IRemoteProxy { +class SharingDhIdListenerProxy : public IRemoteProxy { public: - explicit StartDInputServerCallbackProxy(const sptr &object); + explicit SharingDhIdListenerProxy(const sptr &object); - virtual ~StartDInputServerCallbackProxy() override; + virtual ~SharingDhIdListenerProxy() override; - virtual void OnResult(const int32_t& status, const uint32_t& inputTypes) override; + virtual int32_t OnSharing(std::string dhId) override; + virtual int32_t OnNoSharing(std::string dhId) override; private: - static inline BrokerDelegator delegator_; + static inline BrokerDelegator delegator_; }; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -#endif // START_D_INPUT_CALL_BACK_PROXY_H +#endif // SHARING_DHID_LISTENER_PROXY_H \ No newline at end of file diff --git a/interfaces/ipc/include/start_d_input_server_call_back_stub.h b/interfaces/ipc/include/sharing_dhid_listener_stub.h similarity index 65% rename from interfaces/ipc/include/start_d_input_server_call_back_stub.h rename to interfaces/ipc/include/sharing_dhid_listener_stub.h index 2b3ab67..ba301c7 100644 --- a/interfaces/ipc/include/start_d_input_server_call_back_stub.h +++ b/interfaces/ipc/include/sharing_dhid_listener_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef START_D_INPUT_SERVER_CALL_BACK_STUB_H -#define START_D_INPUT_SERVER_CALL_BACK_STUB_H +#ifndef SHARING_DHID_LISTENER_STUB_H +#define SHARING_DHID_LISTENER_STUB_H -#include "i_start_d_input_server_call_back.h" +#include "i_sharing_dhid_listener.h" #include @@ -25,18 +25,18 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -class StartDInputServerCallbackStub : public IRemoteStub { +class SharingDhIdListenerStub : public IRemoteStub { public: - StartDInputServerCallbackStub(); - virtual ~StartDInputServerCallbackStub() override; + SharingDhIdListenerStub(); + virtual ~SharingDhIdListenerStub() override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: - DISALLOW_COPY_AND_MOVE(StartDInputServerCallbackStub); + DISALLOW_COPY_AND_MOVE(SharingDhIdListenerStub); }; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS -#endif // START_D_INPUT_SERVER_CALL_BACK_STUB_H +#endif // SHARING_DHID_LISTENER_STUB_H diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 29280f5..d423df8 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -26,17 +26,43 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { IMPLEMENT_SINGLE_INSTANCE(DInputSAManager); -const uint32_t DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME = 50; // million seconds +const uint32_t DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME = 100; // million seconds void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) { DInputSAManager::GetInstance().dInputSourceSAOnline.store(false); - std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); - DInputSAManager::GetInstance().dInputSourceProxy_ = nullptr; - } else if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { + { + std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); + DInputSAManager::GetInstance().dInputSourceProxy_ = nullptr; + } + { + std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); + if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { + DHLOGI("SendEvent DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG"); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG, systemAbilityId); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, + AppExecFwk::EventQueue::Priority::IMMEDIATE); + } + } + } + + if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { DInputSAManager::GetInstance().dInputSinkSAOnline.store(false); - std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); - DInputSAManager::GetInstance().dInputSinkProxy_ = nullptr; + { + std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); + DInputSAManager::GetInstance().dInputSinkProxy_ = nullptr; + } + { + std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); + if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { + DHLOGI("SendEvent DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG"); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG, systemAbilityId); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, + AppExecFwk::EventQueue::Priority::IMMEDIATE); + } + } } DHLOGI("sa %d is removed.", systemAbilityId); } @@ -47,14 +73,24 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb 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"); + DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG"); AppExecFwk::InnerEvent::Pointer msgEvent = - AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_CALLBACK_REGISTER_MSG, systemAbilityId); + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SOURCE_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) { + } + + if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { DInputSAManager::GetInstance().dInputSinkSAOnline.store(true); + std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); + if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { + DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG"); + AppExecFwk::InnerEvent::Pointer msgEvent = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG, systemAbilityId); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, + AppExecFwk::EventQueue::Priority::IMMEDIATE); + } } DHLOGI("sa %d is added.", systemAbilityId); } diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 9dedbca..65adeac 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -34,8 +34,7 @@ namespace DistributedHardware { namespace DistributedInput { std::shared_ptr DistributedInputClient::instance(new DistributedInputClient()); DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), - isNodeMonitorCbReg(false), isNodeMonitorCbUnreg(false), - isSimulationEventCbReg(false), isSimulationEventCbUnreg(false) + isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false) { DHLOGI("DistributedInputClient init start"); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); @@ -82,21 +81,6 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( } } -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - DHLOGI("StartDInputServerCb status: %d, inputTypes: %d, addr: %p", status, inputTypes, this); - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = DInputDeviceType::NONE; - } -} - void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) { if (!strJson.empty()) { @@ -109,6 +93,22 @@ void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& de DistributedInputClient::GetInstance().DelWhiteListInfos(deviceId); } +int32_t DistributedInputClient::SharingDhIdListenerCb::OnSharing(std::string dhId) +{ + std::lock_guard lock(DistributedInputClient::GetInstance().sharingDhIdsMtx_); + DHLOGI("Add Sharing Local dhId: %s", GetAnonyString(dhId).c_str()); + DistributedInputClient::GetInstance().sharingDhIds_.insert(dhId); + return DH_SUCCESS; +} + +int32_t DistributedInputClient::SharingDhIdListenerCb::OnNoSharing(std::string dhId) +{ + std::lock_guard lock(DistributedInputClient::GetInstance().sharingDhIdsMtx_); + DHLOGI("Remove No Sharing Local dhId: %s", GetAnonyString(dhId).c_str()); + DistributedInputClient::GetInstance().sharingDhIds_.erase(dhId); + return DH_SUCCESS; +} + DistributedInputClient::DInputClientEventHandler::DInputClientEventHandler( const std::shared_ptr &runner) : AppExecFwk::EventHandler(runner) @@ -119,25 +119,70 @@ void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExe { 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."); + if (eventId == DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG) { + DistributedInputClient::GetInstance().CheckSourceRegisterCallback(); + return; + } + + if (eventId == DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG) { + DistributedInputClient::GetInstance().CheckSinkRegisterCallback(); + return; + } + + if (eventId == DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG) { + DHLOGI("Source SA exit, clear callback flag"); + DistributedInputClient::GetInstance().isAddWhiteListCbReg = false; + DistributedInputClient::GetInstance().isDelWhiteListCbReg = false; + DistributedInputClient::GetInstance().isNodeMonitorCbReg = false; + DistributedInputClient::GetInstance().isSimulationEventCbReg = false; + return; + } + + if (eventId == DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG) { + DHLOGI("Sink SA exit, clear callback flag"); + DistributedInputClient::GetInstance().isSharingDhIdsReg = false; + return; } - DHLOGI("DInputClientEventHandler ProcessEvent end"); } -void DistributedInputClient::CheckRegisterCallback() +void DistributedInputClient::CheckSourceRegisterCallback() { - DHLOGI("CheckRegisterCallback called, awl[%d], dwl[%d], rnm[%d], unm[%d], rmd[%d], umd[%d]", - isAddWhiteListCbReg, isDelWhiteListCbReg, isNodeMonitorCbReg, isNodeMonitorCbUnreg, isSimulationEventCbReg, - isSimulationEventCbUnreg); + DHLOGI("CheckSourceRegisterCallback called, isAddWhiteListCbReg[%d], isDelWhiteListCbReg[%d]," + "isNodeMonitorCbReg[%d], isSimulationEventCbReg[%d]", + isAddWhiteListCbReg.load(), isDelWhiteListCbReg.load(), isNodeMonitorCbReg.load(), + isSimulationEventCbReg.load()); CheckWhiteListCallback(); CheckNodeMonitorCallback(); CheckKeyStateCallback(); } +void DistributedInputClient::CheckSinkRegisterCallback() +{ + DHLOGI("CheckSinkRegisterCallback called, isSharingDhIdsReg[%d]", isSharingDhIdsReg.load()); + CheckSharingDhIdsCallback(); +} + +void DistributedInputClient::CheckSharingDhIdsCallback() +{ + if (!DInputSAManager::GetInstance().GetDInputSinkProxy()) { + DHLOGE("CheckWhiteListCallback client get source proxy fail"); + return; + } + if (!isSharingDhIdsReg) { + if (sharingDhIdListener_ == nullptr) { + sharingDhIdListener_ = new (std::nothrow) SharingDhIdListenerCb(); + } + int32_t ret = + DInputSAManager::GetInstance().dInputSinkProxy_->RegisterSharingDhIdListener(sharingDhIdListener_); + if (ret == DH_SUCCESS) { + isSharingDhIdsReg = true; + } else { + DHLOGE("CheckSharingDhIdsCallback client RegisterSharingDhIdListener fail"); + } + } +} + void DistributedInputClient::CheckWhiteListCallback() { if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { @@ -181,12 +226,6 @@ void DistributedInputClient::CheckNodeMonitorCallback() 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() @@ -199,12 +238,6 @@ void DistributedInputClient::CheckKeyStateCallback() DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(regSimulationEventListener_); isSimulationEventCbReg = true; } - - if (!isSimulationEventCbUnreg && unregSimulationEventListener_ != nullptr) { - DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSimulationEventListener( - unregSimulationEventListener_); - isSimulationEventCbUnreg = true; - } } int32_t DistributedInputClient::InitSource() @@ -231,8 +264,6 @@ int32_t DistributedInputClient::ReleaseSource() serverType = DInputServerType::NULL_SERVER_TYPE; inputTypes_ = DInputDeviceType::NONE; - sinkTypeCallback = nullptr; - sourceTypeCallback = nullptr; addWhiteListCallback_ = nullptr; delWhiteListCallback_ = nullptr; regNodeListener_ = nullptr; @@ -251,7 +282,6 @@ int32_t DistributedInputClient::ReleaseSink() } serverType = DInputServerType::NULL_SERVER_TYPE; inputTypes_ = DInputDeviceType::NONE; - sinkTypeCallback = nullptr; WhiteListUtil::GetInstance().ClearWhiteList(); return DInputSAManager::GetInstance().dInputSinkProxy_->Release(); } @@ -572,37 +602,10 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e return false; } -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) +bool DistributedInputClient::IsStartDistributedInput(const std::string& dhId) { - DHLOGI("IsStartDistributedInput called, inputType: %d, current inputTypes: %d", - inputType, static_cast(inputTypes_)); - int32_t retSource = 0; - int32_t retSink = 0; - - if (sourceTypeCallback == nullptr && DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGI("Init sourceTypeCallback"); - sourceTypeCallback = new(std::nothrow) StartDInputServerCb(); - retSource = DInputSAManager::GetInstance().dInputSourceProxy_->IsStartDistributedInput(inputType, - sourceTypeCallback); - } - - if (sinkTypeCallback == nullptr && DInputSAManager::GetInstance().GetDInputSinkProxy()) { - DHLOGI("Init sinkTypeCallback"); - sinkTypeCallback = new(std::nothrow) StartDInputServerCb(); - retSink = DInputSAManager::GetInstance().dInputSinkProxy_->IsStartDistributedInput(inputType, sinkTypeCallback); - } - - if (static_cast(retSource) != DInputServerType::NULL_SERVER_TYPE) { - serverType = DInputServerType::SOURCE_SERVER_TYPE; - } else if (static_cast(retSink) != DInputServerType::NULL_SERVER_TYPE) { - serverType = DInputServerType::SINK_SERVER_TYPE; - } - - if (inputType & static_cast(inputTypes_)) { - return serverType; - } else { - return DInputServerType::NULL_SERVER_TYPE; - } + std::lock_guard lock(sharingDhIdsMtx_); + return sharingDhIds_.find(dhId) != sharingDhIds_.end(); } int32_t DistributedInputClient::RegisterInputNodeListener(sptr listener) @@ -639,17 +642,11 @@ int32_t DistributedInputClient::UnregisterInputNodeListener(sptrUnregisterInputNodeListener(listener); - if (ret == DH_SUCCESS) { - isNodeMonitorCbUnreg = true; - } else { - isNodeMonitorCbUnreg = false; - unregNodeListener_ = listener; + if (ret != DH_SUCCESS) { DHLOGE("DInputSAManager UnregisterInputNodeListener Failed, ret = %d", ret); } return ret; @@ -689,17 +686,11 @@ int32_t DistributedInputClient::UnregisterSimulationEventListener(sptrUnregisterSimulationEventListener(listener); - if (ret == DH_SUCCESS) { - isSimulationEventCbUnreg = true; - } else { - isSimulationEventCbUnreg = false; - unregSimulationEventListener_ = listener; + if (ret != DH_SUCCESS) { DHLOGE("UnregisterSimulationEventListener Failed, ret = %d", ret); } return ret; diff --git a/interfaces/ipc/src/distributed_input_sink_proxy.cpp b/interfaces/ipc/src/distributed_input_sink_proxy.cpp index ffc5aa3..d2e47a1 100644 --- a/interfaces/ipc/src/distributed_input_sink_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_sink_proxy.cpp @@ -67,33 +67,6 @@ int32_t DistributedInputSinkProxy::Release() return result; } -int32_t DistributedInputSinkProxy::IsStartDistributedInput( - const uint32_t& inputType, sptr callback) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("DistributedInputSinkProxy write token valid failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteUint32(inputType)) { - DHLOGE("DistributedInputSinkProxy write inputType failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("DistributedInputSinkProxy write callback failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - MessageParcel reply; - int32_t result = ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL; - bool ret = SendRequest(IS_START_REMOTE_INPUT, data, reply); - if (!ret) { - DHLOGE("SendRequest fail!"); - return ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL; - } - result = reply.ReadInt32(); - return result; -} - int32_t DistributedInputSinkProxy::NotifyStartDScreen(const SrcScreenInfo &remoteCtrlInfo) { MessageParcel data; @@ -147,6 +120,27 @@ int32_t DistributedInputSinkProxy::NotifyStopDScreen(const std::string &srcScree return result; } +int32_t DistributedInputSinkProxy::RegisterSharingDhIdListener(sptr sharingDhIdListener) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("RegisterSharingDhIdListener write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteRemoteObject(sharingDhIdListener->AsObject())) { + DHLOGE("RegisterSharingDhIdListener write callback failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + MessageParcel reply; + int32_t result = ERR_DH_INPUT_SINK_PROXY_REGISTER_SHARING_DHID_LISTENER_FAIL; + bool ret = SendRequest(REGISTER_SHARING_DHID_LISTENER, data, reply); + if (ret) { + result = reply.ReadInt32(); + } + return result; +} + bool DistributedInputSinkProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { sptr remote = Remote(); diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index 7e1be41..443eca4 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -20,6 +20,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" +#include "i_sharing_dhid_listener.h" namespace OHOS { namespace DistributedHardware { @@ -29,9 +30,9 @@ DistributedInputSinkStub::DistributedInputSinkStub() DHLOGI("DistributedInputSinkStub ctor!"); memberFuncMap_[INIT] = &DistributedInputSinkStub::InitInner; memberFuncMap_[RELEASE] = &DistributedInputSinkStub::ReleaseInner; - memberFuncMap_[IS_START_REMOTE_INPUT] = &DistributedInputSinkStub::IsStartDistributedInputInner; memberFuncMap_[NOTIFY_START_DSCREEN] = &DistributedInputSinkStub::NotifyStartDScreenInner; memberFuncMap_[NOTIFY_STOP_DSCREEN] = &DistributedInputSinkStub::NotifyStopDScreenInner; + memberFuncMap_[REGISTER_SHARING_DHID_LISTENER] = &DistributedInputSinkStub::RegisterSharingDhIdListenerInner; } DistributedInputSinkStub::~DistributedInputSinkStub() @@ -77,20 +78,6 @@ int32_t DistributedInputSinkStub::ReleaseInner(MessageParcel &data, MessageParce return ret; } -int32_t DistributedInputSinkStub::IsStartDistributedInputInner(MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - uint32_t inputType = data.ReadUint32(); - sptr callback = - iface_cast(data.ReadRemoteObject()); - int32_t ret = IsStartDistributedInput(inputType, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSinkStub write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; - } - return ret; -} - int32_t DistributedInputSinkStub::NotifyStartDScreenInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -140,6 +127,19 @@ int32_t DistributedInputSinkStub::NotifyStopDScreenInner(MessageParcel &data, Me } return ret; } + +int32_t DistributedInputSinkStub::RegisterSharingDhIdListenerInner(MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + sptr listener = iface_cast(data.ReadRemoteObject()); + int32_t ret = RegisterSharingDhIdListener(listener); + if (!reply.WriteInt32(ret)) { + DHLOGE("RegisterSharingDhIdListenerInner write ret failed, ret = %d", ret); + return ERR_DH_INPUT_SINK_STUB_REGISTER_SHARING_DHID_LISTENER_FAIL; + } + + return DH_SUCCESS; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index 02fa33f..fbae468 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -525,31 +525,6 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, c return result; } -int32_t DistributedInputSourceProxy::IsStartDistributedInput( - const uint32_t& inputType, 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.WriteUint32(inputType)) { - DHLOGE("DistributedInputSourceProxy write inputType 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_IS_START_INPUT_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::ISSTART_REMOTE_INPUT, data, reply); - if (ret) { - result = reply.ReadInt32(); - } - return result; -} - int32_t DistributedInputSourceProxy::RegisterAddWhiteListCallback(sptr addWhiteListCallback) { if (addWhiteListCallback == nullptr) { diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index bf3482f..774b98b 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -262,18 +262,6 @@ int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel return DH_SUCCESS; } -int32_t DistributedInputSourceStub::HandleIsStartDistributedInput(MessageParcel &data, MessageParcel &reply) -{ - uint32_t inputType = data.ReadUint32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - int32_t ret = IsStartDistributedInput(inputType, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub isStartDistributedInput write ret failed"); - return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; - } - return DH_SUCCESS; -} - int32_t DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply) { std::string userDevId = data.ReadString(); @@ -439,9 +427,6 @@ int32_t DistributedInputSourceStub::OnRemoteRequest( 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); - } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp b/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp new file mode 100644 index 0000000..b28b678 --- /dev/null +++ b/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp @@ -0,0 +1,96 @@ +/* + * 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 "sharing_dhid_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 { +SharingDhIdListenerProxy::SharingDhIdListenerProxy(const sptr &object) + : IRemoteProxy(object) +{ +} + +SharingDhIdListenerProxy::~SharingDhIdListenerProxy() {} + +int32_t SharingDhIdListenerProxy::OnSharing(std::string dhId) +{ + int32_t result = ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("SharingDhIdListenerProxy get remote failed"); + return result; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("SharingDhIdListenerProxy write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteString(dhId)) { + DHLOGE("SharingDhIdListenerProxy write dhId failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + int32_t ret = + remote->SendRequest(static_cast(ISharingDhIdListener::Message::SHARING), data, reply, option); + if (ret == DH_SUCCESS) { + result = reply.ReadInt32(); + } else { + DHLOGE("SharingDhIdListenerProxy SendRequest error: %d", ret); + } + return result; +} + +int32_t SharingDhIdListenerProxy::OnNoSharing(std::string dhId) +{ + int32_t result = ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("SharingDhIdListenerProxy get remote failed"); + return result; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + DHLOGE("SharingDhIdListenerProxy write token valid failed"); + return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; + } + if (!data.WriteString(dhId)) { + DHLOGE("SharingDhIdListenerProxy write dhId failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + + int32_t ret = + remote->SendRequest(static_cast(ISharingDhIdListener::Message::NO_SHARING), data, reply, option); + if (ret == DH_SUCCESS) { + result = reply.ReadInt32(); + } else { + DHLOGE("SharingDhIdListenerProxy SendRequest error: %d", ret); + } + return result; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/ipc/src/start_d_input_server_call_back_stub.cpp b/interfaces/ipc/src/sharing_dhid_listener_stub.cpp similarity index 52% rename from interfaces/ipc/src/start_d_input_server_call_back_stub.cpp rename to interfaces/ipc/src/sharing_dhid_listener_stub.cpp index 2495f50..e5ed558 100644 --- a/interfaces/ipc/src/start_d_input_server_call_back_stub.cpp +++ b/interfaces/ipc/src/sharing_dhid_listener_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "start_d_input_server_call_back_stub.h" +#include "sharing_dhid_listener_stub.h" #include "distributed_hardware_log.h" #include "string_ex.h" @@ -24,27 +24,35 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -StartDInputServerCallbackStub::StartDInputServerCallbackStub() -{ -} +SharingDhIdListenerStub::SharingDhIdListenerStub() {} -StartDInputServerCallbackStub::~StartDInputServerCallbackStub() -{ -} +SharingDhIdListenerStub::~SharingDhIdListenerStub() {} -int32_t StartDInputServerCallbackStub::OnRemoteRequest( +int32_t SharingDhIdListenerStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { if (data.ReadInterfaceToken() != GetDescriptor()) { - DHLOGE("StartDInputServerCallbackStub read token valid failed"); + DHLOGE("SharingDhIdListenerStub read token valid failed"); return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL; } - IStartDInputServerCallback::Message msgCode = static_cast(code); + ISharingDhIdListener::Message msgCode = static_cast(code); switch (msgCode) { - case IStartDInputServerCallback::Message::RESULT: { - int32_t status = data.ReadInt32(); - uint32_t inputTypes = data.ReadUint32(); - OnResult(status, inputTypes); + case ISharingDhIdListener::Message::SHARING: { + std::string dhId = data.ReadString(); + int32_t ret = OnSharing(dhId); + if (!reply.WriteInt32(ret)) { + DHLOGE("SharingDhIdListenerStub write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } + break; + } + case ISharingDhIdListener::Message::NO_SHARING: { + std::string dhId = data.ReadString(); + int32_t ret = OnNoSharing(dhId); + if (!reply.WriteInt32(ret)) { + DHLOGE("SharingDhIdListenerStub write ret failed"); + return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; + } break; } default: diff --git a/interfaces/ipc/src/simulation_event_listener_stub.cpp b/interfaces/ipc/src/simulation_event_listener_stub.cpp index 5287b94..2a208dc 100644 --- a/interfaces/ipc/src/simulation_event_listener_stub.cpp +++ b/interfaces/ipc/src/simulation_event_listener_stub.cpp @@ -43,7 +43,7 @@ int32_t SimulationEventListenerStub::OnRemoteRequest( int32_t eventValue = data.ReadInt32(); int32_t ret = OnSimulationEvent(eventType, eventCode, eventValue); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub write ret failed"); + DHLOGE("SimulationEventListenerStub write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } break; diff --git a/interfaces/ipc/src/start_d_input_server_call_back_proxy.cpp b/interfaces/ipc/src/start_d_input_server_call_back_proxy.cpp deleted file mode 100644 index 3b718da..0000000 --- a/interfaces/ipc/src/start_d_input_server_call_back_proxy.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "start_d_input_server_call_back_proxy.h" - -#include "distributed_hardware_log.h" -#include "ipc_types.h" -#include "parcel.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StartDInputServerCallbackProxy::StartDInputServerCallbackProxy(const sptr &object) - : IRemoteProxy(object) -{ -} - -StartDInputServerCallbackProxy::~StartDInputServerCallbackProxy() -{ -} - -void StartDInputServerCallbackProxy::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - sptr remote = Remote(); - if (remote == nullptr) { - return; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("StartDInputServerCallbackProxy write token valid failed"); - return; - } - if (!data.WriteInt32(status)) { - DHLOGE("StartDInputServerCallbackProxy write status failed"); - return; - } - if (!data.WriteUint32(inputTypes)) { - DHLOGE("StartDInputServerCallbackProxy write inputTypes failed"); - return; - } - int32_t ret = remote->SendRequest( - static_cast(IStartDInputServerCallback::Message::RESULT), data, reply, option); - if (ret != 0) { - return; - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/sink/inputcollector/BUILD.gn b/services/sink/inputcollector/BUILD.gn index 9f48d20..85de338 100755 --- a/services/sink/inputcollector/BUILD.gn +++ b/services/sink/inputcollector/BUILD.gn @@ -21,6 +21,7 @@ ohos_shared_library("libdinput_collector") { "${common_path}/include", "//commonlibrary/c_utils/base/include", "//utils/system/safwk/native/include", + "${frameworks_path}/include", "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 0403fae..eeff682 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -25,9 +25,11 @@ #include #include "event_handler.h" +#include "refbase.h" #include "constants_dinput.h" #include "input_hub.h" +#include "i_sharing_dhid_listener.h" namespace OHOS { namespace DistributedHardware { @@ -37,11 +39,12 @@ public: static DistributedInputCollector &GetInstance(); int32_t Init(std::shared_ptr sinkHandler); void Release(); - void SetSharingTypes(const uint32_t &inputType); + void SetSharingTypes(bool enabled, const uint32_t &inputType); void SetSharingDhIds(bool enabled, std::vector dhIds); void GetMouseNodePath(std::vector dhIds, std::string &mouseNodePath, std::string &dhid); // false for sharing device exist, true for all devices stop sharing bool IsAllDevicesStoped(); + int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener); private: DistributedInputCollector(); @@ -51,6 +54,7 @@ private: static void *CollectEventsThread(void *param); void StartCollectEventsThread(); void StopCollectEventsThread(); + void ReportDhIdSharingState(const AffectDhIds &dhIds); RawEvent mEventBuffer[INPUT_EVENT_BUFFER_SIZE]; pthread_t collectThreadID_; @@ -59,6 +63,9 @@ private: std::unique_ptr inputHub_; std::shared_ptr sinkHandler_; uint32_t inputTypes_; + + std::mutex sharingDhIdListenerMtx_; + sptr sharingDhIdListener_ = nullptr; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 008114d..8980f5c 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -140,10 +140,11 @@ void DistributedInputCollector::StopCollectEventsThread() DHLOGW("DistributedInputCollector::StopCollectEventsThread exit!"); } -void DistributedInputCollector::SetSharingTypes(const uint32_t &inputType) +void DistributedInputCollector::SetSharingTypes(bool enabled, const uint32_t &inputType) { inputTypes_ = 0; - if ((inputType & static_cast(DInputDeviceType::MOUSE)) != 0) { + if ((inputType & static_cast(DInputDeviceType::MOUSE)) != 0 || + (inputType & static_cast(DInputDeviceType::TOUCHPAD)) != 0) { inputTypes_ |= INPUT_DEVICE_CLASS_CURSOR; } if ((inputType & static_cast(DInputDeviceType::KEYBOARD)) != 0) { @@ -153,7 +154,27 @@ void DistributedInputCollector::SetSharingTypes(const uint32_t &inputType) inputTypes_ |= INPUT_DEVICE_CLASS_TOUCH_MT | INPUT_DEVICE_CLASS_TOUCH; } - inputHub_->SetSupportInputType(inputTypes_); + AffectDhIds dhIds = inputHub_->SetSupportInputType(enabled, inputTypes_); + ReportDhIdSharingState(dhIds); +} + +void DistributedInputCollector::ReportDhIdSharingState(const AffectDhIds &dhIds) +{ + std::lock_guard lock(sharingDhIdListenerMtx_); + if (sharingDhIdListener_ == nullptr) { + DHLOGI("sharingDhIdListener_ is null, can not report sharing dhid"); + return; + } + + for (auto const &id : dhIds.sharingDhIds) { + DHLOGI("Sharing DhId: %s", id.c_str()); + sharingDhIdListener_->OnSharing(id); + } + + for (auto const &id : dhIds.noSharingDhIds) { + DHLOGI("No Sharing DhId: %s", id.c_str()); + sharingDhIdListener_->OnNoSharing(id); + } } void DistributedInputCollector::Release() @@ -163,7 +184,8 @@ void DistributedInputCollector::Release() void DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector dhIds) { - inputHub_->SetSharingDevices(enabled, dhIds); + AffectDhIds affdhIds = inputHub_->SetSharingDevices(enabled, dhIds); + ReportDhIdSharingState(affdhIds); } void DistributedInputCollector::GetMouseNodePath( @@ -176,6 +198,14 @@ bool DistributedInputCollector::IsAllDevicesStoped() { return inputHub_->IsAllDevicesStoped(); } + +int32_t DistributedInputCollector::RegisterSharingDhIdListener(sptr sharingDhIdListener) +{ + DHLOGI("RegisterSharingDhIdListener"); + std::lock_guard lock(sharingDhIdListenerMtx_); + sharingDhIdListener_ = sharingDhIdListener; + return DH_SUCCESS; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index 2c6b510..5694a15 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -46,8 +46,6 @@ ohos_shared_library("libdinput_sink") { sources = [ "${common_path}/include/white_list_util.cpp", "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", "src/distributed_input_sink_event_handler.cpp", "src/distributed_input_sink_manager.cpp", ] diff --git a/services/sink/sinkmanager/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h index 22a19d5..eab7a9c 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -97,11 +97,6 @@ public: virtual int32_t Release() override; - virtual int32_t IsStartDistributedInput( - const uint32_t& inputType, sptr callback) override; - - IStartDInputServerCallback* GetStartDInputServerCback(); - DInputServerType GetStartTransFlag(); void SetStartTransFlag(const DInputServerType flag); @@ -121,6 +116,8 @@ public: int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override; + int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener) override; + int32_t Dump(int32_t fd, const std::vector& args) override; private: @@ -130,7 +127,6 @@ private: ServiceSinkRunningState serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE; std::shared_ptr statuslistener_; - sptr startServerCallback_ = nullptr; std::shared_ptr runner_; std::shared_ptr handler_; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 8fa0f07..5678b00 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -156,15 +156,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( // add the input type if (startRes == DH_SUCCESS) { sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes); - DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes()); - } - - IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("onStartRemoteInput called, startServerCB is null."); - } else { - startServerCB->OnResult( - static_cast(sinkManagerObj_->GetStartTransFlag()), sinkManagerObj_->GetInputTypes()); + DistributedInputCollector::GetInstance().SetSharingTypes(true, sinkManagerObj_->GetInputTypes()); } } @@ -176,7 +168,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - (sinkManagerObj_->GetInputTypes() & inputTypes)); - DistributedInputCollector::GetInstance().SetSharingTypes(sinkManagerObj_->GetInputTypes()); + DistributedInputCollector::GetInstance().SetSharingTypes(false, inputTypes); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; @@ -194,14 +186,6 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( sinkManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); } } - - IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("startServerCB is null."); - } else { - startServerCB->OnResult( - static_cast(sinkManagerObj_->GetStartTransFlag()), sinkManagerObj_->GetInputTypes()); - } } void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInputDhid(const int32_t &sessionId, @@ -518,13 +502,6 @@ int32_t DistributedInputSinkManager::Release() // 3.notify callback servertype SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); - IStartDInputServerCallback *startServerCB = GetStartDInputServerCback(); - if (startServerCB == nullptr) { - DHLOGE("Release() called, startServerCB is null."); - } else { - startServerCB->OnResult(0, 0); - } - // 4.Release input collect resource DistributedInputCollector::GetInstance().Release(); @@ -540,28 +517,6 @@ int32_t DistributedInputSinkManager::Release() return DH_SUCCESS; } -int32_t DistributedInputSinkManager::IsStartDistributedInput( - const uint32_t& inputType, sptr callback) -{ - if (callback != nullptr) { - startServerCallback_ = callback; - if (GetStartTransFlag() != DInputServerType::NULL_SERVER_TYPE) { - startServerCallback_->OnResult(static_cast(GetStartTransFlag()), GetInputTypes()); - } - } - - if (inputType & GetInputTypes()) { - return static_cast(isStartTrans_); - } else { - return static_cast(DInputServerType::NULL_SERVER_TYPE); - } -} - -IStartDInputServerCallback* DistributedInputSinkManager::GetStartDInputServerCback() -{ - return startServerCallback_; -} - DInputServerType DistributedInputSinkManager::GetStartTransFlag() { return isStartTrans_; @@ -754,6 +709,13 @@ int32_t DistributedInputSinkManager::NotifyStopDScreen(const std::string& srcScr return DInputContext::GetInstance().RemoveSinkScreenInfo(srcScreenInfoKey); } +int32_t DistributedInputSinkManager::RegisterSharingDhIdListener(sptr sharingDhIdListener) +{ + DHLOGI("RegisterSharingDhIdListener"); + DistributedInputCollector::GetInstance().RegisterSharingDhIdListener(sharingDhIdListener); + return DH_SUCCESS; +} + int32_t DistributedInputSinkManager::Dump(int32_t fd, const std::vector& args) { DHLOGI("DistributedInputSinkManager Dump."); diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn index 9db2c3f..82427ee 100755 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn @@ -58,8 +58,6 @@ ohos_unittest("distributed_input_sinkmanager_test") { "${common_path}/include/input_hub.cpp", "${common_path}/include/white_list_util.cpp", "${ipc_path}/src/distributed_input_sink_stub.cpp", - "${ipc_path}/src/start_d_input_server_call_back_proxy.cpp", - "${ipc_path}/src/start_d_input_server_call_back_stub.cpp", "${services_sink_path}/inputcollector/src/distributed_input_collector.cpp", "//foundation/distributedhardware/distributed_input/services/sink/sinkmanager/src/distributed_input_sink_event_handler.cpp", "//foundation/distributedhardware/distributed_input/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp", diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index f7058b2..0fb96f7 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -61,8 +61,6 @@ ohos_shared_library("libdinput_source") { "${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_d_input_server_call_back_proxy.cpp", - "${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", @@ -71,6 +69,8 @@ ohos_shared_library("libdinput_source") { "${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/sharing_dhid_listener_proxy.cpp", + "${ipc_path}/src/sharing_dhid_listener_stub.cpp", "${ipc_path}/src/simulation_event_listener_proxy.cpp", "${ipc_path}/src/simulation_event_listener_stub.cpp", "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", diff --git a/services/source/sourcemanager/include/distributed_input_source_manager.h b/services/source/sourcemanager/include/distributed_input_source_manager.h index 5cd3f32..970c706 100644 --- a/services/source/sourcemanager/include/distributed_input_source_manager.h +++ b/services/source/sourcemanager/include/distributed_input_source_manager.h @@ -155,8 +155,6 @@ public: 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; @@ -275,7 +273,6 @@ public: 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); std::vector GetInputDeviceId(); @@ -353,7 +350,6 @@ private: std::vector unpreCallbacks_; std::vector staCallbacks_; std::vector stpCallbacks_; - sptr startServerCallback_ = nullptr; std::vector staStringCallbacks_; std::vector stpStringCallbacks_; diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 8d91821..8d1fa52 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -495,13 +495,6 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart } sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ? DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult( - static_cast(sourceManagerObj_->GetStartTransFlag()), - sourceManagerObj_->GetAllInputTypesMap()); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() or is null."); - } sourceManagerObj_->RunStartCallback(deviceId, inputTypes, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD); } @@ -534,13 +527,6 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopC DHLOGI("All Dev Switch Off"); sourceManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); } - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult( - static_cast(sourceManagerObj_->GetStartTransFlag()), - sourceManagerObj_->GetAllInputTypesMap()); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() is null."); - } sourceManagerObj_->RunStopCallback(deviceId, inputTypes, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD); } @@ -605,13 +591,6 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; DInputServerType startTransFlag = DInputServerType(serType); sourceManagerObj_->SetStartTransFlag(startTransFlag); - - if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { - sourceManagerObj_->GetStartDInputServerCback()->OnResult( - serType, static_cast(DInputDeviceType::NONE)); - } else { - DHLOGE("ProcessEvent GetStartDInputServerCback() is null."); - } } void DistributedInputSourceManager::DInputSourceManagerEventHandler::ProcessEvent( @@ -1690,24 +1669,6 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, return DH_SUCCESS; } -int32_t DistributedInputSourceManager::IsStartDistributedInput( - const uint32_t& inputType, sptr callback) -{ - if (callback != nullptr) { - startServerCallback_ = callback; - if (GetStartTransFlag() != DInputServerType::NULL_SERVER_TYPE) { - startServerCallback_->OnResult(static_cast(GetStartTransFlag()), GetAllInputTypesMap()); - } - } - - DHLOGI("param inputType: %d, allInputTypes: %d", inputType, GetAllInputTypesMap()); - if (inputType & GetAllInputTypesMap()) { - return static_cast(isStartTrans_); - } else { - return static_cast(DInputServerType::NULL_SERVER_TYPE); - } -} - int32_t DistributedInputSourceManager::RegisterAddWhiteListCallback(sptr callback) { DHLOGI("RegisterAddWhiteListCallback called."); @@ -2090,11 +2051,6 @@ void DistributedInputSourceManager::StringSplitToVector(const std::string &str, } } -IStartDInputServerCallback* DistributedInputSourceManager::GetStartDInputServerCback() -{ - return startServerCallback_; -} - DInputServerType DistributedInputSourceManager::GetStartTransFlag() { return isStartTrans_; diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 2c8ba51..efb6c27 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -73,8 +73,6 @@ ohos_unittest("distributed_input_sourcemanager_test") { "${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_d_input_server_call_back_proxy.cpp", - "${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/unprepare_d_input_call_back_proxy.cpp", diff --git a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp index 930c5eb..af18f2e 100644 --- a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -61,20 +61,6 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( } } -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = DInputDeviceType::NONE; - } -} - void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) { nlohmann::json inputData = nlohmann::json::parse(strJson); @@ -150,11 +136,6 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const return true; } -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) -{ - return serverType; -} - bool DistributedInputClient::IsJsonData(std::string strData) const { return true; diff --git a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp index 6857955..d369f1e 100644 --- a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -61,20 +61,6 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( } } -void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes) -{ - if (DInputServerType::SOURCE_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else if (DInputServerType::SINK_SERVER_TYPE == static_cast(status)) { - DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = static_cast(inputTypes); - } else { - DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE; - DistributedInputClient::GetInstance().inputTypes_ = DInputDeviceType::NONE; - } -} - void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) { nlohmann::json inputData = nlohmann::json::parse(strJson); @@ -150,11 +136,6 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const return true; } -DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType) -{ - return serverType; -} - bool DistributedInputClient::IsJsonData(std::string strData) const { return true;