From 81d56b457b73bbb50a311b538968ff404c50fb3b Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 13 Jun 2025 11:27:49 +0800 Subject: [PATCH 1/2] add anti Signed-off-by: BrainL --- common/BUILD.gn | 3 + .../distributed_device_profile_constants.h | 3 + .../distributed_device_profile_errors.h | 5 + .../distributed_device_profile_enums.h | 8 +- .../interfaces/i_distributed_device_profile.h | 6 + .../distributed_device_profile_constants.cpp | 3 + .../distributed_device_profile_client.h | 14 ++ .../distributed_device_profile_proxy.h | 6 + .../src/distributed_device_profile_client.cpp | 134 ++++++++++++ .../src/distributed_device_profile_proxy.cpp | 63 ++++++ services/core/BUILD.gn | 3 + .../distributed_device_profile_service_new.h | 8 + .../distributed_device_profile_stub_new.h | 4 + .../listener/kv_store_death_recipient.cpp | 4 + ...distributed_device_profile_service_new.cpp | 124 +++++++++++ .../distributed_device_profile_stub_new.cpp | 77 +++++++ services/core/test/BUILD.gn | 22 ++ services/core/test/fuzztest/BUILD.gn | 1 + ...tributed_device_profile_client_kv_test.cpp | 205 ++++++++++++++++++ ...stributed_device_profile_stub_new_test.cpp | 90 ++++++++ 20 files changed, 782 insertions(+), 1 deletion(-) diff --git a/common/BUILD.gn b/common/BUILD.gn index 82066840..dc264caf 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -55,6 +55,9 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/access_control_profile.cpp", "src/interfaces/accessee.cpp", "src/interfaces/accesser.cpp", + "src/interfaces/business_callback_proxy.cpp", + "src/interfaces/business_callback_stub.cpp", + "src/interfaces/business_event.cpp", "src/interfaces/characteristic_profile.cpp", "src/interfaces/device_icon_info.cpp", "src/interfaces/device_icon_info_filter_options.cpp", diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 02c274d8..c33cb2ff 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -310,6 +310,9 @@ extern const std::string ACCESSERID_EQUAL_CONDITION; extern const std::string ACCESSEEID_EQUAL_CONDITION; extern const std::string IS_LNN_ACL; extern const std::string LNN_ACL_TRUE; +extern const std::string BUSINESS_KEY; +extern const std::string BUSINESS_VALUE; + constexpr int32_t ROWCNT_INIT = -1; constexpr int32_t RET_INIT = -1; constexpr int32_t ROWCOUNT_INIT = -1; diff --git a/common/include/constants/distributed_device_profile_errors.h b/common/include/constants/distributed_device_profile_errors.h index ed3d19f8..0d0918fe 100644 --- a/common/include/constants/distributed_device_profile_errors.h +++ b/common/include/constants/distributed_device_profile_errors.h @@ -208,6 +208,11 @@ constexpr int32_t DP_PUT_LOCAL_SERVICE_INFO_FAIL = 98566326; constexpr int32_t DP_DELETE_LOCAL_SERVICE_INFO_FAIL = 98566327; constexpr int32_t DP_UPDATE_LOCAL_SERVICE_INFO_FAIL = 98566328; constexpr int32_t DP_LOCAL_SERVICE_INFO_MANAGER_INIT_FAIL = 98566329; +constexpr int32_t DP_BUSINESS_EVENT_MANAGER_INIT_FAIL = 98566330; +constexpr int32_t DP_BUSINESS_EVENT_MANAGER_UNINIT_FAIL = 98566331; +constexpr int32_t DP_PUT_BUSINESS_EVENT_FAIL = 98566332; +constexpr int32_t DP_GET_BUSINESS_EVENT_FAIL = 98566333; +constexpr int32_t DP_NOTIFY_BUSINESS_EVENT_FAIL = 98566334; } // namespace DistributedDeviceProfile } // namespace OHOS #endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ERRORS_H diff --git a/common/include/interfaces/distributed_device_profile_enums.h b/common/include/interfaces/distributed_device_profile_enums.h index 6b62fa98..3ca83d93 100644 --- a/common/include/interfaces/distributed_device_profile_enums.h +++ b/common/include/interfaces/distributed_device_profile_enums.h @@ -16,6 +16,7 @@ #ifndef OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ENUMS_H #define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ENUMS_H +#include #include namespace OHOS { @@ -86,7 +87,12 @@ enum class DPInterfaceCode : uint32_t { GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE = 68, DELETE_LOCAL_SERVICE_INFO = 69, GET_ALL_ACL_INCLUDE_LNN_ACL = 70, - MAX = 71 + ON_BUSINESS_EVENT = 71, + REGISTER_BUSINESS_CALLBACK = 72, + UNREGISTER_BUSINESS_CALLBACK = 73, + PUT_BUSINESS_EVENT = 74, + GET_BUSINESS_EVENT = 75, + MAX = 76 }; enum class DeviceIdType : uint32_t { diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h index b459ecc6..567de016 100644 --- a/common/include/interfaces/i_distributed_device_profile.h +++ b/common/include/interfaces/i_distributed_device_profile.h @@ -28,6 +28,7 @@ #include "device_profile_filter_options.h" #include "dp_subscribe_info.h" #include "dp_sync_options.h" +#include "i_business_callback.h" #include "i_sync_completed_callback.h" #include "product_info.h" #include "service_info_profile.h" @@ -104,6 +105,11 @@ public: virtual int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) = 0; virtual int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) = 0; + virtual int32_t RegisterBusinessCallback(const std::string& saId, const std::string& businessKey, + sptr businessCallback) = 0; + virtual int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) = 0; + virtual int32_t PutBusinessEvent(const BusinessEvent& event) = 0; + virtual int32_t GetBusinessEvent(BusinessEvent& event) = 0; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/constants/distributed_device_profile_constants.cpp b/common/src/constants/distributed_device_profile_constants.cpp index 87ad9c09..8f3a1565 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -241,6 +241,9 @@ const std::string ACCESSERID_EQUAL_CONDITION = "accesserId = ? "; const std::string ACCESSEEID_EQUAL_CONDITION = "accesseeId = ? "; const std::string IS_LNN_ACL = "IsLnnAcl"; const std::string LNN_ACL_TRUE = "true"; +const std::string BUSINESS_KEY = "businessKey"; +const std::string BUSINESS_VALUE = "businessValue"; + const std::string CREATE_TURST_DEVICE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS trust_device_table\ (\ deviceId TEXT PRIMARY KEY,\ diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index c9616d28..f0140a52 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -34,6 +34,7 @@ #include "single_instance.h" #include "dp_subscribe_info.h" #include "distributed_device_profile_constants.h" +#include "i_business_callback.h" #include "sync_completed_callback_stub.h" #include "system_ability_status_change_stub.h" #include "profile_change_listener_stub.h" @@ -102,6 +103,11 @@ public: int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, int32_t pinExchangeType, LocalServiceInfo& localServiceInfo); int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType); + int32_t RegisterBusinessCallback(const std::string& saId, const std::string& businessKey, + sptr businessCallback); + int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey); + int32_t PutBusinessEvent(const BusinessEvent& event); + int32_t GetBusinessEvent(BusinessEvent& event); void LoadSystemAbilitySuccess(const sptr &remoteObject); void LoadSystemAbilityFail(); @@ -128,6 +134,9 @@ private: void ReleaseSubscribeDeviceProfileInited(); void ReleaseSubscribePinCodeInvalid(); void ReleaseDeathRecipient(); + void ReRegisterBusinessCallback(); + void ReleaseRegisterBusinessCallback(); + void StartThreadReRegisterBusinessCallback(); class DeviceProfileDeathRecipient : public IRemoteObject::DeathRecipient { public: @@ -152,6 +161,11 @@ private: std::mutex saListenerLock_; sptr saListenerCallback_ = nullptr; + + std::mutex businessLock_; + sptr businessCallback_ = nullptr; + std::string strSaId_ = ""; + std::string businessKey_ = ""; }; } // namespace DeviceProfile } // namespace OHOS diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h index 103d478d..4af62662 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h @@ -28,6 +28,7 @@ #include "refbase.h" #include "distributed_device_profile_enums.h" #include "distributed_device_profile_errors.h" +#include "i_business_callback.h" #include "ipc_utils.h" #include "profile_change_listener_stub.h" @@ -98,6 +99,11 @@ public: int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) override; int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) override; + int32_t RegisterBusinessCallback(const std::string& saId, const std::string& businessKey, + sptr businessCallback) override; + int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) override; + int32_t PutBusinessEvent(const BusinessEvent& event) override; + int32_t GetBusinessEvent(BusinessEvent& event) override; private: static inline BrokerDelegator delegator_; diff --git a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index ed603963..781bde76 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -914,6 +914,7 @@ void DistributedDeviceProfileClient::SystemAbilityListener::OnAddSystemAbility(i DistributedDeviceProfileClient::GetInstance().StartThreadSendSubscribeInfos(); DistributedDeviceProfileClient::GetInstance().StartThreadReSubscribePinCodeInvalid(); DistributedDeviceProfileClient::GetInstance().ReSubscribeDeviceProfileInited(); + DistributedDeviceProfileClient::GetInstance().StartThreadReRegisterBusinessCallback(); } void DistributedDeviceProfileClient::ReleaseSubscribeDeviceProfileSA() @@ -997,6 +998,139 @@ void DistributedDeviceProfileClient::ReleaseResource() ReleaseSubscribePinCodeInvalid(); ReleaseSubscribeDeviceProfileInited(); ReleaseDeathRecipient(); + ReleaseRegisterBusinessCallback(); +} + +void DistributedDeviceProfileClient::StartThreadReRegisterBusinessCallback() +{ + HILOGI("Send Register Business Callback cache in proxy to service!"); + std::thread(&DistributedDeviceProfileClient::ReRegisterBusinessCallback, this).detach(); +} + +void DistributedDeviceProfileClient::ReRegisterBusinessCallback() +{ + HILOGI("call"); + std::string saId = ""; + std::string businessKey = ""; + sptr businessCallback = nullptr; + { + std::lock_guard lock(businessLock_); + if (businessCallback_ == nullptr) { + HILOGI("not use Retry Register Business Callback"); + return; + } + saId = strSaId_; + businessKey = businessKey_; + businessCallback = businessCallback_; + } + int32_t ret = RegisterBusinessCallback(saId, businessKey, businessCallback); + if (ret != DP_SUCCESS) { + HILOGE("Retry Register Business Callback failed"); + return; + } + HILOGI("Retry Register Business Callback succeed"); +} + +void DistributedDeviceProfileClient::ReleaseRegisterBusinessCallback() +{ + std::string saId = ""; + std::string businessKey = ""; + { + std::lock_guard lock(businessLock_); + if (businessCallback_ == nullptr) { + return; + } + saId = strSaId_; + businessKey = businessKey_; + } + + int32_t ret = UnRegisterBusinessCallback(saId, businessKey); + if (ret != DP_SUCCESS) { + HILOGE("unRegisterBusinessCallback failed, ret=%{public}d", ret); + return; + } + + HILOGD("ReleaseRegisterBusinessCallback success"); +} + +int32_t DistributedDeviceProfileClient::RegisterBusinessCallback(const std::string& saId, + const std::string& businessKey, sptr businessCallback) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + if (saId.empty() || businessKey.empty() || businessCallback == nullptr) { + HILOGE("Invalid parameters: saId or businessKey is empty, or businessCallback is nullptr"); + return DP_INVALID_PARAM; + } + sptr innerBusinessCallback = businessCallback->AsObject(); + if (innerBusinessCallback == nullptr) { + HILOGE("businessCallback ipc cast fail!"); + return DP_INVALID_PARAM; + } + { + std::lock_guard lock(businessLock_); + int32_t ret = dpService->RegisterBusinessCallback(saId, businessKey, innerBusinessCallback); + if (ret != DP_SUCCESS) { + HILOGE("Subscribe DP Inited failed!"); + return ret; + } + strSaId_ = saId; + businessKey_ = businessKey; + businessCallback_ = businessCallback; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileClient::UnRegisterBusinessCallback(const std::string& saId, + const std::string& businessKey) +{ + if (businessCallback_ == nullptr) { + HILOGE("not subscribe pincode invalid, no need unsubscribe pincode invalid"); + return DP_SUCCESS; + } + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + if (saId.empty() || businessKey.empty()) { + HILOGE("Invalid parameters: saId or businessKey is empty"); + return DP_INVALID_PARAM; + } + { + std::lock_guard lock(businessLock_); + int32_t ret = dpService->UnRegisterBusinessCallback(saId, businessKey); + if (ret != DP_SUCCESS) { + HILOGE("Unsubscribe DP Inited failed!"); + businessCallback_ = nullptr; + return ret; + } + businessCallback_ = nullptr; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileClient::PutBusinessEvent(const BusinessEvent& event) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->PutBusinessEvent(event); +} + +int32_t DistributedDeviceProfileClient::GetBusinessEvent(BusinessEvent& event) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->GetBusinessEvent(event); } } // namespace DeviceProfile } // namespace OHOS diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp index 96f09af2..9abe3f8d 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp @@ -785,5 +785,68 @@ int32_t DistributedDeviceProfileProxy::DeleteLocalServiceInfo(const std::string& static_cast(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO), data, reply); return DP_SUCCESS; } + +int32_t DistributedDeviceProfileProxy::RegisterBusinessCallback(const std::string& saId, + const std::string& businessKey, sptr businessCallback) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + WRITE_HELPER(data, String, saId); + WRITE_HELPER(data, String, businessKey); + WRITE_HELPER(data, RemoteObject, businessCallback); + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::REGISTER_BUSINESS_CALLBACK), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::UnRegisterBusinessCallback(const std::string& saId, + const std::string& businessKey) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + WRITE_HELPER(data, String, saId); + WRITE_HELPER(data, String, businessKey); + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNREGISTER_BUSINESS_CALLBACK), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::PutBusinessEvent(const BusinessEvent& event) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!event.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_BUSINESS_EVENT), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetBusinessEvent(BusinessEvent& event) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!event.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_BUSINESS_EVENT), data, reply); + if (!event.UnMarshalling(reply)) { + HILOGE("dp ipc read parcel fail"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index abd0f5e7..f4c2aba5 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -20,6 +20,7 @@ config("device_info_manager_config") { visibility += [ "./test/*" ] include_dirs = [ "include", + "include/businesseventmanager", "include/contentsensormanager", "include/common", "include/data_share", @@ -80,6 +81,7 @@ ohos_shared_library("distributed_device_profile_svr") { install_enable = true sources = [ + "src/businesseventmanager/business_event_manager.cpp", "src/common/dp_services_constants.cpp", "src/contentsensormanager/collaboration_info_collector.cpp", "src/contentsensormanager/collector.cpp", @@ -105,6 +107,7 @@ ohos_shared_library("distributed_device_profile_svr") { "src/multiusermanager/multi_user_manager.cpp", "src/permissionmanager/permission_manager.cpp", "src/persistenceadapter/assetadapter/asset_adapter.cpp", + "src/persistenceadapter/kvadapter/business_event_adapter.cpp", "src/persistenceadapter/kvadapter/kv_adapter.cpp", "src/persistenceadapter/kvadapter/switch_adapter.cpp", "src/persistenceadapter/rdbadapter/local_service_info_rdb_adapter.cpp", diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 47531045..7a3f6544 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -113,6 +113,11 @@ public: void DelayUnloadTask() override; bool IsInited() override; void SubscribeAccountCommonEvent(); + int32_t RegisterBusinessCallback(const std::string& saId, const std::string& businessKey, + sptr businessCallback) override; + int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) override; + int32_t PutBusinessEvent(const BusinessEvent& event) override; + int32_t GetBusinessEvent(BusinessEvent& event) override; protected: void OnStart(const SystemAbilityOnDemandReason& startReason) override; @@ -130,6 +135,7 @@ private: int32_t SaveDynamicProfilesFromTempCache(); int32_t NotifyDeviceProfileInited(); int32_t NotifyPinCodeInvalid(const LocalServiceInfo& localServiceInfo); + int32_t NotifyBusinessEvent(const BusinessEvent& event); void GetDynamicProfilesFromTempCache(std::map& entries); void ClearProfileCache(); int32_t UnInitNext(); @@ -155,6 +161,8 @@ private: DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN }; + std::mutex businessEventCallbackMapMtx_; + std::map, sptr> businessCallbackMap_; }; } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/include/distributed_device_profile_stub_new.h b/services/core/include/distributed_device_profile_stub_new.h index be823eaf..c24d6744 100644 --- a/services/core/include/distributed_device_profile_stub_new.h +++ b/services/core/include/distributed_device_profile_stub_new.h @@ -83,6 +83,10 @@ public: int32_t UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); virtual void DelayUnloadTask() = 0; virtual bool IsInited() = 0; + int32_t RegisterBusinessCallbackInner(MessageParcel& data, MessageParcel& reply); + int32_t UnRegisterBusinessCallbackInner(MessageParcel& data, MessageParcel& reply); + int32_t PutBusinessEventInner(MessageParcel& data, MessageParcel& reply); + int32_t GetBusinessEventInner(MessageParcel& data, MessageParcel& reply); private: using Func = int32_t(DistributedDeviceProfileStubNew::*)(MessageParcel& data, MessageParcel& reply); diff --git a/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp b/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp index 1a95d640..cfda0158 100644 --- a/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp +++ b/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp @@ -28,6 +28,7 @@ namespace { const std::string REINIT_TASK = "reInitTask"; const std::string DYNAMIC_STORE_ID = "dp_kv_store"; const std::string STATIC_STORE_ID = "dp_kv_static_store"; + const std::string BUSINESS_STORE_ID = "dp_kv_store_business"; } KvDeathRecipient::KvDeathRecipient(const std::string& storeId) @@ -65,6 +66,9 @@ void KvDeathRecipient::OnRemoteDied() if (storeId == STATIC_STORE_ID) { StaticProfileManager::GetInstance().ReInit(); } + if (storeId == BUSINESS_STORE_ID) { + DeviceProfileManager::GetInstance().ReInit(); + } }; { std::lock_guard lock(reInitMutex_); diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 07fb1c5d..0a800a80 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -24,6 +24,7 @@ #include "iservice_registry.h" #include "sa_profiles.h" +#include "business_event_manager.h" #include "common_event_support.h" #include "content_sensor_manager.h" #include "device_profile_dumper.h" @@ -150,6 +151,10 @@ int32_t DistributedDeviceProfileServiceNew::PostInitNext() HILOGE("ContentSensorManager init failed"); return DP_CONTENT_SENSOR_MANAGER_INIT_FAIL; } + if (BusinessEventManager::GetInstance().Init() != DP_SUCCESS) { + HILOGE("BusinessEventManager init failed"); + return DP_BUSINESS_EVENT_MANAGER_INIT_FAIL; + } SaveSwitchProfilesFromTempCache(); SaveDynamicProfilesFromTempCache(); isInited_ = true; @@ -186,6 +191,10 @@ int32_t DistributedDeviceProfileServiceNew::UnInit() HILOGE("StaticProfileManager UnInit failed"); return DP_CONTENT_SENSOR_MANAGER_UNINIT_FAIL; } + if (BusinessEventManager::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("BusinessEventManager UnInit failed"); + return DP_BUSINESS_EVENT_MANAGER_UNINIT_FAIL; + } int32_t ret = UnInitNext(); if (ret != DP_SUCCESS) { return ret; @@ -1276,5 +1285,120 @@ int32_t DistributedDeviceProfileServiceNew::PutAllTrustedDevices(const std::vect } return ProfileCache::GetInstance().AddAllTrustedDevices(deviceInfos); } + +int32_t DistributedDeviceProfileServiceNew::RegisterBusinessCallback(const std::string& saId, + const std::string& businessKey, sptr businessCallback) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + if (saId.empty() || businessKey.empty() || businessCallback == nullptr) { + HILOGE("Invalid parameters: saId or businessKey is empty, or businessCallback is nullptr"); + return DP_INVALID_PARAM; + } + + sptr callbackProxy = iface_cast(businessCallback); + if (callbackProxy == nullptr) { + HILOGE("Cast to IBusinessCallback failed!"); + return DP_NULLPTR; + } + std::lock_guard lock(businessEventCallbackMapMtx_); + if (businessCallbackMap_.find({saId, businessKey}) != businessCallbackMap_.end()) { + HILOGE("saId and businessKey is exist, saId : %{public}s, businessKey: %{public}s", + saId.c_str(), businessKey.c_str()); + return DP_INVALID_PARAM; + } + businessCallbackMap_[std::make_pair(saId, businessKey)] = businessCallback; + + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileServiceNew::UnRegisterBusinessCallback(const std::string& saId, const std::string& + businessKey) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + if (saId.empty() || businessKey.empty()) { + HILOGE("Invalid parameters: saId or businessKey is empty"); + return DP_INVALID_PARAM; + } + std::lock_guard lock(businessEventCallbackMapMtx_); + auto it = businessCallbackMap_.find(std::make_pair(saId, businessKey)); + if (it == businessCallbackMap_.end()) { + HILOGE("Callback not found for saId: %{public}s, businessKey: %{public}s", saId.c_str(), businessKey.c_str()); + return DP_INVALID_PARAM; + } + businessCallbackMap_.erase(std::make_pair(saId, businessKey)); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileServiceNew::PutBusinessEvent(const BusinessEvent& event) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface PutBusinessEvent"); + int32_t ret = BusinessEventManager::GetInstance().PutBusinessEvent(event); + if (ret != DP_SUCCESS) { + HILOGE("PutBusinessEvent failed, ret: %{public}d", ret); + return ret; + } + ret = NotifyBusinessEvent(event); + if (ret != DP_SUCCESS) { + HILOGE("NotifyBusinessEvent failed, BusinessKey: %{public}s, ret: %{public}d", + event.GetBusinessKey().c_str(), ret); + return DP_NOTIFY_BUSINESS_EVENT_FAIL; + } + HILOGI("NotifyBusinessEvent, BusinessEvent:%{public}s", event.dump().c_str()); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileServiceNew::GetBusinessEvent(BusinessEvent& event) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface GetBusinessEvent"); + return BusinessEventManager::GetInstance().GetBusinessEvent(event); +} + +int32_t DistributedDeviceProfileServiceNew::NotifyBusinessEvent(const BusinessEvent& event) +{ + HILOGI("NotifyBusinessEvent called for BusinessKey: %{public}s, BusinessValue: %{public}s", + event.GetBusinessKey().c_str(), event.GetBusinessValue().c_str()); + sptr callbackProxy = nullptr; + std::lock_guard lock(businessEventCallbackMapMtx_); + for (const auto& [key, callback] : businessCallbackMap_) { + if (key.second != event.GetBusinessKey()) { + HILOGI("BusinessKey not find"); + continue; + } + callbackProxy = iface_cast(callback); + if (callbackProxy == nullptr) { + HILOGE("Cast to IBusinessCallback failed!"); + continue; + } + auto task = [callbackProxy, event]() { + if (callbackProxy == nullptr) { + HILOGE("OnBusinessEvent task callbackProxy is nullptr"); + return; + } + callbackProxy->OnBusinessEvent(event); + }; + auto handler = EventHandlerFactory::GetInstance().GetEventHandler(); + HILOGI("notify"); + if (handler == nullptr || !handler->PostTask(task)) { + HILOGE("Post OnBusinessEvent task failed"); + continue; + } + } + HILOGI("NotifyBusinessEvent task posted successfully"); + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp index 9cbacdb9..807636e8 100644 --- a/services/core/src/distributed_device_profile_stub_new.cpp +++ b/services/core/src/distributed_device_profile_stub_new.cpp @@ -207,6 +207,14 @@ int32_t DistributedDeviceProfileStubNew::NotifyLocalServiceEventInner(uint32_t c return GetLocalServiceInfoByBundleAndPinTypeInner(data, reply); case static_cast(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO): return DeleteLocalServiceInfoInner(data, reply); + case static_cast(DPInterfaceCode::REGISTER_BUSINESS_CALLBACK): + return RegisterBusinessCallbackInner(data, reply); + case static_cast(DPInterfaceCode::UNREGISTER_BUSINESS_CALLBACK): + return UnRegisterBusinessCallbackInner(data, reply); + case static_cast(DPInterfaceCode::PUT_BUSINESS_EVENT): + return PutBusinessEventInner(data, reply); + case static_cast(DPInterfaceCode::GET_BUSINESS_EVENT): + return GetBusinessEventInner(data, reply); default: HILOGW("unknown request code, please check, code = %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -1053,5 +1061,74 @@ int32_t DistributedDeviceProfileStubNew::DeleteDeviceProfileBatchInner(MessagePa } return DP_SUCCESS; } + +int32_t DistributedDeviceProfileStubNew::RegisterBusinessCallbackInner(MessageParcel& data, MessageParcel& reply) +{ + std::string saId = ""; + std::string businessKey = ""; + READ_HELPER(data, String, saId); + READ_HELPER(data, String, businessKey); + sptr businessCallback = data.ReadRemoteObject(); + if (businessCallback == nullptr) { + HILOGE("read remoteObject failed!"); + return ERR_FLATTEN_OBJECT; + } + int32_t ret = RegisterBusinessCallback(saId, businessKey, businessCallback); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStubNew::UnRegisterBusinessCallbackInner(MessageParcel& data, MessageParcel& reply) +{ + std::string saId = ""; + std::string businessKey = ""; + READ_HELPER(data, String, saId); + READ_HELPER(data, String, businessKey); + int32_t ret = UnRegisterBusinessCallback(saId, businessKey); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStubNew::PutBusinessEventInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + BusinessEvent event; + if (!event.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = PutBusinessEvent(event); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStubNew::GetBusinessEventInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + BusinessEvent event; + if (!event.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = GetBusinessEvent(event); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + if (!event.Marshalling(reply)) { + HILOGE("write parcel fail!"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/test/BUILD.gn b/services/core/test/BUILD.gn index 5d82a44f..85de0735 100644 --- a/services/core/test/BUILD.gn +++ b/services/core/test/BUILD.gn @@ -488,6 +488,26 @@ ohos_unittest("product_info_dao_test") { subsystem_name = "deviceprofile" } +ohos_unittest("business_event_adapter_test") { + module_out_path = module_output_path + sources = [ "unittest/business_event_adapter_test.cpp" ] + configs = device_profile_configs + deps = device_profile_deps + external_deps = device_profile_external_deps + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} + +ohos_unittest("business_event_manager_test") { + module_out_path = module_output_path + sources = [ "unittest/business_event_manager_test.cpp" ] + configs = device_profile_configs + deps = device_profile_deps + external_deps = device_profile_external_deps + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} + group("unittest") { testonly = true deps = [ @@ -533,5 +553,7 @@ group("unittest") { ":sync_options_new_test", ":sync_subscriber_death_recipient_test", ":trust_Device_Profile_test", + ":business_event_manager_test", + ":business_event_adapter_test", ] } diff --git a/services/core/test/fuzztest/BUILD.gn b/services/core/test/fuzztest/BUILD.gn index 67e4b2a2..18f15029 100644 --- a/services/core/test/fuzztest/BUILD.gn +++ b/services/core/test/fuzztest/BUILD.gn @@ -18,5 +18,6 @@ group("fuzztest") { "newdeviceprofile_fuzzer:fuzztest", "profileutils_fuzzer:fuzztest", "trustprofilemanager_fuzzer:fuzztest", + "businesseventmanager_fuzzer:fuzztest", ] } diff --git a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp index ea2db737..cdb75b63 100644 --- a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp @@ -19,6 +19,7 @@ #define protected public #include "gtest/gtest.h" #include "refbase.h" +#include "business_callback_stub.h" #include "distributed_device_profile_constants.h" #include "distributed_device_profile_errors.h" #include "distributed_device_profile_log.h" @@ -157,6 +158,21 @@ public: } }; +class BusinessCallback : public BusinessCallbackStub { +public: + BusinessCallback() + { + } + ~BusinessCallback() + { + } + int32_t OnBusinessEvent(const BusinessEvent &event) + { + (void)event; + return DP_SUCCESS; + } +}; + /** * @tc.name:PutServiceProfile001 * @tc.desc: PutServiceProfile success @@ -918,5 +934,194 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, SubscribePinCodeInvalid_002, Test pincodeInvalidCb); EXPECT_EQ(ret, DP_PERMISSION_DENIED); } + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_001, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_SUCCESS); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_002, TestSize.Level1) +{ + std::string saId = ""; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_003, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = ""; + sptr businessCallback = sptr(new BusinessCallback()); + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_004, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = nullptr; + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_005, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = nullptr; + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_GET_SERVICE_FAILED); + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = + DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); + EXPECT_NE(DistributedDeviceProfileClient::GetInstance().dpProxy_, nullptr); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, RegisterBusinessCallback_006, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + + sptr innerBusinessCallback = nullptr; + + int32_t ret = DistributedDeviceProfileClient::GetInstance(). + RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, UnRegisterBusinessCallback_001, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + DistributedDeviceProfileClient::GetInstance().businessCallback_ = businessCallback; + + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterBusinessCallback(saId, businessKey); + EXPECT_EQ(ret, DP_SUCCESS); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, UnRegisterBusinessCallback_002, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + DistributedDeviceProfileClient::GetInstance().businessCallback_ = nullptr; + + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterBusinessCallback(saId, businessKey); + EXPECT_EQ(ret, DP_SUCCESS); + + sptr businessCallback = sptr(new BusinessCallback()); + ret = DistributedDeviceProfileClient::GetInstance().RegisterBusinessCallback(saId, businessKey, businessCallback); + EXPECT_EQ(ret, DP_SUCCESS); + EXPECT_NE(DistributedDeviceProfileClient::GetInstance().businessCallback_, nullptr); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, UnRegisterBusinessCallback_003, TestSize.Level1) +{ + std::string saId = ""; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + DistributedDeviceProfileClient::GetInstance().businessCallback_ = businessCallback; + + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterBusinessCallback(saId, businessKey); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, UnRegisterBusinessCallback_004, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = ""; + sptr businessCallback = sptr(new BusinessCallback()); + DistributedDeviceProfileClient::GetInstance().businessCallback_ = businessCallback; + + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterBusinessCallback(saId, businessKey); + EXPECT_EQ(ret, DP_INVALID_PARAM); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, UnRegisterBusinessCallback_005, TestSize.Level1) +{ + std::string saId = "validSaId"; + std::string businessKey = "validBusinessKey"; + sptr businessCallback = sptr(new BusinessCallback()); + DistributedDeviceProfileClient::GetInstance().businessCallback_ = businessCallback; + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = nullptr; + + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterBusinessCallback(saId, businessKey); + EXPECT_EQ(ret, DP_GET_SERVICE_FAILED); + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = + DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); + EXPECT_NE(DistributedDeviceProfileClient::GetInstance().dpProxy_, nullptr); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, PutBusinessEvent_001, TestSize.Level1) +{ + DistributedDeviceProfileClient::GetInstance().dpProxy_ = nullptr; + + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + event.SetBusinessValue("validValue"); + + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutBusinessEvent(event); + EXPECT_EQ(ret, DP_GET_SERVICE_FAILED); + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = + DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); + EXPECT_NE(DistributedDeviceProfileClient::GetInstance().dpProxy_, nullptr); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, PutBusinessEvent_002, TestSize.Level1) +{ + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + event.SetBusinessValue("validValue"); + + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutBusinessEvent(event); + EXPECT_EQ(ret, DP_SUCCESS); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, GetBusinessEvent_001, TestSize.Level1) +{ + DistributedDeviceProfileClient::GetInstance().dpProxy_ = nullptr; + + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetBusinessEvent(event); + EXPECT_EQ(ret, DP_GET_SERVICE_FAILED); + + DistributedDeviceProfileClient::GetInstance().dpProxy_ = + DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); + EXPECT_NE(DistributedDeviceProfileClient::GetInstance().dpProxy_, nullptr); +} + +HWTEST_F(DistributedDeviceProfileClientKvTest, GetBusinessEvent_002, TestSize.Level1) +{ + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetBusinessEvent(event); + EXPECT_EQ(ret, DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp index 4c77e733..28c5cf93 100644 --- a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp @@ -94,6 +94,11 @@ class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubN int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) override; int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) override; + int32_t RegisterBusinessCallback(const std::string& saId, const std::string& businessKey, + sptr businessCallback) override; + int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) override; + int32_t PutBusinessEvent(const BusinessEvent &event) override; + int32_t GetBusinessEvent(BusinessEvent &event) override; void DelayUnloadTask() override; bool IsInited() override; }; @@ -445,6 +450,35 @@ int32_t MockDistributedDeviceProfileStubNew::DeleteLocalServiceInfo(const std::s (void)pinExchangeType; return 0; } + +int32_t MockDistributedDeviceProfileStubNew::RegisterBusinessCallback(const std::string& saId, + const std::string& businessKey, sptr businessCallback) +{ + (void)saId; + (void)businessKey; + (void)businessCallback; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::UnRegisterBusinessCallback(const std::string& saId, + const std::string& businessKey) +{ + (void)saId; + (void)businessKey; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::PutBusinessEvent(const BusinessEvent& event) +{ + (void)event; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::GetBusinessEvent(BusinessEvent& event) +{ + (void)event; + return 0; +} /** * @tc.name: IsInterfaceTokenValid001 * @tc.desc: IsInterfaceTokenValid @@ -1128,5 +1162,61 @@ HWTEST_F(DistributedDeviceProfileStubNewTest, PutAllTrustedDevicesInner_001, Tes int32_t ret = ProfileStub_->PutAllTrustedDevicesInner(data, reply); EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); } + +HWTEST_F(DistributedDeviceProfileStubNewTest, RegisterBusinessCallbackInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteString("validSaId"); + data.WriteString("validBusinessKey"); + data.WriteRemoteObject(nullptr); + + int32_t ret = ProfileStub_->RegisterBusinessCallbackInner(data, reply); + EXPECT_EQ(ret, ERR_FLATTEN_OBJECT); +} + +HWTEST_F(DistributedDeviceProfileStubNewTest, UnRegisterBusinessCallbackInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteString("validSaId"); + data.WriteString("validBusinessKey"); + + int32_t ret = ProfileStub_->UnRegisterBusinessCallbackInner(data, reply); + EXPECT_EQ(ret, DP_SUCCESS); + EXPECT_EQ(reply.ReadInt32(), DP_SUCCESS); +} + +HWTEST_F(DistributedDeviceProfileStubNewTest, PutBusinessEventInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + event.SetBusinessValue("validValue"); + event.Marshalling(data); + + int32_t ret = ProfileStub_->PutBusinessEventInner(data, reply); + EXPECT_EQ(ret, DP_SUCCESS); + EXPECT_EQ(reply.ReadInt32(), DP_SUCCESS); +} + +HWTEST_F(DistributedDeviceProfileStubNewTest, GetBusinessEventInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + BusinessEvent event; + event.SetBusinessKey("business_id_cast+_reject_event"); + event.SetBusinessValue("validValue"); + event.Marshalling(data); + + int32_t ret = ProfileStub_->GetBusinessEventInner(data, reply); + EXPECT_EQ(ret, DP_SUCCESS); + EXPECT_EQ(reply.ReadInt32(), DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS -- Gitee From 39c777b7773721afa5c49204de43be459e1b0915 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 13 Jun 2025 11:50:25 +0800 Subject: [PATCH 2/2] modify format Signed-off-by: BrainL --- services/core/src/distributed_device_profile_service_new.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 0a800a80..5a1fd52f 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -1316,7 +1316,7 @@ int32_t DistributedDeviceProfileServiceNew::RegisterBusinessCallback(const std:: int32_t DistributedDeviceProfileServiceNew::UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) -{ +{ if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("the caller is permission denied!"); return DP_PERMISSION_DENIED; -- Gitee