diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 1576288a21f001a1027cc1ecabd33b779b61c380..0a44623c020ff2f042b45729fe0ffd18b92ef4d7 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -16,13 +16,14 @@ #ifndef BUNDLE_ACTIVE_CLIENT_H #define BUNDLE_ACTIVE_CLIENT_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" namespace OHOS { namespace BundleActive { class BundleActiveClient { public: - int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId); + int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId, const int& eventId); int IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId); int Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId); static BundleActiveClient& GetInstance(); @@ -34,6 +35,6 @@ private: bool GetBundleActiveProxy(); sptr bundleActiveProxy; }; -} +} } #endif \ No newline at end of file diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index ac9d22cadbe884479a24afd7d8606580363ad3be..b449be2181eb251f2a64c698b474999a1c19b220 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -16,13 +16,14 @@ #ifndef BUNDLE_ACTIVE_PROXY_H #define BUNDLE_ACTIVE_PROXY_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" namespace OHOS { namespace BundleActive { class BundleActiveProxy : public IRemoteProxy { 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; diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 86a86e532da7a2c4b9659810f673123883a4ce32..eb90b0f0553d3af8c224354e95a30f6c23c23200 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -44,6 +44,7 @@ bool BundleActiveClient::GetBundleActiveProxy() } return true; } + int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) { @@ -62,7 +63,9 @@ int BundleActiveClient::IsBundleIdle(std::string& bundleName, std::string& abili return bundleActiveProxy->IsBundleIdle(bundleName, abilityName, abilityId, userId); } -int BundleActiveClient::Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) { +int BundleActiveClient::Query(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 d19611d4ef48918f1f733980dc3e98ea634688af..04ae360e333c7dfebdab1c81d5d1c5c7f2edac42 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -15,7 +15,7 @@ #include "bundle_active_proxy.h" -namespace OHOS{ +namespace OHOS { namespace BundleActive { int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) diff --git a/services/common/include/bundle_active_event.h b/services/common/include/bundle_active_event.h index 4f5f2d9d3c601327bf05527d3eb544cac752440b..0ec081d9636bc5104538666d5c090e90cc6b9b7d 100644 --- a/services/common/include/bundle_active_event.h +++ b/services/common/include/bundle_active_event.h @@ -16,22 +16,20 @@ #ifndef BUNDLE_ACTIVE_EVENT_H #define BUNDLE_ACTIVE_EVENT_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" namespace OHOS { namespace BundleActive { class BundleActiveEvent { public: - //external events - static const int ABILITY_FOREGROUND = 2;//onForeground() called, ability is in front. - static const int ABILITY_BACKGROUND = 3;//onBackground() called, ability is in background. - static const int ABILITY_STOP = 4;//onStop() called, ability is destroyed. + static const int ABILITY_FOREGROUND = 2; + static const int ABILITY_BACKGROUND = 3; + static const int ABILITY_STOP = 4; static const int LONG_TIME_TASK_STARTTED = 5; static const int LONG_TIME_TASK_STOPPED = 6; static const int SYSTEM_INTERACTIVE = 7; static const int USER_INTERACTIVE = 8; - //internal events - static const int END_OF_THE_DAY = 9; + static const int END_OF_THE_DAY = 9; static const int DEVICE_SHUTDOWN = 10; static const int DEVICE_STARTUP = 11; static const int FLUSH_TO_DISK = 12; diff --git a/services/common/include/bundle_active_event_list.h b/services/common/include/bundle_active_event_list.h index 1ac946e744b58f1eceb6b8f4fccfff3d9dfbc552..17ede3f84254a7e239cbb6c1dc0a7c5c6b6dd310 100644 --- a/services/common/include/bundle_active_event_list.h +++ b/services/common/include/bundle_active_event_list.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_EVENT_LIST_H #define BUNDLE_ACTIVE_EVENT_LIST_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_event.h" namespace OHOS { diff --git a/services/common/include/bundle_active_event_stats.h b/services/common/include/bundle_active_event_stats.h index e4469854d4833cbbab825145bb253225c01bc470..8400c92239a4a38215d59873029c11513f2abb45 100644 --- a/services/common/include/bundle_active_event_stats.h +++ b/services/common/include/bundle_active_event_stats.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_EVENT_STATS_H #define BUNDLE_ACTIVE_EVENT_STATS_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" namespace OHOS { namespace BundleActive { diff --git a/services/common/include/bundle_active_event_tracker.h b/services/common/include/bundle_active_event_tracker.h index 19af858521c5e1a4804173bf26804643847e06bb..0866a4cd28ec6d029d2b4e2975ce4db758615944 100644 --- a/services/common/include/bundle_active_event_tracker.h +++ b/services/common/include/bundle_active_event_tracker.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_EVENT_TRACKER_H #define BUNDLE_ACTIVE_EVENT_TRACKER_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_event_stats.h" namespace OHOS { @@ -29,7 +29,8 @@ public: int64_t count_; void CommitTime(const int64_t timeStamp); void Update(int64_t timeStamp); - void AddToEventStats(std::vector& eventStatsList, const int eventId, const int64_t beginTime, const int64_t endTime); + void AddToEventStats(std::vector& eventStatsList, const int eventId, + const int64_t beginTime, const int64_t endTime); BundleActiveEventTracker() {}; }; } diff --git a/services/common/include/bundle_active_package_stats.h b/services/common/include/bundle_active_package_stats.h index 9d0c9f3d34c996a69e79fc06fb11a1146cca1d9e..c893a1bc64059920a3e919e8cc34f4cb6c48d647 100644 --- a/services/common/include/bundle_active_package_stats.h +++ b/services/common/include/bundle_active_package_stats.h @@ -16,26 +16,25 @@ #ifndef bundle_active_package_stats_H #define bundle_active_package_stats_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_event.h" namespace OHOS { namespace BundleActive { -//bundles statistics, including Abilityies and frontservices. class BundleActivePackageStats { public: std::string bundleName_; - int64_t beginTimeStamp_; //start time of counting - int64_t endTimeStamp_; //stop time of counting - int64_t lastTimeUsed_; //the timestamp of last launch - int64_t totalTimeInFront_; // the total time of using the bundle + int64_t beginTimeStamp_; + int64_t endTimeStamp_; + int64_t lastTimeUsed_; + int64_t totalTimeInFront_; int64_t lastTimeLongTimeTaskUsed_; int64_t totalTimeLongTimeTaskUsed_; int launchedCount_; int bundleLaunchedCount_; int lastEvent_; - std::map abilities_; // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. - std::map frontServices_; // restore the frontservices' names using by bundle. + std::map abilities_; + std::map frontServices_; BundleActivePackageStats() {}; BundleActivePackageStats(const BundleActivePackageStats& orig); std::string GetBundleName(); @@ -56,10 +55,8 @@ private: bool HasFrontAbility(); bool AnyFrontServiceStarted(); void UpdateAbility(const int64_t timeStamp, const int eventId, const int abilityId); - void UpdateLongTimeTask(std::string longTimeTaskName, + void UpdateLongTimeTask(std::string longTimeTaskName, const int64_t timeStamp, const int eventId); - - }; } } diff --git a/services/common/include/bundle_active_period_stats.h b/services/common/include/bundle_active_period_stats.h index 29952ad4fb9a06276b720daf84e165b060598455..fb64d5ec2ec0f316b21035f0ea1e9323cca2eca3 100644 --- a/services/common/include/bundle_active_period_stats.h +++ b/services/common/include/bundle_active_period_stats.h @@ -16,7 +16,7 @@ #ifndef bundle_active_period_stats_H #define bundle_active_period_stats_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_event.h" #include "bundle_active_package_stats.h" #include "bundle_active_event_list.h" @@ -48,7 +48,8 @@ public: BundleActiveEventTracker keyguardHiddenTracker_; BundleActivePackageStats& GetOrCreateUsageStats(std::string bundleName); BundleActiveEvent BuildEvent(std::string bundleName, std::string longTimeTaskName); - void Update(std::string bundleName, std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId); + void Update(std::string bundleName, std::string longTimeTaskName, const int64_t timeStamp, const int eventId, + const int abilityId); void AddEvent(BundleActiveEvent event); void UpdateScreenInteractive(const int64_t timeStamp); void UpdateScreenNonInteractive(const int64_t timeStamp); @@ -59,7 +60,6 @@ private: void CommitTime(const int64_t timeStamp); void AddEventStatsTo(std::vector& eventStatsList); std::string GetCachedString(std::string str); - }; } } diff --git a/services/common/include/bundle_active_user_service.h b/services/common/include/bundle_active_user_service.h index ef43c9295a750bbc23f796d10279f08ef574c68a..0f9bba30d61e3d4cc4253758608c780be7058846 100644 --- a/services/common/include/bundle_active_user_service.h +++ b/services/common/include/bundle_active_user_service.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_USER_SERVICE_H #define BUNDLE_ACTIVE_USER_SERVICE_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_event.h" #include "bundle_active_package_stats.h" #include "bundle_active_period_stats.h" @@ -24,18 +24,18 @@ namespace OHOS { namespace BundleActive { - class BundleActiveUserService { public: - BundleActiveUserService(int userId);//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/); + BundleActiveUserService(int userId); private: int incrementBundleLaunch_; int userId_; std::vector currentStats_; 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}; + inline static const std::vector PERIOD_LENGTH = {BundleActivePeriodStats::DAY_IN_MILLIS, + BundleActivePeriodStats::WEEK_IN_MILLIS, BundleActivePeriodStats::MONTH_IN_MILLIS, + BundleActivePeriodStats::YEAR_IN_MILLIS}; void NotifyStatsChanged(); void ReportEvent(BundleActiveEvent event); }; diff --git a/services/common/src/bundle_active_event_list.cpp b/services/common/src/bundle_active_event_list.cpp index 4c027dc3f30e82e84c9b68e7feeebd1a61ecd48d..3e4b715f7a4249d11482bfa3a449803b280bff0e 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -19,7 +19,6 @@ namespace OHOS { namespace BundleActive { BundleActiveEventList::BundleActiveEventList() { - } int BundleActiveEventList::Size() diff --git a/services/common/src/bundle_active_package_stats.cpp b/services/common/src/bundle_active_package_stats.cpp index a4e595a2b13e03496163640705118c1d2f422577..2ba32cacf8eaa3c45e6248d7dcc6bcd7d5ef4ab8 100644 --- a/services/common/src/bundle_active_package_stats.cpp +++ b/services/common/src/bundle_active_package_stats.cpp @@ -78,7 +78,8 @@ int BundleActivePackageStats::GetBundleLaunchedCount() return bundleLaunchedCount_; } -bool BundleActivePackageStats::HasFrontAbility() { +bool BundleActivePackageStats::HasFrontAbility() +{ for (auto ability : abilities_) { if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) { return true; @@ -115,15 +116,13 @@ void BundleActivePackageStats::IncrementBundleLaunchedCount() void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int eventId, const int abilityId) { - if (eventId != BundleActiveEvent::ABILITY_FOREGROUND && eventId != BundleActiveEvent::ABILITY_BACKGROUND && + if (eventId != BundleActiveEvent::ABILITY_FOREGROUND && eventId != BundleActiveEvent::ABILITY_BACKGROUND && eventId != BundleActiveEvent::ABILITY_STOP) { return; } - std::map::iterator it; - it = abilities_.find(abilityId); + std::map::iterator it = abilities_.find(abilityId); if (it != abilities_.end()) { int lastEventId = it->second; - //When we recieve a new event, first update the time stats according to the last event in map. switch (lastEventId) { case BundleActiveEvent::ABILITY_FOREGROUND: IncrementTimeUsed(timeStamp); @@ -150,16 +149,13 @@ void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int } } -void BundleActivePackageStats::UpdateLongTimeTask(std::string longTimeTaskName, +void BundleActivePackageStats::UpdateLongTimeTask(std::string longTimeTaskName, const int64_t timeStamp, const int eventId) { if (eventId != BundleActiveEvent::LONG_TIME_TASK_STARTTED && eventId != BundleActiveEvent::LONG_TIME_TASK_STOPPED) { return; } - - //When we recieve a new event, first update the time stats according to the last service event in map. - std::map::iterator it; - it = frontServices_.find(longTimeTaskName); + std::map::iterator it = frontServices_.find(longTimeTaskName); if (it != frontServices_.end()) { int lastEventId = it->second; switch (lastEventId) { @@ -172,7 +168,7 @@ void BundleActivePackageStats::UpdateLongTimeTask(std::string longTimeTaskName, switch (eventId) { case BundleActiveEvent::LONG_TIME_TASK_STARTTED: - if(!AnyFrontServiceStarted()) { + if (!AnyFrontServiceStarted()) { lastTimeLongTimeTaskUsed_ = timeStamp; } frontServices_[longTimeTaskName] = eventId; diff --git a/services/common/src/bundle_active_period_stats.cpp b/services/common/src/bundle_active_period_stats.cpp index 7a9108a16c28b12a4da9896fb6cebccbe320f9e3..d74063495998998ce3594a021d04cd4685561412 100644 --- a/services/common/src/bundle_active_period_stats.cpp +++ b/services/common/src/bundle_active_period_stats.cpp @@ -20,8 +20,7 @@ namespace OHOS { namespace BundleActive { BundleActivePackageStats& BundleActivePeriodStats::GetOrCreateUsageStats(std::string bundleName) { - std::map::iterator it; - it = bundleStats_.find(bundleName); + std::map::iterator it = bundleStats_.find(bundleName); if (it == bundleStats_.end()) { BundleActivePackageStats newStats; newStats.beginTimeStamp_ = beginTime_; @@ -92,17 +91,18 @@ void BundleActivePeriodStats::UpdateKeyguardHidden(const int64_t timeStamp) keyguardShownTracker_.CommitTime(timeStamp); } -void BundleActivePeriodStats::AddEventStatsTo(std::vector& eventStatsList) { +void BundleActivePeriodStats::AddEventStatsTo(std::vector& eventStatsList) +{ interactiveTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_INTERACTIVE, beginTime_, endTime_); - noninteractiveTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_NON_INTERACTIVE, beginTime_, endTime_); + noninteractiveTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_NON_INTERACTIVE, + beginTime_, endTime_); keyguardShownTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::KEYGUARD_SHOWN, beginTime_, endTime_); keyguardHiddenTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::KEYGUARD_HIDDEN, beginTime_, endTime_); } std::string BundleActivePeriodStats::GetCachedString(std::string str) { - std::set::iterator it; - it = packetNamesCache_.find(str); + std::set::iterator it = packetNamesCache_.find(str); if (it == packetNamesCache_.end()) { packetNamesCache_.insert(str); return str; diff --git a/services/common/src/bundle_active_user_service.cpp b/services/common/src/bundle_active_user_service.cpp index 293367ddde003fa0e5289483af0725e470b00864..932fcc2acea6e1364979d670dbb838d1ce748bf7 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -44,8 +44,7 @@ void BundleActiveUserService::ReportEvent(BundleActiveEvent event) } } for (int i = 0; i < currentStats_.size(); i++) { - switch (event.eventId_) - { + switch (event.eventId_) { case BundleActiveEvent::SCREEN_INTERACTIVE: currentStats_[i].UpdateScreenInteractive(event.timeStamp_); break; @@ -59,7 +58,8 @@ void BundleActiveUserService::ReportEvent(BundleActiveEvent event) currentStats_[i].UpdateKeyguardHidden(event.timeStamp_); break; default: - currentStats_[i].Update(event.bundleName_, event.longTimeTaskName_, event.timeStamp_, event.eventId_, event.abilityId_); + currentStats_[i].Update(event.bundleName_, event.longTimeTaskName_, event.timeStamp_, + event.eventId_, event.abilityId_); if (incrementBundleLaunch_) { currentStats_[i].bundleStats_[event.bundleName_].IncrementBundleLaunchedCount(); } diff --git a/services/include/bundle_active_service.h b/services/include/bundle_active_service.h index 537c899dc58d24fb835b128da5d523c392466aa1..44a9eb6c6bff0e00cfb1460ddd3a1397a5943f1a 100644 --- a/services/include/bundle_active_service.h +++ b/services/include/bundle_active_service.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_SERVICE_H #define BUNDLE_ACTIVE_SERVICE_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" #include "bundle_active_stub.h" namespace OHOS { @@ -37,6 +37,6 @@ protected: void OnStart() override; void OnStop() override; }; -} +} } #endif \ No newline at end of file diff --git a/services/include/bundle_active_stub.h b/services/include/bundle_active_stub.h index ad1521730d16c96c25851c6d6a90f27cee9c81d3..c8e758c4825d42a6c73288d903881c0127aee581 100644 --- a/services/include/bundle_active_stub.h +++ b/services/include/bundle_active_stub.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_STUB_H #define BUNDLE_ACTIVE_STUB_H -#include "bundle_active_iservice.h" +#include "ibundle_active_service.h" namespace OHOS { namespace BundleActive { diff --git a/services/include/bundle_active_iservice.h b/services/include/ibundle_active_service.h similarity index 90% rename from services/include/bundle_active_iservice.h rename to services/include/ibundle_active_service.h index 2f77dc50f1ad4dbef984b668da2c398cc6466b98..68bca28e35b60839d4e73c3e28c898dc4fd8bac2 100644 --- a/services/include/bundle_active_iservice.h +++ b/services/include/ibundle_active_service.h @@ -34,11 +34,12 @@ namespace OHOS { namespace BundleActive { - class IBundleActiveService : public IRemoteBroker { public: - virtual int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) = 0; - virtual int IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) = 0; + virtual int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId, const int& eventId) = 0; + virtual int IsBundleIdle(std::string& bundleName, std::string& abilityName, const int& abilityId, + const int& userId) = 0; virtual int Query(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId) = 0; public: diff --git a/services/src/bundle_active_stub.cpp b/services/src/bundle_active_stub.cpp index b9f333a6e3b26d78848ef71ee4b7eae335782454..7f2337c167eb1c76183ba0d4c318f3a2dd739930 100644 --- a/services/src/bundle_active_stub.cpp +++ b/services/src/bundle_active_stub.cpp @@ -21,7 +21,7 @@ namespace BundleActive { int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) { - switch(code) { + switch (code) { case REPORT_EVENT: { std::string bundleName = data.ReadString(); std::string ablityName = data.ReadString(); @@ -45,7 +45,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int abilityId = data.ReadInt32(); int userId = data.ReadInt32(); int result = Query(bundleName, ablityName, abilityId, userId); - return reply.WriteInt32(result); + return reply.WriteInt32(result); } default: