diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 41123f45a36e259a46c80f2d5633dd3b9ae34734..95427ae137941b48e0efcfeff692d7ecb7ef9108 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -126,6 +126,9 @@ private: const int64_t endTime, const int32_t databaseType, const int32_t index, const int32_t startIndex, const int32_t endIndex, const int32_t userId, std::vector &queryCondition, std::string &queryPackageSql); + void GetCurrentBundleStats(int64_t currentPackageTime, + std::shared_ptr& bundleActiveResult, + std::shared_ptr& intervalStats); bool GetDbIndex(const int64_t beginTime, const int64_t endTime, const int32_t databaseType, int32_t &startIndex, int32_t &endIndex); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 2a42d0af40df5baac3564c8d4577095145d8d0b9..4b611a6bd8d31af8a4496472f080cee073117cdc 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1052,9 +1052,21 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa if (bundleActiveResult == nullptr) { return nullptr; } + GetCurrentBundleStats(currentPackageTime, bundleActiveResult, intervalStats); + bundleActiveResult->Close(); + if (databaseType == DAILY_DATABASE_INDEX) { + eventBeginTime_ = currentPackageTime; + } + int64_t systemTime = GetSystemTimeMs(); + intervalStats->lastTimeSaved_ = systemTime; + return intervalStats; +} + +void BundleActiveUsageDatabase::GetCurrentBundleStats(int64_t currentPackageTime, + shared_ptr& bundleActiveResult, shared_ptr& intervalStats) +{ int32_t tableRowNumber; bundleActiveResult->GetRowCount(tableRowNumber); - map> bundleStats; int64_t relativeLastTimeUsed; int64_t relativeLastTimeFrontServiceUsed; for (int32_t i = 0; i < tableRowNumber; i++) { @@ -1073,16 +1085,9 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa bundleActiveResult->GetInt(PACKAGE_LOG_UID_COLUMN_INDEX, usageStats->uid_); string bundleStatsKey = usageStats->bundleName_ + std::to_string(usageStats->uid_); BundleActiveBundleMgrHelper::GetInstance()->InsertPackageUid(usageStats->bundleName_, usageStats->uid_); - bundleStats.insert(pair>(bundleStatsKey, usageStats)); - } - bundleActiveResult->Close(); - intervalStats->bundleStats_ = bundleStats; - if (databaseType == DAILY_DATABASE_INDEX) { - eventBeginTime_ = currentPackageTime; + intervalStats->bundleStats_.insert( + pair>(bundleStatsKey, usageStats)); } - int64_t systemTime = GetSystemTimeMs(); - intervalStats->lastTimeSaved_ = systemTime; - return intervalStats; } void BundleActiveUsageDatabase::FlushEventInfo(uint32_t databaseType, BundleActivePeriodStats &stats)