From 7c7463e1a2c83c5419abd20809cc9115e2f8738e Mon Sep 17 00:00:00 2001 From: zhanglei Date: Sat, 16 Nov 2024 11:12:37 +0800 Subject: [PATCH] add Signed-off-by: zhanglei --- common/BUILD.gn | 1 + .../distributed_device_profile_constants.h | 12 +- .../distributed_device_profile_enums.h | 8 +- .../interfaces/i_profile_change_listener.h | 4 +- .../profile_change_listener_proxy.h | 4 +- .../interfaces/profile_change_listener_stub.h | 6 +- .../include/interfaces/trust_device_profile.h | 8 +- common/include/utils/profile_utils.h | 12 + .../distributed_device_profile_constants.cpp | 16 +- common/src/interfaces/dp_subscribe_info.cpp | 2 + .../interfaces/i_profile_change_listener.cpp | 37 + .../profile_change_listener_proxy.cpp | 32 +- .../profile_change_listener_stub.cpp | 52 ++ .../src/interfaces/trust_device_profile.cpp | 15 + common/src/utils/profile_utils.cpp | 178 +++++ .../subscribe_profile_manager.h | 4 +- .../trust_profile_manager.h | 29 +- .../subscribe_profile_manager.cpp | 40 ++ .../trust_profile_manager.cpp | 654 +++++++++--------- .../test/unittest/dp_subscribe_info_test.cpp | 36 +- .../unittest/trust_profile_manager_test.cpp | 68 +- 21 files changed, 839 insertions(+), 379 deletions(-) create mode 100644 common/src/interfaces/i_profile_change_listener.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index a225edd3..b4bab637 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/dp_inited_callback_stub.cpp", "src/interfaces/dp_subscribe_info.cpp", "src/interfaces/dp_sync_options.cpp", + "src/interfaces/i_profile_change_listener.cpp", "src/interfaces/profile_change_listener_proxy.cpp", "src/interfaces/profile_change_listener_stub.cpp", "src/interfaces/service_profile.cpp", diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index e7ee9df0..b47a06cd 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -53,6 +53,7 @@ extern const std::string CHARACTERISTIC_VALUE; extern const std::string SUBSCRIBE_TRUST_DEVICE_PROFILE; extern const std::string DEVICE_ID_TYPE; extern const std::string DEVICE_ID_HASH; +extern const std::string PEER_USER_ID; /* AccessControlProfile Attribute */ extern const std::string ACCESS_CONTROL_ID; extern const std::string ACCESSER_ID; @@ -127,7 +128,7 @@ constexpr int32_t MAX_DUMP_ARGS_SIZE = 1000; constexpr int32_t MAX_LISTENER_SIZE = 100; constexpr int32_t MAX_EVENT_HANDLER_SIZE = 50; constexpr int32_t MAX_DB_RECORD_SIZE = 10000; -constexpr int32_t MAX_SUBSCRIBE_CHANGE_SIZE = 3; +constexpr int32_t MAX_SUBSCRIBE_CHANGE_SIZE = 6; constexpr int32_t MAX_INTERFACE_SIZE = 20; constexpr int32_t MAX_SUBSCRIBE_INFO_SIZE = 500; constexpr int32_t MAX_SYNC_RESULTS_SIZE = 50; @@ -175,6 +176,8 @@ constexpr int32_t ROWCOUNT_INIT = -1; constexpr int32_t CHANGEROWCNT_INIT = -1; constexpr int32_t COLUMNINDEX_INIT = -1; constexpr int32_t STATUS_INIT = 0; +constexpr int32_t STATUS_ACTIVE = 1; +constexpr int32_t STATUS_INACTIVE = 0; constexpr int32_t BINDTYPE_INIT = -1; constexpr int32_t BINDLEVEL_INIT = -1; constexpr int32_t DELETEROWS_INIT = -1; @@ -220,15 +223,20 @@ extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERUSER extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEUSERID; extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_ACCESSERTOKENID; extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_ACCESSEETOKENID; +extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_USERID; +extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_USERID; extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERDEVICEID; extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEDEVICEID; extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERBUNDLENAME; extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEBUNDLENAME; extern const std::string SELECT_ACCESSEE_TABLE; extern const std::string SELECT_ACCESSER_TABLE; -extern const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL; +extern const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL_EXCEPT_STATUS; extern const std::string SELECT_ACCESSER_TABLE_WHERE_ALL; extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ALL; +extern const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERDEVICEID_AND_ACCESSERUSERID; +extern const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEDEVICEID_AND_ACCESSEEUSERID; +extern const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID_AND_ACCESSEEID; /* SubscribeTrustInfoManager */ extern const std::string SUBSCRIBE_TRUST_INFO_TABLE; extern const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_SQL; diff --git a/common/include/interfaces/distributed_device_profile_enums.h b/common/include/interfaces/distributed_device_profile_enums.h index 5e454c4b..6560935b 100644 --- a/common/include/interfaces/distributed_device_profile_enums.h +++ b/common/include/interfaces/distributed_device_profile_enums.h @@ -58,7 +58,9 @@ enum class DPInterfaceCode : uint32_t { ON_DEVICE_PROFILE_INITED = 40, SUBSCRIBE_DEVICE_PROFILE_INITED = 41, UNSUBSCRIBE_DEVICE_PROFILE_INITED = 42, - MAX = 43 + ON_TRUST_DEVICE_PROFILE_ACTIVE = 43, + ON_TRUST_DEVICE_PROFILE_INACTIVE = 44, + MAX = 45 }; enum class DeviceIdType : uint32_t { @@ -136,7 +138,9 @@ enum ProfileChangeType { CHAR_PROFILE_ADD = 10, CHAR_PROFILE_UPDATE = 11, CHAR_PROFILE_DELETE = 12, - PROFILE_CHANGE_TYPE_MAX = 13 + TRUST_DEVICE_PROFILE_ACTIVE = 13, + TRUST_DEVICE_PROFILE_INACTIVE = 14, + PROFILE_CHANGE_TYPE_MAX = 15 }; enum StaticCapabilityFlag { CAPABILITY_FLAG_MIN = -1, diff --git a/common/include/interfaces/i_profile_change_listener.h b/common/include/interfaces/i_profile_change_listener.h index 2343dd9f..a6db922b 100644 --- a/common/include/interfaces/i_profile_change_listener.h +++ b/common/include/interfaces/i_profile_change_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,6 +33,8 @@ public: virtual int32_t OnTrustDeviceProfileDelete(const TrustDeviceProfile& profile) = 0; virtual int32_t OnTrustDeviceProfileUpdate(const TrustDeviceProfile& oldProfile, const TrustDeviceProfile& newProfile) = 0; + virtual int32_t OnTrustDeviceProfileActive(const TrustDeviceProfile& profile); + virtual int32_t OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile); virtual int32_t OnDeviceProfileAdd(const DeviceProfile& profile) = 0; virtual int32_t OnDeviceProfileDelete(const DeviceProfile& profile) = 0; virtual int32_t OnDeviceProfileUpdate(const DeviceProfile& oldProfile, const DeviceProfile& newProfile) = 0; diff --git a/common/include/interfaces/profile_change_listener_proxy.h b/common/include/interfaces/profile_change_listener_proxy.h index 11c3744c..0acfed48 100644 --- a/common/include/interfaces/profile_change_listener_proxy.h +++ b/common/include/interfaces/profile_change_listener_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,8 @@ public: int32_t OnTrustDeviceProfileDelete(const TrustDeviceProfile& profile) override; int32_t OnTrustDeviceProfileUpdate(const TrustDeviceProfile& oldProfile, const TrustDeviceProfile& newProfile) override; + int32_t OnTrustDeviceProfileActive(const TrustDeviceProfile& profile) override; + int32_t OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile) override; int32_t OnDeviceProfileAdd(const DeviceProfile& profile) override; int32_t OnDeviceProfileDelete(const DeviceProfile& profile) override; int32_t OnDeviceProfileUpdate(const DeviceProfile& oldProfile, const DeviceProfile& newProfile) override; diff --git a/common/include/interfaces/profile_change_listener_stub.h b/common/include/interfaces/profile_change_listener_stub.h index 08876de7..669a41fd 100644 --- a/common/include/interfaces/profile_change_listener_stub.h +++ b/common/include/interfaces/profile_change_listener_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,8 @@ public: int32_t OnTrustDeviceProfileAddInner(MessageParcel& data, MessageParcel& reply); int32_t OnTrustDeviceProfileDeleteInner(MessageParcel& data, MessageParcel& reply); int32_t OnTrustDeviceProfileUpdateInner(MessageParcel& data, MessageParcel& reply); + int32_t OnTrustDeviceProfileActiveInner(MessageParcel& data, MessageParcel& reply); + int32_t OnTrustDeviceProfileInactiveInner(MessageParcel& data, MessageParcel& reply); int32_t OnDeviceProfileAddInner(MessageParcel& data, MessageParcel& reply); int32_t OnDeviceProfileDeleteInner(MessageParcel& data, MessageParcel& reply); int32_t OnDeviceProfileUpdateInner(MessageParcel& data, MessageParcel& reply); @@ -44,6 +46,8 @@ public: int32_t OnCharacteristicProfileAddInner(MessageParcel& data, MessageParcel& reply); int32_t OnCharacteristicProfileDeleteInner(MessageParcel& data, MessageParcel& reply); int32_t OnCharacteristicProfileUpdateInner(MessageParcel& data, MessageParcel& reply); + int32_t OnTrustDeviceProfileActive(const TrustDeviceProfile& profile) override; + int32_t OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile) override; private: using Func = int32_t(ProfileChangeListenerStub::*)(MessageParcel& data, MessageParcel& reply); diff --git a/common/include/interfaces/trust_device_profile.h b/common/include/interfaces/trust_device_profile.h index 77059397..7b871af4 100644 --- a/common/include/interfaces/trust_device_profile.h +++ b/common/include/interfaces/trust_device_profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,7 +29,8 @@ public: deviceIdType_(static_cast(DeviceIdType::MIN)), deviceIdHash_(""), status_(static_cast(Status::MIN)), - bindType_(static_cast(BindType::MIN)) + bindType_(static_cast(BindType::MIN)), + peerUserId_(-1) {} ~TrustDeviceProfile() = default; @@ -43,6 +44,8 @@ public: void SetStatus(int32_t status); uint32_t GetBindType() const; void SetBindType(uint32_t bindType); + int32_t GetPeerUserId() const; + void SetPeerUserId(int32_t peerUserId); bool Marshalling(MessageParcel& parcel) const override; bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; @@ -53,6 +56,7 @@ private: std::string deviceIdHash_; int32_t status_; uint32_t bindType_; + int32_t peerUserId_; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index fb323d60..9b84c281 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -21,6 +21,7 @@ #include #include +#include "result_set.h" #include "values_bucket.h" #include "access_control_profile.h" @@ -117,6 +118,17 @@ public: static int32_t GenerateCharacteristicDBkeys(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, std::vector& dbKeys, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); + static int32_t ConvertToTrustDeviceProfile(const AccessControlProfile& accessControlProfile, + TrustDeviceProfile& trustDeviceProfile); + static int32_t ConvertToAccessControlProfiles(std::shared_ptr resultSet, + std::shared_ptr accesserResultSet, std::shared_ptr accesseeResultSet, + std::vector& profile); + static int32_t ConvertToTrustDeviceProfile(std::shared_ptr trustResultSet, + TrustDeviceProfile& trustDeviceProfile); + static int32_t ConvertToAccesser(std::shared_ptr accesserResultSet, Accesser& accesser); + static int32_t ConvertToAccessee(std::shared_ptr accesseeResultSet, Accessee& accessee); + static int32_t ConvertToAccessControlProfile(std::shared_ptr accessControlResultSet, + AccessControlProfile& accessControlProfile); }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/constants/distributed_device_profile_constants.cpp b/common/src/constants/distributed_device_profile_constants.cpp index 83e80fe3..2cb4ff11 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -43,6 +43,7 @@ const std::string CHARACTERISTIC_VALUE = "characteristicValue"; const std::string SUBSCRIBE_TRUST_DEVICE_PROFILE = "trust_device_profile"; const std::string DEVICE_ID_TYPE = "deviceIdType"; const std::string DEVICE_ID_HASH = "deviceIdHash"; +const std::string PEER_USER_ID = "peerUserId"; /* AccessControlProfile Attribute */ const std::string ACCESS_CONTROL_ID = "accessControlId"; const std::string ACCESSER_ID = "accesserId"; @@ -182,7 +183,6 @@ const std::string CREATE_ACCESS_CONTROL_TABLE_UNIQUE_INDEX_SQL = authenticationType,\ deviceIdType,\ deviceIdHash,\ - status,\ validPeriod,\ lastAuthTime,\ bindLevel);"; @@ -250,6 +250,10 @@ const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_ACCESS "SELECT * FROM accesser_table WHERE accesserId = ? and accesserDeviceId = ? and accesserTokenId = ? "; const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_ACCESSEETOKENID = "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeDeviceId = ? and accesseeTokenId = ? "; +const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_USERID = + "SELECT * FROM accesser_table WHERE accesserId = ? and accesserDeviceId = ? and accesserUserId = ? "; +const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_USERID = + "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeDeviceId = ? and accesseeUserId = ? "; const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_ACCESSERDEVICEID = "SELECT * FROM accesser_table WHERE accesserId = ? and accesserDeviceId = ? "; const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEDEVICEID = @@ -260,16 +264,22 @@ const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_ACCESSEEBUNDLENAME "SELECT * FROM accessee_table WHERE accesseeId = ? and accesseeBundleName = ? "; const std::string SELECT_ACCESSEE_TABLE = "SELECT * FROM accessee_table "; const std::string SELECT_ACCESSER_TABLE = "SELECT * FROM accesser_table "; -const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL = +const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL_EXCEPT_STATUS = "SELECT * FROM access_control_table WHERE accesserId = ? and accesseeId = ? and trustDeviceId = ? and \ sessionKey = ? and bindType = ? and authenticationType = ? and deviceIdType = ? and deviceIdHash = ? \ - and status = ? and validPeriod = ? and lastAuthTime = ? and bindLevel = ? "; + and validPeriod = ? and lastAuthTime = ? and bindLevel = ? "; const std::string SELECT_ACCESSER_TABLE_WHERE_ALL = "SELECT * FROM accesser_table WHERE accesserDeviceId = ? and accesserUserId = ? and accesserAccountId = ? and \ accesserTokenId = ? and accesserBundleName = ? and accesserHapSignature = ? and accesserBindLevel = ? "; const std::string SELECT_ACCESSEE_TABLE_WHERE_ALL = "SELECT * FROM accessee_table WHERE accesseeDeviceId = ? and accesseeUserId = ? and accesseeAccountId = ? and \ accesseeTokenId = ? and accesseeBundleName = ? and accesseeHapSignature = ? and accesseeBindLevel = ? "; +const std::string SELECT_ACCESSER_TABLE_WHERE_ACCESSERDEVICEID_AND_ACCESSERUSERID = + "SELECT * FROM accesser_table WHERE accesserDeviceId = ? and accesserUserId = ? "; +const std::string SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEDEVICEID_AND_ACCESSEEUSERID = + "SELECT * FROM accessee_table WHERE accesseeDeviceId = ? and accesseeUserId = ? "; +const std::string SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID_AND_ACCESSEEID = + "SELECT * FROM access_control_table WHERE accesserId = ? and accesseeId = ? "; /* SubscribeTrustInfoManager */ const std::string SUBSCRIBE_TRUST_INFO_TABLE = "subscribe_trust_info_table"; const std::string CREATE_SUBSCRIBE_TRUST_INFO_TABLE_SQL = diff --git a/common/src/interfaces/dp_subscribe_info.cpp b/common/src/interfaces/dp_subscribe_info.cpp index ad8ba4e8..78ee3554 100644 --- a/common/src/interfaces/dp_subscribe_info.cpp +++ b/common/src/interfaces/dp_subscribe_info.cpp @@ -118,9 +118,11 @@ std::unordered_set SubscribeInfo::GetProfileChangeTypes() con void SubscribeInfo::AddProfileChangeType(ProfileChangeType profileChangeType) { if (profileChangeType <= PROFILE_CHANGE_TYPE_MIN || profileChangeType >= PROFILE_CHANGE_TYPE_MAX) { + HILOGE("profileChangeType is invaild"); return; } if (subscribeChangeTypes_.size() > MAX_SUBSCRIBE_CHANGE_SIZE) { + HILOGE("subscribeChangeTypes_ size greater than max"); return; } subscribeChangeTypes_.emplace(profileChangeType); diff --git a/common/src/interfaces/i_profile_change_listener.cpp b/common/src/interfaces/i_profile_change_listener.cpp new file mode 100644 index 00000000..b754cac6 --- /dev/null +++ b/common/src/interfaces/i_profile_change_listener.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "i_profile_change_listener.h" +#include "distributed_device_profile_errors.h" + + +namespace OHOS { +namespace DistributedDeviceProfile { +namespace { + const std::string TAG = "IProfileChangeListener"; +} +int32_t IProfileChangeListener::OnTrustDeviceProfileActive(const TrustDeviceProfile& profile) +{ + (void)profile; + return DP_SUCCESS; +} + +int32_t IProfileChangeListener::OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile) +{ + (void)profile; + return DP_SUCCESS; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/profile_change_listener_proxy.cpp b/common/src/interfaces/profile_change_listener_proxy.cpp index 4f8eed06..740957ae 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 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -74,6 +74,36 @@ int32_t ProfileListenerProxy::OnTrustDeviceProfileUpdate(const TrustDeviceProfil return DP_SUCCESS; } +int32_t ProfileListenerProxy::OnTrustDeviceProfileActive(const TrustDeviceProfile& profile) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_CHANGE_LISTENER_TOKEN(data); + if (!profile.Marshalling(data)) { + HILOGE("write reply failed!"); + return ERR_FLATTEN_OBJECT; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ACTIVE), data, reply); + return DP_SUCCESS; +} + +int32_t ProfileListenerProxy::OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_CHANGE_LISTENER_TOKEN(data); + if (!profile.Marshalling(data)) { + HILOGE("write reply failed!"); + return ERR_FLATTEN_OBJECT; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_INACTIVE), data, reply); + return DP_SUCCESS; +} + int32_t ProfileListenerProxy::OnDeviceProfileAdd(const DeviceProfile& profile) { sptr remote = nullptr; diff --git a/common/src/interfaces/profile_change_listener_stub.cpp b/common/src/interfaces/profile_change_listener_stub.cpp index 5558e52a..16bd8d30 100644 --- a/common/src/interfaces/profile_change_listener_stub.cpp +++ b/common/src/interfaces/profile_change_listener_stub.cpp @@ -38,6 +38,10 @@ ProfileChangeListenerStub::ProfileChangeListenerStub() &ProfileChangeListenerStub::OnTrustDeviceProfileDeleteInner; funcsMap_[static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_UPDATE)] = &ProfileChangeListenerStub::OnTrustDeviceProfileUpdateInner; + funcsMap_[static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ACTIVE)] = + &ProfileChangeListenerStub::OnTrustDeviceProfileActiveInner; + funcsMap_[static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_INACTIVE)] = + &ProfileChangeListenerStub::OnTrustDeviceProfileInactiveInner; funcsMap_[static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_ADD)] = &ProfileChangeListenerStub::OnDeviceProfileAddInner; funcsMap_[static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_DELETE)] = @@ -84,6 +88,10 @@ int32_t ProfileChangeListenerStub::OnRemoteRequest(uint32_t code, MessageParcel& return ProfileChangeListenerStub::OnTrustDeviceProfileDeleteInner(data, reply); case static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_UPDATE): return ProfileChangeListenerStub::OnTrustDeviceProfileUpdateInner(data, reply); + case static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ACTIVE): + return ProfileChangeListenerStub::OnTrustDeviceProfileActiveInner(data, reply); + case static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_INACTIVE): + return ProfileChangeListenerStub::OnTrustDeviceProfileInactiveInner(data, reply); case static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_ADD): return ProfileChangeListenerStub::OnDeviceProfileAddInner(data, reply); case static_cast(DPInterfaceCode::ON_DEVICE_PROFILE_DELETE): @@ -161,6 +169,38 @@ int32_t ProfileChangeListenerStub::OnTrustDeviceProfileUpdateInner(MessageParcel return DP_SUCCESS; } +int32_t ProfileChangeListenerStub::OnTrustDeviceProfileActiveInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + TrustDeviceProfile trustDeviceProfile; + if (!trustDeviceProfile.UnMarshalling(data)) { + HILOGE("Read reply failed"); + return ERR_FLATTEN_OBJECT; + } + OnTrustDeviceProfileActive(trustDeviceProfile); + if (!reply.WriteInt32(DP_SUCCESS)) { + HILOGE("Read reply failed"); + return ERR_FLATTEN_OBJECT; + } + return DP_SUCCESS; +} + +int32_t ProfileChangeListenerStub::OnTrustDeviceProfileInactiveInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + TrustDeviceProfile trustDeviceProfile; + if (!trustDeviceProfile.UnMarshalling(data)) { + HILOGE("Read reply failed"); + return ERR_FLATTEN_OBJECT; + } + OnTrustDeviceProfileInactive(trustDeviceProfile); + if (!reply.WriteInt32(DP_SUCCESS)) { + HILOGE("Read reply failed"); + return ERR_FLATTEN_OBJECT; + } + return DP_SUCCESS; +} + int32_t ProfileChangeListenerStub::OnDeviceProfileAddInner(MessageParcel& data, MessageParcel& reply) { HILOGI("called"); @@ -319,5 +359,17 @@ int32_t ProfileChangeListenerStub::OnCharacteristicProfileUpdateInner(MessagePar } return DP_SUCCESS; } + +int32_t ProfileChangeListenerStub::OnTrustDeviceProfileActive(const TrustDeviceProfile& profile) +{ + (void)profile; + return DP_SUCCESS; +} + +int32_t ProfileChangeListenerStub::OnTrustDeviceProfileInactive(const TrustDeviceProfile& profile) +{ + (void)profile; + return DP_SUCCESS; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/trust_device_profile.cpp b/common/src/interfaces/trust_device_profile.cpp index ca7dc04d..0ed24997 100644 --- a/common/src/interfaces/trust_device_profile.cpp +++ b/common/src/interfaces/trust_device_profile.cpp @@ -74,6 +74,16 @@ void TrustDeviceProfile::SetBindType(uint32_t bindType) bindType_ = bindType; } +int32_t TrustDeviceProfile::GetPeerUserId() const +{ + return peerUserId_; +} + +void TrustDeviceProfile::SetPeerUserId(int32_t peerUserId) +{ + peerUserId_ = peerUserId; +} + bool TrustDeviceProfile::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, deviceId_, false); @@ -81,6 +91,7 @@ bool TrustDeviceProfile::Marshalling(MessageParcel& parcel) const 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); return true; } @@ -91,6 +102,7 @@ bool TrustDeviceProfile::UnMarshalling(MessageParcel& parcel) 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); return true; } @@ -105,6 +117,9 @@ std::string TrustDeviceProfile::dump() const cJSON_AddNumberToObject(json, DEVICE_ID_TYPE.c_str(), deviceIdType_); cJSON_AddStringToObject(json, DEVICE_ID_HASH.c_str(), deviceIdHash_.c_str()); cJSON_AddNumberToObject(json, STATUS.c_str(), status_); + cJSON_AddNumberToObject(json, BIND_TYPE.c_str(), bindType_); + cJSON_AddStringToObject(json, PEER_USER_ID.c_str(), + ProfileUtils::GetAnonyString(std::to_string(peerUserId_)).c_str()); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 67515e6d..ed1874dc 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -972,5 +972,183 @@ int32_t ProfileUtils::GenerateCharacteristicDBkeys(const std::string& deviceId, } return DP_SUCCESS; } + +int32_t ProfileUtils::ConvertToTrustDeviceProfile( + const AccessControlProfile& accessControlProfile, TrustDeviceProfile& trustDeviceProfile) +{ + trustDeviceProfile.SetDeviceId(accessControlProfile.GetTrustDeviceId()); + trustDeviceProfile.SetDeviceIdType(accessControlProfile.GetDeviceIdType()); + trustDeviceProfile.SetDeviceIdHash(accessControlProfile.GetDeviceIdHash()); + trustDeviceProfile.SetStatus(accessControlProfile.GetStatus()); + trustDeviceProfile.SetBindType(accessControlProfile.GetBindType()); + std::string peerDeviceId = accessControlProfile.GetTrustDeviceId(); + int32_t peerUserId = accessControlProfile.GetAccesser().GetAccesserUserId(); + if (accessControlProfile.GetAccessee().GetAccesseeDeviceId() == peerDeviceId) { + peerUserId = accessControlProfile.GetAccessee().GetAccesseeUserId(); + } + trustDeviceProfile.SetPeerUserId(peerUserId); + return DP_SUCCESS; +} + +int32_t ProfileUtils::ConvertToAccessControlProfiles(std::shared_ptr resultSet, + std::shared_ptr accesserResultSet, std::shared_ptr accesseeResultSet, + std::vector& profile) +{ + if (accesserResultSet == nullptr) { + HILOGE("accesserResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + if (accesseeResultSet == nullptr) { + HILOGE("accesseeResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + Accesser accesser; + accesserResultSet->GoToNextRow(); + ConvertToAccesser(accesserResultSet, accesser); + Accessee accessee; + accesseeResultSet->GoToNextRow(); + ConvertToAccessee(accesseeResultSet, accessee); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + AccessControlProfile accessControlProfile; + ConvertToAccessControlProfile(resultSet, accessControlProfile); + + accessControlProfile.SetAccesser(accesser); + accessControlProfile.SetAccessee(accessee); + profile.push_back(accessControlProfile); + return DP_SUCCESS; +} + +int32_t ProfileUtils::ConvertToTrustDeviceProfile( + std::shared_ptr trustResultSet, TrustDeviceProfile& trustDeviceProfile) +{ + if (trustResultSet == nullptr) { + HILOGE("trustResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + RowEntity rowEntity; + if (trustResultSet->GetRow(rowEntity) != DP_SUCCESS) { + HILOGE("get trustResultSet failed"); + return DP_GET_RESULTSET_FAIL; + } + std::string deviceId = rowEntity.Get(DEVICE_ID); + int32_t deviceIdType = rowEntity.Get(DEVICE_ID_TYPE); + std::string deviceIdHash = rowEntity.Get(DEVICE_ID_HASH); + int32_t status = rowEntity.Get(STATUS); + + trustDeviceProfile.SetDeviceId(deviceId); + trustDeviceProfile.SetDeviceIdType(deviceIdType); + trustDeviceProfile.SetDeviceIdHash(deviceIdHash); + trustDeviceProfile.SetStatus(status); + return DP_SUCCESS; +} + +int32_t ProfileUtils::ConvertToAccesser(std::shared_ptr accesserResultSet, + Accesser& accesser) +{ + if (accesserResultSet == nullptr) { + HILOGE("accesserResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + RowEntity rowEntity; + if (accesserResultSet->GetRow(rowEntity) != DP_SUCCESS) { + HILOGE("get accesserResultSet failed"); + return DP_GET_RESULTSET_FAIL; + } + int64_t accesserId = rowEntity.Get(ACCESSER_ID); + std::string accesserDeviceId = rowEntity.Get(ACCESSER_DEVICE_ID); + int32_t accesserUserId = rowEntity.Get(ACCESSER_USER_ID); + std::string accesserAccountId = rowEntity.Get(ACCESSER_ACCOUNT_ID); + int64_t accesserTokenId = rowEntity.Get(ACCESSER_TOKEN_ID); + std::string accesserBundleName = rowEntity.Get(ACCESSER_BUNDLE_NAME); + std::string accesserHapSignature = rowEntity.Get(ACCESSER_HAP_SIGNATURE); + int32_t accesserBindLevel = rowEntity.Get(ACCESSER_BIND_LEVEL); + + accesser.SetAccesserId(accesserId); + accesser.SetAccesserDeviceId(accesserDeviceId); + accesser.SetAccesserUserId(accesserUserId); + accesser.SetAccesserAccountId(accesserAccountId); + accesser.SetAccesserTokenId(accesserTokenId); + accesser.SetAccesserBundleName(accesserBundleName); + accesser.SetAccesserHapSignature(accesserHapSignature); + accesser.SetAccesserBindLevel(accesserBindLevel); + return DP_SUCCESS; +} + +int32_t ProfileUtils::ConvertToAccessee(std::shared_ptr accesseeResultSet, + Accessee& accessee) +{ + if (accesseeResultSet == nullptr) { + HILOGE("accesseeResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + RowEntity rowEntity; + if (accesseeResultSet->GetRow(rowEntity) != DP_SUCCESS) { + HILOGE("get accesseeResultSet failed"); + return DP_GET_RESULTSET_FAIL; + } + int64_t accesseeId = rowEntity.Get(ACCESSEE_ID); + std::string accesseeDeviceId = rowEntity.Get(ACCESSEE_DEVICE_ID); + int32_t accesseeUserId = rowEntity.Get(ACCESSEE_USER_ID); + std::string accesseeAccountId = rowEntity.Get(ACCESSEE_ACCOUNT_ID); + int64_t accesseeTokenId = rowEntity.Get(ACCESSEE_TOKEN_ID); + std::string accesseeBundleName = rowEntity.Get(ACCESSEE_BUNDLE_NAME); + std::string accesseeHapSignature = rowEntity.Get(ACCESSEE_HAP_SIGNATURE); + int32_t accesseeBindLevel = rowEntity.Get(ACCESSEE_BIND_LEVEL); + + accessee.SetAccesseeId(accesseeId); + accessee.SetAccesseeDeviceId(accesseeDeviceId); + accessee.SetAccesseeUserId(accesseeUserId); + accessee.SetAccesseeAccountId(accesseeAccountId); + accessee.SetAccesseeTokenId(accesseeTokenId); + accessee.SetAccesseeBundleName(accesseeBundleName); + accessee.SetAccesseeHapSignature(accesseeHapSignature); + accessee.SetAccesseeBindLevel(accesseeBindLevel); + return DP_SUCCESS; +} + +int32_t ProfileUtils::ConvertToAccessControlProfile( + std::shared_ptr accessControlResultSet, AccessControlProfile& accessControlProfile) +{ + if (accessControlResultSet == nullptr) { + HILOGE("accessControlResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + RowEntity rowEntity; + if (accessControlResultSet->GetRow(rowEntity) != DP_SUCCESS) { + HILOGE("get accessControlResultSet failed"); + return DP_GET_RESULTSET_FAIL; + } + int64_t accessControlId = rowEntity.Get(ACCESS_CONTROL_ID); + int64_t accesserId = rowEntity.Get(ACCESSER_ID); + int64_t accesseeId = rowEntity.Get(ACCESSEE_ID); + std::string trustDeviceId = rowEntity.Get(TRUST_DEVICE_ID); + std::string sessionKey = rowEntity.Get(SESSION_KEY); + int32_t bindType = rowEntity.Get(BIND_TYPE); + int32_t authenticationType = rowEntity.Get(AUTHENTICATION_TYPE); + int32_t deviceIdType = rowEntity.Get(DEVICE_ID_TYPE); + std::string deviceIdHash = rowEntity.Get(DEVICE_ID_HASH); + int32_t status = rowEntity.Get(STATUS); + int32_t validPeriod = rowEntity.Get(VALID_PERIOD); + int32_t lastAuthTime = rowEntity.Get(LAST_AUTH_TIME); + int32_t bindLevel = rowEntity.Get(BIND_LEVEL); + + accessControlProfile.SetAccessControlId(accessControlId); + accessControlProfile.SetAccesserId(accesserId); + accessControlProfile.SetAccesseeId(accesseeId); + accessControlProfile.SetTrustDeviceId(trustDeviceId); + accessControlProfile.SetSessionKey(sessionKey); + accessControlProfile.SetBindType(bindType); + accessControlProfile.SetAuthenticationType(authenticationType); + accessControlProfile.SetDeviceIdType(deviceIdType); + accessControlProfile.SetDeviceIdHash(deviceIdHash); + accessControlProfile.SetStatus(status); + accessControlProfile.SetValidPeriod(validPeriod); + accessControlProfile.SetLastAuthTime(lastAuthTime); + accessControlProfile.SetBindLevel(bindLevel); + return DP_SUCCESS; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h index a29ca38e..9fe77633 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 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,6 +39,8 @@ public: int32_t NotifyTrustDeviceProfileUpdate(const TrustDeviceProfile& oldDeviceProfile, const TrustDeviceProfile& newDeviceProfile); 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); diff --git a/services/core/include/trustprofilemanager/trust_profile_manager.h b/services/core/include/trustprofilemanager/trust_profile_manager.h index 872db869..1979f5e6 100644 --- a/services/core/include/trustprofilemanager/trust_profile_manager.h +++ b/services/core/include/trustprofilemanager/trust_profile_manager.h @@ -68,8 +68,6 @@ private: int32_t GetAccessControlProfile(int32_t userId, std::vector& profile); int32_t GetAccessControlProfileByTokenId(int64_t tokenId, const std::string& trustDeviceId, int32_t status, std::vector& profile); - int32_t ConvertToTrustDeviceProfile(const AccessControlProfile& accessControlProfile, - TrustDeviceProfile& trustDeviceProfile); int32_t GetAclProfileByUserIdAndBundleName(std::shared_ptr resultSet, int32_t userId, const std::string& bundleName, std::vector& profile); int32_t GetAclProfileByUserIdAndAccountId(std::shared_ptr resultSet, int64_t accesserId, @@ -78,16 +76,13 @@ private: int64_t tokenId, std::vector& profile); int32_t GetAclProfileByBundleName(std::shared_ptr resultSet, const std::string& bundleName, std::vector& profile); - int32_t ConvertToAccessControlProfiles(std::shared_ptr resultSet, - std::shared_ptr accesserResultSet, std::shared_ptr accesseeResultSet, - std::vector& profile); int32_t PutAccesserProfile(const AccessControlProfile& profile); int32_t PutAccesseeProfile(const AccessControlProfile& profile); int32_t SetAccessControlId(AccessControlProfile& profile); int32_t SetAccesserId(AccessControlProfile& profile); int32_t SetAccesseeId(AccessControlProfile& profile); - int32_t UpdateAccesserProfile(int64_t accesserId, const AccessControlProfile& profile); - int32_t UpdateAccesseeProfile(int64_t accesseeId, const AccessControlProfile& profile); + int32_t UpdateAccesserProfile(AccessControlProfile& profile, bool& isAcerOrAceeExist); + int32_t UpdateAccesseeProfile(AccessControlProfile& profile, bool& isAcerOrAceeExist); int32_t UpdateTrustDeviceProfileNotify(const TrustDeviceProfile& oldProfile, const TrustDeviceProfile& newProfile); int32_t GetResultStatus(const std::string& trustDeviceId, int32_t& trustDeviceStatus); @@ -95,13 +90,7 @@ private: int64_t accesserId, int64_t accesseeId, std::vector& profile); int32_t GetAccessControlProfilesByDeviceId(std::shared_ptr resultSet, int64_t accesserId, int64_t accesseeId, const std::string& trustDeviceId, std::vector& profile); - int32_t DeleteAccessControlProfileCheck(std::shared_ptr resultSet); - int32_t ConvertToTrustDeviceProfile(std::shared_ptr trustResultSet, - TrustDeviceProfile& trustDeviceProfile); - int32_t ConvertToAccesser(std::shared_ptr accesserResultSet, Accesser& accesser); - int32_t ConvertToAccessee(std::shared_ptr accesseeResultSet, Accessee& accessee); - int32_t ConvertToAccessControlProfile(std::shared_ptr accessControlResultSet, - AccessControlProfile& accessControlProfile); + int32_t DeleteAccessControlProfileCheck(const AccessControlProfile& profile); std::shared_ptr GetResultSet(const std::string& sql, std::vector condition); int32_t SetAccessControlProfileId(AccessControlProfile& accessControlProfile); int32_t GetAccessControlProfiles(std::shared_ptr resultSet, int64_t accesserId, @@ -114,12 +103,16 @@ private: int32_t GetAccessControlProfilesByTokenId(std::shared_ptr resultSet, int64_t accesserId, int64_t accesseeId, const std::string& trustDeviceId, int64_t tokenId, std::vector& profile); - int32_t DeleteAccesserCheck(int64_t accesserId); - int32_t DeleteAccesseeCheck(int64_t accesseeId); + int32_t DeleteAccesserCheck(int64_t accesserId, Accesser& accesser); + int32_t DeleteAccesseeCheck(int64_t accesseeId, Accessee& accessee); int32_t DeleteTrustDeviceCheck(const AccessControlProfile& profile); - int32_t UpdateAclCheck(const AccessControlProfile& profile); - int32_t PutAclCheck(const AccessControlProfile& profile); + int32_t UpdateAclCheck(const AccessControlProfile& profile, AccessControlProfile& oldProfile); + int32_t PutAclCheck(const AccessControlProfile& profile, bool peerDevInfoExists); int32_t IsAclExists(const AccessControlProfile& profile); + bool CheckUserIdExists(const AccessControlProfile& profile); + int32_t GetConformCount(const std::string& peerDeviceId, int32_t peerUserId); + int32_t NotifyCheck(const AccessControlProfile& profile, const AccessControlProfile& oldProfile); + int32_t UpdateOrDeleteAclCheck(const AccessControlProfile& profile, bool isAcerOrAceeExist); private: std::shared_ptr rdbStore_; diff --git a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp index 6d9da2b8..cbfe8a3e 100644 --- a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp +++ b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp @@ -159,6 +159,46 @@ int32_t SubscribeProfileManager::NotifyTrustDeviceProfileDelete(const TrustDevic return DP_SUCCESS; } +int32_t SubscribeProfileManager::NotifyTrustDeviceProfileActive(const TrustDeviceProfile& trustDeviceProfile) +{ + auto subscriberInfos = GetSubscribeInfos(SUBSCRIBE_TRUST_DEVICE_PROFILE); + if (subscriberInfos.empty()) { + return DP_SUCCESS; + } + HILOGI("%{public}s!", trustDeviceProfile.dump().c_str()); + for (const auto& subscriberInfo : subscriberInfos) { + sptr listenerProxy = iface_cast(subscriberInfo.GetListener()); + if (listenerProxy == nullptr) { + HILOGE("Cast to IProfileChangeListener failed!"); + continue; + } + if (subscriberInfo.GetProfileChangeTypes().count(ProfileChangeType::TRUST_DEVICE_PROFILE_ACTIVE) != 0) { + listenerProxy->OnTrustDeviceProfileActive(trustDeviceProfile); + } + } + return DP_SUCCESS; +} + +int32_t SubscribeProfileManager::NotifyTrustDeviceProfileInactive(const TrustDeviceProfile& trustDeviceProfile) +{ + auto subscriberInfos = GetSubscribeInfos(SUBSCRIBE_TRUST_DEVICE_PROFILE); + if (subscriberInfos.empty()) { + return DP_SUCCESS; + } + HILOGI("%{public}s!", trustDeviceProfile.dump().c_str()); + for (const auto& subscriberInfo : subscriberInfos) { + sptr listenerProxy = iface_cast(subscriberInfo.GetListener()); + if (listenerProxy == nullptr) { + HILOGE("Cast to IProfileChangeListener failed!"); + continue; + } + if (subscriberInfo.GetProfileChangeTypes().count(ProfileChangeType::TRUST_DEVICE_PROFILE_INACTIVE) != 0) { + listenerProxy->OnTrustDeviceProfileInactive(trustDeviceProfile); + } + } + return DP_SUCCESS; +} + int32_t SubscribeProfileManager::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) { HILOGI("saId: %{public}d!, subscribeKey: %{public}s", subscribeInfo.GetSaId(), diff --git a/services/core/src/trustprofilemanager/trust_profile_manager.cpp b/services/core/src/trustprofilemanager/trust_profile_manager.cpp index 0437628f..15e9a14c 100644 --- a/services/core/src/trustprofilemanager/trust_profile_manager.cpp +++ b/services/core/src/trustprofilemanager/trust_profile_manager.cpp @@ -75,7 +75,6 @@ int32_t TrustProfileManager::PutTrustDeviceProfile(const TrustDeviceProfile& pro { ValuesBucket values; ProfileUtils::TrustDeviceProfileToEntries(profile, values); - int64_t rowId = ROWID_INIT; int32_t ret = RET_INIT; { @@ -90,17 +89,13 @@ int32_t TrustProfileManager::PutTrustDeviceProfile(const TrustDeviceProfile& pro return DP_PUT_TRUST_DEVICE_PROFILE_FAIL; } } - ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileAdd(profile); - if (ret != DP_SUCCESS) { - HILOGE("NotifyTrustDeviceProfileAdd failed"); - return DP_NOTIFY_TRUST_DEVICE_FAIL; - } HILOGI("end!"); return DP_SUCCESS; } int32_t TrustProfileManager::PutAccessControlProfile(const AccessControlProfile& profile) { + bool peerDevInfoExists = CheckUserIdExists(profile); AccessControlProfile accessControlProfile(profile); int32_t ret = this->SetAccessControlProfileId(accessControlProfile); if (ret != DP_SUCCESS) { @@ -136,7 +131,7 @@ int32_t TrustProfileManager::PutAccessControlProfile(const AccessControlProfile& } } HILOGI("PutAclProfile : %{public}s", accessControlProfile.dump().c_str()); - ret = this->PutAclCheck(accessControlProfile); + ret = this->PutAclCheck(accessControlProfile, peerDevInfoExists); if (ret != DP_SUCCESS) { HILOGE("PutAclCheck failed"); return ret; @@ -153,8 +148,7 @@ int32_t TrustProfileManager::PutAccessControlProfile(const AccessControlProfile& int32_t TrustProfileManager::UpdateTrustDeviceProfile(const TrustDeviceProfile& profile) { std::string deviceId = profile.GetDeviceId(); - std::shared_ptr resultSet = - GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, + std::shared_ptr resultSet = GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, std::vector{ ValueObject(deviceId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -174,7 +168,7 @@ int32_t TrustProfileManager::UpdateTrustDeviceProfile(const TrustDeviceProfile& return DP_NOT_FIND_DATA; } TrustDeviceProfile oldProfile; - this->ConvertToTrustDeviceProfile(resultSet, oldProfile); + ProfileUtils::ConvertToTrustDeviceProfile(resultSet, oldProfile); resultSet->Close(); ValuesBucket values; ProfileUtils::TrustDeviceProfileToEntries(profile, values); @@ -199,15 +193,22 @@ int32_t TrustProfileManager::UpdateTrustDeviceProfile(const TrustDeviceProfile& int32_t TrustProfileManager::UpdateAccessControlProfile(const AccessControlProfile& profile) { - int32_t ret = this->UpdateAclCheck(profile); + AccessControlProfile oldProfile; + int32_t ret = this->UpdateAclCheck(profile, oldProfile); if (ret != DP_SUCCESS) { HILOGE("UpdateAclCheck faild"); return ret; } - this->UpdateAccesserProfile(profile.GetAccesserId(), profile); - this->UpdateAccesseeProfile(profile.GetAccesseeId(), profile); + bool isAcerOrAceeExist = false; + AccessControlProfile newProfile(profile); + this->UpdateAccesserProfile(newProfile, isAcerOrAceeExist); + this->UpdateAccesseeProfile(newProfile, isAcerOrAceeExist); + if (UpdateOrDeleteAclCheck(newProfile, isAcerOrAceeExist) == DP_DATA_EXISTS) { + HILOGE("aclProfile is duplicative"); + return DP_SUCCESS; + } ValuesBucket values; - ProfileUtils::AccessControlProfileToEntries(profile, values); + ProfileUtils::AccessControlProfileToEntries(newProfile, values); int32_t changeRowCnt = CHANGEROWCNT_INIT; { std::lock_guard lock(rdbMutex_); @@ -216,21 +217,18 @@ int32_t TrustProfileManager::UpdateAccessControlProfile(const AccessControlProfi return DP_GET_RDBSTORE_FAIL; } ret = rdbStore_->Update(changeRowCnt, ACCESS_CONTROL_TABLE, values, ACCESSCONTROLID_EQUAL_CONDITION, - std::vector{ ValueObject(profile.GetAccessControlId()) }); + std::vector{ ValueObject(newProfile.GetAccessControlId()) }); if (ret != DP_SUCCESS) { HILOGE("update access_control_table failed"); return DP_UPDATE_ACL_PROFILE_FAIL; } } - HILOGI("UpdateAclProfile : %{public}s", profile.dump().c_str()); + this->NotifyCheck(newProfile, oldProfile); + HILOGI("UpdateAclProfile : %{public}s", newProfile.dump().c_str()); int32_t status = STATUS_INIT; - ret = this->GetResultStatus(profile.GetTrustDeviceId(), status); - if (ret != DP_SUCCESS) { - HILOGE("GetResultStatus failed"); - return DP_GET_RESULTSET_FAIL; - } + this->GetResultStatus(newProfile.GetTrustDeviceId(), status); TrustDeviceProfile trustProfile; - this->ConvertToTrustDeviceProfile(profile, trustProfile); + ProfileUtils::ConvertToTrustDeviceProfile(newProfile, trustProfile); trustProfile.SetStatus(status); ret = this->UpdateTrustDeviceProfile(trustProfile); if (ret != DP_SUCCESS) { @@ -262,7 +260,7 @@ int32_t TrustProfileManager::GetTrustDeviceProfile(const std::string& deviceId, resultSet->Close(); return DP_NOT_FIND_DATA; } - this->ConvertToTrustDeviceProfile(resultSet, profile); + ProfileUtils::ConvertToTrustDeviceProfile(resultSet, profile); resultSet->Close(); HILOGI("end!"); return DP_SUCCESS; @@ -270,8 +268,7 @@ int32_t TrustProfileManager::GetTrustDeviceProfile(const std::string& deviceId, int32_t TrustProfileManager::GetAllTrustDeviceProfile(std::vector& profile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_TRUST_DEVICE_TABLE, std::vector {}); + std::shared_ptr resultSet = GetResultSet(SELECT_TRUST_DEVICE_TABLE, std::vector {}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -285,7 +282,7 @@ int32_t TrustProfileManager::GetAllTrustDeviceProfile(std::vectorGoToNextRow() == DP_SUCCESS) { TrustDeviceProfile trustProfile; - this->ConvertToTrustDeviceProfile(resultSet, trustProfile); + ProfileUtils::ConvertToTrustDeviceProfile(resultSet, trustProfile); profile.push_back(trustProfile); } resultSet->Close(); @@ -305,8 +302,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(int32_t userId, const std:: } HILOGI("Params, userId : %{public}s, bundleName : %{public}s, bindtype : %{public}d, status : %{public}d", ProfileUtils::GetAnonyString(std::to_string(userId)).c_str(), bundleName.c_str(), bindType, status); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS, std::vector{ ValueObject(bindType), ValueObject(status) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -380,8 +376,7 @@ int32_t TrustProfileManager::GetAccessControlProfileByTokenId(int64_t tokenId, } HILOGI("Params, tokenId : %{public}" PRId64 ", trustDeviceId : %{public}s, status : %{public}d", tokenId, ProfileUtils::GetAnonyString(trustDeviceId).c_str(), status); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_STATUS, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_STATUS, std::vector{ ValueObject(status) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -418,8 +413,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(int32_t userId, HILOGI("Params, userId : %{public}s, accountId : %{public}s", ProfileUtils::GetAnonyString(std::to_string(userId)).c_str(), ProfileUtils::GetAnonyString(accountId).c_str()); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -457,8 +451,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(int32_t userId, int32_t TrustProfileManager::GetAccessControlProfile(int32_t userId, std::vector &profile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -497,8 +490,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(int32_t userId, std::vector int32_t TrustProfileManager::GetAllAccessControlProfile(std::vector& profile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -542,8 +534,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(const std::string& bundleNa } HILOGI("Params, bundleName : %{public}s, bindType : %{public}d, status : %{public}d", bundleName.c_str(), bindType, status); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_BINDTYPE_AND_STATUS, std::vector{ ValueObject(bindType), ValueObject(status) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -657,8 +648,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(const std::map resultSet = - GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, + std::shared_ptr resultSet = GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, std::vector{ ValueObject(deviceId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -671,14 +661,9 @@ int32_t TrustProfileManager::DeleteTrustDeviceProfile(const std::string& deviceI resultSet->Close(); return DP_NOT_FIND_DATA; } - int32_t ret = resultSet->GoToFirstRow(); - if (ret != DP_SUCCESS) { - HILOGE("deviceId not find"); - resultSet->Close(); - return DP_NOT_FIND_DATA; - } + resultSet->GoToFirstRow(); TrustDeviceProfile profile; - this->ConvertToTrustDeviceProfile(resultSet, profile); + ProfileUtils::ConvertToTrustDeviceProfile(resultSet, profile); resultSet->Close(); { std::lock_guard lock(rdbMutex_); @@ -687,26 +672,20 @@ int32_t TrustProfileManager::DeleteTrustDeviceProfile(const std::string& deviceI return DP_GET_RDBSTORE_FAIL; } int32_t deleteRows = DELETEROWS_INIT; - ret = rdbStore_->Delete(deleteRows, TRUST_DEVICE_TABLE, DEVICEID_EQUAL_CONDITION, + int32_t ret = rdbStore_->Delete(deleteRows, TRUST_DEVICE_TABLE, DEVICEID_EQUAL_CONDITION, std::vector{ ValueObject(deviceId) }); if (ret != DP_SUCCESS) { HILOGE("delete trust_device_table data failed"); return DP_DELETE_TRUST_DEVICE_PROFILE_FAIL; } } - ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileDelete(profile); - if (ret != DP_SUCCESS) { - HILOGE("ProfileDelete failed"); - return DP_NOTIFY_TRUST_DEVICE_FAIL; - } HILOGI("end!"); return DP_SUCCESS; } int32_t TrustProfileManager::DeleteAccessControlProfile(int64_t accessControlId) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID, std::vector{ ValueObject(accessControlId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -719,8 +698,15 @@ int32_t TrustProfileManager::DeleteAccessControlProfile(int64_t accessControlId) resultSet->Close(); return DP_NOT_FIND_DATA; } - int32_t ret = this->DeleteAccessControlProfileCheck(resultSet); + int32_t ret = resultSet->GoToNextRow(); + if (ret != DP_SUCCESS) { + HILOGE("get AccessControlProfileResult failed"); + return DP_NOT_FIND_DATA; + } + AccessControlProfile profile; + ProfileUtils::ConvertToAccessControlProfile(resultSet, profile); resultSet->Close(); + ret = this->DeleteAccessControlProfileCheck(profile); if (ret != DP_SUCCESS) { HILOGE("DeleteAccessControlProfileCheck failed"); return ret; @@ -789,17 +775,6 @@ int32_t TrustProfileManager::CreateUniqueIndex() return DP_SUCCESS; } -int32_t TrustProfileManager::ConvertToTrustDeviceProfile( - const AccessControlProfile& accessControlProfile, TrustDeviceProfile& trustDeviceProfile) -{ - trustDeviceProfile.SetDeviceId(accessControlProfile.GetTrustDeviceId()); - trustDeviceProfile.SetDeviceIdType(accessControlProfile.GetDeviceIdType()); - trustDeviceProfile.SetDeviceIdHash(accessControlProfile.GetDeviceIdHash()); - trustDeviceProfile.SetStatus(accessControlProfile.GetStatus()); - trustDeviceProfile.SetBindType(accessControlProfile.GetBindType()); - return DP_SUCCESS; -} - int32_t TrustProfileManager::GetAclProfileByUserIdAndBundleName(std::shared_ptr resultSet, int32_t userId, const std::string& bundleName, std::vector& profile) { @@ -853,14 +828,13 @@ int32_t TrustProfileManager::GetAclProfileByUserIdAndAccountId(std::shared_ptrGetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -882,7 +856,7 @@ int32_t TrustProfileManager::GetAclProfileByUserIdAndAccountId(std::shared_ptrConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); @@ -969,42 +943,10 @@ int32_t TrustProfileManager::GetAclProfileByBundleName(std::shared_ptr resultSet, - std::shared_ptr accesserResultSet, std::shared_ptr accesseeResultSet, - std::vector& profile) -{ - if (accesserResultSet == nullptr) { - HILOGE("accesserResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - if (accesseeResultSet == nullptr) { - HILOGE("accesseeResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - Accesser accesser; - accesserResultSet->GoToNextRow(); - this->ConvertToAccesser(accesserResultSet, accesser); - Accessee accessee; - accesseeResultSet->GoToNextRow(); - this->ConvertToAccessee(accesseeResultSet, accessee); - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - AccessControlProfile accessControlProfile; - this->ConvertToAccessControlProfile(resultSet, accessControlProfile); - - accessControlProfile.SetAccesser(accesser); - accessControlProfile.SetAccessee(accessee); - profile.push_back(accessControlProfile); - return DP_SUCCESS; -} - int32_t TrustProfileManager::PutAccesserProfile(const AccessControlProfile& profile) { Accesser accesser = profile.GetAccesser(); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ALL, std::vector{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ALL, std::vector{ ValueObject(accesser.GetAccesserDeviceId()), ValueObject(accesser.GetAccesserUserId()), ValueObject(accesser.GetAccesserAccountId()), ValueObject(accesser.GetAccesserTokenId()), ValueObject(accesser.GetAccesserBundleName()), ValueObject(accesser.GetAccesserHapSignature()), @@ -1043,8 +985,7 @@ int32_t TrustProfileManager::PutAccesserProfile(const AccessControlProfile& prof int32_t TrustProfileManager::PutAccesseeProfile(const AccessControlProfile& profile) { Accessee accessee = profile.GetAccessee(); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ALL, std::vector{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ALL, std::vector{ ValueObject(accessee.GetAccesseeDeviceId()), ValueObject(accessee.GetAccesseeUserId()), ValueObject(accessee.GetAccesseeAccountId()), ValueObject(accessee.GetAccesseeTokenId()), ValueObject(accessee.GetAccesseeBundleName()), ValueObject(accessee.GetAccesseeHapSignature()), @@ -1082,8 +1023,7 @@ int32_t TrustProfileManager::PutAccesseeProfile(const AccessControlProfile& prof int32_t TrustProfileManager::SetAccessControlId(AccessControlProfile& profile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE, std::vector {}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -1108,8 +1048,7 @@ int32_t TrustProfileManager::SetAccessControlId(AccessControlProfile& profile) int32_t TrustProfileManager::SetAccesserId(AccessControlProfile& profile) { Accesser accesser = profile.GetAccesser(); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ALL, std::vector{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ALL, std::vector{ ValueObject(accesser.GetAccesserDeviceId()), ValueObject(accesser.GetAccesserUserId()), ValueObject(accesser.GetAccesserAccountId()), ValueObject(accesser.GetAccesserTokenId()), ValueObject(accesser.GetAccesserBundleName()), ValueObject(accesser.GetAccesserHapSignature()), @@ -1155,8 +1094,7 @@ int32_t TrustProfileManager::SetAccesserId(AccessControlProfile& profile) int32_t TrustProfileManager::SetAccesseeId(AccessControlProfile& profile) { Accessee accessee = profile.GetAccessee(); - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ALL, std::vector{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ALL, std::vector{ ValueObject(accessee.GetAccesseeDeviceId()), ValueObject(accessee.GetAccesseeUserId()), ValueObject(accessee.GetAccesseeAccountId()), ValueObject(accessee.GetAccesseeTokenId()), ValueObject(accessee.GetAccesseeBundleName()), ValueObject(accessee.GetAccesseeHapSignature()), @@ -1199,8 +1137,36 @@ int32_t TrustProfileManager::SetAccesseeId(AccessControlProfile& profile) return DP_SUCCESS; } -int32_t TrustProfileManager::UpdateAccesserProfile(int64_t accesserId, const AccessControlProfile& profile) +int32_t TrustProfileManager::UpdateAccesserProfile(AccessControlProfile& profile, bool& isAcerOrAceeExist) { + int64_t accesserId = profile.GetAccesserId(); + Accesser accesser = profile.GetAccesser(); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ALL, std::vector{ + ValueObject(accesser.GetAccesserDeviceId()), ValueObject(accesser.GetAccesserUserId()), + ValueObject(accesser.GetAccesserAccountId()), ValueObject(accesser.GetAccesserTokenId()), + ValueObject(accesser.GetAccesserBundleName()), ValueObject(accesser.GetAccesserHapSignature()), + ValueObject(static_cast(accesser.GetAccesserBindLevel()))}); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + resultSet->GoToNextRow(); + int32_t columnIndex = COLUMNINDEX_INIT; + int64_t oldAccesserId = ACCESSERID_INIT; + resultSet->GetColumnIndex(ACCESSER_ID, columnIndex); + resultSet->GetLong(columnIndex, oldAccesserId); + resultSet->Close(); + if (rowCount != 0 && accesserId != oldAccesserId) { + isAcerOrAceeExist = true; + Accesser oldAccesser; + this->DeleteAccesserCheck(accesserId, oldAccesser); + profile.SetAccesserId(oldAccesserId); + profile.SetAccesser(oldAccesser); + HILOGI("update accesser is exists, UpdateAccesser : %{public}s", accesser.dump().c_str()); + return DP_SUCCESS; + } ValuesBucket values; ProfileUtils::AccesserToEntries(profile, values); int32_t changeRowCnt = CHANGEROWCNT_INIT; @@ -1221,8 +1187,36 @@ int32_t TrustProfileManager::UpdateAccesserProfile(int64_t accesserId, const Acc return DP_SUCCESS; } -int32_t TrustProfileManager::UpdateAccesseeProfile(int64_t accesseeId, const AccessControlProfile& profile) +int32_t TrustProfileManager::UpdateAccesseeProfile(AccessControlProfile& profile, bool& isAcerOrAceeExist) { + int64_t accesseeId = profile.GetAccesseeId(); + Accessee accessee = profile.GetAccessee(); + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ALL, std::vector{ + ValueObject(accessee.GetAccesseeDeviceId()), ValueObject(accessee.GetAccesseeUserId()), + ValueObject(accessee.GetAccesseeAccountId()), ValueObject(accessee.GetAccesseeTokenId()), + ValueObject(accessee.GetAccesseeBundleName()), ValueObject(accessee.GetAccesseeHapSignature()), + ValueObject(static_cast(accessee.GetAccesseeBindLevel()))}); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + resultSet->GoToNextRow(); + int32_t columnIndex = COLUMNINDEX_INIT; + int64_t oldAccesseeId = ACCESSEEID_INIT; + resultSet->GetColumnIndex(ACCESSEE_ID, columnIndex); + resultSet->GetLong(columnIndex, oldAccesseeId); + resultSet->Close(); + if (rowCount != 0 && accesseeId != oldAccesseeId) { + isAcerOrAceeExist = true; + Accessee oldAccessee; + this->DeleteAccesseeCheck(accesseeId, oldAccessee); + profile.SetAccesseeId(oldAccesseeId); + profile.SetAccessee(oldAccessee); + HILOGI("accessee is exists, change accesseeId, UpdateAccessee : %{public}s", accessee.dump().c_str()); + return DP_SUCCESS; + } ValuesBucket values; ProfileUtils::AccesseeToEntries(profile, values); int32_t changeRowCnt = CHANGEROWCNT_INIT; @@ -1246,23 +1240,7 @@ int32_t TrustProfileManager::UpdateAccesseeProfile(int64_t accesseeId, const Acc int32_t TrustProfileManager::UpdateTrustDeviceProfileNotify(const TrustDeviceProfile& oldProfile, const TrustDeviceProfile &newProfile) { - if (oldProfile.GetStatus() == 1 && newProfile.GetStatus() == 0) { - int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileDelete(newProfile); - if (ret != DP_SUCCESS) { - HILOGE("NotifyTrustDeviceProfileDelete failed"); - return DP_NOTIFY_TRUST_DEVICE_FAIL; - } - } - if (oldProfile.GetStatus() == 0 && newProfile.GetStatus() == 1) { - int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileAdd(newProfile); - if (ret != DP_SUCCESS) { - HILOGE("NotifyTrustDeviceProfileAdd failed"); - return DP_NOTIFY_TRUST_DEVICE_FAIL; - } - } - if (oldProfile.GetDeviceId() != newProfile.GetDeviceId() || - oldProfile.GetDeviceIdHash() != newProfile.GetDeviceIdHash() || - oldProfile.GetDeviceIdType() != newProfile.GetDeviceIdType()) { + if (oldProfile.GetStatus() != newProfile.GetStatus()) { int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileUpdate(oldProfile, newProfile); if (ret != DP_SUCCESS) { HILOGE("NotifyTrustDeviceProfileUpdate failed"); @@ -1274,8 +1252,7 @@ int32_t TrustProfileManager::UpdateTrustDeviceProfileNotify(const TrustDevicePro int32_t TrustProfileManager::GetResultStatus(const std::string& trustDeviceId, int32_t& trustDeviceStatus) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID, std::vector{ ValueObject(trustDeviceId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1306,8 +1283,7 @@ int32_t TrustProfileManager::GetResultStatus(const std::string& trustDeviceId, i int32_t TrustProfileManager::GetAccessControlProfile(std::shared_ptr resultSet, int64_t accesserId, int64_t accesseeId, std::vector& profile) { - std::shared_ptr accesserResultSet = - GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ACCESSERID, + std::shared_ptr accesserResultSet = GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ACCESSERID, std::vector{ ValueObject(accesserId) }); if (accesserResultSet == nullptr) { HILOGE("accesserResultSet is nullptr"); @@ -1320,8 +1296,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(std::shared_ptr accesserResultSet->Close(); return DP_NOT_FIND_DATA; } - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); @@ -1334,7 +1309,7 @@ int32_t TrustProfileManager::GetAccessControlProfile(std::shared_ptr accesseeResultSet->Close(); return DP_NOT_FIND_DATA; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1354,14 +1329,13 @@ int32_t TrustProfileManager::GetAccessControlProfilesByDeviceId( int32_t rowCount = ROWCOUNT_INIT; accesserResultSet->GetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1383,30 +1357,23 @@ int32_t TrustProfileManager::GetAccessControlProfilesByDeviceId( HILOGE("accesserResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); return DP_SUCCESS; } -int32_t TrustProfileManager::DeleteAccessControlProfileCheck(std::shared_ptr resultSet) +int32_t TrustProfileManager::DeleteAccessControlProfileCheck(const AccessControlProfile& profile) { - int32_t ret = resultSet->GoToNextRow(); - if (ret != DP_SUCCESS) { - HILOGE("get AccessControlProfileResult failed"); - return DP_NOT_FIND_DATA; - } - AccessControlProfile profile; - this->ConvertToAccessControlProfile(resultSet, profile); - resultSet->Close(); - - ret = this->DeleteAccesseeCheck(profile.GetAccesseeId()); + Accessee accessee; + int32_t ret = this->DeleteAccesseeCheck(profile.GetAccesseeId(), accessee); if (ret != DP_SUCCESS) { HILOGE("DeleteAccesseeCheck failed"); return ret; } - ret = this->DeleteAccesserCheck(profile.GetAccesserId()); + Accesser accesser; + ret = this->DeleteAccesserCheck(profile.GetAccesserId(), accesser); if (ret != DP_SUCCESS) { HILOGE("DeleteAccesserCheck failed"); return ret; @@ -1426,7 +1393,10 @@ int32_t TrustProfileManager::DeleteAccessControlProfileCheck(std::shared_ptrDeleteTrustDeviceCheck(profile); + AccessControlProfile resultProfile(profile); + resultProfile.SetAccesser(accesser); + resultProfile.SetAccessee(accessee); + ret = this->DeleteTrustDeviceCheck(resultProfile); if (ret != DP_SUCCESS) { HILOGE("DeleteTrustDeviceCheck failed"); return ret; @@ -1434,136 +1404,6 @@ int32_t TrustProfileManager::DeleteAccessControlProfileCheck(std::shared_ptr trustResultSet, TrustDeviceProfile& trustDeviceProfile) -{ - if (trustResultSet == nullptr) { - HILOGE("trustResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (trustResultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get trustResultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - std::string deviceId = rowEntity.Get(DEVICE_ID); - int32_t deviceIdType = rowEntity.Get(DEVICE_ID_TYPE); - std::string deviceIdHash = rowEntity.Get(DEVICE_ID_HASH); - int32_t status = rowEntity.Get(STATUS); - - trustDeviceProfile.SetDeviceId(deviceId); - trustDeviceProfile.SetDeviceIdType(deviceIdType); - trustDeviceProfile.SetDeviceIdHash(deviceIdHash); - trustDeviceProfile.SetStatus(status); - return DP_SUCCESS; -} - -int32_t TrustProfileManager::ConvertToAccesser(std::shared_ptr accesserResultSet, - Accesser& accesser) -{ - if (accesserResultSet == nullptr) { - HILOGE("accesserResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (accesserResultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get accesserResultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - int64_t accesserId = rowEntity.Get(ACCESSER_ID); - std::string accesserDeviceId = rowEntity.Get(ACCESSER_DEVICE_ID); - int32_t accesserUserId = rowEntity.Get(ACCESSER_USER_ID); - std::string accesserAccountId = rowEntity.Get(ACCESSER_ACCOUNT_ID); - int64_t accesserTokenId = rowEntity.Get(ACCESSER_TOKEN_ID); - std::string accesserBundleName = rowEntity.Get(ACCESSER_BUNDLE_NAME); - std::string accesserHapSignature = rowEntity.Get(ACCESSER_HAP_SIGNATURE); - int32_t accesserBindLevel = rowEntity.Get(ACCESSER_BIND_LEVEL); - - accesser.SetAccesserId(accesserId); - accesser.SetAccesserDeviceId(accesserDeviceId); - accesser.SetAccesserUserId(accesserUserId); - accesser.SetAccesserAccountId(accesserAccountId); - accesser.SetAccesserTokenId(accesserTokenId); - accesser.SetAccesserBundleName(accesserBundleName); - accesser.SetAccesserHapSignature(accesserHapSignature); - accesser.SetAccesserBindLevel(accesserBindLevel); - return DP_SUCCESS; -} - -int32_t TrustProfileManager::ConvertToAccessee(std::shared_ptr accesseeResultSet, - Accessee& accessee) -{ - if (accesseeResultSet == nullptr) { - HILOGE("accesseeResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (accesseeResultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get accesseeResultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - int64_t accesseeId = rowEntity.Get(ACCESSEE_ID); - std::string accesseeDeviceId = rowEntity.Get(ACCESSEE_DEVICE_ID); - int32_t accesseeUserId = rowEntity.Get(ACCESSEE_USER_ID); - std::string accesseeAccountId = rowEntity.Get(ACCESSEE_ACCOUNT_ID); - int64_t accesseeTokenId = rowEntity.Get(ACCESSEE_TOKEN_ID); - std::string accesseeBundleName = rowEntity.Get(ACCESSEE_BUNDLE_NAME); - std::string accesseeHapSignature = rowEntity.Get(ACCESSEE_HAP_SIGNATURE); - int32_t accesseeBindLevel = rowEntity.Get(ACCESSEE_BIND_LEVEL); - - accessee.SetAccesseeId(accesseeId); - accessee.SetAccesseeDeviceId(accesseeDeviceId); - accessee.SetAccesseeUserId(accesseeUserId); - accessee.SetAccesseeAccountId(accesseeAccountId); - accessee.SetAccesseeTokenId(accesseeTokenId); - accessee.SetAccesseeBundleName(accesseeBundleName); - accessee.SetAccesseeHapSignature(accesseeHapSignature); - accessee.SetAccesseeBindLevel(accesseeBindLevel); - return DP_SUCCESS; -} - -int32_t TrustProfileManager::ConvertToAccessControlProfile( - std::shared_ptr accessControlResultSet, AccessControlProfile& accessControlProfile) -{ - if (accessControlResultSet == nullptr) { - HILOGE("accessControlResultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (accessControlResultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get accessControlResultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - int64_t accessControlId = rowEntity.Get(ACCESS_CONTROL_ID); - int64_t accesserId = rowEntity.Get(ACCESSER_ID); - int64_t accesseeId = rowEntity.Get(ACCESSEE_ID); - std::string trustDeviceId = rowEntity.Get(TRUST_DEVICE_ID); - std::string sessionKey = rowEntity.Get(SESSION_KEY); - int32_t bindType = rowEntity.Get(BIND_TYPE); - int32_t authenticationType = rowEntity.Get(AUTHENTICATION_TYPE); - int32_t deviceIdType = rowEntity.Get(DEVICE_ID_TYPE); - std::string deviceIdHash = rowEntity.Get(DEVICE_ID_HASH); - int32_t status = rowEntity.Get(STATUS); - int32_t validPeriod = rowEntity.Get(VALID_PERIOD); - int32_t lastAuthTime = rowEntity.Get(LAST_AUTH_TIME); - int32_t bindLevel = rowEntity.Get(BIND_LEVEL); - - accessControlProfile.SetAccessControlId(accessControlId); - accessControlProfile.SetAccesserId(accesserId); - accessControlProfile.SetAccesseeId(accesseeId); - accessControlProfile.SetTrustDeviceId(trustDeviceId); - accessControlProfile.SetSessionKey(sessionKey); - accessControlProfile.SetBindType(bindType); - accessControlProfile.SetAuthenticationType(authenticationType); - accessControlProfile.SetDeviceIdType(deviceIdType); - accessControlProfile.SetDeviceIdHash(deviceIdHash); - accessControlProfile.SetStatus(status); - accessControlProfile.SetValidPeriod(validPeriod); - accessControlProfile.SetLastAuthTime(lastAuthTime); - accessControlProfile.SetBindLevel(bindLevel); - return DP_SUCCESS; -} - std::shared_ptr TrustProfileManager::GetResultSet( const std::string& sql, std::vector condition) { @@ -1603,7 +1443,6 @@ int32_t TrustProfileManager::SetAccessControlProfileId(AccessControlProfile& acc Accesser accesser(accessControlProfile.GetAccesser()); accesser.SetAccesserId(accessControlProfile.GetAccesserId()); accessControlProfile.SetAccesser(accesser); - Accessee accessee(accessControlProfile.GetAccessee()); accessee.SetAccesseeId(accessControlProfile.GetAccesseeId()); accessControlProfile.SetAccessee(accessee); @@ -1624,14 +1463,13 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr int32_t rowCount = ROWCOUNT_INIT; accesserResultSet->GetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1653,7 +1491,7 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr HILOGE("accesserResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); @@ -1673,14 +1511,13 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr int32_t rowCount = ROWCOUNT_INIT; accesserResultSet->GetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1702,7 +1539,7 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr HILOGE("accesserResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); @@ -1722,14 +1559,13 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr int32_t rowCount = ROWCOUNT_INIT; accesserResultSet->GetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1751,7 +1587,7 @@ int32_t TrustProfileManager::GetAccessControlProfiles(std::shared_ptr HILOGE("accesserResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); @@ -1772,14 +1608,13 @@ int32_t TrustProfileManager::GetAccessControlProfilesByTokenId(std::shared_ptrGetRowCount(rowCount); if (rowCount != 0) { - std::shared_ptr accesseeResultSet = - GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::shared_ptr accesseeResultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (accesseeResultSet == nullptr) { HILOGE("accesseeResultSet is nullptr"); return DP_GET_RESULTSET_FAIL; } - this->ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); accesseeResultSet->Close(); return DP_SUCCESS; @@ -1801,17 +1636,16 @@ int32_t TrustProfileManager::GetAccessControlProfilesByTokenId(std::shared_ptrConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); + ProfileUtils::ConvertToAccessControlProfiles(resultSet, accesserResultSet, accesseeResultSet, profile); accesserResultSet->Close(); } accesseeResultSet->Close(); return DP_SUCCESS; } -int32_t TrustProfileManager::DeleteAccesserCheck(int64_t accesserId) +int32_t TrustProfileManager::DeleteAccesserCheck(int64_t accesserId, Accesser& accesser) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID, std::vector{ ValueObject(accesserId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1820,6 +1654,15 @@ int32_t TrustProfileManager::DeleteAccesserCheck(int64_t accesserId) int32_t rowCount = ROWCOUNT_INIT; resultSet->GetRowCount(rowCount); resultSet->Close(); + resultSet = GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ACCESSERID, + std::vector{ ValueObject(accesserId) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + resultSet->GoToNextRow(); + ProfileUtils::ConvertToAccesser(resultSet, accesser); + resultSet->Close(); if (rowCount == DELETE_ACCESSER_CONDITION) { std::lock_guard lock(rdbMutex_); if (rdbStore_ == nullptr) { @@ -1833,15 +1676,14 @@ int32_t TrustProfileManager::DeleteAccesserCheck(int64_t accesserId) HILOGE("delete accesser_table accesserId failed"); return DP_DELETE_ACCESSER_PROFILE_FAIL; } - HILOGI("DeleteAccesserId : %{public}" PRId64, accesserId); + HILOGI("DeleteAccesser : %{public}s", accesser.dump().c_str()); } return DP_SUCCESS; } -int32_t TrustProfileManager::UpdateAclCheck(const AccessControlProfile& profile) +int32_t TrustProfileManager::UpdateAclCheck(const AccessControlProfile& profile, AccessControlProfile& oldProfile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID, + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSCONTROLID, std::vector{ ValueObject(profile.GetAccessControlId()) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1855,8 +1697,7 @@ int32_t TrustProfileManager::UpdateAclCheck(const AccessControlProfile& profile) return DP_NOT_FIND_DATA; } resultSet->GoToNextRow(); - AccessControlProfile oldProfile; - this->ConvertToAccessControlProfile(resultSet, oldProfile); + ProfileUtils::ConvertToAccessControlProfile(resultSet, oldProfile); resultSet->Close(); if (oldProfile.GetAccesseeId() != profile.GetAccessee().GetAccesseeId() || oldProfile.GetAccesserId() != profile.GetAccesser().GetAccesserId() || @@ -1868,13 +1709,19 @@ int32_t TrustProfileManager::UpdateAclCheck(const AccessControlProfile& profile) return DP_SUCCESS; } -int32_t TrustProfileManager::PutAclCheck(const AccessControlProfile& profile) +int32_t TrustProfileManager::PutAclCheck(const AccessControlProfile& profile, bool peerDevInfoExists) { TrustDeviceProfile trustProfile; - this->ConvertToTrustDeviceProfile(profile, trustProfile); + ProfileUtils::ConvertToTrustDeviceProfile(profile, trustProfile); + if (!peerDevInfoExists) { + int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileAdd(trustProfile); + if (ret != DP_SUCCESS) { + HILOGE("NotifyTrustDeviceProfileAdd failed"); + return DP_NOTIFY_TRUST_DEVICE_FAIL; + } + } std::string trustDeviceId = profile.GetTrustDeviceId(); - std::shared_ptr resultSet = - GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, + std::shared_ptr resultSet = GetResultSet(SELECT_TRUST_DEVICE_TABLE_WHERE_DEVICEID, std::vector{ ValueObject(trustDeviceId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1903,15 +1750,14 @@ int32_t TrustProfileManager::PutAclCheck(const AccessControlProfile& profile) int32_t TrustProfileManager::IsAclExists(const AccessControlProfile &profile) { std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL, std::vector{ + GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ALL_EXCEPT_STATUS, std::vector{ ValueObject(profile.GetAccesserId()), ValueObject(profile.GetAccesseeId()), ValueObject(profile.GetTrustDeviceId()), ValueObject(profile.GetSessionKey()), ValueObject(static_cast(profile.GetBindType())), ValueObject(static_cast(profile.GetAuthenticationType())), ValueObject(static_cast(profile.GetDeviceIdType())), - ValueObject(profile.GetDeviceIdHash()), ValueObject(profile.GetStatus()), - ValueObject(profile.GetValidPeriod()), ValueObject(profile.GetLastAuthTime()), - ValueObject(static_cast(profile.GetBindLevel()))}); + ValueObject(profile.GetDeviceIdHash()), ValueObject(profile.GetValidPeriod()), + ValueObject(profile.GetLastAuthTime()), ValueObject(static_cast(profile.GetBindLevel()))}); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); return DP_GET_RESULTSET_FAIL; @@ -1926,10 +1772,118 @@ int32_t TrustProfileManager::IsAclExists(const AccessControlProfile &profile) return DP_SUCCESS; } -int32_t TrustProfileManager::DeleteAccesseeCheck(int64_t accesseeId) +bool TrustProfileManager::CheckUserIdExists(const AccessControlProfile& profile) { + std::string peerDeviceId = profile.GetTrustDeviceId(); + int32_t peerUserId = profile.GetAccesser().GetAccesserUserId(); + if (profile.GetAccessee().GetAccesseeDeviceId() == peerDeviceId) { + peerUserId = profile.GetAccessee().GetAccesseeUserId(); + } std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSEEID, + GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ACCESSERDEVICEID_AND_ACCESSERUSERID, + std::vector{ ValueObject(peerDeviceId), ValueObject(peerUserId) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return false; + } + int32_t acerRowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(acerRowCount); + resultSet->Close(); + resultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEDEVICEID_AND_ACCESSEEUSERID, + std::vector{ ValueObject(peerDeviceId), ValueObject(peerUserId) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return false; + } + int32_t aceeRowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(aceeRowCount); + resultSet->Close(); + if (acerRowCount > 0 || aceeRowCount > 0) { + return true; + } + return false; +} + +int32_t TrustProfileManager::GetConformCount(const std::string &peerDeviceId, int32_t peerUserId) +{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID_AND_STATUS, + std::vector{ ValueObject(peerDeviceId), ValueObject(1) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t resultRowCount = 0; + while (resultSet->GoToNextRow() == DP_SUCCESS) { + int32_t columnIndex = COLUMNINDEX_INIT; + int64_t accesserId = ACCESSERID_INIT; + resultSet->GetColumnIndex(ACCESSER_ID, columnIndex); + resultSet->GetLong(columnIndex, accesserId); + int64_t accesseeId = ACCESSEEID_INIT; + resultSet->GetColumnIndex(ACCESSEE_ID, columnIndex); + resultSet->GetLong(columnIndex, accesseeId); + std::shared_ptr accesserResultSet = + GetResultSet(SELECT_ACCESSER_TABLE_WHERE_ACCESSERID_AND_DEVICEID_AND_USERID, + std::vector{ ValueObject(accesserId), ValueObject(peerDeviceId), ValueObject(peerUserId) }); + if (accesserResultSet == nullptr) { + HILOGE("accesserResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t acerRowCount = ROWCOUNT_INIT; + accesserResultSet->GetRowCount(acerRowCount); + accesserResultSet->Close(); + if (acerRowCount > 0) { + resultRowCount++; + } else { + std::shared_ptr accesseeResultSet = GetResultSet( + SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_USERID, std::vector{ + ValueObject(accesseeId), ValueObject(peerDeviceId), ValueObject(peerUserId) }); + if (accesseeResultSet == nullptr) { + HILOGE("accesserResultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t aceeRowCount = ROWCOUNT_INIT; + accesseeResultSet->GetRowCount(aceeRowCount); + if (aceeRowCount > 0) { + resultRowCount++; + } + accesseeResultSet->Close(); + } + } + resultSet->Close(); + return resultRowCount; +} + +int32_t TrustProfileManager::NotifyCheck(const AccessControlProfile& profile, const AccessControlProfile& oldProfile) +{ + std::string peerDeviceId = profile.GetTrustDeviceId(); + int32_t peerUserId = profile.GetAccesser().GetAccesserUserId(); + if (profile.GetAccessee().GetAccesseeDeviceId() == peerDeviceId) { + peerUserId = profile.GetAccessee().GetAccesseeUserId(); + } + int32_t resultCount = GetConformCount(peerDeviceId, peerUserId); + HILOGI("resultCount : %{public}d", resultCount); + TrustDeviceProfile trustProfile; + ProfileUtils::ConvertToTrustDeviceProfile(profile, trustProfile); + if (resultCount == 1 && profile.GetStatus() == STATUS_ACTIVE && oldProfile.GetStatus() == STATUS_INACTIVE) { + int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileActive(trustProfile); + if (ret != DP_SUCCESS) { + HILOGE("NotifyTrustDeviceProfileActive failed"); + return DP_NOTIFY_TRUST_DEVICE_FAIL; + } + } + if (resultCount == 0 && profile.GetStatus() == STATUS_INACTIVE && oldProfile.GetStatus() == STATUS_ACTIVE) { + int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileInactive(trustProfile); + if (ret != DP_SUCCESS) { + HILOGE("NotifyTrustDeviceProfileInactive failed"); + return DP_NOTIFY_TRUST_DEVICE_FAIL; + } + } + return DP_SUCCESS; +} + +int32_t TrustProfileManager::DeleteAccesseeCheck(int64_t accesseeId, Accessee& accessee) +{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSEEID, std::vector{ ValueObject(accesseeId) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1938,6 +1892,15 @@ int32_t TrustProfileManager::DeleteAccesseeCheck(int64_t accesseeId) int32_t rowCount = ROWCOUNT_INIT; resultSet->GetRowCount(rowCount); resultSet->Close(); + resultSet = GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID, + std::vector{ ValueObject(accesseeId) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + resultSet->GoToNextRow(); + ProfileUtils::ConvertToAccessee(resultSet, accessee); + resultSet->Close(); if (rowCount == DELETE_ACCESSEE_CONDITION) { std::lock_guard lock(rdbMutex_); if (rdbStore_ == nullptr) { @@ -1951,15 +1914,23 @@ int32_t TrustProfileManager::DeleteAccesseeCheck(int64_t accesseeId) HILOGE("delete accessee_table accesseeId failed"); return DP_DELETE_ACCESSEE_PROFILE_FAIL; } - HILOGI("DeleteAccesseeId : %{public}" PRId64, accesseeId); + HILOGI("DeleteAccessee : %{public}s", accessee.dump().c_str()); } return DP_SUCCESS; } int32_t TrustProfileManager::DeleteTrustDeviceCheck(const AccessControlProfile& profile) { - std::shared_ptr resultSet = - GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID, + TrustDeviceProfile trustProfile; + ProfileUtils::ConvertToTrustDeviceProfile(profile, trustProfile); + if (!CheckUserIdExists(profile)) { + int32_t ret = SubscribeProfileManager::GetInstance().NotifyTrustDeviceProfileDelete(trustProfile); + if (ret != DP_SUCCESS) { + HILOGE("NotifyTrustDeviceProfileDelete failed"); + return DP_NOTIFY_TRUST_DEVICE_FAIL; + } + } + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_TRUSTDEVICEID, std::vector{ ValueObject(profile.GetTrustDeviceId()) }); if (resultSet == nullptr) { HILOGE("resultSet is nullptr"); @@ -1978,10 +1949,7 @@ int32_t TrustProfileManager::DeleteTrustDeviceCheck(const AccessControlProfile& } else { int32_t status = STATUS_INIT; this->GetResultStatus(profile.GetTrustDeviceId(), status); - TrustDeviceProfile trustDeviceProfile; - trustDeviceProfile.SetDeviceId(profile.GetTrustDeviceId()); - trustDeviceProfile.SetDeviceIdType(profile.GetDeviceIdType()); - trustDeviceProfile.SetDeviceIdHash(profile.GetDeviceIdHash()); + TrustDeviceProfile trustDeviceProfile(trustProfile); trustDeviceProfile.SetStatus(status); ret = this->UpdateTrustDeviceProfile(trustDeviceProfile); if (ret != DP_SUCCESS) { @@ -1991,5 +1959,35 @@ int32_t TrustProfileManager::DeleteTrustDeviceCheck(const AccessControlProfile& } return DP_SUCCESS; } + +int32_t TrustProfileManager::UpdateOrDeleteAclCheck(const AccessControlProfile& profile, bool isAcerOrAceeExist) +{ + std::shared_ptr resultSet = GetResultSet(SELECT_ACCESS_CONTROL_TABLE_WHERE_ACCESSERID_AND_ACCESSEEID, + std::vector{ ValueObject(profile.GetAccesserId()), ValueObject(profile.GetAccesseeId()) }); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + resultSet->Close(); + if (rowCount != 0 && isAcerOrAceeExist) { + std::lock_guard lock(rdbMutex_); + if (rdbStore_ == nullptr) { + HILOGE("rdbStore_ is nullptr"); + return DP_GET_RDBSTORE_FAIL; + } + int32_t deleteRows = DELETEROWS_INIT; + int32_t ret = rdbStore_->Delete(deleteRows, ACCESS_CONTROL_TABLE, ACCESSCONTROLID_EQUAL_CONDITION, + std::vector{ ValueObject(profile.GetAccessControlId()) }); + if (ret != DP_SUCCESS) { + HILOGE("delete access_control_table failed"); + return DP_DELETE_ACCESS_CONTROL_PROFILE_FAIL; + } + HILOGE("aclProfile is exist, DeleteAclProfile : %{public}s", profile.dump().c_str()); + return DP_DATA_EXISTS; + } + return DP_SUCCESS; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/services/core/test/unittest/dp_subscribe_info_test.cpp b/services/core/test/unittest/dp_subscribe_info_test.cpp index c9ab5d48..ebb34ef1 100644 --- a/services/core/test/unittest/dp_subscribe_info_test.cpp +++ b/services/core/test/unittest/dp_subscribe_info_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -68,6 +68,16 @@ public: cout << "OnTrustDeviceProfileUpdate: newProfile " << newProfile.dump() <OnCharacteristicProfileUpdate(oldChaProfile, newChaProfile); EXPECT_EQ(ret, DP_SUCCESS); } + +/* + * @tc.name: Stub_002 + * @tc.desc: Normal testCase of DPSubscribeInfoTest for CRUD + * @tc.type: FUNC + */ +HWTEST_F(DPSubscribeInfoTest, Stub_002, TestSize.Level1) +{ + uint32_t saId = 4801; + std::string subscribeKey = "trust_device_profile"; + std::unordered_set subscribeTypes = {ProfileChangeType::TRUST_DEVICE_PROFILE_ACTIVE, + ProfileChangeType::TRUST_DEVICE_PROFILE_INACTIVE}; + OHOS::sptr subscribeDPChangeListener = + sptr(new DPSubscribeInfoTest::SubscribeDPChangeListener); + SubscribeInfo subscribeInfo(saId, subscribeKey, subscribeTypes, subscribeDPChangeListener); + OHOS::sptr proxy = OHOS::iface_cast(subscribeInfo.GetListener()); + TrustDeviceProfile profile; + profile.SetPeerUserId(1001); + ASSERT_NE(proxy, nullptr); + int32_t ret = proxy->OnTrustDeviceProfileActive(profile); + EXPECT_EQ(ret, DP_SUCCESS); + ret = proxy->OnTrustDeviceProfileInactive(profile); + EXPECT_EQ(ret, DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/test/unittest/trust_profile_manager_test.cpp b/services/core/test/unittest/trust_profile_manager_test.cpp index d5f0205b..0a321120 100644 --- a/services/core/test/unittest/trust_profile_manager_test.cpp +++ b/services/core/test/unittest/trust_profile_manager_test.cpp @@ -160,8 +160,9 @@ HWTEST_F(TrustProfileManagerTest, GetAccessControlProfile_013, TestSize.Level1) GetInstance().GetAccessControlProfile(resultRet, 1, 1, profile); EXPECT_NE(ret, DP_SUCCESS); + AccessControlProfile aclProfile; ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().DeleteAccessControlProfileCheck(resultRet); + GetInstance().DeleteAccessControlProfileCheck(aclProfile); EXPECT_NE(ret, DP_SUCCESS); ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: @@ -179,33 +180,30 @@ HWTEST_F(TrustProfileManagerTest, Convert_001, TestSize.Level1) shared_ptr resultRet = OHOS::DistributedDeviceProfile::TrustProfileManager:: GetInstance().GetResultSet("122", { ValueObject(1) }); TrustDeviceProfile trustProfile; - int32_t ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().ConvertToTrustDeviceProfile(resultRet, trustProfile); + int32_t ret = ProfileUtils::ConvertToTrustDeviceProfile(resultRet, trustProfile); EXPECT_NE(ret, DP_SUCCESS); Accessee accessee; - ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().ConvertToAccessee(resultRet, accessee); + ret = ProfileUtils::ConvertToAccessee(resultRet, accessee); EXPECT_NE(ret, DP_SUCCESS); Accesser accesser; - ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().ConvertToAccesser(resultRet, accesser); + ret = ProfileUtils::ConvertToAccesser(resultRet, accesser); EXPECT_NE(ret, DP_SUCCESS); AccessControlProfile profile; - ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().ConvertToAccessControlProfile(resultRet, profile); + ret = ProfileUtils::ConvertToAccessControlProfile(resultRet, profile); EXPECT_NE(ret, DP_SUCCESS); + AccessControlProfile oldProfile; profile.SetAccessControlId(666); ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().UpdateAclCheck(profile); + GetInstance().UpdateAclCheck(profile, oldProfile); EXPECT_NE(ret, DP_SUCCESS); profile.SetTrustDeviceId("4546456"); ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().UpdateAclCheck(profile); + GetInstance().UpdateAclCheck(profile, oldProfile); EXPECT_NE(ret, DP_SUCCESS); } @@ -290,8 +288,7 @@ HWTEST_F(TrustProfileManagerTest, PutTrustDeviceProfile_001, TestSize.Level1) profile.SetBindLevel(1); TrustDeviceProfile trustProfile; - OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().ConvertToTrustDeviceProfile(profile, trustProfile); + ProfileUtils::ConvertToTrustDeviceProfile(profile, trustProfile); int32_t ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: GetInstance().PutTrustDeviceProfile(trustProfile); EXPECT_NE(ret, DP_SUCCESS); @@ -1489,12 +1486,14 @@ HWTEST_F(TrustProfileManagerTest, RdbStoreIsNullptr_002, TestSize.Level1) GetInstance().SetAccesseeId(profile); EXPECT_NE(ret, DP_SUCCESS); + profile.SetAccessControlId(1); + bool isAcerOrAceeExist = false; ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().UpdateAccesserProfile(1, profile); + GetInstance().UpdateAccesserProfile(profile, isAcerOrAceeExist); EXPECT_NE(ret, DP_SUCCESS); ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().UpdateAccesseeProfile(1, profile); + GetInstance().UpdateAccesseeProfile(profile, isAcerOrAceeExist); EXPECT_NE(ret, DP_SUCCESS); } @@ -1592,21 +1591,54 @@ HWTEST_F(TrustProfileManagerTest, RdbStoreIsNullptr_004, TestSize.Level1) GetInstance().GetAccessControlProfilesByDeviceId(resultSet, 1, 1, "1", profiles); EXPECT_NE(ret, DP_SUCCESS); + Accesser accesser; ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().DeleteAccesserCheck(1); + GetInstance().DeleteAccesserCheck(1, accesser); EXPECT_NE(ret, DP_SUCCESS); + Accessee accessee; ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().DeleteAccesseeCheck(1); + GetInstance().DeleteAccesseeCheck(1, accessee); EXPECT_NE(ret, DP_SUCCESS); + AccessControlProfile oldProfile; ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: - GetInstance().UpdateAclCheck(profile); + GetInstance().UpdateAclCheck(profile, oldProfile); EXPECT_NE(ret, DP_SUCCESS); ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: GetInstance().DeleteTrustDeviceCheck(profile); EXPECT_NE(ret, DP_SUCCESS); } + +/* + * @tc.name: Check_001 + * @tc.desc: Normal testCase of TrustProfileManagerTest for Check + * @tc.type: FUNC + */ +HWTEST_F(TrustProfileManagerTest, Check_001, TestSize.Level1) +{ + AccessControlProfile profile; + profile.SetAccessControlId(1); + profile.SetAccesserId(1); + profile.SetAccesseeId(1); + profile.GetAccessee().SetAccesseeDeviceId("123456"); + profile.GetAccessee().SetAccesseeUserId(6666); + profile.SetStatus(0); + bool ret = OHOS::DistributedDeviceProfile::TrustProfileManager:: + GetInstance().CheckUserIdExists(profile); + EXPECT_EQ(ret, false); + + int32_t count = OHOS::DistributedDeviceProfile::TrustProfileManager:: + GetInstance().GetConformCount("123456", 6666); + EXPECT_EQ(count, DP_GET_RESULTSET_FAIL); + + AccessControlProfile oldProfile; + oldProfile.SetStatus(1); + profile.SetTrustDeviceId("123456"); + int32_t result = OHOS::DistributedDeviceProfile::TrustProfileManager:: + GetInstance().NotifyCheck(profile, oldProfile); + EXPECT_EQ(result, DP_SUCCESS); +} } // namespace DistributedDeviceProfile } // namespace OHOS