diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 1487c37189ec9db6d240c7eeae594ec3aeb2d7b9..6a3f2825d13dc2a118819baddcd9be9b33ef3a45 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -27,19 +27,19 @@ BundleActiveClient& BundleActiveClient::GetInstance() bool BundleActiveClient::GetBundleActiveProxy() { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { + if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); return false; } sptr object = samgr->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); - if (object == nullptr) { + if (!object) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbility[1920] ."); return false; } bundleActiveProxy_ = iface_cast(object); - if (bundleActiveProxy_ == nullptr) { + if (!bundleActiveProxy_) { BUNDLE_ACTIVE_LOGE("Failed to get BundleActiveClient."); return false; } diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 928e667f5814ae4afff19b83eeb2169ae8ced883..d5fc211c87984202f932245ddca4afaadd1e17df 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -37,6 +37,7 @@ public: int userId_; std::string bundleName_; BundleActiveReportHandlerObject(); + BundleActiveReportHandlerObject(const int userId, const std::string bundleName); BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig); ~BundleActiveReportHandlerObject() {}; }; @@ -116,7 +117,7 @@ public: const int64_t timeStamp); // when received a USER_REMOVED commen event, call it to remove data. void OnUserRemoved(const int userId); - void OnUserSwitched(); + void OnUserSwitched(const int userId); // force set app group. void SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId); // get all user in device diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index 1bebdd57dac5cca5056e80ec05bfed8759e2b790..0a9b881012c071ef8339508c9f2c1afaa678467d 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -44,12 +44,11 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData std::stringstream stream; stream << abilityStateData.token.GetRefPtr(); std::string abilityId = stream.str(); - BundleActiveReportHandlerObject tmpHandlerObject; + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); tmpHandlerObject.event_.bundleName_ = abilityStateData.bundleName; tmpHandlerObject.event_.abilityName_ = abilityStateData.abilityName; tmpHandlerObject.event_.abilityId_ = abilityStateData.abilityName; tmpHandlerObject.event_.continuousTaskAbilityName_ = ""; - tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); switch (abilityStateData.abilityState) { diff --git a/services/common/src/bundle_active_binary_search.cpp b/services/common/src/bundle_active_binary_search.cpp index f16cf9348a07a1511d11350ca056d0064d28dc03..28ce0202dfafcef10071dd58de3b860e0dfafd72 100644 --- a/services/common/src/bundle_active_binary_search.cpp +++ b/services/common/src/bundle_active_binary_search.cpp @@ -30,8 +30,9 @@ int32_t BundleActiveBinarySearch::BinarySearch(const std::vector &table { int32_t low = 0; int32_t high = static_cast(tableNameArray.size() - 1); + int32_t divider = 2; while (low <= high) { - int32_t mid = (low + high) >> 1; + int32_t mid = (low + high) / divider; int64_t midValue = tableNameArray.at(mid); if (midValue < targetValue) { low = mid + 1; diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 459524f71a7aebecae2d4bbb9c9a7902f4dfdc28..a64c7204a5627163651f27f8025f0b678b95e42f 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -88,12 +88,11 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (ret == ERR_OK && userId != -1 && !bundleName.empty()) { std::stringstream stream; - BundleActiveReportHandlerObject tmpHandlerObject; + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); tmpHandlerObject.event_.bundleName_ = bundleName; tmpHandlerObject.event_.abilityName_ = ""; tmpHandlerObject.event_.abilityId_ = abilityId; tmpHandlerObject.event_.continuousTaskAbilityName_ = abiliytName; - tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); if (isStart) { diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 31b768e4d609928663ca265fd5983534451c7697..052dbfa1ca15365cff9b53b0e25a00da6f6060d1 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -29,6 +29,12 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject() bundleName_ = ""; } +BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const int userId, const std::string bundleName) +{ + userId_ = userId; + bundleName_ = bundleName; +} + BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig) { event_.bundleName_ = orig.event_.bundleName_; @@ -71,8 +77,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da if (!bundleActiveReportHandler_.expired()) { int32_t userId = data.GetCode(); BUNDLE_ACTIVE_LOGI("remove user id %{public}d", userId); - BundleActiveReportHandlerObject tmpHandlerObject; - tmpHandlerObject.userId_ = userId; + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REMOVE_USER, handlerobjToPtr); @@ -81,7 +86,10 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da } else if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { int32_t userId = data.GetCode(); BUNDLE_ACTIVE_LOGI("OnReceiveEvent receive switched user event, user id is %{public}d", userId); - auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER); + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); + std::shared_ptr handlerobjToPtr = + std::make_shared(tmpHandlerObject); + auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER, handlerobjToPtr); bundleActiveReportHandler_.lock()->SendEvent(event); } else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) { @@ -90,9 +98,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da BUNDLE_ACTIVE_LOGI("action is %{public}s, userID is %{public}d, bundlename is %{public}s", action.c_str(), userId, bundleName.c_str()); if (!bundleActiveReportHandler_.expired()) { - BundleActiveReportHandlerObject tmpHandlerObject; - tmpHandlerObject.bundleName_ = bundleName; - tmpHandlerObject.userId_ = userId; + BundleActiveReportHandlerObject tmpHandlerObject(userId, bundleName); std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED, @@ -356,12 +362,13 @@ void BundleActiveCore::OnUserRemoved(const int userId) bundleGroupController_->OnUserRemoved(userId); } -void BundleActiveCore::OnUserSwitched() +void BundleActiveCore::OnUserSwitched(const int userId) { sptr timer = MiscServices::TimeServiceClient::GetInstance(); auto it = userStatServices_.find(lastUsedUser_); if (it != userStatServices_.end()) { if (it != userStatServices_.end()) { + BUNDLE_ACTIVE_LOGI("restore old user id %{public}d data when switch user", lastUsedUser_); BundleActiveEvent event; event.eventId_ = BundleActiveEvent::FLUSH; int64_t actualRealTime = timer->GetBootTimeMs(); @@ -381,16 +388,20 @@ void BundleActiveCore::OnUserSwitched() BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]); bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]); } + lastUsedUser_ = userId; + OnStatsChanged(userId); } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) { std::lock_guard lock(mutex_); - lastUsedUser_ = userId; - if (userId == 0) { + if (userId == 0 || userId == -1) { return -1; } - BUNDLE_ACTIVE_LOGI("ReportEvent called"); + if (lastUsedUser_ == -1) { + lastUsedUser_ = userId; + BUNDLE_ACTIVE_LOGI("last used id change to %{public}d", lastUsedUser_); + } 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(); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 09eb93dc2f320b20b0c07cbba75066646051f830..5673785421e299a36ff49797cf9b9bf2ae609f5e 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -100,7 +100,7 @@ void BundleActiveService::InitNecessaryState() } try { shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); - } catch(const std::bad_alloc &e) { + } catch (const std::bad_alloc &e) { BUNDLE_ACTIVE_LOGE("Memory allocation failed"); return; } @@ -169,7 +169,6 @@ bool BundleActiveService::SubscribeContinuousTask() return true; } - void BundleActiveService::OnStop() { if (shutdownCallback_ != nullptr) { @@ -186,14 +185,12 @@ void BundleActiveService::OnStop() int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, const std::string& continuousTask, const int userId, const int eventId) { - BUNDLE_ACTIVE_LOGI("report event called123123"); - BundleActiveReportHandlerObject tmpHandlerObject; + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); tmpHandlerObject.event_.bundleName_ = bundleName; tmpHandlerObject.event_.abilityName_ = abilityName; tmpHandlerObject.event_.abilityId_ = abilityId; tmpHandlerObject.event_.eventId_ = eventId; tmpHandlerObject.event_.continuousTaskAbilityName_ = continuousTask; - tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); std::shared_ptr handlerobjToPtr = @@ -214,15 +211,7 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName) int result = -1; OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); if (ret == ERR_OK && userId != -1) { - BUNDLE_ACTIVE_LOGI("IsBundleIdle user id is %{public}d", userId); - if (!GetBundleMgrProxy()) { - BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!"); - return true; - } - bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(callingUid); - if (bundleIsSystemApp == true) { - result = bundleActiveCore_->IsBundleIdle(bundleName, userId); - } + result = bundleActiveCore_->IsBundleIdle(bundleName, userId); } if (result == 0) { return false; @@ -321,15 +310,9 @@ std::vector BundleActiveService::QueryCurrentEvents(const int int userId = -1; OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); if (ret == ERR_OK && userId != -1) { - BUNDLE_ACTIVE_LOGI("QueryCurrentEvents userid is %{public}d", userId); - if (!GetBundleMgrProxy()) { - BUNDLE_ACTIVE_LOGE("QueryCurrentEvents get bundle manager proxy failed!"); - return result; - } std::string bundleName = ""; sptrBundleMgr_->GetBundleNameForUid(callingUid, bundleName); - bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId); - if (!bundleName.empty() && isSystemAppAndHasPermission == true) { + if (!bundleName.empty()) { BUNDLE_ACTIVE_LOGI("QueryCurrentEvents buindle name is %{public}s", bundleName.c_str()); result = bundleActiveCore_->QueryEvents(userId, beginTime, endTime, bundleName); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index d23d2baaa2171145be15f5b627bbe23dd9c295a1..091dd41dadd939af3b843a0086f2e9784f3aec52 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_, @@ -1083,13 +1080,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/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 67632020262716fde8046e027b883beb1963e9f4..a5d57b30547468fc696ae7ca058247d0457d44f0 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -94,7 +94,7 @@ private: int64_t timeoutForDirectlyUse_ = debug_ ? THREE_MINUTE : ONE_HOUR; int64_t timeoutForNotifySeen_ = debug_ ? ONE_MINUTE : TWELVE_HOUR; int64_t timeoutForSystemInteraction_ = debug_ ? ONE_MINUTE : TEN_MINUTE; - int64_t timeoutCalculated_; + int64_t timeoutCalculated_ = 0; sptr sptrBundleMgr_; bool calculationTimeOut(const std::shared_ptr& oneBundleHistory, const int64_t bootBasedTimeStamp); diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 519311f47333923321dccdb69892355d83bf9704..b4ca1b75d59906d0dfd39b8b87e05eb96c549a5d 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -221,7 +221,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co return; } int64_t timeUntilNextCheck; - int eventReason = EventToGroupReason(eventId); + uint32_t eventReason = EventToGroupReason(eventId); switch (eventId) { case BundleActiveEvent::NOTIFICATION_SEEN: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_DAILY, @@ -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/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 5179f8fec2590dc021ce82c4e28b6f5572643ddf..5055d7c98215092d044b26f98b7b933bd01285f5 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -31,6 +31,7 @@ BundleActivePackageHistory::BundleActivePackageHistory() reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT; bundleAliveTimeoutTimeStamp_ = 0; bundleDailyTimeoutTimeStamp_ = 0; + lastCalculatedGroup_ = ACTIVE_GROUP_NEVER; }; void BundleActiveUserHistory::WriteDeviceDuration() diff --git a/services/packageusage/src/bundle_active_event_stats.cpp b/services/packageusage/src/bundle_active_event_stats.cpp index 4dfa187ada9a155923a4604cf46893cf64c21095..3bb55e0e93c99d38715f263ca575abdf1d4f79db 100644 --- a/services/packageusage/src/bundle_active_event_stats.cpp +++ b/services/packageusage/src/bundle_active_event_stats.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace DeviceUsageStats { BundleActiveEventStats::BundleActiveEventStats() { + eventId_ = 0; beginTimeStamp_ = 0; endTimeStamp_ = 0; lastEventTime_ = 0; 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_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index 33b734d06dbd952647057e5e421bc409a328da1a..3fc4a797a813b1bd92f892c6656dd1769b14b6e3 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -69,7 +69,10 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point break; } case MSG_SWITCH_USER: { - bundleActiveCore_->OnUserSwitched(); + BUNDLE_ACTIVE_LOGI("MSG_SWITCH_USER CALLED"); + auto ptrToHandlerobj = event->GetSharedObject(); + BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; + bundleActiveCore_->OnUserSwitched(tmpHandlerobj.userId_); } default: { break; 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); }