From f1b301f3abc71bb8b75dd9b5bb6a6d1b12d8df27 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 11 May 2023 10:05:04 +0800 Subject: [PATCH] update Signed-off-by: zuojiangjiang --- .../framework/cloud/cloud_info.cpp | 2 +- .../service/cloud/cloud_service_impl.cpp | 31 +++++++++---------- .../service/cloud/cloud_service_impl.h | 2 +- .../service/cloud/cloud_syncer.cpp | 28 ----------------- .../service/cloud/cloud_syncer.h | 30 ------------------ 5 files changed, 16 insertions(+), 77 deletions(-) delete mode 100644 datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp delete mode 100644 datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp index 2f44ff85..a50f4d69 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -61,7 +61,7 @@ bool CloudInfo::AppInfo::Unmarshal(const Serializable::json &node) std::string CloudInfo::GetKey() const { - return GetKey(INFO_PREFIX, { std::to_string(user), id }); + return GetKey(INFO_PREFIX, { std::to_string(user) }); } std::map CloudInfo::GetSchemaKey() const 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 083c86b9..0ee41f6b 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -21,7 +21,6 @@ #include "checker/checker_manager.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" -#include "cloud_syncer.h" #include "communicator/device_manager_adapter.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" @@ -64,7 +63,6 @@ CloudServiceImpl::CloudServiceImpl() } UpdateCloudInfo(cloudInfo); AddSchema(cloudInfo); - // TODO: Clear Task }); EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { @@ -99,8 +97,7 @@ CloudServiceImpl::CloudServiceImpl() int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { CloudInfo cloudInfo; - cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + if (GetCloudInfo(id, cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = true; @@ -123,8 +120,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &actions) { CloudInfo cloudInfo; - cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("id:%{public}s", Anonymous::Change(id).c_str()); + if (GetCloudInfo(id, cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } auto keys = cloudInfo.GetSchemaKey(); @@ -171,7 +164,6 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::map executor) return E_OK; } -int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) +int32_t CloudServiceImpl::GetCloudInfo(const std::string &id, CloudInfo &cloudInfo) { auto tokenId = IPCSkeleton::GetCallingTokenID(); 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); - return ERROR; + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true) && + GetServerInfo(cloudInfo ) != SUCCESS) { + ZLOGE("invalid args, user:%{public}d", cloudInfo.user); + return INVALID_ARGUMENT; + } + if (cloudInfo.id != id) { + ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", + Anonymous::Change(id).c_str(), Anonymous::Change(cloudInfo.id).c_str()); + return INVALID_ARGUMENT; } return SUCCESS; } diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h index 45569140..607cb096 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -56,7 +56,7 @@ private: SchemaMeta GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId); StoreMetaData GetStoreMata(int32_t userId, const std::string &bundleName, const std::string &storeName, int32_t instanceId); - int32_t GetCloudInfo(CloudInfo &cloudInfo); + int32_t GetCloudInfo(const std::string &id, CloudInfo &cloudInfo); int32_t GetServerInfo(CloudInfo &cloudInfo); int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); std::string GetAppId(const std::string &bundleName); diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp deleted file mode 100644 index f920c5ec..00000000 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#include "cloud_syncer.h" - -namespace OHOS::CloudData { -CloudSyncer &CloudSyncer::GetInstance() -{ - static CloudSyncer instance; - return instance; -} - -void CloudSyncer::Sync(const DistributedData::CloudInfo &cloudInfo) -{ -} -} // namespace OHOS::CloudData \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h deleted file mode 100644 index c9dd7971..00000000 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H -#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H - -#include "cloud/cloud_info.h" - -namespace OHOS::CloudData { -class CloudSyncer { -public: - static CloudSyncer &GetInstance(); - void Sync(const DistributedData::CloudInfo &cloudInfo); - -private: -}; -} // namespace OHOS::CloudData -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H -- Gitee