From 6510b5eb463885957bcbce9c795a3fb935849cbd Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 14:45:45 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=80=E6=AC=A1=E4=BD=BF=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BA-1=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E8=90=BD?= =?UTF-8?q?=E7=9B=98/=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../src/bundle_active_usage_database.cpp | 33 ++++++++----------- .../src/bundle_active_package_stats.cpp | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index cc0f7a2..fa9c2e3 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/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index 95205f0..022bfc4 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. -- Gitee From ab00994d6a6bf1a0bfd70142585f8770413746f4 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 15:10:27 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=80=E6=AC=A1=E4=BD=BF=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BA-1=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E8=90=BD?= =?UTF-8?q?=E7=9B=98/=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../packageusage/src/bundle_active_user_service.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index ed0dd0f..60a4a4b 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -161,12 +161,15 @@ 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_); + 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(); -- Gitee From 0ede0ed85629558148ad8dd181bf0b6d8f8a5433 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 15:55:20 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=88=A0=E9=99=A4restoretostat=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 60a4a4b..db4022a 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -166,10 +166,6 @@ void BundleActiveUserService::RestoreStats(bool forced) 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(); -- Gitee From e383808405e409b138c80367419ba4334e3f2e38 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 16:59:00 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=88=A0=E9=99=A4restoretostat=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_usage_database.cpp | 2 +- services/packageusage/src/bundle_active_user_service.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index fa9c2e3..718529d 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1079,7 +1079,7 @@ 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 == -1 ? -1 : + usageStats.lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 : relativeLastTimeUsed + packageTableTime; bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed); usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 : diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index db4022a..9682bbc 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -372,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); } -- Gitee From 5f15d35122b19e50ba848e62062b4b52b4e3fced Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 19:14:49 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=9C=A8alive=E4=BF=9D=E6=B4=BB=E6=9C=9F=E5=86=85=E4=B8=8D?= =?UTF-8?q?=E9=99=8D=E7=BA=A7=E7=9A=84=E5=8E=9F=E5=9B=A0GROUP=5FEVENT=5FRE?= =?UTF-8?q?ASON=5FALIVE=5FNOT=5FTIMEOUT=3D0x0009?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/include/bundle_active_group_common.h | 1 + services/packagegroup/src/bundle_active_group_controller.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index d3fdef4..4d8fe0b 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 519311f..9510045 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; -- Gitee From 8ea895dbcee1f66961e7457d7a4fdca464c1bd64 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 20:47:13 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=9C=A8alive=E4=BF=9D=E6=B4=BB=E6=9C=9F=E5=86=85=E4=B8=8D?= =?UTF-8?q?=E9=99=8D=E7=BA=A7=E7=9A=84=E5=8E=9F=E5=9B=A0GROUP=5FEVENT=5FRE?= =?UTF-8?q?ASON=5FALIVE=5FNOT=5FTIMEOUT=3D0x0009?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 09eb93d..cb4241a 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) { -- Gitee