From 58f25ea6bedea1ff622c09a4c9648502f571742a Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 16:31:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E7=A1=AC?= =?UTF-8?q?=E4=BB=B6=E7=AE=A1=E7=90=86=E6=A1=86=E6=9E=B6IDL=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../av_trans_control_center_callback_stub.h | 2 +- .../av_trans_control_center_callback_stub.cpp | 6 +- .../include/av_trans_control_center.h | 6 +- .../av_trans_control_center_callback_proxy.h | 4 +- .../services/src/av_trans_control_center.cpp | 4 +- ...av_trans_control_center_callback_proxy.cpp | 6 +- .../avtransstubonremoterequest_fuzzer.cpp | 8 +- .../av_trans_engine/av_receiver/BUILD.gn | 1 + .../test/unittest/av_receiver_engine/BUILD.gn | 2 + .../av_receiver_engine_provider/BUILD.gn | 2 + .../av_trans_engine/av_sender/BUILD.gn | 1 + .../test/unittest/av_sender_engine/BUILD.gn | 2 + .../av_sender_engine_provider/BUILD.gn | 2 + av_transport/common/include/av_trans_types.h | 46 +- bundle.json | 1 - common/utils/include/dhardware_descriptor.h | 42 +- .../iav_trans_control_center_callback.h | 4 +- common/utils/include/idistributed_hardware.h | 67 -- interfaces/inner_kits/BUILD.gn | 69 +- .../inner_kits/IDistributedHardware.idl | 45 + .../include/distributed_hardware_fwk_kit.h | 8 +- .../include/ih_d_sink_status_listener.h | 21 + .../include/ih_d_source_status_listener.h | 22 + .../inner_kits/include/ipc/dhfwk_sa_manager.h | 6 +- .../include/ipc/distributed_hardware_proxy.h | 69 -- .../src/distributed_hardware_fwk_kit.cpp | 43 +- .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 7 +- .../src/ipc/distributed_hardware_proxy.cpp | 862 ------------------ .../distributedhardwarefwkkit_fuzzer/BUILD.gn | 5 +- .../BUILD.gn | 5 +- interfaces/inner_kits/test/unittest/BUILD.gn | 1 - .../src/distributed_hardware_fwk_kit_test.cpp | 4 +- .../common/ipc/dhfwk_sa_manager/BUILD.gn | 1 + .../include/dhfwk_sa_manager_test.h | 33 +- .../ipc/distributed_hardware_proxy/BUILD.gn | 83 -- .../include/distributed_hardware_proxy_test.h | 84 -- .../src/distributed_hardware_proxy_test.cpp | 522 ----------- .../ipc/publisher_listener_stub/BUILD.gn | 1 + interfaces/kits/napi/BUILD.gn | 1 + .../distributedhardwarefwkservice/BUILD.gn | 6 +- .../componentmanager/component_manager.h | 1 + .../include/distributed_hardware_service.h | 40 +- .../include/distributed_hardware_stub.h | 65 -- .../src/distributed_hardware_service.cpp | 269 +++++- .../src/distributed_hardware_stub.cpp | 653 ------------- .../src/task/disable_task.cpp | 10 +- .../src/task/enable_task.cpp | 10 +- .../fuzztest/componentmanager_fuzzer/BUILD.gn | 1 + .../distributedfwkservices_fuzzer/BUILD.gn | 1 + .../distributedfwkservices_fuzzer.cpp | 9 +- .../test/unittest/BUILD.gn | 1 - .../component_manager/BUILD.gn | 1 + .../distributedhardwareservice/BUILD.gn | 1 + .../src/distributed_hardware_service_test.cpp | 54 +- .../common/distributedhardwarestub/BUILD.gn | 73 -- .../include/distributed_hardware_stub_test.h | 187 ---- .../src/distributed_hardware_stub_test.cpp | 343 ------- .../common/hidumphelper/hidumphelper/BUILD.gn | 1 + 58 files changed, 646 insertions(+), 3178 deletions(-) delete mode 100644 common/utils/include/idistributed_hardware.h create mode 100644 interfaces/inner_kits/IDistributedHardware.idl create mode 100644 interfaces/inner_kits/include/ih_d_sink_status_listener.h create mode 100644 interfaces/inner_kits/include/ih_d_source_status_listener.h delete mode 100644 interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h delete mode 100644 interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp delete mode 100644 interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn delete mode 100644 interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h delete mode 100644 interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp delete mode 100644 services/distributedhardwarefwkservice/include/distributed_hardware_stub.h delete mode 100644 services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp delete mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn delete mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h delete mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp diff --git a/av_transport/av_trans_control_center/inner_kits/include/av_trans_control_center_callback_stub.h b/av_transport/av_trans_control_center/inner_kits/include/av_trans_control_center_callback_stub.h index 57327328..fad76ee9 100644 --- a/av_transport/av_trans_control_center/inner_kits/include/av_trans_control_center_callback_stub.h +++ b/av_transport/av_trans_control_center/inner_kits/include/av_trans_control_center_callback_stub.h @@ -21,7 +21,7 @@ namespace OHOS { namespace DistributedHardware { -class AVTransControlCenterCallbackStub : public IRemoteStub { +class AVTransControlCenterCallbackStub : public IRemoteStub { public: AVTransControlCenterCallbackStub(); virtual ~AVTransControlCenterCallbackStub() override; diff --git a/av_transport/av_trans_control_center/inner_kits/src/av_trans_control_center_callback_stub.cpp b/av_transport/av_trans_control_center/inner_kits/src/av_trans_control_center_callback_stub.cpp index 696bfb12..8a07aad3 100644 --- a/av_transport/av_trans_control_center/inner_kits/src/av_trans_control_center_callback_stub.cpp +++ b/av_transport/av_trans_control_center/inner_kits/src/av_trans_control_center_callback_stub.cpp @@ -37,13 +37,13 @@ int32_t AVTransControlCenterCallbackStub::OnRemoteRequest(uint32_t code, return ERR_INVALID_DATA; } switch (code) { - case (uint32_t)IAVTransControlCenterCallback::Message::SET_PARAMETER: { + case (uint32_t)IAvTransControlCenterCallback::Message::SET_PARAMETER: { return SetParameterInner(data, reply); } - case (uint32_t)IAVTransControlCenterCallback::Message::SET_SHARED_MEMORY: { + case (uint32_t)IAvTransControlCenterCallback::Message::SET_SHARED_MEMORY: { return SetSharedMemoryInner(data, reply); } - case (uint32_t)IAVTransControlCenterCallback::Message::NOTIFY_AV_EVENT: { + case (uint32_t)IAvTransControlCenterCallback::Message::NOTIFY_AV_EVENT: { return NotifyInner(data, reply); } default: diff --git a/av_transport/av_trans_control_center/services/include/av_trans_control_center.h b/av_transport/av_trans_control_center/services/include/av_trans_control_center.h index 4f97415c..19a8e0ac 100644 --- a/av_transport/av_trans_control_center/services/include/av_trans_control_center.h +++ b/av_transport/av_trans_control_center/services/include/av_trans_control_center.h @@ -35,7 +35,7 @@ public: int32_t ReleaseAVCenter(int32_t engineId); int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId); int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event); - int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr &callback); + int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr &callback); // interfaces from ISoftbusChannelListener void OnChannelEvent(const AVTransEvent &event) override; @@ -64,8 +64,8 @@ private: std::vector connectedDevIds_; std::map engine2DevIdMap_; - std::map> callbackMap_; + std::map> callbackMap_; }; } } -#endif \ No newline at end of file +#endif diff --git a/av_transport/av_trans_control_center/services/include/ipc/av_trans_control_center_callback_proxy.h b/av_transport/av_trans_control_center/services/include/ipc/av_trans_control_center_callback_proxy.h index 9b657f4b..95cc33d4 100644 --- a/av_transport/av_trans_control_center/services/include/ipc/av_trans_control_center_callback_proxy.h +++ b/av_transport/av_trans_control_center/services/include/ipc/av_trans_control_center_callback_proxy.h @@ -24,10 +24,10 @@ namespace OHOS { namespace DistributedHardware { -class AVTransControlCenterCallbackProxy : public IRemoteProxy { +class AVTransControlCenterCallbackProxy : public IRemoteProxy { public: explicit AVTransControlCenterCallbackProxy(const sptr &impl) - : IRemoteProxy(impl) + : IRemoteProxy(impl) { } virtual ~AVTransControlCenterCallbackProxy() {} diff --git a/av_transport/av_trans_control_center/services/src/av_trans_control_center.cpp b/av_transport/av_trans_control_center/services/src/av_trans_control_center.cpp index 525791ad..1602c3c5 100644 --- a/av_transport/av_trans_control_center/services/src/av_trans_control_center.cpp +++ b/av_transport/av_trans_control_center/services/src/av_trans_control_center.cpp @@ -202,7 +202,7 @@ int32_t AVTransControlCenter::NotifyAVCenter(int32_t engineId, const AVTransEven } int32_t AVTransControlCenter::RegisterCtlCenterCallback(int32_t engineId, - const sptr &callback) + const sptr &callback) { TRUE_RETURN_V_MSG_E(IsInvalidEngineId(engineId), ERR_DH_AVT_INVALID_PARAM_VALUE, "Invalid input engine id = %{public}d", engineId); @@ -321,4 +321,4 @@ bool AVTransControlCenter::IsInvalidEngineId(int32_t engineId) return (engineId < BASE_ENGINE_ID) || (engineId > rootEngineId_.load()); } } -} \ No newline at end of file +} diff --git a/av_transport/av_trans_control_center/services/src/ipc/av_trans_control_center_callback_proxy.cpp b/av_transport/av_trans_control_center/services/src/ipc/av_trans_control_center_callback_proxy.cpp index 7a6268f7..55a1cda0 100644 --- a/av_transport/av_trans_control_center/services/src/ipc/av_trans_control_center_callback_proxy.cpp +++ b/av_transport/av_trans_control_center/services/src/ipc/av_trans_control_center_callback_proxy.cpp @@ -52,7 +52,7 @@ int32_t AVTransControlCenterCallbackProxy::SetParameter(AVTransTag tag, const st AVTRANS_LOGE("Write value failed"); return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; } - int32_t ret = remote->SendRequest((uint32_t)IAVTransControlCenterCallback::Message::SET_PARAMETER, + int32_t ret = remote->SendRequest((uint32_t)IAvTransControlCenterCallback::Message::SET_PARAMETER, data, reply, option); if (ret != NO_ERROR) { AVTRANS_LOGE("Send Request failed, ret: %{public}d", ret); @@ -90,7 +90,7 @@ int32_t AVTransControlCenterCallbackProxy::SetSharedMemory(const AVTransSharedMe AVTRANS_LOGE("Write memory name failed"); return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; } - int32_t ret = remote->SendRequest((uint32_t)IAVTransControlCenterCallback::Message::SET_SHARED_MEMORY, + int32_t ret = remote->SendRequest((uint32_t)IAvTransControlCenterCallback::Message::SET_SHARED_MEMORY, data, reply, option); if (ret != NO_ERROR) { AVTRANS_LOGE("Send Request failed, ret: %{public}d", ret); @@ -128,7 +128,7 @@ int32_t AVTransControlCenterCallbackProxy::Notify(const AVTransEvent& event) AVTRANS_LOGE("Write event peerDevId failed"); return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; } - int32_t ret = remote->SendRequest((uint32_t)IAVTransControlCenterCallback::Message::NOTIFY_AV_EVENT, + int32_t ret = remote->SendRequest((uint32_t)IAvTransControlCenterCallback::Message::NOTIFY_AV_EVENT, data, reply, option); if (ret != NO_ERROR) { AVTRANS_LOGE("Send Request failed, ret: %{public}d", ret); diff --git a/av_transport/av_trans_control_center/test/fuzztest/avtransstubonremoterequest_fuzzer/avtransstubonremoterequest_fuzzer.cpp b/av_transport/av_trans_control_center/test/fuzztest/avtransstubonremoterequest_fuzzer/avtransstubonremoterequest_fuzzer.cpp index 5b95196a..eb056576 100644 --- a/av_transport/av_trans_control_center/test/fuzztest/avtransstubonremoterequest_fuzzer/avtransstubonremoterequest_fuzzer.cpp +++ b/av_transport/av_trans_control_center/test/fuzztest/avtransstubonremoterequest_fuzzer/avtransstubonremoterequest_fuzzer.cpp @@ -47,12 +47,12 @@ void AVTransStubOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageOption option; pdata.WriteInterfaceToken(AVTransControlCenterCallback::GetDescriptor()); uint32_t code = *(reinterpret_cast(data)) % DC_MESSAGE_SIZE; - if (code == (uint32_t)IAVTransControlCenterCallback::Message::SET_PARAMETER) { + if (code == (uint32_t)IAvTransControlCenterCallback::Message::SET_PARAMETER) { uint32_t tag = *(reinterpret_cast(data)); std::string value(reinterpret_cast(data), size); pdata.WriteUint32(tag); pdata.WriteString(value); - } else if (code == (uint32_t)IAVTransControlCenterCallback::Message::SET_SHARED_MEMORY) { + } else if (code == (uint32_t)IAvTransControlCenterCallback::Message::SET_SHARED_MEMORY) { FuzzedDataProvider fdp(data, size); int32_t fd = fdp.ConsumeIntegral(); int32_t len = fdp.ConsumeIntegral(); @@ -60,7 +60,7 @@ void AVTransStubOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) pdata.WriteFileDescriptor(fd); pdata.WriteInt32(len); pdata.WriteString(name); - } else if (code == (uint32_t)IAVTransControlCenterCallback::Message::NOTIFY_AV_EVENT) { + } else if (code == (uint32_t)IAvTransControlCenterCallback::Message::NOTIFY_AV_EVENT) { uint32_t type = *(reinterpret_cast(data)); std::string content(reinterpret_cast(data), size); std::string devId(reinterpret_cast(data), size); @@ -84,4 +84,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::DistributedHardware::AVTransStubOnRemoteRequestFuzzTest(data, size); return 0; -} \ No newline at end of file +} diff --git a/av_transport/av_trans_engine/av_receiver/BUILD.gn b/av_transport/av_trans_engine/av_receiver/BUILD.gn index 09e2050b..349b6f00 100644 --- a/av_transport/av_trans_engine/av_receiver/BUILD.gn +++ b/av_transport/av_trans_engine/av_receiver/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("distributed_av_receiver") { ] deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk", "${filters_path}:avtrans_input_filter", diff --git a/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine/BUILD.gn b/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine/BUILD.gn index ae091ada..2d76847a 100644 --- a/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine/BUILD.gn +++ b/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AvReceiverEngineTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_receiver:distributed_av_receiver", "${filters_path}:avtrans_input_filter", @@ -134,6 +135,7 @@ ohos_unittest("AvAudioReceiverEngineTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk", "${engine_path}/av_receiver:distributed_av_receiver", diff --git a/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine_provider/BUILD.gn b/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine_provider/BUILD.gn index c3f3fe20..1a3359b9 100644 --- a/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine_provider/BUILD.gn +++ b/av_transport/av_trans_engine/av_receiver/test/unittest/av_receiver_engine_provider/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AvReceiverEngineProviderTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_receiver:distributed_av_receiver", "${filters_path}:avtrans_input_filter", @@ -136,6 +137,7 @@ ohos_unittest("AvAudioReceiverEngineProviderTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_receiver:distributed_av_receiver", "${filters_path}:avtrans_input_filter", diff --git a/av_transport/av_trans_engine/av_sender/BUILD.gn b/av_transport/av_trans_engine/av_sender/BUILD.gn index 6f074dc6..d1a2a93c 100644 --- a/av_transport/av_trans_engine/av_sender/BUILD.gn +++ b/av_transport/av_trans_engine/av_sender/BUILD.gn @@ -65,6 +65,7 @@ ohos_shared_library("distributed_av_sender") { ] deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk", "${filters_path}:avtrans_input_filter", diff --git a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/BUILD.gn b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/BUILD.gn index a1733461..e1143615 100644 --- a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/BUILD.gn +++ b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("AvSenderEngineTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_sender:distributed_av_sender", "${filters_path}:avtrans_input_filter", @@ -134,6 +135,7 @@ ohos_unittest("AvAudioSenderEngineTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk", "${engine_path}/av_sender:distributed_av_sender", diff --git a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine_provider/BUILD.gn b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine_provider/BUILD.gn index 07c3cf87..d1d1d152 100644 --- a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine_provider/BUILD.gn +++ b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine_provider/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AvSenderEngineProviderTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_sender:distributed_av_sender", "${filters_path}:avtrans_input_filter", @@ -138,6 +139,7 @@ ohos_unittest("AvAudioSenderEngineProviderTest") { cflags_cc = cflags deps = [ + "${dh_fwk_sdk_path}:dhfwk_idl_hardware_head", "${dh_fwk_sdk_path}:libdhfwk_sdk", "${engine_path}/av_sender:distributed_av_sender", "${filters_path}:avtrans_input_filter", diff --git a/av_transport/common/include/av_trans_types.h b/av_transport/common/include/av_trans_types.h index cb9ca677..848f3d7d 100644 --- a/av_transport/common/include/av_trans_types.h +++ b/av_transport/common/include/av_trans_types.h @@ -18,6 +18,8 @@ #include #include +#include "parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedHardware { @@ -158,10 +160,52 @@ struct AVTransEvent { std::string peerDevId; }; +struct AVTransEventExt : public AVTransEvent, public Parcelable { + using AVTransEvent::AVTransEvent; + explicit AVTransEventExt() {} + virtual ~AVTransEventExt() = default; + explicit AVTransEventExt(const AVTransEvent& AVTransEvent) + { + type = AVTransEvent.type; + content = AVTransEvent.content; + peerDevId = AVTransEvent.peerDevId; + } + + virtual bool Marshalling(Parcel &parcel) const override + { + if (!parcel.WriteUint32((uint32_t)type)) { + return false; + } + if (!parcel.WriteString(content)) { + return false; + } + if (!parcel.WriteString(peerDevId)) { + return false; + } + return true; + } + + static AVTransEventExt *Unmarshalling(Parcel &parcel) + { + AVTransEventExt *avTransEvent = new (std::nothrow) AVTransEventExt(); + if (avTransEvent == nullptr) { + return nullptr; + } + uint32_t typeValue = parcel.ReadUint32(); + std::string contentValue = parcel.ReadString(); + std::string peerDevIdValue = parcel.ReadString(); + avTransEvent->type = static_cast(typeValue); + avTransEvent->content = contentValue; + avTransEvent->peerDevId = peerDevIdValue; + + return avTransEvent; + } +}; + struct AVStreamInfo { std::string sceneType; std::string peerDevId; }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_AV_TRANSPORT_TYPES_H \ No newline at end of file +#endif // OHOS_AV_TRANSPORT_TYPES_H diff --git a/bundle.json b/bundle.json index c851cf0a..1c9225a1 100644 --- a/bundle.json +++ b/bundle.json @@ -142,7 +142,6 @@ "idistributed_hardware_manager.h", "idistributed_hardware_sink.h", "idistributed_hardware_source.h", - "idistributed_hardware.h", "ihardware_handler.h", "ipublisher_listener.h", "single_instance.h" diff --git a/common/utils/include/dhardware_descriptor.h b/common/utils/include/dhardware_descriptor.h index 8ead0889..e0258a15 100644 --- a/common/utils/include/dhardware_descriptor.h +++ b/common/utils/include/dhardware_descriptor.h @@ -20,13 +20,53 @@ #include #include "device_type.h" +#include "parcel.h" namespace OHOS { namespace DistributedHardware { -struct DHDescriptor { +struct DHDescriptor : public Parcelable { std::string id; DHType dhType; + + DHDescriptor() : id(""), dhType(DHType::UNKNOWN) {} + DHDescriptor(std::string id, DHType dhType) + { + this->id = id; + this->dhType = dhType; + } + + bool ReadFromParcel(Parcel &parcel) + { + id = parcel.ReadString(); + dhType = static_cast(parcel.ReadInt32()); + return true; + } + + virtual bool Marshalling(Parcel &parcel) const override + { + if (!parcel.WriteString(id)) { + return false; + } + if (!parcel.WriteInt32(static_cast(dhType))) { + return false; + } + return true; + } + + static DHDescriptor *Unmarshalling(Parcel &parcel) + { + DHDescriptor *descriptor = new (std::nothrow) DHDescriptor(); + if (descriptor == nullptr) { + return nullptr; + } + + if (!descriptor->ReadFromParcel(parcel)) { + delete descriptor; + descriptor = nullptr; + } + return descriptor; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/utils/include/iav_trans_control_center_callback.h b/common/utils/include/iav_trans_control_center_callback.h index bcbe6338..4b0e884c 100644 --- a/common/utils/include/iav_trans_control_center_callback.h +++ b/common/utils/include/iav_trans_control_center_callback.h @@ -24,7 +24,7 @@ namespace OHOS { namespace DistributedHardware { -class IAVTransControlCenterCallback : public IRemoteBroker { +class IAvTransControlCenterCallback : public IRemoteBroker { public: virtual int32_t SetParameter(AVTransTag tag, const std::string &value) = 0; virtual int32_t SetSharedMemory(const AVTransSharedMemory &memory) = 0; @@ -36,7 +36,7 @@ public: NOTIFY_AV_EVENT = 3 }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.IAVTransControlCenterCallback"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.IAvTransControlCenterCallback"); }; } } diff --git a/common/utils/include/idistributed_hardware.h b/common/utils/include/idistributed_hardware.h deleted file mode 100644 index f219c268..00000000 --- a/common/utils/include/idistributed_hardware.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_IDISTRIBUTED_HARDWARE_H -#define OHOS_IDISTRIBUTED_HARDWARE_H - -#include -#include -#include - -#include "iremote_broker.h" -#include "device_type.h" -#include "dhardware_descriptor.h" -#include "ihardware_status_listener.h" - -#include "distributed_hardware_fwk_kit_paras.h" -#include "iav_trans_control_center_callback.h" -#include "ipublisher_listener.h" - -namespace OHOS { -namespace DistributedHardware { -class IDistributedHardware : public OHOS::IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.accessToken"); - IDistributedHardware() = default; - virtual ~IDistributedHardware() = default; - virtual int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener) = 0; - virtual int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener) = 0; - virtual int32_t PublishMessage(const DHTopic topic, const std::string &msg) = 0; - virtual std::string QueryLocalSysSpec(QueryLocalSysSpecType spec) = 0; - - virtual int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) = 0; - virtual int32_t ReleaseAVCenter(int32_t engineId) = 0; - virtual int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) = 0; - virtual int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) = 0; - virtual int32_t RegisterCtlCenterCallback(int32_t engineId, - const sptr callback) = 0; - virtual int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) = 0; - virtual int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) = 0; - virtual int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) = 0; - virtual int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) = 0; - virtual int32_t GetDistributedHardware(const std::string &networkId, std::vector &descriptors) = 0; - virtual int32_t RegisterDHStatusListener(sptr listener) = 0; - virtual int32_t UnregisterDHStatusListener(sptr listener) = 0; - virtual int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener) = 0; - virtual int32_t UnregisterDHStatusListener(const std::string &networkId, - sptr listener) = 0; - virtual int32_t EnableSink(const std::vector &descriptors) = 0; - virtual int32_t DisableSink(const std::vector &descriptors) = 0; - virtual int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) = 0; - virtual int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IDISTRIBUTED_HARDWARE_H diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index a322c46b..003aaa3d 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") @@ -22,6 +23,71 @@ config("innerkits_external_config") { ] } +idl_gen_interface("dhfwk_idl_hardware") { + sources = [ "IDistributedHardware.idl" ] + log_domainid = "0xD004100" + log_tag = "distributedhardware" +} + +config("dhfwk_idl_hardware_config") { + include_dirs = [ + "include", + "${av_trans_path}/common/include", + "${innerkits_path}/include", + ".", + "${target_gen_dir}", + "${common_path}/utils/include", + ] +} + +ohos_source_set("dhfwk_idl_hardware_source") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":dhfwk_idl_hardware_config" ] + output_values = get_target_outputs(":dhfwk_idl_hardware") + sources = filter_include(output_values, [ "*.cpp" ]) + deps = [ ":dhfwk_idl_hardware" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_hardware_fwk" +} + +ohos_source_set("dhfwk_idl_hardware_head") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":dhfwk_idl_hardware_config" ] + deps = [ ":dhfwk_idl_hardware" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_hardware_fwk" +} + ohos_shared_library("libdhfwk_sdk") { sanitize = { boundary_sanitize = true @@ -52,12 +118,12 @@ ohos_shared_library("libdhfwk_sdk") { "${av_center_kits_path}/src/av_trans_control_center_callback_stub.cpp", "${innerkits_path}/src/distributed_hardware_fwk_kit.cpp", "${innerkits_path}/src/ipc/dhfwk_sa_manager.cpp", - "${innerkits_path}/src/ipc/distributed_hardware_proxy.cpp", "${innerkits_path}/src/ipc/hardware_status_listener_stub.cpp", "${innerkits_path}/src/ipc/publisher_listener_stub.cpp", ] deps = [ + ":dhfwk_idl_hardware_source", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", ] @@ -79,6 +145,7 @@ ohos_shared_library("libdhfwk_sdk") { "c_utils:utils", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/interfaces/inner_kits/IDistributedHardware.idl b/interfaces/inner_kits/IDistributedHardware.idl new file mode 100644 index 00000000..958c9186 --- /dev/null +++ b/interfaces/inner_kits/IDistributedHardware.idl @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-2024 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. + */ +sequenceable AvTransTypes..OHOS.DistributedHardware.AVTransEventExt; +sequenceable DhardwareDescriptor..OHOS.DistributedHardware.DHDescriptor; +interface OHOS.DistributedHardware.IPublisherListener; +interface OHOS.DistributedHardware.IAvTransControlCenterCallback; +interface OHOS.DistributedHardware.IHDSinkStatusListener; +interface OHOS.DistributedHardware.IHDSourceStatusListener; + +interface OHOS.DistributedHardware.IDistributedHardware { + [ipccode 48001] void RegisterPublisherListener([in] unsigned int topic, [in] IPublisherListener listener); + [ipccode 48002] void UnregisterPublisherListener([in] unsigned int topic, [in] IPublisherListener listener); + [ipccode 48003] void PublishMessage([in] unsigned int topic, [in] String msg); + [ipccode 48009] String QueryLocalSysSpec([in] unsigned int spec); + [ipccode 48004] void InitializeAVCenter([in] unsigned int transRole, [out] int engineId); + [oneway, ipccode 48005] void ReleaseAVCenter([in] int engineId); + [oneway, ipccode 48006] void CreateControlChannel([in] int engineId, [in] String peerDevId); + [oneway, ipccode 48007] void NotifyAVCenter([in] int engineId, [in] AVTransEventExt event); + [ipccode 48008] void RegisterCtlCenterCallback([in] int engineId, [in] IAvTransControlCenterCallback call); + [ipccode 1] void NotifySourceRemoteSinkStarted([in] String deviceId); + [ipccode 480010] void PauseDistributedHardware([in] unsigned int dhType, [in] String networkId); + [ipccode 480011] void ResumeDistributedHardware([in] unsigned int dhType, [in] String networkId); + [ipccode 480012] void StopDistributedHardware([in] unsigned int dhType, [in] String networkId); + [ipccode 480013] void GetDistributedHardware([in] String networkId, [out] DHDescriptor[] descriptors); + [ipccode 480014] void RegisterDHStatusListener([in] IHDSinkStatusListener listener); + [ipccode 480015] void UnregisterDHStatusListener([in] IHDSinkStatusListener listener); + [ipccode 480016] void RegisterDHStatusListenerOverload([in] String networkId, [in] IHDSourceStatusListener listener); + [ipccode 480017] void UnregisterDHStatusListenerOverload([in] String networkId, [in] IHDSourceStatusListener listener); + [ipccode 480018] void EnableSink([in] DHDescriptor[] descriptors); + [ipccode 480019] void DisableSink([in] DHDescriptor[] descriptors); + [ipccode 480020] void EnableSource([in] String networkId, [in] DHDescriptor[] descriptors); + [ipccode 480021] void DisableSource([in] String networkId, [in] DHDescriptor[] descriptors); +} \ No newline at end of file diff --git a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h index a531c680..43f97426 100644 --- a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h +++ b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h @@ -26,8 +26,10 @@ #include "distributed_hardware_fwk_kit_paras.h" #include "dhardware_descriptor.h" #include "ipublisher_listener.h" -#include "idistributed_hardware.h" #include "ihardware_status_listener.h" +#include "device_type.h" +#include "av_trans_types.h" +#include "iav_trans_control_center_callback.h" #ifndef API_EXPORT #define API_EXPORT __attribute__((visibility("default"))) @@ -130,7 +132,7 @@ public: * @param callback av control center callback. * @return Returns 0 if success. */ - API_EXPORT int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback); + API_EXPORT int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback); /** * @brief Pause distributed hardware. @@ -256,4 +258,4 @@ private: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H \ No newline at end of file +#endif // OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H diff --git a/interfaces/inner_kits/include/ih_d_sink_status_listener.h b/interfaces/inner_kits/include/ih_d_sink_status_listener.h new file mode 100644 index 00000000..c691ca00 --- /dev/null +++ b/interfaces/inner_kits/include/ih_d_sink_status_listener.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 IH_D_SINK_STATUS_LISTENER_H +#define IH_D_SINK_STATUS_LISTENER_H + +#include "ihardware_status_listener.h" + +#endif // IH_D_SINK_STATUS_LISTENER_H \ No newline at end of file diff --git a/interfaces/inner_kits/include/ih_d_source_status_listener.h b/interfaces/inner_kits/include/ih_d_source_status_listener.h new file mode 100644 index 00000000..3f2c568f --- /dev/null +++ b/interfaces/inner_kits/include/ih_d_source_status_listener.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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 IH_D_SOURCE_STATUS_LISTENER_H +#define IH_D_SOURCE_STATUS_LISTENER_H + + +#include "ihardware_status_listener.h" + +#endif // IH_D_SOURCE_STATUS_LISTENER_H \ No newline at end of file diff --git a/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h b/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h index 831fafeb..1db8c472 100644 --- a/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h +++ b/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h @@ -42,7 +42,7 @@ public: int32_t AddPublisherListenerToCache(const DHTopic topic, sptr listener); void RemovePublisherListenerFromCache(const DHTopic topic, sptr listener); - void AddAVTransControlCenterCbToCache(int32_t engineId, const sptr callback); + void AddAVTransControlCenterCbToCache(int32_t engineId, const sptr callback); void RemoveAVTransControlCenterCbFromCache(int32_t engineId); public: @@ -66,8 +66,8 @@ private: std::mutex publisherListenersMutex_; std::unordered_map>> publisherListenersCache_; std::mutex avTransControlCenterCbMutex_; - std::unordered_map> avTransControlCenterCbCache_; + std::unordered_map> avTransControlCenterCbCache_; }; } // DistributedHardware } // OHOS -#endif // OHOS_DHFWK_SA_MANAGER_H \ No newline at end of file +#endif // OHOS_DHFWK_SA_MANAGER_H diff --git a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h b/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h deleted file mode 100644 index 5f57ee29..00000000 --- a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_PROXY_H -#define OHOS_DISTRIBUTED_HARDWARE_PROXY_H - -#include - -#include "distributed_hardware_fwk_kit_paras.h" -#include "iremote_proxy.h" -#include "refbase.h" -#include "idistributed_hardware.h" - -namespace OHOS { -namespace DistributedHardware { -class DistributedHardwareProxy : public IRemoteProxy { -public: - explicit DistributedHardwareProxy(const sptr impl) - : IRemoteProxy(impl) - { - } - - virtual ~DistributedHardwareProxy() {} - int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener) override; - int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener) override; - int32_t PublishMessage(const DHTopic topic, const std::string &msg) override; - std::string QueryLocalSysSpec(QueryLocalSysSpecType spec) override; - - int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) override; - int32_t ReleaseAVCenter(int32_t engineId) override; - int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) override; - int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) override; - int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback) override; - int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) override; - int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) override; - int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) override; - int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) override; - int32_t GetDistributedHardware(const std::string &networkId, std::vector &descriptors) override; - int32_t RegisterDHStatusListener(sptr listener) override; - int32_t UnregisterDHStatusListener(sptr listener) override; - int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener) override; - int32_t UnregisterDHStatusListener(const std::string &networkId, sptr listener) override; - int32_t EnableSink(const std::vector &descriptors) override; - int32_t DisableSink(const std::vector &descriptors) override; - int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) override; - int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) override; - -private: - int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); - int32_t WriteDescriptors(MessageParcel &data, const std::vector &descriptors); - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_PROXY_H diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index 2ed3502f..927ae0c1 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -68,7 +68,12 @@ int32_t DistributedHardwareFwkKit::RegisterPublisherListener(const DHTopic topic int32_t ret = DH_FWK_SUCCESS; if (DHFWKSAManager::GetInstance().GetDHFWKProxy() != nullptr) { - ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterPublisherListener(topic, listener); + if (listener == nullptr) { + DHLOGE("publisher listener is null"); + ret = ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL; + } else { + ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterPublisherListener((uint32_t)topic, listener); + } DHLOGI("Register publisher listener to DHFWK, ret: %{public}" PRId32, ret); if (ret == DH_FWK_SUCCESS) { return DHFWKSAManager::GetInstance().AddPublisherListenerToCache(topic, listener); @@ -92,7 +97,12 @@ int32_t DistributedHardwareFwkKit::UnregisterPublisherListener(const DHTopic top int32_t ret = DH_FWK_SUCCESS; if (DHFWKSAManager::GetInstance().GetDHFWKProxy() != nullptr) { - ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnregisterPublisherListener(topic, listener); + if (listener == nullptr) { + DHLOGE("publisher listener is null"); + ret = ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL; + } else { + ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnregisterPublisherListener((uint32_t)topic, listener); + } DHLOGI("Unregister publisher listener to DHFWK, ret: %{public}" PRId32, ret); } @@ -116,7 +126,7 @@ int32_t DistributedHardwareFwkKit::PublishMessage(const DHTopic topic, const std return ERR_DH_FWK_PUBLISH_MSG_FAILED; } - int32_t ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->PublishMessage(topic, message); + int32_t ret = DHFWKSAManager::GetInstance().GetDHFWKProxy()->PublishMessage((uint32_t)topic, message); DHLOGI("Publish message to DHFWK, ret: %{public}" PRId32, ret); return ret; @@ -151,7 +161,9 @@ std::string DistributedHardwareFwkKit::QueryLocalSysSpec(enum QueryLocalSysSpecT return ""; } - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->QueryLocalSysSpec(spec); + std::string funcResult; + DHFWKSAManager::GetInstance().GetDHFWKProxy()->QueryLocalSysSpec((uint32_t)spec, funcResult); + return funcResult; } int32_t DistributedHardwareFwkKit::InitializeAVCenter(const TransRole &transRole, int32_t &engineId) @@ -163,7 +175,7 @@ int32_t DistributedHardwareFwkKit::InitializeAVCenter(const TransRole &transRole return ERR_DH_FWK_POINTER_IS_NULL; } - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->InitializeAVCenter(transRole, engineId); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->InitializeAVCenter((uint32_t)transRole, engineId); } int32_t DistributedHardwareFwkKit::ReleaseAVCenter(int32_t engineId) @@ -202,11 +214,11 @@ int32_t DistributedHardwareFwkKit::NotifyAVCenter(int32_t engineId, const AVTran return ERR_DH_FWK_POINTER_IS_NULL; } - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->NotifyAVCenter(engineId, event); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->NotifyAVCenter(engineId, AVTransEventExt(event)); } int32_t DistributedHardwareFwkKit::RegisterCtlCenterCallback(int32_t engineId, - const sptr callback) + const sptr callback) { DHLOGI("Register av control center callback. engineId: %{public}" PRId32, engineId); @@ -215,6 +227,10 @@ int32_t DistributedHardwareFwkKit::RegisterCtlCenterCallback(int32_t engineId, return ERR_DH_FWK_POINTER_IS_NULL; } DHFWKSAManager::GetInstance().AddAVTransControlCenterCbToCache(engineId, callback); + if (callback == nullptr) { + DHLOGE("callback is null"); + return ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL; + } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterCtlCenterCallback(engineId, callback); } @@ -232,7 +248,7 @@ int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const } HiSysEventWriteMsg(DHFWK_INIT_END, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "user pause sink ui."); - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->PauseDistributedHardware(dhType, networkId); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->PauseDistributedHardware((uint32_t)dhType, networkId); } int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, const std::string &networkId) @@ -249,7 +265,7 @@ int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, cons } HiSysEventWriteMsg(DHFWK_INIT_BEGIN, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "user resume sink ui."); - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->ResumeDistributedHardware(dhType, networkId); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->ResumeDistributedHardware((uint32_t)dhType, networkId); } int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const std::string &networkId) @@ -266,7 +282,7 @@ int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const } HiSysEventWriteMsg(DHFWK_EXIT_END, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "user stop sink ui."); - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->StopDistributedHardware(dhType, networkId); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->StopDistributedHardware((uint32_t)dhType, networkId); } int32_t DistributedHardwareFwkKit::GetDistributedHardware( @@ -280,6 +296,7 @@ int32_t DistributedHardwareFwkKit::GetDistributedHardware( DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); return ERR_DH_FWK_POINTER_IS_NULL; } + descriptors.clear(); return DHFWKSAManager::GetInstance().GetDHFWKProxy()->GetDistributedHardware(networkId, descriptors); } @@ -314,7 +331,7 @@ int32_t DistributedHardwareFwkKit::RegisterDHStatusListener( DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); return ERR_DH_FWK_POINTER_IS_NULL; } - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterDHStatusListener(networkId, listener); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterDHStatusListenerOverload(networkId, listener); } int32_t DistributedHardwareFwkKit::UnregisterDHStatusListener( @@ -328,7 +345,7 @@ int32_t DistributedHardwareFwkKit::UnregisterDHStatusListener( DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); return ERR_DH_FWK_POINTER_IS_NULL; } - return DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnregisterDHStatusListener(networkId, listener); + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnregisterDHStatusListenerOverload(networkId, listener); } int32_t DistributedHardwareFwkKit::EnableSink(const std::vector &descriptors) @@ -381,4 +398,4 @@ int32_t DistributedHardwareFwkKit::DisableSource( return DHFWKSAManager::GetInstance().GetDHFWKProxy()->DisableSource(networkId, descriptors); } } // DistributedHardware -} // OHOS \ No newline at end of file +} // OHOS diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index 29c30e52..fadad650 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -155,7 +155,8 @@ int32_t DHFWKSAManager::RestoreListener() for (const auto &entry : publisherListenersCache_) { for (const auto &listener : entry.second) { int32_t innerRet = - DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterPublisherListener(entry.first, listener); + DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterPublisherListener( + (uint32_t)entry.first, listener); if (ret != DH_FWK_SUCCESS) { ret = innerRet; DHLOGE("Register publisher listener failed, topic: %{public}" PRIu32, (uint32_t)entry.first); @@ -200,7 +201,7 @@ void DHFWKSAManager::RemovePublisherListenerFromCache(const DHTopic topic, sptr< } void DHFWKSAManager::AddAVTransControlCenterCbToCache(int32_t engineId, - const sptr callback) + const sptr callback) { std::lock_guard avTransControlCenterCbLock(avTransControlCenterCbMutex_); avTransControlCenterCbCache_[engineId] = callback; @@ -212,4 +213,4 @@ void DHFWKSAManager::RemoveAVTransControlCenterCbFromCache(int32_t engineId) avTransControlCenterCbCache_.erase(engineId); } } // DistributedHardware -} // OHOS \ No newline at end of file +} // OHOS diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp deleted file mode 100644 index 4f89b6b5..00000000 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ /dev/null @@ -1,862 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_proxy.h" - -#include -#include - -#include "anonymous_string.h" -#include "av_trans_errno.h" -#include "constants.h" -#include "dh_utils_tool.h" -#include "dhardware_ipc_interface_code.h" -#include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" -#include "parcel.h" - -namespace OHOS { -namespace DistributedHardware { -#undef DH_LOG_TAG -#define DH_LOG_TAG "DistributedHardwareProxy" -const std::unordered_set DH_TYPE_SET { - DHType::UNKNOWN, DHType::CAMERA, DHType::AUDIO, DHType::SCREEN, DHType::GPS, DHType::INPUT, - DHType::HFP, DHType::A2D, DHType::VIRMODEM_AUDIO, DHType::MAX_DH, - }; - -int32_t DistributedHardwareProxy::RegisterPublisherListener(const DHTopic topic, - const sptr listener) -{ - if (listener == nullptr) { - DHLOGE("publisher listener is null"); - return ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL; - } - - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; - } - if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { - DHLOGE("Topic is invalid!"); - return ERR_DH_FWK_PARA_INVALID; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteUint32((uint32_t)topic)) { - DHLOGE("DistributedHardwareProxy write topic failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("DistributedHardwareProxy write listener failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::REG_PUBLISHER_LISTNER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - ret = reply.ReadInt32(); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("Register Publisher Listener failed, ret: %{public}d", ret); - } - - return ret; -} - -int32_t DistributedHardwareProxy::UnregisterPublisherListener(const DHTopic topic, - const sptr listener) -{ - if (listener == nullptr) { - DHLOGE("publisher listener is null"); - return ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL; - } - - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; - } - if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { - DHLOGE("Topic is invalid!"); - return ERR_DH_FWK_PARA_INVALID; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteUint32((uint32_t)topic)) { - DHLOGE("DistributedHardwareProxy write topic failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("DistributedHardwareProxy write listener failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::UNREG_PUBLISHER_LISTENER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - ret = reply.ReadInt32(); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("Unregister Publisher Listener failed, ret: %{public}d", ret); - } - - return ret; -} - -int32_t DistributedHardwareProxy::PublishMessage(const DHTopic topic, const std::string &msg) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; - } - if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { - DHLOGE("Topic is invalid!"); - return ERR_DH_FWK_PARA_INVALID; - } - if (!IsMessageLengthValid(msg)) { - return ERR_DH_FWK_SERVICE_MSG_INVALID; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteUint32((uint32_t)topic)) { - DHLOGE("DistributedHardwareProxy write topic failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(msg)) { - DHLOGE("DistributedHardwareProxy write listener failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::PUBLISH_MESSAGE), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - ret = reply.ReadInt32(); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("PublishMessage failed, ret: %{public}d", ret); - } - - return ret; -} - -std::string DistributedHardwareProxy::QueryLocalSysSpec(QueryLocalSysSpecType spec) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ""; - } - if (spec <= QueryLocalSysSpecType::MIN || spec >= QueryLocalSysSpecType::MAX) { - DHLOGE("Sys spec type is invalid!"); - return ""; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ""; - } - if (!data.WriteUint32((uint32_t)spec)) { - DHLOGE("DistributedHardwareProxy write local sys spec failed"); - return ""; - } - - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::QUERY_LOCAL_SYS_SPEC), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ""; - } - - std::string specStr = reply.ReadString(); - DHLOGI("Query local sys spec %{public}" PRIu32 ", get: %{public}s", (uint32_t)spec, specStr.c_str()); - return specStr; -} - -int32_t DistributedHardwareProxy::InitializeAVCenter(const TransRole &transRole, int32_t &engineId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteUint32((uint32_t)transRole)) { - DHLOGE("Write trans role failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::INIT_CTL_CEN), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - engineId = reply.ReadInt32(); - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::ReleaseAVCenter(int32_t engineId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteInt32(engineId)) { - DHLOGE("Write engine id failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::RELEASE_CTL_CEN), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::CreateControlChannel(int32_t engineId, const std::string &peerDevId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteInt32(engineId)) { - DHLOGE("Write engine id failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(peerDevId)) { - DHLOGE("Write peerDevId failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::CREATE_CTL_CEN_CHANNEL), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::NotifyAVCenter(int32_t engineId, const AVTransEvent &event) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteInt32(engineId)) { - DHLOGE("Write engine id failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteUint32((uint32_t)event.type)) { - DHLOGE("Write event type failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(event.content)) { - DHLOGE("Write event content failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(event.peerDevId)) { - DHLOGE("Write event peerDevId failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::NOTIFY_AV_EVENT), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::RegisterCtlCenterCallback(int32_t engineId, - const sptr callback) -{ - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - if (callback == nullptr) { - DHLOGE("callback is null"); - return ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteInt32(engineId)) { - DHLOGE("Write engine id failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - DHLOGE("Write callback failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::REGISTER_CTL_CEN_CALLBACK), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::NotifySourceRemoteSinkStarted(std::string &deviceId) -{ - DHLOGI("DistributedHardwareProxy NotifySourceRemoteSinkStarted Start"); - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("NotifySourceRemoteSinkStarted error, remote info is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(deviceId)) { - DHLOGE("Write deviceId error."); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest( - static_cast(DHMsgInterfaceCode::NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - DHLOGI("DistributedHardwareProxy NotifySourceRemoteSinkStarted End"); - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const std::string &networkId) -{ - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - uint32_t type = static_cast(dhType); - if (!data.WriteInt32(type)) { - DHLOGE("Write type failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const std::string &networkId) -{ - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - uint32_t type = static_cast(dhType); - if (!data.WriteInt32(type)) { - DHLOGE("Write type failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::RESUME_DISTRIBUTED_HARDWARE), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::StopDistributedHardware(DHType dhType, const std::string &networkId) -{ - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - int32_t type = static_cast(dhType); - if (!data.WriteInt32(type)) { - DHLOGE("Write type failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::STOP_DISTRIBUTED_HARDWARE), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::GetDistributedHardware( - const std::string &networkId, std::vector &descriptors) -{ - DHLOGI("DistributedHardwareProxy GetDistributedHardware."); - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::GET_DISTRIBUTED_HARDWARE), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - descriptors.clear(); - ReadDescriptors(reply, descriptors); - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::RegisterDHStatusListener(sptr listener) -{ - DHLOGI("DistributedHardwareProxy RegisterDHStatusListener."); - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("Write listener failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::REG_DH_SINK_STATUS_LISTNER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::UnregisterDHStatusListener(sptr listener) -{ - DHLOGI("DistributedHardwareProxy UnregisterDHStatusListener."); - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("Write listener failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::UNREG_DH_SINK_STATUS_LISTNER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::RegisterDHStatusListener( - const std::string &networkId, sptr listener) -{ - DHLOGI("DistributedHardwareProxy RegisterDHStatusListener."); - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("Write listener failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::REG_DH_SOURCE_STATUS_LISTNER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::UnregisterDHStatusListener( - const std::string &networkId, sptr listener) -{ - DHLOGI("DistributedHardwareProxy UnregisterDHStatusListener."); - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteRemoteObject(listener->AsObject())) { - DHLOGE("Write listener failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::UNREG_DH_SOURCE_STATUS_LISTNER), - data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::EnableSink(const std::vector &descriptors) -{ - DHLOGI("DistributedHardwareProxy EnableSink."); - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (WriteDescriptors(data, descriptors)) { - DHLOGE("WriteDescriptors failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::ENABLE_SINK), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::DisableSink(const std::vector &descriptors) -{ - DHLOGI("DistributedHardwareProxy DisableSink."); - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (WriteDescriptors(data, descriptors)) { - DHLOGE("WriteDescriptors failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::DISABLE_SINK), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::EnableSource( - const std::string &networkId, const std::vector &descriptors) -{ - DHLOGI("DistributedHardwareProxy EnableSource."); - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (WriteDescriptors(data, descriptors)) { - DHLOGE("WriteDescriptors failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::ENABLE_SOURCE), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::DisableSource( - const std::string &networkId, const std::vector &descriptors) -{ - DHLOGI("DistributedHardwareProxy DisableSource."); - if (!IsIdLengthValid(networkId)) { - return ERR_DH_FWK_PARA_INVALID; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null!"); - return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - DHLOGE("WriteInterfaceToken fail!"); - return ERR_DH_AVT_SERVICE_WRITE_TOKEN_FAIL; - } - if (!data.WriteString(networkId)) { - DHLOGE("Write networkId failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (WriteDescriptors(data, descriptors)) { - DHLOGE("WriteDescriptors failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::DISABLE_SOURCE), data, reply, option); - if (ret != NO_ERROR) { - DHLOGE("Send Request failed, ret: %{public}d!", ret); - return ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL; - } - return reply.ReadInt32(); -} - -int32_t DistributedHardwareProxy::ReadDescriptors(MessageParcel &data, std::vector &descriptors) -{ - int32_t size = data.ReadInt32(); - if (size > int32_t(MAX_DH_DESCRIPTOR_ARRAY_SIZE)) { - DHLOGE("The array descriptors are too large, size: %{public}d!", size); - return ERR_DH_FWK_PARA_INVALID; - } - for (int32_t i = 0; i < size; ++i) { - DHDescriptor descriptor; - descriptor.dhType = static_cast(data.ReadInt32()); - descriptor.id = data.ReadString(); - descriptors.push_back(descriptor); - } - return NO_ERROR; -} - -int32_t DistributedHardwareProxy::WriteDescriptors(MessageParcel &data, const std::vector &descriptors) -{ - int32_t size = (int32_t)descriptors.size(); - if (size > int32_t(MAX_DH_DESCRIPTOR_ARRAY_SIZE)) { - DHLOGE("The array descriptors are too large, size: %{public}d!", size); - return ERR_DH_FWK_PARA_INVALID; - } - if (!data.WriteInt32(size)) { - DHLOGE("Write descriptors size failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - for (int32_t i = 0; i < size; ++i) { - const DHDescriptor &descriptor = descriptors.at(i); - int32_t type = static_cast(descriptor.dhType); - if (!data.WriteInt32(type)) { - DHLOGE("Write descriptor.dhType failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(descriptor.id)) { - DHLOGE("Write descriptor.id failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - } - return NO_ERROR; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn index 6cd9d1f7..6f7d0093 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn @@ -43,7 +43,10 @@ ohos_fuzztest("DistributedHardwareFwkKitFuzzTest") { ] sources = [ "distributedhardwarefwkkit_fuzzer.cpp" ] - deps = [ "${innerkits_path}:libdhfwk_sdk" ] + deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", + "${innerkits_path}:libdhfwk_sdk", + ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/BUILD.gn b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/BUILD.gn index 531c7e53..59c57dc3 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/BUILD.gn @@ -42,7 +42,10 @@ ohos_fuzztest("DistributedHardwareFwkStubFuzzTest") { ] sources = [ "distributedhardwarefwkstub_fuzzer.cpp" ] - deps = [ "${innerkits_path}:libdhfwk_sdk" ] + deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", + "${innerkits_path}:libdhfwk_sdk", + ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index 839dbd1f..2b8665e5 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -17,7 +17,6 @@ group("kit_test") { deps = [ "common/distributedhardwarefwkkit:distributed_hardware_fwk_kit_test", "common/ipc/dhfwk_sa_manager:dhfwk_sa_manager_test", - "common/ipc/distributed_hardware_proxy:DistributedHardwareProxyTest", "common/ipc/publisher_listener_stub:PublisherListenerStubTest", ] } diff --git a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp index ae4eb0ba..46b9a09d 100644 --- a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp @@ -341,7 +341,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, RegisterCtlCenterCallback_001, testing:: { ASSERT_TRUE(dhfwkPtr_ != nullptr); int32_t engineId = 0; - sptr callback = nullptr; + sptr callback = nullptr; int32_t ret = dhfwkPtr_->RegisterCtlCenterCallback(engineId, callback); EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); } @@ -403,4 +403,4 @@ HWTEST_F(DistributedHardwareFwkKitTest, StopDistributedHardware_001, testing::ex EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/BUILD.gn b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/BUILD.gn index 9b6103da..25f3fbcb 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("DhfwkSaManagerTest") { configs = [ ":module_private_config" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${innerkits_path}:libdhfwk_sdk", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", diff --git a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h index e814b7d5..7552eedd 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h +++ b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h @@ -43,34 +43,35 @@ sptr AsObject() return nullptr; } -int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener) +int32_t RegisterPublisherListener(uint32_t topic, const sptr& listener) { (void)topic; (void)listener; return DH_FWK_SUCCESS; } -int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener) +int32_t UnregisterPublisherListener(uint32_t topic, const sptr& listener) { (void)topic; (void)listener; return DH_FWK_SUCCESS; } -int32_t PublishMessage(const DHTopic topic, const std::string &msg) +int32_t PublishMessage(uint32_t topic, const std::string &msg) { (void)topic; (void)msg; return DH_FWK_SUCCESS; } -std::string QueryLocalSysSpec(QueryLocalSysSpecType spec) +int32_t QueryLocalSysSpec(uint32_t spec, std::string& funcResult) { (void)spec; - return 0; + (void)funcResult; + return DH_FWK_SUCCESS; } -int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) +int32_t InitializeAVCenter(uint32_t transRole, int32_t &engineId) { (void)transRole; (void)engineId; @@ -90,41 +91,41 @@ int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) return DH_FWK_SUCCESS; } -int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) +int32_t NotifyAVCenter(int32_t engineId, const AVTransEventExt &event) { (void)engineId; (void)event; return DH_FWK_SUCCESS; } -int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback) +int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr& callback) { (void)engineId; (void)callback; return DH_FWK_SUCCESS; } -int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) +int32_t NotifySourceRemoteSinkStarted(const std::string &deviceId) { (void)deviceId; return DH_FWK_SUCCESS; } -int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) +int32_t PauseDistributedHardware(uint32_t dhType, const std::string &networkId) { (void)dhType; (void)networkId; return DH_FWK_SUCCESS; } -int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) +int32_t ResumeDistributedHardware(uint32_t dhType, const std::string &networkId) { (void)dhType; (void)networkId; return DH_FWK_SUCCESS; } -int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) +int32_t StopDistributedHardware(uint32_t dhType, const std::string &networkId) { (void)dhType; (void)networkId; @@ -138,26 +139,26 @@ int32_t GetDistributedHardware(const std::string &networkId, std::vector listener) +int32_t RegisterDHStatusListener(const sptr& listener) { (void)listener; return DH_FWK_SUCCESS; } -int32_t UnregisterDHStatusListener(sptr listener) +int32_t UnregisterDHStatusListener(const sptr& listener) { (void)listener; return DH_FWK_SUCCESS; } -int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener) +int32_t RegisterDHStatusListenerOverload(const std::string &networkId, const sptr& listener) { (void)networkId; (void)listener; return DH_FWK_SUCCESS; } -int32_t UnregisterDHStatusListener(const std::string &networkId, sptr listener) +int32_t UnregisterDHStatusListenerOverload(const std::string &networkId, const sptr& listener) { (void)networkId; (void)listener; diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn deleted file mode 100644 index c64e8835..00000000 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2023-2025 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. - -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") - -module_out_path = "distributed_hardware_fwk/distributed_hardware_proxy_test" - -config("module_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "${av_trans_path}/common/include", - "include", - "${utils_path}/include", - "${utils_path}/include/log", - "${common_path}/utils/include", - "${common_path}/log/include", - "${innerkits_path}/include", - "${innerkits_path}/include/ipc", - "${services_path}/distributedhardwarefwkservice/include", - "${services_path}/distributedhardwarefwkservice/include/utils", - "${services_path}/distributedhardwarefwkservice/include/ipc", - ] -} - -ohos_unittest("DistributedHardwareProxyTest") { - module_out_path = module_out_path - - sources = [ - "${services_path}/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp", - "src/distributed_hardware_proxy_test.cpp", - ] - - configs = [ ":module_private_config" ] - - deps = [ - "${innerkits_path}:libdhfwk_sdk", - "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", - "${utils_path}:distributedhardwareutils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DistributedHardwareProxyTest\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_manager", - "access_token:libaccesstoken_sdk", - "access_token:libtokenid_sdk", - "cJSON:cjson", - "c_utils:utils", - "device_manager:devicemanagersdk", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - ] -} - -group("distributed_hardware_proxy_test") { - testonly = true - deps = [ ":DistributedHardwareProxyTest" ] -} diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h deleted file mode 100644 index 7108d198..00000000 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_PROXY_TEST_H -#define OHOS_DISTRIBUTED_HARDWARE_PROXY_TEST_H - -#include -#include -#include - -#include "device_type.h" -#include "distributed_hardware_errno.h" -#include "idistributed_hardware.h" -#include "distributed_hardware_proxy.h" -#include "distributed_hardware_stub.h" - -namespace OHOS { -namespace DistributedHardware { -class DistributedHardwareProxyTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp(); - virtual void TearDown(); - - class TestDistributedHardwareStub : public - OHOS::DistributedHardware::DistributedHardwareStub { - public: - TestDistributedHardwareStub() = default; - virtual ~TestDistributedHardwareStub() = default; - int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener); - int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener); - int32_t PublishMessage(const DHTopic topic, const std::string &msg); - std::string QueryLocalSysSpec(QueryLocalSysSpecType spec); - - int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId); - int32_t ReleaseAVCenter(int32_t engineId); - int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId); - int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event); - int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback); - int32_t NotifySourceRemoteSinkStarted(std::string &deviceId); - int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId); - int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId); - int32_t StopDistributedHardware(DHType dhType, const std::string &networkId); - int32_t GetDistributedHardware(const std::string &networkId, std::vector &descriptors); - int32_t RegisterDHStatusListener(sptr listener); - int32_t UnregisterDHStatusListener(sptr listener); - int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener); - int32_t UnregisterDHStatusListener(const std::string &networkId, sptr listener); - int32_t EnableSink(const std::vector &descriptors); - int32_t DisableSink(const std::vector &descriptors); - int32_t EnableSource(const std::string &networkId, const std::vector &descriptors); - int32_t DisableSource(const std::string &networkId, const std::vector &descriptors); - }; -}; - -class MockIPublisherListener : public IPublisherListener { -public: - sptr AsObject() - { - return nullptr; - } - - void OnMessage(const DHTopic topic, const std::string& message) - { - (void)topic; - (void)message; - } -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_PROXY_TEST_H \ No newline at end of file diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp deleted file mode 100644 index 4a56ec13..00000000 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp +++ /dev/null @@ -1,522 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_proxy_test.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void DistributedHardwareProxyTest::SetUpTestCase() -{ -} - -void DistributedHardwareProxyTest::TearDownTestCase() -{ -} - -void DistributedHardwareProxyTest::SetUp() {} - -void DistributedHardwareProxyTest::TearDown() {} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterPublisherListener(const DHTopic topic, - const sptr listener) -{ - (void)topic; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::UnregisterPublisherListener(const DHTopic topic, - const sptr listener) -{ - (void)topic; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::PublishMessage(const DHTopic topic, - const std::string &msg) -{ - (void)topic; - (void)msg; - return DH_FWK_SUCCESS; -} - -std::string DistributedHardwareProxyTest::TestDistributedHardwareStub::QueryLocalSysSpec(QueryLocalSysSpecType spec) -{ - (void)spec; - return ""; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::InitializeAVCenter(const TransRole &transRole, - int32_t &engineId) -{ - (void)transRole; - (void)engineId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::ReleaseAVCenter(int32_t engineId) -{ - (void)engineId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::CreateControlChannel(int32_t engineId, - const std::string &peerDevId) -{ - (void)engineId; - (void)peerDevId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::NotifyAVCenter(int32_t engineId, - const AVTransEvent &event) -{ - (void)engineId; - (void)event; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterCtlCenterCallback(int32_t engineId, - const sptr callback) -{ - (void)engineId; - (void)callback; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::NotifySourceRemoteSinkStarted(std::string &deviceId) -{ - (void)deviceId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::PauseDistributedHardware(DHType dhType, - const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::ResumeDistributedHardware(DHType dhType, - const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::StopDistributedHardware(DHType dhType, - const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::GetDistributedHardware( - const std::string &networkId, std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterDHStatusListener( - sptr listener) -{ - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::UnregisterDHStatusListener( - sptr listener) -{ - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterDHStatusListener( - const std::string &networkId, sptr listener) -{ - (void)networkId; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::UnregisterDHStatusListener( - const std::string &networkId, sptr listener) -{ - (void)networkId; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::EnableSink( - const std::vector &descriptors) -{ - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::DisableSink( - const std::vector &descriptors) -{ - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::EnableSource( - const std::string &networkId, const std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::DisableSource( - const std::string &networkId, const std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} - -/** - * @tc.name: RegisterPublisherListener_001 - * @tc.desc: Verify the RegisterPublisherListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_001, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_MIN; - sptr listener = nullptr; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.RegisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL, ret); - - sptr listener1(new MockIPublisherListener()); - ASSERT_TRUE(listener1 != nullptr); - ret = dhProxy.RegisterPublisherListener(topic, listener1); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - topic = DHTopic::TOPIC_MAX; - ret = dhProxy.RegisterPublisherListener(topic, listener1); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); -} - -/** - * @tc.name: RegisterAbilityListener_002 - * @tc.desc: Verify the RegisterAbilityListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_002, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; - sptr listener(new MockIPublisherListener()); - ASSERT_TRUE(listener != nullptr); - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.RegisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL, ret); -} - -/** - * @tc.name: UnregisterPublisherListener_001 - * @tc.desc: Verify the UnregisterPublisherListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_001, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_MIN; - sptr listener = nullptr; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.UnregisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL, ret); - - sptr listener1(new MockIPublisherListener()); - ASSERT_TRUE(listener1 != nullptr); - ret = dhProxy.UnregisterPublisherListener(topic, listener1); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - topic = DHTopic::TOPIC_MAX; - ret = dhProxy.RegisterPublisherListener(topic, listener1); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); -} - -/** - * @tc.name: UnregisterPublisherListener_002 - * @tc.desc: Verify the UnregisterPublisherListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_003, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; - sptr listener(new MockIPublisherListener()); - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - int32_t ret = dhProxy.UnregisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL, ret); -} - -/** - * @tc.name: PublishMessage_001 - * @tc.desc: Verify the PublishMessage function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, PublishMessage_001, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_MIN; - std::string msg = ""; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - topic = DHTopic::TOPIC_MAX; - ret = dhProxy.PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); -} - -/** - * @tc.name: PublishMessage_002 - * @tc.desc: Verify the PublishMessage function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, PublishMessage_002, TestSize.Level0) -{ - DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; - std::string msg = ""; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_SERVICE_MSG_INVALID, ret); - - msg = "msg_test"; - ret = dhProxy.PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: QueryLocalSysSpec_001 - * @tc.desc: Verify the QueryLocalSysSpec function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_001, TestSize.Level0) -{ - QueryLocalSysSpecType spec = QueryLocalSysSpecType::MIN; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.QueryLocalSysSpec(spec); - EXPECT_EQ("", ret); - - spec = QueryLocalSysSpecType::MAX; - ret = dhProxy.QueryLocalSysSpec(spec); - EXPECT_EQ("", ret); -} - -HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_002, TestSize.Level0) -{ - QueryLocalSysSpecType spec = QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.QueryLocalSysSpec(spec); - EXPECT_EQ("", ret); -} - -/** - * @tc.name: InitializeAVCenter_001 - * @tc.desc: Verify the InitializeAVCenter function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, InitializeAVCenter_001, TestSize.Level0) -{ - TransRole transRole = TransRole::UNKNOWN; - int32_t engineId = 0; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.InitializeAVCenter(transRole, engineId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: ReleaseAVCenter_001 - * @tc.desc: Verify the ReleaseAVCenter function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, ReleaseAVCenter_001, TestSize.Level0) -{ - int32_t engineId = 0; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.ReleaseAVCenter(engineId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: CreateControlChannel_001 - * @tc.desc: Verify the CreateControlChannel function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, CreateControlChannel_001, TestSize.Level0) -{ - int32_t engineId = 0; - std::string peerDevId = "peerDevId_test"; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.CreateControlChannel(engineId, peerDevId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: NotifyAVCenter_001 - * @tc.desc: Verify the NotifyAVCenter function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, NotifyAVCenter_001, TestSize.Level0) -{ - int32_t engineId = 0; - AVTransEvent event; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.NotifyAVCenter(engineId, event); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: RegisterCtlCenterCallback_001 - * @tc.desc: Verify the RegisterCtlCenterCallback function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, RegisterCtlCenterCallback_001, TestSize.Level0) -{ - int32_t engineId = 0; - sptr callback = nullptr; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.RegisterCtlCenterCallback(engineId, callback); - EXPECT_EQ(ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL, ret); -} - -/** - * @tc.name: NotifySourceRemoteSinkStarted_001 - * @tc.desc: Verify the NotifySourceRemoteSinkStarted function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, NotifySourceRemoteSinkStarted_001, TestSize.Level0) -{ - std::string deviceId = "devid_test"; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.NotifySourceRemoteSinkStarted(deviceId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: PauseDistributedHardware_001 - * @tc.desc: Verify the PauseDistributedHardware function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, PauseDistributedHardware_001, TestSize.Level0) -{ - DHType dhType = DHType::CAMERA; - std::string networkId = ""; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.PauseDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - networkId = "123456789"; - ret = dhProxy.PauseDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: ResumeDistributedHardware_001 - * @tc.desc: Verify the ResumeDistributedHardware function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, ResumeDistributedHardware_001, TestSize.Level0) -{ - DHType dhType = DHType::CAMERA; - std::string networkId = ""; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.ResumeDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - networkId = "123456789"; - ret = dhProxy.ResumeDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} - -/** - * @tc.name: StopDistributedHardware_001 - * @tc.desc: Verify the StopDistributedHardware function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, StopDistributedHardware_001, TestSize.Level0) -{ - DHType dhType = DHType::CAMERA; - std::string networkId = ""; - sptr dhStubPtr(new TestDistributedHardwareStub()); - ASSERT_TRUE(dhStubPtr != nullptr); - DistributedHardwareProxy dhProxy(dhStubPtr); - auto ret = dhProxy.StopDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - - networkId = "123456789"; - ret = dhProxy.StopDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/BUILD.gn b/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/BUILD.gn index 04335ee1..ff0dc189 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("PublisherListenerStubTest") { configs = [ ":module_private_config" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${innerkits_path}:libdhfwk_sdk", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index e5ad6f8d..90ce03dd 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("hardwaremanager") { deps = [ "${distributedhardwarefwk_path}/interfaces/inner_kits:libdhfwk_sdk", + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", ] diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index 0f8256f9..df7df81a 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -74,7 +74,6 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/distributed_hardware_manager.cpp", "src/distributed_hardware_manager_factory.cpp", "src/distributed_hardware_service.cpp", - "src/distributed_hardware_stub.cpp", "src/hidumphelper/enabled_comps_dump.cpp", "src/hidumphelper/hidump_helper.cpp", "src/ipc/hardware_status_listener_proxy.cpp", @@ -114,7 +113,10 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/versionmanager/version_manager.cpp", ] - deps = [ "${utils_path}:distributedhardwareutils" ] + deps = [ + "${innerkits_path}:dhfwk_idl_hardware_source", + "${utils_path}:distributedhardwareutils", + ] defines = [ "HI_LOG_ENABLE", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 730b6f7e..7ce3ed09 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -30,6 +30,7 @@ #include "dh_comm_tool.h" #include "event_handler.h" #include "idistributed_hardware.h" +#include "ihardware_status_listener.h" #include "idistributed_hardware_sink.h" #include "idistributed_hardware_source.h" #include "impl_utils.h" diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index 827ff5ec..29ccd3b2 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -37,31 +37,38 @@ DECLARE_SYSTEM_ABILITY(DistributedHardwareService); public: DistributedHardwareService(int32_t saId, bool runOnCreate); ~DistributedHardwareService() = default; - int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener) override; - int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener) override; - int32_t PublishMessage(const DHTopic topic, const std::string &msg) override; - std::string QueryLocalSysSpec(const QueryLocalSysSpecType spec) override; + int32_t RegisterPublisherListener(uint32_t topic, const sptr& listener) override; + int32_t UnregisterPublisherListener(uint32_t topic, const sptr& listener) override; + int32_t PublishMessage(uint32_t topic, const std::string &msg) override; + int32_t QueryLocalSysSpec(uint32_t spec, std::string& funcResult) override; int Dump(int32_t fd, const std::vector& args) override; - int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) override; + int32_t InitializeAVCenter(uint32_t transRole, int32_t &engineId) override; int32_t ReleaseAVCenter(int32_t engineId) override; int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) override; - int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) override; - int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback) override; - int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) override; - int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) override; - int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) override; - int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) override; + int32_t NotifyAVCenter(int32_t engineId, const AVTransEventExt &event) override; + int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr& callback) override; + int32_t NotifySourceRemoteSinkStarted(const std::string &deviceId) override; + int32_t PauseDistributedHardware(uint32_t dhType, const std::string &networkId) override; + int32_t ResumeDistributedHardware(uint32_t dhType, const std::string &networkId) override; + int32_t StopDistributedHardware(uint32_t dhType, const std::string &networkId) override; int32_t GetDistributedHardware(const std::string &networkId, std::vector &descriptors) override; - int32_t RegisterDHStatusListener(sptr listener) override; - int32_t UnregisterDHStatusListener(sptr listener) override; - int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener) override; - int32_t UnregisterDHStatusListener(const std::string &networkId, sptr listener) override; + int32_t RegisterDHStatusListener(const sptr& listener) override; + int32_t UnregisterDHStatusListener(const sptr& listener) override; + int32_t RegisterDHStatusListenerOverload(const std::string& networkId, + const sptr& listener) override; + int32_t UnregisterDHStatusListenerOverload(const std::string &networkId, + const sptr& listener) override; int32_t EnableSink(const std::vector &descriptors) override; int32_t DisableSink(const std::vector &descriptors) override; int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) override; int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) override; + bool ValidTopic(uint32_t topic); + bool ValidQueryLocalSpec(uint32_t spec); + bool HasAccessDHPermission(); + bool IsSystemHap(); + protected: void OnStart() override; void OnStop() override; @@ -72,6 +79,7 @@ private: void InitLocalDevInfo(); bool DoBusinessInit(); bool IsDepSAStart(); + int32_t QueryLocalSysSpecInternal(uint32_t spec, std::string& funcResult); private: bool registerToService_ = false; @@ -80,4 +88,4 @@ private: }; } // namespace DistributedHardware } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h b/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h deleted file mode 100644 index 4f3641d0..00000000 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_STUB_H -#define OHOS_DISTRIBUTED_HARDWARE_STUB_H - -#include "iremote_stub.h" - -#include "idistributed_hardware.h" - -namespace OHOS { -namespace DistributedHardware { -class DistributedHardwareStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t RegisterPublisherListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t UnregisterPublisherListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t PublishMessageInner(MessageParcel &data, MessageParcel &reply); - int32_t QueryLocalSysSpecInner(MessageParcel &data, MessageParcel &reply); - - int32_t InitializeAVCenterInner(MessageParcel &data, MessageParcel &reply); - int32_t ReleaseAVCenterInner(MessageParcel &data, MessageParcel &reply); - int32_t CreateControlChannelInner(MessageParcel &data, MessageParcel &reply); - int32_t NotifyAVCenterInner(MessageParcel &data, MessageParcel &reply); - int32_t RegisterControlCenterCallbackInner(MessageParcel &data, MessageParcel &reply); - int32_t HandleNotifySourceRemoteSinkStarted(MessageParcel &data, MessageParcel &reply); - int32_t PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t GetDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t RegisterDHStatusSinkListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t UnregisterDHStatusSinkListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t RegisterDHStatusSourceListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t UnregisterDHStatusSourceListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t EnableSinkInner(MessageParcel &data, MessageParcel &reply); - int32_t DisableSinkInner(MessageParcel &data, MessageParcel &reply); - int32_t EnableSourceInner(MessageParcel &data, MessageParcel &reply); - int32_t DisableSourceInner(MessageParcel &data, MessageParcel &reply); - - int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); - int32_t WriteDescriptors(MessageParcel &data, const std::vector &descriptors); - int32_t OnRemoteRequestEx(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); - - bool ValidTopic(uint32_t topic); - bool ValidQueryLocalSpec(uint32_t spec); - bool HasAccessDHPermission(); - bool IsSystemHap(); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_STUB_H diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 30d48e10..eb499cb6 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -42,6 +42,11 @@ #include "publisher.h" #include "task_executor.h" #include "task_factory.h" +#include "accesstoken_kit.h" +#include "ipc_skeleton.h" +#include "tokenid_kit.h" +#include "device_manager.h" +#include "av_trans_log.h" namespace OHOS { namespace DistributedHardware { @@ -54,6 +59,40 @@ namespace { const std::string LOCAL_NETWORKID_ALIAS = "local"; } +bool DistributedHardwareService::ValidTopic(uint32_t topic) +{ + if (topic <= (uint32_t)DHTopic::TOPIC_MIN || topic >= (uint32_t)DHTopic::TOPIC_MAX) { + return false; + } + return true; +} + +bool DistributedHardwareService::ValidQueryLocalSpec(uint32_t spec) +{ + if (spec <= (uint32_t)QueryLocalSysSpecType::MIN || spec >= (uint32_t)QueryLocalSysSpecType::MAX) { + return false; + } + return true; +} + +bool DistributedHardwareService::HasAccessDHPermission() +{ + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; + int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, + permissionName); + return (result == Security::AccessToken::PERMISSION_GRANTED); +} + +bool DistributedHardwareService::IsSystemHap() +{ + uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); + if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + return false; + } + return true; +} + DistributedHardwareService::DistributedHardwareService(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate) { @@ -162,35 +201,76 @@ void DistributedHardwareService::OnStop() registerToService_ = false; } -int32_t DistributedHardwareService::RegisterPublisherListener(const DHTopic topic, - const sptr listener) +int32_t DistributedHardwareService::RegisterPublisherListener(uint32_t topic, + const sptr& listener) { - Publisher::GetInstance().RegisterListener(topic, listener); + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + if (!ValidTopic(topic)) { + DHLOGE("Topic invalid: %{public}" PRIu32, topic); + return ERR_DH_FWK_PARA_INVALID; + } + + Publisher::GetInstance().RegisterListener((DHTopic)topic, listener); return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::UnregisterPublisherListener(const DHTopic topic, - const sptr listener) +int32_t DistributedHardwareService::UnregisterPublisherListener(uint32_t topic, + const sptr& listener) { - Publisher::GetInstance().UnregisterListener(topic, listener); + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + if (!ValidTopic(topic)) { + DHLOGE("Topic invalid: %{public}" PRIu32, topic); + return ERR_DH_FWK_PARA_INVALID; + } + + Publisher::GetInstance().UnregisterListener((DHTopic)topic, listener); return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::PublishMessage(const DHTopic topic, const std::string &msg) +int32_t DistributedHardwareService::PublishMessage(uint32_t topic, const std::string &msg) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + if (!ValidTopic(topic)) { + DHLOGE("Topic invalid: %{public}" PRIu32, topic); + return ERR_DH_FWK_PARA_INVALID; + } + DHContext::GetInstance(); - Publisher::GetInstance().PublishMessage(topic, msg); + Publisher::GetInstance().PublishMessage((DHTopic)topic, msg); return DH_FWK_SUCCESS; } -std::string DistributedHardwareService::QueryLocalSysSpec(const QueryLocalSysSpecType spec) +int32_t DistributedHardwareService::QueryLocalSysSpec(uint32_t spec, std::string& funcResult) +{ + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + if (!ValidQueryLocalSpec(spec)) { + DHLOGE("Spec invalid: %{public}" PRIu32, spec); + return ERR_DH_FWK_PARA_INVALID; + } + + return QueryLocalSysSpecInternal(spec, funcResult); +} + +int32_t DistributedHardwareService::QueryLocalSysSpecInternal(uint32_t spec, std::string& funcResult) { DeviceInfo localDevInfo = DHContext::GetInstance().GetDeviceInfo(); std::vector> resInfos; CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(localDevInfo.deviceId, resInfos); DHType targetDhType = DHType::UNKNOWN; std::string targetKey = ""; - switch (spec) { + switch ((QueryLocalSysSpecType)spec) { case QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER: targetKey = KEY_HISTREAMER_AUDIO_ENCODER; targetDhType = DHType::AUDIO; @@ -215,7 +295,7 @@ std::string DistributedHardwareService::QueryLocalSysSpec(const QueryLocalSysSpe (uint32_t)targetDhType); if (targetDhType == DHType::UNKNOWN) { DHLOGE("Can not find matched dhtype"); - return ""; + return -1; } std::string attrs = ""; @@ -228,10 +308,11 @@ std::string DistributedHardwareService::QueryLocalSysSpec(const QueryLocalSysSpe } if (attrs.empty()) { DHLOGE("Can not find dh attrs"); - return ""; + return -1; } - return QueryDhSysSpec(targetKey, attrs); + funcResult = QueryDhSysSpec(targetKey, attrs); + return 0; } std::string DistributedHardwareService::QueryDhSysSpec(const std::string &targetKey, std::string &attrs) @@ -252,34 +333,82 @@ std::string DistributedHardwareService::QueryDhSysSpec(const std::string &target return result; } -int32_t DistributedHardwareService::InitializeAVCenter(const TransRole &transRole, int32_t &engineId) +int32_t DistributedHardwareService::InitializeAVCenter(uint32_t transRole, int32_t &engineId) { - return AVTransControlCenter::GetInstance().InitializeAVCenter(transRole, engineId); + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + + return AVTransControlCenter::GetInstance().InitializeAVCenter((TransRole)transRole, engineId); } int32_t DistributedHardwareService::ReleaseAVCenter(int32_t engineId) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + return AVTransControlCenter::GetInstance().ReleaseAVCenter(engineId); } int32_t DistributedHardwareService::CreateControlChannel(int32_t engineId, const std::string &peerDevId) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + return AVTransControlCenter::GetInstance().CreateControlChannel(engineId, peerDevId); } -int32_t DistributedHardwareService::NotifyAVCenter(int32_t engineId, const AVTransEvent &event) +int32_t DistributedHardwareService::NotifyAVCenter(int32_t engineId, const AVTransEventExt &event) { - return AVTransControlCenter::GetInstance().NotifyAVCenter(engineId, event); + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + + AVTransEvent AVTE; + AVTE.type = event.type; + AVTE.content = event.content; + AVTE.peerDevId = event.peerDevId; + return AVTransControlCenter::GetInstance().NotifyAVCenter(engineId, AVTE); } int32_t DistributedHardwareService::RegisterCtlCenterCallback(int32_t engineId, - const sptr callback) + const sptr& callback) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + return AVTransControlCenter::GetInstance().RegisterCtlCenterCallback(engineId, callback); } -int32_t DistributedHardwareService::NotifySourceRemoteSinkStarted(std::string &deviceId) +int32_t DistributedHardwareService::NotifySourceRemoteSinkStarted(const std::string &deviceId) { + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + if (!IsIdLengthValid(deviceId)) { + DHLOGE("the deviceId is invalid, %{public}s", GetAnonyString(deviceId).c_str()); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + std::string networkId = ""; + DeviceManager::GetInstance().GetNetworkIdByUdid(DH_FWK_PKG_NAME, deviceId, networkId); + if (!IsIdLengthValid(networkId)) { + DHLOGE("the networkId is invalid, %{public}s", GetAnonyString(networkId).c_str()); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + uint32_t dAccessToken = Security::AccessToken::AccessTokenKit::AllocLocalTokenID(networkId, callerToken); + const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; + int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(dAccessToken, permissionName); + if (result != Security::AccessToken::PERMISSION_GRANTED) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + DHLOGI("DistributedHardwareService NotifySourceRemoteSinkStarted Init DHMS Ready Start."); Publisher::GetInstance().PublishMessage(DHTopic::TOPIC_INIT_DHMS_READY, deviceId); DHLOGI("DistributedHardwareService NotifySourceRemoteSinkStarted Init DHMS Ready End."); @@ -309,55 +438,79 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); - if (sinkMap.find(dhType) == sinkMap.end()) { - DHLOGE("PauseDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); + if (sinkMap.find((DHType)dhType) == sinkMap.end()) { + DHLOGE("PauseDistributedHardware for DHType: %{public}u not init sink handler", dhType); return ERR_DH_FWK_PARA_INVALID; } - int32_t ret = sinkMap[dhType]->PauseDistributedHardware(networkId); + int32_t ret = sinkMap[(DHType)dhType]->PauseDistributedHardware(networkId); if (ret != 0) { - DHLOGE("PauseDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret); + DHLOGE("PauseDistributedHardware for DHType: %{public}u failed, ret: %{public}d", dhType, ret); return ret; } return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, const std::string &networkId) +int32_t DistributedHardwareService::ResumeDistributedHardware(uint32_t dhType, const std::string &networkId) { + if (!IsSystemHap()) { + DHLOGE("GetCallerProcessName not system hap."); + return ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL; + } + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); - if (sinkMap.find(dhType) == sinkMap.end()) { - DHLOGE("ResumeDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); + if (sinkMap.find((DHType)dhType) == sinkMap.end()) { + DHLOGE("ResumeDistributedHardware for DHType: %{public}u not init sink handler", dhType); return ERR_DH_FWK_PARA_INVALID; } - int32_t ret = sinkMap[dhType]->ResumeDistributedHardware(networkId); + int32_t ret = sinkMap[(DHType)dhType]->ResumeDistributedHardware(networkId); if (ret != 0) { - DHLOGE("ResumeDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret); + DHLOGE("ResumeDistributedHardware for DHType: %{public}u failed, ret: %{public}d", dhType, ret); return ret; } return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const std::string &networkId) +int32_t DistributedHardwareService::StopDistributedHardware(uint32_t dhType, const std::string &networkId) { + if (!IsSystemHap()) { + DHLOGE("GetCallerProcessName not system hap."); + return ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL; + } + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); - if (sinkMap.find(dhType) == sinkMap.end()) { - DHLOGE("StopDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); + if (sinkMap.find((DHType)dhType) == sinkMap.end()) { + DHLOGE("StopDistributedHardware for DHType: %{public}u not init sink handler", dhType); return ERR_DH_FWK_PARA_INVALID; } - int32_t ret = sinkMap[dhType]->StopDistributedHardware(networkId); + int32_t ret = sinkMap[(DHType)dhType]->StopDistributedHardware(networkId); if (ret != 0) { - DHLOGE("StopDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret); + DHLOGE("StopDistributedHardware for DHType: %{public}u failed, ret: %{public}d", dhType, ret); return ret; } return DH_FWK_SUCCESS; @@ -366,6 +519,10 @@ int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const int32_t DistributedHardwareService::GetDistributedHardware( const std::string &networkId, std::vector &descriptors) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -401,8 +558,12 @@ int32_t DistributedHardwareService::GetDistributedHardware( return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::RegisterDHStatusListener(sptr listener) +int32_t DistributedHardwareService::RegisterDHStatusListener(const sptr& listener) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } int32_t callingUid = IPCSkeleton::GetCallingUid(); int32_t callingPid = IPCSkeleton::GetCallingPid(); int32_t ret = ComponentManager::GetInstance().RegisterDHStatusListener(listener, callingUid, callingPid); @@ -413,8 +574,12 @@ int32_t DistributedHardwareService::RegisterDHStatusListener(sptr listener) +int32_t DistributedHardwareService::UnregisterDHStatusListener(const sptr& listener) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } int32_t callingUid = IPCSkeleton::GetCallingUid(); int32_t callingPid = IPCSkeleton::GetCallingPid(); int32_t ret = ComponentManager::GetInstance().UnregisterDHStatusListener(listener, callingUid, callingPid); @@ -425,9 +590,13 @@ int32_t DistributedHardwareService::UnregisterDHStatusListener(sptr listener) +int32_t DistributedHardwareService::RegisterDHStatusListenerOverload( + const std::string &networkId, const sptr& listener) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -442,9 +611,13 @@ int32_t DistributedHardwareService::RegisterDHStatusListener( return DH_FWK_SUCCESS; } -int32_t DistributedHardwareService::UnregisterDHStatusListener( - const std::string &networkId, sptr listener) +int32_t DistributedHardwareService::UnregisterDHStatusListenerOverload( + const std::string &networkId, const sptr& listener) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -461,6 +634,10 @@ int32_t DistributedHardwareService::UnregisterDHStatusListener( int32_t DistributedHardwareService::EnableSink(const std::vector &descriptors) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } for (const auto &descriptor : descriptors) { TaskParam taskParam = { .dhId = descriptor.id, @@ -478,6 +655,10 @@ int32_t DistributedHardwareService::EnableSink(const std::vector & int32_t DistributedHardwareService::DisableSink(const std::vector &descriptors) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } for (const auto &descriptor : descriptors) { TaskParam taskParam = { .dhId = descriptor.id, @@ -496,6 +677,10 @@ int32_t DistributedHardwareService::DisableSink(const std::vector int32_t DistributedHardwareService::EnableSource( const std::string &networkId, const std::vector &descriptors) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -518,6 +703,10 @@ int32_t DistributedHardwareService::EnableSource( int32_t DistributedHardwareService::DisableSource( const std::string &networkId, const std::vector &descriptors) { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp deleted file mode 100644 index d1466d0f..00000000 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp +++ /dev/null @@ -1,653 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_stub.h" - -#include - -#include "accesstoken_kit.h" -#include "ipc_skeleton.h" -#include "tokenid_kit.h" - -#include "device_manager.h" - -#include "anonymous_string.h" -#include "constants.h" -#include "dhardware_ipc_interface_code.h" -#include "dh_context.h" -#include "dh_utils_tool.h" -#include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" -#include "publisher_listener_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -int32_t DistributedHardwareStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - DHLOGE("IPC Token valid fail!"); - return ERR_INVALID_DATA; - } - switch (code) { - case static_cast(DHMsgInterfaceCode::REG_PUBLISHER_LISTNER): { - return RegisterPublisherListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::UNREG_PUBLISHER_LISTENER): { - return UnregisterPublisherListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::PUBLISH_MESSAGE): { - return PublishMessageInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::INIT_CTL_CEN): { - return InitializeAVCenterInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::RELEASE_CTL_CEN): { - return ReleaseAVCenterInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::CREATE_CTL_CEN_CHANNEL): { - return CreateControlChannelInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::NOTIFY_AV_EVENT): { - return NotifyAVCenterInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::REGISTER_CTL_CEN_CALLBACK): { - return RegisterControlCenterCallbackInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::QUERY_LOCAL_SYS_SPEC): { - return QueryLocalSysSpecInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED): { - return HandleNotifySourceRemoteSinkStarted(data, reply); - } - case static_cast(DHMsgInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE): { - return PauseDistributedHardwareInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::RESUME_DISTRIBUTED_HARDWARE): { - return ResumeDistributedHardwareInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::STOP_DISTRIBUTED_HARDWARE): { - return StopDistributedHardwareInner(data, reply); - } - default: - return OnRemoteRequestEx(code, data, reply, option); - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::RegisterPublisherListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - uint32_t topicInt = data.ReadUint32(); - if (!ValidTopic(topicInt)) { - DHLOGE("Topic invalid: %{public}" PRIu32, topicInt); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - - DHTopic topic = (DHTopic)topicInt; - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Register publisher listener is null"); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - DHLOGI("Register listener, topic: %{public}" PRIu32, (uint32_t)topic); - RegisterPublisherListener(topic, listener); - reply.WriteInt32(DH_FWK_SUCCESS); - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::UnregisterPublisherListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - uint32_t topicInt = data.ReadUint32(); - if (!ValidTopic(topicInt)) { - DHLOGE("Topic invalid: %{public}" PRIu32, topicInt); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - - DHTopic topic = (DHTopic)topicInt; - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Unregister publisher listener is null"); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - DHLOGI("Unregister listener, topic: %{public}" PRIu32, (uint32_t)topic); - UnregisterPublisherListener(topic, listener); - reply.WriteInt32(DH_FWK_SUCCESS); - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::PublishMessageInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - uint32_t topicInt = data.ReadUint32(); - if (!ValidTopic(topicInt)) { - DHLOGE("Topic invalid: %{public}" PRIu32, topicInt); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - - DHTopic topic = (DHTopic)topicInt; - std::string message = data.ReadString(); - DHLOGI("Publish message, topic: %{public}" PRIu32, (uint32_t)topic); - PublishMessage(topic, message); - reply.WriteInt32(DH_FWK_SUCCESS); - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::QueryLocalSysSpecInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - uint32_t specInt = data.ReadUint32(); - if (!ValidQueryLocalSpec(specInt)) { - DHLOGE("Spec invalid: %{public}" PRIu32, specInt); - reply.WriteInt32(ERR_DH_FWK_PARA_INVALID); - return ERR_DH_FWK_PARA_INVALID; - } - - QueryLocalSysSpecType spec = (QueryLocalSysSpecType)specInt; - DHLOGI("Query Local Sys Spec: %{public}" PRIu32, (uint32_t)spec); - std::string res = QueryLocalSysSpec(spec); - DHLOGI("Get Local spec: %{public}s", res.c_str()); - reply.WriteString(res); - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::InitializeAVCenterInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - TransRole transRole = (TransRole)(data.ReadUint32()); - int32_t engineId = 0; - int32_t ret = InitializeAVCenter(transRole, engineId); - if (!reply.WriteInt32(engineId)) { - DHLOGE("Write engine id failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::ReleaseAVCenterInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - int32_t engineId = data.ReadInt32(); - int32_t ret = ReleaseAVCenter(engineId); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::CreateControlChannelInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - int32_t engineId = data.ReadInt32(); - std::string peerDevId = data.ReadString(); - int32_t ret = CreateControlChannel(engineId, peerDevId); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::NotifyAVCenterInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - int32_t engineId = data.ReadInt32(); - uint32_t type = data.ReadUint32(); - std::string content = data.ReadString(); - std::string peerDevId = data.ReadString(); - int32_t ret = NotifyAVCenter(engineId, AVTransEvent{ (EventType)type, content, peerDevId }); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::RegisterControlCenterCallbackInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - int32_t engineId = data.ReadInt32(); - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - DHLOGE("Input av control center callback is null"); - return ERR_DH_FWK_PARA_INVALID; - } - - int32_t ret = RegisterCtlCenterCallback(engineId, callback); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t OHOS::DistributedHardware::DistributedHardwareStub::HandleNotifySourceRemoteSinkStarted(MessageParcel &data, - MessageParcel &reply) -{ - Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - std::string udid = data.ReadString(); - if (!IsIdLengthValid(udid)) { - DHLOGE("the udid is invalid, %{public}s", GetAnonyString(udid).c_str()); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string networkId = ""; - DeviceManager::GetInstance().GetNetworkIdByUdid(DH_FWK_PKG_NAME, udid, networkId); - if (!IsIdLengthValid(networkId)) { - DHLOGE("the networkId is invalid, %{public}s", GetAnonyString(networkId).c_str()); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - uint32_t dAccessToken = Security::AccessToken::AccessTokenKit::AllocLocalTokenID(networkId, callerToken); - const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; - int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(dAccessToken, permissionName); - if (result != Security::AccessToken::PERMISSION_GRANTED) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - - DHLOGI("DistributedHardwareStub HandleNotifySourceRemoteSinkStarted Start."); - int32_t ret = NotifySourceRemoteSinkStarted(udid); - if (!reply.WriteInt32(ret)) { - DHLOGE("write ret failed."); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - DHLOGI("DistributedHardwareStub HandleNotifySourceRemoteSinkStarted End."); - return DH_FWK_SUCCESS; -} - -bool DistributedHardwareStub::ValidTopic(uint32_t topic) -{ - if (topic <= (uint32_t)DHTopic::TOPIC_MIN || topic >= (uint32_t)DHTopic::TOPIC_MAX) { - return false; - } - return true; -} - -bool DistributedHardwareStub::ValidQueryLocalSpec(uint32_t spec) -{ - if (spec <= (uint32_t)QueryLocalSysSpecType::MIN || spec >= (uint32_t)QueryLocalSysSpecType::MAX) { - return false; - } - return true; -} - -int32_t DistributedHardwareStub::PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) -{ - if (!IsSystemHap()) { - DHLOGE("GetCallerProcessName not system hap."); - return ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL; - } - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - DHType dhType = static_cast(data.ReadInt32()); - std::string networkId = data.ReadString(); - int32_t ret = PauseDistributedHardware(dhType, networkId); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) -{ - if (!IsSystemHap()) { - DHLOGE("GetCallerProcessName not system hap."); - return ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL; - } - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - DHType dhType = static_cast(data.ReadInt32()); - std::string networkId = data.ReadString(); - int32_t ret = ResumeDistributedHardware(dhType, networkId); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) -{ - if (!IsSystemHap()) { - DHLOGE("GetCallerProcessName not system hap."); - return ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL; - } - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - DHType dhType = static_cast(data.ReadInt32()); - std::string networkId = data.ReadString(); - int32_t ret = StopDistributedHardware(dhType, networkId); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::GetDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::vector descriptors; - std::string networkId = data.ReadString(); - int32_t ret = GetDistributedHardware(networkId, descriptors); - if (WriteDescriptors(reply, descriptors)) { - DHLOGE("WriteDescriptors failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::RegisterDHStatusSinkListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Input distributed hardware status sink listener is null"); - return ERR_DH_FWK_PARA_INVALID; - } - int32_t ret = RegisterDHStatusListener(listener); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::UnregisterDHStatusSinkListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Input distributed hardware status sink listener is null"); - return ERR_DH_FWK_PARA_INVALID; - } - int32_t ret = UnregisterDHStatusListener(listener); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::RegisterDHStatusSourceListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string networkId = data.ReadString(); - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Input distributed hardware status source listener is null"); - return ERR_DH_FWK_PARA_INVALID; - } - int32_t ret = RegisterDHStatusListener(networkId, listener); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::UnregisterDHStatusSourceListenerInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string networkId = data.ReadString(); - sptr listener = iface_cast(data.ReadRemoteObject()); - if (listener == nullptr) { - DHLOGE("Input distributed hardware status source listener is null"); - return ERR_DH_FWK_PARA_INVALID; - } - int32_t ret = UnregisterDHStatusListener(networkId, listener); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::EnableSinkInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::vector descriptors; - ReadDescriptors(data, descriptors); - int32_t ret = EnableSink(descriptors); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::DisableSinkInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::vector descriptors; - ReadDescriptors(data, descriptors); - int32_t ret = DisableSink(descriptors); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::EnableSourceInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string networkId = data.ReadString(); - std::vector descriptors; - ReadDescriptors(data, descriptors); - int32_t ret = EnableSource(networkId, descriptors); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::DisableSourceInner(MessageParcel &data, MessageParcel &reply) -{ - if (!HasAccessDHPermission()) { - DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); - return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; - } - std::string networkId = data.ReadString(); - std::vector descriptors; - ReadDescriptors(data, descriptors); - int32_t ret = DisableSource(networkId, descriptors); - if (!reply.WriteInt32(ret)) { - DHLOGE("Write ret code failed!"); - return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; - } - return DH_FWK_SUCCESS; -} - -int32_t DistributedHardwareStub::ReadDescriptors(MessageParcel &data, std::vector &descriptors) -{ - int32_t size = data.ReadInt32(); - if (size > int32_t(MAX_DH_DESCRIPTOR_ARRAY_SIZE)) { - DHLOGE("The array descriptors are too large, size: %{public}d!", size); - return ERR_DH_FWK_PARA_INVALID; - } - for (int32_t i = 0; i < size; ++i) { - DHDescriptor descriptor; - descriptor.dhType = static_cast(data.ReadInt32()); - descriptor.id = data.ReadString(); - descriptors.push_back(descriptor); - } - return NO_ERROR; -} - -int32_t DistributedHardwareStub::WriteDescriptors(MessageParcel &data, const std::vector &descriptors) -{ - int32_t size = (int32_t)descriptors.size(); - if (size > int32_t(MAX_DH_DESCRIPTOR_ARRAY_SIZE)) { - DHLOGE("The array descriptors are too large, size: %{public}d!", size); - return ERR_DH_FWK_PARA_INVALID; - } - if (!data.WriteInt32(size)) { - DHLOGE("Write descriptors size failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - for (int32_t i = 0; i < size; ++i) { - const DHDescriptor &descriptor = descriptors.at(i); - int32_t type = static_cast(descriptor.dhType); - if (!data.WriteInt32(type)) { - DHLOGE("Write descriptor.dhType failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - if (!data.WriteString(descriptor.id)) { - DHLOGE("Write descriptor.id failed!"); - return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; - } - } - return NO_ERROR; -} - -int32_t DistributedHardwareStub::OnRemoteRequestEx(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - switch (code) { - case static_cast(DHMsgInterfaceCode::GET_DISTRIBUTED_HARDWARE): { - return GetDistributedHardwareInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::REG_DH_SINK_STATUS_LISTNER): { - return RegisterDHStatusSinkListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::UNREG_DH_SINK_STATUS_LISTNER): { - return UnregisterDHStatusSinkListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::REG_DH_SOURCE_STATUS_LISTNER): { - return RegisterDHStatusSourceListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::UNREG_DH_SOURCE_STATUS_LISTNER): { - return UnregisterDHStatusSourceListenerInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::ENABLE_SINK): { - return EnableSinkInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::DISABLE_SINK): { - return DisableSinkInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::ENABLE_SOURCE): { - return EnableSourceInner(data, reply); - } - case static_cast(DHMsgInterfaceCode::DISABLE_SOURCE): { - return DisableSourceInner(data, reply); - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return DH_FWK_SUCCESS; -} - -bool DistributedHardwareStub::HasAccessDHPermission() -{ - Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; - int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, - permissionName); - return (result == Security::AccessToken::PERMISSION_GRANTED); -} - -bool DistributedHardwareStub::IsSystemHap() -{ - uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); - if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { - return false; - } - return true; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/disable_task.cpp b/services/distributedhardwarefwkservice/src/task/disable_task.cpp index 3c875fef..9f1d7dd8 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_task.cpp @@ -157,10 +157,7 @@ int32_t DisableTask::DoAutoDisable() } if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && DHContext::GetInstance().GetIsomerismConnectCount() == 0) { - DHDescriptor dhDescriptor { - .dhType = GetDhType(), - .id = GetDhId() - }; + DHDescriptor dhDescriptor(GetDhId(), GetDhType()); if (disableSink) { ret = ComponentManager::GetInstance().ForceDisableSink(dhDescriptor); if (ret != DH_FWK_SUCCESS) { @@ -180,10 +177,7 @@ int32_t DisableTask::DoAutoDisable() int32_t DisableTask::DoActiveDisable() { int32_t ret = DH_FWK_SUCCESS; - DHDescriptor dhDescriptor { - .dhType = GetDhType(), - .id = GetDhId() - }; + DHDescriptor dhDescriptor(GetDhId(), GetDhType()); if (GetEffectSink()) { ret = ComponentManager::GetInstance().DisableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); if (ret != DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/src/task/enable_task.cpp b/services/distributedhardwarefwkservice/src/task/enable_task.cpp index 90a61a4d..4909fbb3 100644 --- a/services/distributedhardwarefwkservice/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/enable_task.cpp @@ -153,10 +153,7 @@ int32_t EnableTask::DoAutoEnable() if (!enableSink && !enableSource) { return ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START; } - DHDescriptor dhDescriptor { - .dhType = GetDhType(), - .id = GetDhId() - }; + DHDescriptor dhDescriptor(GetDhId(), GetDhType()); if (enableSink) { ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); if (ret != DH_FWK_SUCCESS) { @@ -176,10 +173,7 @@ int32_t EnableTask::DoAutoEnable() int32_t EnableTask::DoActiveEnable() { int32_t ret = DH_FWK_SUCCESS; - DHDescriptor dhDescriptor { - .dhType = GetDhType(), - .id = GetDhId() - }; + DHDescriptor dhDescriptor(GetDhId(), GetDhType()); if (GetEffectSink()) { ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); if (ret != DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn index 254f56b2..99e51979 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("ComponentManagerFuzzTest") { sources = [ "componentmanager_fuzzer.cpp" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", ] diff --git a/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/BUILD.gn index 0df53991..2815d11a 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("DistributedFwkServicesFuzzTest") { sources = [ "distributedfwkservices_fuzzer.cpp" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", ] diff --git a/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/distributedfwkservices_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/distributedfwkservices_fuzzer.cpp index fc053180..50fe6217 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/distributedfwkservices_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/distributedfwkservices_fuzzer/distributedfwkservices_fuzzer.cpp @@ -58,7 +58,8 @@ void FwkServicesQueryLocalSysSpecFuzzTest(const uint8_t* data, size_t size) uint32_t sysSpec = *(reinterpret_cast(data)); QueryLocalSysSpecType spec = SPEC_TYPE[sysSpec % QUERY_LOCAL_SYS_SIZE]; - service.QueryLocalSysSpec(spec); + std::string funcResult; + service.QueryLocalSysSpec((uint32_t)spec, funcResult); } void FwkServicesQueryDhSysSpecFuzzTest(const uint8_t* data, size_t size) @@ -93,7 +94,7 @@ void FwkServicesPauseDistributedHardwareFuzzTest(const uint8_t* data, size_t siz DHType dhType = DHType::AUDIO; std::string networkId(reinterpret_cast(data), size); - service.PauseDistributedHardware(dhType, networkId); + service.PauseDistributedHardware((uint32_t)dhType, networkId); } void FwkServicesResumeDistributedHardwareFuzzTest(const uint8_t* data, size_t size) @@ -105,7 +106,7 @@ void FwkServicesResumeDistributedHardwareFuzzTest(const uint8_t* data, size_t si DHType dhType = DHType::AUDIO; std::string networkId(reinterpret_cast(data), size); - service.ResumeDistributedHardware(dhType, networkId); + service.ResumeDistributedHardware((uint32_t)dhType, networkId); } void FwkServicesStopDistributedHardwareFuzzTest(const uint8_t* data, size_t size) @@ -117,7 +118,7 @@ void FwkServicesStopDistributedHardwareFuzzTest(const uint8_t* data, size_t size DHType dhType = DHType::AUDIO; std::string networkId(reinterpret_cast(data), size); - service.StopDistributedHardware(dhType, networkId); + service.StopDistributedHardware((uint32_t)dhType, networkId); } } } diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index 35a30988..c540951d 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -23,7 +23,6 @@ group("test") { "common/dbadapter:db_adapter_test", "common/distributedhardwaremanager:distributed_hardware_manager_test", "common/distributedhardwareservice:distributed_hardware_service_test", - "common/distributedhardwarestub:distributed_hardware_stub_test", "common/hidumphelper/enabledcompsdump:enabled_comps_dump_test", "common/hidumphelper/hidumphelper:hidump_helper_test", "common/ipc:publisher_listener_proxy_test", diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn index 1f5dcda5..42e3838e 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn @@ -55,6 +55,7 @@ ohos_unittest("ComponentManagerTest") { configs = [ ":module_private_config" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", ] diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/BUILD.gn index 65724ea2..9514a348 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("DistributedHardwareServiceTest") { configs = [ ":module_private_config" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", ] diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp index 9667310e..244da574 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp @@ -61,7 +61,7 @@ void DistributedHardwareServiceTest::TearDown() {} HWTEST_F(DistributedHardwareServiceTest, register_publisher_listener_001, TestSize.Level0) { DistributedHardwareService service(ASID, true); - auto ret = service.RegisterPublisherListener(TOPIC, g_listener); + auto ret = service.RegisterPublisherListener((uint32_t)TOPIC, g_listener); EXPECT_EQ(ret, DH_FWK_SUCCESS); } @@ -76,7 +76,7 @@ HWTEST_F(DistributedHardwareServiceTest, register_publisher_listener_002, TestSi { DistributedHardwareService service(ASID, true); sptr listener = nullptr; - auto ret = service.RegisterPublisherListener(TOPIC, listener); + auto ret = service.RegisterPublisherListener((uint32_t)TOPIC, listener); EXPECT_EQ(ret, DH_FWK_SUCCESS); } @@ -89,8 +89,8 @@ HWTEST_F(DistributedHardwareServiceTest, register_publisher_listener_002, TestSi HWTEST_F(DistributedHardwareServiceTest, unregister_publisher_listener_001, TestSize.Level0) { DistributedHardwareService service(ASID, true); - service.RegisterPublisherListener(TOPIC, g_listener); - auto ret = service.UnregisterPublisherListener(TOPIC, g_listener); + service.RegisterPublisherListener((uint32_t)TOPIC, g_listener); + auto ret = service.UnregisterPublisherListener((uint32_t)TOPIC, g_listener); EXPECT_EQ(ret, DH_FWK_SUCCESS); } @@ -105,8 +105,8 @@ HWTEST_F(DistributedHardwareServiceTest, publish_message_001, TestSize.Level0) { DistributedHardwareService service(ASID, true); std::string msg; - service.RegisterPublisherListener(TOPIC, g_listener); - auto ret = service.PublishMessage(TOPIC, msg); + service.RegisterPublisherListener((uint32_t)TOPIC, g_listener); + auto ret = service.PublishMessage((uint32_t)TOPIC, msg); EXPECT_EQ(ret, DH_FWK_SUCCESS); } @@ -121,8 +121,8 @@ HWTEST_F(DistributedHardwareServiceTest, publish_message_002, TestSize.Level0) { DistributedHardwareService service(ASID, true); std::string msg = "msg"; - service.RegisterPublisherListener(TOPIC, g_listener); - auto ret = service.PublishMessage(TOPIC, msg); + service.RegisterPublisherListener((uint32_t)TOPIC, g_listener); + auto ret = service.PublishMessage((uint32_t)TOPIC, msg); EXPECT_EQ(ret, DH_FWK_SUCCESS); } @@ -188,11 +188,17 @@ HWTEST_F(DistributedHardwareServiceTest, OnStart_001, TestSize.Level0) HWTEST_F(DistributedHardwareServiceTest, QueryLocalSysSpec_001, TestSize.Level0) { DistributedHardwareService service(ASID, true); - std::string ret = service.QueryLocalSysSpec(QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER); - ret = service.QueryLocalSysSpec(QueryLocalSysSpecType::HISTREAMER_AUDIO_DECODER); - ret = service.QueryLocalSysSpec(QueryLocalSysSpecType::HISTREAMER_VIDEO_ENCODER); - ret = service.QueryLocalSysSpec(QueryLocalSysSpecType::HISTREAMER_VIDEO_DECODER); - ret = service.QueryLocalSysSpec(QueryLocalSysSpecType::MAX); + std::string funcResult; + service.QueryLocalSysSpec((uint32_t)QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER, funcResult); + std::string ret = funcResult; + service.QueryLocalSysSpec((uint32_t)QueryLocalSysSpecType::HISTREAMER_AUDIO_DECODER, funcResult); + ret = funcResult; + service.QueryLocalSysSpec((uint32_t)QueryLocalSysSpecType::HISTREAMER_VIDEO_ENCODER, funcResult); + ret = funcResult; + service.QueryLocalSysSpec((uint32_t)QueryLocalSysSpecType::HISTREAMER_VIDEO_DECODER, funcResult); + ret = funcResult; + service.QueryLocalSysSpec((uint32_t)QueryLocalSysSpecType::MAX, funcResult); + ret = funcResult; EXPECT_EQ(ret.empty(), true); } @@ -206,9 +212,9 @@ HWTEST_F(DistributedHardwareServiceTest, PauseDistributedHardware_001, TestSize. { DistributedHardwareService service(ASID, true); std::string networkId = "111"; - auto ret = service.PauseDistributedHardware(DHType::UNKNOWN, networkId); - ret = service.PauseDistributedHardware(DHType::CAMERA, networkId); - ret = service.PauseDistributedHardware(DHType::MAX_DH, networkId); + auto ret = service.PauseDistributedHardware((uint32_t)DHType::UNKNOWN, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::CAMERA, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::MAX_DH, networkId); EXPECT_EQ(ret, ERR_DH_FWK_PARA_INVALID); } @@ -222,9 +228,9 @@ HWTEST_F(DistributedHardwareServiceTest, ResumeDistributedHardware_001, TestSize { DistributedHardwareService service(ASID, true); std::string networkId = "111"; - auto ret = service.PauseDistributedHardware(DHType::UNKNOWN, networkId); - ret = service.PauseDistributedHardware(DHType::AUDIO, networkId); - ret = service.PauseDistributedHardware(DHType::MAX_DH, networkId); + auto ret = service.PauseDistributedHardware((uint32_t)DHType::UNKNOWN, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::AUDIO, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::MAX_DH, networkId); EXPECT_EQ(ret, ERR_DH_FWK_PARA_INVALID); } @@ -238,9 +244,9 @@ HWTEST_F(DistributedHardwareServiceTest, StopDistributedHardware_001, TestSize.L { DistributedHardwareService service(ASID, true); std::string networkId = "111"; - auto ret = service.PauseDistributedHardware(DHType::UNKNOWN, networkId); - ret = service.PauseDistributedHardware(DHType::INPUT, networkId); - ret = service.PauseDistributedHardware(DHType::MAX_DH, networkId); + auto ret = service.PauseDistributedHardware((uint32_t)DHType::UNKNOWN, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::INPUT, networkId); + ret = service.PauseDistributedHardware((uint32_t)DHType::MAX_DH, networkId); EXPECT_EQ(ret, ERR_DH_FWK_PARA_INVALID); } @@ -248,7 +254,7 @@ HWTEST_F(DistributedHardwareServiceTest, ResumeDistributedHardware_002, TestSize { DistributedHardwareService service(ASID, true); std::string networkId = "111"; - auto ret = service.ResumeDistributedHardware(DHType::UNKNOWN, networkId); + auto ret = service.ResumeDistributedHardware((uint32_t)DHType::UNKNOWN, networkId); EXPECT_EQ(ret, ERR_DH_FWK_PARA_INVALID); } @@ -256,7 +262,7 @@ HWTEST_F(DistributedHardwareServiceTest, StopDistributedHardware_002, TestSize.L { DistributedHardwareService service(ASID, true); std::string networkId = "111"; - auto ret = service.StopDistributedHardware(DHType::UNKNOWN, networkId); + auto ret = service.StopDistributedHardware((uint32_t)DHType::UNKNOWN, networkId); EXPECT_EQ(ret, ERR_DH_FWK_PARA_INVALID); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn deleted file mode 100644 index 2e5f710c..00000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2022-2024 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. - -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") - -module_out_path = "distributed_hardware_fwk/distributed_hardware_stub_test" - -config("module_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "${av_trans_path}/common/include", - "include", - "${innerkits_path}/include", - "${utils_path}/include", - "${utils_path}/include/log", - "${utils_path}/include/eventbus", - "${common_path}/log/include", - "${common_path}/utils/include", - "${services_path}/distributedhardwarefwkservice/include", - "${services_path}/distributedhardwarefwkservice/include/task", - "${services_path}/distributedhardwarefwkservice/include/utils", - ] -} - -ohos_unittest("DistributedHardwareStubTest") { - module_out_path = module_out_path - - sources = [ "src/distributed_hardware_stub_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DistributedHardwareStubTest\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "eventhandler:libeventhandler", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] -} - -group("distributed_hardware_stub_test") { - testonly = true - deps = [ ":DistributedHardwareStubTest" ] -} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h deleted file mode 100644 index bc5d86fb..00000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_STUB_TEST_H -#define OHOS_DISTRIBUTED_HARDWARE_STUB_TEST_H - -#include - -#include "distributed_hardware_errno.h" -#include "distributed_hardware_fwk_kit_paras.h" -#include "distributed_hardware_stub.h" - -namespace OHOS { -namespace DistributedHardware { -class DistributedHardwareStubTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - std::shared_ptr stubTest_ = nullptr; -}; - -class MockDistributedHardwareStub : public DistributedHardwareStub { -public: -int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener) -{ - (void)topic; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener) -{ - (void)topic; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t PublishMessage(const DHTopic topic, const std::string &msg) -{ - (void)topic; - (void)msg; - return DH_FWK_SUCCESS; -} - -std::string QueryLocalSysSpec(QueryLocalSysSpecType spec) -{ - (void)spec; - return ""; -} - -int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) -{ - (void)transRole; - (void)engineId; - return DH_FWK_SUCCESS; -} - -int32_t ReleaseAVCenter(int32_t engineId) -{ - (void)engineId; - return DH_FWK_SUCCESS; -} - -int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) -{ - (void)engineId; - (void)peerDevId; - return DH_FWK_SUCCESS; -} - -int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) -{ - (void)engineId; - (void)event; - return DH_FWK_SUCCESS; -} - -int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback) -{ - (void)engineId; - (void)callback; - return DH_FWK_SUCCESS; -} - -int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) -{ - (void)deviceId; - return DH_FWK_SUCCESS; -} - -int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) -{ - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; -} - -int32_t GetDistributedHardware(const std::string &networkId, std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t RegisterDHStatusListener(sptr listener) -{ - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t UnregisterDHStatusListener(sptr listener) -{ - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t RegisterDHStatusListener(const std::string &networkId, sptr listener) -{ - (void)networkId; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t UnregisterDHStatusListener(const std::string &networkId, sptr listener) -{ - (void)networkId; - (void)listener; - return DH_FWK_SUCCESS; -} - -int32_t EnableSink(const std::vector &descriptors) -{ - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DisableSink(const std::vector &descriptors) -{ - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} - -int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) -{ - (void)networkId; - (void)descriptors; - return DH_FWK_SUCCESS; -} -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp deleted file mode 100644 index 9be7aaf1..00000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_hardware_stub_test.h" - -#include - -#include "iremote_stub.h" -#include "dhardware_ipc_interface_code.h" -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void DistributedHardwareStubTest::SetUpTestCase(void) {} - -void DistributedHardwareStubTest::TearDownTestCase(void) {} - -void DistributedHardwareStubTest::SetUp() -{ - stubTest_ = std::make_shared(); -} - -void DistributedHardwareStubTest::TearDown() -{ - stubTest_ = nullptr; -} - -/** - * @tc.name: OnRemoteRequest_001 - * @tc.desc: Verify the OnRemoteRequest function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = 0; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_NE(DH_FWK_SUCCESS, stubTest_->OnRemoteRequest(code, data, reply, option)); -} - -/** - * @tc.name: OnRemoteRequest_002 - * @tc.desc: Verify the OnRemoteRequest function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_002, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = 0; - MessageParcel data; - MessageParcel reply; - MessageOption option; - EXPECT_EQ(ERR_INVALID_DATA, stubTest_->OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_003, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::REG_PUBLISHER_LISTNER); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - uint32_t topicInt = (uint32_t)DHTopic::TOPIC_MIN; - data.WriteUint32(topicInt); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_004, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::PUBLISH_MESSAGE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - uint32_t topicInt = (uint32_t)DHTopic::TOPIC_MIN; - data.WriteUint32(topicInt); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_005, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::INIT_CTL_CEN); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - uint32_t transRole = static_cast(TransRole::UNKNOWN); - data.WriteUint32(transRole); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_006, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::RELEASE_CTL_CEN); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - int32_t engineId = 1; - data.WriteInt32(engineId); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_007, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::CREATE_CTL_CEN_CHANNEL); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - int32_t engineId = 1; - std::string peerDevId = "peerDevId_test"; - data.WriteInt32(engineId); - data.WriteString(peerDevId); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_008, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::NOTIFY_AV_EVENT); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - int32_t engineId = 1; - std::string peerDevId = "peerDevId_test"; - uint32_t type = 1; - std::string content = "content_test"; - data.WriteInt32(engineId); - data.WriteString(peerDevId); - data.WriteUint32(type); - data.WriteString(content); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_009, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::QUERY_LOCAL_SYS_SPEC); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - uint32_t specInt = static_cast(QueryLocalSysSpecType::MIN); - data.WriteUint32(specInt); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_010, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - std::string deviceId = "deviceId_test"; - data.WriteString(deviceId); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_011, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_012, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::RESUME_DISTRIBUTED_HARDWARE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_013, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::STOP_DISTRIBUTED_HARDWARE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_IS_SYSTEM_HAP_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_014, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::UNREG_PUBLISHER_LISTENER); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - uint32_t topicInt = (uint32_t)DHTopic::TOPIC_MIN; - data.WriteUint32(topicInt); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_015, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t code = static_cast(DHMsgInterfaceCode::REGISTER_CTL_CEN_CALLBACK); - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(stubTest_->GetDescriptor()); - auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); -} - -/** - * @tc.name: RegisterPublisherListenerInner_001 - * @tc.desc: Verify the RegisterPublisherListenerInner function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, RegisterPublisherListenerInner_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_NE(DH_FWK_SUCCESS, stubTest_->RegisterPublisherListenerInner(data, reply)); -} - -/** - * @tc.name: UnregisterPublisherListenerInner_001 - * @tc.desc: Verify the UnregisterPublisherListenerInner function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, UnregisterPublisherListenerInner_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_NE(DH_FWK_SUCCESS, stubTest_->UnregisterPublisherListenerInner(data, reply)); -} - -/** - * @tc.name: PublishMessageInner_001 - * @tc.desc: Verify the PublishMessageInner function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - MessageParcel data; - MessageParcel reply; - EXPECT_NE(DH_FWK_SUCCESS, stubTest_->PublishMessageInner(data, reply)); -} - -/** - * @tc.name: ValidTopic_001 - * @tc.desc: Verify the ValidTopic function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, ValidTopic_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t topic = static_cast(DHTopic::TOPIC_MIN); - EXPECT_EQ(false, stubTest_->ValidTopic(topic)); - - uint32_t topic1 = static_cast(DHTopic::TOPIC_MAX); - EXPECT_EQ(false, stubTest_->ValidTopic(topic1)); - - uint32_t topic2 = static_cast(DHTopic::TOPIC_START_DSCREEN); - EXPECT_EQ(true, stubTest_->ValidTopic(topic2)); -} - -/** - * @tc.name: ValidQueryLocalSpec_001 - * @tc.desc: Verify the ValidQueryLocalSpec function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_001, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t spec = 1; - EXPECT_EQ(true, stubTest_->ValidQueryLocalSpec(spec)); -} - -/** - * @tc.name: ValidQueryLocalSpec_002 - * @tc.desc: Verify the ValidQueryLocalSpec function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_002, TestSize.Level0) -{ - ASSERT_TRUE(stubTest_ != nullptr); - uint32_t spec = 0; - EXPECT_EQ(false, stubTest_->ValidQueryLocalSpec(spec)); - spec = 5; - EXPECT_EQ(false, stubTest_->ValidQueryLocalSpec(spec)); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/BUILD.gn index 7ae99035..6efdfdb1 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("HidumpHelperTest") { configs = [ ":module_private_config" ] deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", ] -- Gitee From 0d0318fd2c69d7c150362c1264ab55d0cfe143d1 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 17:45:30 +0800 Subject: [PATCH 2/2] Update UT Signed-off-by: BrainL --- .../test/unittest/common/distributedhardwarefwkkit/BUILD.gn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/BUILD.gn b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/BUILD.gn index 8f392692..bb65a549 100644 --- a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/BUILD.gn @@ -38,7 +38,10 @@ ohos_unittest("DistributedHardwareFwkKitTest") { configs = [ ":module_private_config" ] - deps = [ "${innerkits_path}:libdhfwk_sdk" ] + deps = [ + "${innerkits_path}:dhfwk_idl_hardware_head", + "${innerkits_path}:libdhfwk_sdk", + ] defines = [ "HI_LOG_ENABLE", -- Gitee