From 98f55771fbc4a88d156ea91056718a16c1dce34a Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 14:58:54 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 21 ++++++++++++++----- .../include/bundle_active_group_controller.h | 2 +- .../src/bundle_active_group_controller.cpp | 11 +++++----- .../src/bundle_active_group_handler.cpp | 17 +++++++-------- .../src/bundle_active_user_history.cpp | 4 ++++ .../src/bundle_active_user_service.cpp | 5 +++++ 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 1d431ec..ef0ade2 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -23,6 +23,7 @@ namespace OHOS { namespace DeviceUsageStats { +const std::string LAUNCHER_BUNDLE_NAME = "com.ohos.launcher"; BundleActiveReportHandlerObject::BundleActiveReportHandlerObject() { userId_ = -1; @@ -225,7 +226,7 @@ void BundleActiveCore::OnStatsChanged(const int userId) auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); if (handler_.lock()->HasInnerEvent(static_cast(BundleActiveReportHandler::MSG_FLUSH_TO_DISK)) == false) { - BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event"); + BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId); handler_.lock()->SendEvent(event, FLUSH_INTERVAL); } } @@ -389,6 +390,10 @@ void BundleActiveCore::OnUserSwitched(const int userId) it->second->RestoreStats(true); } } + if (!handler_.expired()) { + BUNDLE_ACTIVE_LOGI("OnUserSwitched remove flush to disk event"); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK); + } std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); if (activatedOsAccountIds.size() == 0) { @@ -397,10 +402,9 @@ void BundleActiveCore::OnUserSwitched(const int userId) } for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]); - bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]); + bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], lastUsedUser_); } lastUsedUser_ = userId; - OnStatsChanged(userId); } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) @@ -413,14 +417,21 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) lastUsedUser_ = userId; BUNDLE_ACTIVE_LOGI("last used id change to %{public}d", lastUsedUser_); } + + sptr timer = MiscServices::TimeServiceClient::GetInstance(); + int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); + if (event.bundleName_ == LAUNCHER_BUNDLE_NAME) { + BUNDLE_ACTIVE_LOGI("launcher event, only update app group"); + bundleGroupController_->ReportEvent(event, bootBasedTimeStamp, userId); + return 0; + } + BUNDLE_ACTIVE_LOGI("report event called bundle name %{public}s time %{public}lld userId %{public}d, " "eventid %{public}d, in lock range", event.bundleName_.c_str(), event.timeStamp_, userId, event.eventId_); - sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); if (timeNow == -1) { return -1; } - int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); ConvertToSystemTimeLocked(event); std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow); if (service == nullptr) { diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 90c03cb..ee2f45c 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -84,7 +84,7 @@ public: int IsBundleIdle(const std::string& bundleName, const int userId); int QueryPackageGroup(const int userId, const std::string& bundleName); void ShutDown(const int64_t bootBasedTimeStamp, const int userId); - void OnUserSwitched(const int userId); + void OnUserSwitched(const int userId, const int lastUsedUser); private: std::mutex mutex_; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 97b3297..9278329 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -50,8 +50,11 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) } } -void BundleActiveGroupController::OnUserSwitched(const int userId) +void BundleActiveGroupController::OnUserSwitched(const int userId, const int lastUsedUser) { + BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); + CheckEachBundleState(lastUsedUser); + bundleUserHistory_->WriteBundleUsage(lastUsedUser); std::lock_guard lock(mutex_); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); @@ -282,14 +285,12 @@ 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; + groupReason = GROUP_CONTROL_REASON_USAGE | GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT; notTimeout = true; } else if (newGroup >= ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ > bootBasedTimeStampAdjusted) { newGroup = ACTIVE_GROUP_DAILY; - groupReason = (newGroup == oldGroup) ? oneBundleHistory->reasonInGroup_ : GROUP_CONTROL_REASON_USAGE | - GROUP_EVENT_REASON_ALIVE_TIMEOUT; + groupReason = GROUP_CONTROL_REASON_USAGE | GROUP_EVENT_REASON_ALIVE_TIMEOUT; notTimeout = true; } if (oldGroup < newGroup || notTimeout) { diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index ff45231..2b44748 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -54,19 +54,18 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe break; } case MSG_ONE_TIME_CHECK_BUNDLE_STATE: { - std::vector osAccountInfos; - OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(osAccountInfos); - if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGI("BundleActiveCore::GetAllActiveUser failed"); + std::vector activatedOsAccountIds; + if (AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds) != ERR_OK) { + BUNDLE_ACTIVE_LOGI("query activated account failed"); return; } - if (osAccountInfos.size() == 0) { - BUNDLE_ACTIVE_LOGI("BundleActiveCore::GetAllActiveUser size is 0"); + if (activatedOsAccountIds.size() == 0) { + BUNDLE_ACTIVE_LOGI("GetAllActiveUser size is 0"); return; } - for (uint32_t i = 0; i < osAccountInfos.size(); i++) { - bundleActiveGroupController_->CheckEachBundleState(osAccountInfos[i].GetLocalId()); - bundleActiveGroupController_->RestoreToDatabase(osAccountInfos[i].GetLocalId()); + for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { + bundleActiveGroupController_->CheckEachBundleState(activatedOsAccountIds[i]); + bundleActiveGroupController_->RestoreToDatabase(activatedOsAccountIds[i]); } RemoveEvent(MSG_ONE_TIME_CHECK_BUNDLE_STATE); break; diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index e1d59b5..3d0f0f9 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -197,6 +197,10 @@ void BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int if (oneBundleHistory == nullptr) { return; } + if (oneBundleHistory->currentGroup_ == newGroup || oneBundleHistory->reasonInGroup_ == groupReason) { + BUNDLE_ACTIVE_LOGI("%{public}s group and reason is same as before, not update", bundleName.c_str()); + return; + } oneBundleHistory->currentGroup_ = newGroup; oneBundleHistory->reasonInGroup_ = groupReason; int64_t setTimeStamp = GetBootBasedTimeStamp(bootBasedTimeStamp); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 9682bbc..670e854 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -71,6 +71,7 @@ void BundleActiveUserService::RenewTableTime(int64_t oldTime, int64_t newTime) void BundleActiveUserService::NotifyStatsChanged() { + BUNDLE_ACTIVE_LOGI("NotifyStatsChanged stat change is %{public}d, user is %{public}d", statsChanged_, userId_); if (!statsChanged_) { BUNDLE_ACTIVE_LOGI("NotifyStatsChanged() set stats changed to true"); statsChanged_ = true; @@ -170,6 +171,7 @@ void BundleActiveUserService::RestoreStats(bool forced) } currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; + BUNDLE_ACTIVE_LOGI("change statsChanged_ to %{public}d user is %{public}d", statsChanged_, userId_); } } @@ -260,6 +262,9 @@ void BundleActiveUserService::RenewStatsInMemory(const int64_t timeStamp) if (continueAbilities.find(continueBundleName) != continueAbilities.end()) { for (std::map::iterator it = continueAbilities[continueBundleName].begin(); it != continueAbilities[continueBundleName].end(); it++) { + if (it->second == BundleActiveEvent::ABILITY_BACKGROUND) { + continue; + } (*itInterval)->Update(continueBundleName, "", beginTime, it->second, it->first); } } -- Gitee From 287ed3bdbe256ff32af469a59c46d651761b6ef5 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 18:26:56 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 2 +- services/packageusage/src/bundle_active_user_service.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index ef0ade2..8b06d69 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -224,7 +224,7 @@ void BundleActiveCore::OnStatsChanged(const int userId) std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); - if (handler_.lock()->HasInnerEvent(static_cast(BundleActiveReportHandler::MSG_FLUSH_TO_DISK)) == + if (handler_.lock()->HasInnerEvent(>HasInnerEvent(static_cast(userId)) == false) { BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId); handler_.lock()->SendEvent(event, FLUSH_INTERVAL); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 670e854..cfe1107 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -86,8 +86,8 @@ void BundleActiveUserService::NotifyNewUpdate() void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) { - BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld", - currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds()); + BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d", + currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); RenewStatsInMemory(event.timeStamp_); -- Gitee From 1a15fe175ceb7656863ade731ceaea39d615a948 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 18:27:51 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 8b06d69..0aa4421 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -224,7 +224,7 @@ void BundleActiveCore::OnStatsChanged(const int userId) std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); - if (handler_.lock()->HasInnerEvent(>HasInnerEvent(static_cast(userId)) == + if (handler_.lock()->HasInnerEvent(HasInnerEvent(static_cast(userId)) == false) { BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId); handler_.lock()->SendEvent(event, FLUSH_INTERVAL); -- Gitee From 3d58b41712047bec6329a31fecc5ecf45d0cebab Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 18:51:47 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 1 + services/common/src/bundle_active_core.cpp | 2 +- services/packagegroup/include/bundle_active_group_common.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index d5fc211..e60efbc 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -128,6 +128,7 @@ public: private: static const int64_t FLUSH_INTERVAL = TWO_MINUTE; + static const int64_t DELAY_WHEN_USER_SWITCH = TEN_SECOND; static const int64_t TIME_CHANGE_THRESHOLD_MILLIS = TWO_SECONDS; const int DEFAULT_USER_ID = -1; std::map visibleActivities_; diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 0aa4421..2251c70 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -91,7 +91,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER, handlerobjToPtr); - bundleActiveReportHandler_.lock()->SendEvent(event); + bundleActiveReportHandler_.lock()->SendEvent(event, DELAY_WHEN_USER_SWITCH); } else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) { int32_t userId = data.GetWant().GetIntParam("userId", 0); diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index 4d8fe0b..330ec16 100644 --- a/services/packagegroup/include/bundle_active_group_common.h +++ b/services/packagegroup/include/bundle_active_group_common.h @@ -28,6 +28,7 @@ const int ACTIVE_GROUP_RARE = 40; const int ACTIVE_GROUP_LIMIT = 50; const int ACTIVE_GROUP_NEVER = 60; const int64_t FIVE_SECOND = 5 * 1000; +const int64_t TEN_SECOND = 10 * 1000; const int64_t ONE_MINUTE = 60 * 1000; const int64_t TWO_MINUTE = 2 * ONE_MINUTE; const int64_t THREE_MINUTE = 3 * ONE_MINUTE; -- Gitee From ee725030a425cba2be5efeea9c4fee5eb4998405 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 19:29:07 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 2251c70..e2189f5 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -224,8 +224,7 @@ void BundleActiveCore::OnStatsChanged(const int userId) std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); - if (handler_.lock()->HasInnerEvent(HasInnerEvent(static_cast(userId)) == - false) { + if (handler_.lock()->HasInnerEvent(static_cast(userId)) == false) { BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId); handler_.lock()->SendEvent(event, FLUSH_INTERVAL); } -- Gitee From 455dc3a25f6a10e954aa8f025abb04e4ad4994ab Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 20:01:32 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_common_event_subscriber.h | 1 + services/common/include/bundle_active_core.h | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/services/common/include/bundle_active_common_event_subscriber.h b/services/common/include/bundle_active_common_event_subscriber.h index ffbf6e9..1f0f009 100644 --- a/services/common/include/bundle_active_common_event_subscriber.h +++ b/services/common/include/bundle_active_common_event_subscriber.h @@ -48,6 +48,7 @@ public: void OnReceiveEvent(const CommonEventData &data) override; private: + static const int64_t DELAY_WHEN_USER_SWITCH = TEN_SECOND; std::mutex mutex_; std::weak_ptr activeGroupController_; std::weak_ptr bundleActiveReportHandler_; diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index e60efbc..0cb8268 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -128,8 +128,6 @@ public: private: static const int64_t FLUSH_INTERVAL = TWO_MINUTE; - static const int64_t DELAY_WHEN_USER_SWITCH = TEN_SECOND; - static const int64_t TIME_CHANGE_THRESHOLD_MILLIS = TWO_SECONDS; const int DEFAULT_USER_ID = -1; std::map visibleActivities_; // use weak_ptr to avoid circulate reference of core and handler. -- Gitee From 14b4ff31a9fb85abf836d68fcfea690a5e8b50be Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 20:28:37 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index e2189f5..2ae10a8 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -281,7 +281,7 @@ void BundleActiveCore::RestoreToDatabaseLocked(const int userId) } if (!handler_.expired()) { BUNDLE_ACTIVE_LOGI("RestoreToDatabaseLocked remove flush to disk event"); - handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, userId); } } @@ -344,7 +344,7 @@ int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int userId) it->second->LoadActiveStats(actualSystemTime, true, true); if (!handler_.expired()) { BUNDLE_ACTIVE_LOGI("CheckTimeChangeAndGetWallTime remove flush to disk event"); - handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, userId); } } realTimeShot_ = actualRealTime; @@ -391,7 +391,7 @@ void BundleActiveCore::OnUserSwitched(const int userId) } if (!handler_.expired()) { BUNDLE_ACTIVE_LOGI("OnUserSwitched remove flush to disk event"); - handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, lastUsedUser_); } std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); -- Gitee From e1c22fa75d20be658d68e2e83dab1a931b5f4cc8 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 20:43:32 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 1 + services/common/src/bundle_active_core.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 0cb8268..d5fc211 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -128,6 +128,7 @@ public: private: static const int64_t FLUSH_INTERVAL = TWO_MINUTE; + static const int64_t TIME_CHANGE_THRESHOLD_MILLIS = TWO_SECONDS; const int DEFAULT_USER_ID = -1; std::map visibleActivities_; // use weak_ptr to avoid circulate reference of core and handler. diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 2ae10a8..22c6bbe 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -91,7 +91,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER, handlerobjToPtr); - bundleActiveReportHandler_.lock()->SendEvent(event, DELAY_WHEN_USER_SWITCH); + bundleActiveReportHandler_.lock()->SendEvent(event); } else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) { int32_t userId = data.GetWant().GetIntParam("userId", 0); -- Gitee From 43c1655c0376086e5204e8e563879f954aad9830 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 20:53:33 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= 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 - 1 file changed, 1 deletion(-) diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index 330ec16..4d8fe0b 100644 --- a/services/packagegroup/include/bundle_active_group_common.h +++ b/services/packagegroup/include/bundle_active_group_common.h @@ -28,7 +28,6 @@ const int ACTIVE_GROUP_RARE = 40; const int ACTIVE_GROUP_LIMIT = 50; const int ACTIVE_GROUP_NEVER = 60; const int64_t FIVE_SECOND = 5 * 1000; -const int64_t TEN_SECOND = 10 * 1000; const int64_t ONE_MINUTE = 60 * 1000; const int64_t TWO_MINUTE = 2 * ONE_MINUTE; const int64_t THREE_MINUTE = 3 * ONE_MINUTE; -- Gitee From f1259e8b624899c448155a850e44c68861860408 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 21:17:51 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_common_event_subscriber.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/common/include/bundle_active_common_event_subscriber.h b/services/common/include/bundle_active_common_event_subscriber.h index 1f0f009..ffbf6e9 100644 --- a/services/common/include/bundle_active_common_event_subscriber.h +++ b/services/common/include/bundle_active_common_event_subscriber.h @@ -48,7 +48,6 @@ public: void OnReceiveEvent(const CommonEventData &data) override; private: - static const int64_t DELAY_WHEN_USER_SWITCH = TEN_SECOND; std::mutex mutex_; std::weak_ptr activeGroupController_; std::weak_ptr bundleActiveReportHandler_; -- Gitee From b6e32d90ac11dbf084e2ffc2978a6d4fad5474bd Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 18:05:56 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_report_handler.cpp | 5 +++++ services/packageusage/src/bundle_active_user_service.cpp | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index 3fc4a79..1733d43 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -52,6 +52,11 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point BUNDLE_ACTIVE_LOGI("FLUSH TO DISK HANDLE"); auto ptrToHandlerobj = event->GetSharedObject(); BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; + if (tmpHandlerobj.userId_ != bundleActiveCore_->lastUsedUser_) { + BUNDLE_ACTIVE_LOGI("flush user is %{public}d, not last user %{public}d, return", + tmpHandlerobj.userId_, bundleActiveCore_->lastUsedUser_); + return; + } bundleActiveCore_->RestoreToDatabase(tmpHandlerobj.userId_); break; } diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index cfe1107..fa02643 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -86,8 +86,9 @@ void BundleActiveUserService::NotifyNewUpdate() void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) { - BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d", - currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_); + BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d," + "event is %{public}d", + currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); RenewStatsInMemory(event.timeStamp_); -- Gitee From c8d42ac6b32e726dfff83124f747f304b9d0b4a8 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 18:11:20 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E5=B9=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=EF=BC=8C=E5=B1=8F=E8=94=BDlauncher=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=89=8D=E4=B8=80=E5=A4=A9=E5=89=A9=E4=BD=99=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=88=9B=E5=BB=BA=E7=A9=BA=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=9C=A8=E6=96=B0?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 2 +- services/common/src/bundle_active_core.cpp | 18 +++++++++--------- .../src/bundle_active_report_handler.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index d5fc211..192c3a3 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -142,7 +142,7 @@ private: void RegisterSubscriber(); std::shared_ptr commonEventSubscriber_; void RestoreAllData(); - int lastUsedUser_; + int currentUsedUser_; }; } } diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 22c6bbe..5b5c1bd 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -52,7 +52,7 @@ BundleActiveCore::BundleActiveCore() { systemTimeShot_ = -1; realTimeShot_ = -1; - lastUsedUser_ = -1; + currentUsedUser_ = -1; } BundleActiveCore::~BundleActiveCore() @@ -376,10 +376,10 @@ void BundleActiveCore::OnUserRemoved(const int userId) void BundleActiveCore::OnUserSwitched(const int userId) { sptr timer = MiscServices::TimeServiceClient::GetInstance(); - auto it = userStatServices_.find(lastUsedUser_); + auto it = userStatServices_.find(currentUsedUser_); if (it != userStatServices_.end()) { if (it != userStatServices_.end()) { - BUNDLE_ACTIVE_LOGI("restore old user id %{public}d data when switch user", lastUsedUser_); + BUNDLE_ACTIVE_LOGI("restore old user id %{public}d data when switch user", currentUsedUser_); BundleActiveEvent event; event.eventId_ = BundleActiveEvent::FLUSH; int64_t actualRealTime = timer->GetBootTimeMs(); @@ -391,7 +391,7 @@ void BundleActiveCore::OnUserSwitched(const int userId) } if (!handler_.expired()) { BUNDLE_ACTIVE_LOGI("OnUserSwitched remove flush to disk event"); - handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, lastUsedUser_); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, currentUsedUser_); } std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); @@ -401,9 +401,9 @@ void BundleActiveCore::OnUserSwitched(const int userId) } for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]); - bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], lastUsedUser_); + bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], currentUsedUser_); } - lastUsedUser_ = userId; + currentUsedUser_ = userId; } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) @@ -412,9 +412,9 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) if (userId == 0 || userId == -1) { return -1; } - if (lastUsedUser_ == -1) { - lastUsedUser_ = userId; - BUNDLE_ACTIVE_LOGI("last used id change to %{public}d", lastUsedUser_); + if (currentUsedUser_ == -1) { + currentUsedUser_ = userId; + BUNDLE_ACTIVE_LOGI("last used id change to %{public}d", currentUsedUser_); } sptr timer = MiscServices::TimeServiceClient::GetInstance(); diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index 1733d43..967af93 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -52,9 +52,9 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point BUNDLE_ACTIVE_LOGI("FLUSH TO DISK HANDLE"); auto ptrToHandlerobj = event->GetSharedObject(); BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; - if (tmpHandlerobj.userId_ != bundleActiveCore_->lastUsedUser_) { + if (tmpHandlerobj.userId_ != bundleActiveCore_->currentUsedUser_) { BUNDLE_ACTIVE_LOGI("flush user is %{public}d, not last user %{public}d, return", - tmpHandlerobj.userId_, bundleActiveCore_->lastUsedUser_); + tmpHandlerobj.userId_, bundleActiveCore_->currentUsedUser_); return; } bundleActiveCore_->RestoreToDatabase(tmpHandlerobj.userId_); -- Gitee From 086c1ea6046788d0c9b7210693062efc903d2fa6 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 18:19:46 +0800 Subject: [PATCH 13/16] remove useless handler event Signed-off-by: houdisheng --- .../packageusage/include/bundle_active_report_handler.h | 9 ++++----- .../packageusage/src/bundle_active_report_handler.cpp | 8 +------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/services/packageusage/include/bundle_active_report_handler.h b/services/packageusage/include/bundle_active_report_handler.h index ad2714d..f0fcdaa 100644 --- a/services/packageusage/include/bundle_active_report_handler.h +++ b/services/packageusage/include/bundle_active_report_handler.h @@ -36,11 +36,10 @@ public: void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; void Init(const std::shared_ptr& bundleActiveCore); static const int MSG_REPORT_EVENT = 0; - static const int MSG_REPORT_EVENT_TO_ALL_USER = 1; - static const int MSG_FLUSH_TO_DISK = 2; - static const int MSG_REMOVE_USER = 3; - static const int MSG_BUNDLE_UNINSTALLED = 4; - static const int MSG_SWITCH_USER = 5; + static const int MSG_FLUSH_TO_DISK = 1; + static const int MSG_REMOVE_USER = 2; + static const int MSG_BUNDLE_UNINSTALLED = 3; + static const int MSG_SWITCH_USER = 4; private: std::shared_ptr bundleActiveCore_; diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index 967af93..cbbfdf7 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -42,18 +42,12 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point bundleActiveCore_->ReportEvent(tmpHandlerobj.event_, tmpHandlerobj.userId_); break; } - case MSG_REPORT_EVENT_TO_ALL_USER: { - auto ptrToHandlerobj = event->GetSharedObject(); - BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; - bundleActiveCore_->ReportEventToAllUserId(tmpHandlerobj.event_); - break; - } case MSG_FLUSH_TO_DISK: { BUNDLE_ACTIVE_LOGI("FLUSH TO DISK HANDLE"); auto ptrToHandlerobj = event->GetSharedObject(); BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; if (tmpHandlerobj.userId_ != bundleActiveCore_->currentUsedUser_) { - BUNDLE_ACTIVE_LOGI("flush user is %{public}d, not last user %{public}d, return", + BUNDLE_ACTIVE_LOGE("flush user is %{public}d, not last user %{public}d, return", tmpHandlerobj.userId_, bundleActiveCore_->currentUsedUser_); return; } -- Gitee From 47cf8045ac663dd95ae488190a55a7b8fa0f1aa9 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 18:34:39 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4handl?= =?UTF-8?q?er=E5=88=B7=E7=9B=98=E4=BA=8B=E4=BB=B6=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86handler=E5=88=B7?= =?UTF-8?q?=E7=9B=98=E4=BA=8B=E4=BB=B6=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 --- services/packageusage/src/bundle_active_report_handler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index cbbfdf7..e116809 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -49,6 +49,7 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point if (tmpHandlerobj.userId_ != bundleActiveCore_->currentUsedUser_) { BUNDLE_ACTIVE_LOGE("flush user is %{public}d, not last user %{public}d, return", tmpHandlerobj.userId_, bundleActiveCore_->currentUsedUser_); + RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, tmpHandlerobj.userId_); return; } bundleActiveCore_->RestoreToDatabase(tmpHandlerobj.userId_); -- Gitee From 1d066bcbbc4bf1f32f6e15288db3c8252d2a8f70 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 19:17:43 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4handl?= =?UTF-8?q?er=E5=88=B7=E7=9B=98=E4=BA=8B=E4=BB=B6=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86handler=E5=88=B7?= =?UTF-8?q?=E7=9B=98=E4=BA=8B=E4=BB=B6=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 --- services/common/include/bundle_active_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 192c3a3..99d3728 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -125,6 +125,7 @@ public: // when service stop, call it to unregister commen event and shutdown call back. void UnRegisterSubscriber(); int64_t GetSystemTimeMs(); + int currentUsedUser_; private: static const int64_t FLUSH_INTERVAL = TWO_MINUTE; @@ -142,7 +143,6 @@ private: void RegisterSubscriber(); std::shared_ptr commonEventSubscriber_; void RestoreAllData(); - int currentUsedUser_; }; } } -- Gitee From e3bd0337fc51f13590f83aa5867133e4ccb2b3bd Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sun, 13 Mar 2022 21:40:36 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4handl?= =?UTF-8?q?er=E5=88=B7=E7=9B=98=E4=BA=8B=E4=BB=B6=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86handler=E5=88=B7?= =?UTF-8?q?=E7=9B=98=E4=BA=8B=E4=BB=B6=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 --- services/common/src/bundle_active_core.cpp | 1 + services/packageusage/src/bundle_active_user_service.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 5b5c1bd..11ff64a 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -404,6 +404,7 @@ void BundleActiveCore::OnUserSwitched(const int userId) bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], currentUsedUser_); } currentUsedUser_ = userId; + OnStatsChanged(userId); } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index fa02643..931d54f 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -133,7 +133,9 @@ void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) break; } } - NotifyStatsChanged(); + if (event.eventId_ != BundleActiveEvent::FLUSH) { + NotifyStatsChanged(); + } } void BundleActiveUserService::ReportForShutdown(const BundleActiveEvent& event) -- Gitee