diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 4b611a6bd8d31af8a4496472f080cee073117cdc..96ff0576cf9ae9486e68f69d46ef113b0557fe3a 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -990,15 +990,16 @@ pair BundleActiveUsageDatabase::GetDurationData() void BundleActiveUsageDatabase::FlushPackageInfo(uint32_t databaseType, const BundleActivePeriodStats &stats) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); - if (rdbStore == nullptr) { - BUNDLE_ACTIVE_LOGE("flush package info fail, rdbStore is nullptr"); + if (rdbStore == nullptr || stats->bundleStats_.empty()) { + BUNDLE_ACTIVE_LOGE("flush package info fail, rdbStore is nullptr or bundleStats is empty"); return; } string tableName = PACKAGE_LOG_TABLE + to_string(stats.beginTime_); int32_t changeRow = BUNDLE_ACTIVE_FAIL; std::vector valuesBuckets; vector queryCondition; - for (auto iter = stats.bundleStats_.begin(); iter != stats.bundleStats_.end(); iter++) { + auto bundleStats = stats.bundleStats_; + for (auto iter = bundleStats.begin(); iter != bundleStats.end(); iter++) { if (iter->second == nullptr || (iter->second->totalInFrontTime_ == 0 && iter->second->totalContiniousTaskUsedTime_ == 0)) { continue;