From 79c4152333868280d47efaa9db91d174d5ebd0ef Mon Sep 17 00:00:00 2001 From: wkljy Date: Fri, 30 Jan 2026 19:10:56 +0800 Subject: [PATCH] OTA Signed-off-by: wkljy --- .../bundle_mgr_helper.cpp | 14 ++++ .../bundle_mgr_helper.h | 1 + .../insight_intent/insight_intent_db_cache.h | 4 +- .../insight_intent_rdb_storage_mgr.h | 4 +- .../insight_intent_sys_event_receiver.h | 3 +- .../extract_insight_intent_profile.cpp | 2 +- .../insight_intent_db_cache.cpp | 48 ++++++++++--- .../insight_intent_event_mgr.cpp | 9 ++- .../insight_intent_rdb_storage_mgr.cpp | 67 +++++++++++++------ .../insight_intent_sys_event_receiver.cpp | 22 +++--- .../insightintentdbcache_fuzzer.cpp | 4 +- .../insightintentdbcachefirst_fuzzer.cpp | 7 +- .../insightintentrdbstoragemgr_fuzzer.cpp | 9 ++- .../mock/include/bundle_mgr_helper.h | 3 + .../mock/src/mock_bundle_mgr_helper.cpp | 12 ++++ .../include/mock_insight_intent_db_cache.h | 4 +- .../mock/src/mock_insight_intent_db_cache.cpp | 28 ++++++-- .../mock/src/mock_bundle_mgr_helper.cpp | 6 ++ .../mock/src/mock_bundle_mgr_helper.cpp | 6 ++ .../mock/src/mock_bundle_mgr_helper.cpp | 6 ++ .../mock/src/mock_bundle_mgr_helper.cpp | 6 ++ ...insight_intent_sys_event_receiver_test.cpp | 11 +-- .../insight_intent_db_cache_test.cpp | 20 +++--- .../mock_insight_intent_rdb_storage_mgr.cpp | 5 +- .../insight_intent_rdb_storage_mgr_test.cpp | 35 +++++----- 25 files changed, 250 insertions(+), 86 deletions(-) diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index e89db694fc..d0952a4f49 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -613,6 +613,20 @@ ErrCode BundleMgrHelper::GetBundleInfoV9( return bundleMgr->GetBundleInfoV9(bundleName, flags, bundleInfo, userId); } +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called"); + auto bundleMgr = Connect(); + if (bundleMgr == nullptr) { + TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr"); + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } + + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + return bundleMgr->GetBundleInfos(flags, bundleInfos, userId); +} + bool BundleMgrHelper::GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo) { diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index 62bbe2b5f5..25448ccb29 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -72,6 +72,7 @@ public: std::vector &extensionInfos); ErrCode GetBundleInfoV9( const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId); + ErrCode GetBundleInfosV9(int32_t flags, std::vector &bundleInfos, int32_t userId); bool GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo); bool GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo); diff --git a/services/abilitymgr/include/insight_intent/insight_intent_db_cache.h b/services/abilitymgr/include/insight_intent/insight_intent_db_cache.h index 5b90c07bdb..51518a1d5c 100644 --- a/services/abilitymgr/include/insight_intent/insight_intent_db_cache.h +++ b/services/abilitymgr/include/insight_intent/insight_intent_db_cache.h @@ -48,16 +48,18 @@ public: void GetConfigInsightIntentInfo(const std::string &bundleName, const std::string &moduleName, const std::string &intentName, const int32_t userId, InsightIntentInfo &info); int32_t SaveInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, - const int32_t userId, ExtractInsightIntentProfileInfoVec profileInfos, + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec profileInfos, std::vector configInfos); int32_t DeleteInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, const int32_t userId); int32_t DeleteInsightIntentByUserId(const int32_t userId); + bool HasInsightIntentByName(uint32_t versionCode, const std::string &bundleName, const int32_t userId); void BackupRdb(); private: int32_t userId_ = -1; mutable std::mutex genericInfosMutex_; std::map> intentGenericInfos_; + std::map bundleVersionMap_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/include/insight_intent/insight_intent_rdb_storage_mgr.h b/services/abilitymgr/include/insight_intent/insight_intent_rdb_storage_mgr.h index 2f0a9dd7a5..c360f0746b 100644 --- a/services/abilitymgr/include/insight_intent/insight_intent_rdb_storage_mgr.h +++ b/services/abilitymgr/include/insight_intent/insight_intent_rdb_storage_mgr.h @@ -28,7 +28,7 @@ namespace AbilityRuntime { class InsightRdbStorageMgr : public std::enable_shared_from_this { DECLARE_DELAYED_SINGLETON(InsightRdbStorageMgr) public: - int32_t LoadInsightIntentInfos(const int32_t userId, + int32_t LoadInsightIntentInfos(const int32_t userId, std::map &bundleVersionMap, std::vector &totalInfos, std::vector &configInfos); int32_t LoadConfigInsightIntentInfos( const int32_t userId, std::vector &configInfos); @@ -41,7 +41,7 @@ public: int32_t LoadConfigInsightIntentInfo(const std::string &bundleName, const std::string &moduleName, const std::string &intentName, const int32_t userId, InsightIntentInfo &totalInfo); int32_t SaveStorageInsightIntentData(const std::string &bundleName, const std::string &moduleName, - const int32_t userId, ExtractInsightIntentProfileInfoVec &profileInfos, + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec &profileInfos, std::vector &configInfos); int32_t DeleteStorageInsightIntentData(const std::string &bundleName, const std::string &moduleName, const int32_t userId); diff --git a/services/abilitymgr/include/insight_intent/insight_intent_sys_event_receiver.h b/services/abilitymgr/include/insight_intent/insight_intent_sys_event_receiver.h index a3dace99ea..adc441fa2a 100644 --- a/services/abilitymgr/include/insight_intent/insight_intent_sys_event_receiver.h +++ b/services/abilitymgr/include/insight_intent/insight_intent_sys_event_receiver.h @@ -31,7 +31,8 @@ public: void OnReceiveEvent(const EventFwk::CommonEventData &data) override; private: - void SaveInsightIntentInfos(const std::string &bundleName, const std::string &moduleName, int32_t userId); + void SaveInsightIntentInfos(const std::string &bundleName, const std::string &moduleName, + uint32_t versionCode, int32_t userId); void LoadInsightIntentInfos(int32_t userId = -1); void DeleteInsightIntentInfoByUserId(int32_t userId); void HandleBundleScanFinished(); diff --git a/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp b/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp index a349e73871..6b7aba5999 100644 --- a/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp +++ b/services/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp @@ -654,7 +654,7 @@ bool ExtractInsightIntentProfile::TransformTo(const std::string &profileStr, } } - TAG_LOGI(AAFwkTag::INTENT, "transform success, size: %{public}zu", intentInfos.insightIntents.size()); + TAG_LOGD(AAFwkTag::INTENT, "transform success, size: %{public}zu", intentInfos.insightIntents.size()); return true; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp b/services/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp index 4813a124c2..c3e432eac0 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp @@ -33,7 +33,7 @@ int32_t InsightIntentDbCache::InitInsightIntentCache(const int32_t userId) configInfos.clear(); intentGenericInfos_.clear(); if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos( - userId, totalInfos, configInfos) != ERR_OK) { + userId, bundleVersionMap_, totalInfos, configInfos) != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "Load All IntentData failed"); return ERR_INVALID_VALUE; } @@ -55,7 +55,8 @@ InsightIntentDbCache::~InsightIntentDbCache() {} int32_t InsightIntentDbCache::SaveInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, - const int32_t userId, ExtractInsightIntentProfileInfoVec profileInfos, std::vector configInfos) + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec profileInfos, + std::vector configInfos) { std::lock_guard lock(genericInfosMutex_); if (userId != userId_) { @@ -83,6 +84,7 @@ int32_t InsightIntentDbCache::SaveInsightIntentTotalInfo(const std::string &bund } else { intentGenericInfos_[bundleName] = genericInfos; } + bundleVersionMap_[bundleName] = std::to_string(versionCode); int32_t res = DelayedSingleton::GetInstance()->DeleteStorageInsightIntentData(bundleName, moduleName, userId); if (res != ERR_OK) { @@ -90,7 +92,7 @@ int32_t InsightIntentDbCache::SaveInsightIntentTotalInfo(const std::string &bund return res; } return DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( - bundleName, moduleName, userId, profileInfos, configInfos); + bundleName, moduleName, userId, versionCode, profileInfos, configInfos); } int32_t InsightIntentDbCache::DeleteInsightIntentTotalInfo(const std::string &bundleName, @@ -103,7 +105,8 @@ int32_t InsightIntentDbCache::DeleteInsightIntentTotalInfo(const std::string &bu } if (moduleName.empty()) { intentGenericInfos_.erase(bundleName); - } else { + bundleVersionMap_.erase(bundleName); + } else if (intentGenericInfos_.find(bundleName) != intentGenericInfos_.end()) { for (auto iter = intentGenericInfos_[bundleName].begin(); iter != intentGenericInfos_[bundleName].end();) { if (iter->moduleName == moduleName) { iter = intentGenericInfos_[bundleName].erase(iter); @@ -111,6 +114,10 @@ int32_t InsightIntentDbCache::DeleteInsightIntentTotalInfo(const std::string &bu iter++; } } + if (intentGenericInfos_[bundleName].size() == 0) { + intentGenericInfos_.erase(bundleName); + bundleVersionMap_.erase(bundleName); + } } return DelayedSingleton::GetInstance()->DeleteStorageInsightIntentData(bundleName, moduleName, userId); @@ -126,6 +133,22 @@ int32_t InsightIntentDbCache::DeleteInsightIntentByUserId(const int32_t userId) return DelayedSingleton::GetInstance()->DeleteStorageInsightIntentByUserId(userId); } +bool InsightIntentDbCache::HasInsightIntentByName(uint32_t versionCode, + const std::string &bundleName, const int32_t userId) +{ + std::lock_guard lock(genericInfosMutex_); + if (userId != userId_) { + TAG_LOGW(AAFwkTag::INTENT, "error userId %{public}d.", userId_); + return false; + } + if (bundleVersionMap_.find(bundleName) != bundleVersionMap_.end() && + bundleVersionMap_[bundleName].compare(std::to_string(versionCode)) == 0) { + return true; + } + TAG_LOGD(AAFwkTag::INTENT, "null bundleName %{public}s", bundleName.c_str()); + return false; +} + void InsightIntentDbCache::GetAllInsightIntentGenericInfo(const int32_t userId, std::vector &genericInfos) { @@ -139,8 +162,9 @@ void InsightIntentDbCache::GetAllInsightIntentGenericInfo(const int32_t userId, std::vector totalInfos; std::vector configInfos; - if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos(userId, totalInfos, - configInfos) != ERR_OK) { + std::map bundleVersionMap; + if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos(userId, + bundleVersionMap, totalInfos, configInfos) != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "Load All IntentData failed"); return; } @@ -155,7 +179,9 @@ void InsightIntentDbCache::GetInsightIntentGenericInfoByName(const std::string & { if (userId == userId_) { std::lock_guard lock(genericInfosMutex_); - genericInfos = intentGenericInfos_[bundleName]; + if (intentGenericInfos_.find(bundleName) != intentGenericInfos_.end()) { + genericInfos = intentGenericInfos_[bundleName]; + } return; } @@ -177,6 +203,9 @@ void InsightIntentDbCache::GetInsightIntentGenericInfo(const std::string &bundle { if (userId == userId_) { std::lock_guard lock(genericInfosMutex_); + if (intentGenericInfos_.find(bundleName) == intentGenericInfos_.end()) { + return; + } for (auto info : intentGenericInfos_[bundleName]) { if (info.moduleName == moduleName && info.intentName == intentName) { genericInfo = info; @@ -198,8 +227,9 @@ void InsightIntentDbCache::GetAllInsightIntentInfo(const int32_t userId, std::ve std::vector &configInfos) { std::lock_guard lock(genericInfosMutex_); - if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos( - userId, infos, configInfos) != ERR_OK) { + std::map bundleVersionMap; + if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos(userId, + bundleVersionMap, infos, configInfos) != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "LoadIntentData failed"); return; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp b/services/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp index a6854af61a..f869bc7771 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp @@ -73,7 +73,12 @@ void InsightIntentEventMgr::UpdateInsightIntentEvent(const AppExecFwk::ElementNa TAG_LOGE(AAFwkTag::INTENT, "get bundleMgrHelper instance failed"); return; } - + AppExecFwk::BundleInfo bundleInfo; + if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_DEFAULT), bundleInfo, userId))) { + TAG_LOGE(AAFwkTag::INTENT, "get bundle info failed"); + return; + } OHOS::SplitStr(moduleName, ",", moduleNameVec); for (std::string moduleNameLocal : moduleNameVec) { // Get json profile firstly ret = IN_PROCESS_CALL(bundleMgrHelper->GetJsonProfile(AppExecFwk::INTENT_PROFILE, @@ -97,7 +102,7 @@ void InsightIntentEventMgr::UpdateInsightIntentEvent(const AppExecFwk::ElementNa // save database DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo( - bundleName, moduleNameLocal, userId, infos, configIntentInfos); + bundleName, moduleNameLocal, userId, bundleInfo.versionCode, infos, configIntentInfos); } DelayedSingleton::GetInstance()->BackupRdb(); }); diff --git a/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp b/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp index 51b512f948..f30e18c762 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp @@ -15,9 +15,13 @@ #include "insight_intent_rdb_storage_mgr.h" #include "nlohmann/json.hpp" +#include namespace OHOS { namespace AbilityRuntime { +const int32_t BUNDLE_NAME = 1; +const int32_t VERSION = 4; +const int32_t INTENT_KEY_LENGTH = 5; InsightRdbStorageMgr::InsightRdbStorageMgr() { } @@ -27,8 +31,21 @@ InsightRdbStorageMgr::~InsightRdbStorageMgr() TAG_LOGD(AAFwkTag::INTENT, "InsightRdbStorageMgr is deleted"); } +std::vector SplitStringBySlash(const std::string& inputStr) +{ + std::vector result; + std::stringstream ss(inputStr); + std::string tempStr; + + while (std::getline(ss, tempStr, '/')) { + result.push_back(tempStr); + } + return result; +} + int32_t InsightRdbStorageMgr::LoadInsightIntentInfos(const int32_t userId, - std::vector &totalInfos, std::vector &configInfos) + std::map &bundleVersionMap, std::vector &totalInfos, + std::vector &configInfos) { TAG_LOGD(AAFwkTag::INTENT, "InsightRdbStorageMgr load all intent total infos"); std::unordered_map value; @@ -39,6 +56,13 @@ int32_t InsightRdbStorageMgr::LoadInsightIntentInfos(const int32_t userId, return ERR_INVALID_VALUE; } Transform(value, totalInfos, configInfos); + for (const auto &item : value) { + std::vector res = SplitStringBySlash(item.first); + if (res.size() < INTENT_KEY_LENGTH) { + continue; + } + bundleVersionMap[res[BUNDLE_NAME]] = res[VERSION]; + } return ERR_OK; } @@ -92,18 +116,19 @@ int32_t InsightRdbStorageMgr::LoadInsightIntentInfo(const std::string &bundleNam const std::string &intentName, const int32_t userId, ExtractInsightIntentInfo &totalInfo) { TAG_LOGD(AAFwkTag::INTENT, "InsightRdbStorageMgr load intent total info"); - std::string value; + std::unordered_map value; std::string key = std::to_string(userId).append("/").append(bundleName).append("/") .append(moduleName).append("/").append(intentName); - bool result = DelayedSingleton::GetInstance()->QueryData(key, value); - if (!result) { + bool result = DelayedSingleton::GetInstance()->QueryDataBeginWithKey(key, value); + if (!result || value.size() == 0) { TAG_LOGW(AAFwkTag::INTENT, "get entries error"); return ERR_INVALID_VALUE; } ExtractInsightIntentProfileInfoVec profileInfos; - if (!ExtractInsightIntentProfile::TransformTo(value, profileInfos)) { + //only one intent + if (!ExtractInsightIntentProfile::TransformTo(value.begin()->second, profileInfos)) { TAG_LOGE(AAFwkTag::INTENT, "error key: %{private}s", key.c_str()); - DelayedSingleton::GetInstance()->DeleteData(key); + DelayedSingleton::GetInstance()->DeleteDataBeginWithKey(key); } for (const auto &profileInfo : profileInfos.insightIntents) { if (!ExtractInsightIntentProfile::ProfileInfoFormat(profileInfo, totalInfo)) { @@ -117,18 +142,19 @@ int32_t InsightRdbStorageMgr::LoadConfigInsightIntentInfo(const std::string &bun const std::string &intentName, const int32_t userId, InsightIntentInfo &totalInfo) { TAG_LOGD(AAFwkTag::INTENT, "InsightRdbStorageMgr load intent total info"); - std::string value; + std::unordered_map value; std::string key = std::to_string(userId).append("/").append(bundleName).append("/") .append(moduleName).append("/").append(intentName); - bool result = DelayedSingleton::GetInstance()->QueryData(key, value); - if (!result) { + bool result = DelayedSingleton::GetInstance()->QueryDataBeginWithKey(key, value); + if (!result || value.size() == 0) { TAG_LOGW(AAFwkTag::INTENT, "get entries error"); return ERR_INVALID_VALUE; } std::vector configIntentInfos; - if (!InsightIntentProfile::TransformTo(value, configIntentInfos)) { + //only one intent + if (!InsightIntentProfile::TransformTo(value.begin()->second, configIntentInfos)) { TAG_LOGE(AAFwkTag::INTENT, "error key: %{private}s", key.c_str()); - DelayedSingleton::GetInstance()->DeleteData(key); + DelayedSingleton::GetInstance()->DeleteDataBeginWithKey(key); } for (const auto &configInfo : configIntentInfos) { totalInfo = configInfo; @@ -144,7 +170,7 @@ void InsightRdbStorageMgr::TransformConfigIntent(std::unordered_map configIntentInfos; if (!InsightIntentProfile::TransformTo(item.second, configIntentInfos)) { TAG_LOGE(AAFwkTag::INTENT, "error key: %{private}s", item.first.c_str()); - DelayedSingleton::GetInstance()->DeleteData(item.first); + DelayedSingleton::GetInstance()->DeleteDataBeginWithKey(item.first); } for (const auto &configIntentInfo : configIntentInfos) { configInfos.emplace_back(configIntentInfo); @@ -159,7 +185,8 @@ void InsightRdbStorageMgr::Transform(std::unordered_map::GetInstance()->DeleteData(item.first); + DelayedSingleton::GetInstance()->DeleteDataBeginWithKey(item.first); + continue; } for (const auto &profileInfo : profileInfos.insightIntents) { ExtractInsightIntentInfo totalInfo; @@ -173,7 +200,8 @@ void InsightRdbStorageMgr::Transform(std::unordered_map configIntentInfos; if (!InsightIntentProfile::TransformTo(item.second, configIntentInfos)) { TAG_LOGE(AAFwkTag::INTENT, "error key: %{private}s", item.first.c_str()); - DelayedSingleton::GetInstance()->DeleteData(item.first); + DelayedSingleton::GetInstance()->DeleteDataBeginWithKey(item.first); + continue; } for (const auto &configIntentInfo : configIntentInfos) { configInfos.emplace_back(configIntentInfo); @@ -182,12 +210,13 @@ void InsightRdbStorageMgr::Transform(std::unordered_map &configInfos) + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec &profileInfos, + std::vector &configInfos) { std::lock_guard lock(rdbStorePtrMutex_); for (auto profileInfo : profileInfos.insightIntents) { - std::string key = std::to_string(userId).append("/").append(bundleName).append("/") - .append(moduleName).append("/").append(profileInfo.intentName); + std::string key = std::to_string(userId).append("/").append(bundleName).append("/").append(moduleName). + append("/").append(profileInfo.intentName).append("/").append(std::to_string(versionCode)); nlohmann::json jsonObject; if (!ExtractInsightIntentProfile::ToJson(profileInfo, jsonObject)) { TAG_LOGE(AAFwkTag::INTENT, "Transform error, key: %{private}s", key.c_str()); @@ -199,8 +228,8 @@ int32_t InsightRdbStorageMgr::SaveStorageInsightIntentData(const std::string &bu } } for (auto configInfo : configInfos) { - std::string key = std::to_string(userId).append("/").append(bundleName).append("/") - .append(moduleName).append("/").append(configInfo.intentName); + std::string key = std::to_string(userId).append("/").append(bundleName).append("/").append(moduleName). + append("/").append(configInfo.intentName).append("/").append(std::to_string(versionCode)); nlohmann::json jsonObject; configInfo.moduleName = moduleName; configInfo.bundleName = bundleName; diff --git a/services/abilitymgr/src/insight_intent/insight_intent_sys_event_receiver.cpp b/services/abilitymgr/src/insight_intent/insight_intent_sys_event_receiver.cpp index d2a1e70621..afa8f6b88b 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_sys_event_receiver.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_sys_event_receiver.cpp @@ -37,7 +37,7 @@ InsightIntentSysEventReceiver::InsightIntentSysEventReceiver(const EventFwk::Com } void InsightIntentSysEventReceiver::SaveInsightIntentInfos(const std::string &bundleName, const std::string &moduleName, - int32_t userId) + uint32_t versionCode, int32_t userId) { std::vector moduleNameVec; std::string profile; @@ -75,7 +75,7 @@ void InsightIntentSysEventReceiver::SaveInsightIntentInfos(const std::string &bu // save database ret = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo( - bundleName, moduleNameLocal, userId, infos, configIntentInfos); + bundleName, moduleNameLocal, userId, versionCode, infos, configIntentInfos); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "save intent info failed, bundleName: %{public}s, moduleName: %{public}s, " "userId: %{public}d", bundleName.c_str(), moduleNameLocal.c_str(), userId); @@ -103,7 +103,6 @@ void InsightIntentSysEventReceiver::LoadInsightIntentInfos(int32_t userId) if (DelayedSingleton::GetInstance()-> InitInsightIntentCache(userId) == ERR_OK) { TAG_LOGI(AAFwkTag::INTENT, "Load intent from db success"); - return; } auto bundleMgrHelper = DelayedSingleton::GetInstance(); @@ -113,24 +112,29 @@ void InsightIntentSysEventReceiver::LoadInsightIntentInfos(int32_t userId) } std::vector bundleInfos {}; - if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfos(AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfos, - userId))) { + if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfosV9( + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE), + bundleInfos, userId))) { TAG_LOGE(AAFwkTag::INTENT, "get bundle info failed"); return; } TAG_LOGI(AAFwkTag::INTENT, "bundleInfos size: %{public}zu", bundleInfos.size()); - bool hasIntent = false; + bool hasNewIntent = false; for (auto &bundleInfo : bundleInfos) { + if (DelayedSingleton::GetInstance()-> + HasInsightIntentByName(bundleInfo.versionCode, bundleInfo.name, userId)) { + continue; + } for (const auto &hapInfo : bundleInfo.hapModuleInfos) { if (!hapInfo.hasIntent) { continue; } - SaveInsightIntentInfos(bundleInfo.name, hapInfo.moduleName, userId); - hasIntent = true; + SaveInsightIntentInfos(bundleInfo.name, hapInfo.moduleName, bundleInfo.versionCode, userId); + hasNewIntent = true; } } - if (hasIntent) { + if (hasNewIntent) { DelayedSingleton::GetInstance()->BackupRdb(); } } diff --git a/test/fuzztest/insightintentdbcache_fuzzer/insightintentdbcache_fuzzer.cpp b/test/fuzztest/insightintentdbcache_fuzzer/insightintentdbcache_fuzzer.cpp index 0f434c1ad3..a964b0fef3 100644 --- a/test/fuzztest/insightintentdbcache_fuzzer/insightintentdbcache_fuzzer.cpp +++ b/test/fuzztest/insightintentdbcache_fuzzer/insightintentdbcache_fuzzer.cpp @@ -29,6 +29,7 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace { constexpr size_t STRING_MAX_LENGTH = 128; +constexpr size_t U32_AT_SIZE = 4; } bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { @@ -51,12 +52,13 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); intentName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + uint32_t versionCode = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); profileInfos.insightIntents.push_back(info); AbilityFuzzUtil::GetRandomExtractInsightIntentGenericInfo(fdp, genericInfo); AbilityFuzzUtil::GetRandomExtractInsightIntentInfo(fdp, intentInfo); DelayedSingleton::GetInstance()->InitInsightIntentCache(userId); DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, moduleName, - userId, profileInfos, configIntentInfos); + userId, versionCode, profileInfos, configIntentInfos); DelayedSingleton::GetInstance()->DeleteInsightIntentTotalInfo(bundleName, moduleName, userId); DelayedSingleton::GetInstance()->DeleteInsightIntentByUserId(userId); diff --git a/test/fuzztest/insightintentdbcachefirst_fuzzer/insightintentdbcachefirst_fuzzer.cpp b/test/fuzztest/insightintentdbcachefirst_fuzzer/insightintentdbcachefirst_fuzzer.cpp index a6f2ffe56f..37cf264386 100644 --- a/test/fuzztest/insightintentdbcachefirst_fuzzer/insightintentdbcachefirst_fuzzer.cpp +++ b/test/fuzztest/insightintentdbcachefirst_fuzzer/insightintentdbcachefirst_fuzzer.cpp @@ -40,6 +40,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int32_t userId = 100; int32_t userId2 = 101; int32_t userId3 = 102; + uint32_t versionCode = 0; ExtractInsightIntentProfileInfo profileInfo; ExtractInsightIntentProfileInfoVec profileInfos; @@ -72,8 +73,10 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) insightIntentDbCache->InitInsightIntentCache(userId); insightIntentDbCache->InitInsightIntentCache(userId2); - insightIntentDbCache->SaveInsightIntentTotalInfo(bundleName, moduleName, userId2, profileInfos, configIntentInfos); - insightIntentDbCache->SaveInsightIntentTotalInfo(bundleName, moduleName, userId, profileInfos, configIntentInfos); + insightIntentDbCache->SaveInsightIntentTotalInfo(bundleName, moduleName, userId2, + versionCode, profileInfos, configIntentInfos); + insightIntentDbCache->SaveInsightIntentTotalInfo(bundleName, moduleName, userId, + versionCode, profileInfos, configIntentInfos); insightIntentDbCache->DeleteInsightIntentTotalInfo(bundleName, moduleName, userId2); insightIntentDbCache->DeleteInsightIntentTotalInfo(bundleName, emptyModuleName, userId2); diff --git a/test/fuzztest/insightintentrdbstoragemgr_fuzzer/insightintentrdbstoragemgr_fuzzer.cpp b/test/fuzztest/insightintentrdbstoragemgr_fuzzer/insightintentrdbstoragemgr_fuzzer.cpp index bfcc301cd4..3c80349c85 100644 --- a/test/fuzztest/insightintentrdbstoragemgr_fuzzer/insightintentrdbstoragemgr_fuzzer.cpp +++ b/test/fuzztest/insightintentrdbstoragemgr_fuzzer/insightintentrdbstoragemgr_fuzzer.cpp @@ -33,6 +33,7 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace { constexpr size_t STRING_MAX_LENGTH = 128; +constexpr size_t U32_AT_SIZE = 4; } bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { @@ -44,6 +45,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::unordered_map valueVec; std::string key = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); std::string value = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + uint32_t versionCode = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); valueVec[key] = value; userId = fdp.ConsumeIntegral(); std::vector configInfos; @@ -51,7 +53,9 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::vector totalInfos; ExtractInsightIntentInfo totalInfo; ExtractInsightIntentProfileInfoVec profileInfos; - DelayedSingleton::GetInstance()->LoadInsightIntentInfos(userId, totalInfos, configInfos); + std::map bundleVersionMap; + DelayedSingleton::GetInstance()-> + LoadInsightIntentInfos(userId, bundleVersionMap, totalInfos, configInfos); DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfos(userId, configInfos); DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfoByName(bundleName, userId, configInfos); DelayedSingleton::GetInstance()->LoadInsightIntentInfoByName(bundleName, userId, totalInfos); @@ -59,7 +63,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfo(bundleName, moduleName, intentName, userId, configInfo); DelayedSingleton::GetInstance()->TransformConfigIntent(valueVec, configInfos); DelayedSingleton::GetInstance()->Transform(valueVec, totalInfos, configInfos); - DelayedSingleton::GetInstance()->SaveStorageInsightIntentData(bundleName, moduleName, userId, profileInfos, configInfos); + DelayedSingleton::GetInstance()-> + SaveStorageInsightIntentData(bundleName, moduleName, userId, versionCode, profileInfos, configInfos); DelayedSingleton::GetInstance()->DeleteStorageInsightIntentByUserId(userId); DelayedSingleton::GetInstance()->DeleteStorageInsightIntentData(bundleName, moduleName, userId); return true; diff --git a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h index 8e7a3c0371..5283882b0f 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h +++ b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h @@ -44,6 +44,9 @@ public: bool GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo); ErrCode GetNameForUid(const int32_t uid, std::string &name); bool QueryAppGalleryBundleName(std::string &bundleName); + ErrCode GetBundleInfoV9( + const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId); + ErrCode GetBundleInfosV9(int32_t flags, std::vector &bundleInfos, int32_t userId); private: DECLARE_DELAYED_SINGLETON(BundleMgrHelper) diff --git a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp index c579fc0be6..673a2caeda 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp @@ -106,6 +106,18 @@ bool BundleMgrHelper::GetBundleInfo( return true; } +ErrCode BundleMgrHelper::GetBundleInfoV9( + const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + return ERR_OK; +} + ErrCode BundleMgrHelper::GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex, BundleInfo &bundleInfo, int32_t userId) { diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_insight_intent_db_cache.h b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_insight_intent_db_cache.h index 296eb7206d..f807c6dc4f 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_insight_intent_db_cache.h +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_insight_intent_db_cache.h @@ -50,16 +50,18 @@ public: void GetConfigInsightIntentInfo(const std::string &bundleName, const std::string &moduleName, const std::string &intentName, const int32_t userId, InsightIntentInfo &info); int32_t SaveInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, - const int32_t userId, ExtractInsightIntentProfileInfoVec profileInfos, + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec profileInfos, std::vector configInfos); int32_t DeleteInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, const int32_t userId); int32_t DeleteInsightIntentByUserId(const int32_t userId); + bool HasInsightIntentByName(uint32_t versionCode, const std::string &bundleName, const int32_t userId); void BackupRdb(); private: int32_t userId_ = -1; mutable std::mutex genericInfosMutex_; std::map> intentGenericInfos_; + std::map bundleVersionMap_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_insight_intent_db_cache.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_insight_intent_db_cache.cpp index 9ddc6a724e..f67db48e60 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_insight_intent_db_cache.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_insight_intent_db_cache.cpp @@ -30,11 +30,12 @@ int32_t InsightIntentDbCache::InitInsightIntentCache(const int32_t userId) } std::vector totalInfos; std::vector configInfos; + std::map bundleVersionMap; totalInfos.clear(); configInfos.clear(); intentGenericInfos_.clear(); if (DelayedSingleton::GetInstance()->LoadInsightIntentInfos( - userId, totalInfos, configInfos) != ERR_OK) { + userId, bundleVersionMap, totalInfos, configInfos) != ERR_OK) { TAG_LOGE(AAFwkTag::INTENT, "Load All IntentData failed"); return ERR_INVALID_VALUE; } @@ -55,7 +56,8 @@ InsightIntentDbCache::~InsightIntentDbCache() {} int32_t InsightIntentDbCache::SaveInsightIntentTotalInfo(const std::string &bundleName, const std::string &moduleName, - const int32_t userId, ExtractInsightIntentProfileInfoVec profileInfos, std::vector configInfos) + const int32_t userId, uint32_t versionCode, ExtractInsightIntentProfileInfoVec profileInfos, + std::vector configInfos) { std::lock_guard lock(genericInfosMutex_); if (userId != userId_) { @@ -83,13 +85,31 @@ int32_t InsightIntentDbCache::SaveInsightIntentTotalInfo(const std::string &bund } else { intentGenericInfos_[bundleName] = genericInfos; } + bundleVersionMap_[bundleName] = std::to_string(versionCode); int32_t res = DelayedSingleton::GetInstance()->DeleteStorageInsightIntentData(bundleName, moduleName, userId); if (res != ERR_OK) { TAG_LOGW(AAFwkTag::INTENT, "Save before delete key error"); } - return DelayedSingleton::GetInstance() - ->SaveStorageInsightIntentData(bundleName, moduleName, userId, profileInfos, configInfos); + return DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( + bundleName, moduleName, userId, versionCode, profileInfos, configInfos); +} + +bool InsightIntentDbCache::HasInsightIntentByName(uint32_t versionCode, + const std::string &bundleName, const int32_t userId) +{ + std::lock_guard lock(genericInfosMutex_); + if (userId != userId_) { + TAG_LOGW(AAFwkTag::INTENT, "error userId %{public}d.", userId_); + return false; + } + if (intentGenericInfos_.find(bundleName) != intentGenericInfos_.end() && + bundleVersionMap_.find(bundleName) != bundleVersionMap_.end() && + bundleVersionMap_[bundleName].compare(std::to_string(versionCode)) == 0) { + return true; + } + TAG_LOGW(AAFwkTag::INTENT, "null bundleName %{public}s", bundleName.c_str()); + return false; } int32_t InsightIntentDbCache::DeleteInsightIntentTotalInfo(const std::string &bundleName, diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp index 66f2ffa379..ef9303a938 100755 --- a/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp @@ -203,6 +203,12 @@ ErrCode BundleMgrHelper::GetBundleInfoV9(const std::string& bundleName, return ERR_OK; } +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + return ERR_OK; +} + bool BundleMgrHelper::GetApplicationInfo( const std::string& appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo& appInfo) { diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp index 3ae3a8a6fd..e2f5808e6f 100755 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp @@ -199,6 +199,12 @@ ErrCode BundleMgrHelper::GetBundleInfoV9(const std::string& bundleName, return AAFwk::MyStatus::GetInstance().getBundleInfoV9_; } +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + return ERR_OK; +} + bool BundleMgrHelper::GetApplicationInfo( const std::string& appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo& appInfo) { diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_bundle_mgr_helper.cpp index a895e898f8..ec7fc1e1b4 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_bundle_mgr_helper.cpp @@ -199,6 +199,12 @@ ErrCode BundleMgrHelper::GetBundleInfoV9(const std::string& bundleName, return AAFwk::MyStatus::GetInstance().getBundleInfoV9_; } +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + return ERR_OK; +} + bool BundleMgrHelper::GetApplicationInfo( const std::string& appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo& appInfo) { diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp index 1c1ba5cdf7..f7e5e2dae4 100755 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp @@ -197,6 +197,12 @@ ErrCode BundleMgrHelper::GetBundleInfoV9(const std::string& bundleName, return AAFwk::MyStatus::GetInstance().getBundleInfoV9_; } +ErrCode BundleMgrHelper::GetBundleInfosV9(int32_t flags, + std::vector &bundleInfos, int32_t userId) +{ + return ERR_OK; +} + bool BundleMgrHelper::GetApplicationInfo( const std::string& appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo& appInfo) { diff --git a/test/unittest/insight_intent/insight_intent_sys_event_receiver_test/insight_intent_sys_event_receiver_test.cpp b/test/unittest/insight_intent/insight_intent_sys_event_receiver_test/insight_intent_sys_event_receiver_test.cpp index 6c6583785f..f69d2d3be3 100644 --- a/test/unittest/insight_intent/insight_intent_sys_event_receiver_test/insight_intent_sys_event_receiver_test.cpp +++ b/test/unittest/insight_intent/insight_intent_sys_event_receiver_test/insight_intent_sys_event_receiver_test.cpp @@ -106,26 +106,27 @@ HWTEST_F(InsightIntentSysEventReceiverTest, SaveInsightIntentInfos_0002, TestSiz { // 局部变量定义 EventFwk::CommonEventSubscribeInfo subscribeInfo; + uint32_t ver = 0; auto sysEventReceiver = std::make_shared(subscribeInfo); // 测试1: 无效bundle名称 - sysEventReceiver->SaveInsightIntentInfos(INVALID_BUNDLE_NAME, TEST_MODULE_NAME, MAIN_USER_ID); + sysEventReceiver->SaveInsightIntentInfos(INVALID_BUNDLE_NAME, TEST_MODULE_NAME, ver, MAIN_USER_ID); EXPECT_EQ(sysEventReceiver->lastUserId_, 0); // 验证对象状态正常,未被异常影响 // 测试2: 空模块名称 - sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, EMPTY_MODULE_NAME, MAIN_USER_ID); + sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, EMPTY_MODULE_NAME, ver, MAIN_USER_ID); EXPECT_EQ(sysEventReceiver->lastUserId_, 0); // 测试3: 多模块名称 - sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, MULTI_MODULE_NAME, MAIN_USER_ID); + sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, MULTI_MODULE_NAME, ver, MAIN_USER_ID); EXPECT_EQ(sysEventReceiver->lastUserId_, 0); // 测试4: 无效用户ID - sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, TEST_MODULE_NAME, INVALID_USER_ID); + sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, TEST_MODULE_NAME, ver, INVALID_USER_ID); EXPECT_EQ(sysEventReceiver->lastUserId_, 0); // 测试5: 合法参数 - sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, TEST_MODULE_NAME, MAIN_USER_ID); + sysEventReceiver->SaveInsightIntentInfos(TEST_BUNDLE_NAME, TEST_MODULE_NAME, ver, MAIN_USER_ID); EXPECT_EQ(sysEventReceiver->lastUserId_, 0); } diff --git a/test/unittest/insight_intent_db_cache_test/insight_intent_db_cache_test.cpp b/test/unittest/insight_intent_db_cache_test/insight_intent_db_cache_test.cpp index aa8699da7a..821ccad62c 100644 --- a/test/unittest/insight_intent_db_cache_test/insight_intent_db_cache_test.cpp +++ b/test/unittest/insight_intent_db_cache_test/insight_intent_db_cache_test.cpp @@ -74,14 +74,14 @@ HWTEST_F(InsightIntentDbCacheTest, InsightIntentDbCacheTest_001, TestSize.Level0 DelayedSingleton::GetInstance()->InitInsightIntentCache(userId); MockSaveData(false); auto result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, 100, profileInfos, configInfos); + moduleName, 100, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_INVALID_VALUE); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_INVALID_VALUE); MockSaveData(true); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); @@ -121,7 +121,7 @@ HWTEST_F(InsightIntentDbCacheTest, InsightIntentDbCacheTest_002, TestSize.Level0 EXPECT_EQ(result, ERR_OK); moduleName = "qwe"; DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); result = DelayedSingleton::GetInstance()->DeleteInsightIntentTotalInfo(bundleName, moduleName, userId); EXPECT_EQ(result, ERR_OK); @@ -156,14 +156,14 @@ HWTEST_F(InsightIntentDbCacheTest, InsightIntentDbCacheTest_003, TestSize.Level0 DelayedSingleton::GetInstance()->InitInsightIntentCache(userId); MockSaveData(false); auto result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, 100, profileInfos, configInfos); + moduleName, 100, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_INVALID_VALUE); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_INVALID_VALUE); MockSaveData(true); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); std::vector configInfos1; DelayedSingleton::GetInstance()->GetConfigInsightIntentInfoByName(bundleName, @@ -209,15 +209,15 @@ HWTEST_F(InsightIntentDbCacheTest, InsightIntentDbCacheTest_004, TestSize.Level0 DelayedSingleton::GetInstance()->InitInsightIntentCache(userId); MockSaveData(false); auto result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, 100, profileInfos, configInfos); + moduleName, 100, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_INVALID_VALUE); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); DelayedSingleton::GetInstance()->BackupRdb(); EXPECT_EQ(result, ERR_INVALID_VALUE); MockSaveData(true); result = DelayedSingleton::GetInstance()->SaveInsightIntentTotalInfo(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); std::vector genericInfos; diff --git a/test/unittest/insight_intent_db_cache_test/mock_insight_intent_rdb_storage_mgr.cpp b/test/unittest/insight_intent_db_cache_test/mock_insight_intent_rdb_storage_mgr.cpp index fdfce01d67..64a0835c9d 100644 --- a/test/unittest/insight_intent_db_cache_test/mock_insight_intent_rdb_storage_mgr.cpp +++ b/test/unittest/insight_intent_db_cache_test/mock_insight_intent_rdb_storage_mgr.cpp @@ -88,6 +88,7 @@ InsightRdbStorageMgr::~InsightRdbStorageMgr() } int32_t InsightRdbStorageMgr::LoadInsightIntentInfos(const int32_t userId, + std::map &bundleVersionMap, std::vector &totalInfos, std::vector &configInfos) { ExtractInsightIntentInfo totalInfo; @@ -147,8 +148,8 @@ int32_t InsightRdbStorageMgr::LoadInsightIntentInfo(const std::string &bundleNa } int32_t InsightRdbStorageMgr::SaveStorageInsightIntentData(const std::string &bundleName, - const std::string &moduleName, const int32_t userId, ExtractInsightIntentProfileInfoVec &profileInfos, - std::vector &configInfos) + const std::string &moduleName, const int32_t userId, uint32_t versionCode, + ExtractInsightIntentProfileInfoVec &profileInfos, std::vector &configInfos) { if (g_mockSaveStorageInsightIntentDataRet) { return ERR_OK; diff --git a/test/unittest/insight_intent_rdb_storage_mgr_test/insight_intent_rdb_storage_mgr_test.cpp b/test/unittest/insight_intent_rdb_storage_mgr_test/insight_intent_rdb_storage_mgr_test.cpp index 1a7940e43b..c6f1efaba2 100644 --- a/test/unittest/insight_intent_rdb_storage_mgr_test/insight_intent_rdb_storage_mgr_test.cpp +++ b/test/unittest/insight_intent_rdb_storage_mgr_test/insight_intent_rdb_storage_mgr_test.cpp @@ -92,14 +92,15 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_003, Tes int32_t userId = 0; std::string bundleName; std::string moduleName; + uint32_t versionCode = 0; ExtractInsightIntentProfileInfoVec profileInfos; std::vector configInfos; MockInsertData(false); auto result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, versionCode, profileInfos, configInfos); MockInsertData(true); result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData(bundleName, - moduleName, userId, profileInfos, configInfos); + moduleName, userId, versionCode, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -113,11 +114,14 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_004, Tes int32_t userId = 0; std::vector infos; std::vector configInfos; + std::map bundleVersionMap; + MockQueryDataBeginWithKey(false); auto result = DelayedSingleton::GetInstance()->LoadInsightIntentInfos( - userId, infos, configInfos); + userId, bundleVersionMap, infos, configInfos); MockQueryDataBeginWithKey(true); - result = DelayedSingleton::GetInstance()->LoadInsightIntentInfos(userId, infos, configInfos); + result = DelayedSingleton::GetInstance()-> + LoadInsightIntentInfos(userId, bundleVersionMap, infos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -152,10 +156,10 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_006, Tes std::string moduleName; std::string intentName; ExtractInsightIntentInfo infos; - MockQueryData(false); + MockQueryDataBeginWithKey(false); auto result = DelayedSingleton::GetInstance()->LoadInsightIntentInfo(bundleName, moduleName, intentName, userId, infos); - MockQueryData(true); + MockQueryDataBeginWithKey(true); result = DelayedSingleton::GetInstance()->LoadInsightIntentInfo(bundleName, moduleName, intentName, userId, infos); EXPECT_EQ(result, ERR_OK); @@ -210,10 +214,10 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_009, Tes std::string moduleName; std::string intentName; InsightIntentInfo infos; - MockQueryData(false); + MockQueryDataBeginWithKey(false); auto result = DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfo(bundleName, moduleName, intentName, userId, infos); - MockQueryData(true); + MockQueryDataBeginWithKey(true); result = DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfo(bundleName, moduleName, intentName, userId, infos); EXPECT_EQ(result, ERR_OK); @@ -259,7 +263,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_011, Tes profileInfos.insightIntents.push_back(profileInfo); auto result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( - bundleName, moduleName, userId, profileInfos, configInfos); + bundleName, moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -281,7 +285,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_012, Tes configInfos.push_back(configInfo); auto result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( - bundleName, moduleName, userId, profileInfos, configInfos); + bundleName, moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -298,7 +302,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_013, Tes std::string intentName = "testIntent"; ExtractInsightIntentInfo totalInfo; - MockQueryData(true); + MockQueryDataBeginWithKey(true); auto result = DelayedSingleton::GetInstance()->LoadInsightIntentInfo( bundleName, moduleName, intentName, userId, totalInfo); EXPECT_EQ(result, ERR_OK); @@ -317,7 +321,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_014, Tes std::string intentName = "testIntent"; InsightIntentInfo totalInfo; - MockQueryData(true); + MockQueryDataBeginWithKey(true); auto result = DelayedSingleton::GetInstance()->LoadConfigInsightIntentInfo( bundleName, moduleName, intentName, userId, totalInfo); EXPECT_EQ(result, ERR_OK); @@ -349,10 +353,11 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_016, Tes int32_t userId = 0; std::vector totalInfos; std::vector configInfos; + std::map bundleVersionMap; MockQueryDataBeginWithKey(true); auto result = DelayedSingleton::GetInstance()->LoadInsightIntentInfos( - userId, totalInfos, configInfos); + userId, bundleVersionMap, totalInfos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -375,7 +380,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_018, Tes MockInsertData(false); auto result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( - bundleName, moduleName, userId, profileInfos, configInfos); + bundleName, moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); } @@ -398,7 +403,7 @@ HWTEST_F(InsightIntentRdbStorageMgrTest, InsightIntentRdbStorageMgrTest_019, Tes MockInsertData(false); auto result = DelayedSingleton::GetInstance()->SaveStorageInsightIntentData( - bundleName, moduleName, userId, profileInfos, configInfos); + bundleName, moduleName, userId, 0, profileInfos, configInfos); EXPECT_EQ(result, ERR_OK); } }