diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 09eb93dc2f320b20b0c07cbba75066646051f830..cb4241a7f8d0f8bf723b16f4eebdbdc2f730995f 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -169,7 +169,6 @@ bool BundleActiveService::SubscribeContinuousTask() return true; } - void BundleActiveService::OnStop() { if (shutdownCallback_ != nullptr) { diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index cc0f7a24bd9ef841a049f591ed0bca49b398b6fd..718529db729bd94c0735201ed8b5e7ddcccc0925 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -685,13 +685,12 @@ void BundleActiveUsageDatabase::FlushPackageInfo(unsigned int databaseType, cons queryCondition.push_back(to_string(stats.userId_)); queryCondition.push_back(iter->first); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_STARTED_COUNT, iter->second->bundleStartedCount_); - valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, (iter->second->lastTimeUsed_ - stats.beginTime_)); - if (iter->second->lastContiniousTaskUsed_ == -1) { - valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, (iter->second->lastContiniousTaskUsed_)); - } else { - valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, (iter->second->lastContiniousTaskUsed_ - - stats.beginTime_)); - } + int64_t lastTimeUsedAdjusted = iter->second->lastTimeUsed_ == -1 ? + iter->second->lastTimeUsed_ : iter->second->lastTimeUsed_ - stats.beginTime_; + valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, lastTimeUsedAdjusted); + int64_t lastContinuousTaskUsedAdjusted = iter->second->lastContiniousTaskUsed_ == -1 ? + iter->second->lastContiniousTaskUsed_ : iter->second->lastContiniousTaskUsed_ - stats.beginTime_; + valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, lastContinuousTaskUsedAdjusted); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME, iter->second->totalInFrontTime_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK, iter->second->totalContiniousTaskUsedTime_); rdbStore->Update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ?", queryCondition); @@ -746,13 +745,11 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, usageStats->bundleName_); bundleActiveResult->GetInt(BUNDLE_STARTED_COUNT_COLUMN_INDEX, usageStats->bundleStartedCount_); bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, relativeLastTimeUsed); - usageStats->lastTimeUsed_ = relativeLastTimeUsed + currentPackageTime; + usageStats->lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 : + relativeLastTimeUsed + currentPackageTime; bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed); - if (relativeLastTimeFrontServiceUsed == -1) { - usageStats->lastContiniousTaskUsed_ = -1; - } else { - usageStats->lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed + currentPackageTime; - } + usageStats->lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 : + relativeLastTimeFrontServiceUsed + currentPackageTime; bundleActiveResult->GetLong(TOTAL_TIME_COLUMN_INDEX, usageStats->totalInFrontTime_); bundleActiveResult->GetLong(TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX, usageStats->totalContiniousTaskUsedTime_); bundleStats.insert(pair>(usageStats->bundleName_, @@ -1082,13 +1079,11 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt bundleActiveResult->GetInt(BUNDLE_STARTED_COUNT_COLUMN_INDEX, usageStats.bundleStartedCount_); bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, usageStats.lastTimeUsed_); bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, relativeLastTimeUsed); - usageStats.lastTimeUsed_ = relativeLastTimeUsed + packageTableTime; + usageStats.lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 : + relativeLastTimeUsed + packageTableTime; bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed); - if (relativeLastTimeFrontServiceUsed == -1) { - usageStats.lastContiniousTaskUsed_ = -1; - } else { - usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed + packageTableTime; - } + usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 : + relativeLastTimeFrontServiceUsed + packageTableTime; bundleActiveResult->GetLong(TOTAL_TIME_COLUMN_INDEX, usageStats.totalInFrontTime_); bundleActiveResult->GetLong(TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX, usageStats.totalContiniousTaskUsedTime_); diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index d3fdef4bd2c1294f99c2c08d19bf01d02dd56e9e..4d8fe0ba0f16393f3c7836638621ee567715bc46 100644 --- a/services/packagegroup/include/bundle_active_group_common.h +++ b/services/packagegroup/include/bundle_active_group_common.h @@ -59,6 +59,7 @@ const uint32_t GROUP_EVENT_REASON_BACKGROUND = 0x0005; const uint32_t GROUP_EVENT_REASON_ALIVE_TIMEOUT = 0x0006; const uint32_t GROUP_EVENT_REASON_LONG_TIME_TASK_STARTTED = 0x0007; const uint32_t GROUP_EVENT_REASON_CALCULATED_RESTORED = 0x0008; +const uint32_t GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT = 0x0009; } } } diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 519311f47333923321dccdb69892355d83bf9704..95100453ddf0f05e2af3cf83158c9912d1265630 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -281,6 +281,8 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN bootBasedTimeStampAdjusted) { newGroup = ACTIVE_GROUP_ALIVE; groupReason = oneBundleHistory->reasonInGroup_; + groupReason = (newGroup == oldGroup) ? oneBundleHistory->reasonInGroup_ : GROUP_CONTROL_REASON_USAGE | + GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT; } else if (newGroup >= ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ > bootBasedTimeStampAdjusted) { newGroup = ACTIVE_GROUP_DAILY; diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index 95205f0dee2e2571c838a55899b65fb42557e952..022bfc4e31f71123fb5c68cca9e231e207b0c7d3 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -22,7 +22,7 @@ BundleActivePackageStats::BundleActivePackageStats() bundleName_.clear(); beginTimeStamp_ = 0; // start time of counting endTimeStamp_ = 0; // stop time of counting - lastTimeUsed_ = 0; // the timestamp of last launch + lastTimeUsed_ = -1; // the timestamp of last launch totalInFrontTime_ = 0; // the total time of bundle in front. lastContiniousTaskUsed_ = -1; // the timestamp of bundle calling a continuous task. totalContiniousTaskUsedTime_ = 0; // the total time of bundle use continuous tasks. diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index ed0dd0f6b0a2a782ff3c0b707c88017bab79dddb..9682bbc69ee390a4378825e5fddc1a7680ff7cb6 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -161,13 +161,12 @@ void BundleActiveUserService::RestoreStats(bool forced) if (statsChanged_ || forced) { BUNDLE_ACTIVE_LOGI("RestoreStats() stat changed is true"); for (uint32_t i = 0; i < currentStats_.size(); i++) { - if (currentStats_[i] != nullptr) { + if (currentStats_[i]) { + if (currentStats_[i]->bundleStats_.empty() && currentStats_[i]->events_.events_.empty()) { + continue; + } database_.UpdateUsageData(i, *(currentStats_[i])); } - if (i == 0) { - BUNDLE_ACTIVE_LOGI("RESOTRE EVENT SIZE IS %{public}d, USER ID IS %{public}d", - currentStats_[i]->events_.Size(), userId_); - } } currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; @@ -373,7 +372,7 @@ void BundleActiveUserService::PrintInMemPackageStats(const int idx) int64_t totalUsedTime = it.second->totalInFrontTime_; int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_; int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_; - BUNDLE_ACTIVE_LOGI("In mem, event stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld" + BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld" "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld", totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed); }