diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index e823a93e58bf302670f6232ce3eed3b337c83057..1e1c930457c40eb67fa67f1be4193ed226af88fb 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -979,15 +979,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;