From da651172d6bcf1617a3f2eb7a0396b4bd5dc1050 Mon Sep 17 00:00:00 2001 From: bigteer Date: Tue, 15 Jul 2025 19:38:50 +0800 Subject: [PATCH 01/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 20 +++++++++++-- .../app/src/checker/bundle_checker.h | 3 ++ .../app/src/kvstore_data_service.cpp | 4 +++ .../framework/checker/checker_manager.cpp | 10 +++++++ .../include/checker/checker_manager.h | 3 ++ .../include/metadata/meta_data_manager.h | 30 ------------------- .../framework/metadata/meta_data_manager.cpp | 14 +++++---- 7 files changed, 46 insertions(+), 38 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index b14a5fedd..01a1b56a0 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -63,6 +63,12 @@ bool BundleChecker::SetSwitchesInfo(const CheckerManager::Switches &switches) std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) { + std::string appId; + int32_t userId = info.uid / OHOS::AppExecFwk::Constants::BASE_USER_RANGE; + std::string key = info.bundleName + "###" + std::to_string(userId); + if (appId_.Get(key, appId)) { + return appId; + } auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { ZLOGE("Failed to get system ability mgr."); @@ -78,15 +84,25 @@ std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) ZLOGE("Failed to get bundle manager"); return ""; } - int32_t userId = info.uid / OHOS::AppExecFwk::Constants::BASE_USER_RANGE; - std::string appId = bundleManager->GetAppIdByBundleName(info.bundleName, userId); + appId = bundleManager->GetAppIdByBundleName(info.bundleName, userId); if (appId.empty()) { ZLOGE("GetAppIdByBundleName failed appId:%{public}s, bundleName:%{public}s, uid:%{public}d", appId.c_str(), info.bundleName.c_str(), userId); } + appId_.Set(key, appId); return appId; } +void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int32_t index) +{ + std::string key = bundleName + "###" + std::to_string(user); + std::string appId; + appId_.Get(key, appId); + ZLOGI("DeleteAppidCache bundleName:%{public}s, user:%{public}d, appId:%{public}s.", + bundleName.c_str(), user, appId.c_str()); + appId_.Delete(key); +} + std::string BundleChecker::GetAppId(const CheckerManager::StoreInfo &info) { if (AccessTokenKit::GetTokenTypeFlag(info.tokenId) != TOKEN_HAP) { diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 1eba18e54..3b64f1ffd 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -16,6 +16,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_BUNDLE_CHECKER_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_BUNDLE_CHECKER_H #include "checker/checker_manager.h" +#include "lru_bucket.h" namespace OHOS { namespace DistributedData { class BundleChecker : public CheckerManager::Checker { @@ -36,6 +37,7 @@ public: std::vector GetStaticStores() override; bool IsDynamic(const CheckerManager::StoreInfo &info) override; bool IsStatic(const CheckerManager::StoreInfo &info) override; + void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; private: static BundleChecker instance_; @@ -45,6 +47,7 @@ private: std::vector dynamicStores_; std::vector staticStores_; std::string GetBundleAppId(const CheckerManager::StoreInfo &info); + LRUBucket appId_ {64}; }; } // namespace DistributedData } // namespace OHOS diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index c77fc1334..ad33b8330 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -1049,6 +1049,7 @@ void KvStoreDataService::OnSessionReady(const AppDistributedKv::DeviceInfo &info int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t user, int32_t index) { + CheckerManager::GetInstance().DeleteCache(bundleName, user, index); auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); staticActs.ForEachCopies([bundleName, user, index](const auto &, const std::shared_ptr& acts) { acts->OnAppUninstall(bundleName, user, index); @@ -1059,6 +1060,7 @@ int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t u int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user, int32_t index) { + CheckerManager::GetInstance().DeleteCache(bundleName, user, index); auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); staticActs.ForEachCopies([bundleName, user, index](const auto &, const std::shared_ptr& acts) { acts->OnAppUpdate(bundleName, user, index); @@ -1069,6 +1071,7 @@ int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user int32_t KvStoreDataService::OnInstall(const std::string &bundleName, int32_t user, int32_t index) { + CheckerManager::GetInstance().DeleteCache(bundleName, user, index); auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); staticActs.ForEachCopies([bundleName, user, index](const auto &, const std::shared_ptr& acts) { acts->OnAppInstall(bundleName, user, index); @@ -1089,6 +1092,7 @@ int32_t KvStoreDataService::OnScreenUnlocked(int32_t user) int32_t KvStoreDataService::ClearAppStorage(const std::string &bundleName, int32_t userId, int32_t appIndex, int32_t tokenId) { + CheckerManager::GetInstance().DeleteCache(bundleName, userId, appIndex); auto callerToken = IPCSkeleton::GetCallingTokenID(); NativeTokenInfo nativeTokenInfo; if (AccessTokenKit::GetNativeTokenInfo(callerToken, nativeTokenInfo) != RET_SUCCESS || diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index e02f50c64..d54d0f9d4 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -47,6 +47,16 @@ void CheckerManager::RegisterPlugin(const std::string &checker, std::functionDeleteCache(bundleName, user, index); + } +} + std::string CheckerManager::GetAppId(const 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..651f2bedf 100644 --- a/services/distributeddataservice/framework/include/checker/checker_manager.h +++ b/services/distributeddataservice/framework/include/checker/checker_manager.h @@ -53,6 +53,7 @@ public: virtual std::vector GetStaticStores() = 0; virtual bool IsDynamic(const StoreInfo &info) = 0; virtual bool IsStatic(const StoreInfo &info) = 0; + virtual void DeleteCache(const std::string &bundleName, int32_t user, int32_t index){}; protected: API_EXPORT ~Checker() = default; }; @@ -68,6 +69,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 void DeleteCache(const std::string &bundleName, int32_t user, int32_t index); + private: std::map checkers_; ConcurrentMap> getters_; diff --git a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h index fb8dc79c1..48d8e6ed3 100644 --- a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h +++ b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h @@ -92,36 +92,6 @@ private: ~MetaDataManager(); API_EXPORT bool GetEntries(const std::string &prefix, std::vector &entries, bool isLocal); - - void DelCacheMeta(const std::string &key, bool isLocal) - { - if (!isLocal) { - return; - } - localdata_.Delete(key); - } - - bool LoadCacheMeta(const std::string &key, Serializable &value, bool isLocal) - { - if (!isLocal) { - return false; - } - std::string data; - if (!localdata_.Get(key, data)) { - return false; - } - Serializable::Unmarshall(data, value); - return true; - } - - void SaveCacheMeta(const std::string &key, const std::string &data, bool isLocal) - { - if (!isLocal) { - return; - } - localdata_.Set(key, data); - } - void StopSA(); bool inited_ = false; diff --git a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp index 09bd5c240..d8f7427aa 100644 --- a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp +++ b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp @@ -213,7 +213,7 @@ bool MetaDataManager::SaveMeta(const std::string &key, const Serializable &value ZLOGE("failed! status:%{public}d isLocal:%{public}d, key:%{public}s", status, isLocal, Anonymous::Change(key).c_str()); } - DelCacheMeta(key, isLocal); + localdata_.Delete(key); return status == DistributedDB::DBStatus::OK; } @@ -229,7 +229,7 @@ bool MetaDataManager::SaveMeta(const std::vector &values, bool isLocal) entries.reserve(values.size()); for (const auto &[key, value] : values) { entries.push_back({ { key.begin(), key.end() }, { value.begin(), value.end() } }); - DelCacheMeta(key, isLocal); + localdata_.Delete(key); } auto status = isLocal ? metaStore_->PutLocalBatch(entries) : metaStore_->PutBatch(entries); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { @@ -255,7 +255,9 @@ bool MetaDataManager::LoadMeta(const std::string &key, Serializable &value, bool if (!inited_) { return false; } - if (LoadCacheMeta(key, value, isLocal)) { + std::string temp; + if (localdata_.Get(key, temp)) { + Serializable::Unmarshall(temp, value); return true; } DistributedDB::Value data; @@ -272,7 +274,7 @@ bool MetaDataManager::LoadMeta(const std::string &key, Serializable &value, bool return false; } std::string tempdata(data.begin(), data.end()); - SaveCacheMeta(key, tempdata, isLocal); + localdata_.Set(key, tempdata); Serializable::Unmarshall(tempdata, value); if (isLocal) { data.assign(data.size(), 0); @@ -308,7 +310,7 @@ bool MetaDataManager::DelMeta(const std::string &key, bool isLocal) if (!inited_) { return false; } - DelCacheMeta(key, isLocal); + localdata_.Delete(key); auto status = isLocal ? metaStore_->DeleteLocal({ key.begin(), key.end() }) : metaStore_->Delete({ key.begin(), key.end() }); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { @@ -339,7 +341,7 @@ bool MetaDataManager::DelMeta(const std::vector &keys, bool isLocal dbKeys.reserve(keys.size()); for (auto &key : keys) { dbKeys.emplace_back(key.begin(), key.end()); - DelCacheMeta(key, isLocal); + localdata_.Delete(key); } auto status = isLocal ? metaStore_->DeleteLocalBatch(dbKeys) : metaStore_->DeleteBatch(dbKeys); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { -- Gitee From cf7b020e44ebe7bef8c00c056e57d199fa65d96d Mon Sep 17 00:00:00 2001 From: bigteer Date: Wed, 16 Jul 2025 14:18:25 +0800 Subject: [PATCH 02/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../distributeddataservice/app/src/checker/bundle_checker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 3b64f1ffd..b3f9ac292 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -47,7 +47,7 @@ private: std::vector dynamicStores_; std::vector staticStores_; std::string GetBundleAppId(const CheckerManager::StoreInfo &info); - LRUBucket appId_ {64}; + LRUBucket appId_ {32}; }; } // namespace DistributedData } // namespace OHOS -- Gitee From 499597e678e241ffc2294030cebcd4bfdc765db0 Mon Sep 17 00:00:00 2001 From: bigteer Date: Wed, 16 Jul 2025 14:58:51 +0800 Subject: [PATCH 03/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../include/metadata/meta_data_manager.h | 30 +++++++++++++++++++ .../framework/metadata/meta_data_manager.cpp | 14 ++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h index 48d8e6ed3..fb8dc79c1 100644 --- a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h +++ b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h @@ -92,6 +92,36 @@ private: ~MetaDataManager(); API_EXPORT bool GetEntries(const std::string &prefix, std::vector &entries, bool isLocal); + + void DelCacheMeta(const std::string &key, bool isLocal) + { + if (!isLocal) { + return; + } + localdata_.Delete(key); + } + + bool LoadCacheMeta(const std::string &key, Serializable &value, bool isLocal) + { + if (!isLocal) { + return false; + } + std::string data; + if (!localdata_.Get(key, data)) { + return false; + } + Serializable::Unmarshall(data, value); + return true; + } + + void SaveCacheMeta(const std::string &key, const std::string &data, bool isLocal) + { + if (!isLocal) { + return; + } + localdata_.Set(key, data); + } + void StopSA(); bool inited_ = false; diff --git a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp index d8f7427aa..09bd5c240 100644 --- a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp +++ b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp @@ -213,7 +213,7 @@ bool MetaDataManager::SaveMeta(const std::string &key, const Serializable &value ZLOGE("failed! status:%{public}d isLocal:%{public}d, key:%{public}s", status, isLocal, Anonymous::Change(key).c_str()); } - localdata_.Delete(key); + DelCacheMeta(key, isLocal); return status == DistributedDB::DBStatus::OK; } @@ -229,7 +229,7 @@ bool MetaDataManager::SaveMeta(const std::vector &values, bool isLocal) entries.reserve(values.size()); for (const auto &[key, value] : values) { entries.push_back({ { key.begin(), key.end() }, { value.begin(), value.end() } }); - localdata_.Delete(key); + DelCacheMeta(key, isLocal); } auto status = isLocal ? metaStore_->PutLocalBatch(entries) : metaStore_->PutBatch(entries); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { @@ -255,9 +255,7 @@ bool MetaDataManager::LoadMeta(const std::string &key, Serializable &value, bool if (!inited_) { return false; } - std::string temp; - if (localdata_.Get(key, temp)) { - Serializable::Unmarshall(temp, value); + if (LoadCacheMeta(key, value, isLocal)) { return true; } DistributedDB::Value data; @@ -274,7 +272,7 @@ bool MetaDataManager::LoadMeta(const std::string &key, Serializable &value, bool return false; } std::string tempdata(data.begin(), data.end()); - localdata_.Set(key, tempdata); + SaveCacheMeta(key, tempdata, isLocal); Serializable::Unmarshall(tempdata, value); if (isLocal) { data.assign(data.size(), 0); @@ -310,7 +308,7 @@ bool MetaDataManager::DelMeta(const std::string &key, bool isLocal) if (!inited_) { return false; } - localdata_.Delete(key); + DelCacheMeta(key, isLocal); auto status = isLocal ? metaStore_->DeleteLocal({ key.begin(), key.end() }) : metaStore_->Delete({ key.begin(), key.end() }); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { @@ -341,7 +339,7 @@ bool MetaDataManager::DelMeta(const std::vector &keys, bool isLocal dbKeys.reserve(keys.size()); for (auto &key : keys) { dbKeys.emplace_back(key.begin(), key.end()); - localdata_.Delete(key); + DelCacheMeta(key, isLocal); } auto status = isLocal ? metaStore_->DeleteLocalBatch(dbKeys) : metaStore_->DeleteBatch(dbKeys); if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { -- Gitee From 33a996a500937f39907745c8164db285d0b5559d Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 10:19:48 +0800 Subject: [PATCH 04/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 27 +++++++++++++------ .../app/src/checker/bundle_checker.h | 2 ++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 01a1b56a0..92c1ffd4e 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -61,12 +61,25 @@ bool BundleChecker::SetSwitchesInfo(const CheckerManager::Switches &switches) return true; } +std::string BundleChecker::GetKey(const std::string &bundleName, int32_t userId) +{ + return bundleName + "###" + std::to_string(userId); +} + +bool BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId) +{ + std::string key = Getkey(bundleName, userId); + if (appId_.Get(key, appId)) { + return true; + } + return false; +} + std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) { std::string appId; int32_t userId = info.uid / OHOS::AppExecFwk::Constants::BASE_USER_RANGE; - std::string key = info.bundleName + "###" + std::to_string(userId); - if (appId_.Get(key, appId)) { + if (GetAppidFromCache(info.bundleName, userId, appId)) { return appId; } auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -88,18 +101,16 @@ std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) if (appId.empty()) { ZLOGE("GetAppIdByBundleName failed appId:%{public}s, bundleName:%{public}s, uid:%{public}d", appId.c_str(), info.bundleName.c_str(), userId); + } else { + appId_.Set(GetKey(bundleName, userId), appId); } - appId_.Set(key, appId); return appId; } void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int32_t index) { - std::string key = bundleName + "###" + std::to_string(user); - std::string appId; - appId_.Get(key, appId); - ZLOGI("DeleteAppidCache bundleName:%{public}s, user:%{public}d, appId:%{public}s.", - bundleName.c_str(), user, appId.c_str()); + std::string key = GetKey(bundleName, user); + ZLOGI("DeleteAppidCache bundleName:%{public}s, user:%{public}d.", bundleName.c_str(), user); appId_.Delete(key); } diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index b3f9ac292..21c1e80f6 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -40,6 +40,8 @@ public: void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; private: + bool GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId); + std::string GetKey(const std::string &bundleName, int32_t userId); static BundleChecker instance_; std::map trusts_; std::map distrusts_; -- Gitee From f025275c2a08eb60d0aee164e1d65e30756332a6 Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 10:23:24 +0800 Subject: [PATCH 05/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 92c1ffd4e..6540ff4ca 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -69,7 +69,7 @@ std::string BundleChecker::GetKey(const std::string &bundleName, int32_t userId) bool BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId) { std::string key = Getkey(bundleName, userId); - if (appId_.Get(key, appId)) { + if (appIds_.Get(key, appId)) { return true; } return false; @@ -102,7 +102,7 @@ std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) ZLOGE("GetAppIdByBundleName failed appId:%{public}s, bundleName:%{public}s, uid:%{public}d", appId.c_str(), info.bundleName.c_str(), userId); } else { - appId_.Set(GetKey(bundleName, userId), appId); + appIds_.Set(GetKey(bundleName, userId), appId); } return appId; } @@ -111,7 +111,7 @@ void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int { std::string key = GetKey(bundleName, user); ZLOGI("DeleteAppidCache bundleName:%{public}s, user:%{public}d.", bundleName.c_str(), user); - appId_.Delete(key); + appIds_.Delete(key); } std::string BundleChecker::GetAppId(const CheckerManager::StoreInfo &info) -- Gitee From 0cd63010e3f748cb2099af6429e8113488634247 Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 10:26:41 +0800 Subject: [PATCH 06/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../distributeddataservice/app/src/checker/bundle_checker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 21c1e80f6..bd9f0de45 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -49,7 +49,7 @@ private: std::vector dynamicStores_; std::vector staticStores_; std::string GetBundleAppId(const CheckerManager::StoreInfo &info); - LRUBucket appId_ {32}; + LRUBucket appIds_ {32}; }; } // namespace DistributedData } // namespace OHOS -- Gitee From f64d4c2622d647b001502cd6cf5e80b637117ec9 Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 10:52:30 +0800 Subject: [PATCH 07/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 6540ff4ca..c59dcb178 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -69,10 +69,7 @@ std::string BundleChecker::GetKey(const std::string &bundleName, int32_t userId) bool BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId) { std::string key = Getkey(bundleName, userId); - if (appIds_.Get(key, appId)) { - return true; - } - return false; + return appIds_.Get(key, appId); } std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) -- Gitee From 4b926f3dbdfddb07248707107b000959be4d3d6d Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 11:28:46 +0800 Subject: [PATCH 08/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 17 +++++++++++++---- .../app/src/checker/bundle_checker.h | 4 ++-- .../app/src/kvstore_data_service.cpp | 1 + .../framework/checker/checker_manager.cpp | 10 ++++++++++ .../framework/include/checker/checker_manager.h | 2 ++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index c59dcb178..05669176a 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -66,17 +66,19 @@ std::string BundleChecker::GetKey(const std::string &bundleName, int32_t userId) return bundleName + "###" + std::to_string(userId); } -bool BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId) +std::string BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId) { + std::string appId; std::string key = Getkey(bundleName, userId); - return appIds_.Get(key, appId); + appIds_.Get(key, appId); + return appId; } std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) { - std::string appId; int32_t userId = info.uid / OHOS::AppExecFwk::Constants::BASE_USER_RANGE; - if (GetAppidFromCache(info.bundleName, userId, appId)) { + std::string appId = GetAppidFromCache(info.bundleName, userId); + if (!appId.empty()) { return appId; } auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -111,6 +113,13 @@ void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int appIds_.Delete(key); } +void BundleChecker::ClearCache() +{ + ZLOGI("ClearAppidCache."); + appIds_.ResetCapacity(0); + appIds_.ResetCapacity(32); +} + std::string BundleChecker::GetAppId(const CheckerManager::StoreInfo &info) { if (AccessTokenKit::GetTokenTypeFlag(info.tokenId) != TOKEN_HAP) { diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index bd9f0de45..07aadc0c5 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -38,9 +38,9 @@ public: bool IsDynamic(const CheckerManager::StoreInfo &info) override; bool IsStatic(const CheckerManager::StoreInfo &info) override; void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; - + void ClearCache() override; private: - bool GetAppidFromCache(const std::string &bundleName, int32_t userId, std::string &appId); + std::string GetAppidFromCache(const std::string &bundleName, int32_t userId); std::string GetKey(const std::string &bundleName, int32_t userId); static BundleChecker instance_; std::map trusts_; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index ad33b8330..51af0c61e 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -930,6 +930,7 @@ void KvStoreDataService::AccountEventChanged(const AccountEventInfo &eventInfo) MetaDataManager::GetInstance().DelMeta(StoreMetaMapping(meta).GetKey(), true); PermitDelegate::GetInstance().DelCache(meta.GetKeyWithoutPath()); } + CheckerManager::GetInstance().ClearCache(); g_kvStoreAccountEventStatus = 0; break; } diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index d54d0f9d4..739ff5ce6 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -57,6 +57,16 @@ void CheckerManager::DeleteCache(const std::string &bundleName, int32_t user, in } } +void CheckerManager::ClearCache() +{ + for (auto &[name, checker] : checkers_) { + if (checker == nullptr) { + continue; + } + checker->ClearCache(); + } +} + std::string CheckerManager::GetAppId(const 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 651f2bedf..f42f43c61 100644 --- a/services/distributeddataservice/framework/include/checker/checker_manager.h +++ b/services/distributeddataservice/framework/include/checker/checker_manager.h @@ -54,6 +54,7 @@ public: virtual bool IsDynamic(const StoreInfo &info) = 0; virtual bool IsStatic(const StoreInfo &info) = 0; virtual void DeleteCache(const std::string &bundleName, int32_t user, int32_t index){}; + virtual void ClearCache(){}; protected: API_EXPORT ~Checker() = default; }; @@ -70,6 +71,7 @@ public: API_EXPORT void LoadCheckers(std::vector &checkers); API_EXPORT Checker *GetChecker(const std::string &checker); API_EXPORT void DeleteCache(const std::string &bundleName, int32_t user, int32_t index); + API_EXPORT void ClearCache(); private: std::map checkers_; -- Gitee From 723e1ea6a8cca26785ad715a02c2d9a13e3d451e Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 15:09:13 +0800 Subject: [PATCH 09/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 05669176a..3f214601e 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -28,6 +28,7 @@ namespace OHOS { namespace DistributedData { using namespace Security::AccessToken; +constexpr int CACHE_SIZE = 32; __attribute__((used)) BundleChecker BundleChecker::instance_; BundleChecker::BundleChecker() noexcept { @@ -69,7 +70,7 @@ std::string BundleChecker::GetKey(const std::string &bundleName, int32_t userId) std::string BundleChecker::GetAppidFromCache(const std::string &bundleName, int32_t userId) { std::string appId; - std::string key = Getkey(bundleName, userId); + std::string key = GetKey(bundleName, userId); appIds_.Get(key, appId); return appId; } @@ -101,7 +102,7 @@ std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) ZLOGE("GetAppIdByBundleName failed appId:%{public}s, bundleName:%{public}s, uid:%{public}d", appId.c_str(), info.bundleName.c_str(), userId); } else { - appIds_.Set(GetKey(bundleName, userId), appId); + appIds_.Set(GetKey(info.bundleName, userId), appId); } return appId; } @@ -109,7 +110,6 @@ std::string BundleChecker::GetBundleAppId(const CheckerManager::StoreInfo &info) void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int32_t index) { std::string key = GetKey(bundleName, user); - ZLOGI("DeleteAppidCache bundleName:%{public}s, user:%{public}d.", bundleName.c_str(), user); appIds_.Delete(key); } @@ -117,7 +117,7 @@ void BundleChecker::ClearCache() { ZLOGI("ClearAppidCache."); appIds_.ResetCapacity(0); - appIds_.ResetCapacity(32); + appIds_.ResetCapacity(CACHE_SIZE); } std::string BundleChecker::GetAppId(const CheckerManager::StoreInfo &info) -- Gitee From ec1b4946bc975a3186438067de24a862aa193d48 Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 17 Jul 2025 21:34:09 +0800 Subject: [PATCH 10/11] =?UTF-8?q?bundle=E4=BF=A1=E6=81=AF=E5=8A=A0?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bigteer --- .../distributeddataservice/app/src/checker/bundle_checker.cpp | 2 -- .../distributeddataservice/app/src/checker/bundle_checker.h | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 3f214601e..b726ab915 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -28,7 +28,6 @@ namespace OHOS { namespace DistributedData { using namespace Security::AccessToken; -constexpr int CACHE_SIZE = 32; __attribute__((used)) BundleChecker BundleChecker::instance_; BundleChecker::BundleChecker() noexcept { @@ -115,7 +114,6 @@ void BundleChecker::DeleteCache(const std::string &bundleName, int32_t user, int void BundleChecker::ClearCache() { - ZLOGI("ClearAppidCache."); appIds_.ResetCapacity(0); appIds_.ResetCapacity(CACHE_SIZE); } diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 07aadc0c5..1cce99b48 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -40,6 +40,7 @@ public: void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; void ClearCache() override; private: + static constexpr int CACHE_SIZE = 32; std::string GetAppidFromCache(const std::string &bundleName, int32_t userId); std::string GetKey(const std::string &bundleName, int32_t userId); static BundleChecker instance_; @@ -49,7 +50,7 @@ private: std::vector dynamicStores_; std::vector staticStores_; std::string GetBundleAppId(const CheckerManager::StoreInfo &info); - LRUBucket appIds_ {32}; + LRUBucket appIds_ {CACHE_SIZE}; }; } // namespace DistributedData } // namespace OHOS -- Gitee From 8449637af6bf970306153ed90084532992e087c3 Mon Sep 17 00:00:00 2001 From: zhangdi Date: Thu, 17 Jul 2025 14:00:00 +0000 Subject: [PATCH 11/11] update services/distributeddataservice/app/src/checker/bundle_checker.h. Signed-off-by: zhangdi --- .../distributeddataservice/app/src/checker/bundle_checker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 1cce99b48..a7b07159c 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -40,7 +40,7 @@ public: void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; void ClearCache() override; private: - static constexpr int CACHE_SIZE = 32; + static constexpr int32_t CACHE_SIZE = 32; std::string GetAppidFromCache(const std::string &bundleName, int32_t userId); std::string GetKey(const std::string &bundleName, int32_t userId); static BundleChecker instance_; -- Gitee