From a3d0cc6640f0d5723b9a00e2add8407e6a1c9958 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 16 Feb 2022 17:07:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E9=97=AE=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 From 3ae8c256ddca012d95402d48a58bfe750f5b8929 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 16 Feb 2022 17:14:09 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_user_service.h | 2 +- services/common/src/bundle_active_period_stats.cpp | 1 - services/include/bundle_active_service.h | 1 - services/include/bundle_active_stub.h | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/services/common/include/bundle_active_user_service.h b/services/common/include/bundle_active_user_service.h index e26f22a..ef43c92 100644 --- a/services/common/include/bundle_active_user_service.h +++ b/services/common/include/bundle_active_user_service.h @@ -35,7 +35,7 @@ private: bool statsChanged_; std::string lastBackgroundBundle_; inline static const std::vector PERIOD_LENGTH = {BundleActivePeriodStats::DAY_IN_MILLIS, BundleActivePeriodStats::WEEK_IN_MILLIS, - BundleActivePeriodStats::MONTH_IN_MILLIS, BundleActivePeriodStats::YEAR_IN_MILLIS}; + BundleActivePeriodStats::MONTH_IN_MILLIS, BundleActivePeriodStats::YEAR_IN_MILLIS}; void NotifyStatsChanged(); void ReportEvent(BundleActiveEvent event); }; diff --git a/services/common/src/bundle_active_period_stats.cpp b/services/common/src/bundle_active_period_stats.cpp index adf02e6..87d475d 100644 --- a/services/common/src/bundle_active_period_stats.cpp +++ b/services/common/src/bundle_active_period_stats.cpp @@ -108,6 +108,5 @@ std::string BundleActivePeriodStats::GetCachedString(std::string str) } return *it; } - } } \ No newline at end of file diff --git a/services/include/bundle_active_service.h b/services/include/bundle_active_service.h index 343eada..ae40a7a 100644 --- a/services/include/bundle_active_service.h +++ b/services/include/bundle_active_service.h @@ -21,7 +21,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveService : public SystemAbility, public BundleActiveStub { DECLARE_SYSTEM_ABILITY(BundleActiveService); diff --git a/services/include/bundle_active_stub.h b/services/include/bundle_active_stub.h index 5b1843d..ad15217 100644 --- a/services/include/bundle_active_stub.h +++ b/services/include/bundle_active_stub.h @@ -20,7 +20,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveStub : public IRemoteStub { public: virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) override; -- Gitee From 5aaf60743ea78ef46b13a12a49383dc4b17d5b88 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 16 Feb 2022 17:18:54 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_client.cpp | 15 +++++++++------ interfaces/innerkits/src/bundle_active_proxy.cpp | 11 +++++++---- services/common/src/bundle_active_event_list.cpp | 2 +- services/common/src/bundle_active_event_stats.cpp | 2 +- .../common/src/bundle_active_event_tracker.cpp | 2 +- .../common/src/bundle_active_package_stats.cpp | 2 +- .../common/src/bundle_active_period_stats.cpp | 2 +- .../common/src/bundle_active_user_service.cpp | 2 +- services/src/bundle_active_service.cpp | 2 +- services/src/bundle_active_stub.cpp | 2 +- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 7ddb46d..6e3afae 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -17,12 +17,14 @@ namespace OHOS { namespace BundleActive { -BundleActiveClient& BundleActiveClient::GetInstance() { +BundleActiveClient& BundleActiveClient::GetInstance() +{ static BundleActiveClient instance; return instance; } -bool BundleActiveClient::GetBundleActiveProxy() { +bool BundleActiveClient::GetBundleActiveProxy() +{ sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); @@ -42,14 +44,16 @@ bool BundleActiveClient::GetBundleActiveProxy() { } return true; } -int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) { +int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) +{ if (!GetBundleActiveProxy()) { return -1; } return bundleActiveProxy->ReportEvent(bundleName, abilityName, abilityId, userId, eventId); } -int BundleActiveClient::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveClient::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +{ if (!GetBundleActiveProxy()) { return -1; } @@ -62,6 +66,5 @@ int BundleActiveClient::Query(std::string& bundleName, std::string& abilityName, } return bundleActiveProxy->Query(bundleName, abilityName, abilityId, userId); } - } -} \ No newline at end of file +} diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 4b941b8..13a00a7 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,7 +17,8 @@ namespace OHOS{ namespace BundleActive { -int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) { +int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) +{ MessageParcel data; MessageParcel reply; MessageOption option; @@ -32,7 +33,8 @@ int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& ability return result; } -int BundleActiveProxy::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveProxy::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +{ MessageParcel data; MessageParcel reply; MessageOption option; @@ -46,7 +48,8 @@ int BundleActiveProxy::IsBundleIdle(std::string& bundleName, std::string& abilit return result; } -int BundleActiveProxy::Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveProxy::Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +{ MessageParcel data; MessageParcel reply; MessageOption option; @@ -60,4 +63,4 @@ int BundleActiveProxy::Query(std::string& bundleName, std::string& abilityName, return result; } } -} \ No newline at end of file +} diff --git a/services/common/src/bundle_active_event_list.cpp b/services/common/src/bundle_active_event_list.cpp index 907aec9..4c027dc 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -70,4 +70,4 @@ void BundleActiveEventList::Merge(const BundleActiveEventList& right) } } } -} \ No newline at end of file +} diff --git a/services/common/src/bundle_active_event_stats.cpp b/services/common/src/bundle_active_event_stats.cpp index 127a983..707564d 100644 --- a/services/common/src/bundle_active_event_stats.cpp +++ b/services/common/src/bundle_active_event_stats.cpp @@ -72,4 +72,4 @@ void BundleActiveEventStats::add(const BundleActiveEventStats& right) count_ += right.count_; } } -} \ No newline at end of file +} diff --git a/services/common/src/bundle_active_event_tracker.cpp b/services/common/src/bundle_active_event_tracker.cpp index 9baba83..928e9f9 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -49,4 +49,4 @@ void BundleActiveEventTracker::AddToEventStats(std::vector Date: Wed, 16 Feb 2022 17:33:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_client.cpp | 6 ++++-- interfaces/innerkits/src/bundle_active_proxy.cpp | 3 ++- services/common/src/bundle_active_event_tracker.cpp | 3 ++- services/common/src/bundle_active_package_stats.cpp | 10 +++++----- services/common/src/bundle_active_period_stats.cpp | 3 ++- services/include/bundle_active_service.h | 3 ++- services/src/bundle_active_service.cpp | 9 ++++++--- services/src/bundle_active_stub.cpp | 3 ++- 8 files changed, 25 insertions(+), 15 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 6e3afae..86a86e5 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -44,7 +44,8 @@ bool BundleActiveClient::GetBundleActiveProxy() } return true; } -int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) +int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId, const int& eventId) { if (!GetBundleActiveProxy()) { return -1; @@ -52,7 +53,8 @@ int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilit return bundleActiveProxy->ReportEvent(bundleName, abilityName, abilityId, userId, eventId); } -int BundleActiveClient::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +int BundleActiveClient::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId) { if (!GetBundleActiveProxy()) { return -1; diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 13a00a7..ef77469 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,7 +17,8 @@ namespace OHOS{ namespace BundleActive { -int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) +int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId, const int& eventId) { MessageParcel data; MessageParcel reply; diff --git a/services/common/src/bundle_active_event_tracker.cpp b/services/common/src/bundle_active_event_tracker.cpp index 928e9f9..7735d72 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -35,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; diff --git a/services/common/src/bundle_active_package_stats.cpp b/services/common/src/bundle_active_package_stats.cpp index 1bb8a1a..a4e595a 100644 --- a/services/common/src/bundle_active_package_stats.cpp +++ b/services/common/src/bundle_active_package_stats.cpp @@ -80,8 +80,7 @@ int BundleActivePackageStats::GetBundleLaunchedCount() bool BundleActivePackageStats::HasFrontAbility() { for (auto ability : abilities_) { - if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) - { + if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) { return true; } } @@ -152,8 +151,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; } @@ -185,7 +184,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: diff --git a/services/common/src/bundle_active_period_stats.cpp b/services/common/src/bundle_active_period_stats.cpp index 8b63e64..7a9108a 100644 --- a/services/common/src/bundle_active_period_stats.cpp +++ b/services/common/src/bundle_active_period_stats.cpp @@ -32,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_) { diff --git a/services/include/bundle_active_service.h b/services/include/bundle_active_service.h index ae40a7a..537c899 100644 --- a/services/include/bundle_active_service.h +++ b/services/include/bundle_active_service.h @@ -25,7 +25,8 @@ class BundleActiveService : public SystemAbility, public BundleActiveStub { DECLARE_SYSTEM_ABILITY(BundleActiveService); public: - int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) override; + int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId, const int& eventId) override; int IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) override; int Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) override; BundleActiveService(int32_t systemAbilityId, int runOnCreate) diff --git a/services/src/bundle_active_service.cpp b/services/src/bundle_active_service.cpp index ac80232..5673d57 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 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 0; diff --git a/services/src/bundle_active_stub.cpp b/services/src/bundle_active_stub.cpp index 3bbfda1..b9f333a 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: { -- Gitee From e13df8920bdaeff7b5d40279139e8214c5368e55 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 16 Feb 2022 17:37:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_proxy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index ef77469..d19611d 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -34,7 +34,8 @@ int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& ability return result; } -int BundleActiveProxy::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) +int BundleActiveProxy::IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId) { MessageParcel data; MessageParcel reply; -- Gitee