From a3d0cc6640f0d5723b9a00e2add8407e6a1c9958 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 16 Feb 2022 17:07:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=89=AB=E6=8F=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_event.cpp | 24 ++++++--- .../common/src/bundle_active_event_list.cpp | 18 ++++--- .../common/src/bundle_active_event_stats.cpp | 24 ++++++--- .../src/bundle_active_event_tracker.cpp | 9 ++-- .../src/bundle_active_package_stats.cpp | 54 ++++++++++++------- .../common/src/bundle_active_period_stats.cpp | 27 ++++++---- .../common/src/bundle_active_user_service.cpp | 10 ++-- services/include/bundle_active_iservice.h | 1 - services/src/bundle_active_service.cpp | 13 +++-- services/src/bundle_active_stub.cpp | 3 +- 10 files changed, 120 insertions(+), 63 deletions(-) diff --git a/services/common/src/bundle_active_event.cpp b/services/common/src/bundle_active_event.cpp index 5925445..722583a 100644 --- a/services/common/src/bundle_active_event.cpp +++ b/services/common/src/bundle_active_event.cpp @@ -17,7 +17,8 @@ namespace OHOS { namespace BundleActive { -BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) { +BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) +{ bundleName_ = orig.bundleName_; abilityName_ = orig.abilityName_; abilityId_ = orig.abilityId_; @@ -26,32 +27,39 @@ BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) { isIdle_ = orig.isIdle_; } -BundleActiveEvent::BundleActiveEvent(const int eventId, const int64_t timeStamp) { +BundleActiveEvent::BundleActiveEvent(const int eventId, const int64_t timeStamp) +{ eventId_ = eventId; timeStamp_ = timeStamp; } -std::string BundleActiveEvent::GetBundleName() { +std::string BundleActiveEvent::GetBundleName() +{ return bundleName_; } -std::string BundleActiveEvent::GetAbilityName() { +std::string BundleActiveEvent::GetAbilityName() +{ return abilityName_; } -int BundleActiveEvent::GetAbilityId() { +int BundleActiveEvent::GetAbilityId() +{ return abilityId_; } -int64_t BundleActiveEvent::GetTimeStamp() { +int64_t BundleActiveEvent::GetTimeStamp() +{ return timeStamp_; } -int BundleActiveEvent::GetEventId() { +int BundleActiveEvent::GetEventId() +{ return eventId_; } -bool BundleActiveEvent::GetIsIdle() { +bool BundleActiveEvent::GetIsIdle() +{ return isIdle_; } } diff --git a/services/common/src/bundle_active_event_list.cpp b/services/common/src/bundle_active_event_list.cpp index 1604dcc..907aec9 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -17,19 +17,23 @@ namespace OHOS { namespace BundleActive { -BundleActiveEventList::BundleActiveEventList() { +BundleActiveEventList::BundleActiveEventList() +{ } -int BundleActiveEventList::Size() { +int BundleActiveEventList::Size() +{ return events_.size(); } -void BundleActiveEventList::Clear() { +void BundleActiveEventList::Clear() +{ events_.clear(); } -void BundleActiveEventList::Insert(BundleActiveEvent event) { +void BundleActiveEventList::Insert(BundleActiveEvent event) +{ int size = events_.size(); if (size == 0 || event.timeStamp_ >= events_.back().timeStamp_) { events_.push_back(event); @@ -39,7 +43,8 @@ void BundleActiveEventList::Insert(BundleActiveEvent event) { events_.insert(events_.begin() + insertIdx, event); } -int BundleActiveEventList::FindBestIndex(int64_t timeStamp) { +int BundleActiveEventList::FindBestIndex(int64_t timeStamp) +{ int size = events_.size(); int result = size; int lo = 0; @@ -57,7 +62,8 @@ int BundleActiveEventList::FindBestIndex(int64_t timeStamp) { return result; } -void BundleActiveEventList::Merge(const BundleActiveEventList& right) { +void BundleActiveEventList::Merge(const BundleActiveEventList& right) +{ int size = right.events_.size(); for (int i = 0; i < size; i++) { Insert(right.events_[i]); diff --git a/services/common/src/bundle_active_event_stats.cpp b/services/common/src/bundle_active_event_stats.cpp index f484b8d..127a983 100644 --- a/services/common/src/bundle_active_event_stats.cpp +++ b/services/common/src/bundle_active_event_stats.cpp @@ -17,7 +17,8 @@ namespace OHOS { namespace BundleActive { -BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig) { +BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig) +{ eventId_ = orig.eventId_; beginTimeStamp_ = orig.beginTimeStamp_; endTimeStamp_ = orig.endTimeStamp_; @@ -26,31 +27,38 @@ BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& ori count_ = orig.count_; } -int BundleActiveEventStats::GetEventId() { +int BundleActiveEventStats::GetEventId() +{ return eventId_; } -int BundleActiveEventStats::GetFirstTimeStamp() { +int BundleActiveEventStats::GetFirstTimeStamp() +{ return beginTimeStamp_; } -int BundleActiveEventStats::GetLastTimeStamp() { +int BundleActiveEventStats::GetLastTimeStamp() +{ return endTimeStamp_; } -int BundleActiveEventStats::GetLastEventTime() { +int BundleActiveEventStats::GetLastEventTime() +{ return lastEventTime_; } -int BundleActiveEventStats::GetTotalTime() { +int BundleActiveEventStats::GetTotalTime() +{ return totalTime_; } -int BundleActiveEventStats::GetCount() { +int BundleActiveEventStats::GetCount() +{ return count_; } -void BundleActiveEventStats::add(const BundleActiveEventStats& right) { +void BundleActiveEventStats::add(const BundleActiveEventStats& right) +{ if (eventId_ != right.eventId_) { return; } diff --git a/services/common/src/bundle_active_event_tracker.cpp b/services/common/src/bundle_active_event_tracker.cpp index b0afe2e..9baba83 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -17,14 +17,16 @@ namespace OHOS { namespace BundleActive { -void BundleActiveEventTracker::CommitTime(const int64_t timeStamp) { +void BundleActiveEventTracker::CommitTime(const int64_t timeStamp) +{ if (curStartTime_ != 0) { duration_ += timeStamp - curStartTime_; curStartTime_ = 0; } } -void BundleActiveEventTracker::Update(int64_t timeStamp) { +void BundleActiveEventTracker::Update(int64_t timeStamp) +{ if (curStartTime_ == 0) { count_++; } @@ -33,7 +35,8 @@ void BundleActiveEventTracker::Update(int64_t timeStamp) { lastEventTime_ = timeStamp; } -void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, const int eventId, const int64_t beginTime, const int64_t endTime) { +void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, const int eventId, const int64_t beginTime, const int64_t endTime) +{ if (count_ != 0 || duration_ != 0) { BundleActiveEventStats newEvent; newEvent.eventId_ = eventId; diff --git a/services/common/src/bundle_active_package_stats.cpp b/services/common/src/bundle_active_package_stats.cpp index 1b2005a..c61cc79 100644 --- a/services/common/src/bundle_active_package_stats.cpp +++ b/services/common/src/bundle_active_package_stats.cpp @@ -17,7 +17,8 @@ namespace OHOS { namespace BundleActive { -BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageStats& orig) { +BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageStats& orig) +{ bundleName_ = orig.bundleName_; beginTimeStamp_ = orig.beginTimeStamp_; endTimeStamp_ = orig.endTimeStamp_; @@ -32,74 +33,89 @@ BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageSta lastEvent_ = orig.lastEvent_; } -std::string BundleActivePackageStats::GetBundleName() { +std::string BundleActivePackageStats::GetBundleName() +{ return bundleName_; } -int64_t BundleActivePackageStats::GetBeginTimeStamp() { +int64_t BundleActivePackageStats::GetBeginTimeStamp() +{ return beginTimeStamp_; } -int64_t BundleActivePackageStats::GetEntTimeStamp() { +int64_t BundleActivePackageStats::GetEntTimeStamp() +{ return endTimeStamp_; } -int64_t BundleActivePackageStats::GetLastTimeUsed() { +int64_t BundleActivePackageStats::GetLastTimeUsed() +{ return lastTimeUsed_; } -int64_t BundleActivePackageStats::GetTotalTimeInFront() { +int64_t BundleActivePackageStats::GetTotalTimeInFront() +{ return totalTimeInFront_; } -int64_t BundleActivePackageStats::GetLastTimeFrontServiceUsed() { +int64_t BundleActivePackageStats::GetLastTimeFrontServiceUsed() +{ return lastTimeLongTimeTaskUsed_; } -int64_t BundleActivePackageStats::GetTotalTimeFrontServiceUsed() { +int64_t BundleActivePackageStats::GetTotalTimeFrontServiceUsed() +{ return totalTimeLongTimeTaskUsed_; } -int BundleActivePackageStats::GetLaunchedCount() { +int BundleActivePackageStats::GetLaunchedCount() +{ return launchedCount_; } -int BundleActivePackageStats::GetBundleLaunchedCount() { +int BundleActivePackageStats::GetBundleLaunchedCount() +{ return bundleLaunchedCount_; } bool BundleActivePackageStats::HasFrontAbility() { for (auto ability : abilities_) { - if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) { + if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) + { return true; } } return false; } -bool BundleActivePackageStats::AnyFrontServiceStarted() { +bool BundleActivePackageStats::AnyFrontServiceStarted() +{ return !frontServices_.empty(); } -void BundleActivePackageStats::IncrementTimeUsed(const int64_t timeStamp) { +void BundleActivePackageStats::IncrementTimeUsed(const int64_t timeStamp) +{ if (timeStamp > lastTimeUsed_) { totalTimeInFront_ += timeStamp - lastTimeUsed_; lastTimeUsed_ = timeStamp; } } -void BundleActivePackageStats::IncrementLongTimeTaskTimeUsed(const int64_t timeStamp) { +void BundleActivePackageStats::IncrementLongTimeTaskTimeUsed(const int64_t timeStamp) +{ if (timeStamp > lastTimeLongTimeTaskUsed_) { totalTimeLongTimeTaskUsed_ += timeStamp - lastTimeLongTimeTaskUsed_; lastTimeLongTimeTaskUsed_ = timeStamp; } } -void BundleActivePackageStats::IncrementBundleLaunchedCount() { +void BundleActivePackageStats::IncrementBundleLaunchedCount() +{ bundleLaunchedCount_ += 1; } -void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int eventId, const int abilityId) { +void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int eventId, const int abilityId) +{ if (eventId != BundleActiveEvent::ABILITY_FOREGROUND && eventId != BundleActiveEvent::ABILITY_BACKGROUND && eventId != BundleActiveEvent::ABILITY_STOP) { return; @@ -136,7 +152,8 @@ void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int } void BundleActivePackageStats::UpdateLongTimeTask(std::string longTimeTaskName, - const int64_t timeStamp, const int eventId) { + const int64_t timeStamp, const int eventId) + { if (eventId != BundleActiveEvent::LONG_TIME_TASK_STARTTED && eventId != BundleActiveEvent::LONG_TIME_TASK_STOPPED) { return; } @@ -168,7 +185,8 @@ void BundleActivePackageStats::UpdateLongTimeTask(std::string longTimeTaskName, } } -void BundleActivePackageStats::Update(std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId) { +void BundleActivePackageStats::Update(std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId) +{ switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: case BundleActiveEvent::ABILITY_BACKGROUND: diff --git a/services/common/src/bundle_active_period_stats.cpp b/services/common/src/bundle_active_period_stats.cpp index 57a408e..adf02e6 100644 --- a/services/common/src/bundle_active_period_stats.cpp +++ b/services/common/src/bundle_active_period_stats.cpp @@ -18,7 +18,8 @@ namespace OHOS { namespace BundleActive { -BundleActivePackageStats& BundleActivePeriodStats::GetOrCreateUsageStats(std::string bundleName) { +BundleActivePackageStats& BundleActivePeriodStats::GetOrCreateUsageStats(std::string bundleName) +{ std::map::iterator it; it = bundleStats_.find(bundleName); if (it == bundleStats_.end()) { @@ -31,7 +32,8 @@ BundleActivePackageStats& BundleActivePeriodStats::GetOrCreateUsageStats(std::st return bundleStats_[bundleName]; } -void BundleActivePeriodStats::Update(std::string bundleName, std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId) { +void BundleActivePeriodStats::Update(std::string bundleName, std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId) +{ if (eventId == BundleActiveEvent::DEVICE_SHUTDOWN || eventId == BundleActiveEvent::FLUSH_TO_DISK) { for (auto usageStatsPair : bundleStats_) { usageStatsPair.second.Update("", timeStamp, eventId, abilityId); @@ -45,7 +47,8 @@ void BundleActivePeriodStats::Update(std::string bundleName, std::string longTim } } -void BundleActivePeriodStats::AddEvent(BundleActiveEvent event) { +void BundleActivePeriodStats::AddEvent(BundleActiveEvent event) +{ event.bundleName_ = GetCachedString(event.bundleName_); if (!event.longTimeTaskName_.empty()) { event.longTimeTaskName_ = GetCachedString(event.longTimeTaskName_); @@ -56,29 +59,34 @@ void BundleActivePeriodStats::AddEvent(BundleActiveEvent event) { } } -void BundleActivePeriodStats::CommitTime(const int64_t timeStamp) { +void BundleActivePeriodStats::CommitTime(const int64_t timeStamp) +{ interactiveTracker_.CommitTime(timeStamp); noninteractiveTracker_.CommitTime(timeStamp); keyguardShownTracker_.CommitTime(timeStamp); keyguardHiddenTracker_.CommitTime(timeStamp); } -void BundleActivePeriodStats::UpdateScreenInteractive(const int64_t timeStamp) { +void BundleActivePeriodStats::UpdateScreenInteractive(const int64_t timeStamp) +{ interactiveTracker_.Update(timeStamp); noninteractiveTracker_.CommitTime(timeStamp); } -void BundleActivePeriodStats::UpdateScreenNonInteractive(const int64_t timeStamp) { +void BundleActivePeriodStats::UpdateScreenNonInteractive(const int64_t timeStamp) +{ noninteractiveTracker_.Update(timeStamp); interactiveTracker_.CommitTime(timeStamp); } -void BundleActivePeriodStats::UpdateKeyguardShown(const int64_t timeStamp) { +void BundleActivePeriodStats::UpdateKeyguardShown(const int64_t timeStamp) +{ keyguardShownTracker_.Update(timeStamp); keyguardHiddenTracker_.CommitTime(timeStamp); } -void BundleActivePeriodStats::UpdateKeyguardHidden(const int64_t timeStamp) { +void BundleActivePeriodStats::UpdateKeyguardHidden(const int64_t timeStamp) +{ keyguardHiddenTracker_.Update(timeStamp); keyguardShownTracker_.CommitTime(timeStamp); } @@ -90,7 +98,8 @@ void BundleActivePeriodStats::AddEventStatsTo(std::vector::iterator it; it = packetNamesCache_.find(str); if (it == packetNamesCache_.end()) { diff --git a/services/common/src/bundle_active_user_service.cpp b/services/common/src/bundle_active_user_service.cpp index 3c0f90c..787d591 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -17,20 +17,22 @@ namespace OHOS { namespace BundleActive { -BundleActiveUserService::BundleActiveUserService(int userId){//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/) { +BundleActiveUserService::BundleActiveUserService(int userId) +{ currentStats_.reserve(BundleActivePeriodStats::PERIOD_COUNT); - //m_listener = listener; userId_ = userId; statsChanged_ = false; } -void BundleActiveUserService::NotifyStatsChanged() { +void BundleActiveUserService::NotifyStatsChanged() +{ if (!statsChanged_) { statsChanged_ = true; } } -void BundleActiveUserService::ReportEvent(BundleActiveEvent event) { +void BundleActiveUserService::ReportEvent(BundleActiveEvent event) +{ BundleActivePeriodStats currentDailyStats = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]; if (event.eventId_ == BundleActiveEvent::ABILITY_FOREGROUND) { if (!event.bundleName_.empty() && event.bundleName_ != lastBackgroundBundle_) { diff --git a/services/include/bundle_active_iservice.h b/services/include/bundle_active_iservice.h index 910166e..2f77dc5 100644 --- a/services/include/bundle_active_iservice.h +++ b/services/include/bundle_active_iservice.h @@ -52,5 +52,4 @@ public: }; } } - #endif \ No newline at end of file diff --git a/services/src/bundle_active_service.cpp b/services/src/bundle_active_service.cpp index 84c9d3d..5ddd885 100644 --- a/services/src/bundle_active_service.cpp +++ b/services/src/bundle_active_service.cpp @@ -34,19 +34,22 @@ void BundleActiveService::OnStop() BUNDLE_ACTIVE_LOGI("[Server] OnStop"); } -int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) { +int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) +{ BUNDLE_ACTIVE_LOGI("Report event called"); - return 111; + return 0; } -int BundleActiveService::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveService::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +{ BUNDLE_ACTIVE_LOGI("Is bundle active called"); return true; } -int BundleActiveService::Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveService::Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +{ BUNDLE_ACTIVE_LOGI("Query called"); - return 222; + return 0; } } } \ No newline at end of file diff --git a/services/src/bundle_active_stub.cpp b/services/src/bundle_active_stub.cpp index f1caeec..8f97964 100644 --- a/services/src/bundle_active_stub.cpp +++ b/services/src/bundle_active_stub.cpp @@ -18,7 +18,8 @@ namespace OHOS { namespace BundleActive { -int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) { +int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) +{ switch(code) { case REPORT_EVENT: { std::string bundleName = data.ReadString(); -- Gitee