diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 1d431ec773eba40d739eba0ecf080536e880662f..9d61cde518a3c70c5455a7cac34811be2850b74d 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -225,7 +225,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 +389,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 +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]); + bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], lastUsedUser_); } lastUsedUser_ = userId; - OnStatsChanged(userId); } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 90c03cb291af3d569251447c90284deb2c9e986f..ee2f45c3d3dd46ea63c44921d6f983f026b1178b 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 97b32975d019f353732c15f573b9b6a7e261d0d5..c08a36f093f5639a63b5cce15fa71c615aba5f2c 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); diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index ff45231868fdf2db32b783bbc47f0aaf3623e08a..2b4474873dafc6ecda277f8d80ba055a0bf5706b 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 e1d59b5179dc0cb95a23200d4b7d94fe5e27b6b4..3d0f0f90f67710bf9a3abdd4c8cbd0513a0aee03 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 9682bbc69ee390a4378825e5fddc1a7680ff7cb6..14e767be058fc68e1251f0b4e156db2247a29931 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -170,6 +170,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_); } }