From d528dbad761384f990571f8223bcf9d2a70ddbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Sat, 9 Aug 2025 14:01:45 +0800 Subject: [PATCH 1/2] service dp code 01 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- common/BUILD.gn | 1 + .../distributed_device_profile_constants.h | 22 ++ .../distributed_device_profile_enums.h | 5 +- .../interfaces/i_distributed_device_profile.h | 4 + .../interfaces/service_info_profile_new.h | 138 +++++++ common/include/utils/profile_utils.h | 10 + .../distributed_device_profile_constants.cpp | 24 ++ .../interfaces/service_info_profile_new.cpp | 324 ++++++++++++++++ common/src/utils/profile_utils.cpp | 99 +++++ .../distributed_device_profile_client.h | 4 +- .../distributed_device_profile_proxy.h | 5 +- .../src/distributed_device_profile_client.cpp | 23 ++ .../src/distributed_device_profile_proxy.cpp | 38 ++ services/core/BUILD.gn | 3 + .../include/common/dp_services_constants.h | 12 + .../distributed_device_profile_service_new.h | 5 + .../distributed_device_profile_stub_new.h | 3 + .../kvadapter/service_info_kv_adapter.h | 72 ++++ .../service_info_manager.h | 61 ++++ services/core/include/utils/profile_cache.h | 1 + .../include/utils/profile_control_utils.h | 2 + .../listener/kv_store_death_recipient.cpp | 6 + ...distributed_device_profile_service_new.cpp | 55 +++ .../distributed_device_profile_stub_new.cpp | 47 +++ .../kvadapter/service_info_kv_adapter.cpp | 345 ++++++++++++++++++ .../service_info_manager.cpp | 209 +++++++++++ services/core/src/utils/profile_cache.cpp | 1 + .../core/src/utils/profile_control_utils.cpp | 27 ++ ...stributed_device_profile_stub_new_test.cpp | 25 ++ 29 files changed, 1568 insertions(+), 3 deletions(-) create mode 100644 common/include/interfaces/service_info_profile_new.h create mode 100644 common/src/interfaces/service_info_profile_new.cpp create mode 100644 services/core/include/persistenceadapter/kvadapter/service_info_kv_adapter.h create mode 100644 services/core/include/serviceinfo_manager/service_info_manager.h create mode 100644 services/core/src/persistenceadapter/kvadapter/service_info_kv_adapter.cpp create mode 100644 services/core/src/serviceinfo_manager/service_info_manager.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index 9f148dde..016fc54f 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -105,6 +105,7 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/accessee.cpp", "src/interfaces/accesser.cpp", "src/interfaces/business_event.cpp", + "src/interfaces/service_info_profile_new.cpp", "src/interfaces/characteristic_profile.cpp", "src/interfaces/device_icon_info.cpp", "src/interfaces/device_icon_info_filter_options.cpp", diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index c435bab7..6fef1dd7 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -121,6 +121,9 @@ extern const std::string GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY; extern const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID; extern const std::string GET_ALL_SERVICE_INFO_PROFILE_LIST; extern const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME; +extern const std::string REG_SERVICE_ID; +extern const std::string PUBLISH_STATE; +extern const std::string SERVICE_INFO; /* LocalServiceInfo Attribute */ extern const std::string PUT_LOCAL_SERVICE_INFO; extern const std::string UPDATE_LOCAL_SERVICE_INFO; @@ -320,6 +323,25 @@ extern const std::string LNN_ACL_TRUE; extern const std::string BUSINESS_KEY; extern const std::string BUSINESS_VALUE; +extern const std::string SERVICE_ID_KEY; +extern const std::string SERVICE_ID_VALUE; +extern const std::string SERVICE_TYPE_KEY; +extern const std::string SERVICE_TYPE_VALUE; +extern const std::string SERVICE_NAME_KEY; +extern const std::string SERVICE_NAME_VALUE; +extern const std::string SERVICE_DISPLAY_NAME_KEY; +extern const std::string SERVICE_DISPLAY_NAME_VALUE; +extern const std::string REG_SERVICE_ID_KEY; +extern const std::string REG_SERVICE_ID_VALUE; +extern const std::string SER_PUB_STATE_KEY; +extern const std::string SER_PUB_STATE_VALUE; +extern const std::string DEVICE_ID_KEY; +extern const std::string DEVICE_ID_VALUE; +extern const std::string SER_USER_ID_KEY; +extern const std::string SER_USER_ID_VALUE; +extern const std::string SER_TOKEN_ID_KEY; +extern const std::string SER_TOKEN_ID_VALUE; + constexpr int32_t ROWCNT_INIT = -1; constexpr int32_t RET_INIT = -1; constexpr int32_t ROWCOUNT_INIT = -1; diff --git a/common/include/interfaces/distributed_device_profile_enums.h b/common/include/interfaces/distributed_device_profile_enums.h index 3ca83d93..bcb3c673 100644 --- a/common/include/interfaces/distributed_device_profile_enums.h +++ b/common/include/interfaces/distributed_device_profile_enums.h @@ -92,7 +92,10 @@ enum class DPInterfaceCode : uint32_t { UNREGISTER_BUSINESS_CALLBACK = 73, PUT_BUSINESS_EVENT = 74, GET_BUSINESS_EVENT = 75, - MAX = 76 + PUT_SERVICE_INFO_PROFILE_NEW = 76, + DEL_SERVICE_INFO_PROFILE_NEW = 77, + GET_SERVICE_INFO_PROFILE_NEW = 78, + MAX = 79 }; enum class DeviceIdType : uint32_t { diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h index 413c643c..b44f5431 100644 --- a/common/include/interfaces/i_distributed_device_profile.h +++ b/common/include/interfaces/i_distributed_device_profile.h @@ -37,6 +37,7 @@ #include "trusted_device_info.h" #include "local_service_info.h" #include "business_event.h" +#include "service_info_profile_new.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -110,6 +111,9 @@ public: virtual int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) = 0; virtual int32_t PutBusinessEvent(const BusinessEvent& event) = 0; virtual int32_t GetBusinessEvent(BusinessEvent& event) = 0; + virtual int32_t PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfo) = 0; + virtual int32_t DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, int32_t userId) = 0; + virtual int32_t GetServiceInfo(ServiceInfoProfileNew & serviceInfo) = 0; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/include/interfaces/service_info_profile_new.h b/common/include/interfaces/service_info_profile_new.h new file mode 100644 index 00000000..074ed717 --- /dev/null +++ b/common/include/interfaces/service_info_profile_new.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DP_SERVICE_INFO_H +#define OHOS_DP_SERVICE_INFO_H + +#include +#include + +#include "distributed_device_profile_constants.h" +#include "dp_parcel.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoProfileNew : public DpParcel { +public: + ServiceInfoProfileNew() + : regServiceIdKey_(REG_SERVICE_ID), + regServiceIdValue_(0), + deviceIdKey_(DEVICE_ID), + deviceIdValue_(""), + userIdKey_(RDB_USER_ID), + userIdValue_(0), + tokenIdKey_(TOKENID), + tokenIdValue_(0), + serPubStateKey_(PUBLISH_STATE), + serPubStateValue_(0), + serviceIdKey_(SISERVICE_ID), + serviceIdValue_(0), + serviceTypeKey_(SERVICE_TYPE), + serviceTypeValue_(""), + serviceNameKey_(SERVICE_NAME), + serviceNameValue_(""), + serviceDisplayNameKey_(SERVICE_DISPLAY_NAME), + serviceDisplayNameValue_(""), + isMultiUser_(false) + {}; + + ~ServiceInfoProfileNew(); + + std::string GetRegServiceIdKey() const; + void SetRegServiceIdKey(const std::string ®ServiceIdKey); + int32_t GetRegServiceIdValue() const; + void SetRegServiceIdValue(const int32_t ®ServiceIdValue); + + std::string GetDeviceIdKey() const; + void SetDeviceIdKey(const std::string &deviceIdKey); + std::string GetDeviceIdValue() const; + void SetDeviceIdValue(const std::string &deviceIdValue); + + std::string GetUserIdKey() const; + void SetUserIdKey(const std::string &userIdKey); + int32_t GetUserIdValue() const; + void SetUserIdValue(const int32_t &userIdValue); + + std::string GetTokenIdKey() const; + void SetTokenIdKey(const std::string &tokenIdKey); + int64_t GetTokenIdValue() const; + void SetTokenIdValue(const int64_t &tokenIdValue); + + std::string GetSerPubStateKey() const; + void SetSerPubStateKey(const std::string &serPubStateKey); + int8_t GetSerPubStateValue() const; + void SetSerPubStateValue(const int8_t &SerPubStateValue); + + std::string GetServiceIdKey() const; + void SetServiceIdKey(const std::string &serviceIdKey); + int64_t GetServiceIdValue() const; + void SetServiceIdValue(const int64_t serviceIdValue); + + std::string GetServiceTypeKey() const; + void SetServiceTypeKey(const std::string &serviceTypeKey); + std::string GetServiceTypeValue() const; + void SetServiceTypeValue(const std::string &serviceTypeValue); + + std::string GetServiceNameKey() const; + void SetServiceNameKey(const std::string &serviceNameKey); + std::string GetServiceNameValue() const; + void SetServiceNameValue(const std::string &serviceNameValue); + + std::string GetServiceDisplayNameKey() const; + void SetServiceDisplayNameKey(const std::string &serviceDisplayNameKey); + std::string GetServiceDisplayNameValue() const; + void SetServiceDisplayNameValue(const std::string &serviceDisplayNameValue); + + bool Marshalling(MessageParcel& parcel) const override; + bool UnMarshalling(MessageParcel& parcel) override; + std::string dump() const override; + + bool IsMultiUser() const; + void SetIsMultiUser(bool isMultiUser); + +private: + std::string regServiceIdKey_; + int32_t regServiceIdValue_; + + std::string deviceIdKey_; + std::string deviceIdValue_; + + std::string userIdKey_; + int32_t userIdValue_; + + std::string tokenIdKey_; + int64_t tokenIdValue_; + + std::string serPubStateKey_ ; + int8_t serPubStateValue_; + + std::string serviceIdKey_; + int64_t serviceIdValue_ ; + + std::string serviceTypeKey_ ; + std::string serviceTypeValue_ ; + + std::string serviceNameKey_ ; + std::string serviceNameValue_; + + std::string serviceDisplayNameKey_; + std::string serviceDisplayNameValue_; + + bool isMultiUser_; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS +#endif //OHOS_DP_SERVICE_INFO_H + \ No newline at end of file diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index 870322f9..52cf2795 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -32,6 +32,7 @@ #include "distributed_device_profile_constants.h" #include "service_profile.h" #include "trust_device_profile.h" +#include "service_info_profile_new.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -53,6 +54,8 @@ public: // This mothed can be invoked only when put or delete profile. static bool IsSvrProfileValid(const ServiceProfile& svrProfile); // This mothed can be invoked only when put or delete profile. + static bool IsSerInfoProfileValid(const ServiceInfoProfileNew& serInfoProfile); + // This mothed can be invoked only when put or delete profile. static bool IsCharProfileValid(const CharacteristicProfile& charProfile); // This mothed can be invoked only when get profile. static bool IsDeviceProfileValid(const DeviceProfile& devProfile); @@ -62,6 +65,7 @@ public: static bool IsCharacteristicProfileValid(const CharacteristicProfile& charProfile); static std::string GenerateDeviceProfileKey(const std::string& deviceId); static std::string GenerateServiceProfileKey(const std::string& deviceId, const std::string& serviceName); + static std::string GenerateServiceInfoProfileKey(const std::string& regServiceId); static std::string GenerateCharProfileKey(const std::string& deviceId, const std::string& serviceName, const std::string& charKey); static int32_t TrustDeviceProfileToEntries(const TrustDeviceProfile& profile, ValuesBucket& values); @@ -72,6 +76,8 @@ public: bool isMultiUser = false); static int32_t ServiceProfileToEntries(const ServiceProfile& profile, std::map& values, bool isMultiUser = false); + static int32_t ServiceInfoProfileToEntries(const ServiceInfoProfileNew& profile, std::map& values, + bool isMultiUser = false); static int32_t CharacteristicProfileToEntries(const CharacteristicProfile& profile, std::map& values, bool isMultiUser = false); static int32_t EntriesToTrustDeviceProfile(const ValuesBucket& values, TrustDeviceProfile& profile); @@ -85,6 +91,8 @@ public: static int32_t EntriesToCharProfile(std::map values, CharacteristicProfile& profile); static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty, int32_t userId = DEFAULT_USER_ID); + static std::string GenerateServiceDBKey(const std::string& regSerDBId, const std::string& fieldInfo, + int32_t userId = DEFAULT_USER_ID); static std::string GetProfileKey(const std::string& dbKey); static std::string GetDeviceIdByDBKey(const std::string& dbKey); static std::string GetServiceNameByDBKey(const std::string& dbKey); @@ -114,6 +122,8 @@ public: static std::string RemoveUserIdFromDbKey(const std::string& dbKey); static int32_t GenerateServiceDBkeys(const std::string& deviceId, const std::string& serviceName, std::vector& dbKeys, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); + static int32_t GenerateServiceInfoProfilekeys(const std::string& regServiceId, std::vector& dbKeys, + bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); 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); diff --git a/common/src/constants/distributed_device_profile_constants.cpp b/common/src/constants/distributed_device_profile_constants.cpp index e86ea9c0..f0f2a6f7 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -72,6 +72,7 @@ const std::string SERVICE_PROFILE_TABLE = "service_profile"; const std::string RDB_USER_ID = "userId"; const std::string SERVICE_PROFILE_DEVICE_PROFILE_ID = "deviceProfileId"; const std::string SERVICE_PROFILE_SERVICE_TYPE = "serviceType"; + /* CharacteristicProfile Attribute */ const std::string SERVICE_PROFILE_ID = "serviceProfileId"; const std::string CHARACTERISTIC_PROFILE_TABLE = "characteristic_profile"; @@ -168,6 +169,9 @@ const std::string GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY = "GetServiceInfoProfil const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID = "GetServiceInfoProfileListByTokenId"; const std::string GET_ALL_SERVICE_INFO_PROFILE_LIST = "GetAllServiceInfoProfileList"; const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME = "GetServiceInfoProfileListByBundleName"; +const std::string REG_SERVICE_ID = "regServiceId"; +const std::string PUBLISH_STATE = "publishState"; +const std::string SERVICE_INFO = "serviceInfo"; /* LocalServiceInfo Attribute */ const std::string PUT_LOCAL_SERVICE_INFO = "PutLocalServiceInfo"; const std::string UPDATE_LOCAL_SERVICE_INFO = "UpdateLocalServiceInfo"; @@ -246,6 +250,26 @@ const std::string LNN_ACL_TRUE = "true"; const std::string BUSINESS_KEY = "businessKey"; const std::string BUSINESS_VALUE = "businessValue"; +//service info profile keys value +const std::string SERVICE_ID_KEY = "serviceIdKey"; +const std::string SERVICE_ID_VALUE = "serviceIdValue"; +const std::string SERVICE_TYPE_KEY = "serviceTypeKey"; +const std::string SERVICE_TYPE_VALUE = "serviceTypeValue"; +const std::string SERVICE_NAME_KEY = "serviceNameKey"; +const std::string SERVICE_NAME_VALUE = "serviceNameValue_"; +const std::string SERVICE_DISPLAY_NAME_KEY = "serviceDisplayNameKey"; +const std::string SERVICE_DISPLAY_NAME_VALUE = "serviceDisplayNameValue"; +const std::string REG_SERVICE_ID_KEY = "regServiceIdKey"; +const std::string REG_SERVICE_ID_VALUE = "regServiceIdValue"; +const std::string SER_PUB_STATE_KEY = "serPubStateKey"; +const std::string SER_PUB_STATE_VALUE = "serPubStateValue"; +const std::string DEVICE_ID_KEY = "deviceIdKey"; +const std::string DEVICE_ID_VALUE = "deviceIdValue"; +const std::string SER_USER_ID_KEY = "userIdKey"; +const std::string SER_USER_ID_VALUE = "userIdValue"; +const std::string SER_TOKEN_ID_KEY = "tokenIdKey"; +const std::string SER_TOKEN_ID_VALUE = "tokenIdValue"; + const std::string CREATE_TURST_DEVICE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS trust_device_table\ (\ deviceId TEXT PRIMARY KEY,\ diff --git a/common/src/interfaces/service_info_profile_new.cpp b/common/src/interfaces/service_info_profile_new.cpp new file mode 100644 index 00000000..508e1f8f --- /dev/null +++ b/common/src/interfaces/service_info_profile_new.cpp @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "service_info_profile_new.h" +#include "cJSON.h" +#include "distributed_device_profile_constants.h" +#include "macro_utils.h" +#include "profile_utils.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +namespace { + const std::string TAG = "ServiceInfoProfileNew"; +} + +ServiceInfoProfileNew::~ServiceInfoProfileNew() +{ +} + +std::string ServiceInfoProfileNew::GetServiceIdKey() const +{ + return serviceIdKey_; +} + +void ServiceInfoProfileNew::SetServiceIdKey(const std::string& serviceIdKey) +{ + serviceIdKey_ = serviceIdKey; +} + +int64_t ServiceInfoProfileNew::GetServiceIdValue() const +{ + return serviceIdValue_; +} + +void ServiceInfoProfileNew::SetServiceIdValue(const int64_t serviceIdValue) +{ + serviceIdValue_ = serviceIdValue; +} + +std::string ServiceInfoProfileNew::ServiceInfoProfileNew::GetServiceTypeKey() const +{ + return serviceTypeKey_; +} + +void ServiceInfoProfileNew::SetServiceTypeKey(const std::string& serviceTypeKey) +{ + serviceTypeKey_ = serviceTypeKey; +} + +std::string ServiceInfoProfileNew::GetServiceTypeValue() const +{ + return serviceTypeValue_; +} + +void ServiceInfoProfileNew::SetServiceTypeValue(const std::string& serviceTypeValue) +{ + serviceTypeValue_ = serviceTypeValue; +} + +std::string ServiceInfoProfileNew::GetServiceNameKey() const +{ + return serviceNameKey_; +} + +void ServiceInfoProfileNew::SetServiceNameKey(const std::string &serviceNameKey) +{ + serviceNameKey_ = serviceNameKey; +} + +std::string ServiceInfoProfileNew::GetServiceNameValue() const +{ + return serviceNameValue_; +} + +void ServiceInfoProfileNew::SetServiceNameValue(const std::string &serviceNameValue) +{ + serviceNameValue_ = serviceNameValue; +} + +std::string ServiceInfoProfileNew::GetServiceDisplayNameKey() const +{ + return serviceDisplayNameKey_; +} + +void ServiceInfoProfileNew::SetServiceDisplayNameKey(const std::string &serviceDisplayNameKey) +{ + serviceDisplayNameKey_ = serviceDisplayNameKey; +} + +std::string ServiceInfoProfileNew::GetServiceDisplayNameValue() const +{ + return serviceDisplayNameValue_; +} + +void ServiceInfoProfileNew::SetServiceDisplayNameValue(const std::string &serviceDisplayNameValue) +{ + serviceDisplayNameValue_ = serviceDisplayNameValue; +} + +std::string ServiceInfoProfileNew::GetRegServiceIdKey() const +{ + return regServiceIdKey_; +} + +void ServiceInfoProfileNew::SetRegServiceIdKey(const std::string ®SerDBIdKey) +{ + regServiceIdKey_ = regSerDBIdKey; +} + +int32_t ServiceInfoProfileNew::GetRegServiceIdValue() const +{ + return regServiceIdValue_; +} + +void ServiceInfoProfileNew::SetRegServiceIdValue(const int32_t ®ServiceIdValue) +{ + regServiceIdValue_ = regServiceIdValue; +} + +std::string ServiceInfoProfileNew::GetSerPubStateKey() const +{ + return serPubStateKey_; +} + +void ServiceInfoProfileNew::SetSerPubStateKey(const std::string &serPubStateKey) +{ + serPubStateKey_ = serPubStateKey; +} + +int8_t ServiceInfoProfileNew::GetSerPubStateValue() const +{ + return serPubStateValue_; +} + +void ServiceInfoProfileNew::SetSerPubStateValue(const int8_t &serPubStateValue) +{ + serPubStateValue_ = serPubStateValue; +} + +std::string ServiceInfoProfileNew::GetDeviceIdKey() const +{ + return deviceIdKey_; +} +void ServiceInfoProfileNew::SetDeviceIdKey(const std::string &deviceIdKey) +{ + deviceIdKey_ = deviceIdKey; +} +std::string ServiceInfoProfileNew::GetDeviceIdValue() const +{ + return deviceIdValue_; +} +void ServiceInfoProfileNew::SetDeviceIdValue(const std::string &deviceIdValue) +{ + deviceIdValue_ = deviceIdValue; +} + +std::string ServiceInfoProfileNew::GetUserIdKey() const +{ + return userIdKey_; +} +void ServiceInfoProfileNew::SetUserIdKey(const std::string &userIdKey) +{ + userIdKey_ = userIdKey; +} +int32_t ServiceInfoProfileNew::GetUserIdValue() const +{ + return userIdValue_; +} +void ServiceInfoProfileNew::SetUserIdValue(const int32_t &userIdValue) +{ + userIdValue_ = userIdValue; +} + +std::string ServiceInfoProfileNew::GetTokenIdKey() const +{ + return tokenIdKey_; +} +void ServiceInfoProfileNew::SetTokenIdKey(const std::string &tokenIdKey) +{ + tokenIdKey_ = tokenIdKey; +} +int64_t ServiceInfoProfileNew::GetTokenIdValue() const +{ + return tokenIdValue_; +} +void ServiceInfoProfileNew::SetTokenIdValue(const int64_t &tokenIdValue) +{ + tokenIdValue_ = tokenIdValue; +} + +bool ServiceInfoProfileNew::Marshalling(MessageParcel& parcel) const +{ + WRITE_HELPER(parcel, String, serviceIdKey_); + WRITE_HELPER(parcel, Int64, serviceIdValue_); + + WRITE_HELPER(parcel, String, serviceTypeKey_); + WRITE_HELPER(parcel, String, serviceTypeValue_); + + WRITE_HELPER(parcel, String, serviceNameKey_); + WRITE_HELPER(parcel, String, serviceNameValue_); + + WRITE_HELPER(parcel, String, serviceDisplayNameKey_); + WRITE_HELPER(parcel, String, serviceDisplayNameValue_); + + WRITE_HELPER(parcel, String, regServiceIdKey_); + WRITE_HELPER(parcel, Int32, regServiceIdValue_); + + WRITE_HELPER(parcel, String, serPubStateKey_); + WRITE_HELPER(parcel, Int8, serPubStateValue_); + + WRITE_HELPER(parcel, String, deviceIdKey_); + WRITE_HELPER(parcel, String, deviceIdValue_); + + WRITE_HELPER(parcel, String, userIdKey_); + WRITE_HELPER(parcel, Int32, userIdValue_); + + WRITE_HELPER(parcel, String, tokenIdKey_); + WRITE_HELPER(parcel, Int64, tokenIdValue_); + + return true; +} + +bool ServiceInfoProfileNew::UnMarshalling(MessageParcel& parcel) +{ + READ_HELPER_RET(parcel, String, serviceIdKey_, false); + READ_HELPER_RET(parcel, Int64, serviceIdValue_, false); + + READ_HELPER_RET(parcel, String, serviceTypeKey_, false); + READ_HELPER_RET(parcel, String, serviceTypeValue_, false); + + READ_HELPER_RET(parcel, String, serviceNameKey_, false); + READ_HELPER_RET(parcel, String, serviceNameValue_, false); + + READ_HELPER_RET(parcel, String, serviceDisplayNameKey_, false); + READ_HELPER_RET(parcel, String, serviceDisplayNameValue_, false); + + READ_HELPER_RET(parcel, String, regServiceIdKey_, false); + READ_HELPER_RET(parcel, Int32, regServiceIdValue_, false); + + READ_HELPER_RET(parcel, String, serPubStateKey_, false); + READ_HELPER_RET(parcel, Int8, serPubStateValue_, false); + + READ_HELPER_RET(parcel, String, deviceIdKey_, false); + READ_HELPER_RET(parcel, String, deviceIdValue_, false); + + READ_HELPER_RET(parcel, String, userIdKey_, false); + READ_HELPER_RET(parcel, Int32, userIdValue_, false); + + READ_HELPER_RET(parcel, String, tokenIdKey_, false); + READ_HELPER_RET(parcel, Int64, tokenIdValue_, false); + + return true; +} + +bool ServiceInfoProfileNew::IsMultiUser() const +{ + return isMultiUser_; +} + +void ServiceInfoProfileNew::SetIsMultiUser(bool isMultiUser) +{ + isMultiUser_ = isMultiUser; +} + +std::string ServiceInfoProfileNew::dump() const +{ + cJSON* json = cJSON_CreateObject(); + if (!cJSON_IsObject(json)) { + cJSON_Delete(json); + return EMPTY_STRING; + } + cJSON_AddStringToObject(json, DEVICE_ID_KEY.c_str(), deviceIdKey_.c_str()); + cJSON_AddStringToObject(json, DEVICE_ID_VALUE.c_str(), deviceIdValue_.c_str()); + + cJSON_AddStringToObject(json, SER_USER_ID_KEY.c_str(), userIdKey_.c_str()); + cJSON_AddStringToObject(json, SER_USER_ID_VALUE.c_str(), std::to_string(userIdValue_).c_str()); + + cJSON_AddStringToObject(json, SER_TOKEN_ID_KEY.c_str(), tokenIdKey_.c_str()); + cJSON_AddStringToObject(json, SER_TOKEN_ID_VALUE.c_str(), std::to_string(tokenIdValue_).c_str()); + + cJSON_AddStringToObject(json, SER_PUB_STATE_KEY.c_str(), serPubStateKey_.c_str()); + cJSON_AddStringToObject(json, SER_PUB_STATE_VALUE.c_str(), std::to_string(serPubStateValue_).c_str()); + + cJSON_AddStringToObject(json, SERVICE_ID_KEY.c_str(), serviceIdKey_.c_str()); + cJSON_AddStringToObject(json, SERVICE_ID_VALUE.c_str(), std::to_string(serviceIdValue_).c_str()); + + cJSON_AddStringToObject(json, SERVICE_TYPE_KEY.c_str(), serviceTypeKey_.c_str()); + cJSON_AddStringToObject(json, SERVICE_TYPE_VALUE.c_str(), serviceTypeValue_.c_str()); + + cJSON_AddStringToObject(json, SERVICE_NAME_KEY.c_str(), serviceNameKey_.c_str()); + cJSON_AddStringToObject(json, SERVICE_NAME_VALUE.c_str(), serviceNameValue_.c_str()); + + cJSON_AddStringToObject(json, SERVICE_DISPLAY_NAME_KEY.c_str(), serviceDisplayNameKey_.c_str()); + cJSON_AddStringToObject(json, SERVICE_DISPLAY_NAME_VALUE.c_str(), serviceDisplayNameValue_.c_str()); + + //cJSON_AddStringToObject(json, REG_SERVICE_ID_KEY.c_str(), regSerDBIdKey_.c_str()); + //cJSON_AddStringToObject(json, REG_SERVICE_ID_VALUE.c_str(), regSerDBIdValue_.c_str()); + + char* jsonChars = cJSON_PrintUnformatted(json); + if (jsonChars == NULL) { + cJSON_Delete(json); + HILOGE("cJSON formatted to string failed!"); + return EMPTY_STRING; + } + std::string jsonStr = jsonChars; + cJSON_Delete(json); + cJSON_free(jsonChars); + return jsonStr; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS + \ No newline at end of file diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 3ba188da..ea414ac9 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -294,6 +294,12 @@ bool ProfileUtils::IsSvrProfileValid(const ServiceProfile& svrProfile) IsKeyValid(svrProfile.GetServiceName()); } +bool ProfileUtils::IsSerInfoProfileValid(const ServiceInfoProfileNew& serInfoProfile) +{ + return IsKeyValid(serInfoProfile.GetDeviceIdKey()) && IsLocalUdid(serInfoProfile.GetDeviceIdValue()) && + IsKeyValid(serInfoProfile.GetServiceNameValue()); +} + bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile) { return IsKeyValid(charProfile.GetDeviceId()) && IsLocalUdid(charProfile.GetDeviceId()) && @@ -334,6 +340,11 @@ std::string ProfileUtils::GenerateServiceProfileKey(const std::string& deviceId, return SVR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName; } +std::string ProfileUtils::GenerateServiceInfoProfileKey(const std::string& regServiceId) +{ + return SERVICE_INFO + SEPARATOR + regServiceId; +} + std::string ProfileUtils::GenerateCharProfileKey(const std::string& deviceId, const std::string& serviceName, const std::string& charKey) { @@ -450,6 +461,48 @@ int32_t ProfileUtils::ServiceProfileToEntries(const ServiceProfile& profile, std return DP_SUCCESS; } +int32_t ProfileUtils::ServiceInfoProfileToEntries(const ServiceInfoProfileNew& profile, std::map& values, bool isMultiUser) +{ + HILOGI("ProfileUtils::ServiceInfoProfileToEntries"); + std::string regServiceId = CheckAndAddOhSuffix(profile.GetRegServiceIdKey(), false); + std::string deviceIdKey = CheckAndAddOhSuffix(profile.GetDeviceIdKey(), false); + std::string userIdKey = CheckAndAddOhSuffix(profile.GetUserIdKey(), false); + std::string tokenIdKey = CheckAndAddOhSuffix(profile.GetTokenIdKey(), false); + std::string serPubStateKey = CheckAndAddOhSuffix(profile.GetSerPubStateKey(), false); + std::string serviceIdKey = CheckAndAddOhSuffix(profile.GetServiceIdKey(), false); + std::string serviceTypeKey = CheckAndAddOhSuffix(profile.GetServiceTypeKey(), false); + std::string serviceNameKey = CheckAndAddOhSuffix(profile.GetServiceNameKey(), false); + std::string serviceDisplayNameKey = CheckAndAddOhSuffix(profile.GetServiceDisplayNameKey(), false); + + int32_t userIdVlue = profile.GetUserIdValue(); + + if (isMultiUser) { + values[GenerateServiceDBKey(regServiceId, deviceIdKey, userIdVlue)] = profile.GetDeviceIdValue(); + values[GenerateServiceDBKey(regServiceId, userIdKey, userIdVlue)] = std::to_string(profile.GetUserIdValue()); + values[GenerateServiceDBKey(regServiceId, tokenIdKey, userIdVlue)] = std::to_string(profile.GetTokenIdValue()); + values[GenerateServiceDBKey(regServiceId, serPubStateKey, userIdVlue)] = + std::to_string(profile.GetSerPubStateValue()); + values[GenerateServiceDBKey(regServiceId, serviceIdKey, userIdVlue)] = + std::to_string(profile.GetServiceIdValue()); + values[GenerateServiceDBKey(regServiceId, serviceTypeKey, userIdVlue)] = profile.GetServiceTypeValue(); + values[GenerateServiceDBKey(regServiceId, serviceNameKey, userIdVlue)] = profile.GetServiceNameValue(); + values[GenerateServiceDBKey(regServiceId, serviceDisplayNameKey, userIdVlue)] = + profile.GetServiceDisplayNameValue(); + } else { + values[GenerateServiceDBKey(regServiceId, deviceIdKey)] = profile.GetDeviceIdValue(); + values[GenerateServiceDBKey(regServiceId, userIdKey)] = std::to_string(profile.GetUserIdValue()); + values[GenerateServiceDBKey(regServiceId, tokenIdKey)] = std::to_string(profile.GetTokenIdValue()); + values[GenerateServiceDBKey(regServiceId, serPubStateKey)] = std::to_string(profile.GetSerPubStateValue()); + values[GenerateServiceDBKey(regServiceId, serviceIdKey)] = std::to_string(profile.GetServiceIdValue()); + values[GenerateServiceDBKey(regServiceId, serviceTypeKey)] = profile.GetServiceTypeValue(); + values[GenerateServiceDBKey(regServiceId, serviceNameKey)] = profile.GetServiceNameValue(); + values[GenerateServiceDBKey(regServiceId, serviceDisplayNameKey)] = profile.GetServiceDisplayNameValue(); + } + + return DP_SUCCESS; +} + int32_t ProfileUtils::CharacteristicProfileToEntries(const CharacteristicProfile& profile, std::map& values, bool isMultiUser) { @@ -750,6 +803,20 @@ std::string ProfileUtils::GenerateDBKey(const std::string& profileKey, const std return DBKey; } +std::string ProfileUtils::GenerateServiceDBKey(const std::string& regServiceId, const std::string& trailInfo, + int32_t userId) +{ + std::string DBKey = ""; + + if (userId != DEFAULT_USER_ID) { + DBKey = "serviceInfo" + SEPARATOR + regServiceId + SEPARATOR + trailInfo + SEPARATOR + std::to_string(userId); + } else { + DBKey = "serviceInfo" + SEPARATOR + regServiceId + SEPARATOR + trailInfo; + } + + return DBKey; +} + std::string ProfileUtils::GetProfileProperty(const std::string& dbKey, int32_t userId) { if (dbKey.length() == 0 || dbKey.length() > MAX_STRING_LEN) { @@ -979,6 +1046,38 @@ int32_t ProfileUtils::GenerateServiceDBkeys(const std::string& deviceId, const s return DP_SUCCESS; } +int32_t ProfileUtils::GenerateServiceInfoProfilekeys(const std::string& regServiceId, std::vector& dbKeys, + bool isMultiUser, int32_t userId) +{ + std::string regServiceIdTmp = CheckAndAddOhSuffix(regServiceId, false); + std::string serviceProfileKey = GenerateServiceInfoProfileKey(regServiceIdTmp); + // value not need add OH suffix + if (isMultiUser) { + //dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, REG_SERVICE_ID, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, DEVICE_ID, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, RDB_USER_ID, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, TOKENID, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, PUBLISH_STATE, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_PROFILE_SERVICE_ID, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_TYPE, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_NAME, userId)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_DISPLAY_NAME, userId)); + + } else { + //dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, REG_SERVICE_ID)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, DEVICE_ID)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, RDB_USER_ID)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, TOKENID)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, PUBLISH_STATE)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_PROFILE_SERVICE_ID)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_TYPE)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_NAME)); + dbKeys.emplace_back(GenerateDBKey(serviceProfileKey, SERVICE_DISPLAY_NAME)); + } + return DP_SUCCESS; +} + + int32_t ProfileUtils::GenerateCharacteristicDBkeys(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, std::vector& dbKeys, bool isMultiUser, int32_t userId) { diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index ad13bc05..cba2628f 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -108,11 +108,13 @@ public: int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey); int32_t PutBusinessEvent(const BusinessEvent& event); int32_t GetBusinessEvent(BusinessEvent& event); + int32_t PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfo); + int32_t DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, int32_t userId); + int32_t GetServiceInfo(ServiceInfoProfileNew & serviceInfo); void LoadSystemAbilitySuccess(const sptr &remoteObject); void LoadSystemAbilityFail(); void ReleaseResource(); - public: class SystemAbilityListener : public SystemAbilityStatusChangeStub { public: diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h index d9e96ee3..730a7b39 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h @@ -31,6 +31,7 @@ #include "ipc_utils.h" #include "profile_change_listener_stub.h" + namespace OHOS { namespace DistributedDeviceProfile { class DistributedDeviceProfileProxy : public IRemoteProxy { @@ -103,7 +104,9 @@ public: int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) override; int32_t PutBusinessEvent(const BusinessEvent& event) override; int32_t GetBusinessEvent(BusinessEvent& event) override; - + int32_t PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfoProfile) override; + int32_t DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, int32_t userId) override; + int32_t GetServiceInfo(ServiceInfoProfileNew & serviceInfoProfile) override; private: static inline BrokerDelegator delegator_; }; diff --git a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index bb6bae50..7c26cca6 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -1217,5 +1217,28 @@ int32_t DistributedDeviceProfileClient::GetBusinessEvent(BusinessEvent& event) } return dpService->GetBusinessEvent(event); } + +int32_t DistributedDeviceProfileClient::PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfoProfile) +{ + HILOGI("DistributedDeviceProfileClient::PutServiceInfoProfileNew"); + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->PutServiceInfoProfileNew(serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, + int32_t userId) +{ + HILOGI("DistributedDeviceProfileClient::DelServiceInfoProfileNew"); + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->DelServiceInfoProfileNew(regServiceId, isMultiUser, userId); +} } // namespace DeviceProfile } // namespace OHOS diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp index 9abe3f8d..6ce9e252 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp @@ -848,5 +848,43 @@ int32_t DistributedDeviceProfileProxy::GetBusinessEvent(BusinessEvent& event) } return DP_SUCCESS; } + +int32_t DistributedDeviceProfileProxy::PutServiceInfoProfileNew(const ServiceInfoProfileNew& serviceInfoProfile) +{ + HILOGI("DistributedDeviceProfileProxy::PutServiceInfoProfileNew"); + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!serviceInfoProfile.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE_NEW), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, + int32_t userId) +{ + HILOGI("DistributedDeviceProfileProxy::DelServiceInfoProfileNew"); + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + WRITE_HELPER(data, Int32, regServiceId); + WRITE_HELPER(data, Bool, isMultiUser); + WRITE_HELPER(data, Int32, userId); + + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_SERVICE_INFO_PROFILE_NEW), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetServiceInfo(ServiceInfoProfileNew& serviceInfoProfile) +{ + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 18ec16e8..c8ebd3a8 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -38,6 +38,7 @@ config("device_info_manager_config") { "include/profiledatamanager", "include/publishcommonevent", "include/serviceinfoprofile_manager", + "include/serviceinfo_manager", "include/sessionkeymanager", "include/subscribeprofilemanager", "include/staticcapabilitycollector", @@ -112,6 +113,7 @@ ohos_shared_library("distributed_device_profile_svr") { "src/persistenceadapter/assetadapter/asset_adapter.cpp", "src/persistenceadapter/kvadapter/business_event_adapter.cpp", "src/persistenceadapter/kvadapter/kv_adapter.cpp", + "src/persistenceadapter/kvadapter/service_info_kv_adapter.cpp", "src/persistenceadapter/kvadapter/switch_adapter.cpp", "src/persistenceadapter/rdbadapter/local_service_info_rdb_adapter.cpp", "src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp", @@ -123,6 +125,7 @@ ohos_shared_library("distributed_device_profile_svr") { "src/profiledatamanager/profile_data_manager.cpp", "src/publishcommonevent/dp_account_common_event.cpp", "src/serviceinfoprofile_manager/service_info_profile_manager.cpp", + "src/serviceinfo_manager/service_info_manager.cpp", "src/sessionkeymanager/session_key_manager.cpp", "src/staticcapabilitycollector/static_capability_collector.cpp", "src/staticcapabilityloader/static_capability_loader.cpp", diff --git a/services/core/include/common/dp_services_constants.h b/services/core/include/common/dp_services_constants.h index 270c2559..7e9d1321 100644 --- a/services/core/include/common/dp_services_constants.h +++ b/services/core/include/common/dp_services_constants.h @@ -43,6 +43,9 @@ extern const std::string CREATE_DEVICE_PROFILE_TABLE_UNIQUE_INDEX_SQL; extern const std::string CREATE_DEVICE_PROFILE_WISE_DEVICEID_INDEX_SQL; extern const std::string ALTER_TABLE_DP_ADD_COLUMN_PRODUCT_NAME_SQL; extern const std::string ALTER_TABLE_DP_RENAME_COLUMN_INTERNAL_MODEL_SQL; +/* DeviceDao */ +extern const std::string SERVICE_INFO_RDB_PATH; +extern const std::string SERVICE_INFO_DATABASE_NAME; // DeviceIconInfoDao extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL ; extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_UNIQUE_INDEX_SQL; @@ -72,6 +75,15 @@ extern const std::string SERVICE_INFO_PROFILE_UNIQUE_INDEX_EQUAL_CONDITION; extern const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID_SERVICEID; extern const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID; extern const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_BUNDLENAME; +// ServiceInfo +extern const std::string SERVICE_INFO_TABLE; +extern const std::string CREATE_SERVICE_INFO_TABLE_SQL; +extern const std::string CREATE_SERVICE_INFO_TABLE_UNIQUE_INDEX_SQL; +extern const std::string SELECT_SERVICE_INFO_ALL; +extern const std::string SERVICE_INFO_UNIQUE_INDEX_EQUAL_CONDITION; +extern const std::string SELECT_SERVICE_INFO_TABLE_WHERE_DEVID_USERID_TOKENID_SERVICEID; +extern const std::string SELECT_SERVICE_INFO_TABLE_WHERE_DEVID_USERID_TOKENID; +extern const std::string SELECT_SERVICE_INFO_TABLE_WHERE_DEVID_USERID_BUNDLENAME; // LocalServiceInfo extern const std::string LOCAL_SERVICE_INFO_RDB_PATH; extern const std::string LOCAL_SERVICE_INFO_DATABASE_NAME; diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 5bdd2026..052c1aa2 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -35,6 +35,7 @@ #include "single_instance.h" #include "system_ability.h" #include "system_ability_definition.h" +#include "service_info_profile_new.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -124,6 +125,10 @@ public: int32_t PutBusinessEvent(const BusinessEvent& event) override; int32_t GetBusinessEvent(BusinessEvent& event) override; + int32_t PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfoProfile) override; + int32_t DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, int32_t userId) override; + int32_t GetServiceInfo(ServiceInfoProfileNew & serviceInfoProfile) override; + protected: void OnStart(const SystemAbilityOnDemandReason& startReason) override; void OnStop() override; diff --git a/services/core/include/distributed_device_profile_stub_new.h b/services/core/include/distributed_device_profile_stub_new.h index c24d6744..f93b9c68 100644 --- a/services/core/include/distributed_device_profile_stub_new.h +++ b/services/core/include/distributed_device_profile_stub_new.h @@ -87,6 +87,9 @@ public: int32_t UnRegisterBusinessCallbackInner(MessageParcel& data, MessageParcel& reply); int32_t PutBusinessEventInner(MessageParcel& data, MessageParcel& reply); int32_t GetBusinessEventInner(MessageParcel& data, MessageParcel& reply); + int32_t PutServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply); + int32_t DelServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply); + int32_t GetServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply); private: using Func = int32_t(DistributedDeviceProfileStubNew::*)(MessageParcel& data, MessageParcel& reply); diff --git a/services/core/include/persistenceadapter/kvadapter/service_info_kv_adapter.h b/services/core/include/persistenceadapter/kvadapter/service_info_kv_adapter.h new file mode 100644 index 00000000..e213b3c8 --- /dev/null +++ b/services/core/include/persistenceadapter/kvadapter/service_info_kv_adapter.h @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_SERVICE_KV_ADAPTER_H +#define OHOS_DM_SERVICE_KV_ADAPTER_H + +#include +#include +#include +#include +#include +#include +#include + +#include "distributed_kv_data_manager.h" +#include "ikv_adapter.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoKvAdapter : public DistributedDeviceProfile::IKVAdapter { +public: + ServiceInfoKvAdapter( + const std::shared_ptr &deathListener, DistributedKv::DataType dataType); + + int32_t Init() override; + int32_t UnInit() override; + int32_t ReInit(); + int32_t Put(const std::string& key, const std::string& value) override; + int32_t Get(const std::string& key, std::string& value) override; + int32_t DeleteBatch(const std::vector& keys) override; + int32_t PutBatch(const std::map& values) override; + int32_t Delete(const std::string& key) override; + int32_t DeleteByPrefix(const std::string& keyPrefix) override; + int32_t GetByPrefix(const std::string& keyPrefix, std::map& values) override; + int32_t Sync(const std::vector& deviceList, SyncMode syncMode) override; + int32_t GetDeviceEntries(const std::string& udid, std::map& values) override; + int32_t RemoveDeviceData(const std::string& uuid) override; + void OnRemoteDied(); + +private: + DistributedKv::Status GetKvStorePtr(); + int32_t RegisterKvStoreDeathListener(); + int32_t UnregisterKvStoreDeathListener(); + +private: + DistributedKv::AppId appId_; + DistributedKv::StoreId storeId_; + DistributedKv::DistributedKvDataManager kvDataMgr_; + DistributedKv::DataType dataType_ = DistributedKv::DataType::TYPE_STATICS; + std::shared_ptr kvStorePtr_ = nullptr; + std::shared_ptr deathRecipient_ = nullptr; + + std::mutex serviceInfoAdapterMutex_; + std::atomic isInited_ = false; + std::mutex kvAdapterMutex_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_SERVICE_KV_ADAPTER_H diff --git a/services/core/include/serviceinfo_manager/service_info_manager.h b/services/core/include/serviceinfo_manager/service_info_manager.h new file mode 100644 index 00000000..fe094255 --- /dev/null +++ b/services/core/include/serviceinfo_manager/service_info_manager.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DP_SERVICE_INFO_MANAGER_H +#define OHOS_DP_SERVICE_INFO_MANAGER_H + +#include +#include +#include + +#include "service_info_profile_new.h" +#include "service_info_kv_adapter.h" +#include "distributed_device_profile_constants.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoProfileNewManage { +DECLARE_SINGLE_INSTANCE(ServiceInfoProfileNewManage); +public: + int32_t Init(); + int32_t UnInit(); + int32_t ReInit(); + int32_t PutServiceInfoProfile(const ServiceInfoProfileNew& serviceInfoProfile); + int32_t DeleteServiceInfoProfile(const int32_t regServiceId, bool isMultiUser = false, + int32_t userId = DEFAULT_USER_ID); + int32_t UpdateServiceInfoProfile(const int32_t regServiceId, const ServiceInfoProfileNew &serviceInfoProfile); + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfileList); + int32_t GetServiceInfoProfileByServiceId(const int64_t &serviceId, ServiceInfoProfileNew &serviceInfoProfile); + int32_t GetServiceInfoProfileByRegServiceId(const int32_t ®ServiceId, ServiceInfoProfileNew &serviceInfoProfile); + + void AddToPutTempCache(const std::map& values); +private: + bool IsValidKey(const std::string& key); + +private: + std::shared_ptr serviceInfoKvAdapter_ = nullptr; + std::mutex dynamicStoreMutex_; + std::atomic isFirst_{true}; + std::map putTempCache_; + //std::shared_ptr deviceProfileStore_ = nullptr; + //std::shared_ptr serviceInfoProfileStore_ = nullptr; + + std::mutex putTempCacheMutex_; +}; +} // DistributedDeviceProfile +} // OHOS +#endif // OHOS_DP_SERVICE_INFO_MANAGER_H + \ No newline at end of file diff --git a/services/core/include/utils/profile_cache.h b/services/core/include/utils/profile_cache.h index 5ca3dbe2..773a3bb5 100644 --- a/services/core/include/utils/profile_cache.h +++ b/services/core/include/utils/profile_cache.h @@ -111,6 +111,7 @@ private: std::mutex serviceProfileMutex_; // The key is profileKey, the value is ServiceProfile std::unordered_map serviceProfileMap_; + std::unordered_map serviceInfoProfileMap_; std::mutex charProfileMutex_; // The key is profileKey, the value is CharacteristicProfile std::unordered_map charProfileMap_; diff --git a/services/core/include/utils/profile_control_utils.h b/services/core/include/utils/profile_control_utils.h index d94d2b1c..85f0a4ba 100644 --- a/services/core/include/utils/profile_control_utils.h +++ b/services/core/include/utils/profile_control_utils.h @@ -52,6 +52,8 @@ public: 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, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); + static int32_t DeleteServiceInfoProfile(std::shared_ptr kvStore, const int32_t regServiceId, + bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); static int32_t DeleteCharacteristicProfile(std::shared_ptr kvStore, const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID); diff --git a/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp b/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp index cfda0158..7384b210 100644 --- a/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp +++ b/services/core/src/deviceprofilemanager/listener/kv_store_death_recipient.cpp @@ -21,6 +21,8 @@ #include "distributed_device_profile_constants.h" #include "static_profile_manager.h" +#include "service_info_manager.h" + namespace OHOS { namespace DistributedDeviceProfile { namespace { @@ -29,6 +31,7 @@ namespace { const std::string DYNAMIC_STORE_ID = "dp_kv_store"; const std::string STATIC_STORE_ID = "dp_kv_static_store"; const std::string BUSINESS_STORE_ID = "dp_kv_store_business"; + const std::string SERVICE_INFO_STORE_ID = "dp_kv_store_service_info_profile"; } KvDeathRecipient::KvDeathRecipient(const std::string& storeId) @@ -69,6 +72,9 @@ void KvDeathRecipient::OnRemoteDied() if (storeId == BUSINESS_STORE_ID) { DeviceProfileManager::GetInstance().ReInit(); } + if (storeId == SERVICE_INFO_STORE_ID) { + ServiceInfoProfileNewManage::GetInstance().ReInit(); + } }; { std::lock_guard lock(reInitMutex_); diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 532b0f05..3cef5867 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -42,6 +42,7 @@ #include "profile_cache.h" #include "profile_data_manager.h" #include "service_info_profile_manager.h" +#include "service_info_manager.h" #include "settings_data_manager.h" #include "static_profile_manager.h" #include "static_capability_collector.h" @@ -161,6 +162,11 @@ int32_t DistributedDeviceProfileServiceNew::PostInitNext() HILOGE("BusinessEventManager init failed"); return DP_BUSINESS_EVENT_MANAGER_INIT_FAIL; } + if (ServiceInfoProfileNewManage::GetInstance().Init() != DP_SUCCESS) { + HILOGE("ServiceInfoManager init failed"); + return DP_SERVICE_INFO_PROFILE_MANAGER_INIT_FAIL; + } + #ifndef DEVICE_PROFILE_SWITCH_DISABLE SaveSwitchProfilesFromTempCache(); #endif // DEVICE_PROFILE_SWITCH_DISABLE @@ -289,6 +295,10 @@ int32_t DistributedDeviceProfileServiceNew::UnInitNext() HILOGE("EventHandlerFactory UnInit failed"); return DP_CACHE_UNINIT_FAIL; } + if (ServiceInfoProfileNewManage::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("ServiceInfoManager uninit failed"); + return DP_SERVICE_INFO_PROFILE_MANAGER_INIT_FAIL; + } return DP_SUCCESS; } @@ -1490,5 +1500,50 @@ int32_t DistributedDeviceProfileServiceNew::NotifyBusinessEvent(const BusinessEv HILOGI("NotifyBusinessEvent task posted successfully"); return DP_SUCCESS; } + +int32_t DistributedDeviceProfileServiceNew::PutServiceInfoProfileNew(const ServiceInfoProfileNew& serviceInfoProfile) +{ + HILOGI("DistributedDeviceProfileServiceNew::PutServiceInfoProfileNew"); + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface PutServiceInfoProfile"); + int32_t ret = ServiceInfoProfileNewManage::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + if (ret != DP_SUCCESS) { + HILOGE("PutServiceInfoProfile failed, ret: %{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileServiceNew::DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, + int32_t userId) +{ + HILOGI("DistributedDeviceProfileServiceNew::DelServiceInfoProfileNew"); + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface DelServiceInfoProfile"); + int32_t ret = ServiceInfoProfileNewManage::GetInstance().DeleteServiceInfoProfile(regServiceId, isMultiUser, userId); + if (ret != DP_SUCCESS) { + HILOGE("PutServiceInfoProfile failed, ret: %{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileServiceNew::GetServiceInfo(ServiceInfoProfileNew& serviceInfoProfile) +{ + HILOGI("DistributedDeviceProfileServiceNew::GetServiceInfo"); + // if (!PermissionManager::GetInstance().CheckCallerPermission()) { + // HILOGE("the caller is permission denied!"); + // return DP_PERMISSION_DENIED; + // } + // HILOGD("CheckCallerPermission success interface GetServiceInfo"); + //return ServiceInfoProfileNewManage::GetInstance().GetServiceInfo(event); + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp index eb60f577..11920b85 100644 --- a/services/core/src/distributed_device_profile_stub_new.cpp +++ b/services/core/src/distributed_device_profile_stub_new.cpp @@ -216,6 +216,12 @@ int32_t DistributedDeviceProfileStubNew::NotifyLocalServiceEventInner(uint32_t c return PutBusinessEventInner(data, reply); case static_cast(DPInterfaceCode::GET_BUSINESS_EVENT): return GetBusinessEventInner(data, reply); + case static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE_NEW): + return PutServiceInfoProfileNewInner(data, reply); + case static_cast(DPInterfaceCode::DEL_SERVICE_INFO_PROFILE_NEW): + return DelServiceInfoProfileNewInner(data, reply); + case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_NEW): + return GetServiceInfoProfileNewInner(data, reply); default: HILOGW("unknown request code, please check, code = %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -1155,5 +1161,46 @@ int32_t DistributedDeviceProfileStubNew::GetBusinessEventInner(MessageParcel& da } return DP_SUCCESS; } + +int32_t DistributedDeviceProfileStubNew::PutServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("DistributedDeviceProfileStubNew::PutServiceInfoProfileNewInner"); + ServiceInfoProfileNew serviceInfoProfile; + if (!serviceInfoProfile.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = PutServiceInfoProfileNew(serviceInfoProfile); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStubNew::DelServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("DistributedDeviceProfileStubNew::DelServiceInfoProfileNewInner"); + int32_t regServiceId = 0; + bool isMultiUser = false; + int32_t userId = 0; + READ_HELPER(data, Int32, regServiceId); + READ_HELPER(data, Bool, isMultiUser); + READ_HELPER(data, Int32, userId); + + int32_t ret = DelServiceInfoProfileNew(regServiceId, isMultiUser, userId); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileNewInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("DistributedDeviceProfileStubNew::GetServiceInfoProfileNewInner"); + + return DP_SUCCESS; +} } // namespace DeviceProfile } // namespace OHOS diff --git a/services/core/src/persistenceadapter/kvadapter/service_info_kv_adapter.cpp b/services/core/src/persistenceadapter/kvadapter/service_info_kv_adapter.cpp new file mode 100644 index 00000000..080aad9e --- /dev/null +++ b/services/core/src/persistenceadapter/kvadapter/service_info_kv_adapter.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "service_info_kv_adapter.h" + +#include +#include + +#include "datetime_ex.h" +#include "string_ex.h" +#include "ffrt.h" + +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "distributed_device_profile_constants.h" +#include "profile_cache.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using namespace OHOS::DistributedKv; +namespace { + constexpr int32_t MAX_INIT_RETRY_TIMES = 30; + constexpr int32_t INIT_RETRY_SLEEP_INTERVAL = 200 * 1000; + constexpr uint32_t MAX_BATCH_SIZE = 128; + const std::string DATABASE_DIR = "/data/service/el1/public/database/distributed_device_profile_service"; + const std::string TAG = "ServiceInfoKvAdapter"; + const std::string APP_ID = "distributed_device_profile_service"; + const std::string STORE_ID = "dp_kv_store_service_info_profile"; +} + +ServiceInfoKvAdapter::ServiceInfoKvAdapter( + const std::shared_ptr &deathListener, DistributedKv::DataType dataType) +{ + this->deathRecipient_ = deathListener; + this->dataType_ = dataType; + HILOGD("ServiceInfoKvAdapter Constructor Success"); +} + +int32_t ServiceInfoKvAdapter::Init() +{ + HILOGI("ServiceInfoKvAdapter Init"); + HILOGI("Init local DB, dataType: %{public}d", static_cast(dataType_)); + if (isInited_.load()) { + HILOGI("Local DB already inited."); + return DP_SUCCESS; + } + this->appId_.appId = APP_ID; + this->storeId_.storeId = STORE_ID; + int32_t tryTimes = MAX_INIT_RETRY_TIMES; + int64_t beginTime = GetTickCount(); + while (tryTimes > 0) { + DistributedKv::Status status = GetKvStorePtr(); + if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ != nullptr) { + HILOGI("Init KvStorePtr Success"); + RegisterKvStoreDeathListener(); + isInited_.store(true); + return DP_SUCCESS; + } + HILOGI("CheckKvStore, left times: %{public}d, status: %{public}d", tryTimes, status); + usleep(INIT_RETRY_SLEEP_INTERVAL); + tryTimes--; + } + if (kvStorePtr_ == nullptr) { + HILOGE("kvStorePtr is nullptr!"); + return DP_KV_DB_PTR_NULL; + } + isInited_.store(true); + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::UnInit() +{ + HILOGI("ServiceInfoKvAdapter UnInit"); + if (isInited_.load()) { + if (kvStorePtr_ == nullptr) { + HILOGE("kvStorePtr is nullptr!"); + return DP_KV_DB_PTR_NULL; + } + UnregisterKvStoreDeathListener(); + kvStorePtr_.reset(); + isInited_.store(false); + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::ReInit() +{ + HILOGI("ServiceInfoKvAdapter ReInit"); + UnInit(); + return Init(); +} + +int32_t ServiceInfoKvAdapter::Put(const std::string& key, const std::string& value) +{ + HILOGI("ServiceInfoKvAdapter::Put"); + if (key.empty() || key.size() > MAX_STRING_LEN || value.empty() || value.size() > MAX_STRING_LEN) { + HILOGE("Param is invalid: key or value is empty or too long"); + return DP_INVALID_PARAMS; + } + DistributedKv::Status status; + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ == nullptr) { + HILOGE("kvDBPtr is null!"); + return DP_KV_DB_PTR_NULL; + } + + DistributedKv::Key kvKey(key); + DistributedKv::Value kvValue(value); + status = kvStorePtr_->Put(kvKey, kvValue); + } + if (status != DistributedKv::Status::SUCCESS) { + HILOGE("Put kv to db failed, ret: %{public}d", status); + return DP_PUT_KV_DB_FAIL; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::Get(const std::string& key, std::string& value) +{ + HILOGI("ServiceInfoKvAdapter::Get"); + HILOGI("Get data by key: %{public}s", ProfileUtils::GetDbKeyAnonyString(key).c_str()); + DistributedKv::Key kvKey(key); + DistributedKv::Value kvValue; + DistributedKv::Status status; + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ == nullptr) { + HILOGE("kvStoragePtr_ is null"); + return DP_KV_DB_PTR_NULL; + } + status = kvStorePtr_->Get(kvKey, kvValue); + } + if (status != DistributedKv::Status::SUCCESS) { + HILOGE("Get data from kv failed, key: %{public}s", ProfileUtils::GetDbKeyAnonyString(key).c_str()); + return DP_GET_KV_DB_FAIL; + } + value = kvValue.ToString(); + return DP_SUCCESS; +} + +void ServiceInfoKvAdapter::OnRemoteDied() +{ + HILOGI("ServiceInfoKvAdapter::OnRemoteDied"); + HILOGI("OnRemoteDied, recover db begin"); + auto reInitTask = [this]() { + HILOGI("ReInit, storeId:%{public}s", storeId_.storeId.c_str()); + ReInit(); + }; + ffrt::submit(reInitTask); +} + +DistributedKv::Status ServiceInfoKvAdapter::GetKvStorePtr() +{ + HILOGI("ServiceInfoKvAdapter::GetKvStorePtr"); + DistributedKv::Options options = { + .createIfMissing = true, + .encrypt = false, + .autoSync = false, + .securityLevel = DistributedKv::SecurityLevel::S1, + .area = 1, + .kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION, + .baseDir = DATABASE_DIR + }; + DistributedKv::Status status; + { + std::lock_guard lock(kvAdapterMutex_); + status = kvDataMgr_.GetSingleKvStore(options, appId_, storeId_, kvStorePtr_); + if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ == nullptr) { + status = DistributedKv::Status::ERROR; + } + } + return status; +} + +int32_t ServiceInfoKvAdapter::RegisterKvStoreDeathListener() +{ + HILOGI("ServiceInfoKvAdapter::RegisterKvStoreDeathListener"); + HILOGI("Register death listener"); + { + std::lock_guard lock(kvAdapterMutex_); + kvDataMgr_.RegisterKvStoreServiceDeathRecipient(deathRecipient_); + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::UnregisterKvStoreDeathListener() +{ + HILOGI("ServiceInfoKvAdapter::UnregisterKvStoreDeathListener"); + HILOGI("UnRegister death listener"); + { + std::lock_guard lock(kvAdapterMutex_); + kvDataMgr_.UnRegisterKvStoreServiceDeathRecipient(deathRecipient_); + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::Delete(const std::string& key) +{ + HILOGI("ServiceInfoKvAdapter::Delete"); + HILOGI("key: %{public}s", ProfileUtils::GetDbKeyAnonyString(key).c_str()); + DistributedKv::Status status; + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ == nullptr) { + HILOGE("kvDBPtr is null!"); + return DP_KV_DB_PTR_NULL; + } + DistributedKv::Key kvKey(key); + status = kvStorePtr_->Delete(kvKey); + } + if (status != DistributedKv::Status::SUCCESS) { + HILOGE("Delete kv by key failed!"); + return DP_DEL_KV_DB_FAIL; + } + HILOGD("Delete kv by key success!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::DeleteBatch(const std::vector& keys) +{ + HILOGI("ServiceInfoKvAdapter::DeleteBatch"); + if (keys.empty() || keys.size() > MAX_PROFILE_SIZE) { + HILOGE("keys size(%{public}zu) is invalid!", keys.size()); + return DP_INVALID_PARAMS; + } + + uint32_t keysSize = static_cast(keys.size()); + std::vector> delKeyBatches; + for (uint32_t i = 0; i < keysSize; i += MAX_BATCH_SIZE) { + uint32_t end = (i + MAX_BATCH_SIZE) > keysSize ? keysSize : (i + MAX_BATCH_SIZE); + auto batch = std::vector(keys.begin() + i, keys.begin() + end); + std::vector delKeys; + for (auto item : batch) { + DistributedKv::Key key(item); + delKeys.emplace_back(key); + } + delKeyBatches.emplace_back(delKeys); + } + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ == nullptr) { + HILOGE("kvStorePtr is nullptr!"); + return DP_KV_DB_PTR_NULL; + } + for (auto delKeys : delKeyBatches) { + DistributedKv::Status status = kvStorePtr_->DeleteBatch(delKeys); + if (status != DistributedKv::Status::SUCCESS) { + HILOGE("DeleteBatch failed!"); + return DP_DEL_KV_DB_FAIL; + } + } + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::PutBatch(const std::map& values) +{ + HILOGI("ServiceInfoKvAdapter::PutBatch"); + if (values.empty() || values.size() > MAX_PROFILE_SIZE) { + HILOGE("Param is invalid!"); + return DP_INVALID_PARAMS; + } + DistributedKv::Status status; + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ == nullptr) { + HILOGE("kvDBPtr is null!"); + return DP_KV_DB_PTR_NULL; + } + std::vector entries; + DistributedKv::Value oldV; + DistributedKv::Key kvKey; + for (auto item : values) { + kvKey = item.first; + if (kvStorePtr_->Get(kvKey, oldV) == DistributedKv::Status::SUCCESS && oldV.ToString() == item.second) { + HILOGI("The key-value pair already exists. key=%{public}s,value=%{public}s", + ProfileUtils::GetDbKeyAnonyString(item.first).c_str(), + ProfileUtils::GetAnonyString(item.second).c_str()); + continue; + } + + Entry entry; + entry.key = kvKey; + entry.value = item.second; + entries.emplace_back(entry); + } + if (entries.empty()) { + HILOGD("All key-value pair already exists."); + return DP_SUCCESS; + } + status = kvStorePtr_->PutBatch(entries); + } + if (status != DistributedKv::Status::SUCCESS) { + HILOGE("PutBatch kv to db failed, ret: %{public}d", status); + return DP_PUT_KV_DB_FAIL; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::GetByPrefix(const std::string& keyPrefix, std::map& values) +{ + (void)keyPrefix; + (void)values; + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::DeleteByPrefix(const std::string& keyPrefix) +{ + (void)keyPrefix; + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::Sync(const std::vector& deviceList, SyncMode syncMode) +{ + (void)deviceList; + (void)syncMode; + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::GetDeviceEntries(const std::string& udid, std::map& values) +{ + (void)udid; + (void)values; + return DP_SUCCESS; +} + +int32_t ServiceInfoKvAdapter::RemoveDeviceData(const std::string& uuid) +{ + (void)uuid; + return DP_SUCCESS; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/core/src/serviceinfo_manager/service_info_manager.cpp b/services/core/src/serviceinfo_manager/service_info_manager.cpp new file mode 100644 index 00000000..8e795119 --- /dev/null +++ b/services/core/src/serviceinfo_manager/service_info_manager.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "service_info_manager.h" +#include "profile_utils.h" + +#include "service_info_profile_new.h" +#include "distributed_device_profile_constants.h" +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "dp_services_constants.h" +#include "kv_data_change_listener.h" +#include "kv_store_death_recipient.h" +#include "kv_sync_completed_listener.h" +#include "profile_control_utils.h" + +#include "multi_user_manager.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(ServiceInfoProfileNewManage) + +namespace { + const std::string DP_REJECT_KEY = "business_id_cast+_reject_event"; + const std::string DP_DISTURBANCE_KEY = "business_id_cast+_disturbance_event"; + const std::string STORE_ID = "dp_kv_store_service_info_profile"; + const std::string TAG = "ServiceInfoProfileNewManage"; + const std::set validKeys_ = { DP_REJECT_KEY, DP_DISTURBANCE_KEY }; +} + +int32_t ServiceInfoProfileNewManage::Init() +{ + HILOGI("call!"); + std::lock_guard lock(dynamicStoreMutex_); + serviceInfoKvAdapter_ = std::make_shared( + std::make_shared(STORE_ID), DistributedKv::TYPE_DYNAMICAL); + int32_t ret = serviceInfoKvAdapter_->Init(); + if (ret != DP_SUCCESS) { + HILOGE("businessEventAdapter init failed, ret: %{public}d", ret); + return DP_INIT_DB_FAILED; + } + HILOGI("Init finish, ret: %{public}d", ret); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::UnInit() +{ + HILOGI("call!"); + { + std::lock_guard lock(dynamicStoreMutex_); + if (serviceInfoKvAdapter_ == nullptr) { + HILOGE("serviceInfoKvAdapter_ is nullptr"); + return DP_KV_DB_PTR_NULL; + } + serviceInfoKvAdapter_->UnInit(); + serviceInfoKvAdapter_ = nullptr; + } + HILOGI("UnInit success"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::ReInit() +{ + HILOGI("call!"); + UnInit(); + return Init(); +} + +int32_t ServiceInfoProfileNewManage::PutServiceInfoProfile(const ServiceInfoProfileNew& serviceInfoProfile) +{ + HILOGI("ServiceInfoProfileNewManage::PutServiceInfoProfile"); + int32_t userId = serviceInfoProfile.GetUserIdValue(); + HILOGI("serviceInfoProfile: %{public}s", serviceInfoProfile.dump().c_str()); + if (!ProfileUtils::IsSerInfoProfileValid(serviceInfoProfile)) { + HILOGE("the profile is invalid!"); + return DP_INVALID_PARAMS; + } + std::map entries; + if (serviceInfoProfile.IsMultiUser()) { + ProfileUtils::ServiceInfoProfileToEntries(serviceInfoProfile, entries, true); + if (MultiUserManager::GetInstance().GetCurrentForegroundUserID() == userId) { + ProfileUtils::ServiceInfoProfileToEntries(serviceInfoProfile, entries); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::ServiceInfoProfileToEntries(serviceInfoProfile, entries); + } + // if (isFirst_.load()) { + // AddToPutTempCache(entries); + // return DP_SUCCESS; + // } + { + std::lock_guard lock(dynamicStoreMutex_); + if (serviceInfoKvAdapter_ == nullptr) { + HILOGE("deviceProfileStore is nullptr!"); + return DP_KV_DB_PTR_NULL; + } + if (serviceInfoKvAdapter_->PutBatch(entries) != DP_SUCCESS) { + HILOGE("PutServiceProfile fail! serviceInfoProfile: %{public}s", serviceInfoProfile.dump().c_str()); + return DP_PUT_KV_DB_FAIL; + } + } + HILOGD("PutServiceProfile success"); + + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::DeleteServiceInfoProfile(const int32_t regServiceId, bool isMultiUser, + int32_t userId) +{ + HILOGD("ServiceInfoProfileNewManage::DeleteServiceInfoProfile"); + int32_t res = 0; + { + std::lock_guard lock(dynamicStoreMutex_); + res = ProfileControlUtils::DeleteServiceInfoProfile(serviceInfoKvAdapter_, regServiceId, isMultiUser, + userId); + } + if (res != DP_SUCCESS) { + HILOGE("DeleteServiceProfile fail, reason: %{public}d!", res); + return res; + } + HILOGD("DeleteServiceProfile success"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::UpdateServiceInfoProfile(const int32_t regServiceId, const ServiceInfoProfileNew &serviceInfoProfile) +{ + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::GetAllServiceInfoProfileList(std::vector& serviceInfoProfileList) +{ + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::GetServiceInfoProfileByServiceId(const int64_t &serviceId, ServiceInfoProfileNew &serviceInfoProfile) +{ + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileNewManage::GetServiceInfoProfileByRegServiceId(const int32_t ®ServiceId, ServiceInfoProfileNew &serviceInfoProfile) +{ + return DP_SUCCESS; +} + +// int32_t ServiceInfoProfileNewManage::GetServiceInfo(ServiceInfoProfileNew& serviceInfo) +// { +// if (serviceInfo.GetServiceIdKey().empty()) { +// HILOGE("Invalid parameter: BusinessKey is empty"); +// return DP_INVALID_PARAM; +// } +// if (!IsValidKey(serviceInfo.GetServiceIdKey())) { +// HILOGE("Invalid BusinessKey: %{public}s", serviceInfo.GetServiceIdKey().c_str()); +// return DP_INVALID_PARAM; +// } + +// std::string key = serviceInfo.GetServiceIdKey(); +// std::string value; +// { +// std::lock_guard lock(dynamicStoreMutex_); +// if (serviceInfoKvAdapter_ == nullptr) { +// HILOGE("serviceInfoKvAdapter_ is null"); +// return DP_KV_DB_PTR_NULL; +// } +// int32_t ret = serviceInfoKvAdapter_->Get(key, value); +// if (ret != DP_SUCCESS) { +// HILOGE("Failed to get business serviceInfo with key: %{public}s", key.c_str()); +// return DP_GET_BUSINESS_EVENT_FAIL; +// } +// serviceInfo.SetServiceIdValue(value); +// } +// HILOGI("GetBusinessEvent success for key: %{public}s", key.c_str()); +// return DP_SUCCESS; +// } + +bool ServiceInfoProfileNewManage::IsValidKey(const std::string& key) +{ + return validKeys_.find(key) != validKeys_.end(); +} + +void ServiceInfoProfileNewManage::AddToPutTempCache(const std::map& values) +{ + if (values.empty()) { + HILOGW("values empty!"); + return; + } + HILOGI("values.size : %{public}zu", values.size()); + { + std::lock_guard lock(putTempCacheMutex_); + for (const auto& [key, value] : values) { + putTempCache_[key] = value; + } + } +} +} // namespace DistributedDeviceProfile +} // namespace OHOS diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index 78625bbd..0307a68e 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -66,6 +66,7 @@ int32_t ProfileCache::UnInit() { std::lock_guard lock(serviceProfileMutex_); serviceProfileMap_.clear(); + serviceInfoProfileMap_.clear(); } { std::lock_guard lock(charProfileMutex_); diff --git a/services/core/src/utils/profile_control_utils.cpp b/services/core/src/utils/profile_control_utils.cpp index e2677544..0e76d598 100644 --- a/services/core/src/utils/profile_control_utils.cpp +++ b/services/core/src/utils/profile_control_utils.cpp @@ -453,6 +453,33 @@ int32_t ProfileControlUtils::DeleteServiceProfile(std::shared_ptr kv return DP_SUCCESS; } +int32_t ProfileControlUtils::DeleteServiceInfoProfile(std::shared_ptr kvStore, const int32_t regServiceId, + bool isMultiUser, int32_t userId) +{ + HILOGD("call!"); + if (kvStore == nullptr) { + HILOGE("kvStore is nullptr!"); + return DP_INVALID_PARAMS; + } + std::string strRegServiceId = std::to_string(regServiceId); + std::vector keys; + if (isMultiUser) { + ProfileUtils::GenerateServiceInfoProfilekeys(strRegServiceId, keys, true, userId); + if (MultiUserManager::GetInstance().GetCurrentForegroundUserID() == userId) { + ProfileUtils::GenerateServiceInfoProfilekeys(strRegServiceId, keys); + } else { + HILOGI("the profile does not belong to the current user."); + } + } else { + ProfileUtils::GenerateServiceInfoProfilekeys(strRegServiceId, keys); + } + if (kvStore->DeleteBatch(keys) != DP_SUCCESS) { + HILOGE("DeleteServiceProfile fail!"); + return DP_DEL_KV_DB_FAIL; + } + return DP_SUCCESS; +} + int32_t ProfileControlUtils::DeleteCharacteristicProfile(std::shared_ptr kvStore, const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, bool isMultiUser, int32_t userId) diff --git a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp index 7bd48b73..e4f2e592 100644 --- a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp @@ -100,6 +100,10 @@ class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubN int32_t UnRegisterBusinessCallback(const std::string& saId, const std::string& businessKey) override; int32_t PutBusinessEvent(const BusinessEvent &event) override; int32_t GetBusinessEvent(BusinessEvent &event) override; + int32_t PutServiceInfoProfileNew(const ServiceInfoProfileNew & serviceInfo) override; + int32_t DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, int32_t userId) override; + int32_t GetServiceInfo(ServiceInfoProfileNew & serviceInfo) override; + void DelayUnloadTask() override; bool IsInited() override; }; @@ -480,6 +484,27 @@ int32_t MockDistributedDeviceProfileStubNew::GetBusinessEvent(BusinessEvent& eve (void)event; return 0; } + +int32_t MockDistributedDeviceProfileStubNew::PutServiceInfoProfileNew(const ServiceInfoProfileNew& serviceInfo) +{ + (void)serviceInfo; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::DelServiceInfoProfileNew(const int32_t regServiceId, bool isMultiUser, + int32_t userId) +{ + (void)regServiceId; + (void)isMultiUser; + (void)userId; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::GetServiceInfo(ServiceInfoProfileNew& serviceInfo) +{ + (void)serviceInfo; + return 0; +} /** * @tc.name: IsInterfaceTokenValid001 * @tc.desc: IsInterfaceTokenValid -- Gitee From ef598e06edb8ef04b138d9dc720970125bb9d572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Mon, 11 Aug 2025 16:58:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=20=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../distributed_device_profile_constants.h | 1 + .../interfaces/service_info_profile_new.h | 125 +++------ .../distributed_device_profile_constants.cpp | 1 + .../interfaces/service_info_profile_new.cpp | 263 +++++------------- common/src/utils/profile_utils.cpp | 65 +++-- .../service_info_manager.cpp | 4 +- 6 files changed, 148 insertions(+), 311 deletions(-) diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 6fef1dd7..d192e01f 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -124,6 +124,7 @@ extern const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME; extern const std::string REG_SERVICE_ID; extern const std::string PUBLISH_STATE; extern const std::string SERVICE_INFO; +extern const std::string SERVICE_IS_MULTI_USER; /* LocalServiceInfo Attribute */ extern const std::string PUT_LOCAL_SERVICE_INFO; extern const std::string UPDATE_LOCAL_SERVICE_INFO; diff --git a/common/include/interfaces/service_info_profile_new.h b/common/include/interfaces/service_info_profile_new.h index 074ed717..aca64530 100644 --- a/common/include/interfaces/service_info_profile_new.h +++ b/common/include/interfaces/service_info_profile_new.h @@ -27,110 +27,65 @@ namespace DistributedDeviceProfile { class ServiceInfoProfileNew : public DpParcel { public: ServiceInfoProfileNew() - : regServiceIdKey_(REG_SERVICE_ID), - regServiceIdValue_(0), - deviceIdKey_(DEVICE_ID), - deviceIdValue_(""), - userIdKey_(RDB_USER_ID), - userIdValue_(0), - tokenIdKey_(TOKENID), - tokenIdValue_(0), - serPubStateKey_(PUBLISH_STATE), - serPubStateValue_(0), - serviceIdKey_(SISERVICE_ID), - serviceIdValue_(0), - serviceTypeKey_(SERVICE_TYPE), - serviceTypeValue_(""), - serviceNameKey_(SERVICE_NAME), - serviceNameValue_(""), - serviceDisplayNameKey_(SERVICE_DISPLAY_NAME), - serviceDisplayNameValue_(""), - isMultiUser_(false) + : regServiceId_(0), + deviceId_(""), + isMultiUser_(false), + userId_(0), + tokenId_(0), + publishState_(0), + serviceId_(0), + serviceType_(""), + serviceName_(""), + serviceDisplayName_("") {}; ~ServiceInfoProfileNew(); - std::string GetRegServiceIdKey() const; - void SetRegServiceIdKey(const std::string ®ServiceIdKey); - int32_t GetRegServiceIdValue() const; - void SetRegServiceIdValue(const int32_t ®ServiceIdValue); + int32_t GetRegServiceId() const; + void SetRegServiceId(const int32_t ®ServiceIdValue); - std::string GetDeviceIdKey() const; - void SetDeviceIdKey(const std::string &deviceIdKey); - std::string GetDeviceIdValue() const; - void SetDeviceIdValue(const std::string &deviceIdValue); + std::string GetDeviceId() const; + void SetDeviceId(const std::string &deviceIdValue); - std::string GetUserIdKey() const; - void SetUserIdKey(const std::string &userIdKey); - int32_t GetUserIdValue() const; - void SetUserIdValue(const int32_t &userIdValue); + bool GetIsMultiUser() const; + void SetIsMultiUser(bool isMultiUser); + + int32_t GetUserId() const; + void SetUserId(const int32_t &userIdValue); - std::string GetTokenIdKey() const; - void SetTokenIdKey(const std::string &tokenIdKey); - int64_t GetTokenIdValue() const; - void SetTokenIdValue(const int64_t &tokenIdValue); + int64_t GetTokenId() const; + void SetTokenId(const int64_t &tokenIdValue); - std::string GetSerPubStateKey() const; - void SetSerPubStateKey(const std::string &serPubStateKey); - int8_t GetSerPubStateValue() const; - void SetSerPubStateValue(const int8_t &SerPubStateValue); + int8_t GetSerPubState() const; + void SetSerPubState(const int8_t &SerPubStateValue); - std::string GetServiceIdKey() const; - void SetServiceIdKey(const std::string &serviceIdKey); - int64_t GetServiceIdValue() const; - void SetServiceIdValue(const int64_t serviceIdValue); + int64_t GetServiceId() const; + void SetServiceId(const int64_t serviceIdValue); - std::string GetServiceTypeKey() const; - void SetServiceTypeKey(const std::string &serviceTypeKey); - std::string GetServiceTypeValue() const; - void SetServiceTypeValue(const std::string &serviceTypeValue); + std::string GetServiceType() const; + void SetServiceType(const std::string &serviceTypeValue); - std::string GetServiceNameKey() const; - void SetServiceNameKey(const std::string &serviceNameKey); - std::string GetServiceNameValue() const; - void SetServiceNameValue(const std::string &serviceNameValue); + std::string GetServiceName() const; + void SetServiceName(const std::string &serviceNameValue); - std::string GetServiceDisplayNameKey() const; - void SetServiceDisplayNameKey(const std::string &serviceDisplayNameKey); - std::string GetServiceDisplayNameValue() const; - void SetServiceDisplayNameValue(const std::string &serviceDisplayNameValue); + std::string GetServiceDisplayName() const; + void SetServiceDisplayName(const std::string &serviceDisplayNameValue); bool Marshalling(MessageParcel& parcel) const override; bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; - bool IsMultiUser() const; - void SetIsMultiUser(bool isMultiUser); - private: - std::string regServiceIdKey_; - int32_t regServiceIdValue_; - - std::string deviceIdKey_; - std::string deviceIdValue_; - - std::string userIdKey_; - int32_t userIdValue_; - - std::string tokenIdKey_; - int64_t tokenIdValue_; - - std::string serPubStateKey_ ; - int8_t serPubStateValue_; - - std::string serviceIdKey_; - int64_t serviceIdValue_ ; - - std::string serviceTypeKey_ ; - std::string serviceTypeValue_ ; - - std::string serviceNameKey_ ; - std::string serviceNameValue_; - - std::string serviceDisplayNameKey_; - std::string serviceDisplayNameValue_; - + int32_t regServiceId_; + std::string deviceId_; bool isMultiUser_; + int32_t userId_; + int64_t tokenId_; + int8_t publishState_; + int64_t serviceId_; + std::string serviceType_; + std::string serviceName_; + std::string serviceDisplayName_; }; } // 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 f0f2a6f7..c663739c 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -172,6 +172,7 @@ const std::string GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME = "GetServiceInfo const std::string REG_SERVICE_ID = "regServiceId"; const std::string PUBLISH_STATE = "publishState"; const std::string SERVICE_INFO = "serviceInfo"; +const std::string SERVICE_IS_MULTI_USER = "isMultiUser"; /* LocalServiceInfo Attribute */ const std::string PUT_LOCAL_SERVICE_INFO = "PutLocalServiceInfo"; const std::string UPDATE_LOCAL_SERVICE_INFO = "UpdateLocalServiceInfo"; diff --git a/common/src/interfaces/service_info_profile_new.cpp b/common/src/interfaces/service_info_profile_new.cpp index 508e1f8f..6af1b227 100644 --- a/common/src/interfaces/service_info_profile_new.cpp +++ b/common/src/interfaces/service_info_profile_new.cpp @@ -29,251 +29,135 @@ ServiceInfoProfileNew::~ServiceInfoProfileNew() { } -std::string ServiceInfoProfileNew::GetServiceIdKey() const +int64_t ServiceInfoProfileNew::GetServiceId() const { - return serviceIdKey_; + return serviceId_; } -void ServiceInfoProfileNew::SetServiceIdKey(const std::string& serviceIdKey) +void ServiceInfoProfileNew::SetServiceId(const int64_t serviceId) { - serviceIdKey_ = serviceIdKey; + serviceId_ = serviceId; } -int64_t ServiceInfoProfileNew::GetServiceIdValue() const +std::string ServiceInfoProfileNew::GetServiceType() const { - return serviceIdValue_; + return serviceType_; } -void ServiceInfoProfileNew::SetServiceIdValue(const int64_t serviceIdValue) +void ServiceInfoProfileNew::SetServiceType(const std::string& serviceType) { - serviceIdValue_ = serviceIdValue; + serviceType_ = serviceType; } -std::string ServiceInfoProfileNew::ServiceInfoProfileNew::GetServiceTypeKey() const +std::string ServiceInfoProfileNew::GetServiceName() const { - return serviceTypeKey_; + return serviceName_; } -void ServiceInfoProfileNew::SetServiceTypeKey(const std::string& serviceTypeKey) +void ServiceInfoProfileNew::SetServiceName(const std::string &serviceName) { - serviceTypeKey_ = serviceTypeKey; + serviceName_ = serviceName; } -std::string ServiceInfoProfileNew::GetServiceTypeValue() const +std::string ServiceInfoProfileNew::GetServiceDisplayName() const { - return serviceTypeValue_; + return serviceDisplayName_; } -void ServiceInfoProfileNew::SetServiceTypeValue(const std::string& serviceTypeValue) +void ServiceInfoProfileNew::SetServiceDisplayName(const std::string &serviceDisplayName) { - serviceTypeValue_ = serviceTypeValue; + serviceDisplayName_ = serviceDisplayName; } -std::string ServiceInfoProfileNew::GetServiceNameKey() const +int32_t ServiceInfoProfileNew::GetRegServiceId() const { - return serviceNameKey_; + return regServiceId_; } -void ServiceInfoProfileNew::SetServiceNameKey(const std::string &serviceNameKey) +void ServiceInfoProfileNew::SetRegServiceId(const int32_t ®ServiceId) { - serviceNameKey_ = serviceNameKey; + regServiceId_ = regServiceId; } -std::string ServiceInfoProfileNew::GetServiceNameValue() const +int8_t ServiceInfoProfileNew::GetSerPubState() const { - return serviceNameValue_; + return publishState_; } -void ServiceInfoProfileNew::SetServiceNameValue(const std::string &serviceNameValue) +void ServiceInfoProfileNew::SetSerPubState(const int8_t &serPubState) { - serviceNameValue_ = serviceNameValue; + publishState_ = serPubState; } -std::string ServiceInfoProfileNew::GetServiceDisplayNameKey() const +std::string ServiceInfoProfileNew::GetDeviceId() const { - return serviceDisplayNameKey_; + return deviceId_; } - -void ServiceInfoProfileNew::SetServiceDisplayNameKey(const std::string &serviceDisplayNameKey) -{ - serviceDisplayNameKey_ = serviceDisplayNameKey; -} - -std::string ServiceInfoProfileNew::GetServiceDisplayNameValue() const -{ - return serviceDisplayNameValue_; -} - -void ServiceInfoProfileNew::SetServiceDisplayNameValue(const std::string &serviceDisplayNameValue) -{ - serviceDisplayNameValue_ = serviceDisplayNameValue; -} - -std::string ServiceInfoProfileNew::GetRegServiceIdKey() const +void ServiceInfoProfileNew::SetDeviceId(const std::string &deviceId) { - return regServiceIdKey_; + deviceId_ = deviceId; } -void ServiceInfoProfileNew::SetRegServiceIdKey(const std::string ®SerDBIdKey) +int32_t ServiceInfoProfileNew::GetUserId() const { - regServiceIdKey_ = regSerDBIdKey; + return userId_; } - -int32_t ServiceInfoProfileNew::GetRegServiceIdValue() const -{ - return regServiceIdValue_; -} - -void ServiceInfoProfileNew::SetRegServiceIdValue(const int32_t ®ServiceIdValue) +void ServiceInfoProfileNew::SetUserId(const int32_t &userId) { - regServiceIdValue_ = regServiceIdValue; + userId_ = userId; } -std::string ServiceInfoProfileNew::GetSerPubStateKey() const +int64_t ServiceInfoProfileNew::GetTokenId() const { - return serPubStateKey_; + return tokenId_; } - -void ServiceInfoProfileNew::SetSerPubStateKey(const std::string &serPubStateKey) -{ - serPubStateKey_ = serPubStateKey; -} - -int8_t ServiceInfoProfileNew::GetSerPubStateValue() const +void ServiceInfoProfileNew::SetTokenId(const int64_t &tokenId) { - return serPubStateValue_; + tokenId_ = tokenId; } -void ServiceInfoProfileNew::SetSerPubStateValue(const int8_t &serPubStateValue) -{ - serPubStateValue_ = serPubStateValue; -} - -std::string ServiceInfoProfileNew::GetDeviceIdKey() const -{ - return deviceIdKey_; -} -void ServiceInfoProfileNew::SetDeviceIdKey(const std::string &deviceIdKey) -{ - deviceIdKey_ = deviceIdKey; -} -std::string ServiceInfoProfileNew::GetDeviceIdValue() const -{ - return deviceIdValue_; -} -void ServiceInfoProfileNew::SetDeviceIdValue(const std::string &deviceIdValue) -{ - deviceIdValue_ = deviceIdValue; -} - -std::string ServiceInfoProfileNew::GetUserIdKey() const -{ - return userIdKey_; -} -void ServiceInfoProfileNew::SetUserIdKey(const std::string &userIdKey) -{ - userIdKey_ = userIdKey; -} -int32_t ServiceInfoProfileNew::GetUserIdValue() const -{ - return userIdValue_; -} -void ServiceInfoProfileNew::SetUserIdValue(const int32_t &userIdValue) +bool ServiceInfoProfileNew::GetIsMultiUser() const { - userIdValue_ = userIdValue; + return isMultiUser_; } -std::string ServiceInfoProfileNew::GetTokenIdKey() const -{ - return tokenIdKey_; -} -void ServiceInfoProfileNew::SetTokenIdKey(const std::string &tokenIdKey) -{ - tokenIdKey_ = tokenIdKey; -} -int64_t ServiceInfoProfileNew::GetTokenIdValue() const -{ - return tokenIdValue_; -} -void ServiceInfoProfileNew::SetTokenIdValue(const int64_t &tokenIdValue) +void ServiceInfoProfileNew::SetIsMultiUser(bool isMultiUser) { - tokenIdValue_ = tokenIdValue; + isMultiUser_ = isMultiUser; } bool ServiceInfoProfileNew::Marshalling(MessageParcel& parcel) const { - WRITE_HELPER(parcel, String, serviceIdKey_); - WRITE_HELPER(parcel, Int64, serviceIdValue_); - - WRITE_HELPER(parcel, String, serviceTypeKey_); - WRITE_HELPER(parcel, String, serviceTypeValue_); - - WRITE_HELPER(parcel, String, serviceNameKey_); - WRITE_HELPER(parcel, String, serviceNameValue_); - - WRITE_HELPER(parcel, String, serviceDisplayNameKey_); - WRITE_HELPER(parcel, String, serviceDisplayNameValue_); - - WRITE_HELPER(parcel, String, regServiceIdKey_); - WRITE_HELPER(parcel, Int32, regServiceIdValue_); - - WRITE_HELPER(parcel, String, serPubStateKey_); - WRITE_HELPER(parcel, Int8, serPubStateValue_); - - WRITE_HELPER(parcel, String, deviceIdKey_); - WRITE_HELPER(parcel, String, deviceIdValue_); - - WRITE_HELPER(parcel, String, userIdKey_); - WRITE_HELPER(parcel, Int32, userIdValue_); - - WRITE_HELPER(parcel, String, tokenIdKey_); - WRITE_HELPER(parcel, Int64, tokenIdValue_); + WRITE_HELPER(parcel, Int32, regServiceId_); + WRITE_HELPER(parcel, String, deviceId_); + WRITE_HELPER(parcel, Bool, isMultiUser_); + WRITE_HELPER(parcel, Int32, userId_); + WRITE_HELPER(parcel, Int64, tokenId_); + WRITE_HELPER(parcel, Int8, publishState_); + WRITE_HELPER(parcel, Int64, serviceId_); + WRITE_HELPER(parcel, String, serviceType_); + WRITE_HELPER(parcel, String, serviceName_); + WRITE_HELPER(parcel, String, serviceDisplayName_); return true; } bool ServiceInfoProfileNew::UnMarshalling(MessageParcel& parcel) { - READ_HELPER_RET(parcel, String, serviceIdKey_, false); - READ_HELPER_RET(parcel, Int64, serviceIdValue_, false); - - READ_HELPER_RET(parcel, String, serviceTypeKey_, false); - READ_HELPER_RET(parcel, String, serviceTypeValue_, false); - - READ_HELPER_RET(parcel, String, serviceNameKey_, false); - READ_HELPER_RET(parcel, String, serviceNameValue_, false); - - READ_HELPER_RET(parcel, String, serviceDisplayNameKey_, false); - READ_HELPER_RET(parcel, String, serviceDisplayNameValue_, false); - - READ_HELPER_RET(parcel, String, regServiceIdKey_, false); - READ_HELPER_RET(parcel, Int32, regServiceIdValue_, false); - - READ_HELPER_RET(parcel, String, serPubStateKey_, false); - READ_HELPER_RET(parcel, Int8, serPubStateValue_, false); - - READ_HELPER_RET(parcel, String, deviceIdKey_, false); - READ_HELPER_RET(parcel, String, deviceIdValue_, false); - - READ_HELPER_RET(parcel, String, userIdKey_, false); - READ_HELPER_RET(parcel, Int32, userIdValue_, false); - - READ_HELPER_RET(parcel, String, tokenIdKey_, false); - READ_HELPER_RET(parcel, Int64, tokenIdValue_, false); + READ_HELPER_RET(parcel, Int32, regServiceId_, false); + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, Int64, tokenId_, false); + READ_HELPER_RET(parcel, Int8, publishState_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceDisplayName_, false); return true; } -bool ServiceInfoProfileNew::IsMultiUser() const -{ - return isMultiUser_; -} - -void ServiceInfoProfileNew::SetIsMultiUser(bool isMultiUser) -{ - isMultiUser_ = isMultiUser; -} - std::string ServiceInfoProfileNew::dump() const { cJSON* json = cJSON_CreateObject(); @@ -281,32 +165,23 @@ std::string ServiceInfoProfileNew::dump() const cJSON_Delete(json); return EMPTY_STRING; } - cJSON_AddStringToObject(json, DEVICE_ID_KEY.c_str(), deviceIdKey_.c_str()); - cJSON_AddStringToObject(json, DEVICE_ID_VALUE.c_str(), deviceIdValue_.c_str()); + cJSON_AddStringToObject(json, DEVICE_ID.c_str(), deviceId_.c_str()); - cJSON_AddStringToObject(json, SER_USER_ID_KEY.c_str(), userIdKey_.c_str()); - cJSON_AddStringToObject(json, SER_USER_ID_VALUE.c_str(), std::to_string(userIdValue_).c_str()); + cJSON_AddStringToObject(json, SERVICE_IS_MULTI_USER.c_str(), std::to_string(isMultiUser_).c_str()); - cJSON_AddStringToObject(json, SER_TOKEN_ID_KEY.c_str(), tokenIdKey_.c_str()); - cJSON_AddStringToObject(json, SER_TOKEN_ID_VALUE.c_str(), std::to_string(tokenIdValue_).c_str()); + cJSON_AddStringToObject(json, USERID.c_str(), std::to_string(userId_).c_str()); - cJSON_AddStringToObject(json, SER_PUB_STATE_KEY.c_str(), serPubStateKey_.c_str()); - cJSON_AddStringToObject(json, SER_PUB_STATE_VALUE.c_str(), std::to_string(serPubStateValue_).c_str()); + cJSON_AddStringToObject(json, TOKENID.c_str(), std::to_string(tokenId_).c_str()); - cJSON_AddStringToObject(json, SERVICE_ID_KEY.c_str(), serviceIdKey_.c_str()); - cJSON_AddStringToObject(json, SERVICE_ID_VALUE.c_str(), std::to_string(serviceIdValue_).c_str()); + cJSON_AddStringToObject(json, PUBLISH_STATE.c_str(), std::to_string(publishState_).c_str()); - cJSON_AddStringToObject(json, SERVICE_TYPE_KEY.c_str(), serviceTypeKey_.c_str()); - cJSON_AddStringToObject(json, SERVICE_TYPE_VALUE.c_str(), serviceTypeValue_.c_str()); + cJSON_AddStringToObject(json, SISERVICE_ID.c_str(), std::to_string(serviceId_).c_str()); - cJSON_AddStringToObject(json, SERVICE_NAME_KEY.c_str(), serviceNameKey_.c_str()); - cJSON_AddStringToObject(json, SERVICE_NAME_VALUE.c_str(), serviceNameValue_.c_str()); + cJSON_AddStringToObject(json, SERVICE_TYPE.c_str(), serviceType_.c_str()); - cJSON_AddStringToObject(json, SERVICE_DISPLAY_NAME_KEY.c_str(), serviceDisplayNameKey_.c_str()); - cJSON_AddStringToObject(json, SERVICE_DISPLAY_NAME_VALUE.c_str(), serviceDisplayNameValue_.c_str()); + cJSON_AddStringToObject(json, SERVICE_NAME.c_str(), serviceName_.c_str()); - //cJSON_AddStringToObject(json, REG_SERVICE_ID_KEY.c_str(), regSerDBIdKey_.c_str()); - //cJSON_AddStringToObject(json, REG_SERVICE_ID_VALUE.c_str(), regSerDBIdValue_.c_str()); + cJSON_AddStringToObject(json, SERVICE_DISPLAY_NAME.c_str(), serviceDisplayName_.c_str()); char* jsonChars = cJSON_PrintUnformatted(json); if (jsonChars == NULL) { diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index ea414ac9..e569f9c5 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -296,8 +296,8 @@ bool ProfileUtils::IsSvrProfileValid(const ServiceProfile& svrProfile) bool ProfileUtils::IsSerInfoProfileValid(const ServiceInfoProfileNew& serInfoProfile) { - return IsKeyValid(serInfoProfile.GetDeviceIdKey()) && IsLocalUdid(serInfoProfile.GetDeviceIdValue()) && - IsKeyValid(serInfoProfile.GetServiceNameValue()); + return IsKeyValid(serInfoProfile.GetDeviceId()) && IsLocalUdid(serInfoProfile.GetDeviceId()) && + IsKeyValid(serInfoProfile.GetServiceName()); } bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile) @@ -465,39 +465,44 @@ int32_t ProfileUtils::ServiceInfoProfileToEntries(const ServiceInfoProfileNew& p std::string>& values, bool isMultiUser) { HILOGI("ProfileUtils::ServiceInfoProfileToEntries"); - std::string regServiceId = CheckAndAddOhSuffix(profile.GetRegServiceIdKey(), false); - std::string deviceIdKey = CheckAndAddOhSuffix(profile.GetDeviceIdKey(), false); - std::string userIdKey = CheckAndAddOhSuffix(profile.GetUserIdKey(), false); - std::string tokenIdKey = CheckAndAddOhSuffix(profile.GetTokenIdKey(), false); - std::string serPubStateKey = CheckAndAddOhSuffix(profile.GetSerPubStateKey(), false); - std::string serviceIdKey = CheckAndAddOhSuffix(profile.GetServiceIdKey(), false); - std::string serviceTypeKey = CheckAndAddOhSuffix(profile.GetServiceTypeKey(), false); - std::string serviceNameKey = CheckAndAddOhSuffix(profile.GetServiceNameKey(), false); - std::string serviceDisplayNameKey = CheckAndAddOhSuffix(profile.GetServiceDisplayNameKey(), false); - - int32_t userIdVlue = profile.GetUserIdValue(); + + std::string regServiceId = CheckAndAddOhSuffix(REG_SERVICE_ID, false); + + std::string deviceIdKey = CheckAndAddOhSuffix(DEVICE_ID, false); + std::string isMultiUserKey = CheckAndAddOhSuffix(SERVICE_IS_MULTI_USER, false); + std::string userIdKey = CheckAndAddOhSuffix(USERID, false); + std::string tokenIdKey = CheckAndAddOhSuffix(TOKENID, false); + std::string publishStateKey = CheckAndAddOhSuffix(PUBLISH_STATE, false); + std::string serviceIdKey = CheckAndAddOhSuffix(SISERVICE_ID, false); + std::string serviceTypeKey = CheckAndAddOhSuffix(SERVICE_TYPE, false); + std::string serviceNameKey = CheckAndAddOhSuffix(SERVICE_NAME, false); + std::string serviceDisplayNameKey = CheckAndAddOhSuffix(SERVICE_DISPLAY_NAME, false); + + int32_t userIdVlue = profile.GetUserId(); if (isMultiUser) { - values[GenerateServiceDBKey(regServiceId, deviceIdKey, userIdVlue)] = profile.GetDeviceIdValue(); - values[GenerateServiceDBKey(regServiceId, userIdKey, userIdVlue)] = std::to_string(profile.GetUserIdValue()); - values[GenerateServiceDBKey(regServiceId, tokenIdKey, userIdVlue)] = std::to_string(profile.GetTokenIdValue()); - values[GenerateServiceDBKey(regServiceId, serPubStateKey, userIdVlue)] = - std::to_string(profile.GetSerPubStateValue()); + values[GenerateServiceDBKey(regServiceId, deviceIdKey, userIdVlue)] = profile.GetDeviceId(); + values[GenerateServiceDBKey(regServiceId, isMultiUserKey, userIdVlue)] = profile.GetIsMultiUser(); + values[GenerateServiceDBKey(regServiceId, userIdKey, userIdVlue)] = std::to_string(profile.GetUserId()); + values[GenerateServiceDBKey(regServiceId, tokenIdKey, userIdVlue)] = std::to_string(profile.GetTokenId()); + values[GenerateServiceDBKey(regServiceId, publishStateKey, userIdVlue)] = + std::to_string(profile.GetSerPubState()); values[GenerateServiceDBKey(regServiceId, serviceIdKey, userIdVlue)] = - std::to_string(profile.GetServiceIdValue()); - values[GenerateServiceDBKey(regServiceId, serviceTypeKey, userIdVlue)] = profile.GetServiceTypeValue(); - values[GenerateServiceDBKey(regServiceId, serviceNameKey, userIdVlue)] = profile.GetServiceNameValue(); + std::to_string(profile.GetServiceId()); + values[GenerateServiceDBKey(regServiceId, serviceTypeKey, userIdVlue)] = profile.GetServiceType(); + values[GenerateServiceDBKey(regServiceId, serviceNameKey, userIdVlue)] = profile.GetServiceName(); values[GenerateServiceDBKey(regServiceId, serviceDisplayNameKey, userIdVlue)] = - profile.GetServiceDisplayNameValue(); + profile.GetServiceDisplayName(); } else { - values[GenerateServiceDBKey(regServiceId, deviceIdKey)] = profile.GetDeviceIdValue(); - values[GenerateServiceDBKey(regServiceId, userIdKey)] = std::to_string(profile.GetUserIdValue()); - values[GenerateServiceDBKey(regServiceId, tokenIdKey)] = std::to_string(profile.GetTokenIdValue()); - values[GenerateServiceDBKey(regServiceId, serPubStateKey)] = std::to_string(profile.GetSerPubStateValue()); - values[GenerateServiceDBKey(regServiceId, serviceIdKey)] = std::to_string(profile.GetServiceIdValue()); - values[GenerateServiceDBKey(regServiceId, serviceTypeKey)] = profile.GetServiceTypeValue(); - values[GenerateServiceDBKey(regServiceId, serviceNameKey)] = profile.GetServiceNameValue(); - values[GenerateServiceDBKey(regServiceId, serviceDisplayNameKey)] = profile.GetServiceDisplayNameValue(); + values[GenerateServiceDBKey(regServiceId, deviceIdKey)] = profile.GetDeviceId(); + values[GenerateServiceDBKey(regServiceId, isMultiUserKey)] = profile.GetIsMultiUser(); + values[GenerateServiceDBKey(regServiceId, userIdKey)] = std::to_string(profile.GetUserId()); + values[GenerateServiceDBKey(regServiceId, tokenIdKey)] = std::to_string(profile.GetTokenId()); + values[GenerateServiceDBKey(regServiceId, publishStateKey)] = std::to_string(profile.GetSerPubState()); + values[GenerateServiceDBKey(regServiceId, serviceIdKey)] = std::to_string(profile.GetServiceId()); + values[GenerateServiceDBKey(regServiceId, serviceTypeKey)] = profile.GetServiceType(); + values[GenerateServiceDBKey(regServiceId, serviceNameKey)] = profile.GetServiceName(); + values[GenerateServiceDBKey(regServiceId, serviceDisplayNameKey)] = profile.GetServiceDisplayName(); } return DP_SUCCESS; diff --git a/services/core/src/serviceinfo_manager/service_info_manager.cpp b/services/core/src/serviceinfo_manager/service_info_manager.cpp index 8e795119..2e4dab0a 100644 --- a/services/core/src/serviceinfo_manager/service_info_manager.cpp +++ b/services/core/src/serviceinfo_manager/service_info_manager.cpp @@ -81,14 +81,14 @@ int32_t ServiceInfoProfileNewManage::ReInit() int32_t ServiceInfoProfileNewManage::PutServiceInfoProfile(const ServiceInfoProfileNew& serviceInfoProfile) { HILOGI("ServiceInfoProfileNewManage::PutServiceInfoProfile"); - int32_t userId = serviceInfoProfile.GetUserIdValue(); + int32_t userId = serviceInfoProfile.GetUserId(); HILOGI("serviceInfoProfile: %{public}s", serviceInfoProfile.dump().c_str()); if (!ProfileUtils::IsSerInfoProfileValid(serviceInfoProfile)) { HILOGE("the profile is invalid!"); return DP_INVALID_PARAMS; } std::map entries; - if (serviceInfoProfile.IsMultiUser()) { + if (serviceInfoProfile.GetIsMultiUser()) { ProfileUtils::ServiceInfoProfileToEntries(serviceInfoProfile, entries, true); if (MultiUserManager::GetInstance().GetCurrentForegroundUserID() == userId) { ProfileUtils::ServiceInfoProfileToEntries(serviceInfoProfile, entries); -- Gitee