diff --git a/bundle.json b/bundle.json index 5b8a73709cf39522cf6296adba2b1b2befd6597d..190949305c688aba02fdbf94876775ca873e7fdc 100644 --- a/bundle.json +++ b/bundle.json @@ -37,9 +37,12 @@ "bundle_framework", "napi", "dsoftbus", + "drivers_interface_distributed_audio", + "drivers_interface_distributed_camera", "eventhandler", "hitrace", "c_utils", + "hdf_core", "hilog", "cJSON", "samgr", @@ -136,6 +139,7 @@ "header_files": [ "constants.h", "device_type.h", + "dhardware_descriptor.h", "dhardware_ipc_interface_code.h", "distributed_hardware_errno.h", "iav_trans_control_center_callback.h", @@ -144,6 +148,7 @@ "idistributed_hardware_source.h", "idistributed_hardware.h", "ihardware_handler.h", + "ihardware_status_listener.h", "ipublisher_listener.h", "single_instance.h" ], diff --git a/common/utils/include/dhardware_ipc_interface_code.h b/common/utils/include/dhardware_ipc_interface_code.h index 902c02a08ecb3d7636c79101658bd7837834e36e..67a54efcfd1fff84dfcaf595ea2eda40f93836c5 100644 --- a/common/utils/include/dhardware_ipc_interface_code.h +++ b/common/utils/include/dhardware_ipc_interface_code.h @@ -43,6 +43,8 @@ enum class DHMsgInterfaceCode : uint32_t { DISABLE_SINK = 480019, ENABLE_SOURCE = 480020, DISABLE_SOURCE = 480021, + LOAD_HDF = 480022, + UNLOAD_HDF = 480023, NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED = 1, }; } // namespace DistributedHardware diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index c3c8d47513fde0f2062b4d2928b4b37731d7f8ba..f235ec62d3a16a2ff7c48c1ae6b7724d812e15f6 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -95,6 +95,11 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_SERVICE_MSG_INVALID = -10809; constexpr int32_t ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL = -10810; constexpr int32_t ERR_DH_FWK_GETDISTRIBUTEDHARDWARE_TIMEOUT = -10811; + constexpr int32_t ERR_DH_FWK_STATUS_LISTENER_IS_NULL = -10812; + constexpr int32_t ERR_DH_FWK_REGISTER_HDF_LISTENER_FAIL = -10813; + constexpr int32_t ERR_DH_FWK_LOAD_HDF_FAIL = -10814; + constexpr int32_t ERR_DH_FWK_LOAD_HDF_TIMEOUT = -10815; + constexpr int32_t ERR_DH_FWK_NO_HDF_SUPPORT = -10816; /* AccessManager errno, range: [-10900, -10999] */ constexpr int32_t ERR_DH_FWK_ACCESS_INIT_DM_FAILED = -10900; diff --git a/common/utils/include/idistributed_hardware.h b/common/utils/include/idistributed_hardware.h index e17488b9d7696b128cf587913a2136c18aecbdd9..c46f6431ed80e1784bea150abf1a38956dc66e2e 100644 --- a/common/utils/include/idistributed_hardware.h +++ b/common/utils/include/idistributed_hardware.h @@ -63,6 +63,8 @@ public: 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; + virtual int32_t LoadDistributedHDF(const DHType dhType) = 0; + virtual int32_t UnLoadDistributedHDF(const DHType dhType) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h index d2744e90ae8325ccaf4618ae051ae412b1ce5771..bb7d6678544e9bf9991f774c20b028c4891c7b6c 100644 --- a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h +++ b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h @@ -238,6 +238,22 @@ public: */ API_EXPORT int32_t DisableSource(const std::string &networkId, const std::vector &descriptors); + /** + * @brief Load distributed HDF. + * + * @param dhType distributed hardware type. + * @return Returns 0 if success. + */ + API_EXPORT int32_t LoadDistributedHDF(const DHType dhType); + + /** + * @brief Unload distributed HDF. + * + * @param dhType distributed hardware type. + * @return Returns 0 if success. + */ + API_EXPORT int32_t UnLoadDistributedHDF(const DHType dhType); + private: /** * @brief Determine whether the topic is valid. diff --git a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h b/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h index 90937e86472e681bc581ab49c035420aac3309d4..7fba9350aa2e6e319acf3783f4afe9e547aeda88 100644 --- a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h +++ b/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h @@ -57,6 +57,8 @@ public: 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; + int32_t LoadDistributedHDF(const DHType dhType) override; + int32_t UnLoadDistributedHDF(const DHType dhType) override; private: int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index 91ea88ca18963ff81e1adff3e1c26a84fde9b169..4e3880052b1709698e8bc62b7214c9247469f11d 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -227,7 +227,7 @@ int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const GetAnonyString(networkId).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not pause distributed hardware."); return ERR_DH_FWK_POINTER_IS_NULL; } HiSysEventWriteMsg(DHFWK_INIT_END, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, @@ -244,7 +244,7 @@ int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, cons GetAnonyString(networkId).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not resume distributed hardware."); return ERR_DH_FWK_POINTER_IS_NULL; } HiSysEventWriteMsg(DHFWK_INIT_BEGIN, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, @@ -261,7 +261,7 @@ int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const GetAnonyString(networkId).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not stop distributed hardware."); return ERR_DH_FWK_POINTER_IS_NULL; } HiSysEventWriteMsg(DHFWK_EXIT_END, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, @@ -287,7 +287,7 @@ int32_t DistributedHardwareFwkKit::RegisterDHStatusListener(sptrRegisterDHStatusListener(listener); @@ -297,7 +297,7 @@ int32_t DistributedHardwareFwkKit::UnregisterDHStatusListener(sptrUnregisterDHStatusListener(listener); @@ -311,7 +311,7 @@ int32_t DistributedHardwareFwkKit::RegisterDHStatusListener( } DHLOGI("Register distributed hardware status source listener %{public}s.", GetAnonyString(networkId).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not register distributed hardware status listener."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->RegisterDHStatusListener(networkId, listener); @@ -325,7 +325,7 @@ int32_t DistributedHardwareFwkKit::UnregisterDHStatusListener( } DHLOGI("Unregister distributed hardware status source listener %{public}s.", GetAnonyString(networkId).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not unregister distributed hardware status listener."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnregisterDHStatusListener(networkId, listener); @@ -335,7 +335,7 @@ int32_t DistributedHardwareFwkKit::EnableSink(const std::vector &d { DHLOGI("Enable distributed hardware sink descriptors %{public}s.", DumpDescriptors(descriptors).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not enable sink."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->EnableSink(descriptors); @@ -345,7 +345,7 @@ int32_t DistributedHardwareFwkKit::DisableSink(const std::vector & { DHLOGI("Disable distributed hardware sink descriptors %{public}s.", DumpDescriptors(descriptors).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not disable sink."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->DisableSink(descriptors); @@ -360,7 +360,7 @@ int32_t DistributedHardwareFwkKit::EnableSource( DHLOGI("Enable distributed hardware source networkId %{public}s, descriptors %{public}s.", GetAnonyString(networkId).c_str(), DumpDescriptors(descriptors).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not enable source."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->EnableSource(networkId, descriptors); @@ -375,10 +375,30 @@ int32_t DistributedHardwareFwkKit::DisableSource( DHLOGI("Disable distributed hardware source networkId %{public}s, descriptors %{public}s.", GetAnonyString(networkId).c_str(), DumpDescriptors(descriptors).c_str()); if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { - DHLOGI("DHFWK not online or get proxy failed, can not register av control center callback."); + DHLOGI("DHFWK not online or get proxy failed, can not disable source."); return ERR_DH_FWK_POINTER_IS_NULL; } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->DisableSource(networkId, descriptors); } + +int32_t DistributedHardwareFwkKit::LoadDistributedHDF(const DHType dhType) +{ + DHLOGI("Load distributed HDF, dhType: %{public}u.", dhType); + if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { + DHLOGI("DHFWK not online or get proxy failed, can not load distributed HDF."); + return ERR_DH_FWK_POINTER_IS_NULL; + } + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->LoadDistributedHDF(dhType); +} + +int32_t DistributedHardwareFwkKit::UnLoadDistributedHDF(const DHType dhType) +{ + DHLOGI("UnLoad distributed HDF, dhType: %{public}u.", dhType); + if (DHFWKSAManager::GetInstance().GetDHFWKProxy() == nullptr) { + DHLOGI("DHFWK not online or get proxy failed, can not unload distributed HDF."); + return ERR_DH_FWK_POINTER_IS_NULL; + } + return DHFWKSAManager::GetInstance().GetDHFWKProxy()->UnLoadDistributedHDF(dhType); +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index 47ee352db885aa38588b58f8b7ae2fa6008c8d69..d3f104ce5d6d649f2dff14cdb8856ba7d067d14c 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -578,6 +578,10 @@ int32_t DistributedHardwareProxy::GetDistributedHardware(const std::string &netw int32_t DistributedHardwareProxy::RegisterDHStatusListener(sptr listener) { DHLOGI("DistributedHardwareProxy RegisterDHStatusListener."); + if (listener == nullptr) { + DHLOGE("status listener is null"); + return ERR_DH_FWK_STATUS_LISTENER_IS_NULL; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null!"); @@ -606,6 +610,10 @@ int32_t DistributedHardwareProxy::RegisterDHStatusListener(sptr listener) { DHLOGI("DistributedHardwareProxy UnregisterDHStatusListener."); + if (listener == nullptr) { + DHLOGE("status listener is null"); + return ERR_DH_FWK_STATUS_LISTENER_IS_NULL; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null!"); @@ -635,6 +643,10 @@ int32_t DistributedHardwareProxy::RegisterDHStatusListener( const std::string &networkId, sptr listener) { DHLOGI("DistributedHardwareProxy RegisterDHStatusListener."); + if (listener == nullptr) { + DHLOGE("status listener is null"); + return ERR_DH_FWK_STATUS_LISTENER_IS_NULL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -671,6 +683,10 @@ int32_t DistributedHardwareProxy::UnregisterDHStatusListener( const std::string &networkId, sptr listener) { DHLOGI("DistributedHardwareProxy UnregisterDHStatusListener."); + if (listener == nullptr) { + DHLOGE("status listener is null"); + return ERR_DH_FWK_STATUS_LISTENER_IS_NULL; + } if (!IsIdLengthValid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } @@ -827,6 +843,62 @@ int32_t DistributedHardwareProxy::DisableSource( return reply.ReadInt32(); } +int32_t DistributedHardwareProxy::LoadDistributedHDF(const DHType dhType) +{ + 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.WriteUint32(type)) { + DHLOGE("Write type failed"); + return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; + } + int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::LOAD_HDF), + 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::UnLoadDistributedHDF(const DHType dhType) +{ + 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.WriteUint32(type)) { + DHLOGE("Write type failed"); + return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL; + } + int32_t ret = remote->SendRequest(static_cast(DHMsgInterfaceCode::UNLOAD_HDF), + 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(); diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp index afd2c4a6b638bf432dc0213b105e44a08e1fec49..ec0f72348fdb06aaf00753c55826e89543f8428e 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp @@ -304,6 +304,30 @@ void DisableSinkFuzzTest(const uint8_t *data, size_t size) descriptors.push_back(dhDescriptor); dhfwkKit.DisableSink(descriptors); } + +void LoadDistributedHDFFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + DHType dhType = static_cast(*(reinterpret_cast(data))); + + DistributedHardwareFwkKit dhfwkKit; + dhfwkKit.LoadDistributedHDF(dhType); +} + +void UnLoadDistributedHDFFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + DHType dhType = static_cast(*(reinterpret_cast(data))); + + DistributedHardwareFwkKit dhfwkKit; + dhfwkKit.UnLoadDistributedHDF(dhType); +} } // namespace DistributedHardware } // namespace OHOS @@ -328,5 +352,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::DistributedHardware::DisableSourceFuzzTest(data, size); OHOS::DistributedHardware::EnableSinkFuzzTest(data, size); OHOS::DistributedHardware::DisableSinkFuzzTest(data, size); + OHOS::DistributedHardware::LoadDistributedHDFFuzzTest(data, size); + OHOS::DistributedHardware::UnLoadDistributedHDFFuzzTest(data, size); return 0; } \ No newline at end of file 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 eb5994952bd5cde0524a5a2a9c1fedd363c94c99..27ecfe959ad5d712e87110711fc6197e1ddba425 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 @@ -603,5 +603,31 @@ HWTEST_F(DistributedHardwareFwkKitTest, DisableSource_001, testing::ext::TestSiz ret = dhfwkPtr_->DisableSource(networkId, descriptors); EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); } + +/** + * @tc.name: LoadDistributedHDF_001 + * @tc.desc: Verify the LoadDistributedHDF function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, LoadDistributedHDF_001, testing::ext::TestSize.Level0) +{ + ASSERT_TRUE(dhfwkPtr_ != nullptr); + int32_t ret = dhfwkPtr_->LoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); +} + +/** + * @tc.name: UnLoadDistributedHDF_001 + * @tc.desc: Verify the UnLoadDistributedHDF function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, UnLoadDistributedHDF_001, testing::ext::TestSize.Level0) +{ + ASSERT_TRUE(dhfwkPtr_ != nullptr); + int32_t ret = dhfwkPtr_->UnLoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file 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 7639175f2aaac9a861f6d58b847f179a0a0785be..0f5f633f943e2e932b4b00f53c6bd7793796216b 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 @@ -191,6 +191,18 @@ int32_t DisableSource(const std::string &networkId, 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); + int32_t LoadDistributedHDF(const DHType dhType); + int32_t UnLoadDistributedHDF(const DHType dhType); }; class TestDistributedHardwareStub2 : public TestDistributedHardwareStub { 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 index 0195307b1453a40e6fef55f90eb412201671e41a..a318789c972cf1dd1961da250a3d10392a922c86 100644 --- 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 @@ -208,6 +208,18 @@ int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::DisableSource return DH_FWK_SUCCESS; } +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::LoadDistributedHDF(const DHType dhType) +{ + (void)dhType; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::UnLoadDistributedHDF(const DHType dhType) +{ + (void)dhType; + return DH_FWK_SUCCESS; +} + void DistributedHardwareProxyTest::TestGetDistributedHardwareCallback::OnSuccess( const std::string &networkId, const std::vector &descriptors, EnableStep enableStep) { @@ -586,6 +598,16 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterDHStatusListener_Source_001, Test EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } +HWTEST_F(DistributedHardwareProxyTest, RegisterDHStatusListener_Source_002, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + sptr listener(new MockHDSourceStatusListenerStub()); + auto ret = dhProxy.RegisterDHStatusListener(std::string(), nullptr); + EXPECT_EQ(ERR_DH_FWK_STATUS_LISTENER_IS_NULL, ret); +} + HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Source_001, TestSize.Level1) { std::string networkId = "123456"; @@ -599,6 +621,16 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Source_001, Te EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } +HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Source_002, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + sptr listener(new MockHDSourceStatusListenerStub()); + auto ret = dhProxy.UnregisterDHStatusListener(std::string(), nullptr); + EXPECT_EQ(ERR_DH_FWK_STATUS_LISTENER_IS_NULL, ret); +} + HWTEST_F(DistributedHardwareProxyTest, RegisterDHStatusListener_Sink_001, TestSize.Level1) { sptr dhStubPtr(new TestDistributedHardwareStub()); @@ -609,6 +641,16 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterDHStatusListener_Sink_001, TestSi EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } +HWTEST_F(DistributedHardwareProxyTest, RegisterDHStatusListener_Sink_002, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + sptr listener(new MockHDSinkStatusListenerStub()); + auto ret = dhProxy.RegisterDHStatusListener(nullptr); + EXPECT_EQ(ERR_DH_FWK_STATUS_LISTENER_IS_NULL, ret); +} + HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Sink_001, TestSize.Level1) { sptr dhStubPtr(new TestDistributedHardwareStub()); @@ -619,6 +661,16 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Sink_001, Test EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } +HWTEST_F(DistributedHardwareProxyTest, UnregisterDHStatusListener_Sink_002, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + sptr listener(new MockHDSinkStatusListenerStub()); + auto ret = dhProxy.UnregisterDHStatusListener(nullptr); + EXPECT_EQ(ERR_DH_FWK_STATUS_LISTENER_IS_NULL, ret); +} + HWTEST_F(DistributedHardwareProxyTest, EnableSink_001, TestSize.Level1) { sptr dhStubPtr(new TestDistributedHardwareStub()); @@ -664,5 +716,39 @@ HWTEST_F(DistributedHardwareProxyTest, DisableSource_001, TestSize.Level1) auto ret = dhProxy.DisableSource(networkId, descriptors); EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } + +HWTEST_F(DistributedHardwareProxyTest, LoadDistributedHDF_001, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + + auto ret = dhProxy.LoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); +} + +HWTEST_F(DistributedHardwareProxyTest, LoadDistributedHDF_002, TestSize.Level1) +{ + DistributedHardwareProxy dhProxy(nullptr); + auto ret = dhProxy.LoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); +} + +HWTEST_F(DistributedHardwareProxyTest, UnLoadDistributedHDF_001, TestSize.Level1) +{ + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + + auto ret = dhProxy.UnLoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); +} + +HWTEST_F(DistributedHardwareProxyTest, UnLoadDistributedHDF_002, TestSize.Level1) +{ + DistributedHardwareProxy dhProxy(nullptr); + auto ret = dhProxy.UnLoadDistributedHDF(DHType::CAMERA); + EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index 13f6f2f7bfc4f71daeaac03852acb94e3eabbaf5..5af3a4aa4595ffc1fb84309bd73fa8c98a3caa39 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("distributedhardwarefwksvr") { "include/hidumphelper", "include/ipc", "include/lowlatency", + "include/hdfoperate", ] sources = [ @@ -156,9 +157,14 @@ ohos_shared_library("distributedhardwarefwksvr") { "c_utils:utils", "config_policy:configpolicy_util", "device_manager:devicemanagersdk", + "drivers_interface_distributed_audio:libdaudioext_proxy_2.0", + "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", "dsoftbus:softbus_client", "eventhandler:libeventhandler", "ffrt:libffrt", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdi", + "hdf_core:libpub_utils", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 624c00e18506e9773c76ed065bdb58436fb1439d..50559348202a69d32c1eb87ab1093c707513eeea 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -262,6 +262,7 @@ private: void RecoverAutoEnableSource(DHType dhType); void RecoverActiveEnableSink(DHType dhType); void RecoverActiveEnableSource(DHType dhType); + void ResetHdfLoadRefCount(DHType dhType); private: std::map compSource_; std::shared_mutex compSourceMutex_; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index c535261565401fe474c15190c31d0aa249706880..840a09fea6165a27eae840793787903b422b5a2d 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -62,6 +62,8 @@ public: 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; + int32_t LoadDistributedHDF(const DHType dhType) override; + int32_t UnLoadDistributedHDF(const DHType dhType) override; protected: void OnStart() override; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h b/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h index 4f3641d0cdc0715daee986fc27a2adf9bb9027dc..21a325bcf73ee68ccc905289173b2763e1cdaa08 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h @@ -50,6 +50,8 @@ private: int32_t DisableSinkInner(MessageParcel &data, MessageParcel &reply); int32_t EnableSourceInner(MessageParcel &data, MessageParcel &reply); int32_t DisableSourceInner(MessageParcel &data, MessageParcel &reply); + int32_t LoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply); + int32_t UnLoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply); int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); int32_t WriteDescriptors(MessageParcel &data, const std::vector &descriptors); diff --git a/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h b/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h new file mode 100644 index 0000000000000000000000000000000000000000..fa51ef279d6d624f6eadaf19555bf9c7e051361a --- /dev/null +++ b/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h @@ -0,0 +1,93 @@ +/* + * 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_DAUDIO_HDF_OPERATE_H +#define OHOS_DAUDIO_HDF_OPERATE_H + +#include +#include +#include + +#include "iservstat_listener_hdi.h" +#include "idevmgr_hdi.h" +#include "iservmgr_hdi.h" +#include "single_instance.h" +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string AUDIO_SERVICE_NAME = "daudio_primary_service"; +const std::string AUDIOEXT_SERVICE_NAME = "daudio_ext_service"; +constexpr uint16_t AUDIO_INVALID_VALUE = 0xffff; +constexpr int32_t AUDIO_WAIT_TIME = 5000; +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using OHOS::HDI::ServiceManager::V1_0::IServiceManager; +using OHOS::HDI::ServiceManager::V1_0::IServStatListener; +using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; +using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioManager; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioHdfCallback; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::DAudioEvent; + +class FwkDAudioHdfCallback; +class DaudioHdfOperate { +DECLARE_SINGLE_INSTANCE(DaudioHdfOperate); + +public: + int32_t LoadDaudioHDFImpl(); + int32_t UnLoadDaudioHDFImpl(); + void ResetRefCount(); + +private: + int32_t WaitLoadService(const std::string& servName); + OHOS::sptr MakeServStatListener(); + int32_t LoadDevice(); + int32_t UnLoadDevice(); + int32_t RegisterHdfListener(); + int32_t UnRegisterHdfListener(); + +private: + OHOS::sptr devmgr_; + OHOS::sptr servMgr_; + OHOS::sptr audioSrvHdf_; + OHOS::sptr fwkDAudioHdfCallback_; + std::atomic audioServStatus_ = AUDIO_INVALID_VALUE; + std::atomic audioextServStatus_ = AUDIO_INVALID_VALUE; + std::condition_variable hdfOperateCon_; + std::mutex hdfOperateMutex_; + int32_t hdfLoadRef_ = 0; + std::mutex hdfLoadRefMutex_; +}; + +class DAudioHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { +public: + using StatusCallback = std::function; + explicit DAudioHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) + { + } + ~DAudioHdfServStatListener() override = default; + void OnReceive(const ServiceStatus& status) override; + +private: + StatusCallback callback_; +}; + +class FwkDAudioHdfCallback : public IDAudioHdfCallback { +protected: + int32_t NotifyEvent(int32_t devId, const DAudioEvent& event) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DAUDIO_HDF_OPERATE_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h b/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h new file mode 100644 index 0000000000000000000000000000000000000000..f7cf7099081b68713d42667ef789facb5b8f114a --- /dev/null +++ b/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h @@ -0,0 +1,91 @@ +/* + * 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_DCAMERA_HDF_OPERATE_H +#define OHOS_DCAMERA_HDF_OPERATE_H + +#include +#include +#include + +#include "iservstat_listener_hdi.h" +#include "idevmgr_hdi.h" +#include "iservmgr_hdi.h" +#include "single_instance.h" +#include "v1_1/id_camera_provider.h" + +namespace OHOS { +namespace DistributedHardware { +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using OHOS::HDI::ServiceManager::V1_0::IServiceManager; +using OHOS::HDI::ServiceManager::V1_0::IServStatListener; +using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; +using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +using OHOS::HDI::DistributedCamera::V1_1::IDCameraProvider; +using OHOS::HDI::DistributedCamera::V1_1::IDCameraHdfCallback; +using OHOS::HDI::DistributedCamera::V1_1::DCameraHDFEvent; +const std::string CAMERA_SERVICE_NAME = "distributed_camera_service"; +const std::string PROVIDER_SERVICE_NAME = "distributed_camera_provider_service"; +constexpr uint16_t CAMERA_INVALID_VALUE = 0xffff; +constexpr int32_t CAMERA_WAIT_TIME = 2000; + +class FwkDCameraHdfCallback; +class DCameraHdfOperate { +DECLARE_SINGLE_INSTANCE(DCameraHdfOperate); + +public: + int32_t LoadDcameraHDFImpl(); + int32_t UnLoadDcameraHDFImpl(); + void ResetRefCount(); + +private: + int32_t WaitLoadCameraService(); + int32_t WaitLoadProviderService(); + OHOS::sptr MakeServStatListener(); + int32_t LoadDevice(); + int32_t UnLoadDevice(); + int32_t RegisterHdfListener(); + int32_t UnRegisterHdfListener(); + +private: + OHOS::sptr fwkDCameraHdfCallback_; + std::atomic cameraServStatus_ = CAMERA_INVALID_VALUE; + std::atomic providerServStatus_ = CAMERA_INVALID_VALUE; + std::condition_variable hdfOperateCon_; + std::mutex hdfOperateMutex_; + int32_t hdfLoadRef_ = 0; + std::mutex hdfLoadRefMutex_; +}; + +class DCameraHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { +public: + using StatusCallback = std::function; + explicit DCameraHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) + { + } + ~DCameraHdfServStatListener() override = default; + void OnReceive(const ServiceStatus& status) override; + +private: + StatusCallback callback_; +}; + +class FwkDCameraHdfCallback : public IDCameraHdfCallback { +protected: + int32_t NotifyEvent(int32_t devId, const DCameraHDFEvent& event) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_HDF_OPERATE_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 1769e890399eef7871611f2a7080632d1f145f73..0dc1ebc8835584373793fcc0ead2749c30ba10cb 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -639,6 +639,9 @@ void ComponentManager::DoRecover(DHType dhType) if (ret != DH_FWK_SUCCESS) { DHLOGE("DoRecover setname failed."); } + // reset hdf load status + DHLOGI("Reset HDF load ref for DHType %{public}" PRIu32, (uint32_t)dhType); + ResetHdfLoadRefCount(dhType); // reset enable status DHLOGI("Reset enable status for DHType %{public}" PRIu32, (uint32_t)dhType); ResetSinkEnableStatus(dhType); @@ -1742,6 +1745,10 @@ void ComponentManager::RecoverActiveEnableSource(DHType dhType) DHLOGI("RecoverActiveEnableSource end, dhType = %{public}#X.", dhType); } +void ComponentManager::ResetHdfLoadRefCount(DHType dhType) +{ +} + int32_t ComponentManager::InitCompSource(DHType dhType) { std::unique_lock lock(compSourceMutex_); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index bc63bfd32eb30daf8b48eaecc4f66acac5539bc6..125a00425034253b417b0c74b17a8de9dd4d9773 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -550,5 +550,15 @@ int32_t DistributedHardwareService::DisableSource( } return DH_FWK_SUCCESS; } + +int32_t DistributedHardwareService::LoadDistributedHDF(const DHType dhType) +{ + return ERR_DH_FWK_NO_HDF_SUPPORT; +} + +int32_t DistributedHardwareService::UnLoadDistributedHDF(const DHType dhType) +{ + return ERR_DH_FWK_NO_HDF_SUPPORT; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp index 19c8d50577e58eaf6bb66e7964c94362489ed403..0aeed9455352a246b3f48c360222197960220d22 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp @@ -553,6 +553,36 @@ int32_t DistributedHardwareStub::DisableSourceInner(MessageParcel &data, Message return DH_FWK_SUCCESS; } +int32_t DistributedHardwareStub::LoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply) +{ + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + DHType dhType = static_cast(data.ReadUint32()); + int32_t ret = LoadDistributedHDF(dhType); + if (!reply.WriteInt32(ret)) { + DHLOGE("Write ret code failed!"); + return ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL; + } + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareStub::UnLoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply) +{ + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + return ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL; + } + DHType dhType = static_cast(data.ReadUint32()); + int32_t ret = UnLoadDistributedHDF(dhType); + 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(); @@ -635,6 +665,12 @@ int32_t DistributedHardwareStub::OnRemoteRequestEx(uint32_t code, MessageParcel case static_cast(DHMsgInterfaceCode::DISABLE_SOURCE): { return DisableSourceInner(data, reply); } + case static_cast(DHMsgInterfaceCode::LOAD_HDF): { + return LoadDistributedHDFInner(data, reply); + } + case static_cast(DHMsgInterfaceCode::UNLOAD_HDF): { + return UnLoadDistributedHDFInner(data, reply); + } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index 510be3ca49e15ca7afefa5438de9ec923edfb7ae..9d9d05b286b8ab32d9244eb8051c11f9e8363ed9 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -926,8 +926,9 @@ HWTEST_F(ComponentManagerTest, Recover_001, TestSize.Level1) */ HWTEST_F(ComponentManagerTest, DoRecover_001, TestSize.Level1) { - DHType dhType = DHType::CAMERA; - ComponentManager::GetInstance().DoRecover(dhType); + ComponentManager::GetInstance().DoRecover(DHType::UNKNOWN); + ComponentManager::GetInstance().DoRecover(DHType::AUDIO); + ComponentManager::GetInstance().DoRecover(DHType::CAMERA); EXPECT_EQ(true, ComponentManager::GetInstance().compSource_.empty()); } 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 1e67bb281ac18fca0512b62e6547fb4ea08f4b29..21f6983850e917ff441fe7c72555d1c349c8a79a 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 @@ -531,5 +531,20 @@ HWTEST_F(DistributedHardwareServiceTest, QueryDhSysSpec_002, TestSize.Level1) cJSON_free(cjson1); cJSON_Delete(attrJson1); } + +HWTEST_F(DistributedHardwareServiceTest, LoadDistributedHDF_001, TestSize.Level1) +{ + DistributedHardwareService service(ASID, true); + EXPECT_EQ(DH_FWK_SUCCESS, service.LoadDistributedHDF(DHType::AUDIO)); + EXPECT_EQ(DH_FWK_SUCCESS, service.LoadDistributedHDF(DHType::AUDIO)); + EXPECT_EQ(DH_FWK_SUCCESS, service.LoadDistributedHDF(DHType::CAMERA)); + EXPECT_EQ(DH_FWK_SUCCESS, service.LoadDistributedHDF(DHType::CAMERA)); + EXPECT_EQ(ERR_DH_FWK_NO_HDF_SUPPORT, service.LoadDistributedHDF(DHType::UNKNOWN)); + EXPECT_EQ(DH_FWK_SUCCESS, service.UnLoadDistributedHDF(DHType::AUDIO)); + EXPECT_EQ(DH_FWK_SUCCESS, service.UnLoadDistributedHDF(DHType::AUDIO)); + EXPECT_EQ(DH_FWK_SUCCESS, service.UnLoadDistributedHDF(DHType::CAMERA)); + EXPECT_EQ(DH_FWK_SUCCESS, service.UnLoadDistributedHDF(DHType::CAMERA)); + EXPECT_EQ(ERR_DH_FWK_NO_HDF_SUPPORT, service.UnLoadDistributedHDF(DHType::UNKNOWN)); +} } // namespace DistributedHardware } // namespace OHOS 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 index 9e6d4975c98a8056493d3fe57d9a276b27a8c3b7..0f84636a6d9bf163fbaa67b17fe10e681433dba2 100644 --- 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 @@ -185,6 +185,18 @@ int32_t DisableSource(const std::string &networkId, const std::vector { 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 index 4e39062c4e9facce6a05a66399b46b88e41665e4..e8096830c0287fad7ee76a60f95fc9b1573ad6c2 100644 --- 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 @@ -690,5 +690,37 @@ HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_002, TestSize.Level1) spec = 5; EXPECT_EQ(false, stubTest_->ValidQueryLocalSpec(spec)); } + +/** + * @tc.name: LoadDistributedHDFInner_001 + * @tc.desc: Verify the LoadDistributedHDFInner function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, LoadDistributedHDFInner_001, TestSize.Level1) +{ + ASSERT_TRUE(stubTest_ != nullptr); + ASSERT_TRUE(token_ != nullptr); + EXPECT_CALL(*token_, VerifyAccessToken(_, _)).WillRepeatedly(Return(PERMISSION_GRANTED)); + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(DH_FWK_SUCCESS, stubTest_->LoadDistributedHDFInner(data, reply)); +} + +/** + * @tc.name: UnLoadDistributedHDFInner_001 + * @tc.desc: Verify the UnLoadDistributedHDFInner function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, UnLoadDistributedHDFInner_001, TestSize.Level1) +{ + ASSERT_TRUE(stubTest_ != nullptr); + ASSERT_TRUE(token_ != nullptr); + EXPECT_CALL(*token_, VerifyAccessToken(_, _)).WillRepeatedly(Return(PERMISSION_GRANTED)); + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(DH_FWK_SUCCESS, stubTest_->UnLoadDistributedHDFInner(data, reply)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp index db748356901acc73cefc0b6925ad912d223391ce..873945181bbbcfc6b26386fbf1e4cb37017d26aa 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -47,13 +47,6 @@ void DHModemContextExtTest::TearDownTestCase() {} EXPECT_EQ(ret, DH_FWK_SUCCESS); } - HWTEST_F(DHModemContextExtTest, GetModemExtInstance_001, TestSize.Level1) - { - DHModemContextExt::GetInstance().soHandle_ = nullptr; - DHModemContextExt::GetInstance().GetModemExtInstance(); - EXPECT_NE(DHModemContextExt::GetInstance().distributedModemExt_, nullptr); - } - HWTEST_F(DHModemContextExtTest, GetModemExtInstance_002, TestSize.Level1) { int32_t ret = DHModemContextExt::GetInstance().GetHandler();