diff --git a/common/include/dinput_ipc_interface_code.h b/common/include/dinput_ipc_interface_code.h index e503c2c79ab0b86d610e31383de7eb1b2a8c4620..be71e68c37aad4a43d2b186a78442b961ee8eda5 100644 --- a/common/include/dinput_ipc_interface_code.h +++ b/common/include/dinput_ipc_interface_code.h @@ -21,13 +21,30 @@ namespace OHOS { namespace DistributedHardware { /* SAID: 4809 */ -enum class IAddWhiteListInfosCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class IDelWhiteListInfosCBInterfaceCode : uint32_t { - RESULT = 0 +enum class IDInputSourceInterfaceCode : uint32_t { + INIT = 0xf001U, + RELEASE = 0xf002U, + REGISTER_REMOTE_INPUT = 0xf003U, + UNREGISTER_REMOTE_INPUT = 0xf004U, + PREPARE_REMOTE_INPUT = 0xf005U, + UNPREPARE_REMOTE_INPUT = 0xf006U, + START_REMOTE_INPUT = 0xf007U, + STOP_REMOTE_INPUT = 0xf008U, + PREPARE_RELAY_REMOTE_INPUT = 0xf00aU, + UNPREPARE_RELAY_REMOTE_INPUT = 0xf00bU, + START_RELAY_TYPE_REMOTE_INPUT = 0xf00cU, + STOP_RELAY_TYPE_REMOTE_INPUT = 0xf00dU, + START_DHID_REMOTE_INPUT = 0xf00eU, + STOP_DHID_REMOTE_INPUT = 0xf00fU, + START_RELAY_DHID_REMOTE_INPUT = 0xf010U, + STOP_RELAY_DHID_REMOTE_INPUT = 0xf011U, + REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT = 0xf013U, + REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT = 0xf014U, + REGISTER_NODE_LISTENER = 0xf015U, + UNREGISTER_NODE_LISTENER = 0xf016U, + REGISTER_SIMULATION_EVENT_LISTENER = 0xf017U, + UNREGISTER_SIMULATION_EVENT_LISTENER = 0xf018U, + SYNC_NODE_INFO_REMOTE_INPUT = 0xf019U, }; /* SAID: 4810 */ @@ -39,96 +56,6 @@ enum class IDInputSinkInterfaceCode : uint32_t { REGISTER_SHARING_DHID_LISTENER = 0xf015U, GET_SINK_SCREEN_INFOS = 0xf016U, }; - -/* SAID: 4809 */ -enum class IDInputSourceInterfaceCode : uint32_t { - INIT = 0xf001, - RELEASE = 0xf002, - REGISTER_REMOTE_INPUT = 0xf003, - UNREGISTER_REMOTE_INPUT = 0xf004, - PREPARE_REMOTE_INPUT = 0xf005, - UNPREPARE_REMOTE_INPUT = 0xf006, - START_REMOTE_INPUT = 0xf007, - STOP_REMOTE_INPUT = 0xf008, - 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, -}; - -/* SAID: 4810 */ -enum class IGetSinkScreenInfosCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4810 */ -enum class InputNodeListenerInterfaceCode : uint32_t { - RESULT_ON = 0, - RESULT_OFF = 1 -}; - -/* SAID: 4809 */ -enum class IPrepareDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class IRegisterDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class ISharingDhIdListenerInterfaceCode : uint32_t { - SHARING = 0, - NO_SHARING = 1 -}; - -/* SAID: 4809 */ -enum class ISimulationEventListenerInterfaceCode : uint32_t { - RESULT_ON = 0 -}; - -/* SAID: 4809 */ -enum class IStartDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class IStartStopDInputsCBInterfaceCode : uint32_t { - RESULT_STRING = 0 -}; - -/* SAID: 4809 */ -enum class IStartStopResultCBInterfaceCode : uint32_t { - RESULT_START = 0, - RESULT_STOP = 1 -}; - -/* SAID: 4809 */ -enum class IStopDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class IUnprepareDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; - -/* SAID: 4809 */ -enum class IUnregisterDInputCBInterfaceCode : uint32_t { - RESULT = 0 -}; } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index f718615d1ccf48df93288d250f62fa49f43938f6..8b81788c441aa297128cf341377f62671fde7727 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -64,14 +64,16 @@ WhiteListUtil &WhiteListUtil::GetInstance(void) int32_t WhiteListUtil::Init() { char buf[MAX_PATH_LEN] = {0}; + char path[PATH_MAX + 1] = {0x00}; char *whiteListFilePath = GetOneCfgFile(WHITELIST_FILE_PATH, buf, MAX_PATH_LEN); - if (whiteListFilePath == nullptr) { - DHLOGE("WhiteListFilePath is null!"); - return ERR_DH_INPUT_WHILTELIST_FILE_PATH_IS_NULL; + if (strlen(whiteListFilePath) == 0 || strlen(whiteListFilePath) > PATH_MAX || + realpath(whiteListFilePath, path) == nullptr) { + DHLOGE("File connicailization failed."); + return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } - std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary); + std::ifstream inFile(path, std::ios::in | std::ios::binary); if (!inFile.is_open()) { - DHLOGE("WhiteListUtil Init error, file open fail path=%s", whiteListFilePath); + DHLOGE("WhiteListUtil Init error, file open fail path=%s", path); return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } diff --git a/frameworks/include/i_distributed_sink_input.h b/frameworks/include/i_distributed_sink_input.h index fbc8f03d75afce5f561ee074f9d4c9caf2882b3d..733fb7b0c7606abdc3fdcf0253197e447a09ff83 100644 --- a/frameworks/include/i_distributed_sink_input.h +++ b/frameworks/include/i_distributed_sink_input.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -53,15 +53,6 @@ public: virtual int32_t NotifyStopDScreen(const std::string &srcScreenInfoKey) = 0; virtual int32_t RegisterSharingDhIdListener(sptr sharingDhIdListener) = 0; - - enum { - INIT = 0xf011U, - RELEASE = 0xf012U, - NOTIFY_START_DSCREEN = 0xf013U, - NOTIFY_STOP_DSCREEN = 0xf014U, - REGISTER_SHARING_DHID_LISTENER = 0xf015U, - GET_SINK_SCREEN_INFOS = 0xf016U, - }; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index 7e6ea62d029a52b9f3ef49403010c91407f79e3d..f84f87c3d4db4b4ba40ea812c52eff065893d38b 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -98,32 +98,6 @@ public: 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, - REGISTER_REMOTE_INPUT = 0xf003, - UNREGISTER_REMOTE_INPUT = 0xf004, - PREPARE_REMOTE_INPUT = 0xf005, - UNPREPARE_REMOTE_INPUT = 0xf006, - START_REMOTE_INPUT = 0xf007, - STOP_REMOTE_INPUT = 0xf008, - 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 } // namespace DistributedHardware diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index 4855fe4c10188fbeaccd27d22b863a4f673685da..a602e636e47483a9094fd4e30ac5b4d1c30a837d 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -85,7 +85,7 @@ public: int32_t UnregisterSimulationEventListener(sptr listener) override; private: - bool SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply); + bool SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; }; diff --git a/interfaces/ipc/src/add_white_list_infos_call_back_proxy.cpp b/interfaces/ipc/src/add_white_list_infos_call_back_proxy.cpp index 759dea0ac913a2b1c8b327076b9a773da22282ce..9ec62470d86fc51d01a4e18b14637c31d074de11 100644 --- a/interfaces/ipc/src/add_white_list_infos_call_back_proxy.cpp +++ b/interfaces/ipc/src/add_white_list_infos_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -54,7 +54,7 @@ void AddWhiteListInfosCallbackProxy::OnResult(const std::string& deviceId, const DHLOGE("AddWhiteListInfosCallbackProxy write strJson failed"); return; } - remote->SendRequest(static_cast(IAddWhiteListInfosCallback::Message::RESULT), data, reply, option); + remote->SendRequest(static_cast(IAddWhiteListInfosCallback::Message::RESULT), data, reply, option); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/del_white_list_infos_call_back_proxy.cpp b/interfaces/ipc/src/del_white_list_infos_call_back_proxy.cpp index ca978e5131c702c4bfd631ea0f1716c92a909dcf..4b1f7156af7fc6426074e5fcf9d7fc7e7ed1221c 100644 --- a/interfaces/ipc/src/del_white_list_infos_call_back_proxy.cpp +++ b/interfaces/ipc/src/del_white_list_infos_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -50,7 +50,7 @@ void DelWhiteListInfosCallbackProxy::OnResult(const std::string& deviceId) DHLOGE("DelWhiteListInfosCallbackProxy write deviceId failed"); return; } - remote->SendRequest(static_cast(IDelWhiteListInfosCallback::Message::RESULT), data, reply, option); + remote->SendRequest(static_cast(IDelWhiteListInfosCallback::Message::RESULT), data, reply, option); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/distributed_input_sink_proxy.cpp b/interfaces/ipc/src/distributed_input_sink_proxy.cpp index 7a435b5393619cdfa6f1945b0142064aaa765ef3..4d4cce9eb61db5302efed66d52561b2e83e786dc 100644 --- a/interfaces/ipc/src/distributed_input_sink_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_sink_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,6 +18,7 @@ #include "anonymous_string.h" #include "dinput_errcode.h" +#include "dinput_ipc_interface_code.h" #include "dinput_log.h" #include "dinput_utils_tool.h" #include "i_get_sink_screen_infos_call_back.h" @@ -41,7 +42,7 @@ int32_t DistributedInputSinkProxy::Init() return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t result = ERR_DH_INPUT_SINK_PROXY_INIT_FAIL; - bool ret = SendRequest(INIT, data, reply); + bool ret = SendRequest(static_cast(IDInputSinkInterfaceCode::INIT), data, reply); if (!ret) { DHLOGE("SendRequest fail!"); return ERR_DH_INPUT_SINK_PROXY_INIT_FAIL; @@ -59,7 +60,7 @@ int32_t DistributedInputSinkProxy::Release() return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t result = ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL; - bool ret = SendRequest(RELEASE, data, reply); + bool ret = SendRequest(static_cast(IDInputSinkInterfaceCode::RELEASE), data, reply); if (!ret) { DHLOGE("SendRequest fail!"); return ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL; @@ -85,7 +86,7 @@ int32_t DistributedInputSinkProxy::RegisterGetSinkScreenInfosCallback(sptr(IDInputSinkInterfaceCode::GET_SINK_SCREEN_INFOS), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -114,7 +115,7 @@ int32_t DistributedInputSinkProxy::NotifyStartDScreen(const SrcScreenInfo &remot return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t result = ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL; - bool ret = SendRequest(NOTIFY_START_DSCREEN, data, reply); + bool ret = SendRequest(static_cast(IDInputSinkInterfaceCode::NOTIFY_START_DSCREEN), data, reply); if (!ret) { DHLOGE("SendRequest fail!"); return ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL; @@ -136,7 +137,7 @@ int32_t DistributedInputSinkProxy::NotifyStopDScreen(const std::string &srcScree return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t result = ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL; - bool ret = SendRequest(NOTIFY_STOP_DSCREEN, data, reply); + bool ret = SendRequest(static_cast(IDInputSinkInterfaceCode::NOTIFY_STOP_DSCREEN), data, reply); if (!ret) { DHLOGE("SendRequest fail!"); return ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL; @@ -159,7 +160,8 @@ int32_t DistributedInputSinkProxy::RegisterSharingDhIdListener(sptr(IDInputSinkInterfaceCode::REGISTER_SHARING_DHID_LISTENER), + data, reply); if (ret) { result = reply.ReadInt32(); } diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index 28ff50687baaab782d68b28ec1c429f55dfa7270..7dfca9610aaa447f14a0ec81e1176962a05863e2 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -19,6 +19,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" +#include "dinput_ipc_interface_code.h" #include "dinput_log.h" #include "i_sharing_dhid_listener.h" @@ -28,12 +29,18 @@ namespace DistributedInput { DistributedInputSinkStub::DistributedInputSinkStub() { DHLOGI("DistributedInputSinkStub ctor!"); - memberFuncMap_[INIT] = &DistributedInputSinkStub::InitInner; - memberFuncMap_[RELEASE] = &DistributedInputSinkStub::ReleaseInner; - memberFuncMap_[NOTIFY_START_DSCREEN] = &DistributedInputSinkStub::NotifyStartDScreenInner; - memberFuncMap_[NOTIFY_STOP_DSCREEN] = &DistributedInputSinkStub::NotifyStopDScreenInner; - memberFuncMap_[REGISTER_SHARING_DHID_LISTENER] = &DistributedInputSinkStub::RegisterSharingDhIdListenerInner; - memberFuncMap_[GET_SINK_SCREEN_INFOS] = &DistributedInputSinkStub::RegisterGetSinkScreenInfosInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::INIT)] = + &DistributedInputSinkStub::InitInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::RELEASE)] = + &DistributedInputSinkStub::ReleaseInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::NOTIFY_START_DSCREEN)] = + &DistributedInputSinkStub::NotifyStartDScreenInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::NOTIFY_STOP_DSCREEN)] = + &DistributedInputSinkStub::NotifyStopDScreenInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::REGISTER_SHARING_DHID_LISTENER)] = + &DistributedInputSinkStub::RegisterSharingDhIdListenerInner; + memberFuncMap_[static_cast(IDInputSinkInterfaceCode::GET_SINK_SCREEN_INFOS)] = + &DistributedInputSinkStub::RegisterGetSinkScreenInfosInner; } DistributedInputSinkStub::~DistributedInputSinkStub() diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index 25e95b3ef4430381f2d81594ff2664497854de6c..30981af84625eb982d0e9414b1d338b1755ae76b 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,7 @@ #include "distributed_input_source_proxy.h" #include "dinput_errcode.h" +#include "dinput_ipc_interface_code.h" #include "dinput_log.h" namespace OHOS { @@ -37,7 +38,7 @@ int32_t DistributedInputSourceProxy::Init() return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t result = ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::INIT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::INIT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -53,7 +54,7 @@ int32_t DistributedInputSourceProxy::Release() DHLOGE("DistributedInputSourceProxy write token valid failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } - bool ret = SendRequest(IDistributedSourceInput::MessageCode::RELEASE, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::RELEASE), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -86,7 +87,7 @@ int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::stri } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::REGISTER_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -115,7 +116,7 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNREGISTER_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -141,7 +142,7 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput( MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::PREPARE_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -167,7 +168,7 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &dev } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNPREPARE_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -198,7 +199,7 @@ int32_t DistributedInputSourceProxy::StartRemoteInput( } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -228,7 +229,7 @@ int32_t DistributedInputSourceProxy::StopRemoteInput( } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -262,7 +263,8 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string& srcId, } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_RELAY_TYPE_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT), data, + reply); if (ret) { result = reply.ReadInt32(); } @@ -296,7 +298,8 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string& srcId, c } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_RELAY_TYPE_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -326,7 +329,7 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -356,7 +359,8 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &src } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -394,7 +398,7 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -432,7 +436,7 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT), data, reply); if (ret) { result = reply.ReadInt32(); } @@ -474,7 +478,8 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -516,7 +521,8 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, c } MessageParcel reply; int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL; - bool ret = SendRequest(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT, data, reply); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -541,7 +547,8 @@ int32_t DistributedInputSourceProxy::RegisterAddWhiteListCallback(sptr(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -565,7 +572,8 @@ int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -586,7 +594,8 @@ int32_t DistributedInputSourceProxy::RegisterInputNodeListener(sptr(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -608,7 +617,8 @@ int32_t DistributedInputSourceProxy::UnregisterInputNodeListener(sptr(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -637,7 +647,8 @@ int32_t DistributedInputSourceProxy::SyncNodeInfoRemoteInput(const std::string & } 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); + bool ret = SendRequest(static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -660,7 +671,8 @@ int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER), + data, reply); if (ret) { result = reply.ReadInt32(); } @@ -682,15 +694,15 @@ int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER), + data, reply); if (ret) { result = reply.ReadInt32(); } return result; } -bool DistributedInputSourceProxy::SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, - MessageParcel &reply) +bool DistributedInputSourceProxy::SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply) { sptr remote = Remote(); if (remote == nullptr) { diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 16e2fdaa0fd1ad752d3dfdb9ba8367e38ddda726..1c7ec802f135ed98e875e9e04b7fdc302096ef76 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -17,6 +17,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" +#include "dinput_ipc_interface_code.h" #include "dinput_log.h" namespace OHOS { @@ -393,73 +394,73 @@ int32_t DistributedInputSourceStub::OnRemoteRequest( return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } switch (code) { - case static_cast(IDistributedSourceInput::MessageCode::INIT): { + case static_cast(IDInputSourceInterfaceCode::INIT): { return HandleInitDistributedHardware(reply); } - case static_cast(IDistributedSourceInput::MessageCode::RELEASE): { + case static_cast(IDInputSourceInterfaceCode::RELEASE): { return HandleReleaseDistributedHardware(reply); } - case static_cast(IDistributedSourceInput::MessageCode::REGISTER_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT): { return HandleRegisterDistributedHardware(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT): { return HandleUnregisterDistributedHardware(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::PREPARE_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::PREPARE_REMOTE_INPUT): { return HandlePrepareRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::UNPREPARE_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT): { return HandleUnprepareRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::START_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::START_REMOTE_INPUT): { return HandleStartRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::STOP_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT): { return HandleStopRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::START_RELAY_TYPE_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT): { return HandleStartRelayTypeRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::STOP_RELAY_TYPE_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT): { return HandleStopRelayTypeRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::PREPARE_RELAY_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT): { return HandlePrepareRelayRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::UNPREPARE_RELAY_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT): { return HandleUnprepareRelayRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::START_DHID_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT): { return HandleStartDhidRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::STOP_DHID_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT): { return HandleStopDhidRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::START_RELAY_DHID_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT): { return HandleStartRelayDhidRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::STOP_RELAY_DHID_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT): { return HandleStopRelayDhidRemoteInput(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): { return HandleRegisterAddWhiteListCallback(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): { return HandleRegisterDelWhiteListCallback(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::REGISTER_NODE_LISTENER): { + case static_cast(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER): { return HandleRegisterInputNodeListener(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_NODE_LISTENER): { + case static_cast(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER): { return HandleUnRegisterInputNodeListener(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::REGISTER_SIMULATION_EVENT_LISTENER): { + case static_cast(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER): { return HandleRegisterSimulationEventListener(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::UNREGISTER_SIMULATION_EVENT_LISTENER): { + case static_cast(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER): { return HandleUnregisterSimulationEventListener(data, reply); } - case static_cast(IDistributedSourceInput::MessageCode::SYNC_NODE_INFO_REMOTE_INPUT): { + case static_cast(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT): { return HandleSyncNodeInfoRemoteInput(data, reply); } default: diff --git a/interfaces/ipc/src/get_sink_screen_infos_call_back_proxy.cpp b/interfaces/ipc/src/get_sink_screen_infos_call_back_proxy.cpp index c20011f13c1656a732064b81cfe30be551687650..30a77cacfb55f7e3482e5a10a770b3e190ce4d5d 100644 --- a/interfaces/ipc/src/get_sink_screen_infos_call_back_proxy.cpp +++ b/interfaces/ipc/src/get_sink_screen_infos_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -50,7 +50,7 @@ void GetSinkScreenInfosCallbackProxy::OnResult(const std::string& strJson) DHLOGE("write strJson failed"); return; } - remote->SendRequest(static_cast(IGetSinkScreenInfosCallback::Message::RESULT), data, reply, option); + remote->SendRequest(static_cast(IGetSinkScreenInfosCallback::Message::RESULT), data, reply, option); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/input_node_listener_proxy.cpp b/interfaces/ipc/src/input_node_listener_proxy.cpp index fe7c1ea2eaee67b3c25042b16a8f9b53ce2f8b61..75e3497368babce17fe2324791287dc8ee47b633 100644 --- a/interfaces/ipc/src/input_node_listener_proxy.cpp +++ b/interfaces/ipc/src/input_node_listener_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -61,7 +61,8 @@ void InputNodeListenerProxy::OnNodeOnLine(const std::string srcDevId, const std: DHLOGE("InputNodeListenerProxy write sinkNodeDesc failed"); return; } - int32_t ret = remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_ON), data, reply, option); + int32_t ret = remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_ON), data, reply, + option); if (ret != 0) { return; } @@ -94,8 +95,8 @@ void InputNodeListenerProxy::OnNodeOffLine(const std::string srcDevId, const std DHLOGE("InputNodeListenerProxy write sinkNodeId failed"); return; } - int32_t ret = - remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_OFF), data, reply, option); + int32_t ret = remote->SendRequest(static_cast(InputNodeListener::Message::RESULT_OFF), data, reply, + option); if (ret != 0) { return; } diff --git a/interfaces/ipc/src/prepare_d_input_call_back_proxy.cpp b/interfaces/ipc/src/prepare_d_input_call_back_proxy.cpp index 18b4c282bd3bf03b6b22eb4d933235174073d00d..e27c1ed23cf9f2a9131ed18f8bd7d954b1eb8044 100644 --- a/interfaces/ipc/src/prepare_d_input_call_back_proxy.cpp +++ b/interfaces/ipc/src/prepare_d_input_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -53,7 +53,7 @@ void PrepareDInputCallbackProxy::OnResult(const std::string& deviceId, const int return; } int32_t ret = remote->SendRequest( - static_cast(IPrepareDInputCallback::Message::RESULT), data, reply, option); + static_cast(IPrepareDInputCallback::Message::RESULT), data, reply, option); if (ret != 0) { return; } diff --git a/interfaces/ipc/src/register_d_input_call_back_proxy.cpp b/interfaces/ipc/src/register_d_input_call_back_proxy.cpp index 58302e64b27d0e950726a4397b3e45fdb7556f0a..92cfd458ff59170795a4a39f41c894ef079041ca 100644 --- a/interfaces/ipc/src/register_d_input_call_back_proxy.cpp +++ b/interfaces/ipc/src/register_d_input_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -56,7 +56,7 @@ void RegisterDInputCallbackProxy::OnResult(const std::string& devId, const std:: return; } int32_t ret = remote->SendRequest( - static_cast(IRegisterDInputCallback::Message::RESULT), data, reply, option); + static_cast(IRegisterDInputCallback::Message::RESULT), data, reply, option); if (ret != 0) { return; } diff --git a/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp b/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp index daabdf8e68ad2cfd519c647dc776663c5c33efd0..cca24ce377fe3c7712c38f88163b9e83082ca1a3 100644 --- a/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp +++ b/interfaces/ipc/src/sharing_dhid_listener_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -53,7 +53,7 @@ int32_t SharingDhIdListenerProxy::OnSharing(std::string dhId) } int32_t ret = - remote->SendRequest(static_cast(ISharingDhIdListener::Message::SHARING), data, reply, option); + remote->SendRequest(static_cast(ISharingDhIdListener::Message::SHARING), data, reply, option); if (ret == DH_SUCCESS) { result = reply.ReadInt32(); } else { @@ -84,7 +84,7 @@ int32_t SharingDhIdListenerProxy::OnNoSharing(std::string dhId) } int32_t ret = - remote->SendRequest(static_cast(ISharingDhIdListener::Message::NO_SHARING), data, reply, option); + remote->SendRequest(static_cast(ISharingDhIdListener::Message::NO_SHARING), data, reply, option); if (ret == DH_SUCCESS) { result = reply.ReadInt32(); } else { diff --git a/interfaces/ipc/src/simulation_event_listener_proxy.cpp b/interfaces/ipc/src/simulation_event_listener_proxy.cpp index 4412a77e46c1c524f99aa06891243a5d27180a20..3c6079ede56a9601e34c5f0719f8bb6f04bd04af 100644 --- a/interfaces/ipc/src/simulation_event_listener_proxy.cpp +++ b/interfaces/ipc/src/simulation_event_listener_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -60,7 +60,7 @@ int32_t SimulationEventListenerProxy::OnSimulationEvent(uint32_t type, uint32_t return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } int32_t ret = - remote->SendRequest(static_cast(ISimulationEventListener::Message::RESULT_ON), data, reply, option); + remote->SendRequest(static_cast(ISimulationEventListener::Message::RESULT_ON), data, reply, option); if (ret == DH_SUCCESS) { result = reply.ReadInt32(); } else { diff --git a/interfaces/ipc/src/start_d_input_call_back_proxy.cpp b/interfaces/ipc/src/start_d_input_call_back_proxy.cpp index 1384901e5388bb8703b0f3d82b0f58326a47b52e..de77a25e0fe5263d09b898692d8bb5f57e5c00ba 100644 --- a/interfaces/ipc/src/start_d_input_call_back_proxy.cpp +++ b/interfaces/ipc/src/start_d_input_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -59,7 +59,7 @@ void StartDInputCallbackProxy::OnResult(const std::string& devId, const uint32_t return; } int32_t ret = remote->SendRequest( - static_cast(IStartDInputCallback::Message::RESULT), data, reply, option); + static_cast(IStartDInputCallback::Message::RESULT), data, reply, option); if (ret != 0) { return; } 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 index d2a40878c51521ffaa7115e24c55dec3a5a1669b..6660f5242e0b49389e45bfd0b166b18fb86e99ef 100644 --- a/interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp +++ b/interfaces/ipc/src/start_stop_d_inputs_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -52,7 +52,7 @@ void StartStopDInputsCallbackProxy::OnResultDhids(const std::string &devId, cons DHLOGE("StartStopDInputsCallbackProxy write status valid failed"); return; } - int32_t ret = remote->SendRequest(static_cast(IStartStopDInputsCallback::Message::RESULT_STRING), + int32_t ret = remote->SendRequest(static_cast(IStartStopDInputsCallback::Message::RESULT_STRING), data, reply, option); if (ret != 0) { DHLOGE("OnResultDhids error, ret = %d", ret); diff --git a/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp b/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp index 8307480b79806f17d26b12dd798f34b7b2eb56c5..c0bb5e4edc6a0ef10dc1bb8eda5a18a7a66d28d1 100644 --- a/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp +++ b/interfaces/ipc/src/start_stop_result_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -66,8 +66,8 @@ void StartStopResultCallbackProxy::OnStart( } } - int32_t ret = - remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_START), data, reply, option); + int32_t ret = remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_START), data, + reply, option); if (ret != 0) { DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret); return; @@ -111,8 +111,8 @@ void StartStopResultCallbackProxy::OnStop( } } - int32_t ret = - remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_STOP), data, reply, option); + int32_t ret = remote->SendRequest(static_cast(IStartStopResultCallback::Message::RESULT_STOP), data, + reply, option); if (ret != 0) { DHLOGE("StartStopResultCallbackProxy SendRequest errno:%d", ret); return; diff --git a/interfaces/ipc/src/unregister_d_input_call_back_proxy.cpp b/interfaces/ipc/src/unregister_d_input_call_back_proxy.cpp index 1648dfd22ab9ee6df24b1614f14d072bb69c3b25..d6e9b498bbb0b347fa38bbbdd2463c1f65c4007a 100644 --- a/interfaces/ipc/src/unregister_d_input_call_back_proxy.cpp +++ b/interfaces/ipc/src/unregister_d_input_call_back_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -59,7 +59,7 @@ void UnregisterDInputCallbackProxy::OnResult(const std::string& devId, const std return; } int32_t ret = remote->SendRequest( - static_cast(IUnregisterDInputCallback::Message::RESULT), data, reply, option); + static_cast(IUnregisterDInputCallback::Message::RESULT), data, reply, option); if (ret != 0) { return; } diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp index a89a2705f7a3848a6a57a87dee153a1821ad21b0..0ca566bd10425db2672878aae2329bb95e6cedf2 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -353,10 +353,6 @@ HWTEST_F(AddWhiteListInfosCallbackTest, DistributedInputSinkStub01, testing::ext ret = sinkProxy.RegisterGetSinkScreenInfosCallback(sinkScreenCb); EXPECT_EQ(DH_SUCCESS, ret); - SrcScreenInfo srcScreenInfo {"devid_test", "uuid_test", 1, 1, 1860, 980, "srcphyid", 1, 980, 490}; - ret = sinkProxy.NotifyStartDScreen(srcScreenInfo); - EXPECT_EQ(DH_SUCCESS, ret); - std::string srcScreenInfoKey = "srcScreenInfoKey_test"; ret = sinkProxy.NotifyStopDScreen(srcScreenInfoKey); EXPECT_EQ(DH_SUCCESS, ret); diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index 836b3497ed336bbe4998a3b16f9c7111c9d294d0..160762e6ca95fad646585265b52834a9d1215d6f 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -17,6 +17,7 @@ #include #include "dinput_errcode.h" +#include "dinput_ipc_interface_code.h" namespace OHOS { namespace DistributedHardware { @@ -352,10 +353,10 @@ HWTEST_F(DInputSourceCallBackTest, SendRequest01, testing::ext::TestSize.Level1) { sptr callBackStubPtr = new TestDInputSourceCallBackStub(); DistributedInputSourceProxy callBackProxy(callBackStubPtr); - IDistributedSourceInput::MessageCode code = IDistributedSourceInput::MessageCode::INIT; + IDInputSourceInterfaceCode code = IDInputSourceInterfaceCode::INIT; MessageParcel data; MessageParcel reply; - bool ret = callBackProxy.SendRequest(code, data, reply); + bool ret = callBackProxy.SendRequest(static_cast(code), data, reply); EXPECT_EQ(false, ret); } 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 c60c8d3f43c623cde977b93d20de2d3fe5040746..8820003640176a2b4e29112a1de57856ee2091af 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp @@ -305,13 +305,6 @@ HWTEST_F(DistributedInputSinkManagerTest, UpdateSinkScreenInfoCache_01, testing: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSinkManagerTest, NotifyStartDScreen_01, testing::ext::TestSize.Level1) -{ - SrcScreenInfo srcScreenInfo {"devid_test", "uuid_test", 1, 1, 1860, 980, "srcphyid", 1, 980, 490}; - int32_t ret = sinkManager_->NotifyStartDScreen(srcScreenInfo); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_01, testing::ext::TestSize.Level1) { std::string srcScreenInfoKey = ""; diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index a0c8a787c82eb1e1e7a68921bba581f70df6ba33..09f319e36958b6902c84d87bc1bdebd645363d55 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -15,6 +15,8 @@ group("fuzztest") { testonly = true deps = [ + "dinputsinkhandler_fuzzer:fuzztest", + "dinputsourcehandler_fuzzer:fuzztest", "distributedinputclient_fuzzer:fuzztest", "distributedinputkit_fuzzer:fuzztest", "distributedinputsinktransport_fuzzer:fuzztest", diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn b/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..908aaa1b03f5423362389deb13e9758a72435537 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputSinkHandlerFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputsinkhandler_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinput_sink_handler_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sinkhandler:libdinput_sink_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputSinkHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputSinkHandlerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init b/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e66a6b337cf382a2066c908d845458e0f457c1c --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dinput_sink_handler_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_sink_input.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +void InitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params); +} + +void ReleaseSinkFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink(); +} + +void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string dhId(reinterpret_cast(data), size); + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params); +} + +void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string dhId(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSinkFuzzTest(data, size); + OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size); + OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size); + OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5dd97ac8e86fe72b8db7beeeac99da78a1659608 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef DINPUT_SINK_HANDLER_FUZZER_H +#define DINPUT_SINK_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputsinkhandler_fuzzer" + +#endif // DINPUT_SINK_HANDLER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/project.xml b/test/fuzztest/dinputsinkhandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn b/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..76f3e60cd48c3fb4b3db9b31ec41a128c26558c8 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputSourceHandlerFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputsourcehandler_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinput_source_handler_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sourcehandler:libdinput_source_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputSourceHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputSourceHandlerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init b/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5a5ba6d8ce01ff95880c41fc74b181a7fd887d7 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dinput_source_handler_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_sink_input.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback { +public: + TestRegisterInputCallback() = default; + virtual ~TestRegisterInputCallback() = default; + virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override + { + return 0; + } +}; + +class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback { +public: + TestUnregisterInputCallback() = default; + virtual ~TestUnregisterInputCallback() = default; + virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override + { + return 0; + } +}; + +void InitSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params); +} + +void ReleaseSourceFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource(); +} + +void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string key(reinterpret_cast(data), size); + std::string value(reinterpret_cast(data), size); + DistributedInput::DistributedInputSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSourceFuzzTest(data, size); + OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size); + OHOS::DistributedHardware::ConfigDistributedHardwareFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..dda0d85d3c9681c7b153fc959cb1e2603fb9398e --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef DINPUT_SOURCE_HANDLER_FUZZER_H +#define DINPUT_SOURCE_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputsourcehandler_fuzzer" + +#endif // DINPUT_SOURCE_HANDLER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/project.xml b/test/fuzztest/dinputsourcehandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +