From a28234768e00bb08e98664f0c5e0fcbcc652b60a Mon Sep 17 00:00:00 2001 From: wTong6 Date: Wed, 2 Apr 2025 10:38:42 +0800 Subject: [PATCH] fix Signed-off-by: wTong6 --- .../framework/checker/checker_manager.cpp | 19 ++++++++ .../include/checker/checker_manager.h | 6 ++- .../service/cloud/cloud_service_impl.cpp | 44 ++++++++++++------- .../service/cloud/cloud_service_impl.h | 5 ++- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index e02f50c64..379730202 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -126,6 +126,7 @@ std::vector CheckerManager::GetDynamicStores() } return res; } + std::vector CheckerManager::GetStaticStores() { std::vector res; @@ -140,6 +141,24 @@ std::vector CheckerManager::GetStaticStores() } return res; } + +std::set CheckerManager::GetKvStores() +{ + std::set stores; + for (auto &[name, checker] : checkers_) { + if (checker == nullptr) { + continue; + } + for (auto &storeInfo : checker->GetDynamicStores()) { + stores.insert(std::move(storeInfo.bundleName)); + } + for (auto &storeInfo : checker->GetStaticStores()) { + stores.insert(std::move(storeInfo.bundleName)); + } + } + return stores; +} + bool CheckerManager::IsDynamic(const CheckerManager::StoreInfo &info) { for (auto &[name, checker] : checkers_) { diff --git a/services/distributeddataservice/framework/include/checker/checker_manager.h b/services/distributeddataservice/framework/include/checker/checker_manager.h index f53279949..09c290391 100644 --- a/services/distributeddataservice/framework/include/checker/checker_manager.h +++ b/services/distributeddataservice/framework/include/checker/checker_manager.h @@ -15,9 +15,11 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H +#include #include -#include "visibility.h" + #include "concurrent_map.h" +#include "visibility.h" namespace OHOS { namespace DistributedData { class CheckerManager { @@ -68,6 +70,8 @@ public: API_EXPORT bool IsSwitches(const StoreInfo &info); API_EXPORT void LoadCheckers(std::vector &checkers); API_EXPORT Checker *GetChecker(const std::string &checker); + API_EXPORT std::set GetKvStores(); + private: std::map checkers_; ConcurrentMap> getters_; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index a286b810c..6d943d30a 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -397,17 +397,9 @@ std::map> CloudServiceImpl::GetDbInfoFromE return dbInfos; } -bool CloudServiceImpl::DoKvCloudSync(int32_t userId, const std::string &bundleName, int32_t triggerMode) +bool CloudServiceImpl::DoPrioritySync(int32_t userId, CloudSyncScene scene) { - auto stores = CheckerManager::GetInstance().GetDynamicStores(); - auto staticStores = CheckerManager::GetInstance().GetStaticStores(); - stores.insert(stores.end(), staticStores.begin(), staticStores.end()); - bool found = std::any_of(stores.begin(), stores.end(), [&bundleName](const CheckerManager::StoreInfo &storeInfo) { - return bundleName.empty() || storeInfo.bundleName == bundleName; - }); - if (!found) { - return found; - } + auto stores = CheckerManager::GetInstance().GetKvStores(); std::vector users; if (userId != INVALID_USER_ID) { users.emplace_back(userId); @@ -416,12 +408,11 @@ bool CloudServiceImpl::DoKvCloudSync(int32_t userId, const std::string &bundleNa } for (auto user : users) { for (const auto &store : stores) { - int32_t mode = (store.bundleName != bundleName && triggerMode == MODE_PUSH) ? MODE_CONSISTENCY - : triggerMode; - syncManager_.DoCloudSync(SyncManager::SyncInfo(user, store.bundleName, store.storeId, {}, mode)); + syncManager_.DoCloudSync( + SyncManager::SyncInfo(user, store.bundleName, store.storeId, {}, ConvertSceneToMode(scene))); } } - return found; + return true; } int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::string &bundleName) @@ -1195,20 +1186,31 @@ bool CloudServiceImpl::ReleaseUserInfo(int32_t user, CloudSyncScene scene) return true; } -bool CloudServiceImpl::DoCloudSync(int32_t user, CloudSyncScene scene) +bool CloudServiceImpl::DoGeneralSync(int32_t userId, int32_t triggerMode) { auto [status, cloudInfo] = GetCloudInfo(user); if (status != SUCCESS) { - Report(GetDfxFaultType(scene), Fault::CSF_CLOUD_INFO, "", "DoCloudSync ret=" + std::to_string(status)); + Report(GetDfxFaultType(scene), Fault::CSF_CLOUD_INFO, "", "DoGeneralSync ret=" + std::to_string(status)); return false; } + auto stores = CheckerManager::GetInstance().GetKvStores(); for (const auto &appInfo : cloudInfo.apps) { SyncManager::SyncInfo info(user, appInfo.first); + if (!stores.empty() && stores.find(appInfo.first) != stores.end()) { + continue; + } syncManager_.DoCloudSync(info); } return true; } +bool CloudServiceImpl::DoCloudSync(int32_t user, CloudSyncScene scene) +{ + DoPrioritySync(user, scene); + DoGeneralSync(user, scene); + return true; +} + bool CloudServiceImpl::StopCloudSync(int32_t user, CloudSyncScene scene) { syncManager_.StopCloudSync(user); @@ -1705,4 +1707,14 @@ QueryLastResults CloudServiceImpl::AssembleLastResults(const std::vector GetSharingHandle(const HapInfo &hapInfo); bool GetStoreMetaData(StoreMetaData &meta); - bool DoKvCloudSync(int32_t userId, const std::string &bundleName = "", int32_t triggerMode = 0); + bool DoPrioritySync(int32_t userId, CloudSyncScene scene); + bool DoGeneralSync(int32_t userId, CloudSyncScene scene); + int32_t ConvertSceneToMode(CloudSyncScene scene); using SaveStrategy = int32_t (*)(const std::vector &values, const HapInfo &hapInfo); static const SaveStrategy STRATEGY_SAVERS[Strategy::STRATEGY_BUTT]; @@ -209,6 +211,7 @@ private: static constexpr Handle WORK_RELEASE = &CloudServiceImpl::ReleaseUserInfo; static constexpr Handle WORK_DO_CLOUD_SYNC = &CloudServiceImpl::DoCloudSync; static constexpr Handle WORK_STOP_CLOUD_SYNC = &CloudServiceImpl::StopCloudSync; + static constexpr Handle WORK_DO_GENERAL_SYNC = &CloudServiceImpl::DoGeneralSync; }; } // namespace OHOS::CloudData -- Gitee