diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp index e8d83c18a3f71ebf3af7291800e507b2a85f8c32..be368f11f6871e19392e8a94aa71b9e71d8749b0 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -92,15 +92,17 @@ bool CloudInfo::IsExist(const std::string &bundleName) const return false; } -void CloudInfo::DelApp(const std::string &bundleName) +void CloudInfo::UpdateApp(const std::vector &appInfos) { - for (auto it = apps.begin(); it != apps.end();) { - if (it->bundleName == bundleName) { - it = apps.erase(it); - break; + auto tmpInfo = appInfos; + for (auto &info : tmpInfo) { + auto app = GetApp(info.bundleName); + if (app.bundleName.empty()) { + continue; } - it++; + info.cloudSwitch = app.cloudSwitch; } + apps = tmpInfo; } CloudInfo::AppInfo &CloudInfo::GetApp(const std::string &bundleName) 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 f87c1d0374ea0e63bc0a1bcb85205e9d5d302ce8..c7d2cd17e3c88f9c8bbf350999d5b6c22e27d4bb 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -40,7 +40,7 @@ public: std::string GetSchemaKey(std::string bundleName) const; bool IsValid() const; bool IsExist(const std::string &bundleName) const; - void DelApp(const std::string &bundleName); + void UpdateApp(const std::vector &appInfos); AppInfo &GetApp(const std::string &bundleName); static std::string GetPrefix(const std::initializer_list &field); 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 0cf1ebe737fd3218e52cbbc23ad475cc1c0be836..334f7277c807e6c79b488861fd10bbdbe388ee74 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -56,6 +56,7 @@ CloudServiceImpl::CloudServiceImpl() } UpdateCloudInfo(cloudInfo); AddSchema(cloudInfo); + // TODO: Clear Task }); EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { @@ -95,7 +96,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS) { + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = true; @@ -113,7 +114,7 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) std::lock_guard lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS) { + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = false; @@ -128,7 +129,7 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri std::lock_guard lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS) { + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } auto &app = cloudInfo.GetApp(bundleName); @@ -147,7 +148,7 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::mapGetUserByToken(tokenId); - if (ConfigCloudInfo(storeInfo, cloudInfo) != SUCCESS) { - return ERROR; - } - UpdateSchema(cloudInfo, storeInfo, storeInfo.version); - if (GetStoreSchema(cloudInfo, storeInfo, schema) != SUCCESS) { - return ERROR; - } - return SUCCESS; -} - -int32_t CloudServiceImpl::ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo &cloudInfo) -{ - if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); - return ERROR; - } - if (!cloudInfo.IsExist(storeInfo.bundleName)) { - CloudInfo::AppInfo appInfo; - appInfo.bundleName = storeInfo.bundleName; - appInfo.appId = GetAppId(storeInfo.bundleName); - cloudInfo.apps.emplace_back(appInfo); - } - MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); - return SUCCESS; -} - -int32_t CloudServiceImpl::GetStoreSchema(const CloudInfo &cloudInfo, const StoreInfo &storeInfo, std::string &schema) -{ - if (!cloudInfo.IsExist(storeInfo.bundleName)) { - ZLOGE("no exist bundleName:%{public}s", storeInfo.bundleName.c_str()); - return ERROR; - } - SchemaMeta schemaMeta; - auto keys = cloudInfo.GetSchemaKey(); - if (!MetaDataManager::GetInstance().LoadMeta(keys[storeInfo.bundleName], schemaMeta, true)) { - ZLOGE("schema empty bundleName:%{public}s", storeInfo.bundleName.c_str()); - return ERROR; - } - auto database = schemaMeta.GetDataBase(storeInfo.storeId); - if (database.name.empty()) { - ZLOGE("storeId:%{public}s", storeInfo.storeId.c_str()); - return ERROR; - } - schema = Serializable::Marshall(database); - return SUCCESS; -} - -int32_t CloudServiceImpl::ClearConfig(const std::string &id, const StoreInfo &storeInfo) -{ - if (!CheckAccess(storeInfo.bundleName)) { - ZLOGE("permission denied"); - return ERROR; - } - - CloudInfo cloudInfo; - cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS) { - ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); - return ERROR; - } - if (cloudInfo.IsExist(storeInfo.bundleName)) { - auto keys = cloudInfo.GetSchemaKey(); - MetaDataManager::GetInstance().DelMeta(keys[storeInfo.bundleName], true); - cloudInfo.DelApp(storeInfo.bundleName); - } - return SUCCESS; -} - int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) { auto tokenId = IPCSkeleton::GetCallingTokenID(); @@ -299,6 +222,7 @@ void CloudServiceImpl::UpdateCloudInfo(CloudInfo &cloudInfo) } oldInfo.totalSpace = cloudInfo.totalSpace; oldInfo.remainSpace = cloudInfo.remainSpace; + oldInfo.UpdateApp(cloudInfo.apps); cloudInfo = oldInfo; MetaDataManager::GetInstance().SaveMeta(oldInfo.GetKey(), oldInfo, true); } @@ -327,31 +251,4 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa schemaMeta = instance->GetAppSchema(user, bundleName); return SUCCESS; } - -void CloudServiceImpl::UpdateSchema(CloudInfo &cloudInfo, const StoreInfo &storeInfo, int32_t version) -{ - SchemaMeta schemaMeta; - auto key = cloudInfo.GetSchemaKey(storeInfo.bundleName); - if (!MetaDataManager::GetInstance().LoadMeta(key, schemaMeta, true)) { - if (GetAppSchema(cloudInfo.user, storeInfo.bundleName, schemaMeta) != SUCCESS) { - ZLOGI("get schema meta fail"); - return; - } - MetaDataManager::GetInstance().SaveMeta(key, schemaMeta, true); - } - if (version <= schemaMeta.version) { - ZLOGI("input ver:%{public}d, meta ver:%{public}d", version, schemaMeta.version); - return; - } - SchemaMeta serverMeta; - if (GetAppSchema(cloudInfo.user, storeInfo.bundleName, serverMeta) != SUCCESS) { - ZLOGI("get schema meta fail"); - return; - } - if (serverMeta.version != version) { - ZLOGI("input ver:%{public}d, server ver:%{public}d", version, serverMeta.version); - return; - } - MetaDataManager::GetInstance().SaveMeta(key, serverMeta, true); -} } // namespace OHOS::CloudData \ No newline at end of file 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 0df774ea64211fdcd38c6fe9a1c2387de6b1c518..80aa5100110b5deabddbbf55a04257e06a576757 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -31,8 +31,6 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; - int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) override; - int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) override; private: class Factory { @@ -49,16 +47,13 @@ private: void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); - void UpdateSchema(CloudInfo &cloudInfo, const StoreInfo &storeInfo, int32_t version); - int32_t ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo &cloudInfo); - int32_t GetStoreSchema(const CloudInfo &cloudInfo, const StoreInfo &storeInfo, std::string &schema); int32_t GetCloudInfo(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); bool CheckAccess(const std::string &bundleName); std::mutex mutex_; - ConcurrentMap clousInfos_; + ConcurrentMap cloudInfos_; }; } // namespace OHOS::DistributedData diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index ae472364b384740df612fc14ed67c39e9018876d..2ccf869e5aabae40423eec2672653278ebe36783 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -27,8 +27,6 @@ const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { &CloudServiceStub::OnChangeAppSwitch, &CloudServiceStub::OnClean, &CloudServiceStub::OnNotifyDataChange, - &CloudServiceStub::OnConfig, - &CloudServiceStub::OnClearConfig, }; int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) @@ -103,27 +101,4 @@ int32_t CloudServiceStub::OnNotifyDataChange(const std::string &id, MessageParce auto result = NotifyDataChange(id, bundleName); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; } - -int32_t CloudServiceStub::OnConfig(const std::string &id, MessageParcel &data, MessageParcel &reply) -{ - StoreInfo storeInfo; - if (!ITypesUtil::Unmarshal(data, storeInfo)) { - ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); - return IPC_STUB_INVALID_DATA_ERR; - } - std::string schema; - auto result = Config(id, storeInfo, schema); - return ITypesUtil::Marshal(reply, result, schema) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; -} - -int32_t CloudServiceStub::OnClearConfig(const std::string &id, MessageParcel &data, MessageParcel &reply) -{ - StoreInfo storeInfo; - if (!ITypesUtil::Unmarshal(data, storeInfo)) { - ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); - return IPC_STUB_INVALID_DATA_ERR; - } - auto result = ClearConfig(id, storeInfo); - return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; -} } // namespace OHOS::CloudData diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h index f1f3cd62c9027864abce694fa82d15c4f0aaabe9..4175015d2731ca380b02874ab4af692502cd22d9 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h @@ -31,8 +31,6 @@ private: int32_t OnChangeAppSwitch(const std::string &id, MessageParcel &data, MessageParcel &reply); int32_t OnClean(const std::string &id, MessageParcel &data, MessageParcel &reply); int32_t OnNotifyDataChange(const std::string &id, MessageParcel &data, MessageParcel &reply); - int32_t OnConfig(const std::string &id, MessageParcel &data, MessageParcel &reply); - int32_t OnClearConfig(const std::string &id, MessageParcel &data, MessageParcel &reply); static const Handler HANDLERS[TRANS_BUTT]; }; } // namespace OHOS::CloudData diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index ccb7f2d032cf17b8285cccdbb8b1c1e4c703439a..8f98b6d49ad302a3d287c7b1d8213b6851077d1a 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -471,8 +471,7 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) int32_t RdbServiceImpl::OnInitialize() { auto tokenId = IPCSkeleton::GetCallingTokenID(); - auto user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); - auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, user); + auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, tokenId); EventCenter::GetInstance().PostEvent(std::move(initEvt)); return RDB_OK; } @@ -485,9 +484,8 @@ int32_t RdbServiceImpl::GetSchema(const std::string &bundleName, const std::stri } auto event = std::make_unique(CloudEvent::GET_SCHEMA, IPCSkeleton::GetCallingTokenID(), storeName, bundleName); - EventCenter::GetInstance().PostEvent(move(event)); - - return 0; + EventCenter::GetInstance().PostEvent(std::move(event)); + return RDB_OK; } } // namespace OHOS::DistributedRdb diff --git a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h index 0c6e7844e0fee698c095b425df031eec020e2971..7dec3bf806788cc32dbe148eb8f9380126c01794 100644 --- a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h +++ b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h @@ -30,8 +30,6 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; - int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) override; - int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) override; private: sptr remote_; diff --git a/relational_store/frameworks/native/cloud_data/include/cloud_types_util.h b/relational_store/frameworks/native/cloud_data/include/cloud_types_util.h deleted file mode 100644 index 8dbd969de69f127c60202ea2e425eb019ae869c1..0000000000000000000000000000000000000000 --- a/relational_store/frameworks/native/cloud_data/include/cloud_types_util.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_CLOUD_CLOUD_TYPES_UTIL_H -#define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H - -#include "cloud_service.h" -#include "itypes_util.h" -#include "rdb_visibility.h" - -namespace OHOS::ITypesUtil { -using StoreInfo = CloudData::CloudService::StoreInfo; -template<> -RDB_API_EXPORT bool Marshalling(const StoreInfo &input, MessageParcel &data); -template<> -RDB_API_EXPORT bool Unmarshalling(StoreInfo &output, MessageParcel &data); -} // namespace OHOS::ITypesUtil -#endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H diff --git a/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp b/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp index 833cb5a38426a1d57840f4c495cd7271cd057a27..fd2955952e297bd114c74381c714c4dd3d4e1650 100644 --- a/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp +++ b/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp @@ -102,27 +102,4 @@ int32_t CloudServiceProxy::NotifyDataChange(const std::string &id, const std::st } return static_cast(status); } - -int32_t CloudServiceProxy::Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) -{ - MessageParcel reply; - int32_t status = IPC_SEND(TRANS_CONFIG, reply, id, storeInfo); - if (status != SUCCESS) { - ZLOGE("status:0x%{public}x id:%{public}.6s bundleName:%{public}s, storeId:%{public}s", - status, id.c_str(), storeInfo.bundleName.c_str(), storeInfo.storeId.c_str()); - } - ITypesUtil::Unmarshal(reply, schema); - return static_cast(status); -} - -int32_t CloudServiceProxy::ClearConfig(const std::string &id, const StoreInfo &storeInfo) -{ - MessageParcel reply; - int32_t status = IPC_SEND(TRANS_CLEAR_CONFIG, reply, id, storeInfo); - if (status != SUCCESS) { - ZLOGE("status:0x%{public}x id:%{public}.6s bundleName:%{public}s, storeId:%{public}s", - status, id.c_str(), storeInfo.bundleName.c_str(), storeInfo.storeId.c_str()); - } - return static_cast(status); -} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp b/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp deleted file mode 100644 index d127971f6f49a396f11a4e351a9254b2517aa29c..0000000000000000000000000000000000000000 --- a/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp +++ /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. - */ - -#include "cloud_types_util.h" - -namespace OHOS::ITypesUtil { -template<> -bool Marshalling(const StoreInfo &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, input.bundleName, input.storeId, input.version); -} -template<> -bool Unmarshalling(StoreInfo &output, MessageParcel &data) -{ - return ITypesUtil::Unmarshal(data, output.bundleName, output.storeId, output.version); -} -} // namespace OHOS::ITypesUtil - \ No newline at end of file diff --git a/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h b/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h index 83792cf66d33ec8da98628135dacc56f1c26b71e..c180cf9938650fa70a3469bdde5625aa6f679a30 100644 --- a/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h +++ b/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h @@ -30,8 +30,6 @@ public: TRANS_CHANGE_APP_SWITCH, TRANS_CLEAN, TRANS_NOTIFY_DATA_CHANGE, - TRANS_CONFIG, - TRANS_CLEAR_CONFIG, TRANS_BUTT, }; enum Action : int32_t @@ -57,20 +55,12 @@ public: IPC_PARCEL_ERROR }; - struct RDB_API_EXPORT StoreInfo { - std::string bundleName; - std::string storeId; - int32_t version; - }; - virtual ~CloudService() = default; virtual int32_t EnableCloud(const std::string &id, const std::map &switches) = 0; virtual int32_t DisableCloud(const std::string &id) = 0; virtual int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) = 0; virtual int32_t Clean(const std::string &id, const std::map &actions) = 0; virtual int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) = 0; - virtual int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) = 0; - virtual int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) = 0; static constexpr const char *SERVICE_NAME = "cloud"; };