From daebce0bb347b49b18c7c80471615ee4fef588ac Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 24 Oct 2024 20:26:54 +0800 Subject: [PATCH 1/9] =?UTF-8?q?DP=EF=BC=8CSP=EF=BC=8CCP=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../distributed_device_profile_constants.h | 1 + .../interfaces/characteristic_profile.h | 16 +++++++++ common/include/interfaces/device_profile.h | 10 +++++- common/include/interfaces/service_profile.h | 8 +++++ .../src/interfaces/characteristic_profile.cpp | 31 ++++++++++++++-- common/src/interfaces/device_profile.cpp | 34 ++++++++++++++++-- common/src/interfaces/service_profile.cpp | 36 +++++++++++++++++-- 7 files changed, 129 insertions(+), 7 deletions(-) diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 2e6d6339..05f4174a 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -137,6 +137,7 @@ const std::string DEV_PREFIX = "dev"; const std::string SVR_PREFIX = "svr"; const std::string CHAR_PREFIX = "char"; const std::string USER_ID = "user_id"; +const std::string IS_MULTI_USER = "is_muilt_user"; const std::string TOKEN_ID = "token_id"; const std::string ALL_PROC = "all"; constexpr int32_t NUM_1 = 1; diff --git a/common/include/interfaces/characteristic_profile.h b/common/include/interfaces/characteristic_profile.h index 4b71bd8d..ff9ec9c0 100644 --- a/common/include/interfaces/characteristic_profile.h +++ b/common/include/interfaces/characteristic_profile.h @@ -31,6 +31,16 @@ public: characteristicKey_(characteristicKey), characteristicValue_(characteristicValue) {} + CharacteristicProfile(const std::string& deviceId, const std::string& serviceName, + const std::string& characteristicKey, const std::string& characteristicValue, const bool isMuitUser, + const int32_t userId) + : deviceId_(deviceId), + serviceName_(serviceName), + characteristicKey_(characteristicKey), + characteristicValue_(characteristicValue), + isMuitUser_(isMuitUser), + userId_(userId) + {} CharacteristicProfile() = default; ~CharacteristicProfile() = default; @@ -42,6 +52,10 @@ public: void SetCharacteristicKey(const std::string& characteristicId); std::string GetCharacteristicValue() const; void SetCharacteristicValue(const std::string& characteristicValue); + bool GetIsMuitUser() const; + void SetIsMuitUser(bool isMuitUser); + int32_t GetUserId() const; + void SetUserId(int32_t userId); bool Marshalling(MessageParcel& parcel) const override; bool UnMarshalling(MessageParcel& parcel) override; bool operator!=(const CharacteristicProfile& charProfile) const; @@ -52,6 +66,8 @@ private: std::string serviceName_ = ""; std::string characteristicKey_ = ""; std::string characteristicValue_ = ""; + bool isMuitUser_ = false; + int32_t userId_ = -1; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/include/interfaces/device_profile.h b/common/include/interfaces/device_profile.h index c7244cc9..f23a8be4 100644 --- a/common/include/interfaces/device_profile.h +++ b/common/include/interfaces/device_profile.h @@ -35,7 +35,9 @@ public: osSysCap_(""), osApiLevel_(0), osVersion_(""), - osType_(0) + osType_(0), + isMuitUser_(false), + userId_(-1) {} ~DeviceProfile() = default; @@ -61,6 +63,10 @@ public: void SetOsVersion(const std::string& osVersion); int32_t GetOsType() const; void SetOsType(int32_t osType); + bool GetIsMuitUser() const; + void SetIsMuitUser(bool isMuitUser); + int32_t GetUserId() const; + void SetUserId(int32_t userId); bool Marshalling(MessageParcel& parcel) const override; bool UnMarshalling(MessageParcel& parcel) override; bool operator!=(const DeviceProfile& deviceProfile) const; @@ -79,6 +85,8 @@ private: int32_t osApiLevel_; std::string osVersion_; int32_t osType_; + bool isMuitUser_; + int32_t userId_; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/include/interfaces/service_profile.h b/common/include/interfaces/service_profile.h index 850abf5e..2b310a8f 100644 --- a/common/include/interfaces/service_profile.h +++ b/common/include/interfaces/service_profile.h @@ -25,6 +25,8 @@ namespace DistributedDeviceProfile { class ServiceProfile : public DpParcel { public: ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType); + ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType, + const bool isMuitUser, const int32_t userId); ServiceProfile(); ~ServiceProfile(); @@ -34,6 +36,10 @@ public: void SetServiceName(const std::string& serviceName); std::string GetServiceType() const; void SetServiceType(const std::string& serviceType); + bool GetIsMuitUser() const; + void SetIsMuitUser(bool isMuitUser); + int32_t GetUserId() const; + void SetUserId(int32_t userId); bool Marshalling(MessageParcel& parcel) const override; bool UnMarshalling(MessageParcel& parcel) override; bool operator!=(const ServiceProfile& serviceProfile) const; @@ -43,6 +49,8 @@ private: std::string deviceId_ = ""; std::string serviceName_ = ""; std::string serviceType_ = ""; + bool isMuitUser_ = false; + int32_t userId_ = -1; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/characteristic_profile.cpp b/common/src/interfaces/characteristic_profile.cpp index 8cc41bdb..87ae47b1 100644 --- a/common/src/interfaces/characteristic_profile.cpp +++ b/common/src/interfaces/characteristic_profile.cpp @@ -64,12 +64,34 @@ void CharacteristicProfile::SetCharacteristicValue(const std::string& characteri characteristicValue_ = characteristicValue; } +bool CharacteristicProfile::GetIsMuitUser() const +{ + return isMuitUser_; +} + +void CharacteristicProfile::SetIsMuitUser(bool isMuitUser) +{ + isMuitUser_ = isMuitUser; +} + +int32_t CharacteristicProfile::GetUserId() const +{ + return userId_; +} + +void CharacteristicProfile::SetUserId(int32_t userId) +{ + userId_ = userId; +} + bool CharacteristicProfile::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, deviceId_, false); WRITE_HELPER_RET(parcel, String, serviceName_, false); WRITE_HELPER_RET(parcel, String, characteristicKey_, false); WRITE_HELPER_RET(parcel, String, characteristicValue_, false); + WRITE_HELPER_RET(parcel, Bool, isMuitUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); return true; } @@ -79,6 +101,8 @@ bool CharacteristicProfile::UnMarshalling(MessageParcel& parcel) READ_HELPER_RET(parcel, String, serviceName_, false); READ_HELPER_RET(parcel, String, characteristicKey_, false); READ_HELPER_RET(parcel, String, characteristicValue_, false); + READ_HELPER_RET(parcel, Bool, isMuitUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); return true; } @@ -86,7 +110,8 @@ bool CharacteristicProfile::operator!=(const CharacteristicProfile& charProfile) { bool isNotEqual = (deviceId_ != charProfile.GetDeviceId() || serviceName_ != charProfile.GetServiceName() || characteristicKey_ != charProfile.GetCharacteristicKey() || - characteristicValue_ != charProfile.GetCharacteristicValue()); + characteristicValue_ != charProfile.GetCharacteristicValue() || isMuitUser_ != charProfile.GetIsMuitUser() || + userId_ != charProfile.GetUserId()); if (isNotEqual) { return true; } else { @@ -104,6 +129,8 @@ std::string CharacteristicProfile::dump() const cJSON_AddStringToObject(json, DEVICE_ID.c_str(), ProfileUtils::GetAnonyString(deviceId_).c_str()); cJSON_AddStringToObject(json, SERVICE_NAME.c_str(), serviceName_.c_str()); cJSON_AddStringToObject(json, CHARACTERISTIC_KEY.c_str(), characteristicKey_.c_str()); + cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); + cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_); if (characteristicKey_ == SWITCH_STATUS) { cJSON_AddStringToObject(json, CHARACTERISTIC_VALUE.c_str(), characteristicValue_.c_str()); } else { @@ -122,4 +149,4 @@ std::string CharacteristicProfile::dump() const return jsonStr; } } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/src/interfaces/device_profile.cpp b/common/src/interfaces/device_profile.cpp index 1e0b0df4..142eb788 100644 --- a/common/src/interfaces/device_profile.cpp +++ b/common/src/interfaces/device_profile.cpp @@ -134,6 +134,26 @@ void DeviceProfile::SetOsSysCap(const std::string& osSysCap) osSysCap_ = osSysCap; } +bool DeviceProfile::GetIsMuitUser() const +{ + return isMuitUser_; +} + +void DeviceProfile::SetIsMuitUser(bool isMuitUser) +{ + isMuitUser_ = isMuitUser; +} + +int32_t DeviceProfile::GetUserId() const +{ + return userId_; +} + +void DeviceProfile::SetUserId(int32_t userId) +{ + userId_ = userId; +} + bool DeviceProfile::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, deviceId_, false); @@ -147,6 +167,8 @@ bool DeviceProfile::Marshalling(MessageParcel& parcel) const WRITE_HELPER_RET(parcel, Int32, osApiLevel_, false); WRITE_HELPER_RET(parcel, String, osVersion_, false); WRITE_HELPER_RET(parcel, Int32, osType_, false); + WRITE_HELPER_RET(parcel, Bool, isMuitUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); return true; } @@ -163,6 +185,8 @@ bool DeviceProfile::UnMarshalling(MessageParcel& parcel) READ_HELPER_RET(parcel, Int32, osApiLevel_, false); READ_HELPER_RET(parcel, String, osVersion_, false); READ_HELPER_RET(parcel, Int32, osType_, false); + READ_HELPER_RET(parcel, Bool, isMuitUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); return true; } @@ -173,7 +197,8 @@ bool DeviceProfile::operator!=(const DeviceProfile& deviceProfile) const manufactureName_ != deviceProfile.GetManufactureName() || deviceModel_ != deviceProfile.GetDeviceModel() || storageCapability_ != deviceProfile.GetStorageCapability() || osSysCap_ != deviceProfile.GetOsSysCap() || osApiLevel_ != deviceProfile.GetOsApiLevel() || osVersion_ != deviceProfile.GetOsVersion() || osType_ != - deviceProfile.GetOsType()); + deviceProfile.GetOsType() || isMuitUser_ != deviceProfile.GetIsMuitUser() || userId_ != + deviceProfile.GetUserId()); if (isNotEqual) { return true; } else { @@ -199,6 +224,8 @@ std::string DeviceProfile::dump() const cJSON_AddNumberToObject(json, OS_API_LEVEL.c_str(), osApiLevel_); cJSON_AddStringToObject(json, OS_VERSION.c_str(), osVersion_.c_str()); cJSON_AddNumberToObject(json, OS_TYPE.c_str(), osType_); + cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); + cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); @@ -234,6 +261,9 @@ std::string DeviceProfile::AnnoymizeDump() const ProfileUtils::GetAnonyString(osVersion_).c_str()); cJSON_AddStringToObject(json, OS_TYPE.c_str(), ProfileUtils::GetAnonyString(std::to_string(osType_)).c_str()); + cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); + cJSON_AddStringToObject(json, USER_ID.c_str(), + ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str()); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); @@ -246,4 +276,4 @@ std::string DeviceProfile::AnnoymizeDump() const return jsonStr; } } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/src/interfaces/service_profile.cpp b/common/src/interfaces/service_profile.cpp index 97719f4c..d44c90b8 100644 --- a/common/src/interfaces/service_profile.cpp +++ b/common/src/interfaces/service_profile.cpp @@ -29,6 +29,11 @@ ServiceProfile::ServiceProfile(const std::string& deviceId, const std::string& s const std::string& serviceType) : deviceId_(deviceId), serviceName_(serviceName), serviceType_(serviceType) { } +ServiceProfile::ServiceProfile(const std::string& deviceId, const std::string& serviceName, + const std::string& serviceType, const bool isMuitUser, const int32_t userId): + deviceId_(deviceId), serviceName_(serviceName), serviceType_(serviceType), isMuitUser_(isMuitUser), userId_(userId) +{ +} ServiceProfile::ServiceProfile() { } @@ -67,11 +72,33 @@ void ServiceProfile::SetServiceType(const std::string& serviceType) serviceType_ = serviceType; } +bool ServiceProfile::GetIsMuitUser() const +{ + return isMuitUser_; +} + +void ServiceProfile::SetIsMuitUser(bool isMuitUser) +{ + isMuitUser_ = isMuitUser; +} + +int32_t ServiceProfile::GetUserId() const +{ + return userId_; +} + +void ServiceProfile::SetUserId(int32_t userId) +{ + userId_ = userId; +} + bool ServiceProfile::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, deviceId_, false); WRITE_HELPER_RET(parcel, String, serviceName_, false); WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, Bool, isMuitUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); return true; } @@ -80,13 +107,16 @@ bool ServiceProfile::UnMarshalling(MessageParcel& parcel) READ_HELPER_RET(parcel, String, deviceId_, false); READ_HELPER_RET(parcel, String, serviceName_, false); READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, Bool, isMuitUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); return true; } bool ServiceProfile::operator!=(const ServiceProfile& serviceProfile) const { bool isNotEqual = (deviceId_ != serviceProfile.GetDeviceId() || serviceName_ != serviceProfile.GetServiceName() || - serviceType_ != serviceProfile.GetServiceType()); + serviceType_ != serviceProfile.GetServiceType() || isMuitUser_ != serviceProfile.GetIsMuitUser() || + userId_ != serviceProfile.GetUserId()); if (isNotEqual) { return true; } else { @@ -104,6 +134,8 @@ std::string ServiceProfile::dump() const cJSON_AddStringToObject(json, DEVICE_ID.c_str(), ProfileUtils::GetAnonyString(deviceId_).c_str()); cJSON_AddStringToObject(json, SERVICE_NAME.c_str(), serviceName_.c_str()); cJSON_AddStringToObject(json, SERVICE_TYPE.c_str(), serviceType_.c_str()); + cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); + cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); @@ -116,4 +148,4 @@ std::string ServiceProfile::dump() const return jsonStr; } } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee From 9fbf40c8f070250c089403f5b94dae2f9f6ec663 Mon Sep 17 00:00:00 2001 From: guoyi Date: Thu, 24 Oct 2024 20:30:52 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distributed_device_profile_constants.h | 2 ++ common/include/interfaces/dp_subscribe_info.h | 13 ++++++----- common/src/interfaces/dp_subscribe_info.cpp | 22 +++++++++++++++---- .../listener/kv_data_change_listener.cpp | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 2e6d6339..ca181d0d 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -142,6 +142,8 @@ const std::string ALL_PROC = "all"; constexpr int32_t NUM_1 = 1; constexpr int32_t NUM_2 = 2; constexpr int32_t NUM_3 = 3; +constexpr int32_t NUM_4 = 4; +constexpr int32_t DEFAULT_USER_ID = -1; constexpr uint32_t NUM_1U = 1; constexpr uint32_t NUM_8U = 8; constexpr uint16_t CUR_SWITCH_LEN = 3; diff --git a/common/include/interfaces/dp_subscribe_info.h b/common/include/interfaces/dp_subscribe_info.h index a95a0dc4..2429d262 100644 --- a/common/include/interfaces/dp_subscribe_info.h +++ b/common/include/interfaces/dp_subscribe_info.h @@ -29,20 +29,23 @@ namespace DistributedDeviceProfile { class SubscribeInfo : public DpParcel { public: SubscribeInfo(int32_t saId, const std::string& subscribeKey, - std::unordered_set subscribeChangeTypes, sptr profileChangeListener); + std::unordered_set subscribeChangeTypes, sptr profileChangeListener, + int32_t userId = DEFAULT_USER_ID); SubscribeInfo(); ~SubscribeInfo(); int32_t GetSaId() const; void SetSaId(int32_t saId); std::string GetSubscribeKey() const; - void SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute); + void SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute, + int32_t userId = DEFAULT_USER_ID); void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, - const std::string& serviceAttribute); + const std::string& serviceAttribute, int32_t userId = DEFAULT_USER_ID); void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey, const std::string& characteristicAttribute); + const std::string& characteristicKey, const std::string& characteristicAttribute, + int32_t userId = DEFAULT_USER_ID); // subscribeTrustDeviceProfile - void SetSubscribeKey(const std::string& subscribeKey); + void SetSubscribeKey(const std::string& subscribeKey, int32_t userId = DEFAULT_USER_ID); sptr GetListener() const; void SetListener(sptr listener); std::unordered_set GetProfileChangeTypes() const; diff --git a/common/src/interfaces/dp_subscribe_info.cpp b/common/src/interfaces/dp_subscribe_info.cpp index 561104c9..f4884eec 100644 --- a/common/src/interfaces/dp_subscribe_info.cpp +++ b/common/src/interfaces/dp_subscribe_info.cpp @@ -27,10 +27,14 @@ namespace { const std::string TAG = "SubscribeInfo"; } SubscribeInfo::SubscribeInfo(int32_t saId, const std::string& subscribeKey, - std::unordered_set subscribeChangeTypes, sptr profileChangeListener) + std::unordered_set subscribeChangeTypes, sptr profileChangeListener, + int32_t userId = DEFAULT_USER_ID) { this->saId_ = saId; this->subscribeKey_ = subscribeKey; + if (userId != DEFAULT_USER_ID) { + this->subscribeKey_ = this->subscribeKey_ + SEPARATOR + userId; + } this->subscribeChangeTypes_ = subscribeChangeTypes; if (profileChangeListener == nullptr) { HILOGI("constructor!"); @@ -61,21 +65,31 @@ void SubscribeInfo::SetSaId(int32_t saId) saId_ = saId; } -void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute) +void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute, + int32_t userId = DEFAULT_USER_ID) { subscribeKey_ = DEV_PREFIX + SEPARATOR + deviceId + SEPARATOR + deviceAttribute; + if (userId != DEFAULT_USER_ID) { + subscribeKey_ = subscribeKey_ + SEPARATOR + userId; + } } void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, - const std::string& serviceAttribute) + const std::string& serviceAttribute, int32_t userId = DEFAULT_USER_ID) { subscribeKey_ = SVR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + serviceAttribute; + if (userId != DEFAULT_USER_ID) { + subscribeKey_ = subscribeKey_ + SEPARATOR + userId; + } } void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey, const std::string& characteristicAttribute) + const std::string& characteristicKey, const std::string& characteristicAttribute, int32_t userId = DEFAULT_USER_ID) { subscribeKey_ = CHAR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + characteristicKey + SEPARATOR + characteristicAttribute; + if (userId != DEFAULT_USER_ID) { + subscribeKey_ = subscribeKey_ + SEPARATOR + userId; + } } std::string SubscribeInfo::GetSubscribeKey() const diff --git a/services/core/src/deviceprofilemanager/listener/kv_data_change_listener.cpp b/services/core/src/deviceprofilemanager/listener/kv_data_change_listener.cpp index 0a33b1f4..4dc19487 100644 --- a/services/core/src/deviceprofilemanager/listener/kv_data_change_listener.cpp +++ b/services/core/src/deviceprofilemanager/listener/kv_data_change_listener.cpp @@ -134,7 +134,7 @@ void KvDataChangeListener::FilterEntries(const std::vector HILOGW("%{public}s is invalid dbKey", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str()); continue; } - if (res[0] == CHAR_PREFIX && res.back() == CHARACTERISTIC_KEY) { + if (res[0] == CHAR_PREFIX && res.size() > NUM_3 && res[NUM_3] == CHARACTERISTIC_KEY) { HILOGD("%{public}s is charProfileKey", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str()); continue; } -- Gitee From 1e92e7a2987c8ec63cc8d300186f8ef18613f34a Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 25 Oct 2024 15:33:10 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenshuo --- bundle.json | 3 ++- .../distributed_device_profile_errors.h | 1 + services/core/BUILD.gn | 4 ++++ .../dp_account_common_event.h | 0 services/core/include/utils/profile_cache.h | 4 ++++ .../dp_account_common_event.cpp | 0 services/core/src/utils/profile_cache.cpp | 21 +++++++++++++++++++ 7 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 services/core/include/publishcommonevent/dp_account_common_event.h create mode 100644 services/core/src/publishcommonevent/dp_account_common_event.cpp diff --git a/bundle.json b/bundle.json index 48740ca2..8f8cc673 100644 --- a/bundle.json +++ b/bundle.json @@ -42,7 +42,8 @@ "dmsfwk", "device_manager", "init", - "relational_store" + "relational_store", + "os_account" ], "third_party": [ "json" diff --git a/common/include/constants/distributed_device_profile_errors.h b/common/include/constants/distributed_device_profile_errors.h index a5a90612..20015580 100644 --- a/common/include/constants/distributed_device_profile_errors.h +++ b/common/include/constants/distributed_device_profile_errors.h @@ -151,6 +151,7 @@ constexpr int32_t DP_NULLPTR = 98566273; constexpr int32_t DP_SUBSCRIBE_INITED_FALI = 98566274; constexpr int32_t DP_GET_DEVICE_ENTRIES_FAIL = 98566275; constexpr int32_t DP_RDB_DATABASE_RESTORE_FAIL = 98566276; +constexpr int32_t DP_GET_FOREGROUND_ID_FAIL = 98566277; } // namespace DistributedDeviceProfile } // namespace OHOS #endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ERRORS_H diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 17b1b110..6d19178a 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -105,6 +105,8 @@ ohos_shared_library("distributed_device_profile_svr") { "access_token:libaccesstoken_sdk", "cJSON:cjson", "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "device_auth:deviceauth_sdk", "device_manager:devicemanagersdk", @@ -116,6 +118,8 @@ ohos_shared_library("distributed_device_profile_svr") { "init:libbegetutil", "ipc:ipc_core", "kv_store:distributeddata_inner", + "os_account:libaccountkits", + "os_account:os_account_innerkits", "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/core/include/publishcommonevent/dp_account_common_event.h b/services/core/include/publishcommonevent/dp_account_common_event.h new file mode 100644 index 00000000..e69de29b diff --git a/services/core/include/utils/profile_cache.h b/services/core/include/utils/profile_cache.h index f78040dc..ad467996 100644 --- a/services/core/include/utils/profile_cache.h +++ b/services/core/include/utils/profile_cache.h @@ -94,7 +94,11 @@ private: int32_t RefreshCharProfileCache(const std::vector& characteristicProfiles); int32_t RefreshStaticProfileCache(const std::unordered_map& staticProfiles); + int32_t GetForegroundId(); + private: + std:mutex foregroundIdMutex_; + int32_t foregroundId_ = -1; std::string localNetworkId_; std::mutex switchMutex_; uint32_t curLocalSwitch_ = 0x0000; diff --git a/services/core/src/publishcommonevent/dp_account_common_event.cpp b/services/core/src/publishcommonevent/dp_account_common_event.cpp new file mode 100644 index 00000000..e69de29b diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index 269479e7..b49ac1d0 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -24,6 +24,7 @@ #include "content_sensor_manager_utils.h" #include "distributed_device_profile_errors.h" #include "device_profile_manager.h" +#include "os_account_manager.h" #include "profile_utils.h" #include "static_profile_manager.h" #include "switch_profile_manager.h" @@ -51,6 +52,13 @@ int32_t ProfileCache::Init() HILOGW("GetTrustedDeviceList failed, res: %{public}d", res); return DP_SUCCESS; } + { + std::lock_guard lock(foregroundIdMutex_); + foregroundId_ = GetForegroundId(); + if (foregroundId_ == DP_GET_FOREGROUND_ID_FAIL) { + LOGE("GetForegroundId id failed, ForegroundId: %{public}d", foregroundId_); + } + } std::string udid = EMPTY_STRING; std::lock_guard lock(onlineDeviceLock_); @@ -833,5 +841,18 @@ std::string ProfileCache::GetLocalUuid() localUuid_ = localUuid; return localUuid; } + +int32_t ProfileCache::GetForegroundId() +{ + int32_t foregroundId; + int32_t res = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(foregroundId); + if (res != DP_SUCCESS) { + LOGE("GetForegroundId failed, res:%{public}d", res); + return DP_GET_FOREGROUND_ID_FAIL; + } + LOGI("current foregroundId = %{public}d", foregroundId); + return foregroundId; +} + } // namespace DeviceProfile } // namespace OHOS -- Gitee From 13453783b0862efa05acde19be383a6f89d77e90 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Sat, 26 Oct 2024 15:18:44 +0800 Subject: [PATCH 4/9] =?UTF-8?q?PutServiceProfile=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/utils/profile_utils.h | 4 ++++ common/src/utils/profile_utils.cpp | 19 ++++++++++++++++++- services/core/include/utils/profile_cache.h | 3 +-- .../device_profile_manager.cpp | 12 +++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index a80ba25c..7bb4b539 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -70,6 +70,8 @@ public: static int32_t AccesseeToEntries(const AccessControlProfile& aclProfile, ValuesBucket& values); static int32_t DeviceProfileToEntries(const DeviceProfile& profile, std::map& values); static int32_t ServiceProfileToEntries(const ServiceProfile& profile, std::map& values); + static int32_t ServiceProfileToMuiltUserEntries(const ServiceProfile& profile, std::map& values); static int32_t CharacteristicProfileToEntries(const CharacteristicProfile& profile, std::map& values); static int32_t EntriesToTrustDeviceProfile(const ValuesBucket& values, TrustDeviceProfile& profile); @@ -80,6 +82,8 @@ public: static int32_t EntriesToServiceProfile(std::map values, ServiceProfile& profile); static int32_t EntriesToCharProfile(std::map values, CharacteristicProfile& profile); static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty); + static std::string GenerateMuiltUserDBKey(const std::string& profileKey, const std::string& profileProperty, + int32_t userId); static std::string GetProfileKey(const std::string& dbKey); static std::string GetDeviceIdByDBKey(const std::string& dbKey); static std::string GetServiceNameByDBKey(const std::string& dbKey); diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index a3e87d3d..1ec51591 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -479,8 +479,19 @@ int32_t ProfileUtils::ServiceProfileToEntries(const ServiceProfile& profile, std return DP_SUCCESS; } +int32_t ProfileUtils::ServiceProfileToMuiltUserEntries(const ServiceProfile& profile, std::map& values) +{ + std::string serviceName = CheckAndAddOhSuffix(profile.GetServiceName(), true); + std::string serviceProfileKey = GenerateServiceProfileKey(profile.GetDeviceId(), serviceName); + // value not need add OH suffix + values[GenerateMuiltUserDBKey(serviceProfileKey, SERVICE_NAME, profile.GetUserId())] = profile.GetServiceName(); + values[GenerateMuiltUserDBKey(serviceProfileKey, SERVICE_TYPE, profile.GetUserId())] = profile.GetServiceType(); + return DP_SUCCESS; +} + int32_t ProfileUtils::CharacteristicProfileToEntries(const CharacteristicProfile& profile, - std::map& values) + std::map& values) { std::string serviceName = CheckAndAddOhSuffix(profile.GetServiceName(), true); std::string charProfileKey = GenerateCharProfileKey(profile.GetDeviceId(), serviceName, @@ -690,6 +701,12 @@ std::string ProfileUtils::GenerateDBKey(const std::string& profileKey, const std return profileKey + SEPARATOR + profileProperty; } +std::string ProfileUtils::GenerateMuiltUserDBKey(const std::string& profileKey, const std::string& profileProperty, + int32_t userId) +{ + return profileKey + SEPARATOR + profileProperty + SEPARATOR + std::to_string(userId); +} + std::string ProfileUtils::GetProfileProperty(const std::string& dbKey) { if (dbKey.length() == 0 || dbKey.length() > MAX_STRING_LEN) { diff --git a/services/core/include/utils/profile_cache.h b/services/core/include/utils/profile_cache.h index ad467996..5d2dea2f 100644 --- a/services/core/include/utils/profile_cache.h +++ b/services/core/include/utils/profile_cache.h @@ -89,13 +89,12 @@ public: std::string GetLocalUdid(); std::string GetLocalNetworkId(); std::string GetLocalUuid(); + int32_t GetForegroundId(); private: int32_t RefreshCharProfileCache(const std::vector& characteristicProfiles); int32_t RefreshStaticProfileCache(const std::unordered_map& staticProfiles); - int32_t GetForegroundId(); - private: std:mutex foregroundIdMutex_; int32_t foregroundId_ = -1; diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index 2a2d7023..c1fe67a6 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -138,7 +138,17 @@ int32_t DeviceProfileManager::PutServiceProfile(const ServiceProfile& servicePro return DP_INVALID_PARAMS; } std::map entries; - ProfileUtils::ServiceProfileToEntries(serviceProfile, entries); + if (serviceProfile.GetIsMuitUser()) { + ProfileUtils::ServiceProfileToMuiltUserEntries(serviceProfile, entries); + int32_t currentUserId = ProfileCache::GetInstance().GetForegroundId(); + if (currentUserId == serviceProfile.GetUserId()) { + ProfileUtils::ServiceProfileToEntries(serviceProfile, entries); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::ServiceProfileToEntries(serviceProfile, entries); + } if (isFirst_.load()) { AddToPutTempCache(entries); return DP_SUCCESS; -- Gitee From a01580935ae3d4c4efee9a2cf5010460587a4889 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Sat, 26 Oct 2024 16:38:01 +0800 Subject: [PATCH 5/9] =?UTF-8?q?KV=20Put=E6=8E=A5=E5=8F=A3=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=A4=9A=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/utils/profile_utils.h | 15 ++-- common/src/utils/profile_utils.cpp | 75 +++++++++++-------- .../device_profile_manager.cpp | 49 ++++++++++-- 3 files changed, 94 insertions(+), 45 deletions(-) diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index 7bb4b539..6b00ccc6 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -68,12 +68,12 @@ public: static int32_t AccessControlProfileToEntries(const AccessControlProfile& profile, ValuesBucket& values); static int32_t AccesserToEntries(const AccessControlProfile& aclProfile, ValuesBucket& values); static int32_t AccesseeToEntries(const AccessControlProfile& aclProfile, ValuesBucket& values); - static int32_t DeviceProfileToEntries(const DeviceProfile& profile, std::map& values); - static int32_t ServiceProfileToEntries(const ServiceProfile& profile, std::map& values); - static int32_t ServiceProfileToMuiltUserEntries(const ServiceProfile& profile, std::map& values); + static int32_t DeviceProfileToEntries(const DeviceProfile& profile, std::map& values, + bool isMuiltUser = false); + static int32_t ServiceProfileToEntries(const ServiceProfile& profile, std::map& values, + bool isMuiltUser = false); static int32_t CharacteristicProfileToEntries(const CharacteristicProfile& profile, - std::map& values); + std::map& values, bool isMuiltUser = false); static int32_t EntriesToTrustDeviceProfile(const ValuesBucket& values, TrustDeviceProfile& profile); static int32_t EntriesToAccessControlProfile(const ValuesBucket& values, AccessControlProfile& profile); static int32_t EntriesToAccesser(const ValuesBucket& values, Accesser& accesser); @@ -81,9 +81,8 @@ public: static int32_t EntriesToDeviceProfile(std::map values, DeviceProfile& profile); static int32_t EntriesToServiceProfile(std::map values, ServiceProfile& profile); static int32_t EntriesToCharProfile(std::map values, CharacteristicProfile& profile); - static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty); - static std::string GenerateMuiltUserDBKey(const std::string& profileKey, const std::string& profileProperty, - int32_t userId); + static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty, + int32_t userId = -1); static std::string GetProfileKey(const std::string& dbKey); static std::string GetDeviceIdByDBKey(const std::string& dbKey); static std::string GetServiceNameByDBKey(const std::string& dbKey); diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 1ec51591..225106ca 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -458,46 +458,59 @@ int32_t ProfileUtils::AccesseeToEntries(const AccessControlProfile& aclProfile, return DP_SUCCESS; } -int32_t ProfileUtils::DeviceProfileToEntries(const DeviceProfile& profile, std::map& values) +int32_t ProfileUtils::DeviceProfileToEntries(const DeviceProfile& profile, std::map& values, + bool isMuiltUser) { std::string deviceProfileKey = GenerateDeviceProfileKey(profile.GetDeviceId()); - values[GenerateDBKey(deviceProfileKey, OS_SYS_CAPACITY)] = profile.GetOsSysCap(); - values[GenerateDBKey(deviceProfileKey, OS_VERSION)] = profile.GetOsVersion(); - values[GenerateDBKey(deviceProfileKey, OS_TYPE)] = std::to_string(profile.GetOsType()); - values[GenerateDBKey(deviceProfileKey, OS_VERSION + OH_PROFILE_SUFFIX)] = profile.GetOsVersion(); - values[GenerateDBKey(deviceProfileKey, OS_TYPE + OH_PROFILE_SUFFIX)] = std::to_string(profile.GetOsType()); - return DP_SUCCESS; -} - -int32_t ProfileUtils::ServiceProfileToEntries(const ServiceProfile& profile, std::map& values) -{ - std::string serviceName = CheckAndAddOhSuffix(profile.GetServiceName(), true); - std::string serviceProfileKey = GenerateServiceProfileKey(profile.GetDeviceId(), serviceName); - // value not need add OH suffix - values[GenerateDBKey(serviceProfileKey, SERVICE_NAME)] = profile.GetServiceName(); - values[GenerateDBKey(serviceProfileKey, SERVICE_TYPE)] = profile.GetServiceType(); + if (isMuiltUser) { + values[GenerateDBKey(deviceProfileKey, OS_SYS_CAPACITY, profile.GetUserId())] = profile.GetOsSysCap(); + values[GenerateDBKey(deviceProfileKey, OS_VERSION, profile.GetUserId())] = profile.GetOsVersion(); + values[GenerateDBKey(deviceProfileKey, OS_TYPE, profile.GetUserId())] = std::to_string(profile.GetOsType()); + values[GenerateDBKey(deviceProfileKey, OS_VERSION + OH_PROFILE_SUFFIX, profile.GetUserId())] = + profile.GetOsVersion(); + values[GenerateDBKey(deviceProfileKey, OS_TYPE + OH_PROFILE_SUFFIX, profile.GetUserId())] = + std::to_string(profile.GetOsType()); + } else { + values[GenerateDBKey(deviceProfileKey, OS_SYS_CAPACITY)] = profile.GetOsSysCap(); + values[GenerateDBKey(deviceProfileKey, OS_VERSION)] = profile.GetOsVersion(); + values[GenerateDBKey(deviceProfileKey, OS_TYPE)] = std::to_string(profile.GetOsType()); + values[GenerateDBKey(deviceProfileKey, OS_VERSION + OH_PROFILE_SUFFIX)] = profile.GetOsVersion(); + values[GenerateDBKey(deviceProfileKey, OS_TYPE + OH_PROFILE_SUFFIX)] = std::to_string(profile.GetOsType()); + } return DP_SUCCESS; } -int32_t ProfileUtils::ServiceProfileToMuiltUserEntries(const ServiceProfile& profile, std::map& values) +int32_t ProfileUtils::ServiceProfileToEntries(const ServiceProfile& profile, std::map& values + , bool isMuiltUser) { std::string serviceName = CheckAndAddOhSuffix(profile.GetServiceName(), true); std::string serviceProfileKey = GenerateServiceProfileKey(profile.GetDeviceId(), serviceName); // value not need add OH suffix - values[GenerateMuiltUserDBKey(serviceProfileKey, SERVICE_NAME, profile.GetUserId())] = profile.GetServiceName(); - values[GenerateMuiltUserDBKey(serviceProfileKey, SERVICE_TYPE, profile.GetUserId())] = profile.GetServiceType(); + if (isMuiltUser) { + values[GenerateDBKey(serviceProfileKey, SERVICE_NAME, profile.GetUserId())] = profile.GetServiceName(); + values[GenerateDBKey(serviceProfileKey, SERVICE_TYPE, profile.GetUserId())] = profile.GetServiceType(); + } else{ + values[GenerateDBKey(serviceProfileKey, SERVICE_NAME)] = profile.GetServiceName(); + values[GenerateDBKey(serviceProfileKey, SERVICE_TYPE)] = profile.GetServiceType(); + } return DP_SUCCESS; } int32_t ProfileUtils::CharacteristicProfileToEntries(const CharacteristicProfile& profile, - std::map& values) + std::map& values, bool isMuiltUser) { std::string serviceName = CheckAndAddOhSuffix(profile.GetServiceName(), true); std::string charProfileKey = GenerateCharProfileKey(profile.GetDeviceId(), serviceName, profile.GetCharacteristicKey()); - values[GenerateDBKey(charProfileKey, CHARACTERISTIC_KEY)] = profile.GetCharacteristicKey(); - values[GenerateDBKey(charProfileKey, CHARACTERISTIC_VALUE)] = profile.GetCharacteristicValue(); + if (isMuiltUser) { + values[GenerateDBKey(charProfileKey, CHARACTERISTIC_KEY, profile.GetUserId())] = + profile.GetCharacteristicKey(); + values[GenerateDBKey(charProfileKey, CHARACTERISTIC_VALUE, profile.GetUserId())] = + profile.GetCharacteristicValue(); + } else { + values[GenerateDBKey(charProfileKey, CHARACTERISTIC_KEY)] = profile.GetCharacteristicKey(); + values[GenerateDBKey(charProfileKey, CHARACTERISTIC_VALUE)] = profile.GetCharacteristicValue(); + } return DP_SUCCESS; } @@ -696,17 +709,19 @@ int32_t ProfileUtils::EntriesToCharProfile(std::map va return DP_SUCCESS; } -std::string ProfileUtils::GenerateDBKey(const std::string& profileKey, const std::string& profileProperty) -{ - return profileKey + SEPARATOR + profileProperty; -} - -std::string ProfileUtils::GenerateMuiltUserDBKey(const std::string& profileKey, const std::string& profileProperty, +std::string ProfileUtils::GenerateDBKey(const std::string& profileKey, const std::string& profileProperty, int32_t userId) { - return profileKey + SEPARATOR + profileProperty + SEPARATOR + std::to_string(userId); + std::string DBKey = ""; + if (userId != -1) { + DBKey = profileKey + SEPARATOR + profileProperty + SEPARATOR + std::to_string(userId); + } else { + DBKey = profileKey + SEPARATOR + profileProperty; + } + return DBKey; } + std::string ProfileUtils::GetProfileProperty(const std::string& dbKey) { if (dbKey.length() == 0 || dbKey.length() > MAX_STRING_LEN) { diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index c1fe67a6..44f4c12e 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -110,7 +110,16 @@ int32_t DeviceProfileManager::PutDeviceProfile(const DeviceProfile& deviceProfil return DP_INVALID_PARAMS; } std::map entries; - ProfileUtils::DeviceProfileToEntries(deviceProfile, entries); + if (deviceProfile.GetIsMuitUser()) { + ProfileUtils::DeviceProfileToEntries(deviceProfile, entries, true); + if (ProfileCache::GetInstance().GetForegroundId() == deviceProfile.GetUserId()) { + ProfileUtils::DeviceProfileToEntries(deviceProfile, entries); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::DeviceProfileToEntries(deviceProfile, entries); + } if (isFirst_.load()) { AddToPutTempCache(entries); return DP_SUCCESS; @@ -139,9 +148,8 @@ int32_t DeviceProfileManager::PutServiceProfile(const ServiceProfile& servicePro } std::map entries; if (serviceProfile.GetIsMuitUser()) { - ProfileUtils::ServiceProfileToMuiltUserEntries(serviceProfile, entries); - int32_t currentUserId = ProfileCache::GetInstance().GetForegroundId(); - if (currentUserId == serviceProfile.GetUserId()) { + ProfileUtils::ServiceProfileToEntries(serviceProfile, entries, true); + if (ProfileCache::GetInstance().GetForegroundId() == serviceProfile.GetUserId()) { ProfileUtils::ServiceProfileToEntries(serviceProfile, entries); } else { HILOGI("the profile does not belong to the current user."); @@ -177,7 +185,16 @@ int32_t DeviceProfileManager::PutServiceProfileBatch(const std::vector entries; - ProfileUtils::CharacteristicProfileToEntries(charProfile, entries); + if (charProfile.GetIsMuitUser()) { + ProfileUtils::CharacteristicProfileToEntries(charProfile, entries, true); + if (ProfileCache::GetInstance().GetForegroundId() == charProfile.GetUserId()) { + ProfileUtils::CharacteristicProfileToEntries(charProfile, entries); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::CharacteristicProfileToEntries(charProfile, entries); + } if (isFirst_.load()) { AddToPutTempCache(entries); return DP_SUCCESS; @@ -235,7 +261,16 @@ int32_t DeviceProfileManager::PutCharacteristicProfileBatch(const std::vector Date: Fri, 25 Oct 2024 15:33:10 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenshuo --- bundle.json | 4 +- .../distributed_device_profile_errors.h | 1 + services/core/BUILD.gn | 8 + .../multiusermanager/multi_user_manager.h | 46 +++++ .../dp_account_common_event.h | 83 ++++++++ .../multiusermanager/multi_user_manager.cpp | 66 +++++++ .../dp_account_common_event.cpp | 187 ++++++++++++++++++ 7 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 services/core/include/multiusermanager/multi_user_manager.h create mode 100644 services/core/include/publishcommonevent/dp_account_common_event.h create mode 100644 services/core/src/multiusermanager/multi_user_manager.cpp create mode 100644 services/core/src/publishcommonevent/dp_account_common_event.cpp diff --git a/bundle.json b/bundle.json index 48740ca2..80310ebc 100644 --- a/bundle.json +++ b/bundle.json @@ -27,6 +27,7 @@ "cJSON", "c_utils", "config_policy", + "common_event_service", "hisysevent", "hilog", "ipc", @@ -42,7 +43,8 @@ "dmsfwk", "device_manager", "init", - "relational_store" + "relational_store", + "os_account" ], "third_party": [ "json" diff --git a/common/include/constants/distributed_device_profile_errors.h b/common/include/constants/distributed_device_profile_errors.h index a5a90612..20015580 100644 --- a/common/include/constants/distributed_device_profile_errors.h +++ b/common/include/constants/distributed_device_profile_errors.h @@ -151,6 +151,7 @@ constexpr int32_t DP_NULLPTR = 98566273; constexpr int32_t DP_SUBSCRIBE_INITED_FALI = 98566274; constexpr int32_t DP_GET_DEVICE_ENTRIES_FAIL = 98566275; constexpr int32_t DP_RDB_DATABASE_RESTORE_FAIL = 98566276; +constexpr int32_t DP_GET_FOREGROUND_ID_FAIL = 98566277; } // namespace DistributedDeviceProfile } // namespace OHOS #endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ERRORS_H diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 17b1b110..9cc45bbb 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -26,10 +26,12 @@ config("device_info_manager_config") { "include/deviceprofilemanager/listener", "include/dfx", "include/dm_adapter", + "include/multiusermanager", "include/permissionmanager", "include/persistenceadapter", "include/persistenceadapter/kvadapter", "include/persistenceadapter/rdbadapter", + "include/publishcommonevent", "include/subscribeprofilemanager", "include/staticcapabilitycollector", "include/staticcapabilityloader", @@ -81,10 +83,12 @@ ohos_shared_library("distributed_device_profile_svr") { "src/distributed_device_profile_service_new.cpp", "src/distributed_device_profile_stub_new.cpp", "src/dm_adapter/dm_adapter.cpp", + "src/multiusermanager/multi_user_manager.cpp", "src/permissionmanager/permission_manager.cpp", "src/persistenceadapter/kvadapter/kv_adapter.cpp", "src/persistenceadapter/kvadapter/switch_adapter.cpp", "src/persistenceadapter/rdbadapter/rdb_adapter.cpp", + "src/publishcommonevent/dp_account_common_event.cpp", "src/staticcapabilitycollector/static_capability_collector.cpp", "src/staticcapabilityloader/static_capability_loader.cpp", "src/subscribeprofilemanager/subscribe_profile_manager.cpp", @@ -105,6 +109,8 @@ ohos_shared_library("distributed_device_profile_svr") { "access_token:libaccesstoken_sdk", "cJSON:cjson", "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "device_auth:deviceauth_sdk", "device_manager:devicemanagersdk", @@ -116,6 +122,8 @@ ohos_shared_library("distributed_device_profile_svr") { "init:libbegetutil", "ipc:ipc_core", "kv_store:distributeddata_inner", + "os_account:libaccountkits", + "os_account:os_account_innerkits", "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/core/include/multiusermanager/multi_user_manager.h b/services/core/include/multiusermanager/multi_user_manager.h new file mode 100644 index 00000000..3c312087 --- /dev/null +++ b/services/core/include/multiusermanager/multi_user_manager.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef OHOS_DP_MULTIPLE_USER_CONNECTOR_H +#define OHOS_DP_MULTIPLE_USER_CONNECTOR_H + +#include +#include +#include +#include + +#include "iremote_object.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class MultiUserManager { + DECLARE_SINGLE_INSTANCE(MultiUserManager); +public: + int32_t Init(); + + int32_t UnInit(); + + int32_t GetCurrentForegroundUserID(); + + void SetCurrentForegroundUserID(int32_t userId); + +private: + int32_t foregroundUserId_ = -1; + std::mutex foregroundUserIdLock_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DP_MULTIPLE_USER_CONNECTOR_H diff --git a/services/core/include/publishcommonevent/dp_account_common_event.h b/services/core/include/publishcommonevent/dp_account_common_event.h new file mode 100644 index 00000000..17aed149 --- /dev/null +++ b/services/core/include/publishcommonevent/dp_account_common_event.h @@ -0,0 +1,83 @@ +/* + * 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. + */ + +#ifndef OHOS_DP_ACCOUNT_COMMON_EVENT_H +#define OHOS_DP_ACCOUNT_COMMON_EVENT_H + +#include +#include +#include +#include + +#include "common_event_data.h" +#include "common_event_manager.h" +#include "common_event_subscribe_info.h" +#include "common_event_subscriber.h" +#include "matching_skills.h" +#include "system_ability_status_change_stub.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using OHOS::EventFwk::CommonEventData; +using OHOS::EventFwk::CommonEventSubscriber; +using OHOS::EventFwk::CommonEventSubscribeInfo; +using AccountEventCallback = std::function; + +class DpAccountEventSubscriber : public CommonEventSubscriber { +public: + DpAccountEventSubscriber(const CommonEventSubscribeInfo &subscribeInfo, const AccountEventCallback &callback, + const std::vector &eventNameVec) : CommonEventSubscriber(subscribeInfo), + eventNameVec_(eventNameVec), callback_(callback) {} + ~DpAccountEventSubscriber() override = default; + std::vector GetSubscriberEventNameVec() const; + void OnReceiveEvent(const CommonEventData &data) override; + +private: + std::vector eventNameVec_; + AccountEventCallback callback_; +}; + +class DpAccountCommonEventManager { +public: + DpAccountCommonEventManager() = default; + ~DpAccountCommonEventManager(); + bool SubscribeAccountCommonEvent(const std::vector &eventNameVec, + const AccountEventCallback &callback); + bool UnsubscribeAccountCommonEvent(); + +private: + std::vector eventNameVec_; + bool eventValidFlag_ = false; + std::mutex evenSubscriberMutex_; + std::shared_ptr subscriber_ = nullptr; + sptr statusChangeListener_ = nullptr; + int32_t counter_ = 0; + +private: + class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { + public: + explicit SystemAbilityStatusChangeListener(std::shared_ptr AccountSubscriber) + : changeSubscriber_(AccountSubscriber) {} + ~SystemAbilityStatusChangeListener() = default; + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + + private: + std::shared_ptr changeSubscriber_; + }; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DP_ACCOUNT_COMMON_EVENT_H diff --git a/services/core/src/multiusermanager/multi_user_manager.cpp b/services/core/src/multiusermanager/multi_user_manager.cpp new file mode 100644 index 00000000..19bedd84 --- /dev/null +++ b/services/core/src/multiusermanager/multi_user_manager.cpp @@ -0,0 +1,66 @@ +/* + * 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 "multi_user_manager.h" + +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" + +#include "account_info.h" +#include "ohos_account_kits.h" +#include "os_account_manager.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(MultiUserManager); + +namespace { + const std::string TAG = "MultiUserManager"; +} + +int32_t MultiUserManager::Init() +{ + HILOGI("Init"); + int32_t foregroundId; + int32_t res = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(foregroundId); + if (res != DP_SUCCESS) { + HILOGD("GetForegroundId failed, res:%{public}d", res); + return DP_GET_FOREGROUND_ID_FAIL; + } + HILOGI("current foregroundId = %{public}d", foregroundId); + SetCurrentForegroundUserID(foregroundId); + + return DP_SUCCESS; +} + +int32_t MultiUserManager::UnInit() +{ + return DP_SUCCESS; +} + +void MultiUserManager::SetCurrentForegroundUserID(int32_t userId) +{ + std::lock_guard lock(foregroundUserIdLock_); + foregroundUserId_ = userId; +} + +int32_t MultiUserManager::GetCurrentForegroundUserID() +{ + std::lock_guard lock(foregroundUserIdLock_); + return foregroundUserId_; +} + +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/core/src/publishcommonevent/dp_account_common_event.cpp b/services/core/src/publishcommonevent/dp_account_common_event.cpp new file mode 100644 index 00000000..46ae4946 --- /dev/null +++ b/services/core/src/publishcommonevent/dp_account_common_event.cpp @@ -0,0 +1,187 @@ +/* + * 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 "dp_account_common_event.h" + +#include +#include + +#include "common_event_support.h" +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "iservice_registry.h" +#include "multi_user_manager.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using OHOS::EventFwk::MatchingSkills; +using OHOS::EventFwk::CommonEventManager; + +constexpr int32_t MAX_TRY_TIMES = 3; + +namespace { + const std::string TAG = "AccountCommonEvent"; +} + +std::vector DpAccountEventSubscriber::GetSubscriberEventNameVec() const +{ + return eventNameVec_; +} + +DpAccountCommonEventManager::~DpAccountCommonEventManager() +{ + DpAccountCommonEventManager::UnsubscribeAccountCommonEvent(); +} + +bool DpAccountCommonEventManager::SubscribeAccountCommonEvent(const std::vector &eventNameVec, + const AccountEventCallback &callback) +{ + if (eventNameVec.empty() || callback == nullptr) { + HILOGE("eventNameVec is empty or callback is nullptr."); + return false; + } + std::lock_guard locker(evenSubscriberMutex_); + if (eventValidFlag_) { + HILOGE("failed to subscribe account commom eventName size: %{public}zu", eventNameVec.size()); + return false; + } + + MatchingSkills matchingSkills; + for (auto &item : eventNameVec) { + matchingSkills.AddEvent(item); + } + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + subscriber_ = std::make_shared(subscriberInfo, callback, eventNameVec); + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + HILOGE("samgrProxy is nullptr"); + subscriber_ = nullptr; + return false; + } + statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(subscriber_); + if (statusChangeListener_ == nullptr) { + HILOGE("statusChangeListener_ is nullptr"); + subscriber_ = nullptr; + return false; + } + while (counter_ != MAX_TRY_TIMES) { + if (samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_) == ERR_OK) { + HILOGI("SubscribeAccountEvent success."); + counter_ = 0; + break; + } + if (++counter_ == MAX_TRY_TIMES) { + HILOGI("SubscribeAccountEvent failed."); + } + sleep(1); + } + eventNameVec_ = eventNameVec; + eventValidFlag_ = true; + HILOGI("success to subscribe account commom event name size: %{public}zu", eventNameVec.size()); + return true; +} + +bool DpAccountCommonEventManager::UnsubscribeAccountCommonEvent() +{ + std::lock_guard locker(evenSubscriberMutex_); + if (!eventValidFlag_) { + HILOGE("failed to unsubscribe account commom event name size: %{public}zu because event is invalid.", + eventNameVec_.size()); + return false; + } + if (subscriber_ != nullptr) { + HILOGI("start to unsubscribe account commom event name size: %{public}zu", eventNameVec_.size()); + if (!CommonEventManager::UnSubscribeCommonEvent(subscriber_)) { + HILOGE("failed to unsubscribe account commom event name size: %{public}zu", eventNameVec_.size()); + return false; + } + HILOGI("success to unsubscribe account commom event name size: %{public}zu", eventNameVec_.size()); + subscriber_ = nullptr; + } + if (statusChangeListener_ != nullptr) { + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + HILOGE("samgrProxy is nullptr"); + return false; + } + int32_t ret = samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_); + if (ret != ERR_OK) { + HILOGE("failed to unsubscribe system ability COMMON_EVENT_SERVICE_ID ret:%{public}d", ret); + return false; + } + statusChangeListener_ = nullptr; + } + + HILOGI("success to unsubscribe account commom event name size: %{public}zu", eventNameVec_.size()); + eventValidFlag_ = false; + return true; +} + +void DpAccountEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + std::string receiveEvent = data.GetWant().GetAction(); + HILOGI("Received account event: %{public}s", receiveEvent.c_str()); + int32_t userId = data.GetCode(); + bool accountValiedEvent = false; + if (receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED || + receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { + userId = data.GetCode(); + accountValiedEvent = true; + } + if (receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT || + receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN) { + userId = data.GetWant().GetIntParam("userId", 0); + accountValiedEvent = true; + } + if (userId <= 0 || !accountValiedEvent) { + HILOGE("Invalied account type event."); + return; + } +} + +void DpAccountCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility( + int32_t systemAbilityId, const std::string& deviceId) +{ + HILOGI("systemAbility is added with said: %{public}d.", systemAbilityId); + if (systemAbilityId != COMMON_EVENT_SERVICE_ID) { + return; + } + if (changeSubscriber_ == nullptr) { + HILOGE("failed to subscribe account commom event because changeSubscriber_ is nullptr."); + return; + } + std::vector eventNameVec = changeSubscriber_->GetSubscriberEventNameVec(); + HILOGI("start to subscribe account commom eventName: %{public}zu", eventNameVec.size()); + if (!CommonEventManager::SubscribeCommonEvent(changeSubscriber_)) { + HILOGE("failed to subscribe account commom event: %{public}zu", eventNameVec.size()); + } + // int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); + // std::string accountId = MultipleUserConnector::GetOhosAccountId(); + // HILOGI("after subscribe account event accountId: %{public}s, userId: %{public}s", + // GetAnonyString(accountId).c_str(), GetAnonyInt32(userId).c_str()); + // if (userId > 0) { + // MultipleUserConnector::SetSwitchOldUserId(userId); + // MultipleUserConnector::SetSwitchOldAccountId(accountId); + // } +} + +void DpAccountCommonEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( + int32_t systemAbilityId, const std::string& deviceId) +{ + HILOGI("systemAbility is removed with said: %{public}d.", systemAbilityId); +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From 5393c0a20e69c49b030e1ff976f82230a67e32c3 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Sun, 27 Oct 2024 16:50:19 +0800 Subject: [PATCH 7/9] =?UTF-8?q?delete=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7=E9=9C=80=E8=A6=81=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../core/include/distributed_device_profile_client.h | 5 +++-- .../core/include/distributed_device_profile_proxy.h | 5 +++-- .../core/src/distributed_device_profile_client.cpp | 8 ++++---- .../core/src/distributed_device_profile_proxy.cpp | 8 ++++++-- .../deviceprofilemanager/device_profile_manager.h | 5 +++-- .../include/distributed_device_profile_service_new.h | 5 +++-- services/core/include/utils/profile_control_utils.h | 7 ++++--- .../deviceprofilemanager/device_profile_manager.cpp | 10 ++++++---- .../src/distributed_device_profile_service_new.cpp | 8 ++++---- .../core/src/distributed_device_profile_stub_new.cpp | 12 ++++++++++-- services/core/src/utils/profile_control_utils.cpp | 5 +++-- 11 files changed, 49 insertions(+), 29 deletions(-) diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index aafde03c..2a73a27e 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -60,9 +60,10 @@ public: ServiceProfile& serviceProfile); int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& characteristicProfile); - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName); + int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, + bool isMuitUser = false, int32_t userId = -1); int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey); + const std::string& characteristicKey, bool isMuitUser = false, int32_t userId = -1); int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); int32_t SyncDeviceProfile(const DpSyncOptions& syncOptions, sptr syncCb); diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h index 3bbb4872..5c3cc151 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h @@ -56,9 +56,10 @@ public: ServiceProfile& serviceProfile) override; int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName) override; + int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMuitUser = false, + int32_t userId = -1) override; int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId) override; + const std::string& characteristicId, bool isMuitUser = false, int32_t userId = -1) override; int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; diff --git a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index ebb55d92..b02b2c98 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -286,25 +286,25 @@ int32_t DistributedDeviceProfileClient::GetCharacteristicProfile(const std::stri } int32_t DistributedDeviceProfileClient::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName) + const std::string& serviceName, bool isMuitUser, int32_t userId) { auto dpService = GetDeviceProfileService(); if (dpService == nullptr) { HILOGE("Get dp service failed"); return DP_GET_SERVICE_FAILED; } - return dpService->DeleteServiceProfile(deviceId, serviceName); + return dpService->DeleteServiceProfile(deviceId, serviceName, isMuitUser, userId); } int32_t DistributedDeviceProfileClient::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicKey) + const std::string& serviceName, const std::string& characteristicKey, bool isMuitUser, int32_t userId) { auto dpService = GetDeviceProfileService(); if (dpService == nullptr) { HILOGE("Get dp service failed"); return DP_GET_SERVICE_FAILED; } - return dpService->DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey); + return dpService->DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey, isMuitUser, userId); } int32_t DistributedDeviceProfileClient::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp index c7098b69..b7087aa8 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp @@ -247,7 +247,7 @@ int32_t DistributedDeviceProfileProxy::GetCharacteristicProfile(const std::strin } int32_t DistributedDeviceProfileProxy::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName) + const std::string& serviceName, bool isMuitUser, int32_t userId) { sptr remote = nullptr; GET_REMOTE_OBJECT(remote); @@ -255,13 +255,15 @@ int32_t DistributedDeviceProfileProxy::DeleteServiceProfile(const std::string& d WRITE_INTERFACE_TOKEN(data); WRITE_HELPER(data, String, deviceId); WRITE_HELPER(data, String, serviceName); + WRITE_HELPER(data, Bool, isMuitUser); + WRITE_HELPER(data, Int32, userId); MessageParcel reply; SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE), data, reply); return DP_SUCCESS; } int32_t DistributedDeviceProfileProxy::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId) + const std::string& serviceName, const std::string& characteristicId, bool isMuitUser, int32_t userId) { sptr remote = nullptr; GET_REMOTE_OBJECT(remote); @@ -270,6 +272,8 @@ int32_t DistributedDeviceProfileProxy::DeleteCharacteristicProfile(const std::st WRITE_HELPER(data, String, deviceId); WRITE_HELPER(data, String, serviceName); WRITE_HELPER(data, String, characteristicId); + WRITE_HELPER(data, Bool, isMuitUser); + WRITE_HELPER(data, Int32, userId); MessageParcel reply; SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_CHAR_PROFILE), data, reply); return DP_SUCCESS; diff --git a/services/core/include/deviceprofilemanager/device_profile_manager.h b/services/core/include/deviceprofilemanager/device_profile_manager.h index 5e9f5ade..fa99f112 100644 --- a/services/core/include/deviceprofilemanager/device_profile_manager.h +++ b/services/core/include/deviceprofilemanager/device_profile_manager.h @@ -56,9 +56,10 @@ public: ServiceProfile& serviceProfile); int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, CharacteristicProfile& charProfile); - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName); + int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMuitUser = false, + int32_t userId = -1); int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey); + const std::string& characteristicKey, bool isMuitUser = false, int32_t userId = -1); int32_t GetAllDeviceProfile(std::vector& deviceProfiles); int32_t GetAllServiceProfile(std::vector& serviceProfiles); int32_t GetAllCharacteristicProfile(std::vector& charProfiles); diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index f491f41c..b23455a2 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -58,9 +58,10 @@ public: ServiceProfile& serviceProfile) override; int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName) override; + int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMuitUser = false, + int32_t userId = -1) override; int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey) override; + const std::string& characteristicKey, bool isMuitUser = false, int32_t userId = -1) override; int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, diff --git a/services/core/include/utils/profile_control_utils.h b/services/core/include/utils/profile_control_utils.h index 224d6d52..202cc3d6 100644 --- a/services/core/include/utils/profile_control_utils.h +++ b/services/core/include/utils/profile_control_utils.h @@ -50,9 +50,10 @@ public: static int32_t GetSwitchCharacteristicProfile(const std::string& appId, const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, CharacteristicProfile& charProfile); static int32_t DeleteServiceProfile(std::shared_ptr kvStore, const std::string& deviceId, - const std::string& serviceName); + const std::string& serviceName, bool isMuitUser = false, int32_t userId = -1); static int32_t DeleteCharacteristicProfile(std::shared_ptr kvStore, const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicKey); + const std::string& serviceName, const std::string& characteristicKey, bool isMuitUser = false, + int32_t userId = -1); static int32_t GetAllDeviceProfile(std::shared_ptr kvStore, std::vector& deviceProfiles); static int32_t GetAllServiceProfile(std::shared_ptr kvStore, std::vector& serviceProfiles); @@ -62,4 +63,4 @@ public: }; } // namespace DeviceProfile } // namespace OHOS -#endif // OHOS_DP_DEVICE_PROFILE_MANAGER_H \ No newline at end of file +#endif // OHOS_DP_DEVICE_PROFILE_MANAGER_H diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index bfc7df08..ff7af7da 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -343,13 +343,15 @@ int32_t DeviceProfileManager::GetCharacteristicProfile(const std::string& device return DP_SUCCESS; } -int32_t DeviceProfileManager::DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName) +int32_t DeviceProfileManager::DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, + bool isMuitUser, int32_t userId) { HILOGD("call!"); int32_t res = 0; { std::lock_guard lock(dynamicStoreMutex_); - res = ProfileControlUtils::DeleteServiceProfile(deviceProfileStore_, deviceId, serviceName); + res = ProfileControlUtils::DeleteServiceProfile(deviceProfileStore_, deviceId, serviceName, isMuitUser, + userId); } if (res != DP_SUCCESS) { HILOGE("DeleteServiceProfile fail, reason: %{public}d!", res); @@ -360,14 +362,14 @@ int32_t DeviceProfileManager::DeleteServiceProfile(const std::string& deviceId, } int32_t DeviceProfileManager::DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicKey) + const std::string& characteristicKey, bool isMuitUser, int32_t userId) { HILOGD("call!"); int32_t res = 0; { std::lock_guard lock(dynamicStoreMutex_); res = ProfileControlUtils::DeleteCharacteristicProfile(deviceProfileStore_, deviceId, serviceName, - characteristicKey); + characteristicKey, isMuitUser, userId); } if (res != DP_SUCCESS) { HILOGE("DeleteCharacteristicProfile fail, reason: %{public}d!", res); diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 010cdadb..a64498ac 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -439,20 +439,20 @@ int32_t DistributedDeviceProfileServiceNew::GetCharacteristicProfile(const std:: } int32_t DistributedDeviceProfileServiceNew::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName) + const std::string& serviceName, bool isMuitUser, int32_t userId) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); return DP_PERMISSION_DENIED; } HILOGD("CheckCallerPermission success interface DeleteServiceProfile"); - int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName); + int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName, isMuitUser, userId); DpRadarHelper::GetInstance().ReportDeleteServiceProfile(ret, deviceId); return ret; } int32_t DistributedDeviceProfileServiceNew::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicKey) + const std::string& serviceName, const std::string& characteristicKey, bool isMuitUser, int32_t userId) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -460,7 +460,7 @@ int32_t DistributedDeviceProfileServiceNew::DeleteCharacteristicProfile(const st } HILOGD("CheckCallerPermission success interface DeleteCharacteristicProfile"); int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName, - characteristicKey); + characteristicKey, isMuitUser, userId); DpRadarHelper::GetInstance().ReportDeleteCharProfile(ret, deviceId); return ret; } diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp index a5272779..9a15771f 100644 --- a/services/core/src/distributed_device_profile_stub_new.cpp +++ b/services/core/src/distributed_device_profile_stub_new.cpp @@ -429,9 +429,13 @@ int32_t DistributedDeviceProfileStubNew::DeleteServiceProfileInner(MessageParcel { std::string deviceId; std::string serviceName; + bool isMuitUser; + int32_t userId; READ_HELPER(data, String, deviceId); READ_HELPER(data, String, serviceName); - int32_t ret = DeleteServiceProfile(deviceId, serviceName); + READ_HELPER(data, Bool, isMuitUser); + READ_HELPER(data, Int32, userId); + int32_t ret = DeleteServiceProfile(deviceId, serviceName, isMuitUser, userId); if (!reply.WriteInt32(ret)) { HILOGE("Write reply failed"); return ERR_FLATTEN_OBJECT; @@ -444,10 +448,14 @@ int32_t DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner(Messag std::string deviceId; std::string serviceName; std::string characteristicKey; + bool isMuitUser; + int32_t userId; READ_HELPER(data, String, deviceId); READ_HELPER(data, String, serviceName); READ_HELPER(data, String, characteristicKey); - int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey); + READ_HELPER(data, Bool, isMuitUser); + READ_HELPER(data, Int32, userId); + int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey, isMuitUser, userId); if (!reply.WriteInt32(ret)) { HILOGE("Write reply failed"); return ERR_FLATTEN_OBJECT; diff --git a/services/core/src/utils/profile_control_utils.cpp b/services/core/src/utils/profile_control_utils.cpp index f8f3bd35..23db7206 100644 --- a/services/core/src/utils/profile_control_utils.cpp +++ b/services/core/src/utils/profile_control_utils.cpp @@ -412,7 +412,7 @@ int32_t ProfileControlUtils::GetSwitchCharacteristicProfile(const std::string& a } int32_t ProfileControlUtils::DeleteServiceProfile(std::shared_ptr kvStore, const std::string& deviceId, - const std::string& serviceName) + const std::string& serviceName, bool isMuitUser, int32_t userId) { HILOGD("call!"); if (kvStore == nullptr) { @@ -437,7 +437,8 @@ int32_t ProfileControlUtils::DeleteServiceProfile(std::shared_ptr kv } int32_t ProfileControlUtils::DeleteCharacteristicProfile(std::shared_ptr kvStore, - const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey) + const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, bool isMuitUser, + int32_t userId) { HILOGI("call!"); if (kvStore == nullptr) { -- Gitee From 507ffd4df1b9703816c1a3fd4ad82e9f1e7b53fc Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Sun, 27 Oct 2024 17:50:42 +0800 Subject: [PATCH 8/9] =?UTF-8?q?KV=20Delete=E6=8E=A5=E5=8F=A3=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=A4=9A=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/utils/profile_utils.h | 5 +++ common/src/utils/profile_utils.cpp | 31 +++++++++++++++++ .../core/src/utils/profile_control_utils.cpp | 33 ++++++++++++------- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index e15340ed..5e9cf88c 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -109,6 +109,11 @@ public: static bool IsNumStr(const std::string& inString); static int32_t GetUserIdFromDbKey(const std::string& dbKey); static std::string RemoveUserIdFromDbKey(const std::string& dbKey); + static int32_t GenerateServiceDBkeys(const std::string& deviceId, const std::string& serviceName, + std::vector& dbKeys, bool isMuiltUser = false, int32_t userId = -1); + static int32_t GenerateCharacteristicDBkeys(const std::string& deviceId, const std::string& serviceName, + const std::string& characteristicKey, std::vector& dbKeys, bool isMuiltUser = false, + int32_t userId = -1); }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 2e8bc7c3..86cec0eb 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -886,5 +886,36 @@ std::string ProfileUtils::RemoveUserIdFromDbKey(const std::string& dbKey) } return dbKeyWithoutUserId; } + +int32_t ProfileUtils::GenerateServiceDBkeys(const std::string& deviceId, const std::string& serviceName, + std::vector& dbKeys, bool isMuiltUser, int32_t userId) +{ + std::string localServiceName = CheckAndAddOhSuffix(serviceName, true); + std::string serviceProfileKey = GenerateServiceProfileKey(deviceId, localServiceName); + // value not need add OH suffix + if (isMuiltUser) { + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_NAME, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_TYPE, userId)); + } else{ + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_NAME)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_TYPE)); + } + return DP_SUCCESS; +} + +int32_t ProfileUtils::GenerateCharacteristicDBkeys(const std::string& deviceId, const std::string& serviceName, + const std::string& characteristicKey, std::vector& dbKeys, bool isMuiltUser, int32_t userId) +{ + std::string localServiceName = CheckAndAddOhSuffix(serviceName, true); + std::string charProfileKey = GenerateCharProfileKey(deviceId, localServiceName, characteristicKey); + if (isMuiltUser) { + dbKeys.emplace_back(GenerateDBKey(charProfileKey, CHARACTERISTIC_KEY, userId)); + dbKeys.emplace_back(GenerateDBKey(charProfileKey, CHARACTERISTIC_VALUE, userId)); + } else{ + dbKeys.emplace_back(GenerateDBKey(charProfileKey, CHARACTERISTIC_KEY)); + dbKeys.emplace_back(GenerateDBKey(charProfileKey, CHARACTERISTIC_VALUE)); + } + return DP_SUCCESS; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/utils/profile_control_utils.cpp b/services/core/src/utils/profile_control_utils.cpp index 23db7206..d7a320c3 100644 --- a/services/core/src/utils/profile_control_utils.cpp +++ b/services/core/src/utils/profile_control_utils.cpp @@ -426,9 +426,18 @@ int32_t ProfileControlUtils::DeleteServiceProfile(std::shared_ptr kv } HILOGI("deviceId: %{public}s, serviceName: %{public}s!", ProfileUtils::GetAnonyString(deviceId).c_str(), serviceName.c_str()); - - std::string profileKeyPrefix = ProfileUtils::GenerateServiceProfileKey(deviceId, serviceName); - if (kvStore->DeleteByPrefix(profileKeyPrefix) != DP_SUCCESS) { + std::vector keys; + if (isMuitUser) { + ProfileUtils::GenerateServiceDBkeys(deviceId, serviceName, keys, true, userId); + if (ProfileCache::GetInstance().GetForegroundId() == userId) { + ProfileUtils::GenerateServiceDBkeys(deviceId, serviceName, keys); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::GenerateServiceDBkeys(deviceId, serviceName, keys); + } + if (kvStore->DeleteBatch(keys) != DP_SUCCESS) { HILOGE("DeleteServiceProfile fail!"); return DP_DEL_KV_DB_FAIL; } @@ -452,16 +461,18 @@ int32_t ProfileControlUtils::DeleteCharacteristicProfile(std::shared_ptrDeleteByPrefix(profileKeyPrefix) != DP_SUCCESS) { - HILOGE("DeleteCharacteristicProfile fail!"); - return DP_GET_KV_DB_FAIL; + std::vector keys; + if (isMuitUser) { + ProfileUtils::GenerateCharacteristicDBkeys(deviceId, serviceName, characteristicKey,keys, true, userId); + if (ProfileCache::GetInstance().GetForegroundId() == userId) { + ProfileUtils::GenerateCharacteristicDBkeys(deviceId, serviceName, characteristicKey, keys); + } else { + HILOGI("the profile does not belong to the current user."); } + } else { + ProfileUtils::GenerateCharacteristicDBkeys(deviceId, serviceName, characteristicKey, keys); } - std::string profileKeyPrefix = ProfileUtils::GenerateCharProfileKey(deviceId, serviceName, characteristicKey); - if (kvStore->DeleteByPrefix(profileKeyPrefix) != DP_SUCCESS) { + if (kvStore->DeleteBatch(keys) != DP_SUCCESS) { HILOGE("DeleteCharacteristicProfile fail!"); return DP_DEL_KV_DB_FAIL; } -- Gitee From 776ed347e33251057aa3f201ba30efa9a5b440a8 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Mon, 28 Oct 2024 10:18:12 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=99=9A=E5=87=BD=E6=95=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0=EF=BC=8CuserId?= =?UTF-8?q?=E5=8C=BF=E5=90=8Ddump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/interfaces/i_distributed_device_profile.h | 5 +++-- common/src/interfaces/characteristic_profile.cpp | 3 ++- common/src/interfaces/device_profile.cpp | 3 ++- common/src/interfaces/service_profile.cpp | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h index 58b59991..66bdd5e0 100644 --- a/common/include/interfaces/i_distributed_device_profile.h +++ b/common/include/interfaces/i_distributed_device_profile.h @@ -52,9 +52,10 @@ public: ServiceProfile& serviceProfile) = 0; virtual int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) = 0; - virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName) = 0; + virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, + bool isMuitUser = false, int32_t userId = -1) = 0; virtual int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId) = 0; + const std::string& characteristicId, bool isMuitUser = false, int32_t userId = -1) = 0; virtual int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; virtual int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; virtual int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) = 0; diff --git a/common/src/interfaces/characteristic_profile.cpp b/common/src/interfaces/characteristic_profile.cpp index 87ae47b1..af87ba73 100644 --- a/common/src/interfaces/characteristic_profile.cpp +++ b/common/src/interfaces/characteristic_profile.cpp @@ -130,7 +130,8 @@ std::string CharacteristicProfile::dump() const cJSON_AddStringToObject(json, SERVICE_NAME.c_str(), serviceName_.c_str()); cJSON_AddStringToObject(json, CHARACTERISTIC_KEY.c_str(), characteristicKey_.c_str()); cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); - cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_); + cJSON_AddStringToObject(json, USER_ID.c_str(), + ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str()); if (characteristicKey_ == SWITCH_STATUS) { cJSON_AddStringToObject(json, CHARACTERISTIC_VALUE.c_str(), characteristicValue_.c_str()); } else { diff --git a/common/src/interfaces/device_profile.cpp b/common/src/interfaces/device_profile.cpp index e2e8414b..228636a3 100644 --- a/common/src/interfaces/device_profile.cpp +++ b/common/src/interfaces/device_profile.cpp @@ -225,7 +225,8 @@ std::string DeviceProfile::dump() const cJSON_AddStringToObject(json, OS_VERSION.c_str(), osVersion_.c_str()); cJSON_AddNumberToObject(json, OS_TYPE.c_str(), osType_); cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); - cJSON_AddStringToObject(json, USER_ID.c_str(), ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str()); + cJSON_AddStringToObject(json, USER_ID.c_str(), + ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str()); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); diff --git a/common/src/interfaces/service_profile.cpp b/common/src/interfaces/service_profile.cpp index d44c90b8..9d9409e2 100644 --- a/common/src/interfaces/service_profile.cpp +++ b/common/src/interfaces/service_profile.cpp @@ -135,7 +135,8 @@ std::string ServiceProfile::dump() const cJSON_AddStringToObject(json, SERVICE_NAME.c_str(), serviceName_.c_str()); cJSON_AddStringToObject(json, SERVICE_TYPE.c_str(), serviceType_.c_str()); cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_); - cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_); + cJSON_AddStringToObject(json, USER_ID.c_str(), + ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str()); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { cJSON_Delete(json); -- Gitee