diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp index c0b0ccc89ccd471148934ef31437510e22e3c03b..4d022a2f65cf10b26ced407a04f13e536315b0c6 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -77,20 +77,20 @@ bool CloudInfo::IsValid() const return !id.empty(); } -bool CloudInfo::IsExist(const std::string &appId) const +bool CloudInfo::IsExist(const std::string &bundleName) const { for (const auto &app : apps) { - if (app.appId == appId) { + if (app.bundleName == bundleName) { return true; } } return false; } -void CloudInfo::DelApp(const std::string &appId) +void CloudInfo::DelApp(const std::string &bundleName) { for (auto it = apps.begin(); it != apps.end();) { - if ((*it).appId == appId) { + if ((*it).bundleName == bundleName) { it = apps.erase(it); break; } @@ -98,10 +98,10 @@ void CloudInfo::DelApp(const std::string &appId) } } -CloudInfo::AppInfo &CloudInfo::GetApp(const std::string &appId) +CloudInfo::AppInfo &CloudInfo::GetApp(const std::string &bundleName) { for (auto &app : apps) { - if (app.appId == appId) { + if (app.bundleName == bundleName) { return app; } } diff --git a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h index db56c3bd395c0c30671e5482ff2d90209734b0a0..31339b799d5107a1c88f1e63b9e1e8eadc1f42d0 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -39,9 +39,9 @@ public: std::string GetKey() const; std::map GetSchemaKey() const; bool IsValid() const; - bool IsExist(const std::string &appId) const; - void DelApp(const std::string &appId); - AppInfo &GetApp(const std::string &appId); + bool IsExist(const std::string &bundleName) const; + void DelApp(const std::string &bundleName); + AppInfo &GetApp(const std::string &bundleName); static std::string GetPrefix(const std::initializer_list &field); bool Marshal(json &node) const override; diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index a035ab9527a96110eec79a7b0951584013c1d78f..8de4f2cf23863bc705ee14705b45e5d295aa6ed3 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -31,8 +31,6 @@ namespace OHOS::CloudData { using namespace DistributedData; -using namespace DistributedKv; -using namespace DistributedRdb; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; CloudServiceImpl::Factory::Factory() { FeatureSystem::GetInstance().RegisterCreator(CloudServiceImpl::SERVICE_NAME, [this]() { @@ -70,8 +68,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &actions) { - return 0; + CloudInfo cloudInfo; + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS) { + ZLOGE("id:%{public}s", Anonymous::Change(id).c_str()); + return INVALID_ARGUMENT; + } + auto keys = cloudInfo.GetSchemaKey(); + for (const auto &action : actions) { + if (!cloudInfo.IsExist(action.first)) { + continue; + } + SchemaMeta schemaMeta; + if (MetaDataManager::GetInstance().LoadMeta(keys[action.first], schemaMeta, true)) { + // do action + } + } + return SUCCESS; } int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::string &bundleName) @@ -134,7 +146,7 @@ int32_t CloudServiceImpl::Config(const std::string &id, const StoreInfo &storeIn auto tokenId = IPCSkeleton::GetCallingTokenID(); CloudInfo cloudInfo; cloudInfo.id = id; - cloudInfo.user = AccountDelegate::GetInstance()->GetUserByToken(tokenId);; + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId);; if (ConfigCloudInfo(storeInfo, cloudInfo) != SUCCESS) { return ERROR; } @@ -151,11 +163,10 @@ int32_t CloudServiceImpl::ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); return ERROR; } - auto appId = GetAppId(storeInfo.bundleName); - if (!cloudInfo.IsExist(appId)) { + if (!cloudInfo.IsExist(storeInfo.bundleName)) { CloudInfo::AppInfo appInfo; appInfo.bundleName = storeInfo.bundleName; - appInfo.appId = appId; + appInfo.appId = GetAppId(storeInfo.bundleName); cloudInfo.apps.emplace_back(appInfo); } MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); @@ -165,8 +176,7 @@ int32_t CloudServiceImpl::ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo int32_t CloudServiceImpl::GetStoreSchema( const CloudInfo &cloudInfo, const StoreInfo &storeInfo, std::string &schema) { - auto appId = GetAppId(storeInfo.bundleName); - if (!cloudInfo.IsExist(appId)) { + if (!cloudInfo.IsExist(storeInfo.bundleName)) { ZLOGE("no exist bundleName:%{public}s", storeInfo.bundleName.c_str()); return ERROR; } @@ -198,11 +208,10 @@ int32_t CloudServiceImpl::ClearConfig(const std::string &id, const StoreInfo &st ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); return ERROR; } - auto appId = GetAppId(storeInfo.bundleName); - if (cloudInfo.IsExist(appId)) { + if (cloudInfo.IsExist(storeInfo.bundleName)) { auto keys = cloudInfo.GetSchemaKey(); MetaDataManager::GetInstance().DelMeta(keys[storeInfo.bundleName], true); - cloudInfo.DelApp(appId); + cloudInfo.DelApp(storeInfo.bundleName); } return SUCCESS; } @@ -210,7 +219,7 @@ int32_t CloudServiceImpl::ClearConfig(const std::string &id, const StoreInfo &st int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) { auto tokenId = IPCSkeleton::GetCallingTokenID(); - cloudInfo.user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { ZLOGE("invalid argument id:%{public}s, user:%{public}d", Anonymous::Change(cloudInfo.id).c_str(), cloudInfo.user); diff --git a/relational_store/test/native/cloud_data/BUILD.gn b/relational_store/test/native/cloud_data/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..021323f2b18534c0c21e5fa135fc128876574df9 --- /dev/null +++ b/relational_store/test/native/cloud_data/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright (c) 2023 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. +