From 7bacf7631f45e310846a7671565217e4b246720f Mon Sep 17 00:00:00 2001 From: wangtiantian Date: Thu, 7 Dec 2023 19:42:51 +0800 Subject: [PATCH] IssueNo:#I8MN15 Description:fix bug Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../dbms/include/distributed_data_storage.h | 2 + .../dbms/src/distributed_data_storage.cpp | 68 ++++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/services/dbms/include/distributed_data_storage.h b/services/dbms/include/distributed_data_storage.h index fd2840f..fdc2eee 100644 --- a/services/dbms/include/distributed_data_storage.h +++ b/services/dbms/include/distributed_data_storage.h @@ -53,6 +53,8 @@ private: DistributedBundleInfo ConvertToDistributedBundleInfo(const BundleInfo &bundleInfo); int32_t GetUdidByNetworkId(const std::string &networkId, std::string &udid); bool InnerSaveStorageDistributeInfo(const DistributedBundleInfo &distributedBundleInfo); + std::map GetAllOldDistributionBundleInfo(); + private: static std::mutex mutex_; static std::shared_ptr instance_; diff --git a/services/dbms/src/distributed_data_storage.cpp b/services/dbms/src/distributed_data_storage.cpp index add8dad..a44cd6b 100644 --- a/services/dbms/src/distributed_data_storage.cpp +++ b/services/dbms/src/distributed_data_storage.cpp @@ -358,56 +358,74 @@ DistributedBundleInfo DistributedDataStorage::ConvertToDistributedBundleInfo(con } distributedBundleInfo.enabled = bundleInfo.applicationInfo.enabled; distributedBundleInfo.accessTokenId = bundleInfo.applicationInfo.accessTokenId; + distributedBundleInfo.updateTime = bundleInfo.updateTime; return distributedBundleInfo; } void DistributedDataStorage::UpdateDistributedData(int32_t userId) { APP_LOGI("UpdateDistributedData"); + auto bundleMgr = DelayedSingleton::GetInstance()->GetBundleMgr(); + if (bundleMgr == nullptr) { + APP_LOGE("Get bundleMgr shared_ptr nullptr"); + return; + } + std::map oldDistributedBundleInfos = GetAllOldDistributionBundleInfo(); + std::vector bundleInfos; + if (!bundleMgr->GetBundleInfos(FLAGS, bundleInfos, userId)) { + APP_LOGE("get bundleInfos failed"); + return; + } + for (const auto &bundleInfo : bundleInfos) { + if (bundleInfo.singleton) { + continue; + } + if (oldDistributedBundleInfos.find(bundleInfo.name) != oldDistributedBundleInfos.end()) { + if (oldDistributedBundleInfos[bundleInfo.name].updateTime == bundleInfo.updateTime) { + APP_LOGW("bundleName:%{public}s no need to update", bundleInfo.name.c_str()); + continue; + } + } + if (!InnerSaveStorageDistributeInfo(ConvertToDistributedBundleInfo(bundleInfo))) { + APP_LOGW("UpdateDistributedData SaveStorageDistributeInfo:%{public}s failed", bundleInfo.name.c_str()); + } + } +} + +std::map DistributedDataStorage::GetAllOldDistributionBundleInfo() +{ + APP_LOGD("start"); + std::map oldDistributedBundleInfos; if (kvStorePtr_ == nullptr) { APP_LOGE("kvStorePtr_ is null"); - return; + return oldDistributedBundleInfos; } std::string udid; if (!GetLocalUdid(udid)) { APP_LOGE("GetLocalUdid failed"); - return; + return oldDistributedBundleInfos; } Key allEntryKeyPrefix(""); std::vector allEntries; Status status = kvStorePtr_->GetEntries(allEntryKeyPrefix, allEntries); if (status != Status::SUCCESS) { APP_LOGE("dataManager_ GetEntries error: %{public}d", status); - return; + return oldDistributedBundleInfos; } - for (auto entry : allEntries) { + for (const auto &entry : allEntries) { std::string key = entry.key.ToString(); if (key.find(udid) == std::string::npos) { continue; } - status = kvStorePtr_->Delete(entry.key); - if (status != Status::SUCCESS) { - APP_LOGE("Delete key:%{public}s failed", key.c_str()); - } - } - auto bundleMgr = DelayedSingleton::GetInstance()->GetBundleMgr(); - if (bundleMgr == nullptr) { - APP_LOGE("Get bundleMgr shared_ptr nullptr"); - return; - } - std::vector bundleInfos; - if (!bundleMgr->GetBundleInfos(FLAGS, bundleInfos, userId)) { - APP_LOGE("get bundleInfos failed"); - return; - } - for (auto bundleInfo : bundleInfos) { - if (bundleInfo.singleton) { - continue; - } - if (!InnerSaveStorageDistributeInfo(ConvertToDistributedBundleInfo(bundleInfo))) { - APP_LOGW("UpdateDistributedData SaveStorageDistributeInfo:%{public}s failed", bundleInfo.name.c_str()); + std::string value = entry.value.ToString(); + DistributedBundleInfo distributedBundleInfo; + if (distributedBundleInfo.FromJsonString(value)) { + oldDistributedBundleInfos.emplace(distributedBundleInfo.bundleName, distributedBundleInfo); + } else { + APP_LOGE("DistributionInfo FromJsonString key:%{public}s failed", key.c_str()); } } + return oldDistributedBundleInfos; } } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file -- Gitee