diff --git a/services/core/include/datashare/settings_data_manager.h b/services/core/include/datashare/settings_data_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..73953d1bf8450f28e42c3d27102d9744278fad43 --- /dev/null +++ b/services/core/include/datashare/settings_data_manager.h @@ -0,0 +1,57 @@ +/* + * 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_SETTINGS_DATA_CONNECTOR_H +#define OHOS_DP_SETTINGS_DATA_CONNECTOR_H + +#include +#include +#include +#include + +#include "datashare_helper.h" + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +class SettingsDataManager { + DECLARE_SINGLE_INSTANCE(SettingsDataManager); +public: + int32_t Init(); + int32_t UnInit(); + + int32_t GetUserDefinedDeviceName(int32_t userId, std::string &deviceName); + int32_t SetUserDefinedDeviceName(const std::string &deviceName, int32_t userId); + int32_t GetDisplayDeviceName(int32_t userId, std::string &deviceName); + int32_t SetDisplayDeviceName(const std::string &deviceName, int32_t userId); + int32_t GetDeviceName(std::string &deviceName); +private: + int32_t GetValue(const std::string &tableName, int32_t userId, const std::string &key, std::string &value); + int32_t SetValue(const std::string &tableName, int32_t userId, const std::string &key, const std::string &value); + + std::string GetProxyUriStr(const std::string &tableName, int32_t userId); + std::shared_ptr CreateDataShareHelper(const std::string &proxyUri); + Uri MakeUri(const std::string &proxyUri, const std::string &key); + bool ReleaseDataShareHelper(std::shared_ptr helper); + + sptr GetRemoteObj(); + +private: + std::mutex remoteObjMtx_; + sptr remoteObj_; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS +#endif // OHOS_DP_SETTINGS_DATA_CONNECTOR_H diff --git a/services/core/include/profiledatamanager/profile_data_manager.h b/services/core/include/profiledatamanager/profile_data_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..872d24c9955cad35bb24c51eb067a5283b669f6b --- /dev/null +++ b/services/core/include/profiledatamanager/profile_data_manager.h @@ -0,0 +1,53 @@ +/* + * 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_PROFILE_DATA_MANAGER_H +#define OHOS_DP_PROFILE_DATA_MANAGER_H + +#include + +#include "kvstore_observer.h" + +#include "device_icon_info.h" +#include "device_icon_info_filter_options.h" +#include "device_profile.h" +#include "device_profile_dao.h" +#include "product_info.h" +#include "single_instance.h" +namespace OHOS { +namespace DistributedDeviceProfile { +class ProfileDataManager { + DECLARE_SINGLE_INSTANCE(ProfileDataManager); +public: + int32_t Init(); + int32_t UnInit(); + + int32_t PutDeviceProfileBatch(std::vector& deviceProfiles); + int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, + std::vector& deviceProfiles); + int32_t PutProductInfoBatch(const std::vector& productInfos); + int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos); + int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, + std::vector& deviceIconInfos); + + int32_t PutDeviceProfile(DeviceProfile deviceProfile); +private: + bool FilterInvaildSymbol(std::string str); + int32_t PutDeviceIconInfo(const DeviceIconInfo& deviceIconInfo); + int32_t PutProductInfo(const ProductInfo& productInfo); +}; +} // DistributedDeviceProfile +} // OHOS +#endif // OHOS_DP_PROFILE_DATA_MANAGER_H diff --git a/services/core/src/datashare/settings_data_manager.cpp b/services/core/src/datashare/settings_data_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..548ce6d914bff242ede389088de8e24ecbae964a --- /dev/null +++ b/services/core/src/datashare/settings_data_manager.cpp @@ -0,0 +1,213 @@ +/* + * 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 "settings_data_manager.h" + +#include "iservice_registry.h" +#include "system_ability_definition.h" + +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(SettingsDataManager) +namespace { +const std::string TAG = "SettingsDataManager"; +constexpr int32_t USERID_HELPER_NUMBER = 100; +const std::string SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/"; +const std::string SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; +const std::string URI_PROXY_SUFFIX = "?Proxy=true"; +// global uri : datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true +const std::string SETTINGSDATA_GLOBAL = "SETTINGSDATA"; +const std::string SETTINGS_GENERAL_DEVICE_NAME = "settings.general.device_name"; // SETTINGSDATA +// system uri : datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_{userId}?Proxy=true +const std::string SETTINGSDATA_SYSTEM = "USER_SETTINGSDATA_"; +// secure uri : datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_{userId}?Proxy=true +const std::string SETTINGSDATA_SECURE = "USER_SETTINGSDATA_SECURE_"; +const std::string SETTINGS_GENERAL_DISPLAY_DEVICE_NAME = "settings.general.display_device_name"; +const std::string SETTINGS_GENERAL_USER_DEFINED_DEVICE_NAME = "settings.general.user_defined_device_name"; + +const std::string SETTING_COLUMN_VALUE = "VALUE"; +const std::string SETTING_COLUMN_KEYWORD = "KEYWORD"; +} + +int32_t SettingsDataManager::Init() +{ + GetRemoteObj(); + return DP_SUCCESS; +} + +int32_t SettingsDataManager::UnInit() +{ + std::lock_guard lock(remoteObjMtx_); + remoteObj_ = nullptr; + return DP_SUCCESS; +} + +int32_t SettingsDataManager::GetUserDefinedDeviceName(int32_t userId, std::string &deviceName) +{ + return GetValue(SETTINGSDATA_SECURE, userId, SETTINGS_GENERAL_USER_DEFINED_DEVICE_NAME, deviceName); +} + +int32_t SettingsDataManager::SetUserDefinedDeviceName(const std::string &deviceName, int32_t userId) +{ + return SetValue(SETTINGSDATA_SECURE, userId, SETTINGS_GENERAL_USER_DEFINED_DEVICE_NAME, deviceName); +} + +int32_t SettingsDataManager::GetDisplayDeviceName(int32_t userId, std::string &deviceName) +{ + return GetValue(SETTINGSDATA_SECURE, userId, SETTINGS_GENERAL_DISPLAY_DEVICE_NAME, deviceName); +} + +int32_t SettingsDataManager::SetDisplayDeviceName(const std::string &deviceName, int32_t userId) +{ + return SetValue(SETTINGSDATA_SECURE, userId, SETTINGS_GENERAL_DISPLAY_DEVICE_NAME, deviceName); +} + +int32_t SettingsDataManager::GetDeviceName(std::string &deviceName) +{ + return GetValue(SETTINGSDATA_GLOBAL, 0, SETTINGS_GENERAL_DEVICE_NAME, deviceName); +} + +sptr SettingsDataManager::GetRemoteObj() +{ + std::lock_guard lock(remoteObjMtx_); + if (remoteObj_ != nullptr) { + return remoteObj_; + } + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + HILOGE("get sa manager return nullptr"); + return nullptr; + } + auto remoteObj = samgr->GetSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID ); + if (remoteObj == nullptr) { + HILOGE("get system ability failed, id=%{public}d", DISTRIBUTED_DEVICE_PROFILE_SA_ID ); + return nullptr; + } + remoteObj_ = remoteObj; + return remoteObj_; +} + +int32_t SettingsDataManager::GetValue(const std::string &tableName, int32_t userId, + const std::string &key, std::string &value) +{ + std::string proxyUri = GetProxyUriStr(tableName, userId); + auto helper = CreateDataShareHelper(proxyUri); + if (helper == nullptr) { + HILOGE("helper is nullptr"); + return DP_NULLPTR; + } + std::vector columns = { SETTING_COLUMN_VALUE }; + DataShare::DataSharePredicates predicates; + predicates.EqualTo(SETTING_COLUMN_KEYWORD, key); + Uri uri = MakeUri(proxyUri, key); + auto resultSet = helper->Query(uri, predicates, columns); + ReleaseDataShareHelper(helper); + if (resultSet == nullptr) { + HILOGE("Query failed key=%{public}s", key.c_str()); + return DP_NULLPTR; + } + int32_t count; + resultSet->GetRowCount(count); + if (count == 0) { + HILOGW("no value, key=%{public}s", key.c_str()); + resultSet->Close(); + return DP_SUCCESS; + } + int32_t index = 0; + resultSet->GoToRow(index); + int32_t ret = resultSet->GetString(index, value); + if (ret != DataShare::E_OK) { + HILOGE("get value failed, ret=%{public}d", ret); + resultSet->Close(); + return ret; + } + resultSet->Close(); + return DP_SUCCESS; +} + +int32_t SettingsDataManager::SetValue(const std::string &tableName, int32_t userId, + const std::string &key, const std::string &value) +{ + std::string proxyUri = GetProxyUriStr(tableName, userId); + auto helper = CreateDataShareHelper(proxyUri); + if (helper == nullptr) { + HILOGE("helper is nullptr"); + return DP_NULLPTR; + } + + DataShare::DataShareValuesBucket val; + val.Put(SETTING_COLUMN_KEYWORD, key); + val.Put(SETTING_COLUMN_VALUE, value); + Uri uri = MakeUri(proxyUri, key); + DataShare::DataSharePredicates predicates; + predicates.EqualTo(SETTING_COLUMN_KEYWORD, key); + int ret = helper->Update(uri, predicates, val); + if (ret <= 0) { + HILOGW("Update failed, ret=%{public}d", ret); + ret = helper->Insert(uri, val); + } + ReleaseDataShareHelper(helper); + if (ret <= 0) { + HILOGE("set value failed, ret=%{public}d", ret); + return ret; + } + return ret; +} + +std::shared_ptr SettingsDataManager::CreateDataShareHelper(const std::string &proxyUri) +{ + auto [ret, helper] = DataShare::DataShareHelper::Create(GetRemoteObj(), proxyUri, SETTINGS_DATA_EXT_URI); + if (ret != 0) { + HILOGE("create helper failed ret %{public}d", ret); + return nullptr; + } + return helper; +} + +std::string SettingsDataManager::GetProxyUriStr(const std::string &tableName, int32_t userId) +{ + if (userId < USERID_HELPER_NUMBER) { + userId = USERID_HELPER_NUMBER; + } + if (tableName == SETTINGSDATA_GLOBAL) { + return SETTING_URI_PROXY + SETTINGSDATA_GLOBAL + URI_PROXY_SUFFIX; + } else { + return SETTING_URI_PROXY + tableName + std::to_string(userId) + URI_PROXY_SUFFIX; + } +} + +Uri SettingsDataManager::MakeUri(const std::string &proxyUri, const std::string &key) +{ + Uri uri(proxyUri + "&key=" + key); + return uri; +} + +bool SettingsDataManager::ReleaseDataShareHelper(std::shared_ptr helper) +{ + if (helper == nullptr) { + HILOGE("helper is nullptr"); + return false; + } + if (!helper->Release()) { + HILOGE("release helper fail"); + return false; + } + return true; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS diff --git a/services/core/src/profiledatamanager/profile_data_manager.cpp b/services/core/src/profiledatamanager/profile_data_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dacbcf35293b0fab01da0a9277beb6ae6a4fac0c --- /dev/null +++ b/services/core/src/profiledatamanager/profile_data_manager.cpp @@ -0,0 +1,279 @@ +/* + * 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 "profile_data_manager.h" + +#include "device_profile_manager.h" +#include "device_icon_info_dao.h" +#include "distributed_device_profile_constants.h" +#include "distributed_device_profile_errors.h" +#include "distributed_device_profile_log.h" +#include "multi_user_manager.h" +#include "product_info_dao.h" +#include "profile_cache.h" +#include "profile_utils.h" +#include "settings_data_manager.h" +#include "content_sensor_manager_utils.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +IMPLEMENT_SINGLE_INSTANCE(ProfileDataManager) + +namespace { +const std::string TAG = "ProfileDataManager"; +} + +int32_t ProfileDataManager::Init() +{ + if (DeviceProfileDao::GetInstance().Init() != DP_SUCCESS) { + HILOGE("DeviceProfileDao init failed"); + return DP_DEVICE_PROFILE_DAO_INIT_FAIL; + } + if (ProductInfoDao::GetInstance().Init() != DP_SUCCESS) { + HILOGE("ProductInfoDao init failed"); + return DP_PRODUCT_INFO_DAO_INIT_FAIL; + } + if (DeviceIconInfoDao::GetInstance().Init() != DP_SUCCESS) { + HILOGE("DeviceIconInfoDao init failed"); + return DP_DEVICE_ICON_INFO_DAO_INIT_FAIL; + } + if (SettingsDataManager::GetInstance().Init() != DP_SUCCESS) { + HILOGE("SettingsDataManager init failed"); + return DP_SETTINGSDATA_MANAGER_INIT_FAIL; + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::UnInit() +{ + if (DeviceProfileDao::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("DeviceProfileDao unInit failed"); + return DP_DEVICE_PROFILE_DAO_UNINIT_FAIL; + } + if (ProductInfoDao::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("ProductInfoDao unInit failed"); + return DP_PRODUCT_INFO_DAO_UNINIT_FAIL; + } + if (DeviceIconInfoDao::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("DeviceIconInfoDao unInit failed"); + return DP_DEVICE_ICON_INFO_DAO_UNINIT_FAIL; + } + if (SettingsDataManager::GetInstance().UnInit() != DP_SUCCESS) { + HILOGE("SettingsDataManager unInit failed"); + return DP_SETTINGSDATA_MANAGER_UNINIT_FAIL; + } + return 0; +} + +int32_t ProfileDataManager::PutDeviceProfile(DeviceProfile deviceProfile) +{ + if (deviceProfile.GetDeviceId().empty() || ProfileDataManager::FilterInvaildSymbol(deviceProfile.GetDeviceId())) { + HILOGE("deviceId invaild,deviceId=%{public}s", + ProfileUtils::GetAnonyString(deviceProfile.GetDeviceId()).c_str()); + } + if (deviceProfile.GetDeviceId() == ProfileCache::GetInstance().GetLocalUdid()) { + deviceProfile.SetUserId(MultiUserManager::GetInstance().GetCurrentForegroundUserID()); + } else { + deviceProfile.SetUserId(0); + } + deviceProfile.SetAccountId(ProfileCache::GetInstance().GetLocalAccountId()); + DeviceProfileFilterOptions filterOptions; + filterOptions.AddDeviceIds(deviceProfile.GetDeviceId()); + filterOptions.SetUserId(deviceProfile.GetUserId()); + filterOptions.SetAccountId(deviceProfile.GetAccountId()); + std::vector oldDeviceProfiles; + int32_t ret = RET_INIT; + ret = DeviceProfileDao::GetInstance().GetDeviceProfiles(filterOptions, oldDeviceProfiles); + if ((ret != DP_SUCCESS) && (ret != DP_NOT_FIND_DATA)) { + HILOGE("GetDeviceProfiles failed,ret=%{public}d", ret); + return ret; + } + if (oldDeviceProfiles.empty()) { + HILOGI("oldDeviceProfiles is mepty"); + deviceProfile.SetId(DEFAULT_ID); + } else { + DeviceProfile oldDeviceProfile = oldDeviceProfiles[0]; + deviceProfile.SetId(oldDeviceProfile.GetId()); + } + if (deviceProfile.GetId() <= 0) { + ret = DeviceProfileDao::GetInstance().PutDeviceProfile(deviceProfile); + } else { + ret = DeviceProfileDao::GetInstance().UpdateDeviceProfile(deviceProfile); + } + if (ret != DP_SUCCESS) { + HILOGE("PutDeviceProfile failed,ret=%{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +bool ProfileDataManager::FilterInvaildSymbol(std::string str) +{ + if (str.length() == 0 || str.length() > MAX_STRING_LEN) { + return false; + } + size_t found = str.find(SEPARATOR); + if (found == std::string::npos) { + return false; + } + size_t foundSlashes = str.find(SLASHES); + if (foundSlashes == std::string::npos) { + return false; + } + return true; +} + +int32_t ProfileDataManager::PutDeviceProfileBatch(std::vector& deviceProfiles) +{ + if (deviceProfiles.empty()) { + HILOGE("deviceProfiles is empty"); + return DP_INVALID_PARAM; + } + int32_t ret = RET_INIT; + for (auto deviceProfile : deviceProfiles) { + int32_t putRet = PutDeviceProfile(deviceProfile); + if (ret != DP_SUCCESS) { + ret = putRet; + } + } + if (ret != DP_SUCCESS) { + HILOGE("PutDeviceProfiles failed,ret=%{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::GetDeviceProfiles(DeviceProfileFilterOptions& options, + std::vector& deviceProfiles) +{ + std::string localUdid = ProfileCache::GetInstance().GetLocalUdid(); + int32_t localUserId = MultiUserManager::GetInstance().GetCurrentForegroundUserID(); + options.SetUserId(localUserId); + int32_t ret = DeviceProfileDao::GetInstance().GetDeviceProfiles(options, deviceProfiles); + if (ret != DP_SUCCESS) { + HILOGE("GetDeviceProfile failed,ret=%{public}d", ret); + return ret; + } + if (deviceProfiles.empty()) { + HILOGE("GetDeviceProfile failed,deviceProfiles is empty"); + return DP_DEVICE_PROFILE_NOT_FOUND; + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, + std::vector& deviceIconInfos) +{ + if (filterOptions.GetProductIds().empty() || filterOptions.GetSubProductId().empty() || + filterOptions.GetImageType().empty() || filterOptions.GetSpecName().empty()) { + HILOGE(""); + return DP_INVALID_PARAM; + } + int32_t ret = DeviceIconInfoDao::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos); + if (ret != DP_SUCCESS) { + HILOGE("GetDeviceIconInfos failed,ret=%{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) +{ + if (deviceIconInfos.empty()) { + HILOGE("ProductInfos is empty"); + return DP_INVALID_PARAM; + } + for (auto &deviceIconInfo : deviceIconInfos) { + int32_t ret = PutDeviceIconInfo(deviceIconInfo); + if (ret != DP_SUCCESS) { + HILOGE("PutDeviceIconInfo is failed,ret=%{public}d", ret); + return ret; + } + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::PutDeviceIconInfo(const DeviceIconInfo& deviceIconInfo) +{ + DeviceIconInfoFilterOptions filterOptions; + std::vector productIds; + productIds.emplace_back(deviceIconInfo.GetProductId()); + filterOptions.SetProductIds(productIds); + filterOptions.SetSubProductId(deviceIconInfo.GetSubProductId()); + filterOptions.SetImageType(deviceIconInfo.GetImageType()); + filterOptions.SetSpecName(deviceIconInfo.GetSpecName()); + std::vector deviceIconInfos; + int32_t ret = DeviceIconInfoDao::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos); + if ((ret != DP_SUCCESS) && (ret != DP_NOT_FIND_DATA)) { + HILOGE("GetDeviceIconInfos failed,ret=%{public}d", ret); + return ret; + } + if (deviceIconInfos.empty()) { + ret = DeviceIconInfoDao::GetInstance().PutDeviceIconInfo(deviceIconInfo); + } else { + DeviceIconInfo updateDeviceIconInfo = deviceIconInfo; + updateDeviceIconInfo.SetId(deviceIconInfos[0].GetId()); + ret = DeviceIconInfoDao::GetInstance().UpdateDeviceIconInfo(updateDeviceIconInfo); + } + if (ret != DP_SUCCESS) { + HILOGE("PutDeviceIconInfo failed,ret=%{public}d", ret); + return ret; + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::PutProductInfoBatch(const std::vector& productInfos) +{ + if (productInfos.empty()) { + HILOGE("ProductInfos is empty"); + return DP_INVALID_PARAM; + } + for (auto &productInfo : productInfos) { + int32_t ret = PutProductInfo(productInfo); + if (ret != DP_SUCCESS) { + HILOGE("PutProductInfo is failed,ret=%{public}d", ret); + return ret; + } + } + return DP_SUCCESS; +} + +int32_t ProfileDataManager::PutProductInfo(const ProductInfo& productInfo) +{ + if (productInfo.GetProductId().empty()) { + HILOGE("ProductId is nullptr"); + return DP_INVALID_PARAM; + } + std::vector productIds; + productIds.emplace_back(productInfo.GetProductId()); + std::vector productInfos; + int32_t ret = ProductInfoDao::GetInstance().GetProductInfos(productIds, productInfos); + if ((ret != DP_SUCCESS) && (ret != DP_NOT_FIND_DATA)) { + HILOGE("GetProductInfos failed,ret=%{public}d", ret); + return ret; + } + if (productInfos.empty()) { + ret = ProductInfoDao::GetInstance().PutProductInfo(productInfo); + } else { + ret = ProductInfoDao::GetInstance().UpdateProductInfo(productInfo); + } + if (ret != DP_SUCCESS) { + HILOGE("PutProductInfo failed,ret=%{public}d", ret); + return ret; + } + return DP_SUCCESS; +} +} // namespace DistributedDeviceProfile +} // namespace OHOS