diff --git a/bundle.json b/bundle.json index 4f5ee067d1d412ec015baddc3b485ad96ec78ff4..68d073ec9c32ba56c992df546947e2b26b5a2267 100644 --- a/bundle.json +++ b/bundle.json @@ -72,8 +72,7 @@ "name": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_sdk", "header": { "header_files": [ - "distributed_device_profile_client.h", - "distributed_device_profile_proxy.h" + "distributed_device_profile_client.h" ], "header_base": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core/include/" } @@ -89,7 +88,6 @@ "device_profile.h", "dp_subscribe_info.h", "dp_sync_options.h", - "i_distributed_device_profile.h", "i_profile_change_listener.h", "i_sync_completed_callback.h", "profile_change_listener_proxy.h", diff --git a/common/BUILD.gn b/common/BUILD.gn index dc264caf350f5629f6bbb7b029abcc8de82d891e..685d3e597ad65dfaf9616c2f015d19af0c4aea0a 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/dp_inited_callback_proxy.cpp", "src/interfaces/dp_inited_callback_stub.cpp", "src/interfaces/dp_subscribe_info.cpp", + "src/interfaces/dp_subscribe_info_extension.cpp", "src/interfaces/dp_sync_options.cpp", "src/interfaces/i_profile_change_listener.cpp", "src/interfaces/local_service_info.cpp", @@ -88,9 +89,14 @@ ohos_shared_library("distributed_device_profile_common") { "src/utils/profile_utils.cpp", ] - deps = [] + deps = [ + "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc", + ] - public_configs = [ ":distributed_device_profile_common_config" ] + public_configs = [ + ":distributed_device_profile_common_config", + "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc_config", + ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/common/include/interfaces/access_control_profile.h b/common/include/interfaces/access_control_profile.h index 4edb3da51d8eb28ca8bc09786baa436ebd777590..797daac79896aaef87cd3479fa938227e43dee13 100644 --- a/common/include/interfaces/access_control_profile.h +++ b/common/include/interfaces/access_control_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,11 +21,11 @@ #include "accesser.h" #include "accessee.h" #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class AccessControlProfile : public DpParcel { +class AccessControlProfile : public Parcelable { public: AccessControlProfile(); ~AccessControlProfile() = default; @@ -63,9 +63,13 @@ public: void SetDeviceIdHash(const std::string& deviceIdHash); std::string GetExtraData() const; void SetExtraData(const std::string& extraData); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static AccessControlProfile *Unmarshalling(Parcel &parcel); private: int64_t accessControlId_; diff --git a/common/include/interfaces/accessee.h b/common/include/interfaces/accessee.h index 4bbac0bd249322e71f993e0739bc7d0ae59f2145..70c018b432a7c42dffa13219d5ca0c0161ac94c0 100644 --- a/common/include/interfaces/accessee.h +++ b/common/include/interfaces/accessee.h @@ -20,6 +20,7 @@ #include #include "distributed_device_profile_enums.h" #include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -65,6 +66,8 @@ public: bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; + bool Marshalling(Parcel& parcel) const; + bool UnMarshalling(Parcel& parcel); private: int64_t accesseeId_; std::string accesseeDeviceId_; diff --git a/common/include/interfaces/accesser.h b/common/include/interfaces/accesser.h index b565e43c79c4bbdcb694ae6fd769669fbf9b91e1..78fcf6c39718832225abaed4747fab1747d33604 100644 --- a/common/include/interfaces/accesser.h +++ b/common/include/interfaces/accesser.h @@ -20,6 +20,7 @@ #include #include "distributed_device_profile_enums.h" #include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -64,6 +65,8 @@ public: bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; + bool Marshalling(Parcel& parcel) const; + bool UnMarshalling(Parcel& parcel); private: int64_t accesserId_; std::string accesserDeviceId_; diff --git a/common/include/interfaces/characteristic_profile.h b/common/include/interfaces/characteristic_profile.h index 57523ba011961500fd0dd426517939f3e45b39cd..6cb5d757712e1a9bf97e273e191f5b10c72bc799 100644 --- a/common/include/interfaces/characteristic_profile.h +++ b/common/include/interfaces/characteristic_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,11 +19,11 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class CharacteristicProfile : public DpParcel { +class CharacteristicProfile : public Parcelable { public: CharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, const std::string& characteristicValue) @@ -57,11 +57,14 @@ public: void SetIsMultiUser(bool isMultiUser); int32_t GetUserId() const; void SetUserId(int32_t userId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const CharacteristicProfile& charProfile) const; - std::string dump() const override; + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static CharacteristicProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; std::string serviceName_ = ""; diff --git a/common/include/interfaces/device_icon_info.h b/common/include/interfaces/device_icon_info.h index 302f67d604b64e49683a2a069452af0fe991e3b6..c666e4404c39caf3548fd5f3c5cbd79e3a4a9ea8 100644 --- a/common/include/interfaces/device_icon_info.h +++ b/common/include/interfaces/device_icon_info.h @@ -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 @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceIconInfo : public DpParcel { +class DeviceIconInfo : public Parcelable { public: DeviceIconInfo() : id_(0), @@ -54,11 +54,13 @@ public: void SetUrl(const std::string& url); std::vector GetIcon() const; void SetIcon(const std::vector& icon); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const DeviceIconInfo& other) const; - std::string dump() const override; - + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceIconInfo *Unmarshalling(Parcel &parcel); private: int32_t id_; std::string productId_; diff --git a/common/include/interfaces/device_icon_info_filter_options.h b/common/include/interfaces/device_icon_info_filter_options.h index 7f5be3960856db88965a79fcc5171d84b3bf560a..f57274c32f89696e2af65df74a3c526b276cacd5 100644 --- a/common/include/interfaces/device_icon_info_filter_options.h +++ b/common/include/interfaces/device_icon_info_filter_options.h @@ -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 @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceIconInfoFilterOptions : public DpParcel { +class DeviceIconInfoFilterOptions : public Parcelable { public: DeviceIconInfoFilterOptions() : internalModel_(""), subProductId_(""), imageType_(""), specName_("") {} @@ -40,9 +40,12 @@ public: std::string GetSpecName() const; void SetSpecName(const std::string& specName); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceIconInfoFilterOptions *Unmarshalling(Parcel &parcel); private: std::vector productIds_; diff --git a/common/include/interfaces/device_profile.h b/common/include/interfaces/device_profile.h index 7072a39d84b8e6f53756d99cc4bedb8a9c3801f6..756153a07de22245fea2667cc0e7b4e449dde737 100644 --- a/common/include/interfaces/device_profile.h +++ b/common/include/interfaces/device_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,11 +19,11 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceProfile : public DpParcel { +class DeviceProfile : public Parcelable { public: DeviceProfile() : deviceId_(""), @@ -126,10 +126,10 @@ public: void SetAccountId(const std::string& accountId); std::string GetInternalModel() const; void SetInternalModel(const std::string& internalModel); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const DeviceProfile& deviceProfile) const; - std::string dump() const override; + std::string dump() const; std::string AnnoymizeDump() const; const std::string GetBleMac() const; void SetBleMac(const std::string& bleMac); @@ -139,6 +139,9 @@ public: void SetSleMac(const std::string& sleMac); int32_t GetSetupType() const; void SetSetupType(int32_t setupType); + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_; std::string deviceName_; diff --git a/common/include/interfaces/device_profile_filter_options.h b/common/include/interfaces/device_profile_filter_options.h index db28c64ca4a0dc3fce90b923d80fa04b6e8e85c7..1f5e46709903076f2f915c75a7341995834a354a 100644 --- a/common/include/interfaces/device_profile_filter_options.h +++ b/common/include/interfaces/device_profile_filter_options.h @@ -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 @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceProfileFilterOptions : public DpParcel { +class DeviceProfileFilterOptions : public Parcelable { public: DeviceProfileFilterOptions() : userId_(-1), @@ -43,9 +43,13 @@ public: std::vector GetDeviceProfileIds() const; void SetDeviceProfileIds(std::vector deviceProfileIds); void AddDeviceProfileIds(int32_t deviceProfileId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceProfileFilterOptions *Unmarshalling(Parcel &parcel); private: int32_t userId_; diff --git a/common/include/interfaces/dp_subscribe_info.h b/common/include/interfaces/dp_subscribe_info.h index 2429d26249540ba4050f2bd51b0df482974a3b0a..ea4d16c91467e34a9130e6b80b1c9cdc40a9c1f2 100644 --- a/common/include/interfaces/dp_subscribe_info.h +++ b/common/include/interfaces/dp_subscribe_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,7 +18,7 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" #include "macro_utils.h" #include "iremote_broker.h" #include "i_profile_change_listener.h" @@ -26,7 +26,7 @@ namespace OHOS { namespace DistributedDeviceProfile { -class SubscribeInfo : public DpParcel { +class SubscribeInfo { public: SubscribeInfo(int32_t saId, const std::string& subscribeKey, std::unordered_set subscribeChangeTypes, sptr profileChangeListener, @@ -50,9 +50,9 @@ public: void SetListener(sptr listener); std::unordered_set GetProfileChangeTypes() const; void AddProfileChangeType(ProfileChangeType profileChangeType); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; private: int32_t saId_ = -1; diff --git a/common/include/interfaces/dp_subscribe_info_extension.h b/common/include/interfaces/dp_subscribe_info_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..ebf2ff51be7b5434a937e54206b57de41cc30a8e --- /dev/null +++ b/common/include/interfaces/dp_subscribe_info_extension.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H +#define OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H + +#include +#include +#include "message_parcel.h" +#include "macro_utils.h" +#include "iremote_broker.h" +#include "i_profile_change_listener.h" +#include "distributed_device_profile_constants.h" +#include "dp_subscribe_info.h" + + +namespace OHOS { +namespace DistributedDeviceProfile { +class SubscribeInfoExt : public Parcelable, public SubscribeInfo { +public: + SubscribeInfoExt(int32_t saId, const std::string& subscribeKey, + std::unordered_set subscribeChangeTypes, + sptr profileChangeListener, + int32_t userId = DEFAULT_USER_ID); + SubscribeInfoExt(const SubscribeInfo& subscribeInfo); + SubscribeInfoExt(); + ~SubscribeInfoExt(); + + void SetListener(sptr listener); + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static SubscribeInfoExt *Unmarshalling(Parcel &parcel); + +private: + int32_t saId_ = -1; + std::string subscribeKey_ = ""; + std::unordered_set subscribeChangeTypes_; + sptr listener_ = nullptr; +}; + +class SubscribeExtCompare : public SubscribeCompare { +public: + SubscribeExtCompare() = default; + ~SubscribeExtCompare() = default; +}; + +class SubscribeExtHash : public SubscribeHash { +public: + SubscribeExtHash() = default; + ~SubscribeExtHash() = default; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS + +#endif // OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H \ No newline at end of file diff --git a/common/include/interfaces/dp_sync_options.h b/common/include/interfaces/dp_sync_options.h index ceaf502c383053970f1be8348a644f762639b808..7ac11e8c2f8d947b8138576b59879b86f6ddc7c3 100644 --- a/common/include/interfaces/dp_sync_options.h +++ b/common/include/interfaces/dp_sync_options.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,13 +19,13 @@ #include #include #include -#include "dp_parcel.h" +#include "message_parcel.h" #include "distributed_device_profile_constants.h" #include "distributed_device_profile_enums.h" namespace OHOS { namespace DistributedDeviceProfile { -class DpSyncOptions : public DpParcel { +class DpSyncOptions : public Parcelable { public: DpSyncOptions() = default; ~DpSyncOptions() = default; @@ -35,10 +35,13 @@ public: void AddDevice(const std::string& deviceId); void SetSyncMode(SyncMode mode); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DpSyncOptions *Unmarshalling(Parcel &parcel); private: SyncMode syncMode_{SyncMode::PUSH_PULL}; std::vector syncDeviceIds_; diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h deleted file mode 100644 index 567de016050e17e164ebd01baac31196e07ddc0e..0000000000000000000000000000000000000000 --- a/common/include/interfaces/i_distributed_device_profile.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H -#define OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H - -#include - -#include "iremote_broker.h" - -#include "access_control_profile.h" -#include "characteristic_profile.h" -#include "device_icon_info.h" -#include "device_icon_info_filter_options.h" -#include "device_profile.h" -#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" -#include "service_info_unique_key.h" -#include "service_profile.h" -#include "trust_device_profile.h" -#include "trusted_device_info.h" -#include "local_service_info.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class IDistributedDeviceProfile : public OHOS::IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DeviceProfile.IDistributedDeviceProfile"); - IDistributedDeviceProfile() = default; - virtual ~IDistributedDeviceProfile() = default; - virtual int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) = 0; - virtual int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) = 0; - virtual int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) = 0; - virtual int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) = 0; - virtual int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) = 0; - virtual int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) = 0; - virtual int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) = 0; - virtual int32_t DeleteAccessControlProfile(int32_t accessControlId) = 0; - virtual int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) = 0; - virtual int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) = 0; - virtual int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) = 0; - virtual int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) = 0; - virtual int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) = 0; - virtual int32_t PutServiceProfile(const ServiceProfile& serviceProfile) = 0; - virtual int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) = 0; - virtual int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) = 0; - virtual int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) = 0; - virtual int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) = 0; - virtual int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) = 0; - virtual int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) = 0; - virtual int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) = 0; - virtual int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) = 0; - virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, - bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0; - virtual int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0; - virtual int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; - virtual int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; - virtual int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) = 0; - virtual int32_t UnSubscribeDeviceProfileInited(int32_t saId) = 0; - virtual int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) = 0; - virtual int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) = 0; - virtual int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) = 0; - virtual int32_t SendSubscribeInfos(std::map listenerMap) = 0; - virtual int32_t PutAllTrustedDevices(const std::vector deviceInfos) = 0; - virtual int32_t PutProductInfoBatch(const std::vector& productInfos) = 0; - virtual int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) = 0; - virtual int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) = 0; - virtual int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) = 0; - virtual int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) = 0; - virtual int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) = 0; - 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 -#endif // OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H diff --git a/common/include/interfaces/local_service_info.h b/common/include/interfaces/local_service_info.h index 26b682c79600d6d302d526db4f25e11a8ff635d9..51f17aa36f72de334b492d0d27e7e2c8052d13e1 100644 --- a/common/include/interfaces/local_service_info.h +++ b/common/include/interfaces/local_service_info.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class LocalServiceInfo : public DpParcel { +class LocalServiceInfo : public Parcelable { public: LocalServiceInfo(const std::string& bundleName, const int32_t authBoxType, const int32_t authType, const int32_t pinExchangeType, @@ -56,9 +56,13 @@ public: std::string GetExtraInfo() const; void SetExtraInfo(const std::string& extraInfo); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static LocalServiceInfo *Unmarshalling(Parcel &parcel); private: std::string bundleName_ = ""; diff --git a/common/include/interfaces/product_info.h b/common/include/interfaces/product_info.h index 3f32690af61a8aca34f5b0631482a48fd6366cb8..042e406e89510baa84ae46f5b35b26fcc7e35eba 100644 --- a/common/include/interfaces/product_info.h +++ b/common/include/interfaces/product_info.h @@ -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 @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ProductInfo : public DpParcel { +class ProductInfo : public Parcelable { public: ProductInfo() : productId_(""), model_(""), @@ -43,10 +43,14 @@ public: void SetProductShortName(const std::string& productShortName); std::string GetImageVersion() const; void SetImageVersion(const std::string& imageVersion); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const ProductInfo& other) const; - std::string dump() const override; + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ProductInfo *Unmarshalling(Parcel &parcel); private: std::string GetAnonyProductName(const std::string& value) const; diff --git a/common/include/interfaces/service_info_profile.h b/common/include/interfaces/service_info_profile.h index f348a92c0d672083c493f22405c73ed19a68a9ca..894eb2df92e48b8e8dee3424e542c3de0bbb889b 100644 --- a/common/include/interfaces/service_info_profile.h +++ b/common/include/interfaces/service_info_profile.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceInfoProfile : public DpParcel { +class ServiceInfoProfile : public Parcelable { public: ServiceInfoProfile(const std::string& deviceId, const int32_t userId, const std::string& networkId, const std::string& tokenId, const int64_t serviceId, const std::string& serviceType, @@ -98,9 +98,13 @@ public: std::string GetExtraInfo() const; void SetExtraInfo(const std::string& extraInfo); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceInfoProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/service_info_unique_key.h b/common/include/interfaces/service_info_unique_key.h index 201fc880838531b5b37a8685be254d0bb33f2d21..ad705be31d70c037abf5639e2f4030390814f795 100644 --- a/common/include/interfaces/service_info_unique_key.h +++ b/common/include/interfaces/service_info_unique_key.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceInfoUniqueKey : public DpParcel { +class ServiceInfoUniqueKey : public Parcelable { public: ServiceInfoUniqueKey(const std::string& deviceId, const int32_t userId, const std::string& tokenId, const int64_t serviceId) @@ -53,9 +53,13 @@ public: void SetBundleName(const std::string& bundleName); bool operator<(const ServiceInfoUniqueKey& rhs) const; - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceInfoUniqueKey *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/service_profile.h b/common/include/interfaces/service_profile.h index b8ff73bd859c32aae8c456ed39ba1ef93718a94d..a075afcbd68bd486a29bea4b3be38f65f03f9a90 100644 --- a/common/include/interfaces/service_profile.h +++ b/common/include/interfaces/service_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,11 +19,12 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" +#include "distributed_device_profile_errors.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceProfile : public DpParcel { +class ServiceProfile : public Parcelable { public: ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType); ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType, @@ -41,10 +42,14 @@ public: void SetIsMultiUser(bool isMultiUser); int32_t GetUserId() const; void SetUserId(int32_t userId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const ServiceProfile& serviceProfile) const; - std::string dump() const override; + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/trust_device_profile.h b/common/include/interfaces/trust_device_profile.h index 8ced271eb1f9b1e552a5b4b328bc92f60ac55af3..ddde58f84d7c743a33ba80d96f8d285b0dfade0d 100644 --- a/common/include/interfaces/trust_device_profile.h +++ b/common/include/interfaces/trust_device_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class TrustDeviceProfile : public DpParcel { +class TrustDeviceProfile : public Parcelable { public: TrustDeviceProfile() : deviceId_(""), @@ -49,9 +49,13 @@ public: void SetPeerUserId(int32_t peerUserId); int32_t GetLocalUserId() const; void SetLocalUserId(int32_t localUserId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static TrustDeviceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_; diff --git a/common/include/interfaces/trusted_device_info.h b/common/include/interfaces/trusted_device_info.h index 820290404a57cfdaba47ba2a0b0b412ef191ee94..986cc2a68b607ac828a3b59e6b4cfe580c372506 100644 --- a/common/include/interfaces/trusted_device_info.h +++ b/common/include/interfaces/trusted_device_info.h @@ -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 @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class TrustedDeviceInfo : public DpParcel { +class TrustedDeviceInfo : public Parcelable { public: TrustedDeviceInfo() : networkId_(""), authForm_(BINDTYPE_INIT), deviceTypeId_(0), osVersion_(""), osType_(0), udid_(""), uuid_("") @@ -46,9 +46,13 @@ public: bool operator!=(const TrustedDeviceInfo& trustedDeviceInfo) const; bool operator<(const TrustedDeviceInfo& trustedDeviceInfo) const; - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static TrustedDeviceInfo *Unmarshalling(Parcel &parcel); private: std::string networkId_; diff --git a/common/include/utils/ipc_utils.h b/common/include/utils/ipc_utils.h index 4d3ba09229d83271c70a78bbb285746ef6f92838..708dfc43c05939622959022c6a2e2fce32a1195d 100644 --- a/common/include/utils/ipc_utils.h +++ b/common/include/utils/ipc_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,6 +33,7 @@ #include "distributed_device_profile_errors.h" #include "distributed_device_profile_log.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "product_info.h" #include "service_info_profile.h" #include "service_profile.h" diff --git a/common/src/interfaces/access_control_profile.cpp b/common/src/interfaces/access_control_profile.cpp index a77bd79162d5e9b20b54039667bcfb150ffde75b..0b0ad7984489aba60f59a39684a8aed4dd88f362 100644 --- a/common/src/interfaces/access_control_profile.cpp +++ b/common/src/interfaces/access_control_profile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -279,5 +279,62 @@ std::string AccessControlProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool AccessControlProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int64, accessControlId_, false); + READ_HELPER_RET(parcel, Int64, accesserId_, false); + READ_HELPER_RET(parcel, Int64, accesseeId_, false); + READ_HELPER_RET(parcel, String, sessionKey_, false); + READ_HELPER_RET(parcel, Uint32, bindType_, false); + READ_HELPER_RET(parcel, Uint32, authenticationType_, false); + READ_HELPER_RET(parcel, Uint32, bindLevel_, false); + READ_HELPER_RET(parcel, Int32, status_, false); + READ_HELPER_RET(parcel, Int64, validPeriod_, false); + READ_HELPER_RET(parcel, Int64, lastAuthTime_, false); + READ_HELPER_RET(parcel, String, trustDeviceId_, false); + READ_HELPER_RET(parcel, Uint32, deviceIdType_, false); + READ_HELPER_RET(parcel, String, deviceIdHash_, false); + READ_HELPER_RET(parcel, String, extraData_, false); + accesser_.UnMarshalling(parcel); + accessee_.UnMarshalling(parcel); + return true; +} + +AccessControlProfile *AccessControlProfile::Unmarshalling(Parcel &parcel) +{ + AccessControlProfile *accessControlProfile = new (std::nothrow) AccessControlProfile(); + if (accessControlProfile == nullptr) { + return nullptr; + } + + if (!accessControlProfile->ReadFromParcel(parcel)) { + delete accessControlProfile; + accessControlProfile = nullptr; + } + + return accessControlProfile; +} + +bool AccessControlProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accessControlId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeId_, false); + WRITE_HELPER_RET(parcel, String, sessionKey_, false); + WRITE_HELPER_RET(parcel, Uint32, bindType_, false); + WRITE_HELPER_RET(parcel, Uint32, authenticationType_, false); + WRITE_HELPER_RET(parcel, Uint32, bindLevel_, false); + WRITE_HELPER_RET(parcel, Int32, status_, false); + WRITE_HELPER_RET(parcel, Int64, validPeriod_, false); + WRITE_HELPER_RET(parcel, Int64, lastAuthTime_, false); + WRITE_HELPER_RET(parcel, String, trustDeviceId_, false); + WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false); + WRITE_HELPER_RET(parcel, String, deviceIdHash_, false); + WRITE_HELPER_RET(parcel, String, extraData_, false); + accesser_.Marshalling(parcel); + accessee_.Marshalling(parcel); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/accessee.cpp b/common/src/interfaces/accessee.cpp index d647404c689299b7b512f060b54ba665d013f570..1992c397a8bdf2a9b817e0d1f0aa70a74b710446 100644 --- a/common/src/interfaces/accessee.cpp +++ b/common/src/interfaces/accessee.cpp @@ -282,5 +282,47 @@ std::string Accessee::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool Accessee::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accesseeId_, false); + WRITE_HELPER_RET(parcel, String, accesseeDeviceId_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeUserId_, false); + WRITE_HELPER_RET(parcel, String, accesseeAccountId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeTokenId_, false); + WRITE_HELPER_RET(parcel, String, accesseeBundleName_, false); + WRITE_HELPER_RET(parcel, String, accesseeHapSignature_, false); + WRITE_HELPER_RET(parcel, Uint32, accesseeBindLevel_, false); + WRITE_HELPER_RET(parcel, String, accesseeDeviceName_, false); + WRITE_HELPER_RET(parcel, String, accesseeServiceName_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeCredentialId_, false); + WRITE_HELPER_RET(parcel, String, accesseeCredentialIdStr_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeStatus_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeSessionKeyId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeSKTimeStamp_, false); + WRITE_HELPER_RET(parcel, String, accesseeExtraData_, false); + return true; +} + +bool Accessee::UnMarshalling(Parcel& parcel) +{ + READ_HELPER_RET(parcel, Int64, accesseeId_, false); + READ_HELPER_RET(parcel, String, accesseeDeviceId_, false); + READ_HELPER_RET(parcel, Int32, accesseeUserId_, false); + READ_HELPER_RET(parcel, String, accesseeAccountId_, false); + READ_HELPER_RET(parcel, Int64, accesseeTokenId_, false); + READ_HELPER_RET(parcel, String, accesseeBundleName_, false); + READ_HELPER_RET(parcel, String, accesseeHapSignature_, false); + READ_HELPER_RET(parcel, Uint32, accesseeBindLevel_, false); + READ_HELPER_RET(parcel, String, accesseeDeviceName_, false); + READ_HELPER_RET(parcel, String, accesseeServiceName_, false); + READ_HELPER_RET(parcel, Int32, accesseeCredentialId_, false); + READ_HELPER_RET(parcel, String, accesseeCredentialIdStr_, false); + READ_HELPER_RET(parcel, Int32, accesseeStatus_, false); + READ_HELPER_RET(parcel, Int32, accesseeSessionKeyId_, false); + READ_HELPER_RET(parcel, Int64, accesseeSKTimeStamp_, false); + READ_HELPER_RET(parcel, String, accesseeExtraData_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/accesser.cpp b/common/src/interfaces/accesser.cpp index 04346db5ec00d36f51deb36a351af62f7f44817b..f9d76ae31870b7f88ce9b2763c7bc2e4c1e69761 100644 --- a/common/src/interfaces/accesser.cpp +++ b/common/src/interfaces/accesser.cpp @@ -280,5 +280,47 @@ std::string Accesser::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool Accesser::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accesserId_, false); + WRITE_HELPER_RET(parcel, String, accesserDeviceId_, false); + WRITE_HELPER_RET(parcel, Int32, accesserUserId_, false); + WRITE_HELPER_RET(parcel, String, accesserAccountId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserTokenId_, false); + WRITE_HELPER_RET(parcel, String, accesserBundleName_, false); + WRITE_HELPER_RET(parcel, String, accesserHapSignature_, false); + WRITE_HELPER_RET(parcel, Uint32, accesserBindLevel_, false); + WRITE_HELPER_RET(parcel, String, accesserDeviceName_, false); + WRITE_HELPER_RET(parcel, String, accesserServiceName_, false); + WRITE_HELPER_RET(parcel, Int32, accesserCredentialId_, false); + WRITE_HELPER_RET(parcel, String, accesserCredentialIdStr_, false); + WRITE_HELPER_RET(parcel, Int32, accesserStatus_, false); + WRITE_HELPER_RET(parcel, Int32, accesserSessionKeyId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserSKTimeStamp_, false); + WRITE_HELPER_RET(parcel, String, accesserExtraData_, false); + return true; +} + +bool Accesser::UnMarshalling(Parcel& parcel) +{ + READ_HELPER_RET(parcel, Int64, accesserId_, false); + READ_HELPER_RET(parcel, String, accesserDeviceId_, false); + READ_HELPER_RET(parcel, Int32, accesserUserId_, false); + READ_HELPER_RET(parcel, String, accesserAccountId_, false); + READ_HELPER_RET(parcel, Int64, accesserTokenId_, false); + READ_HELPER_RET(parcel, String, accesserBundleName_, false); + READ_HELPER_RET(parcel, String, accesserHapSignature_, false); + READ_HELPER_RET(parcel, Uint32, accesserBindLevel_, false); + READ_HELPER_RET(parcel, String, accesserDeviceName_, false); + READ_HELPER_RET(parcel, String, accesserServiceName_, false); + READ_HELPER_RET(parcel, Int32, accesserCredentialId_, false); + READ_HELPER_RET(parcel, String, accesserCredentialIdStr_, false); + READ_HELPER_RET(parcel, Int32, accesserStatus_, false); + READ_HELPER_RET(parcel, Int32, accesserSessionKeyId_, false); + READ_HELPER_RET(parcel, Int64, accesserSKTimeStamp_, false); + READ_HELPER_RET(parcel, String, accesserExtraData_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/characteristic_profile.cpp b/common/src/interfaces/characteristic_profile.cpp index 13123602bfbec07f2351c45916f6ffaeba2325c2..1acbe87ae2fa2a4c2f771d32ce80443b5d99d109 100644 --- a/common/src/interfaces/characteristic_profile.cpp +++ b/common/src/interfaces/characteristic_profile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -148,5 +148,42 @@ std::string CharacteristicProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool CharacteristicProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, characteristicKey_, false); + READ_HELPER_RET(parcel, String, characteristicValue_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + return true; +} + +CharacteristicProfile *CharacteristicProfile::Unmarshalling(Parcel &parcel) +{ + CharacteristicProfile *characteristicProfile = new (std::nothrow) CharacteristicProfile(); + if (characteristicProfile == nullptr) { + return nullptr; + } + + if (!characteristicProfile->ReadFromParcel(parcel)) { + delete characteristicProfile; + characteristicProfile = nullptr; + } + + return characteristicProfile; +} + +bool CharacteristicProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, characteristicKey_, false); + WRITE_HELPER_RET(parcel, String, characteristicValue_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_icon_info.cpp b/common/src/interfaces/device_icon_info.cpp index 8587c3fcec8da6c5ded66991d6f81b0f423a4f64..723586c50a5bb72beac875f7886e32c1536475cb 100644 --- a/common/src/interfaces/device_icon_info.cpp +++ b/common/src/interfaces/device_icon_info.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 @@ -198,5 +198,79 @@ std::string DeviceIconInfo::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceIconInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, imageType_, false); + READ_HELPER_RET(parcel, String, specName_, false); + READ_HELPER_RET(parcel, String, version_, false); + READ_HELPER_RET(parcel, String, wiseVersion_, false); + READ_HELPER_RET(parcel, String, url_, false); + int32_t length = parcel.ReadInt32(); + if (length <= 0 || length > MAX_ICON_SIZE) { + HILOGE("uint8_t vector, params size is invalid! size : %{public}d", length); + return false; + } + + std::vector icon; + icon.reserve(length); + for (int32_t i = 0; i < length; ++i) { + uint8_t byte = 0; + if (!parcel.ReadUint8(byte)) { + HILOGE("ReadUint8 failed at index %{public}d", i); + return false; + } + icon.push_back(byte); + } + icon_ = icon; + return true; +} + +DeviceIconInfo *DeviceIconInfo::Unmarshalling(Parcel &parcel) +{ + DeviceIconInfo *deviceIconInfo = new (std::nothrow) DeviceIconInfo(); + if (deviceIconInfo == nullptr) { + return nullptr; + } + + if (!deviceIconInfo->ReadFromParcel(parcel)) { + delete deviceIconInfo; + deviceIconInfo = nullptr; + } + + return deviceIconInfo; +} + +bool DeviceIconInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, imageType_, false); + WRITE_HELPER_RET(parcel, String, specName_, false); + WRITE_HELPER_RET(parcel, String, version_, false); + WRITE_HELPER_RET(parcel, String, wiseVersion_, false); + WRITE_HELPER_RET(parcel, String, url_, false); + int32_t length = static_cast(icon_.size()); + WRITE_HELPER_RET(parcel, Int32, length, false); + if (icon_.empty() || icon_.size() > MAX_ICON_SIZE) { + HILOGE("uint8_t vector, params size is invalid! size : %{public}zu", icon_.size()); + return false; + } + if (length > 0) { + const uint8_t* buffer = reinterpret_cast(icon_.data()); + for (int32_t i = 0; i < length; ++i) { + if (!parcel.WriteUint8(buffer[i])) { + HILOGE("WriteUint8 failed at index %{public}d", i); + return false; + } + } + } + + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_icon_info_filter_options.cpp b/common/src/interfaces/device_icon_info_filter_options.cpp index 2426a342745f6ea88a4d3e72bd66a097bf8079e2..f8b898c6e70457a6bd6849f272322409b803484e 100644 --- a/common/src/interfaces/device_icon_info_filter_options.cpp +++ b/common/src/interfaces/device_icon_info_filter_options.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 @@ -142,5 +142,57 @@ std::string DeviceIconInfoFilterOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceIconInfoFilterOptions::ReadFromParcel(Parcel &parcel) +{ + size_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size); + return false; + } + for (uint32_t i = 0; i < size; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + productIds_.emplace_back(item); + } + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, imageType_, false); + READ_HELPER_RET(parcel, String, specName_, false); + return true; +} + +DeviceIconInfoFilterOptions *DeviceIconInfoFilterOptions::Unmarshalling(Parcel &parcel) +{ + DeviceIconInfoFilterOptions *deviceIconInfoFilterOptions = new (std::nothrow) DeviceIconInfoFilterOptions(); + if (deviceIconInfoFilterOptions == nullptr) { + return nullptr; + } + + if (!deviceIconInfoFilterOptions->ReadFromParcel(parcel)) { + delete deviceIconInfoFilterOptions; + deviceIconInfoFilterOptions = nullptr; + } + + return deviceIconInfoFilterOptions; +} + +bool DeviceIconInfoFilterOptions::Marshalling(Parcel& parcel) const +{ + size_t size = productIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size, false); + if (productIds_.empty() || productIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", productIds_.size()); + return false; + } + for (const auto& item : productIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, imageType_, false); + WRITE_HELPER_RET(parcel, String, specName_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_profile.cpp b/common/src/interfaces/device_profile.cpp index c2d49df649f4f193d2112facec4816b6bc91505c..68babbbed1a77d1d158fa24e88f4b7b97ce7364a 100644 --- a/common/src/interfaces/device_profile.cpp +++ b/common/src/interfaces/device_profile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -544,5 +544,98 @@ std::string DeviceProfile::AnnoymizeDump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, deviceName_, false); + READ_HELPER_RET(parcel, String, manufactureName_, false); + READ_HELPER_RET(parcel, String, deviceModel_, false); + READ_HELPER_RET(parcel, Int64, storageCapability_, false); + READ_HELPER_RET(parcel, String, osSysCap_, false); + READ_HELPER_RET(parcel, Int32, osApiLevel_, false); + READ_HELPER_RET(parcel, String, osVersion_, false); + READ_HELPER_RET(parcel, Int32, osType_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, devType_, false); + READ_HELPER_RET(parcel, String, manu_, false); + READ_HELPER_RET(parcel, String, sn_, false); + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, productName_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, hiv_, false); + READ_HELPER_RET(parcel, String, mac_, false); + READ_HELPER_RET(parcel, String, fwv_, false); + READ_HELPER_RET(parcel, String, hwv_, false); + READ_HELPER_RET(parcel, String, swv_, false); + READ_HELPER_RET(parcel, Int32, protType_, false); + READ_HELPER_RET(parcel, String, wiseUserId_, false); + READ_HELPER_RET(parcel, String, wiseDeviceId_, false); + READ_HELPER_RET(parcel, String, registerTime_, false); + READ_HELPER_RET(parcel, String, modifyTime_, false); + READ_HELPER_RET(parcel, String, shareTime_, false); + READ_HELPER_RET(parcel, String, accountId_, false); + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, bleMac_, false); + READ_HELPER_RET(parcel, String, brMac_, false); + READ_HELPER_RET(parcel, String, sleMac_, false); + READ_HELPER_RET(parcel, Int32, setupType_, false); + return true; +} + +DeviceProfile *DeviceProfile::Unmarshalling(Parcel &parcel) +{ + DeviceProfile *deviceProfile = new (std::nothrow) DeviceProfile(); + if (deviceProfile == nullptr) { + return nullptr; + } + + if (!deviceProfile->ReadFromParcel(parcel)) { + delete deviceProfile; + deviceProfile = nullptr; + } + + return deviceProfile; +} + +bool DeviceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, deviceName_, false); + WRITE_HELPER_RET(parcel, String, manufactureName_, false); + WRITE_HELPER_RET(parcel, String, deviceModel_, false); + WRITE_HELPER_RET(parcel, Int64, storageCapability_, false); + WRITE_HELPER_RET(parcel, String, osSysCap_, false); + WRITE_HELPER_RET(parcel, Int32, osApiLevel_, false); + WRITE_HELPER_RET(parcel, String, osVersion_, false); + WRITE_HELPER_RET(parcel, Int32, osType_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, devType_, false); + WRITE_HELPER_RET(parcel, String, manu_, false); + WRITE_HELPER_RET(parcel, String, sn_, false); + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, productName_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, hiv_, false); + WRITE_HELPER_RET(parcel, String, mac_, false); + WRITE_HELPER_RET(parcel, String, fwv_, false); + WRITE_HELPER_RET(parcel, String, hwv_, false); + WRITE_HELPER_RET(parcel, String, swv_, false); + WRITE_HELPER_RET(parcel, Int32, protType_, false); + WRITE_HELPER_RET(parcel, String, wiseUserId_, false); + WRITE_HELPER_RET(parcel, String, wiseDeviceId_, false); + WRITE_HELPER_RET(parcel, String, registerTime_, false); + WRITE_HELPER_RET(parcel, String, modifyTime_, false); + WRITE_HELPER_RET(parcel, String, shareTime_, false); + WRITE_HELPER_RET(parcel, String, accountId_, false); + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, bleMac_, false); + WRITE_HELPER_RET(parcel, String, brMac_, false); + WRITE_HELPER_RET(parcel, String, sleMac_, false); + WRITE_HELPER_RET(parcel, Int32, setupType_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_profile_filter_options.cpp b/common/src/interfaces/device_profile_filter_options.cpp index af1d19991b49c1de3aff43462e61d2c77acaf66f..2e61556b1afae8a791caf1f83f94892793f73ac3 100644 --- a/common/src/interfaces/device_profile_filter_options.cpp +++ b/common/src/interfaces/device_profile_filter_options.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 @@ -149,5 +149,99 @@ std::string DeviceProfileFilterOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceProfileFilterOptions::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, accountId_, false); + + size_t size1 = parcel.ReadUint32(); + if (size1 == 0 || size1 > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size1); + return false; + } + for (uint32_t i = 0; i < size1; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + deviceIds_.emplace_back(item); + } + + size_t size2 = parcel.ReadUint32(); + if (size2 == 0 || size2 > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size2); + return false; + } + for (uint32_t i = 0; i < size2; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + wiseDeviceIds_.emplace_back(item); + } + + size_t size3 = parcel.ReadUint32(); + if (size3 == 0 || size3 > MAX_ID_SIZE) { + HILOGE("int32_t vector, params size is invalid! size : %{public}zu", size3); + return false; + } + for (uint32_t i = 0; i < size3; i++) { + int32_t item = 0; + READ_HELPER_RET(parcel, Int32, item, false); + deviceProfileIds_.emplace_back(item); + } + + return true; +} + +DeviceProfileFilterOptions *DeviceProfileFilterOptions::Unmarshalling(Parcel &parcel) +{ + DeviceProfileFilterOptions *deviceProfileFilterOptions = new (std::nothrow) DeviceProfileFilterOptions(); + if (deviceProfileFilterOptions == nullptr) { + return nullptr; + } + + if (!deviceProfileFilterOptions->ReadFromParcel(parcel)) { + delete deviceProfileFilterOptions; + deviceProfileFilterOptions = nullptr; + } + + return deviceProfileFilterOptions; +} + +bool DeviceProfileFilterOptions::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, accountId_, false); + + size_t size1 = deviceIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size1, false); + if (deviceIds_.empty() || deviceIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", deviceIds_.size()); + return false; + } + for (const auto& item : deviceIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } + + size_t size2 = wiseDeviceIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size2, false); + if (wiseDeviceIds_.empty() || wiseDeviceIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", wiseDeviceIds_.size()); + return false; + } + for (const auto& item : wiseDeviceIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } + + size_t size3 = deviceProfileIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size3, false); + if (deviceProfileIds_.empty() || deviceProfileIds_.size() > MAX_ID_SIZE) { + HILOGE("int32_t vector, params size is invalid! size : %{public}zu", deviceProfileIds_.size()); + return false; + } + for (const auto& item : deviceProfileIds_) { + WRITE_HELPER_RET(parcel, Int32, item, false); + } + + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/dp_inited_callback_proxy.cpp b/common/src/interfaces/dp_inited_callback_proxy.cpp index c318dc841f808119eb1b56b5a6436a48523aff1a..07d6d30bd40e13a71a978a81c10e1ffd5155e27a 100644 --- a/common/src/interfaces/dp_inited_callback_proxy.cpp +++ b/common/src/interfaces/dp_inited_callback_proxy.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 @@ -16,7 +16,7 @@ #include "dp_inited_callback_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/dp_subscribe_info.cpp b/common/src/interfaces/dp_subscribe_info.cpp index 78ee3554cc7ab7d3810e34f07277c6d41826e021..0867413d59ce61de6433111ce5da3c944a5a602d 100644 --- a/common/src/interfaces/dp_subscribe_info.cpp +++ b/common/src/interfaces/dp_subscribe_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -204,4 +204,3 @@ std::string SubscribeInfo::dump() const } } // namespace DistributedDeviceProfile } // namespace OHOS - diff --git a/common/src/interfaces/dp_subscribe_info_extension.cpp b/common/src/interfaces/dp_subscribe_info_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90cf5e9cd0da2109e9f15d3d99ddaca9fc8289fc --- /dev/null +++ b/common/src/interfaces/dp_subscribe_info_extension.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dp_subscribe_info_extension.h" +#include "cJSON.h" +#include "distributed_device_profile_constants.h" +#include "ipc_utils.h" +#include "macro_utils.h" +#include "profile_change_listener_stub.h" +#include "profile_utils.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +namespace { + const std::string TAG = "SubscribeInfoExt"; +} +SubscribeInfoExt::SubscribeInfoExt(int32_t saId, const std::string& subscribeKey, + std::unordered_set subscribeChangeTypes, + sptr profileChangeListener, + int32_t userId) +{ + this->saId_ = saId; + this->subscribeKey_ = subscribeKey; + if (userId != DEFAULT_USER_ID) { + this->subscribeKey_ = this->subscribeKey_ + SEPARATOR + std::to_string(userId); + } + this->subscribeChangeTypes_ = subscribeChangeTypes; + if (profileChangeListener == nullptr) { + HILOGI("constructor!"); + return; + } + if (profileChangeListener->AsObject() == nullptr) { + HILOGI("constructor!"); + return; + } + this->listener_ = profileChangeListener->AsObject(); +} + +SubscribeInfoExt::SubscribeInfoExt(const SubscribeInfo& subscribeInfo) +{ + this->saId_ = subscribeInfo.GetSaId(); + this->subscribeKey_ = subscribeInfo.GetSubscribeKey(); + this->subscribeChangeTypes_ = subscribeInfo.GetProfileChangeTypes(); + if (subscribeInfo.GetListener() == nullptr) { + HILOGI("constructor!"); + return; + } + this->listener_ = subscribeInfo.GetListener(); +} + +SubscribeInfoExt::SubscribeInfoExt() +{ +} + +SubscribeInfoExt::~SubscribeInfoExt() +{ +} + +void SubscribeInfoExt::SetListener(sptr listener) +{ + this->listener_ = listener; +} + +bool SubscribeInfoExt::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int32, saId_, false); + READ_HELPER_RET(parcel, String, subscribeKey_, false); + + uint32_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_SUBSCRIBE_CHANGE_SIZE) { + HILOGE("Params size is invalid! size: %{public}u", size); + return false; + } + for (uint32_t i = 0; i < size; ++i) { + uint32_t num = parcel.ReadUint32(); + if (num <= static_cast(ProfileChangeType::PROFILE_CHANGE_TYPE_MIN) || + num >= static_cast(ProfileChangeType::PROFILE_CHANGE_TYPE_MAX)) { + HILOGE("The value is invalid! index: %{public}u, value: %{public}u", i, num); + return false; + } + subscribeChangeTypes_.emplace(static_cast(num)); + } + return true; +} + +SubscribeInfoExt *SubscribeInfoExt::Unmarshalling(Parcel &parcel) +{ + SubscribeInfoExt *subscribeInfoExtension = new (std::nothrow) SubscribeInfoExt(); + if (subscribeInfoExtension == nullptr) { + return nullptr; + } + + if (!subscribeInfoExtension->ReadFromParcel(parcel)) { + delete subscribeInfoExtension; + subscribeInfoExtension = nullptr; + } + + return subscribeInfoExtension; +} + +bool SubscribeInfoExt::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, saId_, false); + WRITE_HELPER_RET(parcel, String, subscribeKey_, false); + + uint32_t size = subscribeChangeTypes_.size(); + WRITE_HELPER_RET(parcel, Uint32, size, false); + if (size == 0 || size > MAX_SUBSCRIBE_CHANGE_SIZE) { + HILOGE("changeTypes size is invalid! size: %{public}u", size); + return false; + } + for (ProfileChangeType item : subscribeChangeTypes_) { + WRITE_HELPER_RET(parcel, Int32, static_cast(item), false); + } + return true; +} +} +} \ No newline at end of file diff --git a/common/src/interfaces/dp_sync_options.cpp b/common/src/interfaces/dp_sync_options.cpp index 4d42d9fc9ccddbe153b62fbcdedba2ca01c8aeda..726aa6485c2be28ad2624bb54c154d72337462a9 100644 --- a/common/src/interfaces/dp_sync_options.cpp +++ b/common/src/interfaces/dp_sync_options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -109,5 +109,48 @@ std::string DpSyncOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DpSyncOptions::ReadFromParcel(Parcel &parcel) +{ + int32_t mode = 0; + READ_HELPER_RET(parcel, Int32, mode, false); + syncMode_ = static_cast(mode); + int32_t size = 0; + READ_HELPER_RET(parcel, Int32, size, false); + if (size > MAX_DEVICE_SIZE) { + return false; + } + for (int32_t i = 0; i < size; i++) { + std::string deviceId; + READ_HELPER_RET(parcel, String, deviceId, false); + syncDeviceIds_.emplace_back(deviceId); + } + return true; +} + +DpSyncOptions *DpSyncOptions::Unmarshalling(Parcel &parcel) +{ + DpSyncOptions *dpSyncOptions = new (std::nothrow) DpSyncOptions(); + if (dpSyncOptions == nullptr) { + return nullptr; + } + + if (!dpSyncOptions->ReadFromParcel(parcel)) { + delete dpSyncOptions; + dpSyncOptions = nullptr; + } + + return dpSyncOptions; +} + +bool DpSyncOptions::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, static_cast(syncMode_), false); + WRITE_HELPER_RET(parcel, Int32, static_cast(syncDeviceIds_.size()), false); + for (const auto& deviceId : syncDeviceIds_) { + WRITE_HELPER_RET(parcel, String, deviceId, false); + } + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/local_service_info.cpp b/common/src/interfaces/local_service_info.cpp index ea1579b9a801d988bf0292c4209e4dd8c55f3bfc..374df36414c2438bd3cdafd97556bad52ddddd9c 100644 --- a/common/src/interfaces/local_service_info.cpp +++ b/common/src/interfaces/local_service_info.cpp @@ -42,7 +42,7 @@ void LocalServiceInfo::SetBundleName(const std::string& bundleName) { bundleName_ = bundleName; } - + int32_t LocalServiceInfo::GetAuthBoxType() const { return authBoxType_; @@ -52,7 +52,7 @@ void LocalServiceInfo::SetAuthBoxType(const int32_t authBoxType) { authBoxType_ = authBoxType; } - + int32_t LocalServiceInfo::GetAuthType() const { return authType_; @@ -62,7 +62,7 @@ void LocalServiceInfo::SetAuthType(const int32_t authType) { authType_ = authType; } - + int32_t LocalServiceInfo::GetPinExchangeType() const { return pinExchangeType_; @@ -131,5 +131,44 @@ std::string LocalServiceInfo::dump() const { return ""; } + +bool LocalServiceInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, bundleName_, false); + READ_HELPER_RET(parcel, Int32, authBoxType_, false); + READ_HELPER_RET(parcel, Int32, authType_, false); + READ_HELPER_RET(parcel, Int32, pinExchangeType_, false); + READ_HELPER_RET(parcel, String, pinCode_, false); + READ_HELPER_RET(parcel, String, description_, false); + READ_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} + +LocalServiceInfo *LocalServiceInfo::Unmarshalling(Parcel &parcel) +{ + LocalServiceInfo *localServiceInfo = new (std::nothrow) LocalServiceInfo(); + if (localServiceInfo == nullptr) { + return nullptr; + } + + if (!localServiceInfo->ReadFromParcel(parcel)) { + delete localServiceInfo; + localServiceInfo = nullptr; + } + + return localServiceInfo; +} + +bool LocalServiceInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, bundleName_, false); + WRITE_HELPER_RET(parcel, Int32, authBoxType_, false); + WRITE_HELPER_RET(parcel, Int32, authType_, false); + WRITE_HELPER_RET(parcel, Int32, pinExchangeType_, false); + WRITE_HELPER_RET(parcel, String, pinCode_, false); + WRITE_HELPER_RET(parcel, String, description_, false); + WRITE_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/pincode_invalid_callback_proxy.cpp b/common/src/interfaces/pincode_invalid_callback_proxy.cpp index 50c9255cf31bcd06006ccd312ab2908c1da3cb30..5925844bf2003607cc192a6631805deab5adfe0d 100644 --- a/common/src/interfaces/pincode_invalid_callback_proxy.cpp +++ b/common/src/interfaces/pincode_invalid_callback_proxy.cpp @@ -16,7 +16,7 @@ #include "pincode_invalid_callback_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/product_info.cpp b/common/src/interfaces/product_info.cpp index 324b94e8353a984f596de90288755ffa6a686e92..0bc16af11eb489e7028e746517e4bcfb45fd146b 100644 --- a/common/src/interfaces/product_info.cpp +++ b/common/src/interfaces/product_info.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 @@ -76,7 +76,6 @@ void ProductInfo::SetImageVersion(const std::string& imageVersion) this->imageVersion_ = imageVersion; } - bool ProductInfo::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, productId_, false); @@ -158,5 +157,40 @@ std::string ProductInfo::GetAnonyProductName(const std::string& productName) con cJSON_Delete(json); return jsonStr; } + +bool ProductInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, model_, false); + READ_HELPER_RET(parcel, String, productName_, false); + READ_HELPER_RET(parcel, String, productShortName_, false); + READ_HELPER_RET(parcel, String, imageVersion_, false); + return true; +} + +ProductInfo *ProductInfo::Unmarshalling(Parcel &parcel) +{ + ProductInfo *productInfo = new (std::nothrow) ProductInfo(); + if (productInfo == nullptr) { + return nullptr; + } + + if (!productInfo->ReadFromParcel(parcel)) { + delete productInfo; + productInfo = nullptr; + } + + return productInfo; +} + +bool ProductInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, model_, false); + WRITE_HELPER_RET(parcel, String, productName_, false); + WRITE_HELPER_RET(parcel, String, productShortName_, false); + WRITE_HELPER_RET(parcel, String, imageVersion_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/profile_change_listener_proxy.cpp b/common/src/interfaces/profile_change_listener_proxy.cpp index 740957ae2ead233f83dc7ee13e890a46c30cc3cb..939dc4e4d39af39aa14df4550886caceb5b607db 100644 --- a/common/src/interfaces/profile_change_listener_proxy.cpp +++ b/common/src/interfaces/profile_change_listener_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ #include "profile_change_listener_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/service_info_profile.cpp b/common/src/interfaces/service_info_profile.cpp index 9e126f86a19d1eb2db1a96befa55bb04b67bc87b..64745cc24552be8dad168c0450d5556a37f50463 100644 --- a/common/src/interfaces/service_info_profile.cpp +++ b/common/src/interfaces/service_info_profile.cpp @@ -74,7 +74,7 @@ void ServiceInfoProfile::SetTokenId(const std::string& tokenId) { tokenId_ = tokenId; } - + int64_t ServiceInfoProfile::GetServiceId() const { return serviceId_; @@ -99,12 +99,12 @@ std::string ServiceInfoProfile::GetServiceName() const { return serviceName_; } - + void ServiceInfoProfile::SetServiceName(const std::string& serviceName) { serviceName_ = serviceName; } - + std::string ServiceInfoProfile::GetServiceDisplayName() const { return serviceDisplayName_; @@ -124,7 +124,7 @@ void ServiceInfoProfile::SetCustomData(const std::string& customData) { customData_ = customData; } - + int32_t ServiceInfoProfile::GetCustomDataLen() const { return customDataLen_; @@ -164,7 +164,7 @@ void ServiceInfoProfile::SetAbilityName(const std::string& abilityName) { abilityName_ = abilityName; } - + int32_t ServiceInfoProfile::GetAuthBoxType() const { return authBoxType_; @@ -174,7 +174,7 @@ void ServiceInfoProfile::SetAuthBoxType(const int32_t authBoxType) { authBoxType_ = authBoxType; } - + int32_t ServiceInfoProfile::GetAuthType() const { return authType_; @@ -184,7 +184,7 @@ void ServiceInfoProfile::SetAuthType(const int32_t authType) { authType_ = authType; } - + int32_t ServiceInfoProfile::GetPinExchangeType() const { return pinExchangeType_; @@ -214,12 +214,12 @@ void ServiceInfoProfile::SetDescription(const std::string& description) { description_ = description; } - + std::string ServiceInfoProfile::GetServiceDicoveryScope() const { return serviceDicoveryScope_; } - + void ServiceInfoProfile::SetServiceDicoveryScope(const std::string& serviceDicoveryScope) { serviceDicoveryScope_ = serviceDicoveryScope; @@ -289,5 +289,70 @@ std::string ServiceInfoProfile::dump() const { return ""; } + +bool ServiceInfoProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, networkId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceDisplayName_, false); + READ_HELPER_RET(parcel, String, customData_, false); + READ_HELPER_RET(parcel, Int32, customDataLen_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + READ_HELPER_RET(parcel, String, moduleName_, false); + READ_HELPER_RET(parcel, String, abilityName_, false); + READ_HELPER_RET(parcel, Int32, authBoxType_, false); + READ_HELPER_RET(parcel, Int32, authType_, false); + READ_HELPER_RET(parcel, Int32, pinExchangeType_, false); + READ_HELPER_RET(parcel, String, pinCode_, false); + READ_HELPER_RET(parcel, String, description_, false); + READ_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + READ_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} + +ServiceInfoProfile *ServiceInfoProfile::Unmarshalling(Parcel &parcel) +{ + ServiceInfoProfile *serviceInfoProfile = new (std::nothrow) ServiceInfoProfile(); + if (serviceInfoProfile == nullptr) { + return nullptr; + } + + if (!serviceInfoProfile->ReadFromParcel(parcel)) { + delete serviceInfoProfile; + serviceInfoProfile = nullptr; + } + + return serviceInfoProfile; +} + +bool ServiceInfoProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, networkId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, serviceDisplayName_, false); + WRITE_HELPER_RET(parcel, String, customData_, false); + WRITE_HELPER_RET(parcel, Int32, customDataLen_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + WRITE_HELPER_RET(parcel, String, moduleName_, false); + WRITE_HELPER_RET(parcel, String, abilityName_, false); + WRITE_HELPER_RET(parcel, Int32, authBoxType_, false); + WRITE_HELPER_RET(parcel, Int32, authType_, false); + WRITE_HELPER_RET(parcel, Int32, pinExchangeType_, false); + WRITE_HELPER_RET(parcel, String, pinCode_, false); + WRITE_HELPER_RET(parcel, String, description_, false); + WRITE_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + WRITE_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/service_info_unique_key.cpp b/common/src/interfaces/service_info_unique_key.cpp index 9e46fef4218a5f3c97a049b64b781a7cd10bb999..e796a458b7a999d38d5dbfffb1564b693f4925e2 100644 --- a/common/src/interfaces/service_info_unique_key.cpp +++ b/common/src/interfaces/service_info_unique_key.cpp @@ -61,7 +61,7 @@ void ServiceInfoUniqueKey::SetTokenId(const std::string& tokenId) { tokenId_ = tokenId; } - + int64_t ServiceInfoUniqueKey::GetServiceId() const { return serviceId_; @@ -111,5 +111,40 @@ std::string ServiceInfoUniqueKey::dump() const { return ""; } + +bool ServiceInfoUniqueKey::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + return true; +} + +ServiceInfoUniqueKey *ServiceInfoUniqueKey::Unmarshalling(Parcel &parcel) +{ + ServiceInfoUniqueKey *serviceInfoUniqueKey = new (std::nothrow) ServiceInfoUniqueKey(); + if (serviceInfoUniqueKey == nullptr) { + return nullptr; + } + + if (!serviceInfoUniqueKey->ReadFromParcel(parcel)) { + delete serviceInfoUniqueKey; + serviceInfoUniqueKey = nullptr; + } + + return serviceInfoUniqueKey; +} + +bool ServiceInfoUniqueKey::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/service_profile.cpp b/common/src/interfaces/service_profile.cpp index d4bc2272fac940bd4dc7c8d22790d7e949f0c838..01b32ff12cd4c107106dca9eff38bc75b0de70e8 100644 --- a/common/src/interfaces/service_profile.cpp +++ b/common/src/interfaces/service_profile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -148,5 +148,40 @@ std::string ServiceProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool ServiceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + return true; +} + +ServiceProfile *ServiceProfile::Unmarshalling(Parcel &parcel) +{ + ServiceProfile *serviceProfile = new (std::nothrow) ServiceProfile(); + if (serviceProfile == nullptr) { + return nullptr; + } + + if (!serviceProfile->ReadFromParcel(parcel)) { + delete serviceProfile; + serviceProfile = nullptr; + } + + return serviceProfile; +} + +bool ServiceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/trust_device_profile.cpp b/common/src/interfaces/trust_device_profile.cpp index 75521705ff2647bb07bf4125953ff068ed649150..267162995cfffc69de53e00dea34f24a456a09bd 100644 --- a/common/src/interfaces/trust_device_profile.cpp +++ b/common/src/interfaces/trust_device_profile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -145,5 +145,44 @@ std::string TrustDeviceProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool TrustDeviceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Uint32, deviceIdType_, false); + READ_HELPER_RET(parcel, String, deviceIdHash_, false); + READ_HELPER_RET(parcel, Int32, status_, false); + READ_HELPER_RET(parcel, Uint32, bindType_, false); + READ_HELPER_RET(parcel, Int32, peerUserId_, false); + READ_HELPER_RET(parcel, Int32, localUserId_, false); + return true; +} + +TrustDeviceProfile *TrustDeviceProfile::Unmarshalling(Parcel &parcel) +{ + TrustDeviceProfile *trustDeviceProfile = new (std::nothrow) TrustDeviceProfile(); + if (trustDeviceProfile == nullptr) { + return nullptr; + } + + if (!trustDeviceProfile->ReadFromParcel(parcel)) { + delete trustDeviceProfile; + trustDeviceProfile = nullptr; + } + + return trustDeviceProfile; +} + +bool TrustDeviceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false); + WRITE_HELPER_RET(parcel, String, deviceIdHash_, false); + WRITE_HELPER_RET(parcel, Int32, status_, false); + WRITE_HELPER_RET(parcel, Uint32, bindType_, false); + WRITE_HELPER_RET(parcel, Int32, peerUserId_, false); + WRITE_HELPER_RET(parcel, Int32, localUserId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/trusted_device_info.cpp b/common/src/interfaces/trusted_device_info.cpp index cb3059f2e9097156fef5502db8edaca5641cd914..86646825f27953be6dce494fec008c14ec4a2bc4 100644 --- a/common/src/interfaces/trusted_device_info.cpp +++ b/common/src/interfaces/trusted_device_info.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 @@ -175,5 +175,44 @@ std::string TrustedDeviceInfo::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool TrustedDeviceInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, networkId_, false); + READ_HELPER_RET(parcel, Int32, authForm_, false); + READ_HELPER_RET(parcel, Uint16, deviceTypeId_, false); + READ_HELPER_RET(parcel, String, osVersion_, false); + READ_HELPER_RET(parcel, Int32, osType_, false); + READ_HELPER_RET(parcel, String, udid_, false); + READ_HELPER_RET(parcel, String, uuid_, false); + return true; +} + +TrustedDeviceInfo *TrustedDeviceInfo::Unmarshalling(Parcel &parcel) +{ + TrustedDeviceInfo *trustedDeviceInfo = new (std::nothrow) TrustedDeviceInfo(); + if (trustedDeviceInfo == nullptr) { + return nullptr; + } + + if (!trustedDeviceInfo->ReadFromParcel(parcel)) { + delete trustedDeviceInfo; + trustedDeviceInfo = nullptr; + } + + return trustedDeviceInfo; +} + +bool TrustedDeviceInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, networkId_, false); + WRITE_HELPER_RET(parcel, Int32, authForm_, false); + WRITE_HELPER_RET(parcel, Uint16, deviceTypeId_, false); + WRITE_HELPER_RET(parcel, String, osVersion_, false); + WRITE_HELPER_RET(parcel, Int32, osType_, false); + WRITE_HELPER_RET(parcel, String, udid_, false); + WRITE_HELPER_RET(parcel, String, uuid_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/utils/ipc_utils.cpp b/common/src/utils/ipc_utils.cpp index 78a259bdd5350a5dc44fdf348e24a69ef1a63553..7976e2e047b9425e3f3d970f21fd72223c77177c 100644 --- a/common/src/utils/ipc_utils.cpp +++ b/common/src/utils/ipc_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,6 +15,7 @@ #include "ipc_utils.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "macro_utils.h" namespace OHOS { diff --git a/interfaces/innerkits/core/BUILD.gn b/interfaces/innerkits/core/BUILD.gn index 95a346e3e5f84d7191123cdada091e75d367e670..17be76738d94daf2e1727bee02ba3b3e79fe7591 100644 --- a/interfaces/innerkits/core/BUILD.gn +++ b/interfaces/innerkits/core/BUILD.gn @@ -14,16 +14,64 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") +import("//build/config/components/idl_tool/idl.gni") + +idl_gen_interface("distributed_device_profile_interfaces_gn") { + sources=["IDistributedDeviceProfile.idl"] + hitrace = "HITRACE_TAG_DEVICE_PROFILE" + log_domainid = "0xD004400" + log_tag = "Distributed_Device_Profile" +} + +config("distributed_device_profile_interfaces_ipc_config"){ + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("distributed_device_profile_interfaces_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + output_values = get_target_outputs(":distributed_device_profile_interfaces_gn") + sources = [] + sources += filter_include(output_values, [ "*.cpp" ]) + configs = [ + ":distributed_device_profile_interfaces_ipc_config" + ] + include_dirs = [ + "${device_profile_common}/include/constants", + "${device_profile_common}/include/interfaces", + "${device_profile_common}/include/utils", + ] + deps = [ ":distributed_device_profile_interfaces_gn",] + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} config("distributed_device_profile_sdk_config") { visibility = [ ":*" ] include_dirs = [ "include", "include/callback", + "${device_profile_path}/radar/include", "${device_profile_common}/include/constants", "${device_profile_common}/include/interfaces", "${device_profile_common}/include/utils", - "${device_profile_path}/radar/include", ] } @@ -56,14 +104,17 @@ ohos_shared_library("distributed_device_profile_sdk") { sources = [ "src/callback/device_profile_load_callback.cpp", "src/distributed_device_profile_client.cpp", - "src/distributed_device_profile_proxy.cpp", ] - public_configs = [ ":distributed_device_profile_sdk_config" ] + public_configs = [ + ":distributed_device_profile_sdk_config", + ":distributed_device_profile_interfaces_ipc_config", + ] deps = [ "${device_profile_common}:distributed_device_profile_common", "${device_profile_path}/radar:device_profile_radar", + ":distributed_device_profile_interfaces_ipc", ] external_deps = [ diff --git a/interfaces/innerkits/core/IDistributedDeviceProfile.idl b/interfaces/innerkits/core/IDistributedDeviceProfile.idl new file mode 100644 index 0000000000000000000000000000000000000000..6f29d9324a6be0f86bc823295a42dc283c64084b --- /dev/null +++ b/interfaces/innerkits/core/IDistributedDeviceProfile.idl @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable OHOS.DistributedDeviceProfile.TrustDeviceProfile; +sequenceable OHOS.DistributedDeviceProfile.DeviceProfile; +sequenceable OHOS.DistributedDeviceProfile.ServiceProfile; +sequenceable OHOS.DistributedDeviceProfile.CharacteristicProfile; +sequenceable OHOS.DistributedDeviceProfile.AccessControlProfile; +sequenceable dp_subscribe_info_extension..OHOS.DistributedDeviceProfile.SubscribeInfoExt; +sequenceable dp_sync_options..OHOS.DistributedDeviceProfile.DpSyncOptions; +sequenceable OHOS.DistributedDeviceProfile.TrustedDeviceInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceProfileFilterOptions; +sequenceable OHOS.DistributedDeviceProfile.ProductInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceIconInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceIconInfoFilterOptions; +sequenceable OHOS.IRemoteObject; +sequenceable OHOS.DistributedDeviceProfile.ServiceInfoProfile; +sequenceable OHOS.DistributedDeviceProfile.ServiceInfoUniqueKey; +sequenceable OHOS.DistributedDeviceProfile.LocalServiceInfo; + +interface OHOS.DistributedDeviceProfile.IDistributedDeviceProfile { + [ipccode 7] void PutAccessControlProfile([in] AccessControlProfile aclProfile); + [ipccode 8] void UpdateAccessControlProfile([in] AccessControlProfile aclProfile); + [ipccode 9] void GetTrustDeviceProfile([in] String deviceId, [out] TrustDeviceProfile trustDeviceProfile); + [ipccode 10] void GetAllTrustDeviceProfile([out] TrustDeviceProfile[] trustDeviceProfiles); + [ipccode 11] void GetAccessControlProfile([in] OrderedMap queryParams, + [out] AccessControlProfile[] accessControlProfiles); + [ipccode 12] void GetAllAccessControlProfile([out] AccessControlProfile[] accessControlProfiles); + [ipccode 13] void DeleteAccessControlProfile([in] int accessControlId); + [ipccode 46] void PutDeviceProfileBatch([in] DeviceProfile[] deviceProfiles); + [ipccode 14] void PutServiceProfile([in] ServiceProfile serviceProfile); + [ipccode 15] void PutServiceProfileBatch([in] ServiceProfile[] serviceProfiles); + [ipccode 16] void PutCharacteristicProfile([in] CharacteristicProfile charProfile); + [ipccode 17] void PutCharacteristicProfileBatch([in] CharacteristicProfile[] charProfiles); + [ipccode 18] void GetDeviceProfile([in] String deviceId, [inout] DeviceProfile deviceProfile); + [ipccode 47] void GetDeviceProfiles([in] DeviceProfileFilterOptions options,[out] DeviceProfile[] deviceProfiles); + [ipccode 51] void DeleteDeviceProfileBatch([in] DeviceProfile[] deviceProfiles); + [ipccode 19] void GetServiceProfile([in] String deviceId, [in] String serviceName, + [inout] ServiceProfile serviceProfile); + [ipccode 20] void GetCharacteristicProfile([in] String deviceId, [in] String serviceName, + [in] String characteristicId, [inout] CharacteristicProfile charProfile); + [ipccode 21] void DeleteServiceProfile([in] String deviceId, [in] String serviceName, + [in] boolean isMultiUser, [in] int userId); + [ipccode 22] void DeleteCharacteristicProfile([in] String deviceId, [in] String serviceName, + [in] String characteristicId, [in] boolean isMultiUser, [in] int userId); + [ipccode 23] void SubscribeDeviceProfile([in] SubscribeInfoExt subscribeInfoExtension, + [in] IRemoteObject listener); + [ipccode 24] void UnSubscribeDeviceProfile([in] SubscribeInfoExt subscribeInfoExtension, + [in] IRemoteObject listener); + [ipccode 41] void SubscribeDeviceProfileInited([in] int saId, [in] IRemoteObject dpInitedCallback); + [ipccode 42] void UnSubscribeDeviceProfileInited([in] int saId); + [ipccode 25] void SyncDeviceProfile([in] DpSyncOptions syncOptions, + [in] IRemoteObject syncCompletedCallback); + [ipccode 26] void SendSubscribeInfos([in] OrderedMap listenerMap, + [in] OrderedMap listeners); + [ipccode 45] void PutAllTrustedDevices([in] TrustedDeviceInfo[] deviceInfos); + [ipccode 50] void PutProductInfoBatch([in] ProductInfo[] productInfos); + [ipccode 49] void PutDeviceIconInfoBatch([in] DeviceIconInfo[] deviceIconInfos); + [ipccode 48] void GetDeviceIconInfos([in] DeviceIconInfoFilterOptions filterOptions,[out] DeviceIconInfo[] deviceIconInfos); + [ipccode 59] void PutSessionKey([in] unsigned int userId, [in] unsigned char[] sessionKey, [out] int sessionKeyId); + [ipccode 60] void GetSessionKey([in] unsigned int userId, [in] int sessionKeyId, [out] unsigned char[] sessionKey); + [ipccode 61] void UpdateSessionKey([in] unsigned int userId, [in] int sessionKeyId, [in] unsigned char[] sessionKey); + [ipccode 62] void DeleteSessionKey([in] unsigned int userId, [in] int sessionKeyId); + [ipccode 64] void SubscribePinCodeInvalid([in] String bundleName, [in] int pinExchangeType, + [in] IRemoteObject pinCodeCallback); + [ipccode 65] void UnSubscribePinCodeInvalid([in] String bundleName, [in] int pinExchangeType); + [ipccode 52] void PutServiceInfoProfile([in] ServiceInfoProfile serviceInfoProfile); + [ipccode 53] void DeleteServiceInfoProfile([in] ServiceInfoUniqueKey key); + [ipccode 54] void UpdateServiceInfoProfile([in] ServiceInfoProfile serviceInfoProfile); + [ipccode 55] void GetServiceInfoProfileByUniqueKey([in] ServiceInfoUniqueKey key, + [out] ServiceInfoProfile serviceInfoProfile); + [ipccode 56] void GetServiceInfoProfileListByTokenId([in]ServiceInfoUniqueKey key, + [out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 57] void GetAllServiceInfoProfileList([out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 58] void GetServiceInfoProfileListByBundleName([in] ServiceInfoUniqueKey key, + [out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 66] void PutLocalServiceInfo([in] LocalServiceInfo localServiceInfo); + [ipccode 67] void UpdateLocalServiceInfo([in] LocalServiceInfo localServiceInfo); + [ipccode 68] void GetLocalServiceInfoByBundleAndPinType([in] String bundleName, + [in] int pinExchangeType, [out] LocalServiceInfo localServiceInfo); + [ipccode 69] void DeleteLocalServiceInfo([in] String bundleName,[in] int pinExchangeType); + [ipccode 70] void GetAllAclIncludeLnnAcl([out] AccessControlProfile[] accessControlProfiles); +} \ No newline at end of file diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index 7f27d01f5f010033c51596609f807dead79cb7c2..2346b232e2b0d19e1f477eb1930658e25923c40b 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -27,12 +27,13 @@ #include #include "i_pincode_invalid_callback.h" #include "i_profile_change_listener.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "i_dp_inited_callback.h" #include "iremote_object.h" #include "refbase.h" #include "single_instance.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "distributed_device_profile_constants.h" #include "i_business_callback.h" #include "sync_completed_callback_stub.h" @@ -160,6 +161,8 @@ private: std::mutex subscribeLock_; std::map subscribeInfos_; + std::map subscribeInfoExtensions_; + std::map> listeners_; std::mutex saListenerLock_; sptr saListenerCallback_ = nullptr; @@ -170,6 +173,9 @@ private: std::string businessKey_ = ""; const std::set retryErrCodes_ = {DP_SERVICE_STOPPED, DP_LOAD_SERVICE_ERR}; + + SubscribeInfoExt subscribeInfoExt_; + sptr listener_ = nullptr; }; } // 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 deleted file mode 100644 index 4af626628008450d4e48658cd049fc112dea3667..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H -#define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H - -#include -#include -#include -#include - -#include "i_distributed_device_profile.h" -#include "i_dp_inited_callback.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#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" - -namespace OHOS { -namespace DistributedDeviceProfile { -class DistributedDeviceProfileProxy : public IRemoteProxy { -public: - explicit DistributedDeviceProfileProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~DistributedDeviceProfileProxy() {} - - int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; - int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) override; - int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; - int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; - int32_t DeleteAccessControlProfile(int32_t accessControlId) override; - int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) override; - int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) override; - int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) override; - int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) override; - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t PutServiceProfile(const ServiceProfile& serviceProfile) override; - int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) override; - int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) override; - int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) override; - int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) override; - int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) override; - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) override; - int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMultiUser = false, - int32_t userId = DEFAULT_USER_ID) override; - int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; - int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; - int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; - int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t SyncDeviceProfile(const DpSyncOptions& syncOptions, sptr syncCompletedCallback) override; - int32_t SendSubscribeInfos(std::map listenerMap) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; - int32_t PutProductInfoBatch(const std::vector& productInfos) override; - int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; - int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) override; - int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; - int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; - int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - 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_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H diff --git a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index bb6bae509931b7dc8bdf29fcb484e652b9a97622..51dd2a438b338d53867a3dec028d022819048af0 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -33,7 +33,7 @@ #include "dp_radar_helper.h" #include "event_handler.h" #include "event_runner.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iremote_broker.h" @@ -124,7 +124,16 @@ void DistributedDeviceProfileClient::SendSubscribeInfosToService() HILOGE("SubscribeInfos size is invalid!size: %{public}zu!", subscribeInfos_.size()); return; } - dpService->SendSubscribeInfos(subscribeInfos_); + + subscribeInfoExtensions_.clear(); + listeners_.clear(); + for (const auto& subscribeInfo : subscribeInfos_) { + SubscribeInfoExt subscribeInfoExtension(subscribeInfo.second); + sptr listener = subscribeInfo.second.GetListener(); + subscribeInfoExtensions_.insert(std::make_pair(subscribeInfo.first, subscribeInfoExtension)); + listeners_.insert(std::make_pair(subscribeInfo.first, listener)); + } + dpService->SendSubscribeInfos(subscribeInfoExtensions_, listeners_); } } @@ -507,7 +516,9 @@ int32_t DistributedDeviceProfileClient::SubscribeDeviceProfile(const SubscribeIn subscribeInfos_[subscribeTag] = subscribeInfo; HILOGI("subscribeInfos_.size is %{public}zu", subscribeInfos_.size()); } - return dpService->SubscribeDeviceProfile(subscribeInfo); + subscribeInfoExt_ = SubscribeInfoExt(subscribeInfo); + listener_ = subscribeInfo.GetListener(); + return dpService->SubscribeDeviceProfile(subscribeInfoExt_, listener_); } int32_t DistributedDeviceProfileClient::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) @@ -523,7 +534,9 @@ int32_t DistributedDeviceProfileClient::UnSubscribeDeviceProfile(const Subscribe subscribeInfos_.erase(subscribeInfo.GetSubscribeKey() + SEPARATOR + std::to_string(subscribeInfo.GetSaId())); HILOGI("subscribeInfos_.size is %{public}zu", subscribeInfos_.size()); } - return dpService->UnSubscribeDeviceProfile(subscribeInfo); + subscribeInfoExt_ = SubscribeInfoExt(subscribeInfo); + listener_ = subscribeInfo.GetListener(); + return dpService->UnSubscribeDeviceProfile(subscribeInfoExt_, listener_); } int32_t DistributedDeviceProfileClient::SyncDeviceProfile(const DpSyncOptions& syncOptions, diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp deleted file mode 100644 index 9abe3f8dcc31585888f4819f4a8d64aec4a1eac0..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ /dev/null @@ -1,852 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "distributed_device_profile_proxy.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "DistributedDeviceProfileProxy"; -} - -int32_t DistributedDeviceProfileProxy::PutAccessControlProfile(const AccessControlProfile& aclProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!aclProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateAccessControlProfile(const AccessControlProfile& aclProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!aclProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutProductInfoBatch(const std::vector& productInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, productInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceIconInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!filterOptions.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS), data, reply); - if (!IpcUtils::UnMarshalling(reply, deviceIconInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetTrustDeviceProfile(const std::string& deviceId, - TrustDeviceProfile& trustDeviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE), data, reply); - if (!trustDeviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, trustDeviceProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, queryParams)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ACL_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllAccessControlProfile( - std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteAccessControlProfile(int32_t accessControlId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, accessControlId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutSessionKey( - uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - if (!IpcUtils::Marshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SESSION_KEY), data, reply); - READ_HELPER(reply, Int32, sessionKeyId); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetSessionKey( - uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SESSION_KEY), data, reply); - if (!IpcUtils::UnMarshalling(reply, sessionKey)) { - HILOGE("dp ipc read parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateSessionKey( - uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - if (!IpcUtils::Marshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_SESSION_KEY), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_SESSION_KEY), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutDeviceProfileBatch(std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceProfile(const ServiceProfile& serviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceProfileBatch(const std::vector& serviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, serviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutCharacteristicProfile(const CharacteristicProfile& charProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!charProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_CHAR_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutCharacteristicProfileBatch( - const std::vector& charProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, charProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, Bool, deviceProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, deviceProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW), data, reply); - if (!deviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!options.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_PROFILES), data, reply); - if (!IpcUtils::UnMarshalling(reply, deviceProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteDeviceProfileBatch(std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, Bool, serviceProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, serviceProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_PROFILE), data, reply); - if (!serviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceInfoProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceInfoProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY), data, reply); - if (!serviceInfoProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllServiceInfoProfileList( - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, String, characteristicId); - WRITE_HELPER(data, Bool, charProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, charProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_CHAR_PROFILE), data, reply); - if (!charProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName, bool isMultiUser, int32_t userId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, Bool, isMultiUser); - WRITE_HELPER(data, Int32, userId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, String, characteristicId); - WRITE_HELPER(data, Bool, isMultiUser); - WRITE_HELPER(data, Int32, userId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_CHAR_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!subscribeInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!subscribeInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SyncDeviceProfile(const DpSyncOptions& syncOptions, - const sptr syncCompletedCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!syncOptions.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - WRITE_HELPER(data, RemoteObject, syncCompletedCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SendSubscribeInfos(std::map listenerMap) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, listenerMap)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, saId); - WRITE_HELPER(data, RemoteObject, dpInitedCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribeDeviceProfileInited(int32_t saId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, saId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::SubscribePinCodeInvalid( - const std::string& bundleName, int32_t pinExchangeType, sptr pinCodeCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - WRITE_HELPER(data, RemoteObject, pinCodeCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribePinCodeInvalid( - const std::string& bundleName, int32_t pinExchangeType) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::PutAllTrustedDevices( - const std::vector deviceInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!localServiceInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!localServiceInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, - static_cast(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE), data, reply); - if (!localServiceInfo.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, - 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/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/radar/test/unittest/BUILD.gn b/radar/test/unittest/BUILD.gn index 6bae4277b6ec5f1a56a420c2cf390d9c4d1b86ec..612cac1e5c6bdd5cbaa4fdb92932d2d882dcbe13 100644 --- a/radar/test/unittest/BUILD.gn +++ b/radar/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -29,6 +29,7 @@ device_profile_external_deps = [ "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "c_utils:utils", ] ohos_unittest("dp_radar_helper_test_new") { diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index f4c2aba5ee167d9978b244a1a9f4fdab070c5134..3513c9243fc46cdc2dbacad294798c224c5e55d8 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -101,7 +101,6 @@ ohos_shared_library("distributed_device_profile_svr") { "src/deviceprofilemanager/switch_profile_manager.cpp", "src/dfx/device_profile_dumper.cpp", "src/distributed_device_profile_service_new.cpp", - "src/distributed_device_profile_stub_new.cpp", "src/dm_adapter/dm_adapter.cpp", "src/localserviceinfomanager/local_service_info_manager.cpp", "src/multiusermanager/multi_user_manager.cpp", @@ -133,6 +132,7 @@ ohos_shared_library("distributed_device_profile_svr") { deps = [ "${device_profile_common}:distributed_device_profile_common", "${device_profile_path}/radar:device_profile_radar", + "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc", ] configs = [ ":device_info_manager_config" ] @@ -168,6 +168,8 @@ ohos_shared_library("distributed_device_profile_svr") { part_name = "device_info_manager" subsystem_name = "deviceprofile" + + public_configs = [ "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc_config" ] } group("unittest") { diff --git a/services/core/include/common/dp_services_constants.h b/services/core/include/common/dp_services_constants.h index a861f21662051ad5426625f2e7b9529c6678484b..12341993d2334cb0870c193b559a394583e8ac5a 100644 --- a/services/core/include/common/dp_services_constants.h +++ b/services/core/include/common/dp_services_constants.h @@ -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 @@ -38,7 +38,7 @@ extern const std::string CREATE_DEVICE_PROFILE_WISE_DEVICEID_INDEX_SQL; extern const std::string ALTER_TABLE_DP_ADD_COLUMN_PRODUCT_NAME_SQL; extern const std::string ALTER_TABLE_DP_RENAME_COLUMN_INTERNAL_MODEL_SQL; // DeviceIconInfoDao -extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL ; +extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL; extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_UNIQUE_INDEX_SQL; extern const std::string SELECT_DEVICE_ICON_INFO_TABLE; extern const std::string ALTER_TABLE_DEVICE_ICON_INFO_ADD_COLUMN_INTENAL_MODEL_SQL; diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 28fac2c846cf8f887f6e1581eeca5e8a1c423991..a6e98a13b271c5191e95cb9e08d7bd9d806c2394 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -23,7 +23,7 @@ #include "device_icon_info.h" #include "device_icon_info_filter_options.h" #include "device_profile_filter_options.h" -#include "distributed_device_profile_stub_new.h" +#include "distributed_device_profile_stub.h" #include "dp_account_common_event.h" #include "event_handler.h" #include "event_runner.h" @@ -38,7 +38,7 @@ namespace OHOS { namespace DistributedDeviceProfile { -class DistributedDeviceProfileServiceNew : public SystemAbility, public DistributedDeviceProfileStubNew { +class DistributedDeviceProfileServiceNew : public SystemAbility, public DistributedDeviceProfileStub { DECLARE_SYSTEM_ABILITY(DistributedDeviceProfileServiceNew); DECLARE_SINGLE_INSTANCE_BASE(DistributedDeviceProfileServiceNew); @@ -56,7 +56,7 @@ public: int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, + int32_t GetAccessControlProfile(const std::map& queryParams, std::vector& accessControlProfiles) override; int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; @@ -65,14 +65,15 @@ public: int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) override; int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) override; int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) override; - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) override; + int32_t PutDeviceProfileBatch(const std::vector& deviceProfiles) override; int32_t PutServiceProfile(const ServiceProfile& serviceProfile) override; int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) override; int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) override; int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) override; int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) override; - int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, std::vector& deviceProfiles) override; - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) override; + int32_t GetDeviceProfiles(const DeviceProfileFilterOptions& options, + std::vector& deviceProfiles) override; + int32_t DeleteDeviceProfileBatch(const std::vector& deviceProfiles) override; int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, ServiceProfile& serviceProfile) override; int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, @@ -95,25 +96,28 @@ public: int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, std::vector& serviceInfoProfiles) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; + int32_t SubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfoExtension, + const sptr& listener) override; + int32_t UnSubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfoExtension, + const sptr& listener) override; int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; + const sptr& syncCompletedCallback) override; + int32_t SubscribeDeviceProfileInited(int32_t saId, const sptr& dpInitedCallback) override; int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; + const sptr& pinCodeCallback) override; int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; + int32_t PutAllTrustedDevices(const std::vector& deviceInfos) override; int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo)override; int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo)override; 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 SendSubscribeInfos(std::map listenerMap) override; + int32_t SendSubscribeInfos(const std::map& listenerMap, + const std::map>& listeners) override; int32_t Dump(int32_t fd, const std::vector& args) override; - void DelayUnloadTask() override; - bool IsInited() override; + void DelayUnloadTask(); + bool IsInited(); bool IsReadyIntoIdle(); void AddRunningIpcCount(); void SubtractRunningIpcCount(); @@ -171,6 +175,9 @@ private: }; std::mutex businessEventCallbackMapMtx_; std::map, sptr> businessCallbackMap_; + + SubscribeInfoExt subscribeInfoExt_; + std::map listenerMapTrans_; }; } // 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 deleted file mode 100644 index c24d67447bfd80e1aed77402e4f9186c56023e4f..0000000000000000000000000000000000000000 --- a/services/core/include/distributed_device_profile_stub_new.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H -#define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H - -#include -#include - -#include "iremote_stub.h" - -#include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" -#include "ipc_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class DistributedDeviceProfileStubNew : public IRemoteStub { -public: - DistributedDeviceProfileStubNew(); - ~DistributedDeviceProfileStubNew(); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - - int32_t PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllAclIncludeLnnAclInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply); - int32_t PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllServiceInfoProfileListInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); - 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); - bool IsInterfaceTokenValid(MessageParcel& data); - void InitAclAndSubscribe(); - int32_t NotifyEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - int32_t NotifyAclEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - int32_t NotifyProfileDataEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option); - int32_t NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option); -private: - std::unordered_set aclAndSubscribeFuncs_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H diff --git a/services/core/include/profiledatamanager/profile_data_manager.h b/services/core/include/profiledatamanager/profile_data_manager.h index 5bebd54507d5126c3fa3ecb0dbb5c3bc9ce0b7e9..32565268642c129fe8543d88c3aba0d83964b402 100644 --- a/services/core/include/profiledatamanager/profile_data_manager.h +++ b/services/core/include/profiledatamanager/profile_data_manager.h @@ -33,16 +33,16 @@ class ProfileDataManager { public: int32_t Init(); int32_t UnInit(); - - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles); - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles); + + int32_t PutDeviceProfileBatch(const std::vector& deviceProfiles); + int32_t DeleteDeviceProfileBatch(const std::vector& deviceProfiles); int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, std::vector& deviceProfiles); int32_t PutProductInfoBatch(const std::vector& productInfos); int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos); int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, std::vector& deviceIconInfos); - + int32_t PutDeviceProfile(DeviceProfile deviceProfile); private: bool FilterInvaildSymbol(std::string str); diff --git a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h index 9fe776331dfbde5653b89c7aa91e839bcaf5ec3a..b0dba465ad067e9ecaf5cb0108537c693235389f 100644 --- a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h +++ b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,7 @@ #include "distributed_device_profile_enums.h" #include "device_profile.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "service_profile.h" #include "characteristic_profile.h" @@ -41,9 +42,9 @@ public: int32_t NotifyTrustDeviceProfileDelete(const TrustDeviceProfile& trustDeviceProfile); int32_t NotifyTrustDeviceProfileActive(const TrustDeviceProfile& trustDeviceProfile); int32_t NotifyTrustDeviceProfileInactive(const TrustDeviceProfile& trustDeviceProfile); - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); - int32_t SubscribeDeviceProfile(std::map subscribeInfos); - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); + int32_t SubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfo); + int32_t SubscribeDeviceProfile(const std::map subscribeInfos); + int32_t UnSubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfo); private: int32_t NotifyDeviceProfileAdd(const std::string& dbKey, const std::string& dbValue); @@ -55,7 +56,8 @@ private: int32_t NotifyCharProfileAdd(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileUpdate(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileDelete(const std::string& dbKey, const std::string& dbValue); - std::unordered_set GetSubscribeInfos(const std::string& dbKey); + std::unordered_set GetSubscribeInfos( + const std::string& dbKey); std::string DBKeyToSubcribeKey(const std::string& dbkey); private: @@ -63,7 +65,8 @@ private: std::mutex funcsMutex_; std::map funcsMap_; std::mutex subscribeMutex_; - std::map> subscribeInfoMap_; + std::map> + subscribeInfoExtensionMap_; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 4fa23a2749cf20a19211f8f92134bcbb34e724aa..15309fdc4f9498eacde75f89c06f0409217e8882 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -364,7 +364,7 @@ int32_t DistributedDeviceProfileServiceNew::GetDeviceIconInfos(const DeviceIconI return ret; } -int32_t DistributedDeviceProfileServiceNew::DeleteDeviceProfileBatch(std::vector& deviceProfiles) +int32_t DistributedDeviceProfileServiceNew::DeleteDeviceProfileBatch(const std::vector& deviceProfiles) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("the caller is permission denied!"); @@ -399,8 +399,8 @@ int32_t DistributedDeviceProfileServiceNew::GetAllTrustDeviceProfile( return ret; } -int32_t DistributedDeviceProfileServiceNew::GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) +int32_t DistributedDeviceProfileServiceNew::GetAccessControlProfile( + const std::map& queryParams, std::vector& accessControlProfiles) { if (!PermissionManager::GetInstance().IsCallerTrust(GET_ACCESS_CONTROL_PROFILE)) { HILOGE("the caller is permission denied!"); @@ -489,7 +489,7 @@ int32_t DistributedDeviceProfileServiceNew::DeleteSessionKey(uint32_t userId, in return ret; } -int32_t DistributedDeviceProfileServiceNew::PutDeviceProfileBatch(std::vector& deviceProfiles) +int32_t DistributedDeviceProfileServiceNew::PutDeviceProfileBatch(const std::vector& deviceProfiles) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("the caller is permission denied!"); @@ -698,7 +698,7 @@ int32_t DistributedDeviceProfileServiceNew::GetDeviceProfile(const std::string& return ret; } -int32_t DistributedDeviceProfileServiceNew::GetDeviceProfiles(DeviceProfileFilterOptions& options, +int32_t DistributedDeviceProfileServiceNew::GetDeviceProfiles(const DeviceProfileFilterOptions& options, std::vector& deviceProfiles) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { @@ -706,7 +706,8 @@ int32_t DistributedDeviceProfileServiceNew::GetDeviceProfiles(DeviceProfileFilte return DP_PERMISSION_DENIED; } HILOGD("CheckCallerPermission success interface GetDeviceProfiles"); - int32_t ret = ProfileDataManager::GetInstance().GetDeviceProfiles(options, deviceProfiles); + DeviceProfileFilterOptions newOptions = options; + int32_t ret = ProfileDataManager::GetInstance().GetDeviceProfiles(newOptions, deviceProfiles); return ret; } @@ -833,32 +834,38 @@ int32_t DistributedDeviceProfileServiceNew::DeleteLocalServiceInfo(const std::st return ret; } -int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfile(const SubscribeInfo& subscriberInfo) +int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfoExtension, + const sptr& listener) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); return DP_PERMISSION_DENIED; } + subscribeInfoExt_ = subscribeInfoExtension; + subscribeInfoExt_.SetListener(listener); HILOGD("CheckCallerPermission success interface SubscribeDeviceProfile"); - int32_t ret = SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(subscriberInfo); - DpRadarHelper::GetInstance().ReportSubscribeDeviceProfile(ret, subscriberInfo); + int32_t ret = SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(subscribeInfoExt_); + DpRadarHelper::GetInstance().ReportSubscribeDeviceProfile(ret, subscribeInfoExt_); return ret; } -int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile(const SubscribeInfo& subscriberInfo) +int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile( + const SubscribeInfoExt& subscribeInfoExtension, const sptr& listener) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); return DP_PERMISSION_DENIED; } + subscribeInfoExt_ = subscribeInfoExtension; + subscribeInfoExt_.SetListener(listener); HILOGD("CheckCallerPermission success interface UnSubscribeDeviceProfile"); - int32_t ret = SubscribeProfileManager::GetInstance().UnSubscribeDeviceProfile(subscriberInfo); - DpRadarHelper::GetInstance().ReportUnSubscribeDeviceProfile(ret, subscriberInfo); + int32_t ret = SubscribeProfileManager::GetInstance().UnSubscribeDeviceProfile(subscribeInfoExt_); + DpRadarHelper::GetInstance().ReportUnSubscribeDeviceProfile(ret, subscribeInfoExt_); return ret; } int32_t DistributedDeviceProfileServiceNew::SyncDeviceProfile( - const DistributedDeviceProfile::DpSyncOptions& syncOptions, sptr syncCompletedCallback) + const DistributedDeviceProfile::DpSyncOptions& syncOptions, const sptr& syncCompletedCallback) { if (!PermissionManager::GetInstance().CheckCallerSyncPermission()) { HILOGE("this caller is permission denied!"); @@ -870,9 +877,21 @@ int32_t DistributedDeviceProfileServiceNew::SyncDeviceProfile( return ret; } -int32_t DistributedDeviceProfileServiceNew::SendSubscribeInfos(std::map listenerMap) +int32_t DistributedDeviceProfileServiceNew::SendSubscribeInfos( + const std::map& listenerMap, + const std::map>& listeners) { - return SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(listenerMap); + listenerMapTrans_.clear(); + for (const auto& [key, subscribeInfoExt] : listenerMap) { + auto listenerIt = listeners.find(key); + if (listenerIt == listeners.end()) { + continue; + } + SubscribeInfoExt subscribeInfoExtTemp = subscribeInfoExt; + subscribeInfoExtTemp.SetListener(listenerIt->second); + listenerMapTrans_.emplace(key, std::move(subscribeInfoExtTemp)); + } + return SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(listenerMapTrans_); } int32_t DistributedDeviceProfileServiceNew::Dump(int32_t fd, const std::vector& args) @@ -1197,7 +1216,7 @@ void DistributedDeviceProfileServiceNew::ClearProfileCache() } int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfileInited(int32_t saId, - sptr dpInitedCallback) + const sptr & dpInitedCallback) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -1237,7 +1256,7 @@ int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfileInited(int32 } int32_t DistributedDeviceProfileServiceNew::SubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType, sptr pinCodeCallback) + int32_t pinExchangeType, const sptr& pinCodeCallback) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -1328,7 +1347,7 @@ int32_t DistributedDeviceProfileServiceNew::NotifyPinCodeInvalid(const LocalServ return DP_SUCCESS; } -int32_t DistributedDeviceProfileServiceNew::PutAllTrustedDevices(const std::vector deviceInfos) +int32_t DistributedDeviceProfileServiceNew::PutAllTrustedDevices(const std::vector& deviceInfos) { if (!PermissionManager::GetInstance().IsCallerTrust(PUT_ALL_TRUSTED_DEVICES)) { HILOGE("this caller is permission denied!"); diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp deleted file mode 100644 index eb60f577c773a58bb7e353c7255dd635e26b3585..0000000000000000000000000000000000000000 --- a/services/core/src/distributed_device_profile_stub_new.cpp +++ /dev/null @@ -1,1159 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "distributed_device_profile_stub_new.h" - -#include - -#include "ipc_skeleton.h" -#include "ipc_utils.h" - -#include "distributed_device_profile_enums.h" -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_log.h" -#include "distributed_device_profile_service_new.h" -#include "profile_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { -const std::string TAG = "DistributedDeviceProfileStubNew"; -} - -DistributedDeviceProfileStubNew::DistributedDeviceProfileStubNew() -{ - InitAclAndSubscribe(); -} - -void DistributedDeviceProfileStubNew::InitAclAndSubscribe() -{ - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_DEVICE_PROFILES)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UPDATE_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID)); -} - -DistributedDeviceProfileStubNew::~DistributedDeviceProfileStubNew() -{ - HILOGI("destructor!"); -} - -bool DistributedDeviceProfileStubNew::IsInterfaceTokenValid(MessageParcel& data) -{ - return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor(); -} - - -int32_t DistributedDeviceProfileStubNew::NotifyAclEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_ACL_PROFILE): - return PutAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE): - return UpdateAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE): - return GetTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE): - return GetAllTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ACL_PROFILE): - return GetAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE): - return GetAllAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL): - return GetAllAclIncludeLnnAclInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_ACL_PROFILE): - return DeleteAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SESSION_KEY): - return PutSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SESSION_KEY): - return GetSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SESSION_KEY): - return UpdateSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SESSION_KEY): - return DeleteSessionKeyInner(data, reply); - default: - return NotifyProfileDataEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyProfileDataEventInner( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - switch (code) { - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE): - return SubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE): - return UnSubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS): - return SendSubscribeInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE): - return PutServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH): - return PutServiceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE): - return PutCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH): - return PutCharacteristicProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED): - return SubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED): - return UnSubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES): - return PutAllTrustedDevicesInner(data, reply); - case static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH): - return PutDeviceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILES): - return GetDeviceProfilesInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS): - return GetDeviceIconInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH): - return PutDeviceIconInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH): - return PutProductInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH): - return DeleteDeviceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID): - return SubscribePinCodeInvalidInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID): - return UnSubscribePinCodeInvalidInner(data, reply); - default: - HILOGE("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW): - return GetDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_PROFILE): - return GetServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_CHAR_PROFILE): - return GetCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE): - return DeleteServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_CHAR_PROFILE): - return DeleteCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW): - return SyncDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE): - return PutServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE): - return DeleteServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE): - return UpdateServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY): - return GetServiceInfoProfileByUniqueKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID): - return GetServiceInfoProfileListByTokenIdInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST): - return GetAllServiceInfoProfileListInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME): - return GetServiceInfoProfileListByBundleNameInner(data, reply); - default: - return NotifyLocalServiceEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO): - return PutLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO): - return UpdateLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE): - 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); - } -} - -int32_t DistributedDeviceProfileStubNew::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid()); - if (DistributedDeviceProfileServiceNew::GetInstance().IsStopped()) { - HILOGE("dp service has stopped"); - return DP_SERVICE_STOPPED; - } - bool exitIdleStateResult = DistributedDeviceProfileServiceNew::GetInstance().ExitIdleState(); - if (!exitIdleStateResult) { - HILOGE("CancelIdle failed, ExitIdleState = %{public}d", exitIdleStateResult); - return DP_SERVICE_ON_IDLE; - } - DistributedDeviceProfileServiceNew::GetInstance().AddRunningIpcCount(); - DelayUnloadTask(); - if (!IsInterfaceTokenValid(data)) { - HILOGE("check interface token failed"); - DistributedDeviceProfileServiceNew::GetInstance().SubtractRunningIpcCount(); - return DP_INTERFACE_CHECK_FAILED; - } - if (aclAndSubscribeFuncs_.find(code) != aclAndSubscribeFuncs_.end()) { - int32_t aclRet = NotifyAclEventInner(code, data, reply, option); - DistributedDeviceProfileServiceNew::GetInstance().SubtractRunningIpcCount(); - return aclRet; - } - if (!IsInited()) { - HILOGE("DP not finish init"); - DistributedDeviceProfileServiceNew::GetInstance().SubtractRunningIpcCount(); - return DP_LOAD_SERVICE_ERR; - } - int32_t ret = NotifyEventInner(code, data, reply, option); - DistributedDeviceProfileServiceNew::GetInstance().SubtractRunningIpcCount(); - return ret; -} - -int32_t DistributedDeviceProfileStubNew::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGD("called"); - std::string deviceId; - READ_HELPER(data, String, deviceId); - TrustDeviceProfile trustDeviceProfile; - int32_t ret = GetTrustDeviceProfile(deviceId, trustDeviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!trustDeviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector trustDeviceProfiles; - int32_t ret = GetAllTrustDeviceProfile(trustDeviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::map queryParams; - if (!IpcUtils::UnMarshalling(data, queryParams)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - std::vector accessControlProfiles; - int32_t ret = GetAccessControlProfile(queryParams, accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector accessControlProfiles; - int32_t ret = GetAllAccessControlProfile(accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllAclIncludeLnnAclInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector accessControlProfiles; - int32_t ret = GetAllAclIncludeLnnAcl(accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - int32_t accessControlId; - READ_HELPER(data, Int32, accessControlId); - int32_t ret = DeleteAccessControlProfile(accessControlId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - sessionKey.clear(); - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = PutSessionKey(userId, sessionKey, sessionKeyId); - if (!reply.WriteInt32(ret)) { - sessionKey.clear(); - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - WRITE_HELPER(reply, Int32, sessionKeyId); - sessionKey.clear(); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - std::vector sessionKey; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = GetSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - sessionKey.clear(); - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - if (!IpcUtils::Marshalling(reply, sessionKey)) { - sessionKey.clear(); - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - sessionKey.clear(); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - sessionKey.clear(); - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = UpdateSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - sessionKey.clear(); - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - sessionKey.clear(); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = DeleteSessionKey(userId, sessionKeyId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceProfile serviceProfile; - if (!serviceProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceProfile(serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector serviceProfiles; - if (!IpcUtils::UnMarshalling(data, serviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceProfileBatch(serviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - CharacteristicProfile charProfile; - if (!charProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutCharacteristicProfile(charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector charProfiles; - if (!IpcUtils::UnMarshalling(data, charProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutCharacteristicProfileBatch(charProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - DeviceProfile deviceProfile; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - deviceProfile.SetIsMultiUser(isMultiUser); - deviceProfile.SetUserId(userId); - int32_t ret = GetDeviceProfile(deviceId, deviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!deviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - ServiceProfile serviceProfile; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - serviceProfile.SetIsMultiUser(isMultiUser); - serviceProfile.SetUserId(userId); - int32_t ret = GetServiceProfile(deviceId, serviceName, serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - CharacteristicProfile charProfile; - charProfile.SetIsMultiUser(isMultiUser); - charProfile.SetUserId(userId); - int32_t ret = GetCharacteristicProfile(deviceId, serviceName, characteristicKey, charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!charProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DeleteServiceProfile(deviceId, serviceName, isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey, isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = SubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UnSubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - DistributedDeviceProfile::DpSyncOptions syncOptions; - if (!syncOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - sptr syncCompletedCallback = data.ReadRemoteObject(); - int32_t ret = SyncDeviceProfile(syncOptions, syncCompletedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply) -{ - std::map listenerMap; - if (!IpcUtils::UnMarshalling(data, listenerMap)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = SendSubscribeInfos(listenerMap); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - sptr dpInitedCallback = data.ReadRemoteObject(); - if (dpInitedCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SubscribeDeviceProfileInited(saId, dpInitedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - int32_t ret = UnSubscribeDeviceProfileInited(saId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceInfos; - if (!IpcUtils::UnMarshalling(data, deviceInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutAllTrustedDevices(deviceInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, - MessageParcel& reply) -{ - LocalServiceInfo localServiceInfo; - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = GetLocalServiceInfoByBundleAndPinType(bundleName, pinExchangeType, localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!localServiceInfo.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = DeleteLocalServiceInfo(bundleName, pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceProfileFilterOptions options; - std::vector deviceProfiles; - if (!options.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetDeviceProfiles(options, deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - sptr pincodeInvalidCallback = data.ReadRemoteObject(); - if (pincodeInvalidCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SubscribePinCodeInvalid(bundleName, - pinExchangeType, pincodeInvalidCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = UnSubscribePinCodeInvalid(bundleName, - pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector productInfos; - if (!IpcUtils::UnMarshalling(data, productInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutProductInfoBatch(productInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceIconInfos; - if (!IpcUtils::UnMarshalling(data, deviceIconInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutDeviceIconInfoBatch(deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceIconInfoFilterOptions filterOptions; - std::vector deviceIconInfos; - if (!filterOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetDeviceIconInfos(filterOptions, - deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceIconInfos)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoUniqueKey key; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DeleteServiceInfoProfile(key); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - ServiceInfoProfile serviceInfoProfile; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileByUniqueKey(key, - serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceInfoProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileListByTokenId(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllServiceInfoProfileListInner(MessageParcel& data, - MessageParcel& reply) -{ - std::vector serviceInfoProfiles; - int32_t ret = GetAllServiceInfoProfileList(serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileListByBundleName(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DeleteDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - 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/src/profiledatamanager/profile_data_manager.cpp b/services/core/src/profiledatamanager/profile_data_manager.cpp index a52ccab6ab986885282e5713bb8f229fa30b94d1..61662338167cb640e7085dd4e52cc8792bcb8e8c 100644 --- a/services/core/src/profiledatamanager/profile_data_manager.cpp +++ b/services/core/src/profiledatamanager/profile_data_manager.cpp @@ -67,7 +67,7 @@ int32_t ProfileDataManager::UnInit() } return 0; } - + int32_t ProfileDataManager::PutDeviceProfile(DeviceProfile deviceProfile) { if (deviceProfile.GetDeviceId().empty() || ProfileDataManager::FilterInvaildSymbol(deviceProfile.GetDeviceId())) { @@ -107,7 +107,7 @@ int32_t ProfileDataManager::PutDeviceProfile(DeviceProfile deviceProfile) return DP_SUCCESS; } -int32_t ProfileDataManager::DeleteDeviceProfileBatch(std::vector& deviceProfiles) +int32_t ProfileDataManager::DeleteDeviceProfileBatch(const std::vector& deviceProfiles) { HILOGI("deviceProfiles.size:%{public}zu", deviceProfiles.size()); if (deviceProfiles.empty()) { @@ -156,7 +156,7 @@ bool ProfileDataManager::FilterInvaildSymbol(std::string str) return true; } -int32_t ProfileDataManager::PutDeviceProfileBatch(std::vector& deviceProfiles) +int32_t ProfileDataManager::PutDeviceProfileBatch(const std::vector& deviceProfiles) { if (deviceProfiles.empty()) { HILOGE("deviceProfiles is empty"); diff --git a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp index 06cebceb1520c2029b1969af382304e3e10060a8..02a2298a1f97ca3fc4005de0064e3eeafed16522 100644 --- a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp +++ b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License") * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -59,7 +59,7 @@ int32_t SubscribeProfileManager::UnInit() HILOGI("call!"); { std::lock_guard lockGuard(subscribeMutex_); - subscribeInfoMap_.clear(); + subscribeInfoExtensionMap_.clear(); } { std::lock_guard lockGuard(funcsMutex_); @@ -199,32 +199,32 @@ int32_t SubscribeProfileManager::NotifyTrustDeviceProfileInactive(const TrustDev return DP_SUCCESS; } -int32_t SubscribeProfileManager::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) +int32_t SubscribeProfileManager::SubscribeDeviceProfile(const SubscribeInfoExt& subscribeInfo) { HILOGI("saId: %{public}d!, subscribeKey: %{public}s", subscribeInfo.GetSaId(), ProfileUtils::GetDbKeyAnonyString(subscribeInfo.GetSubscribeKey()).c_str()); { std::lock_guard lock(subscribeMutex_); - if (subscribeInfoMap_.size() > MAX_LISTENER_SIZE) { - HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", subscribeInfoMap_.size()); + if (subscribeInfoExtensionMap_.size() > MAX_LISTENER_SIZE) { + HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", subscribeInfoExtensionMap_.size()); return DP_EXCEED_MAX_SIZE_FAIL; } - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].size() > MAX_LISTENER_SIZE) { + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].size() > MAX_LISTENER_SIZE) { HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].size()); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].size()); return DP_EXCEED_MAX_SIZE_FAIL; } - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].find(subscribeInfo) != - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].end()) { + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].find(subscribeInfo) != + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].end()) { HILOGI("this sa subscribeInfo is exist, saId : %{public}d", subscribeInfo.GetSaId()); - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); } - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].emplace(subscribeInfo); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].emplace(subscribeInfo); } return DP_SUCCESS; } -int32_t SubscribeProfileManager::SubscribeDeviceProfile(std::map subscribeInfos) +int32_t SubscribeProfileManager::SubscribeDeviceProfile(const std::map subscribeInfos) { HILOGD("call!"); for (auto item : subscribeInfos) { @@ -233,16 +233,16 @@ int32_t SubscribeProfileManager::SubscribeDeviceProfile(std::map lock(subscribeMutex_); - if (subscribeInfoMap_.find(subscribeInfo.GetSubscribeKey()) != subscribeInfoMap_.end()) { - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].empty()) { - subscribeInfoMap_.erase(subscribeInfo.GetSubscribeKey()); + if (subscribeInfoExtensionMap_.find(subscribeInfo.GetSubscribeKey()) != subscribeInfoExtensionMap_.end()) { + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].empty()) { + subscribeInfoExtensionMap_.erase(subscribeInfo.GetSubscribeKey()); } } } @@ -514,16 +514,17 @@ int32_t SubscribeProfileManager::NotifyCharProfileDelete(const std::string& dbKe } return DP_SUCCESS; } -std::unordered_set SubscribeProfileManager::GetSubscribeInfos( - const std::string& dbKey) + +std::unordered_set SubscribeProfileManager::GetSubscribeInfos + (const std::string& dbKey) { { std::lock_guard lock(subscribeMutex_); - if (subscribeInfoMap_.find(dbKey) == subscribeInfoMap_.end()) { + if (subscribeInfoExtensionMap_.find(dbKey) == subscribeInfoExtensionMap_.end()) { HILOGD("This dbKey is not subscribed, dbKey: %{public}s", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str()); return {}; } - return subscribeInfoMap_[dbKey]; + return subscribeInfoExtensionMap_[dbKey]; } } diff --git a/services/core/test/BUILD.gn b/services/core/test/BUILD.gn index 85de0735cba6e504a68b6f4d75062fa79cb37d5f..a2dfb8937a5a87aac13b3e191edd89852d879ba4 100644 --- a/services/core/test/BUILD.gn +++ b/services/core/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. +# Copyright (c) 2023-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -324,20 +324,6 @@ ohos_unittest("dp_dm_adapter_test") { subsystem_name = "deviceprofile" } -ohos_unittest("distributed_device_profile_stub_new_test") { - module_out_path = module_output_path - sources = [ "unittest/distributed_device_profile_stub_new_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] -} - ohos_unittest("content_sensor_manager_utils_test") { module_out_path = module_output_path sources = [ "unittest/content_sensor_manager_utils_test.cpp" ] @@ -524,7 +510,6 @@ group("unittest") { ":device_profile_locd_callback_test", ":device_profile_manager_new_test", ":distributed_device_profile_client_kv_new_test", - ":distributed_device_profile_stub_new_test", ":dp_account_common_event_test", ":dp_content_sensor_test", ":dp_dm_adapter_test", diff --git a/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp b/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp index 56b9834367d01eeb2acfb38d27b8eb39521a9391..2b31cdd9d42b0fee3eca2fb1bb82b3aaa8fd4466 100644 --- a/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp +++ b/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.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 @@ -101,7 +101,6 @@ void FuzzDeviceProfile(const uint8_t* rawData, size_t size) code += MIN_INTERFACE_CODE; } DistributedDeviceProfileServiceNew::GetInstance().OnRemoteRequest(code, data, reply, option); - DistributedDeviceProfileServiceNew::GetInstance().NotifyEventInner(code, data, reply, option); } } } 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 b9d4dcc3e434df93a8fd230cf455fe281dd4f793..c690b1b2804b65919ad229a7601dfe78fd53e605 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 @@ -199,7 +199,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutServiceProfile001, TestSize.Le HWTEST_F(DistributedDeviceProfileClientKvTest, PutServiceProfileBatch001, TestSize.Level1) { vector serviceProfiles; - + ServiceProfile serviceProfile1; serviceProfile1.SetDeviceId("deviceId1"); serviceProfile1.SetServiceName("serviceName1"); @@ -210,7 +210,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutServiceProfileBatch001, TestSi serviceProfile2.SetServiceType("serviceType2"); serviceProfiles.push_back(serviceProfile1); serviceProfiles.push_back(serviceProfile2); - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().PutServiceProfileBatch(serviceProfiles); EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } @@ -224,7 +224,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutServiceProfileBatch001, TestSi HWTEST_F(DistributedDeviceProfileClientKvTest, PutServiceProfileBatch002, TestSize.Level1) { vector serviceProfiles; - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().PutServiceProfileBatch(serviceProfiles); EXPECT_EQ(errCode, DP_INVALID_PARAMS); } @@ -242,7 +242,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutCharacteristicProfile001, Test charProfile.SetServiceName("serviceName"); charProfile.SetCharacteristicKey("characteristicKey"); charProfile.SetCharacteristicValue("characteristicValue"); - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().PutCharacteristicProfile(charProfile); EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } @@ -256,7 +256,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutCharacteristicProfile001, Test HWTEST_F(DistributedDeviceProfileClientKvTest, PutCharacteristicProfileBatch001, TestSize.Level1) { vector charProfiles; - + CharacteristicProfile charProfile1; charProfile1.SetDeviceId("deviceId1"); charProfile1.SetServiceName("serviceName1"); @@ -283,7 +283,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutCharacteristicProfileBatch001, HWTEST_F(DistributedDeviceProfileClientKvTest, PutCharacteristicProfileBatch002, TestSize.Level1) { vector charProfiles; - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().PutCharacteristicProfileBatch(charProfiles); EXPECT_EQ(errCode, DP_INVALID_PARAMS); } @@ -298,7 +298,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, GetDeviceProfile001, TestSize.Lev { string deviceId = "deviceId"; DeviceProfile deviceProfile; - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, deviceProfile); EXPECT_NE(errCode, DP_SUCCESS); @@ -335,7 +335,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, GetServiceProfile001, TestSize.Le string deviceId = "deviceId"; string serviceName = "serviceName"; ServiceProfile serviceProfile; - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().GetServiceProfile( deviceId, serviceName, serviceProfile); EXPECT_NE(errCode, DP_SUCCESS); @@ -353,7 +353,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, GetCharacteristicProfile001, Test string serviceName = "serviceName"; string characteristicKey = "characteristicKey"; CharacteristicProfile characteristicProfile; - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile( deviceId, serviceName, characteristicKey, characteristicProfile); EXPECT_NE(errCode, DP_SUCCESS); @@ -407,7 +407,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, SubscribeDeviceProfile001, TestSi OHOS::sptr subscribeDPChangeListener = OHOS::sptr(new SubscribeDPChangeListener); SubscribeInfo subscribeInfo(saId, subscribeKey, subscribeTypes, subscribeDPChangeListener); - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeDeviceProfile(subscribeInfo); EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } @@ -430,7 +430,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, UnSubscribeDeviceProfile001, Test OHOS::sptr subscribeDPChangeListener = OHOS::sptr(new SubscribeDPChangeListener); SubscribeInfo subscribeInfo(saId, subscribeKey, subscribeTypes, subscribeDPChangeListener); - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnSubscribeDeviceProfile(subscribeInfo); EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } @@ -445,11 +445,11 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, SyncDeviceProfile001, TestSize.Le { DistributedDeviceProfile::DpSyncOptions syncOptions; OHOS::sptr syncCb = nullptr; - + syncOptions.AddDevice("deviceId1"); syncOptions.AddDevice("deviceId2"); syncOptions.SetSyncMode(SyncMode::MIN); - + int32_t errCode = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOptions, syncCb); EXPECT_EQ(errCode, DP_SYNC_DEVICE_FAIL); } @@ -649,7 +649,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, PutDeviceProfileBatch_001, TestSi { std::vector deviceProfiles; int32_t errCode = DistributedDeviceProfileClient::GetInstance().PutDeviceProfileBatch(deviceProfiles); - EXPECT_EQ(errCode, DP_WRITE_PARCEL_FAIL); + EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } /** @@ -676,7 +676,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, DeleteDeviceProfileBatch_001, Tes { std::vector deviceProfiles; int32_t errCode = DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfileBatch(deviceProfiles); - EXPECT_EQ(errCode, DP_WRITE_PARCEL_FAIL); + EXPECT_EQ(errCode, DP_PERMISSION_DENIED); } /** @@ -703,7 +703,7 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, GetDeviceIconInfos_001, TestSize. DeviceIconInfoFilterOptions filterOptions; std::vector deviceIconInfos; int32_t errCode = DistributedDeviceProfileClient::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos); - EXPECT_EQ(errCode, DP_PERMISSION_DENIED); + EXPECT_EQ(errCode, ERR_INVALID_DATA); } /** diff --git a/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp b/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp index 8fe8e11bb551d9cd9691f6dffa7410acc6f168a4..86501e44d9364363a339687918652524b73fd6e6 100644 --- a/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -117,7 +117,7 @@ void DistributedDeviceProfileClientRdbTest::SetUpTestCase() std::string subscribekey = "trust_device_profile"; std::unordered_set subscribeTypes = {ProfileChangeType::TRUST_DEVICE_PROFILE_ADD, ProfileChangeType::TRUST_DEVICE_PROFILE_UPDATE, ProfileChangeType::TRUST_DEVICE_PROFILE_DELETE}; - + OHOS::sptr subscribeDPChangeListener = OHOS::sptr(new SubscribeDPChangeListener); SubscribeInfo subscribeInfo(saId, subscribekey, subscribeTypes, subscribeDPChangeListener); @@ -196,7 +196,7 @@ HWTEST_F(DistributedDeviceProfileClientRdbTest, PutAccessControlProfile_001, Tes value.Clear(); ProfileUtils::AccesseeToEntries(profile, value); ProfileUtils::EntriesToAccessee(value, accessee); - EXPECT_EQ(ret, DP_PERMISSION_DENIED); + EXPECT_EQ(ret, ERR_INVALID_DATA); } /* 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 deleted file mode 100644 index 7bd48b7328c6b1f45e5f6fb843792d7a6d45a3d6..0000000000000000000000000000000000000000 --- a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp +++ /dev/null @@ -1,1240 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -#include "profile_utils.h" -#include "distributed_device_profile_constants.h" -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_log.h" -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_enums.h" -#include "distributed_device_profile_service_new.h" -#include "distributed_device_profile_stub_new.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -using namespace testing::ext; -using namespace std; - -class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubNew { - int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; - int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) override; - int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; - int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; - int32_t DeleteAccessControlProfile(int32_t accessControlId) override; - int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) override; - int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) override; - int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) override; - int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) override; - int32_t PutServiceProfile(const ServiceProfile& serviceProfile) override; - int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) override; - int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) override; - int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) override; - int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) override; - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) override; - int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMultiUser = false, - int32_t userId = DEFAULT_USER_ID) override; - int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; - int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; - int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; - int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; - int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) override; - int32_t SendSubscribeInfos(std::map listenerMap) override; - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) override; - int32_t PutProductInfoBatch(const std::vector& productInfos) override; - int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; - int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) override; - int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; - int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; - int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - 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; -}; - -class DistributedDeviceProfileStubNewTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr ProfileStub_ = nullptr; -}; - -void DistributedDeviceProfileStubNewTest::SetUpTestCase(void) -{ -} - -void DistributedDeviceProfileStubNewTest::TearDownTestCase(void) -{ -} - -void DistributedDeviceProfileStubNewTest::SetUp() -{ - ProfileStub_ = std::make_shared(); -} - -void DistributedDeviceProfileStubNewTest::TearDown() -{ - ProfileStub_ = nullptr; -} - -int32_t MockDistributedDeviceProfileStubNew::PutAccessControlProfile(const AccessControlProfile& aclProfile) -{ - (void)aclProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateAccessControlProfile(const AccessControlProfile& aclProfile) -{ - (void)aclProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetTrustDeviceProfile(const std::string& deviceId, - TrustDeviceProfile& trustDeviceProfile) -{ - (void)deviceId; - (void)trustDeviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllTrustDeviceProfile( - std::vector& trustDeviceProfiles) -{ - (void)trustDeviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::DeleteDeviceProfileBatch(std::vector& deviceProfiles) -{ - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) -{ - (void)queryParams; - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllAccessControlProfile( - std::vector& accessControlProfiles) -{ - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllAclIncludeLnnAcl( - std::vector& accessControlProfiles) -{ - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteAccessControlProfile(int32_t accessControlId) -{ - (void)accessControlId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutSessionKey( - uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetSessionKey( - uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateSessionKey( - uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) -{ - (void)userId; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutServiceProfile(const ServiceProfile& serviceProfile) -{ - (void)serviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutServiceProfileBatch(const std::vector& serviceProfiles) -{ - (void)serviceProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutCharacteristicProfile(const CharacteristicProfile& charProfile) -{ - (void)charProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutCharacteristicProfileBatch( - const std::vector& charProfiles) -{ - (void)charProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetDeviceProfile(const std::string& deviceId, - DeviceProfile& deviceProfile) -{ - (void)deviceId; - (void)deviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetServiceProfile(const std::string& deviceId, - const std::string& serviceName, ServiceProfile& serviceProfile) -{ - (void)deviceId; - (void)serviceName; - (void)serviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) -{ - (void)deviceId; - (void)serviceName; - (void)characteristicId; - (void)charProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName, bool isMultiUser, int32_t userId) -{ - (void)deviceId; - (void)serviceName; - (void)isMultiUser; - (void)userId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId) -{ - (void)deviceId; - (void)serviceName; - (void)characteristicId; - (void)isMultiUser; - (void)userId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - (void)subscribeInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - (void)subscribeInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SubscribeDeviceProfileInited(int32_t saId, - sptr dpInitedCallback) -{ - (void)saId; - (void)dpInitedCallback; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInited(int32_t saId) -{ - (void)saId; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::SubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType, sptr pinCodeCallback) -{ - (void)bundleName; - (void)pinExchangeType; - (void)pinCodeCallback; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::UnSubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType) -{ - (void)bundleName; - (void)pinExchangeType; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutAllTrustedDevices(const std::vector deviceInfos) -{ - (void)deviceInfos; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SyncDeviceProfile( - const DistributedDeviceProfile::DpSyncOptions& syncOptions, sptr syncCompletedCallback) -{ - (void)syncOptions; - (void)syncCompletedCallback; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SendSubscribeInfos(std::map listenerMap) -{ - (void)listenerMap; - return 0; -} -void MockDistributedDeviceProfileStubNew::DelayUnloadTask() -{ - return; -} -bool MockDistributedDeviceProfileStubNew::IsInited() -{ - return true; -} - -int32_t MockDistributedDeviceProfileStubNew::GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) -{ - (void)options; - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutDeviceProfileBatch(std::vector& deviceProfiles) -{ - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutProductInfoBatch(const std::vector& productInfos) -{ - (void)productInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) -{ - (void)deviceIconInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) -{ - (void)filterOptions; - (void)deviceIconInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) -{ - (void)key; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) -{ - (void)key; - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - (void)key; - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllServiceInfoProfileList( - std::vector& serviceInfoProfiles) -{ - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - (void)key; - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) -{ - (void)bundleName; - (void)pinExchangeType; - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteLocalServiceInfo(const std::string& bundleName, - int32_t pinExchangeType) -{ - (void)bundleName; - (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 - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, IsInterfaceTokenValid_001, TestSize.Level1) -{ - std::shared_ptr devProStubNew = - std::make_shared(); - - MessageParcel data; - bool ret = ProfileStub_->IsInterfaceTokenValid(data); - EXPECT_EQ(false, ret); -} - -/** - * @tc.name: OnRemoteRequest001 - * @tc.desc: OnRemoteRequest - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, OnRemoteRequest_001, TestSize.Level1) -{ - uint32_t code = static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ADD); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(DP_INTERFACE_CHECK_FAILED, ret); -} - -/** - * @tc.name: OnRemoteRequest002 - * @tc.desc: OnRemoteRequest - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, OnRemoteRequest_002, TestSize.Level1) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(DP_INTERFACE_CHECK_FAILED, ret); -} - -/** - * @tc.name: OnRemoteRequest003 - * @tc.desc: OnRemoteRequest - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, OnRemoteRequest_003, TestSize.Level1) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - DistributedDeviceProfileServiceNew::GetInstance().isStopped_ = true; - int32_t ret = ProfileStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(DP_SERVICE_STOPPED, ret); -} - -/** - * @tc.name: PutAccessControlProfileInner001 - * @tc.desc: PutAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: UpdateAccessControlProfileInner001 - * @tc.desc: UpdateAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, UpdateAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->UpdateAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetTrustDeviceProfileInner001 - * @tc.desc: GetTrustDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetTrustDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetTrustDeviceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetAllTrustDeviceProfileInner001 - * @tc.desc: GetAllTrustDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAllTrustDeviceProfileInner_001, TestSize.Level1) -{ - std::string udid = "udid"; - std::string serviceId = "serviceId"; - MessageParcel data; - MessageParcel reply; - data.WriteString(udid); - data.WriteString(serviceId); - int32_t ret = ProfileStub_->GetAllTrustDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetAccessControlProfileInner001 - * @tc.desc: GetAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetAllAccessControlProfileInner001 - * @tc.desc: GetAllAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAllAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetAllAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_WRITE_PARCEL_FAIL, ret); -} - -/** - * @tc.name: DeleteAccessControlProfileInner001 - * @tc.desc: DeleteAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteAccessControlProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: PutServiceProfileInner001 - * @tc.desc: PutServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutServiceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: PutServiceProfileBatchInner001 - * @tc.desc: PutServiceProfileBatchInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutServiceProfileBatchInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutServiceProfileBatchInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: PutCharacteristicProfileBatchInner001 - * @tc.desc: PutCharacteristicProfileBatchInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutCharacteristicProfileBatchInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutCharacteristicProfileBatchInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetDeviceProfileInner001 - * @tc.desc: GetDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetDeviceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetServiceProfileInner001 - * @tc.desc: GetServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetCharacteristicProfileInner001 - * @tc.desc: GetCharacteristicProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetCharacteristicProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetCharacteristicProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: DeleteServiceProfileInner001 - * @tc.desc: DeleteServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: DeleteCharacteristicProfileInner001 - * @tc.desc: DeleteCharacteristicProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteCharacteristicProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: SubscribeDeviceProfileInner001 - * @tc.desc: SubscribeDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SubscribeDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SubscribeDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: UnSubscribeDeviceProfileInner001 - * @tc.desc: UnSubscribeDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, UnSubscribeDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->UnSubscribeDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: SyncDeviceProfileInner001 - * @tc.desc: SyncDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SyncDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SyncDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: SendSubscribeInfosInner001 - * @tc.desc: SendSubscribeInfosInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SendSubscribeInfosInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SendSubscribeInfosInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_001 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_001, TestSize.Level0) -{ - uint32_t code = 1000; - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(305, ret); -} - -/** - * @tc.name: NotifyAclEventInner_002 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_002, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_003 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_003, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_004 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_004, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyAclEventInner_005 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_005, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_006 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_006, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_007 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_007, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_WRITE_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_008 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_008, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DELETE_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyAclEventInner_009 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_009, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_010 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_010, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_011 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_011, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_012 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_012, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_013 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_013, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_014 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_014, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_015 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_015, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyEventInner_001 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_001, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_002 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_002, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_003 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_003, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_004 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_004, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_005 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_005, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DEL_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_006 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_006, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyEventInner_007 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_007, TestSize.Level0) -{ - uint32_t code = 1000; - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(305, ret); -} - -/** - * @tc.name: PutAllTrustedDevicesInner001 - * @tc.desc: PutAllTrustedDevicesInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutAllTrustedDevicesInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - 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 diff --git a/services/core/test/unittest/dp_profile_service_test.cpp b/services/core/test/unittest/dp_profile_service_test.cpp index 383dc451dd19ff0fa72d7174107eaae1367953af..4428ea9b4f8c9a66013073a5a0c672d9ebccb738 100644 --- a/services/core/test/unittest/dp_profile_service_test.cpp +++ b/services/core/test/unittest/dp_profile_service_test.cpp @@ -116,14 +116,14 @@ HWTEST_F(DpProfileServiceTest, CreateUnloadHandler_001, TestSize.Level1) DistributedDeviceProfileServiceNew::GetInstance().unloadHandler_ = nullptr; int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().CreateUnloadHandler(); EXPECT_EQ(DP_SUCCESS, ret); - + ret = DistributedDeviceProfileServiceNew::GetInstance().DestroyUnloadHandler(); EXPECT_EQ(DP_SUCCESS, ret); - + EventHandlerFactory::GetInstance().Init(); ret = DistributedDeviceProfileServiceNew::GetInstance().CreateUnloadHandler(); EXPECT_EQ(DP_SUCCESS, ret); - + ret = DistributedDeviceProfileServiceNew::GetInstance().DestroyUnloadHandler(); EXPECT_EQ(DP_SUCCESS, ret); } @@ -435,14 +435,16 @@ HWTEST_F(DpProfileServiceTest, DeleteLocalServiceInfo_001, TestSize.Level1) HWTEST_F(DpProfileServiceTest, SubscribeDeviceProfile_001, TestSize.Level1) { SubscribeInfo subscriberInfo; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfile(subscriberInfo); + sptr listener = nullptr; + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfile(subscriberInfo, listener); EXPECT_EQ(DP_PERMISSION_DENIED, ret); } HWTEST_F(DpProfileServiceTest, UnSubscribeDeviceProfile_001, TestSize.Level1) { SubscribeInfo subscriberInfo; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfile(subscriberInfo); + sptr listener = nullptr; + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfile(subscriberInfo, listener); EXPECT_EQ(DP_PERMISSION_DENIED, ret); }