From b646afc4a8c1508c7c13aacc05159223a6d7d787 Mon Sep 17 00:00:00 2001 From: torrizo Date: Mon, 17 Feb 2025 10:55:03 +0000 Subject: [PATCH 1/2] srviceI111 Signed-off-by: torrizo --- .../include/interfaces/service_info_profile.h | 129 ++++++++ .../interfaces/service_info_unique_key.h | 68 ++++ .../src/interfaces/service_info_profile.cpp | 293 ++++++++++++++++++ .../interfaces/service_info_unique_key.cpp | 110 +++++++ 4 files changed, 600 insertions(+) create mode 100644 common/include/interfaces/service_info_profile.h create mode 100644 common/include/interfaces/service_info_unique_key.h create mode 100644 common/src/interfaces/service_info_profile.cpp create mode 100644 common/src/interfaces/service_info_unique_key.cpp diff --git a/common/include/interfaces/service_info_profile.h b/common/include/interfaces/service_info_profile.h new file mode 100644 index 00000000..f348a92c --- /dev/null +++ b/common/include/interfaces/service_info_profile.h @@ -0,0 +1,129 @@ +/* + * 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_PROFILE_H +#define OHOS_DP_SERVICE_INFO_PROFILE_H + +#include +#include + +#include "distributed_device_profile_constants.h" +#include "dp_parcel.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoProfile : public DpParcel { +public: + ServiceInfoProfile(const std::string& deviceId, const int32_t userId, const std::string& networkId, + const std::string& tokenId, const int64_t serviceId, const std::string& serviceType, + const std::string& serviceName, const std::string& serviceDisplayName, const std::string& customData, + const int32_t customDataLen, const std::string& bundleName, const std::string& moduleName, + const std::string abilityName, const int32_t authBoxType, const int32_t authType, const int32_t pinExchangeType, + const std::string& pinCode, const std::string& description, const std::string& serviceDicoveryScope, + const std::string& extraInfo) + : deviceId_(deviceId), + userId_(userId), + networkId_(networkId), + tokenId_(tokenId), + serviceId_(serviceId), + serviceType_(serviceType), + serviceName_(serviceName), + serviceDisplayName_(serviceDisplayName), + customData_(customData), + customDataLen_(customDataLen), + bundleName_(bundleName), + moduleName_(moduleName), + abilityName_(abilityName), + authBoxType_(authBoxType), + authType_(authType), + pinExchangeType_(pinExchangeType), + pinCode_(pinCode), + description_(description), + serviceDicoveryScope_(serviceDicoveryScope), + extraInfo_(extraInfo) + {} + ServiceInfoProfile(); + ~ServiceInfoProfile(); + + std::string GetDeviceId() const; + void SetDeviceId(const std::string& deviceId); + int32_t GetUserId() const; + void SetUserId(const int32_t userId); + std::string GetNetworkId() const; + void SetNetworkId(const std::string& networkId); + std::string GetTokenId() const; + void SetTokenId(const std::string& tokenId); + int64_t GetServiceId() const; + void SetServiceId(const int64_t serviceId); + std::string GetServiceType() const; + void SetServiceType(const std::string& serviceType); + std::string GetServiceName() const; + void SetServiceName(const std::string& serviceName); + std::string GetServiceDisplayName() const; + void SetServiceDisplayName(const std::string& serviceDisplayName); + std::string GetCustomData() const; + void SetCustomData(const std::string& customData); + int32_t GetCustomDataLen() const; + void SetCustomDataLen(const int32_t customDataLen); + std::string GetBundleName() const; + void SetBundleName(const std::string& bundleName); + std::string GetModuleName() const; + void SetModuleName(const std::string& moduleName); + std::string GetAbilityName() const; + void SetAbilityName(const std::string& abilityName); + int32_t GetAuthBoxType() const; + void SetAuthBoxType(const int32_t authBoxType); + int32_t GetAuthType() const; + void SetAuthType(const int32_t authType); + int32_t GetPinExchangeType() const; + void SetPinExchangeType(const int32_t pinExchangeType); + std::string GetPinCode() const; + void SetPinCode(const std::string& pinCode); + std::string GetDescription() const; + void SetDescription(const std::string& description); + std::string GetServiceDicoveryScope() const; + void SetServiceDicoveryScope(const std::string& serviceDicoveryScope); + std::string GetExtraInfo() const; + void SetExtraInfo(const std::string& extraInfo); + + bool Marshalling(MessageParcel& parcel) const override; + bool UnMarshalling(MessageParcel& parcel) override; + std::string dump() const override; + +private: + std::string deviceId_ = ""; + int32_t userId_ = DEFAULT_USER_ID; + std::string networkId_ = ""; + std::string tokenId_ = ""; + int64_t serviceId_ = DEFAULT_SERVICE_ID; + std::string serviceType_ = ""; + std::string serviceName_ = ""; + std::string serviceDisplayName_ = ""; + std::string customData_ = ""; + int32_t customDataLen_ = 0; + std::string bundleName_ = ""; + std::string moduleName_ = ""; + std::string abilityName_ = ""; + int32_t authBoxType_ = 0; + int32_t authType_ = 0; + int32_t pinExchangeType_ = 0; + std::string pinCode_ = ""; + std::string description_ = ""; + std::string serviceDicoveryScope_ = ""; + std::string extraInfo_ = ""; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS +#endif //OHOS_DP_SERVICE_INFO_PROFILE_H diff --git a/common/include/interfaces/service_info_unique_key.h b/common/include/interfaces/service_info_unique_key.h new file mode 100644 index 00000000..4fb1e219 --- /dev/null +++ b/common/include/interfaces/service_info_unique_key.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DP_SERVICE_INFO_UNIQUE_KEY_H +#define OHOS_DP_SERVICE_INFO_UNIQUE_KEY_H + +#include +#include + +#include "distributed_device_profile_constants.h" +#include "dp_parcel.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoUniqueKey : public DpParcel { +public: + ServiceInfoUniqueKey(const std::string& deviceId, const int32_t userId, const std::string& tokenId, + const int64_t serviceId) + : deviceId_(deviceId), + userId_(userId), + tokenId_(tokenId), + serviceId_(serviceId) + {} + ServiceInfoUniqueKey(const std::string& deviceId, const int32_t userId, const std::string& bundleName) + : deviceId_(deviceId), + userId_(userId), + bundleName_(bundleName) + {} + ServiceInfoUniqueKey(); + ~ServiceInfoUniqueKey(); + + std::string GetDeviceId() const; + void SetDeviceId(const std::string& deviceId); + int32_t GetUserId() const; + void SetUserId(const int32_t userId); + std::string GetTokenId() const; + void SetTokenId(const std::string& tokenId); + int64_t GetServiceId() const; + void SetServiceId(const int64_t serviceId); + std::string GetBundleName() const; + void SetBundleName(const std::string& bundleName); + + bool Marshalling(MessageParcel& parcel) const override; + bool UnMarshalling(MessageParcel& parcel) override; + std::string dump() const override; + +private: + std::string deviceId_ = ""; + int32_t userId_ = DEFAULT_USER_ID; + std::string tokenId_ = ""; + int64_t serviceId_ = DEFAULT_SERVICE_ID; + std::string bundleName_ = ""; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS +#endif //OHOS_DP_SERVICE_INFO_UNIQUE_KEY_H diff --git a/common/src/interfaces/service_info_profile.cpp b/common/src/interfaces/service_info_profile.cpp new file mode 100644 index 00000000..9e126f86 --- /dev/null +++ b/common/src/interfaces/service_info_profile.cpp @@ -0,0 +1,293 @@ +/* + * 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.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 = "ServiceInfoProfile"; +} + +ServiceInfoProfile::ServiceInfoProfile() +{ +} + +ServiceInfoProfile::~ServiceInfoProfile() +{ +} + +std::string ServiceInfoProfile::GetDeviceId() const +{ + return deviceId_; +} + +void ServiceInfoProfile::SetDeviceId(const std::string& deviceId) +{ + deviceId_ = deviceId; +} + +int32_t ServiceInfoProfile::GetUserId() const +{ + return userId_; +} + +void ServiceInfoProfile::SetUserId(const int32_t userId) +{ + userId_ = userId; +} + +std::string ServiceInfoProfile::GetNetworkId() const +{ + return networkId_; +} + +void ServiceInfoProfile::SetNetworkId(const std::string& networkId) +{ + networkId_ = networkId; +} + +std::string ServiceInfoProfile::GetTokenId() const +{ + return tokenId_; +} + +void ServiceInfoProfile::SetTokenId(const std::string& tokenId) +{ + tokenId_ = tokenId; +} + +int64_t ServiceInfoProfile::GetServiceId() const +{ + return serviceId_; +} + +void ServiceInfoProfile::SetServiceId(const int64_t serviceId) +{ + serviceId_ = serviceId; +} + +std::string ServiceInfoProfile::GetServiceType() const +{ + return serviceType_; +} + +void ServiceInfoProfile::SetServiceType(const std::string& serviceType) +{ + serviceType_ = serviceType; +} + +std::string ServiceInfoProfile::GetServiceName() const +{ + return serviceName_; +} + +void ServiceInfoProfile::SetServiceName(const std::string& serviceName) +{ + serviceName_ = serviceName; +} + +std::string ServiceInfoProfile::GetServiceDisplayName() const +{ + return serviceDisplayName_; +} + +void ServiceInfoProfile::SetServiceDisplayName(const std::string& serviceDisplayName) +{ + serviceDisplayName_ = serviceDisplayName; +} + +std::string ServiceInfoProfile::GetCustomData() const +{ + return customData_; +} + +void ServiceInfoProfile::SetCustomData(const std::string& customData) +{ + customData_ = customData; +} + +int32_t ServiceInfoProfile::GetCustomDataLen() const +{ + return customDataLen_; +} + +void ServiceInfoProfile::SetCustomDataLen(const int32_t customDataLen) +{ + customDataLen_ = customDataLen; +} + +std::string ServiceInfoProfile::GetBundleName() const +{ + return bundleName_; +} + +void ServiceInfoProfile::SetBundleName(const std::string& bundleName) +{ + bundleName_ = bundleName; +} + +std::string ServiceInfoProfile::GetModuleName() const +{ + return moduleName_; +} + +void ServiceInfoProfile::SetModuleName(const std::string& moduleName) +{ + moduleName_ = moduleName; +} + +std::string ServiceInfoProfile::GetAbilityName() const +{ + return abilityName_; +} + +void ServiceInfoProfile::SetAbilityName(const std::string& abilityName) +{ + abilityName_ = abilityName; +} + +int32_t ServiceInfoProfile::GetAuthBoxType() const +{ + return authBoxType_; +} + +void ServiceInfoProfile::SetAuthBoxType(const int32_t authBoxType) +{ + authBoxType_ = authBoxType; +} + +int32_t ServiceInfoProfile::GetAuthType() const +{ + return authType_; +} + +void ServiceInfoProfile::SetAuthType(const int32_t authType) +{ + authType_ = authType; +} + +int32_t ServiceInfoProfile::GetPinExchangeType() const +{ + return pinExchangeType_; +} + +void ServiceInfoProfile::SetPinExchangeType(const int32_t pinExchangeType) +{ + pinExchangeType_ = pinExchangeType; +} + +std::string ServiceInfoProfile::GetPinCode() const +{ + return pinCode_; +} + +void ServiceInfoProfile::SetPinCode(const std::string& pinCode) +{ + pinCode_ = pinCode; +} + +std::string ServiceInfoProfile::GetDescription() const +{ + return description_; +} + +void ServiceInfoProfile::SetDescription(const std::string& description) +{ + description_ = description; +} + +std::string ServiceInfoProfile::GetServiceDicoveryScope() const +{ + return serviceDicoveryScope_; +} + +void ServiceInfoProfile::SetServiceDicoveryScope(const std::string& serviceDicoveryScope) +{ + serviceDicoveryScope_ = serviceDicoveryScope; +} + +std::string ServiceInfoProfile::GetExtraInfo() const +{ + return extraInfo_; +} + +void ServiceInfoProfile::SetExtraInfo(const std::string& extraInfo) +{ + extraInfo_ = extraInfo; +} + +bool ServiceInfoProfile::Marshalling(MessageParcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, networkId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, serviceDisplayName_, false); + WRITE_HELPER_RET(parcel, String, customData_, false); + WRITE_HELPER_RET(parcel, Int32, customDataLen_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + WRITE_HELPER_RET(parcel, String, moduleName_, false); + WRITE_HELPER_RET(parcel, String, abilityName_, false); + WRITE_HELPER_RET(parcel, Int32, authBoxType_, false); + WRITE_HELPER_RET(parcel, Int32, authType_, false); + WRITE_HELPER_RET(parcel, Int32, pinExchangeType_, false); + WRITE_HELPER_RET(parcel, String, pinCode_, false); + WRITE_HELPER_RET(parcel, String, description_, false); + WRITE_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + WRITE_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} + +bool ServiceInfoProfile::UnMarshalling(MessageParcel& parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, networkId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceDisplayName_, false); + READ_HELPER_RET(parcel, String, customData_, false); + READ_HELPER_RET(parcel, Int32, customDataLen_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + READ_HELPER_RET(parcel, String, moduleName_, false); + READ_HELPER_RET(parcel, String, abilityName_, false); + READ_HELPER_RET(parcel, Int32, authBoxType_, false); + READ_HELPER_RET(parcel, Int32, authType_, false); + READ_HELPER_RET(parcel, Int32, pinExchangeType_, false); + READ_HELPER_RET(parcel, String, pinCode_, false); + READ_HELPER_RET(parcel, String, description_, false); + READ_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + READ_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} + +std::string ServiceInfoProfile::dump() const +{ + return ""; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS diff --git a/common/src/interfaces/service_info_unique_key.cpp b/common/src/interfaces/service_info_unique_key.cpp new file mode 100644 index 00000000..0a93bfc3 --- /dev/null +++ b/common/src/interfaces/service_info_unique_key.cpp @@ -0,0 +1,110 @@ +/* + * 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_unique_key.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 = "ServiceInfoUniqueKey"; +} +ServiceInfoUniqueKey::ServiceInfoUniqueKey() +{ +} +ServiceInfoUniqueKey::~ServiceInfoUniqueKey() +{ +} +std::string ServiceInfoUniqueKey::GetDeviceId() const +{ + return deviceId_; +} + +void ServiceInfoUniqueKey::SetDeviceId(const std::string& deviceId) +{ + deviceId_ = deviceId; +} + +int32_t ServiceInfoUniqueKey::GetUserId() const +{ + return userId_; +} + +void ServiceInfoUniqueKey::SetUserId(const int32_t userId) +{ + userId_ = userId; +} + +std::string ServiceInfoUniqueKey::GetTokenId() const +{ + return tokenId_; +} + +void ServiceInfoUniqueKey::SetTokenId(const std::string& tokenId) +{ + tokenId_ = tokenId; +} + +int64_t ServiceInfoUniqueKey::GetServiceId() const +{ + return serviceId_; +} + +void ServiceInfoUniqueKey::SetServiceId(const int64_t serviceId) +{ + serviceId_ = serviceId; +} + +std::string ServiceInfoUniqueKey::GetBundleName() const +{ + return bundleName_; +} + +void ServiceInfoUniqueKey::SetBundleName(const std::string& bundleName) +{ + bundleName_ = bundleName; +} + +bool ServiceInfoUniqueKey::Marshalling(MessageParcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + return true; +} + +bool ServiceInfoUniqueKey::UnMarshalling(MessageParcel& parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + return true; +} + +std::string ServiceInfoUniqueKey::dump() const +{ + return ""; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS -- Gitee From e27c3bd79e30ca1fdba6eca599c5c2e0e38c2323 Mon Sep 17 00:00:00 2001 From: torrizo Date: Mon, 17 Feb 2025 10:59:37 +0000 Subject: [PATCH 2/2] add serviceInfoProfile Signed-off-by: torrizo --- common/BUILD.gn | 2 + .../distributed_device_profile_constants.h | 24 ++ .../distributed_device_profile_errors.h | 4 + .../distributed_device_profile_enums.h | 9 +- .../interfaces/i_distributed_device_profile.h | 12 + common/include/utils/ipc_utils.h | 3 + .../distributed_device_profile_constants.cpp | 23 ++ .../src/interfaces/service_info_profile.cpp | 6 +- .../utils/content_sensor_manager_utils.cpp | 2 +- common/src/utils/ipc_utils.cpp | 55 ++- common/src/utils/profile_utils.cpp | 1 - .../distributed_device_profile_client.h | 11 +- .../distributed_device_profile_proxy.h | 10 + .../src/distributed_device_profile_client.cpp | 74 ++++ .../src/distributed_device_profile_proxy.cpp | 124 ++++++ .../include/distributed_device_profile_stub.h | 7 + .../src/distributed_device_profile_stub.cpp | 147 ++++++- permission/permission.json | 7 + services/core/BUILD.gn | 3 + .../include/common/dp_services_constants.h | 11 + .../distributed_device_profile_service_new.h | 12 + .../rdbadapter/service_info_rdb_adapter.h | 54 +++ .../service_info_profile_manager.h | 60 +++ .../core/src/common/dp_services_constants.cpp | 179 +++++---- ...distributed_device_profile_service_new.cpp | 88 ++++ .../permissionmanager/permission_manager.cpp | 7 + .../rdbadapter/profile_data_rdb_adapter.cpp | 7 +- .../rdbadapter/service_info_rdb_adapter.cpp | 256 ++++++++++++ .../characteristic_profile_dao.cpp | 2 +- .../device_icon_info_dao.cpp | 2 +- .../profiledatamanager/device_profile_dao.cpp | 2 +- .../profiledatamanager/product_info_dao.cpp | 2 +- .../service_info_profile_manager.cpp | 377 ++++++++++++++++++ .../trust_profile_manager.cpp | 4 + ...stributed_device_profile_stub_new_test.cpp | 56 +++ 35 files changed, 1551 insertions(+), 92 deletions(-) create mode 100644 services/core/include/persistenceadapter/rdbadapter/service_info_rdb_adapter.h create mode 100644 services/core/include/serviceinfoprofile_manager/service_info_profile_manager.h create mode 100644 services/core/src/persistenceadapter/rdbadapter/service_info_rdb_adapter.cpp create mode 100644 services/core/src/serviceinfoprofile_manager/service_info_profile_manager.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index 36e720f2..eb20c944 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -67,6 +67,8 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/product_info.cpp", "src/interfaces/profile_change_listener_proxy.cpp", "src/interfaces/profile_change_listener_stub.cpp", + "src/interfaces/service_info_profile.cpp", + "src/interfaces/service_info_unique_key.cpp", "src/interfaces/service_profile.cpp", "src/interfaces/sync_completed_callback_proxy.cpp", "src/interfaces/sync_completed_callback_stub.cpp", diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 45ae50bf..753cc5e8 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -95,6 +95,29 @@ extern const std::string SPEC_NAME; extern const std::string DEVICE_ICON; extern const std::string DEVICE_ICON_VERSION; extern const std::string DEVICE_ICON_URL; + /* ServiceInfoProfile Attribute */ +extern const std::string SRNETWORK_ID; +extern const std::string SISERVICE_ID; +extern const std::string SERVICE_DISPLAY_NAME; +extern const std::string CUSTOM_DATA; +extern const std::string CUSTOM_DATA_LEN; +extern const std::string BUNDLE_NAME; +extern const std::string MODULE_NAME; +extern const std::string ABILITY_NAME; +extern const std::string AUTH_BOX_TYPE; +extern const std::string AUTH_TYPE; +extern const std::string PIN_EXCHANGE_TYPE; +extern const std::string PINCODE; +extern const std::string DESCRIPTION; +extern const std::string SERVICE_DISCOVERY_SCOPE; +extern const std::string EXTRAINFO; +extern const std::string PUT_SERVICE_INFO_PROFILE; +extern const std::string DELETE_SERVICE_INFO_PROFILE; +extern const std::string UPDATE_SERVICE_INFO_PROFILE; +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; /* TrustDeviceProfile Attribute */ extern const std::string SUBSCRIBE_TRUST_DEVICE_PROFILE; extern const std::string DEVICE_ID_TYPE; @@ -218,6 +241,7 @@ constexpr int32_t NUM_4 = 4; constexpr int32_t NUM_5 = 5; constexpr int32_t NUM_6 = 6; constexpr int32_t DEFAULT_USER_ID = -1; +constexpr int64_t DEFAULT_SERVICE_ID = -1; constexpr int32_t DEFAULT_ID = -1; constexpr int32_t DEFAULT_SERVICE_PROFILE_ID = -1; constexpr int32_t DEFAULT_DEVICE_PROFILE_ID = -1; diff --git a/common/include/constants/distributed_device_profile_errors.h b/common/include/constants/distributed_device_profile_errors.h index 42e71a72..45be1141 100644 --- a/common/include/constants/distributed_device_profile_errors.h +++ b/common/include/constants/distributed_device_profile_errors.h @@ -189,6 +189,10 @@ constexpr int32_t DP_CREATE_INDEX_FAIL = 98566308; constexpr int32_t DP_SETTINGSDATA_MANAGER_INIT_FAIL = 98566309; constexpr int32_t DP_SETTINGSDATA_MANAGER_UNINIT_FAIL = 98566310; constexpr int32_t DP_PROFILE_DATA_MANAGER_UNINIT_FAIL = 98566311; +constexpr int32_t DP_SERVICE_INFO_PROFILE_MANAGER_INIT_FAIL = 98566312; +constexpr int32_t DP_PUT_SERVICE_INFO_PROFILE_FAIL = 98566313; +constexpr int32_t DP_DELETE_SERVICE_INFO_PROFILE_FAIL = 98566314; +constexpr int32_t DP_UPDATE_SERVICE_INFO_PROFILE_FAIL = 98566315; } // namespace DistributedDeviceProfile } // namespace OHOS #endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ERRORS_H diff --git a/common/include/interfaces/distributed_device_profile_enums.h b/common/include/interfaces/distributed_device_profile_enums.h index 6e831ac0..cb5ac11d 100644 --- a/common/include/interfaces/distributed_device_profile_enums.h +++ b/common/include/interfaces/distributed_device_profile_enums.h @@ -67,7 +67,14 @@ enum class DPInterfaceCode : uint32_t { PUT_DEVICE_ICON_INFO_BATCH = 49, PUT_PRODUCT_INFO_BATCH = 50, DELETE_DEVICE_PROFILE_BATCH = 51, - MAX = 52 + PUT_SERVICE_INFO_PROFILE = 52, + DELETE_SERVICE_INFO_PROFILE = 53, + UPDATE_SERVICE_INFO_PROFILE = 54, + GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY = 55, + GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID = 56, + GET_ALL_SERVICE_INFO_PROFILE_LIST = 57, + GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME = 58, + MAX = 59 }; 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 e3315494..b580f5f9 100644 --- a/common/include/interfaces/i_distributed_device_profile.h +++ b/common/include/interfaces/i_distributed_device_profile.h @@ -30,6 +30,8 @@ #include "dp_sync_options.h" #include "i_sync_completed_callback.h" #include "product_info.h" +#include "service_info_profile.h" +#include "service_info_unique_key.h" #include "service_profile.h" #include "trust_device_profile.h" #include "trusted_device_info.h" @@ -78,6 +80,16 @@ public: virtual int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) = 0; virtual int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, std::vector& deviceIconInfos) = 0; + virtual int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) = 0; + virtual int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) = 0; + virtual int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) = 0; + virtual int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) = 0; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/include/utils/ipc_utils.h b/common/include/utils/ipc_utils.h index 4168ecac..4d3ba092 100644 --- a/common/include/utils/ipc_utils.h +++ b/common/include/utils/ipc_utils.h @@ -34,6 +34,7 @@ #include "distributed_device_profile_log.h" #include "dp_subscribe_info.h" #include "product_info.h" +#include "service_info_profile.h" #include "service_profile.h" #include "trust_device_profile.h" #include "trusted_device_info.h" @@ -57,6 +58,8 @@ public: static bool Marshalling(MessageParcel& parcel, const std::vector& deviceInfos); static bool Marshalling(MessageParcel& parcel, const std::vector& deviceIconInfos); static bool Marshalling(MessageParcel& parcel, const std::vector& productInfos); + static bool Marshalling(MessageParcel& parcel, const std::vector& serviceInfoProfiles); + static bool UnMarshalling(MessageParcel& parcel, std::vector& serviceInfoProfiles); static bool UnMarshalling(MessageParcel& parcel, std::vector& productInfos); static bool UnMarshalling(MessageParcel& parcel, std::vector& deviceIconInfos); static bool UnMarshalling(MessageParcel& parcel, std::vector& trustDeviceProfiles); diff --git a/common/src/constants/distributed_device_profile_constants.cpp b/common/src/constants/distributed_device_profile_constants.cpp index 3036e8e9..2399d573 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -126,6 +126,29 @@ const std::string SUBSCRIBE_CHANGE_TYPES = "subscribeChangeTypes"; /* syncOptions */ const std::string SYNC_MODE = "syncMode"; const std::string SYNC_DEVICE_IDS = "syncDevices"; +/* ServiceInfoProfile Attribute */ +const std::string SRNETWORK_ID = "networkId"; +const std::string SISERVICE_ID = "serviceId"; +const std::string SERVICE_DISPLAY_NAME = "serviceDisplayName"; +const std::string CUSTOM_DATA = "customData"; +const std::string CUSTOM_DATA_LEN = "customDataLen"; +const std::string BUNDLE_NAME = "bundleName"; +const std::string MODULE_NAME = "moduleName"; +const std::string ABILITY_NAME = "abilityName"; +const std::string AUTH_BOX_TYPE = "authBoxType"; +const std::string AUTH_TYPE = "authType"; +const std::string PIN_EXCHANGE_TYPE = "pinExchangeType"; +const std::string PINCODE = "pinCode"; +const std::string DESCRIPTION = "description"; +const std::string SERVICE_DISCOVERY_SCOPE = "serviceDicoveryScope"; +const std::string EXTRAINFO = "extraInfo"; +const std::string PUT_SERVICE_INFO_PROFILE = "PutServiceInfoProfile"; +const std::string DELETE_SERVICE_INFO_PROFILE = "DeleteServiceInfoProfile"; +const std::string UPDATE_SERVICE_INFO_PROFILE = "UpdateServiceInfoProfile"; +const std::string GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY = "GetServiceInfoProfileByUniqueKey"; +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"; /* Interface Name */ const std::string PUT_ACCESS_CONTROL_PROFILE = "PutAccessControlProfile"; const std::string UPDATE_ACCESS_CONTROL_PROFILE = "UpdateAccessControlProfile"; diff --git a/common/src/interfaces/service_info_profile.cpp b/common/src/interfaces/service_info_profile.cpp index 9e126f86..ccc5bbd1 100644 --- a/common/src/interfaces/service_info_profile.cpp +++ b/common/src/interfaces/service_info_profile.cpp @@ -225,10 +225,10 @@ void ServiceInfoProfile::SetServiceDicoveryScope(const std::string& serviceDicov serviceDicoveryScope_ = serviceDicoveryScope; } -std::string ServiceInfoProfile::GetExtraInfo() const -{ + std::string ServiceInfoProfile::GetExtraInfo() const + { return extraInfo_; -} + } void ServiceInfoProfile::SetExtraInfo(const std::string& extraInfo) { diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index a4220229..6852aa56 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -206,7 +206,7 @@ std::string ContentSensorManagerUtils::ObtainProductId() return ""; } productId_ = productIdTemp; - if (productId_.size() > 1) { + if (productId_.size() > NUM_1) { productId_.pop_back(); } return productId_; diff --git a/common/src/utils/ipc_utils.cpp b/common/src/utils/ipc_utils.cpp index 27235195..b4c12787 100644 --- a/common/src/utils/ipc_utils.cpp +++ b/common/src/utils/ipc_utils.cpp @@ -239,6 +239,38 @@ bool IpcUtils::Marshalling(MessageParcel& parcel, const std::vector& serviceInfoProfiles) +{ + uint32_t size = serviceInfoProfiles.size(); + WRITE_HELPER_RET(parcel, Uint32, size, false); + if (serviceInfoProfiles.empty() || serviceInfoProfiles.size() > MAX_PROFILE_SIZE) { + HILOGE("deviceInfos size is invalid!size : %{public}zu", serviceInfoProfiles.size()); + return false; + } + for (const auto& item : serviceInfoProfiles) { + item.Marshalling(parcel); + } + return true; +} + +bool IpcUtils::UnMarshalling(MessageParcel& parcel, std::vector& serviceInfoProfiles) +{ + uint32_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_PROFILE_SIZE) { + HILOGE("Profile size is invalid!size : %{public}u", size); + return false; + } + for (uint32_t i = 0; i < size; i++) { + ServiceInfoProfile serviceInfoProfile; + if (!serviceInfoProfile.UnMarshalling(parcel)) { + HILOGE("Profile UnMarshalling fail!"); + return false; + } + serviceInfoProfiles.emplace_back(serviceInfoProfile); + } + return true; +} + bool IpcUtils::UnMarshalling(MessageParcel& parcel, std::vector& deviceIconInfos) { uint32_t size = parcel.ReadUint32(); @@ -397,18 +429,23 @@ bool IpcUtils::UnMarshalling(MessageParcel& parcel, std::vector& params bool IpcUtils::UnMarshalling(MessageParcel& parcel, std::vector& params) { - int32_t length = parcel.ReadInt32(); - if (length == 0 || length > MAX_ICON_SIZE) { - HILOGE("uint8_t vector, params size is invalid! size : %{public}d", length); + uint32_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_PARAM_SIZE) { + HILOGE("Params size is invalid!size : %{public}u", size); return false; } - const unsigned char *buffer = nullptr; - if ((buffer = reinterpret_cast(parcel.ReadRawData((size_t)length))) == nullptr) { - HILOGE("read raw data failed, length = %{public}d", length); - return false; + for (uint32_t i = 0; i < size; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + std::string::size_type position = item.find(SEPARATOR); + if (position == item.npos) { + HILOGE("Not found the separator!"); + continue; + } + std::string key = item.substr(0, position); + std::string value = item.substr(position + 1); + params[key] = value; } - std::vector icon(buffer, buffer + length); - params = icon; return true; } diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 24bef78c..e03ebc48 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -1066,6 +1066,5 @@ int32_t ProfileUtils::ConvertToAccessControlProfile( accessControlProfile.SetBindLevel(bindLevel); return DP_SUCCESS; } - } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index 182d5de2..1b614629 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -78,7 +78,16 @@ public: int32_t SubscribeDeviceProfileInited(int32_t saId, sptr initedCb); int32_t UnSubscribeDeviceProfileInited(int32_t saId); int32_t PutAllTrustedDevices(const std::vector& deviceInfos); - + int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile); + int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key); + int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile); + int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, ServiceInfoProfile& serviceInfoProfile); + int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles); + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles); + int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles); + void LoadSystemAbilitySuccess(const sptr &remoteObject); void LoadSystemAbilityFail(); diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h index c19a2b3c..003d0e53 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h @@ -75,6 +75,16 @@ public: int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, std::vector& deviceIconInfos) override; + int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; + int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; + int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; 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 dbf4e541..42b1291e 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -234,6 +234,80 @@ int32_t DistributedDeviceProfileClient::PutServiceProfile(const ServiceProfile& return dpService->PutServiceProfile(serviceProfile); } +int32_t DistributedDeviceProfileClient::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->PutServiceInfoProfile(serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->DeleteServiceInfoProfile(key); +} + +int32_t DistributedDeviceProfileClient::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->UpdateServiceInfoProfile(serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); +} + +int32_t DistributedDeviceProfileClient::GetAllServiceInfoProfileList( + std::vector& serviceInfoProfiles) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->GetAllServiceInfoProfileList(serviceInfoProfiles); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + auto dpService = GetDeviceProfileService(); + if (dpService == nullptr) { + HILOGE("Get dp service failed"); + return DP_GET_SERVICE_FAILED; + } + return dpService->GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); +} + int32_t DistributedDeviceProfileClient::PutServiceProfileBatch(const std::vector& serviceProfiles) { auto dpService = GetDeviceProfileService(); diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp index 2efea3c4..6d439997 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp @@ -331,6 +331,130 @@ int32_t DistributedDeviceProfileProxy::GetServiceProfile(const std::string& devi return DP_SUCCESS; } +int32_t DistributedDeviceProfileProxy::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!serviceInfoProfile.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!key.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!serviceInfoProfile.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE), data, reply); + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!key.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY), data, reply); + if (!serviceInfoProfile.UnMarshalling(reply)) { + HILOGE("dp ipc read parcel fail"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!key.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID), + data, reply); + if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { + HILOGE("dp ipc read parcel fail"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetAllServiceInfoProfileList( + std::vector& serviceInfoProfiles) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST), + data, reply); + if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { + HILOGE("dp ipc read parcel fail"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + sptr remote = nullptr; + GET_REMOTE_OBJECT(remote); + MessageParcel data; + WRITE_INTERFACE_TOKEN(data); + if (!key.Marshalling(data)) { + HILOGE("dp ipc write parcel fail"); + return DP_WRITE_PARCEL_FAIL; + } + MessageParcel reply; + SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME), + data, reply); + if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { + HILOGE("dp ipc read parcel fail"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + int32_t DistributedDeviceProfileProxy::GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) { diff --git a/old/services/core/include/distributed_device_profile_stub.h b/old/services/core/include/distributed_device_profile_stub.h index 21f82237..6dc5448f 100644 --- a/old/services/core/include/distributed_device_profile_stub.h +++ b/old/services/core/include/distributed_device_profile_stub.h @@ -68,6 +68,13 @@ public: int32_t PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply); int32_t PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply); int32_t GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply); + int32_t PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); + int32_t DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); + int32_t UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); + int32_t GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply); + int32_t GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, MessageParcel& reply); + int32_t GetAllServiceInfoProfileListInner(MessageParcel& data, MessageParcel& reply); + int32_t GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, MessageParcel& reply); virtual void DelayUnloadTask() { return; diff --git a/old/services/core/src/distributed_device_profile_stub.cpp b/old/services/core/src/distributed_device_profile_stub.cpp index 894e7728..3a742d82 100644 --- a/old/services/core/src/distributed_device_profile_stub.cpp +++ b/old/services/core/src/distributed_device_profile_stub.cpp @@ -228,6 +228,20 @@ int32_t DistributedDeviceProfileStub::NotifyNewEventInner(uint32_t code, Message return DeleteCharacteristicProfileInner(data, reply); case static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW): return SyncDeviceProfileNewInner(data, reply); + case static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE): + return PutServiceInfoProfileInner(data, reply); + case static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE): + return DeleteServiceInfoProfileInner(data, reply); + case static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE): + return UpdateServiceInfoProfileInner(data, reply); + case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY): + return GetServiceInfoProfileByUniqueKeyInner(data, reply); + case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID): + return GetServiceInfoProfileListByTokenIdInner(data, reply); + case static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST): + return GetAllServiceInfoProfileListInner(data, reply); + case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME): + return GetServiceInfoProfileListByBundleNameInner(data, reply); default: HILOGW("unknown request code, please check, code = %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -477,6 +491,138 @@ int32_t DistributedDeviceProfileStub::GetDeviceIconInfosInner(MessageParcel& dat return DP_SUCCESS; } +int32_t DistributedDeviceProfileStub::PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + ServiceInfoProfile serviceInfoProfile; + if (!serviceInfoProfile.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + ServiceInfoUniqueKey key; + if (!key.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceInfoProfile(key); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) +{ + HILOGI("called"); + ServiceInfoProfile serviceInfoProfile; + if (!serviceInfoProfile.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return DP_WRITE_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply) +{ + ServiceInfoUniqueKey key; + ServiceInfoProfile serviceInfoProfile; + if (!key.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileByUniqueKey(key, + serviceInfoProfile); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + if (!serviceInfoProfile.Marshalling(reply)) { + HILOGE("write parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, + MessageParcel& reply) +{ + ServiceInfoUniqueKey key; + std::vector serviceInfoProfiles; + if (!key.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByTokenId(key, + serviceInfoProfiles); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + + if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { + HILOGE("Write parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::GetAllServiceInfoProfileListInner(MessageParcel& data, + MessageParcel& reply) +{ + std::vector serviceInfoProfiles; + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + + if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { + HILOGE("Write parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + +int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, + MessageParcel& reply) +{ + ServiceInfoUniqueKey key; + std::vector serviceInfoProfiles; + if (!key.UnMarshalling(data)) { + HILOGE("read parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByBundleName(key, + serviceInfoProfiles); + if (!reply.WriteInt32(ret)) { + HILOGE("Write reply failed"); + return ERR_FLATTEN_OBJECT; + } + + if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { + HILOGE("Write parcel fail!"); + return DP_READ_PARCEL_FAIL; + } + return DP_SUCCESS; +} + int32_t DistributedDeviceProfileStub::DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) { std::vector deviceProfiles; @@ -819,7 +965,6 @@ int32_t DistributedDeviceProfileStub::SyncDeviceProfileNewInner(MessageParcel& d return DP_SUCCESS; } - int32_t DistributedDeviceProfileStub::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply) { std::map listenerMap; diff --git a/permission/permission.json b/permission/permission.json index 7ea15a85..343b475a 100644 --- a/permission/permission.json +++ b/permission/permission.json @@ -7,6 +7,13 @@ "GetAllTrustDeviceProfile": ["device_manager", "softbus_server"], "GetAllAccessControlProfile": ["device_manager", "softbus_server"], "PutAllTrustedDevices": ["device_manager"], + "PutServiceInfoProfile": ["device_manager"], + "DeleteServiceInfoProfile": ["device_manager"], + "UpdateServiceInfoProfile": ["device_manager"], + "GetServiceInfoProfileByUniqueKey": ["device_manager"], + "GetServiceInfoProfileListByTokenId": ["device_manager"], + "GetAllServiceInfoProfileList": ["device_manager"], + "GetServiceInfoProfileListByBundleName": ["device_manager"], "PutServiceProfile": ["all"], "PutServiceProfileBatch": ["all"], "PutCharacteristicProfile": ["all"], diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 3a171e41..e190dfa1 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -34,6 +34,7 @@ config("device_info_manager_config") { "include/persistenceadapter/rdbadapter", "include/profiledatamanager", "include/publishcommonevent", + "include/serviceinfoprofile_manager", "include/subscribeprofilemanager", "include/staticcapabilitycollector", "include/staticcapabilityloader", @@ -102,11 +103,13 @@ ohos_shared_library("distributed_device_profile_svr") { "src/persistenceadapter/kvadapter/switch_adapter.cpp", "src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp", "src/persistenceadapter/rdbadapter/rdb_adapter.cpp", + "src/persistenceadapter/rdbadapter/service_info_rdb_adapter.cpp", "src/profiledatamanager/device_icon_info_dao.cpp", "src/profiledatamanager/device_profile_dao.cpp", "src/profiledatamanager/product_info_dao.cpp", "src/profiledatamanager/profile_data_manager.cpp", "src/publishcommonevent/dp_account_common_event.cpp", + "src/serviceinfoprofile_manager/service_info_profile_manager.cpp", "src/staticcapabilitycollector/static_capability_collector.cpp", "src/staticcapabilityloader/static_capability_loader.cpp", "src/subscribeprofilemanager/subscribe_profile_manager.cpp", diff --git a/services/core/include/common/dp_services_constants.h b/services/core/include/common/dp_services_constants.h index 6535cd33..3083ec6d 100644 --- a/services/core/include/common/dp_services_constants.h +++ b/services/core/include/common/dp_services_constants.h @@ -27,6 +27,8 @@ constexpr int32_t AND_LENGTH = 5; constexpr int32_t WHERE_LENGTH = 7; extern const std::string PROFILE_DATA_RDB_PATH; extern const std::string PROFILE_DATA_DATABASE_NAME; +extern const std::string SERVICE_INFO_PROFILE_RDB_PATH; +extern const std::string SERVICE_INFO_PROFILE_DATABASE_NAME; extern const std::string ID_EQUAL_CONDITION; extern const std::string SELECT_DEVICE_PROFILE_TABLE; extern const std::string SELECT_DEVICE_PROFILE_TABLE_WHERE_DEVID_USERID; @@ -52,6 +54,15 @@ extern const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_SQL; extern const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_CHARACTERISTIC_KEY; extern const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_SERVICE_PROFILE_ID; extern const std::string SELECT_CHARACTERISTIC_PROFILE_TABLE_MAX_ID; +// ServiceInfoProfile +extern const std::string SERVICE_INFO_PROFILE_TABLE; +extern const std::string CREATE_SERVICE_INFO_PROFILE_TABLE_SQL; +extern const std::string CREATE_SERVICE_INFO_PROFILE_TABLE_UNIQUE_INDEX_SQL; +extern const std::string SELECT_SERVICE_INFO_PROFILE_ALL; +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; } // namespace DistributedDeviceProfile } // namespace OHOS #endif // OHOS_DP_SERVICES_CONSTANTS_H diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 64ad9abe..0315c797 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -29,6 +29,8 @@ #include "event_handler.h" #include "event_runner.h" #include "product_info.h" +#include "service_info_profile.h" +#include "service_info_unique_key.h" #include "single_instance.h" #include "system_ability.h" #include "system_ability_definition.h" @@ -74,6 +76,16 @@ public: int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, std::vector& deviceIconInfos) override; + int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; + int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; + int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, diff --git a/services/core/include/persistenceadapter/rdbadapter/service_info_rdb_adapter.h b/services/core/include/persistenceadapter/rdbadapter/service_info_rdb_adapter.h new file mode 100644 index 00000000..9af0254e --- /dev/null +++ b/services/core/include/persistenceadapter/rdbadapter/service_info_rdb_adapter.h @@ -0,0 +1,54 @@ +/* + * 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_RDB_ADAPTER_H +#define OHOS_DP_SERVICE_INFO_RDB_ADAPTER_H + + +#include +#include "irdb_adapter.h" +#include "rdb_open_callback.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class ServiceInfoRdbAdapter : public IRdbAdapter { + DECLARE_SINGLE_INSTANCE(ServiceInfoRdbAdapter); +public: + int32_t Init() override; + int32_t UnInit() override; + int32_t Put(int64_t& outRowId, const std::string& table, const ValuesBucket& Values) override; + int32_t Delete(int32_t& deleteRows, const std::string& table, const std::string& whereClause, + const std::vector& bindArgs = {}) override; + int32_t Update(int32_t& changedRows, const std::string& table, const ValuesBucket& values, + const std::string& whereClause, const std::vector& bindArgs = {}) override; + int32_t CreateTable(const std::string& sql) override; + std::shared_ptr Get(const std::string& sql, const std::vector& args = {}) override; + int32_t GetRDBPtr(); + bool IsInit(); + +private: + std::shared_ptr store_ = nullptr; + std::mutex ServiceInfoRdbAdapterMtx_; +}; + +class ServiceInfoOpenCallback : public NativeRdb::RdbOpenCallback { +public: + int32_t OnCreate(RdbStore& store) override; + int32_t OnUpgrade(RdbStore& store, int oldVersion, int newVersion) override; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS +#endif // OHOS_DP_SERVICE_INFO_RDB_ADAPTER_H diff --git a/services/core/include/serviceinfoprofile_manager/service_info_profile_manager.h b/services/core/include/serviceinfoprofile_manager/service_info_profile_manager.h new file mode 100644 index 00000000..90655efe --- /dev/null +++ b/services/core/include/serviceinfoprofile_manager/service_info_profile_manager.h @@ -0,0 +1,60 @@ +/* + * 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_PROFILE_MANAGER_H +#define OHOS_DP_SERVICE_INFO_PROFILE_MANAGER_H + +#include +#include +#include +#include +#include + +#include "kvstore_observer.h" +#include "values_bucket.h" + +#include "service_info_profile.h" +#include "service_info_rdb_adapter.h" +#include "service_info_unique_key.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +using namespace OHOS::NativeRdb; +class ServiceInfoProfileManager { + DECLARE_SINGLE_INSTANCE(ServiceInfoProfileManager); +public: + int32_t Init(); + int32_t UnInit(); + int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile); + int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key); + int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile); + int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, ServiceInfoProfile& serviceInfoProfile); + int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles); + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles); + int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles); +private: + int32_t ConvertToServiceInfo(std::shared_ptr resultSet, ServiceInfoProfile& serviceInfo); + int32_t ServiceInfoProfileToEntries(const ServiceInfoProfile& serviceInfo, ValuesBucket& values); + int32_t CreateTable(); + int32_t CreateIndex(); + +private: +}; +} // DistributedDeviceProfile +} // OHOS +#endif // OHOS_DP_SERVICE_INFO_PROFILE_MANAGER_H diff --git a/services/core/src/common/dp_services_constants.cpp b/services/core/src/common/dp_services_constants.cpp index 8950a865..e937491f 100644 --- a/services/core/src/common/dp_services_constants.cpp +++ b/services/core/src/common/dp_services_constants.cpp @@ -23,88 +23,91 @@ namespace { /* DeviceProfileDao */ const std::string PROFILE_DATA_RDB_PATH = "/data/service/el2/public/database/distributed_device_profile_service/"; const std::string PROFILE_DATA_DATABASE_NAME = "profile_data.db"; +const std::string SERVICE_INFO_PROFILE_RDB_PATH = + "/data/service/el1/public/database/distributed_device_profile_service/"; +const std::string SERVICE_INFO_PROFILE_DATABASE_NAME = "service_info_store.db"; const std::string ID_EQUAL_CONDITION = "id = ?"; const std::string SELECT_DEVICE_PROFILE_TABLE = "SELECT * FROM device_profile WHERE "; const std::string SELECT_DEVICE_PROFILE_TABLE_WHERE_DEVID_USERID = "SELECT * FROM device_profile WHERE deviceId = ? AND userId = ?"; const std::string CREATE_DEVICE_PROFILE_TABLE_SQL = -"CREATE TABLE IF NOT EXISTS device_profile (\n" -" id INTEGER PRIMARY KEY AUTOINCREMENT,\n" -" deviceId TEXT NOT NULL,\n" -" userId INTEGER,\n" -" accountId TEXT,\n" -" productId TEXT,\n" -" subProductId TEXT,\n" -" model TEXT,\n" -" devType TEXT,\n" -" deviceName TEXT,\n" -" manu TEXT,\n" -" sn TEXT,\n" -" hiv TEXT,\n" -" mac TEXT,\n" -" bleMac TEXT,\n" -" brMac TEXT,\n" -" sleMac TEXT,\n" -" fwv TEXT,\n" -" hwv TEXT,\n" -" swv TEXT,\n" -" protType INTEGER,\n" -" setupType INTEGER,\n" -" wiseUserId TEXT,\n" -" wiseDeviceId TEXT,\n" -" registerTime TEXT,\n" -" modifyTime TEXT,\n" -" shareTime TEXT,\n" -" innerModel TEXT\n" -")"; + "CREATE TABLE IF NOT EXISTS device_profile (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " deviceId TEXT NOT NULL,\n" + " userId INTEGER,\n" + " accountId TEXT,\n" + " productId TEXT,\n" + " subProductId TEXT,\n" + " model TEXT,\n" + " devType TEXT,\n" + " deviceName TEXT,\n" + " manu TEXT,\n" + " sn TEXT,\n" + " hiv TEXT,\n" + " mac TEXT,\n" + " bleMac TEXT,\n" + " brMac TEXT,\n" + " sleMac TEXT,\n" + " fwv TEXT,\n" + " hwv TEXT,\n" + " swv TEXT,\n" + " protType INTEGER,\n" + " setupType INTEGER,\n" + " wiseUserId TEXT,\n" + " wiseDeviceId TEXT,\n" + " registerTime TEXT,\n" + " modifyTime TEXT,\n" + " shareTime TEXT,\n" + " innerModel TEXT\n" + ")"; const std::string CREATE_DEVICE_PROFILE_TABLE_UNIQUE_INDEX_SQL = -"CREATE UNIQUE INDEX IF NOT EXISTS unique_device_profile ON device_profile (deviceId, userId)"; + "CREATE UNIQUE INDEX IF NOT EXISTS unique_device_profile ON device_profile (deviceId, userId)"; const std::string CREATE_DEVICE_PROFILE_WISE_DEVICEID_INDEX_SQL = -"CREATE INDEX IF NOT EXISTS index_wiseDeviceId ON device_profile (wiseDeviceId)"; + "CREATE INDEX IF NOT EXISTS index_wiseDeviceId ON device_profile (wiseDeviceId)"; // DeviceIconInfoDao const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL = "CREATE TABLE IF NOT EXISTS device_icon_info\ -(id INTEGER PRIMARY KEY AUTOINCREMENT,\ -productId TEXT,\ -subProductId TEXT,\ -imageType TEXT,\ -specName TEXT,\ -version TEXT,\ -url TEXT,\ -icon blob);"; + (id INTEGER PRIMARY KEY AUTOINCREMENT,\ + productId TEXT,\ + subProductId TEXT,\ + imageType TEXT,\ + specName TEXT,\ + version TEXT,\ + url TEXT,\ + icon blob);"; const std::string CREATE_DEVICE_ICON_INFO_TABLE_UNIQUE_INDEX_SQL = "CREATE UNIQUE INDEX if not exists \ -unique_device_icon_info ON device_icon_info (productId, subProductId, imageType, specName);"; + unique_device_icon_info ON device_icon_info (productId, subProductId, imageType, specName);"; const std::string SELECT_DEVICE_ICON_INFO_TABLE = "SELECT a.*,b.imageVersion FROM device_icon_info a \ -LEFT JOIN product_info b ON a.productId = b.productId \ -WHERE "; + LEFT JOIN product_info b ON a.productId = b.productId \ + WHERE "; // ProductInfoDao const std::string CREATE_PRODUCT_INFO_TABLE_SQL = "CREATE TABLE IF NOT EXISTS product_info \ -(productId TEXT PRIMARY KEY,\ -model TEXT,\ -productName TEXT,\ -productShortName TEXT,\ -imageVersion TEXT);"; + (productId TEXT PRIMARY KEY,\ + model TEXT,\ + productName TEXT,\ + productShortName TEXT,\ + imageVersion TEXT);"; const std::string SELECT_PRODUCT_INFO_TABLE = "SELECT * FROM product_info WHERE "; /* ServiceProfileDao */ const std::string SELECT_SERVICE_PROGILES = "SELECT sp.*, dp.deviceId, dp.userId FROM service_profile sp \ LEFT JOIN device_profile dp ON dp.id=sp.deviceProfileId WHERE "; const std::string CREATE_SERVICE_PROFILE_TABLE_SQL = -"CREATE TABLE IF NOT EXISTS service_profile (\n" -" id INTEGER PRIMARY KEY AUTOINCREMENT,\n" -" deviceProfileId INTEGER NOT NULL,\n" -" serviceId TEXT NOT NULL,\n" -" serviceType TEXT,\n" -" FOREIGN KEY (\n" -" deviceProfileId\n" -" )\n" -" REFERENCES device_profile (id)\n" -")"; + "CREATE TABLE IF NOT EXISTS service_profile (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " deviceProfileId INTEGER NOT NULL,\n" + " serviceId TEXT NOT NULL,\n" + " serviceType TEXT,\n" + " FOREIGN KEY (\n" + " deviceProfileId\n" + " )\n" + " REFERENCES device_profile (id)\n" + ")"; const std::string CREATE_SERVICE_PROFILE_TABLE_INDEX_SERVICEID_SQL = -"CREATE INDEX if not exists serviceId_idx ON service_profile (serviceId)"; + "CREATE INDEX if not exists serviceId_idx ON service_profile (serviceId)"; const std::string CREATE_SERVICE_PROFILE_TABLE_INDEX_DEVICEPROFILEID_SQL = -"CREATE INDEX if not exists deviceProfileId_idx ON service_profile (deviceProfileId)"; + "CREATE INDEX if not exists deviceProfileId_idx ON service_profile (deviceProfileId)"; const std::string SELECT_SERVICE_PROFILE_TABLE_WHERE_DEVID_SERID_SERTYPE = -"SELECT * FROM service_profile WHERE deviceProfileId = ? AND serviceId = ? AND serviceType = ?"; + "SELECT * FROM service_profile WHERE deviceProfileId = ? AND serviceId = ? AND serviceType = ?"; // CharateristicProfileDao const std::string SELECT_CHARACTERISTIC_PROFILE_TABLE_MAX_ID = "SELECT * FROM characteristic_profile WHERE serviceProfileId = ? AND characteristicKey = ? \ @@ -114,16 +117,54 @@ const std::string SELECT_CHARACTERISTIC_PROFILE_TABLE = "SELECT cp.*,sp.serviceI left join service_profile sp on cp.serviceProfileId=sp.id\ left join device_profile dp on dp.id=sp.deviceProfileId WHERE "; const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS characteristic_profile (\ - id INTEGER PRIMARY KEY AUTOINCREMENT,\ - serviceProfileId INTEGER NOT NULL,\ - characteristicKey TEXT NOT NULL,\ - characteristicValue TEXT NOT NULL,\ - FOREIGN KEY (serviceProfileId)\ - REFERENCES service_profile (id)\ -);"; + id INTEGER PRIMARY KEY AUTOINCREMENT,\ + serviceProfileId INTEGER NOT NULL,\ + characteristicKey TEXT NOT NULL,\ + characteristicValue TEXT NOT NULL,\ + FOREIGN KEY (serviceProfileId)\ + REFERENCES service_profile (id)\ + );"; const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_CHARACTERISTIC_KEY = -"CREATE INDEX IF NOT EXISTS index_characteristicKey ON characteristic_profile (characteristicKey)"; + "CREATE INDEX IF NOT EXISTS index_characteristicKey ON characteristic_profile (characteristicKey)"; const std::string CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_SERVICE_PROFILE_ID = -"CREATE INDEX IF NOT EXISTS index_serviceProfileId ON characteristic_profile (serviceProfileId)"; + "CREATE INDEX IF NOT EXISTS index_serviceProfileId ON characteristic_profile (serviceProfileId)"; +// ServiceInfoProfile +const std::string SERVICE_INFO_PROFILE_TABLE = "service_info_profile"; +const std::string CREATE_SERVICE_INFO_PROFILE_TABLE_SQL = + "CREATE TABLE IF NOT EXISTS service_info_profile (\n" + " deviceId TEXT,\n" + " userId INTEGER,\n" + " networkId TEXT,\n" + " tokenId TEXT,\n" + " serviceId INTEGER,\n" + " serviceType TEXT,\n" + " serviceName TEXT,\n" + " serviceDisplayName TEXT,\n" + " customData TEXT,\n" + " customDataLen INTEGER,\n" + " bundleName TEXT,\n" + " moduleName TEXT,\n" + " abilityName TEXT,\n" + " authBoxType INTEGER,\n" + " authType INTEGER,\n" + " pinExchangeType INTEGER,\n" + " pinCode TEXT,\n" + " description TEXT,\n" + " serviceDicoveryScope TEXT,\n" + " extraInfo TEXT\n" + ")"; +const std::string CREATE_SERVICE_INFO_PROFILE_TABLE_UNIQUE_INDEX_SQL = + "CREATE UNIQUE INDEX IF NOT EXISTS unique_service_info_profile ON service_info_profile " + "(deviceId, userId, tokenId, serviceId)"; +const std::string SERVICE_INFO_PROFILE_UNIQUE_INDEX_EQUAL_CONDITION = + "deviceId = ? AND userId = ? AND tokenId = ? AND serviceId = ?"; +const std::string SELECT_SERVICE_INFO_PROFILE_ALL = + "SELECT * FROM service_info_profile;"; +const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID_SERVICEID = + "SELECT * FROM service_info_profile WHERE deviceId = ? AND userId = ? AND tokenId = ? AND serviceId = ?"; +const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID = + "SELECT * FROM service_info_profile WHERE deviceId = ? AND userId = ? AND tokenId = ?"; +const std::string SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_BUNDLENAME = + "SELECT * FROM service_info_profile WHERE deviceId = ? AND userId = ? AND bundleName = ?"; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index bdb4706d..518fd2fe 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -37,6 +37,7 @@ #include "permission_manager.h" #include "profile_cache.h" #include "profile_data_manager.h" +#include "service_info_profile_manager.h" #include "static_profile_manager.h" #include "static_capability_collector.h" #include "subscribe_profile_manager.h" @@ -118,6 +119,10 @@ int32_t DistributedDeviceProfileServiceNew::PostInit() HILOGE("StaticCapabilityCollector init failed"); return DP_CONTENT_SENSOR_MANAGER_INIT_FAIL; } + if (ServiceInfoProfileManager::GetInstance().Init() != DP_SUCCESS) { + HILOGE("ServiceInfoProfileManager init failed"); + return DP_SERVICE_INFO_PROFILE_MANAGER_INIT_FAIL; + } if (MultiUserManager::GetInstance().Init() != DP_SUCCESS) { HILOGE("MultiUserManager init failed"); return DP_MULTI_USER_MANAGER_INIT_FAIL; @@ -398,6 +403,89 @@ int32_t DistributedDeviceProfileServiceNew::PutServiceProfileBatch(const std::ve return ret; } +int32_t DistributedDeviceProfileServiceNew::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface PutServiceInfoProfile"); + int32_t ret = ServiceInfoProfileManager::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface DeleteServiceInfoProfile"); + int32_t ret = ServiceInfoProfileManager::GetInstance().DeleteServiceInfoProfile(key); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface UpdateServiceInfoProfile"); + int32_t ret = ServiceInfoProfileManager::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface GetServiceInfoProfileByUniqueKey"); + int32_t ret = ServiceInfoProfileManager::GetInstance().GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface GetServiceInfoProfileListByTokenId"); + int32_t ret = ServiceInfoProfileManager::GetInstance().GetServiceInfoProfileListByTokenId(key, + serviceInfoProfiles); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::GetAllServiceInfoProfileList( + std::vector& serviceInfoProfiles) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface GetAllServiceInfoProfileList"); + int32_t ret = ServiceInfoProfileManager::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles); + return ret; +} + +int32_t DistributedDeviceProfileServiceNew::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + if (!PermissionManager::GetInstance().CheckCallerPermission()) { + HILOGE("the caller is permission denied!"); + return DP_PERMISSION_DENIED; + } + HILOGD("CheckCallerPermission success interface GetServiceInfoProfileListByBundleName"); + int32_t ret = ServiceInfoProfileManager::GetInstance().GetServiceInfoProfileListByBundleName(key, + serviceInfoProfiles); + return ret; +} + int32_t DistributedDeviceProfileServiceNew::PutCharacteristicProfile(const CharacteristicProfile& charProfile) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { diff --git a/services/core/src/permissionmanager/permission_manager.cpp b/services/core/src/permissionmanager/permission_manager.cpp index e5305153..9656e195 100644 --- a/services/core/src/permissionmanager/permission_manager.cpp +++ b/services/core/src/permissionmanager/permission_manager.cpp @@ -102,6 +102,13 @@ int32_t PermissionManager::ParsePermissionJson(const cJSON* const permissionJson HILOGE("Permission json size is invalid!size: %{public}d!", size); return DP_PARSE_PERMISSION_JSON_FAIL; } + SetPermissionMap(permissionJson, PUT_SERVICE_INFO_PROFILE); + SetPermissionMap(permissionJson, DELETE_SERVICE_INFO_PROFILE); + SetPermissionMap(permissionJson, UPDATE_SERVICE_INFO_PROFILE); + SetPermissionMap(permissionJson, GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY); + SetPermissionMap(permissionJson, GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID); + SetPermissionMap(permissionJson, GET_ALL_SERVICE_INFO_PROFILE_LIST); + SetPermissionMap(permissionJson, GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME); SetPermissionMap(permissionJson, PUT_ACCESS_CONTROL_PROFILE); SetPermissionMap(permissionJson, UPDATE_ACCESS_CONTROL_PROFILE); SetPermissionMap(permissionJson, GET_ACCESS_CONTROL_PROFILE); diff --git a/services/core/src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp b/services/core/src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp index 99f7b780..68df1a32 100644 --- a/services/core/src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp +++ b/services/core/src/persistenceadapter/rdbadapter/profile_data_rdb_adapter.cpp @@ -223,8 +223,11 @@ int32_t ProfileDataRdbAdapter::GetRDBPtr() bool ProfileDataRdbAdapter::IsInit() { - if (store_ == nullptr) { - return false; + { + std::lock_guard lock(ProfileDataRdbAdapterMtx_); + if (store_ == nullptr) { + return false; + } } return true; } diff --git a/services/core/src/persistenceadapter/rdbadapter/service_info_rdb_adapter.cpp b/services/core/src/persistenceadapter/rdbadapter/service_info_rdb_adapter.cpp new file mode 100644 index 00000000..c8ffb903 --- /dev/null +++ b/services/core/src/persistenceadapter/rdbadapter/service_info_rdb_adapter.cpp @@ -0,0 +1,256 @@ +/* + * 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_rdb_adapter.h" + +#include +#include +#include + +#include "distributed_device_profile_constants.h" +#include "dp_services_constants.h" +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "rdb_errno.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(ServiceInfoRdbAdapter); +using namespace std::chrono_literals; +namespace { + const std::set TABLES = { + "service_info_profile" + }; + const std::string TAG = "ServiceInfoRdbAdapter"; +} + +int32_t ServiceInfoRdbAdapter::Init() +{ + int32_t retryTimes = RDB_INIT_MAX_TIMES; + while (retryTimes > 0) { + if (GetRDBPtr() == DP_SUCCESS) { + HILOGI("ServiceInfoRdbAdapter init success"); + return DP_SUCCESS; + } + usleep(RDB_INIT_INTERVAL_TIME); + retryTimes--; + } + HILOGE("ServiceInfoRdbAdapter init failed"); + return DP_RDBADAPTER_INIT_FAIL; +} + +int32_t ServiceInfoRdbAdapter::UnInit() +{ + HILOGI("ServiceInfoRdbAdapter unInit"); + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + store_ = nullptr; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoRdbAdapter::Put(int64_t& outRowId, const std::string& table, const ValuesBucket& values) +{ + if (TABLES.find(table) == TABLES.end()) { + HILOGE("table does not exist"); + return DP_RDBADAPTER_TABLE_NOT_EXIST; + } + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return DP_RDB_DB_PTR_NULL; + } + int32_t ret = store_->Insert(outRowId, table, values); + if (ret == E_SQLITE_CORRUPT) { + HILOGE("database corrupt ret:%{public}d", ret); + int32_t restoreRet = store_->Restore(""); + if (restoreRet != E_OK) { + HILOGE("Restore failed restoreRet:%{public}d", restoreRet); + return DP_RDB_DATABASE_RESTORE_FAIL; + } + ret = store_->Insert(outRowId, table, values); + } + if (ret != E_OK) { + HILOGE("ServiceInfoRdbAdapter put failed ret:%{public}d", ret); + return DP_RDBADAPTER_PUT_FAIL; + } + } + return DP_SUCCESS; +} + +int32_t ServiceInfoRdbAdapter::Delete(int32_t& deleteRows, const std::string& table, const std::string& whereClause, + const std::vector& bindArgs) +{ + if (TABLES.find(table) == TABLES.end()) { + HILOGE("table does not exist"); + return DP_RDBADAPTER_TABLE_NOT_EXIST; + } + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return DP_RDB_DB_PTR_NULL; + } + int32_t ret = store_->Delete(deleteRows, table, whereClause, bindArgs); + if (ret == E_SQLITE_CORRUPT) { + HILOGE("database corrupt ret:%{public}d", ret); + int32_t restoreRet = store_->Restore(""); + if (restoreRet != E_OK) { + HILOGE("Restore failed restoreRet:%{public}d", restoreRet); + return DP_RDB_DATABASE_RESTORE_FAIL; + } + ret = store_->Delete(deleteRows, table, whereClause, bindArgs); + } + if (ret != E_OK) { + HILOGE("ServiceInfoRdbAdapter delete failed ret:%{public}d", ret); + return DP_RDBADAPTER_DELETE_FAIL; + } + } + return DP_SUCCESS; +} + +int32_t ServiceInfoRdbAdapter::Update(int32_t& changedRows, const std::string& table, const ValuesBucket& values, + const std::string& whereClause, const std::vector& bindArgs) +{ + if (TABLES.find(table) == TABLES.end()) { + HILOGE("table does not exist"); + return DP_RDBADAPTER_TABLE_NOT_EXIST; + } + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return DP_RDB_DB_PTR_NULL; + } + int32_t ret = store_->Update(changedRows, table, values, whereClause, bindArgs); + if (ret == E_SQLITE_CORRUPT) { + HILOGE("database corrupt ret:%{public}d", ret); + int32_t restoreRet = store_->Restore(""); + if (restoreRet != E_OK) { + HILOGE("Restore failed restoreRet:%{public}d", restoreRet); + return DP_RDB_DATABASE_RESTORE_FAIL; + } + ret = store_->Update(changedRows, table, values, whereClause, bindArgs); + } + if (ret != E_OK) { + HILOGE("ServiceInfoRdbAdapter update failed ret:%{public}d", ret); + return DP_RDBADAPTER_UPDATE_FAIL; + } + } + return DP_SUCCESS; +} + +std::shared_ptr ServiceInfoRdbAdapter::Get(const std::string& sql, const std::vector& args) +{ + std::shared_ptr resultSet = nullptr; + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return nullptr; + } + resultSet = store_->QueryByStep(sql, args); + if (resultSet == nullptr) { + HILOGE("resultSet is null"); + return nullptr; + } + int32_t rowCount = ROWCOUNT_INIT; + int32_t ret = resultSet->GetRowCount(rowCount); + if (ret == E_SQLITE_CORRUPT) { + HILOGE("database corrupt ret:%{public}d", ret); + resultSet->Close(); + ret = store_->Restore(""); + if (ret != E_OK) { + HILOGE("Restore failed ret:%{public}d", ret); + return nullptr; + } + resultSet = store_->QueryByStep(sql, args); + } + } + return resultSet; +} + +int32_t ServiceInfoRdbAdapter::GetRDBPtr() +{ + int32_t version = RDB_VERSION; + ServiceInfoOpenCallback helper; + RdbStoreConfig config(SERVICE_INFO_PROFILE_RDB_PATH + SERVICE_INFO_PROFILE_DATABASE_NAME); + config.SetSecurityLevel(SecurityLevel::S2); + config.SetHaMode(HAMode::MAIN_REPLICA); + config.SetAllowRebuild(true); + int32_t errCode = E_OK; + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + store_ = RdbHelper::GetRdbStore(config, version, helper, errCode); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return DP_RDB_DB_PTR_NULL; + } + NativeRdb::RebuiltType rebuiltType = NativeRdb::RebuiltType::NONE; + errCode = store_->GetRebuilt(rebuiltType); + if (errCode != E_OK) { + HILOGE("getRDBPtr failed errCode:%{public}d", errCode); + return DP_GET_RDBSTORE_FAIL; + } + if (rebuiltType == NativeRdb::RebuiltType::REBUILT) { + HILOGE("database corrupt"); + int32_t restoreRet = store_->Restore(""); + if (restoreRet != E_OK) { + HILOGE("Restore failed restoreRet:%{public}d", restoreRet); + return DP_RDB_DATABASE_RESTORE_FAIL; + } + } + } + return DP_SUCCESS; +} + +bool ServiceInfoRdbAdapter::IsInit() +{ + if (store_ == nullptr) { + return false; + } + return true; +} + +int32_t ServiceInfoRdbAdapter::CreateTable(const std::string& sql) +{ + { + std::lock_guard lock(ServiceInfoRdbAdapterMtx_); + if (store_ == nullptr) { + HILOGE("RDBStore_ is null"); + return DP_RDB_DB_PTR_NULL; + } + if (store_->ExecuteSql(sql) != E_OK) { + HILOGE("ServiceInfoRdbAdapter create table failed"); + return DP_RDBADAPTER_TABLE_NOT_EXIST; + } + } + return DP_SUCCESS; +} + +int32_t ServiceInfoOpenCallback::OnCreate(RdbStore& store) +{ + HILOGI("rdbStore create"); + return NativeRdb::E_OK; +} + +int32_t ServiceInfoOpenCallback::OnUpgrade(RdbStore& store, int oldVersion, int newVersion) +{ + HILOGI("rdbStore upgrade"); + return NativeRdb::E_OK; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS diff --git a/services/core/src/profiledatamanager/characteristic_profile_dao.cpp b/services/core/src/profiledatamanager/characteristic_profile_dao.cpp index 17fc4c0f..471da118 100644 --- a/services/core/src/profiledatamanager/characteristic_profile_dao.cpp +++ b/services/core/src/profiledatamanager/characteristic_profile_dao.cpp @@ -35,7 +35,7 @@ namespace { int32_t CharacteristicProfileDao::Init() { - int32_t ret; + int32_t ret = RET_INIT; if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { ret = ProfileDataRdbAdapter::GetInstance().Init(); if (ret != DP_SUCCESS) { diff --git a/services/core/src/profiledatamanager/device_icon_info_dao.cpp b/services/core/src/profiledatamanager/device_icon_info_dao.cpp index b0164280..6f22024c 100644 --- a/services/core/src/profiledatamanager/device_icon_info_dao.cpp +++ b/services/core/src/profiledatamanager/device_icon_info_dao.cpp @@ -31,7 +31,7 @@ namespace { int32_t DeviceIconInfoDao::Init() { std::lock_guard lock(rdbMutex_); - int32_t ret; + int32_t ret = RET_INIT; if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { ret = ProfileDataRdbAdapter::GetInstance().Init(); if (ret != DP_SUCCESS) { diff --git a/services/core/src/profiledatamanager/device_profile_dao.cpp b/services/core/src/profiledatamanager/device_profile_dao.cpp index 2f34521c..f274e45e 100644 --- a/services/core/src/profiledatamanager/device_profile_dao.cpp +++ b/services/core/src/profiledatamanager/device_profile_dao.cpp @@ -33,7 +33,7 @@ namespace { int32_t DeviceProfileDao::Init() { std::lock_guard lock(rdbMutex_); - int32_t ret; + int32_t ret = RET_INIT; if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { ret = ProfileDataRdbAdapter::GetInstance().Init(); if (ret != DP_SUCCESS) { diff --git a/services/core/src/profiledatamanager/product_info_dao.cpp b/services/core/src/profiledatamanager/product_info_dao.cpp index 2d001692..e5098e94 100644 --- a/services/core/src/profiledatamanager/product_info_dao.cpp +++ b/services/core/src/profiledatamanager/product_info_dao.cpp @@ -31,7 +31,7 @@ namespace { int32_t ProductInfoDao::Init() { std::lock_guard lock(rdbMutex_); - int32_t ret; + int32_t ret = RET_INIT; if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { ret = ProfileDataRdbAdapter::GetInstance().Init(); if (ret != DP_SUCCESS) { diff --git a/services/core/src/serviceinfoprofile_manager/service_info_profile_manager.cpp b/services/core/src/serviceinfoprofile_manager/service_info_profile_manager.cpp new file mode 100644 index 00000000..3eb0f6a9 --- /dev/null +++ b/services/core/src/serviceinfoprofile_manager/service_info_profile_manager.cpp @@ -0,0 +1,377 @@ +/* + * 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_manager.h" + +#include "distributed_device_profile_constants.h" +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "dp_services_constants.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(ServiceInfoProfileManager) + +namespace { +const std::string TAG = "ServiceInfoProfileManager"; +} + +int32_t ServiceInfoProfileManager::Init() +{ + int32_t ret = ServiceInfoRdbAdapter::GetInstance().Init(); + if (ret != DP_SUCCESS) { + HILOGE("ServiceInfoRdbAdapter Init failed"); + return DP_INIT_DB_FAILED; + } + CreateTable(); + CreateIndex(); + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::UnInit() +{ + int32_t ret = ServiceInfoRdbAdapter::GetInstance().UnInit(); + if (ret != DP_SUCCESS) { + HILOGE("ServiceInfoRdbAdapter UnInit failed"); + return DP_UNINIT_FAIL; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::CreateTable() +{ + int32_t ret = ServiceInfoRdbAdapter::GetInstance().CreateTable(CREATE_SERVICE_INFO_PROFILE_TABLE_SQL); + if (ret != DP_SUCCESS) { + HILOGE("service_info_profile create failed"); + return DP_CREATE_TABLE_FAIL; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::CreateIndex() +{ + int32_t ret = ServiceInfoRdbAdapter::GetInstance().CreateTable( + CREATE_SERVICE_INFO_PROFILE_TABLE_UNIQUE_INDEX_SQL); + if (ret != DP_SUCCESS) { + HILOGE("service_info_profile unique index create failed"); + return DP_CREATE_UNIQUE_INDEX_FAIL; + } + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + if (serviceInfoProfile.GetDeviceId().empty() || serviceInfoProfile.GetUserId() == DEFAULT_USER_ID || + serviceInfoProfile.GetTokenId().empty() || serviceInfoProfile.GetServiceId() == DEFAULT_USER_ID) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + ValuesBucket values; + ServiceInfoProfileToEntries(serviceInfoProfile, values); + int64_t rowId = ROWID_INIT; + int32_t ret = RET_INIT; + ServiceInfoUniqueKey key; + ServiceInfoProfile oldSerInfo; + key.SetDeviceId(serviceInfoProfile.GetDeviceId()); + key.SetUserId(serviceInfoProfile.GetUserId()); + key.SetTokenId(serviceInfoProfile.GetTokenId()); + key.SetServiceId(serviceInfoProfile.GetServiceId()); + int32_t getRet = GetServiceInfoProfileByUniqueKey(key, oldSerInfo); + if (getRet == DP_SUCCESS) { + HILOGI("serviceInfoProfile already exit"); + return DP_SUCCESS; + } + ret = ServiceInfoRdbAdapter::GetInstance().Put(rowId, SERVICE_INFO_PROFILE_TABLE, values); + if (ret != DP_SUCCESS) { + HILOGE("%{public}s insert failed", SERVICE_INFO_PROFILE_TABLE.c_str()); + return DP_PUT_SERVICE_INFO_PROFILE_FAIL; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + if (key.GetDeviceId().empty() || key.GetUserId() == DEFAULT_USER_ID || + key.GetTokenId().empty() || key.GetServiceId() == DEFAULT_SERVICE_ID) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + ServiceInfoProfile oldServiceInfo; + int32_t getRet = GetServiceInfoProfileByUniqueKey(key, oldServiceInfo); + if (getRet == DP_NOT_FIND_DATA) { + HILOGI("ServiceInfoProfile not exit, doesn't need delete"); + return DP_SUCCESS; + } + if (getRet != DP_SUCCESS) { + HILOGE("GetServiceInfoProfile filed"); + return getRet; + } + int32_t deleteRows = DELETEROWS_INIT; + int32_t ret = ServiceInfoRdbAdapter::GetInstance().Delete(deleteRows, SERVICE_INFO_PROFILE_TABLE, + SERVICE_INFO_PROFILE_UNIQUE_INDEX_EQUAL_CONDITION, + std::vector{ValueObject(key.GetDeviceId()), ValueObject(key.GetUserId()), + ValueObject(key.GetTokenId()), ValueObject(key.GetServiceId())}); + if (ret != DP_SUCCESS) { + HILOGE("delete %{public}s data failed", SERVICE_INFO_PROFILE_TABLE.c_str()); + return DP_DELETE_SERVICE_INFO_PROFILE_FAIL; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + if (serviceInfoProfile.GetDeviceId().empty() || serviceInfoProfile.GetUserId() == DEFAULT_USER_ID || + serviceInfoProfile.GetTokenId().empty() || serviceInfoProfile.GetServiceId() == DEFAULT_SERVICE_ID) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + ServiceInfoUniqueKey key; + ServiceInfoProfile serInfo; + key.SetDeviceId(serviceInfoProfile.GetDeviceId()); + key.SetUserId(serviceInfoProfile.GetUserId()); + key.SetTokenId(serviceInfoProfile.GetTokenId()); + key.SetServiceId(serviceInfoProfile.GetServiceId()); + int32_t getRet = GetServiceInfoProfileByUniqueKey(key, serInfo); + if (getRet == DP_NOT_FIND_DATA) { + HILOGE("serviceInfoProfile not exit, can't update"); + return getRet; + } + if (getRet != DP_SUCCESS) { + HILOGI("GetServiceInfoProfileByUniqueKey failed"); + return getRet; + } + ValuesBucket values; + ServiceInfoProfileToEntries(serviceInfoProfile, values); + int32_t changeRowCnt = CHANGEROWCNT_INIT; + int32_t ret = ServiceInfoRdbAdapter::GetInstance().Update(changeRowCnt, SERVICE_INFO_PROFILE_TABLE, values, + SERVICE_INFO_PROFILE_UNIQUE_INDEX_EQUAL_CONDITION, + std::vector{ValueObject(serviceInfoProfile.GetDeviceId()), + ValueObject(serviceInfoProfile.GetUserId()), + ValueObject(serviceInfoProfile.GetTokenId()), + ValueObject(serviceInfoProfile.GetServiceId())}); + if (ret != DP_SUCCESS) { + HILOGE("Update %{public}s table failed", SERVICE_INFO_PROFILE_TABLE.c_str()); + return DP_UPDATE_SERVICE_INFO_PROFILE_FAIL; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + if (key.GetDeviceId().empty() || key.GetUserId() == DEFAULT_USER_ID || + key.GetTokenId().empty() || key.GetServiceId() == DEFAULT_SERVICE_ID) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + std::vector condition; + condition.emplace_back(ValueObject(key.GetDeviceId())); + condition.emplace_back(ValueObject(key.GetUserId())); + condition.emplace_back(ValueObject(key.GetTokenId())); + condition.emplace_back(ValueObject(key.GetServiceId())); + std::shared_ptr resultSet = ServiceInfoRdbAdapter::GetInstance().Get( + SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID_SERVICEID, condition); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + if (rowCount == 0) { + HILOGE("by condition not find data"); + resultSet->Close(); + return DP_NOT_FIND_DATA; + } + int32_t ret = resultSet->GoToNextRow(); + if (ret != DP_SUCCESS) { + HILOGE("get ServiceInfoProfileResult failed"); + resultSet->Close(); + return DP_NOT_FIND_DATA; + } + ConvertToServiceInfo(resultSet, serviceInfoProfile); + resultSet->Close(); + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + if (key.GetDeviceId().empty() || key.GetUserId() == DEFAULT_USER_ID || key.GetTokenId().empty()) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + std::vector condition; + condition.emplace_back(ValueObject(key.GetDeviceId())); + condition.emplace_back(ValueObject(key.GetUserId())); + condition.emplace_back(ValueObject(key.GetTokenId())); + std::shared_ptr resultSet = ServiceInfoRdbAdapter::GetInstance().Get( + SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_TOKENID, condition); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + if (rowCount == 0) { + HILOGE("by condition not find data"); + resultSet->Close(); + return DP_NOT_FIND_DATA; + } + while (resultSet->GoToNextRow() == DP_SUCCESS) { + ServiceInfoProfile serviceInfoProfile; + ConvertToServiceInfo(resultSet, serviceInfoProfile); + serviceInfoProfiles.emplace_back(serviceInfoProfile); + } + resultSet->Close(); + if (serviceInfoProfiles.empty()) { + return DP_NOT_FIND_DATA; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) +{ + std::vector condition; + std::shared_ptr resultSet = ServiceInfoRdbAdapter::GetInstance().Get( + SELECT_SERVICE_INFO_PROFILE_ALL, condition); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + if (rowCount == 0) { + HILOGE("by condition not find data"); + resultSet->Close(); + return DP_NOT_FIND_DATA; + } + while (resultSet->GoToNextRow() == DP_SUCCESS) { + ServiceInfoProfile serviceInfoProfile; + ConvertToServiceInfo(resultSet, serviceInfoProfile); + serviceInfoProfiles.emplace_back(serviceInfoProfile); + } + resultSet->Close(); + if (serviceInfoProfiles.empty()) { + return DP_NOT_FIND_DATA; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + if (key.GetDeviceId().empty() || key.GetUserId() == DEFAULT_USER_ID || key.GetBundleName().empty()) { + HILOGE("Invalid parameter"); + return DP_INVALID_PARAM; + } + std::vector condition; + condition.emplace_back(ValueObject(key.GetDeviceId())); + condition.emplace_back(ValueObject(key.GetUserId())); + condition.emplace_back(ValueObject(key.GetBundleName())); + std::shared_ptr resultSet = ServiceInfoRdbAdapter::GetInstance().Get( + SELECT_SERVICE_INFO_PROFILE_TABLE_WHERE_DEVID_USERID_BUNDLENAME, condition); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + int32_t rowCount = ROWCOUNT_INIT; + resultSet->GetRowCount(rowCount); + if (rowCount == 0) { + HILOGE("by condition not find data"); + resultSet->Close(); + return DP_NOT_FIND_DATA; + } + while (resultSet->GoToNextRow() == DP_SUCCESS) { + ServiceInfoProfile serviceInfoProfile; + ConvertToServiceInfo(resultSet, serviceInfoProfile); + serviceInfoProfiles.emplace_back(serviceInfoProfile); + } + resultSet->Close(); + if (serviceInfoProfiles.empty()) { + return DP_NOT_FIND_DATA; + } + HILOGI("end!"); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::ConvertToServiceInfo(std::shared_ptr resultSet, + ServiceInfoProfile& serviceInfo) +{ + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return DP_GET_RESULTSET_FAIL; + } + RowEntity rowEntity; + if (resultSet->GetRow(rowEntity) != DP_SUCCESS) { + HILOGE("get resultSet failed"); + return DP_GET_RESULTSET_FAIL; + } + serviceInfo.SetDeviceId(rowEntity.Get(DEVICE_ID)); + serviceInfo.SetUserId(rowEntity.Get(USERID)); + serviceInfo.SetNetworkId(rowEntity.Get(SRNETWORK_ID)); + serviceInfo.SetTokenId(rowEntity.Get(TOKENID)); + serviceInfo.SetServiceId(rowEntity.Get(SISERVICE_ID)); + serviceInfo.SetServiceType(rowEntity.Get(SERVICE_TYPE)); + serviceInfo.SetServiceName(rowEntity.Get(SERVICE_NAME)); + serviceInfo.SetServiceDisplayName(rowEntity.Get(SERVICE_DISPLAY_NAME)); + serviceInfo.SetCustomData(rowEntity.Get(CUSTOM_DATA)); + serviceInfo.SetCustomDataLen(rowEntity.Get(CUSTOM_DATA_LEN)); + serviceInfo.SetBundleName(rowEntity.Get(BUNDLE_NAME)); + serviceInfo.SetModuleName(rowEntity.Get(MODULE_NAME)); + serviceInfo.SetAbilityName(rowEntity.Get(ABILITY_NAME)); + serviceInfo.SetAuthBoxType(rowEntity.Get(AUTH_BOX_TYPE)); + serviceInfo.SetAuthType(rowEntity.Get(AUTH_TYPE)); + serviceInfo.SetPinExchangeType(rowEntity.Get(PIN_EXCHANGE_TYPE)); + serviceInfo.SetPinCode(rowEntity.Get(PINCODE)); + serviceInfo.SetDescription(rowEntity.Get(DESCRIPTION)); + serviceInfo.SetServiceDicoveryScope(rowEntity.Get(SERVICE_DISCOVERY_SCOPE)); + serviceInfo.SetExtraInfo(rowEntity.Get(EXTRAINFO)); + return DP_SUCCESS; +} + +int32_t ServiceInfoProfileManager::ServiceInfoProfileToEntries(const ServiceInfoProfile& serviceInfo, + ValuesBucket& values) +{ + values.PutString(DEVICE_ID, serviceInfo.GetDeviceId()); + values.PutInt(USERID, serviceInfo.GetUserId()); + values.PutString(SRNETWORK_ID, serviceInfo.GetNetworkId()); + values.PutString(TOKENID, serviceInfo.GetTokenId()); + values.PutLong(SISERVICE_ID, serviceInfo.GetServiceId()); + values.PutString(SERVICE_TYPE, serviceInfo.GetServiceType()); + values.PutString(SERVICE_NAME, serviceInfo.GetServiceName()); + values.PutString(SERVICE_DISPLAY_NAME, serviceInfo.GetServiceDisplayName()); + values.PutString(CUSTOM_DATA, serviceInfo.GetCustomData()); + values.PutInt(CUSTOM_DATA_LEN, serviceInfo.GetCustomDataLen()); + values.PutString(BUNDLE_NAME, serviceInfo.GetBundleName()); + values.PutString(MODULE_NAME, serviceInfo.GetModuleName()); + values.PutString(ABILITY_NAME, serviceInfo.GetAbilityName()); + values.PutInt(AUTH_BOX_TYPE, serviceInfo.GetAuthBoxType()); + values.PutInt(AUTH_TYPE, serviceInfo.GetAuthType()); + values.PutInt(PIN_EXCHANGE_TYPE, serviceInfo.GetPinExchangeType()); + values.PutString(PINCODE, serviceInfo.GetPinCode()); + values.PutString(DESCRIPTION, serviceInfo.GetDescription()); + values.PutString(SERVICE_DISCOVERY_SCOPE, serviceInfo.GetServiceDicoveryScope()); + values.PutString(EXTRAINFO, serviceInfo.GetExtraInfo()); + return DP_SUCCESS; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS diff --git a/services/core/src/trustprofilemanager/trust_profile_manager.cpp b/services/core/src/trustprofilemanager/trust_profile_manager.cpp index ec2c58a4..08e52a65 100644 --- a/services/core/src/trustprofilemanager/trust_profile_manager.cpp +++ b/services/core/src/trustprofilemanager/trust_profile_manager.cpp @@ -1940,6 +1940,10 @@ bool TrustProfileManager::CheckUserIdExists(int64_t accesserId, int64_t accessee GetResultSet(SELECT_ACCESSEE_TABLE_WHERE_ACCESSEEID_AND_DEVICEID_AND_USERID, std::vector{ ValueObject(accesseeId), ValueObject(localDeviceId), ValueObject(localUserId) }); + if (accesseeResultSet == nullptr) { + HILOGE("accesseeResultSet is nullptr"); + return false; + } int32_t aceeRowCount = ROWCOUNT_INIT; accesseeResultSet->GetRowCount(aceeRowCount); accesseeResultSet->Close(); 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 45d06bc3..add5d270 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 @@ -71,6 +71,16 @@ class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubN int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, std::vector& deviceIconInfos) override; + int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; + int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) override; + int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; + int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; + int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) override; void DelayUnloadTask() override; bool IsInited() override; }; @@ -297,6 +307,52 @@ int32_t MockDistributedDeviceProfileStubNew::GetDeviceIconInfos(const DeviceIcon return 0; } +int32_t MockDistributedDeviceProfileStubNew::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + (void)serviceInfoProfile; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + (void)key; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + (void)serviceInfoProfile; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + (void)key; + (void)serviceInfoProfile; + return 0; +} + +int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + (void)key; + (void)serviceInfoProfiles; + return 0; +} +int32_t MockDistributedDeviceProfileStubNew::GetAllServiceInfoProfileList( + std::vector& serviceInfoProfiles) +{ + (void)serviceInfoProfiles; + return 0; +} +int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + (void)key; + (void)serviceInfoProfiles; + return 0; +} /** * @tc.name: IsInterfaceTokenValid001 * @tc.desc: IsInterfaceTokenValid -- Gitee