From 18d3f4bfe7ab3db6d801e2a3f02d2061868ffee8 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 10 Jan 2022 21:22:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/.gitkeep | 0 .../innerkits/include/bundle_active_client.h | 2 -- .../innerkits/include/bundle_active_proxy.h | 2 -- .../innerkits/src/bundle_active_client.cpp | 1 - .../innerkits/src/bundle_active_proxy.cpp | 2 -- services/common/include/bundle_active_event.h | 9 +-------- .../common/include/bundle_active_event_list.h | 1 - .../common/include/bundle_active_event_stats.h | 2 -- .../include/bundle_active_event_tracker.h | 2 -- .../include/bundle_active_interval_stats.h | 3 --- .../common/include/bundle_active_usage_stats.h | 3 +-- .../include/bundle_active_user_service.h | 5 ----- services/common/src/bundle_active_event.cpp | 2 -- .../common/src/bundle_active_event_list.cpp | 6 +++++- .../common/src/bundle_active_event_stats.cpp | 8 ++++++-- .../common/src/bundle_active_event_tracker.cpp | 3 ++- .../src/bundle_active_interval_stats.cpp | 1 - .../common/src/bundle_active_usage_stats.cpp | 18 +++++++++++++++++- .../common/src/bundle_active_user_service.cpp | 3 +-- services/include/bundle_active_iservice.h | 1 - services/include/bundle_active_service.h | 6 ------ services/src/bundle_active_service.cpp | 6 ++---- services/src/bundle_active_stub.cpp | 2 -- 23 files changed, 35 insertions(+), 53 deletions(-) create mode 100644 interfaces/innerkits/.gitkeep diff --git a/interfaces/innerkits/.gitkeep b/interfaces/innerkits/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 20fb365..1576288 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -20,7 +20,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveClient { public: int ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId); @@ -35,7 +34,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 a12e1d9..ac9d22c 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -20,7 +20,6 @@ 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; @@ -35,7 +34,6 @@ public: private: static inline BrokerDelegator delegator_; }; - } } diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 0540c44..9f9d835 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -17,7 +17,6 @@ namespace OHOS { namespace BundleActive { - BundleActiveClient& BundleActiveClient::GetInstance() { static BundleActiveClient instance; return instance; diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 1187cbd..4b941b8 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,7 +17,6 @@ namespace OHOS{ namespace BundleActive { - int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, const int& abilityId, const int& userId, const int& eventId) { MessageParcel data; MessageParcel reply; @@ -60,6 +59,5 @@ int BundleActiveProxy::Query(std::string& bundleName, std::string& abilityName, int32_t result = reply.ReadInt32(); return result; } - } } \ No newline at end of file diff --git a/services/common/include/bundle_active_event.h b/services/common/include/bundle_active_event.h index 7d3158f..551dcb8 100644 --- a/services/common/include/bundle_active_event.h +++ b/services/common/include/bundle_active_event.h @@ -20,23 +20,18 @@ namespace OHOS { namespace BundleActive { - class BundleActiveEvent { public: //external events - //static const int ABILITY_START = 1;//onStart() called, ability is not in front, but still visible 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 FRONT_SERVICE_STARTTED = 5; - //static const int FRONT_SERVICE_CONTINUED = 11; static const int FRONT_SERVICE_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 CONTINUE_PREVIOUS_DAY = 21; static const int DEVICE_SHUTDOWN = 10; static const int DEVICE_STARTUP = 11; static const int FLUSH_TO_DISK = 12; @@ -52,8 +47,6 @@ public: long m_timeStamp; int m_eventId; bool m_isIdle; - -public: BundleActiveEvent() {}; BundleActiveEvent(const BundleActiveEvent& orig); BundleActiveEvent(int eventId, long timeStamp); @@ -64,7 +57,7 @@ public: int GetEventId(); bool GetIsIdle(); }; - } } + #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_event_list.h b/services/common/include/bundle_active_event_list.h index e8c0076..85242e2 100644 --- a/services/common/include/bundle_active_event_list.h +++ b/services/common/include/bundle_active_event_list.h @@ -32,7 +32,6 @@ public: private: std::vector m_events; }; - } } #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_event_stats.h b/services/common/include/bundle_active_event_stats.h index e7a789e..366e310 100644 --- a/services/common/include/bundle_active_event_stats.h +++ b/services/common/include/bundle_active_event_stats.h @@ -20,7 +20,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveEventStats { public: int m_eventId; @@ -39,7 +38,6 @@ public: int GetCount(); void add(const BundleActiveEventStats& right); }; - } } #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_event_tracker.h b/services/common/include/bundle_active_event_tracker.h index 09dc98a..be13bf5 100644 --- a/services/common/include/bundle_active_event_tracker.h +++ b/services/common/include/bundle_active_event_tracker.h @@ -21,7 +21,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveEventTracker { public: long m_curStartTime; @@ -33,7 +32,6 @@ public: void AddToEventStats(std::vector& eventStatsList, int eventId, long beginTime, long endTime); BundleActiveEventTracker() {}; }; - } } #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_interval_stats.h b/services/common/include/bundle_active_interval_stats.h index ea7e74e..1caa687 100644 --- a/services/common/include/bundle_active_interval_stats.h +++ b/services/common/include/bundle_active_interval_stats.h @@ -24,7 +24,6 @@ namespace OHOS { namespace BundleActive { - class BundleActiveIntervalStats { public: static const int CURRENT_MAJOR_VERSION = 1; @@ -51,7 +50,6 @@ public: BundleActiveEventTracker m_noninteractiveTracker; BundleActiveEventTracker m_keyguardShownTracker; BundleActiveEventTracker m_keyguardHiddenTracker; - BundleActiveUsageStats& GetOrCreateUsageStats(std::string bundleName); BundleActiveEvent BuildEvent(std::string bundleName, std::string serviceName); void Update(std::string bundleName, std::string serviceName, long timeStamp, int eventId, int abilityId); @@ -67,7 +65,6 @@ private: std::string GetCachedString(std::string str); }; - } } #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_usage_stats.h b/services/common/include/bundle_active_usage_stats.h index f97e3b8..10eb568 100644 --- a/services/common/include/bundle_active_usage_stats.h +++ b/services/common/include/bundle_active_usage_stats.h @@ -21,7 +21,6 @@ namespace OHOS { namespace BundleActive { - //bundles statistics, including activities and frontservices. class BundleActiveUsageStats { public: @@ -52,6 +51,7 @@ public: void IncrementTimeUsed(long timeStamp); void IncrementServiceTimeUsed(long timeStamp); void IncrementBundleLaunchedCount(); + private: bool HasFrontAbility(); bool AnyFrontServiceStarted(); @@ -60,7 +60,6 @@ private: }; - } } #endif diff --git a/services/common/include/bundle_active_user_service.h b/services/common/include/bundle_active_user_service.h index 3e68c03..5e8abec 100644 --- a/services/common/include/bundle_active_user_service.h +++ b/services/common/include/bundle_active_user_service.h @@ -27,7 +27,6 @@ namespace BundleActive { class BundleActiveUserService { public: - BundleActiveUserService(int userId);//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/); virtual void onStatsUpdated() = 0; virtual void onstatsReloaded() = 0; @@ -39,15 +38,11 @@ private: std::vector m_currentStats; bool m_statsChanged; std::string m_lastBackgroundBundle; - //BundleActiveService m_listener; inline static const std::vector INTERVAL_LENGTH = {BundleActiveIntervalStats::DAY_IN_MILLIS, BundleActiveIntervalStats::WEEK_IN_MILLIS, BundleActiveIntervalStats::MONTH_IN_MILLIS, BundleActiveIntervalStats::YEAR_IN_MILLIS}; void NotifyStatsChanged(); void ReportEvent(BundleActiveEvent event); - - }; - } } #endif \ No newline at end of file diff --git a/services/common/src/bundle_active_event.cpp b/services/common/src/bundle_active_event.cpp index e8b3e2e..4e74d3f 100644 --- a/services/common/src/bundle_active_event.cpp +++ b/services/common/src/bundle_active_event.cpp @@ -17,7 +17,6 @@ namespace OHOS { namespace BundleActive { - BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) { m_bundleName = orig.m_bundleName; m_abilityName = orig.m_abilityName; @@ -55,6 +54,5 @@ int BundleActiveEvent::GetEventId() { bool BundleActiveEvent::GetIsIdle() { return m_isIdle; } - } } diff --git a/services/common/src/bundle_active_event_list.cpp b/services/common/src/bundle_active_event_list.cpp index 9b58f81..d20e3d5 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -20,12 +20,15 @@ namespace BundleActive { BundleActiveEventList::BundleActiveEventList() { } + int BundleActiveEventList::Size() { return m_events.size(); } + void BundleActiveEventList::Clear() { m_events.clear(); } + void BundleActiveEventList::Insert(BundleActiveEvent event) { int size = m_events.size(); if (size == 0 || event.m_timeStamp >= m_events.back().m_timeStamp) { @@ -35,6 +38,7 @@ void BundleActiveEventList::Insert(BundleActiveEvent event) { int insertIdx = FirstIndexOnOrAfter(event.m_timeStamp); m_events.insert(m_events.begin() + insertIdx, event); } + int BundleActiveEventList::FirstIndexOnOrAfter(long timeStamp) { int size = m_events.size(); int result = size; @@ -52,12 +56,12 @@ int BundleActiveEventList::FirstIndexOnOrAfter(long timeStamp) { } return result; } + void BundleActiveEventList::Merge(const BundleActiveEventList& right) { int size = right.m_events.size(); for (int i = 0; i < size; i++) { Insert(right.m_events[i]); } } - } } \ 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 3e162ce..33eac44 100644 --- a/services/common/src/bundle_active_event_stats.cpp +++ b/services/common/src/bundle_active_event_stats.cpp @@ -17,7 +17,6 @@ namespace OHOS { namespace BundleActive { - BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig) { m_eventId = orig.m_eventId; m_beginTimeStamp = orig.m_beginTimeStamp; @@ -30,21 +29,27 @@ BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& ori int BundleActiveEventStats::GetEventId() { return m_eventId; } + int BundleActiveEventStats::GetFirstTimeStamp() { return m_beginTimeStamp; } + int BundleActiveEventStats::GetLastTimeStamp() { return m_endTimeStamp; } + int BundleActiveEventStats::GetLastEventTime() { return m_lastEventTime; } + int BundleActiveEventStats::GetTotalTime() { return m_totalTime; } + int BundleActiveEventStats::GetCount() { return m_count; } + void BundleActiveEventStats::add(const BundleActiveEventStats& right) { if (m_eventId != right.m_eventId) { return; @@ -58,6 +63,5 @@ void BundleActiveEventStats::add(const BundleActiveEventStats& right) { m_totalTime += right.m_totalTime; m_count += right.m_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 239226f..870a4c0 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -23,6 +23,7 @@ void BundleActiveEventTracker::CommitTime(long timeStamp) { m_curStartTime = 0; } } + void BundleActiveEventTracker::Update(long timeStamp) { if (m_curStartTime == 0) { m_count++; @@ -31,6 +32,7 @@ void BundleActiveEventTracker::Update(long timeStamp) { m_curStartTime = timeStamp; m_lastEventTime = timeStamp; } + void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, int eventId, long beginTime, long endTime) { if (m_count != 0 || m_duration != 0) { BundleActiveEventStats newEvent; @@ -43,6 +45,5 @@ void BundleActiveEventTracker::AddToEventStats(std::vector::iterator it; it = m_bundleStats.find(bundleName); diff --git a/services/common/src/bundle_active_usage_stats.cpp b/services/common/src/bundle_active_usage_stats.cpp index c39c8f4..17a142a 100644 --- a/services/common/src/bundle_active_usage_stats.cpp +++ b/services/common/src/bundle_active_usage_stats.cpp @@ -31,33 +31,43 @@ BundleActiveUsageStats::BundleActiveUsageStats (const BundleActiveUsageStats& or m_frontServices = orig.m_frontServices; m_lastEvent = orig.m_lastEvent; } + std::string BundleActiveUsageStats::GetBundleName() { return m_bundleName; } + long BundleActiveUsageStats::GetBeginTimeStamp() { return m_beginTimeStamp; } + long BundleActiveUsageStats::GetEntTimeStamp() { return m_endTimeStamp; } + long BundleActiveUsageStats::GetLastTimeUsed() { return m_lastTimeUsed; } + long BundleActiveUsageStats::GetTotalTimeInFront() { return m_totalTimeInFront; } + long BundleActiveUsageStats::GetLastTimeFrontServiceUsed() { return m_lastTimeFrontServiceUsed; } + long BundleActiveUsageStats::GetTotalTimeFrontServiceUsed() { return m_totalTimeFrontServiceUsed; } + int BundleActiveUsageStats::GetLaunchedCount() { return m_launchedCount; } + int BundleActiveUsageStats::GetBundleLaunchedCount() { return m_bundleLaunchedCount; } + bool BundleActiveUsageStats::HasFrontAbility() { for (auto ability : m_abilities) { if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) { @@ -66,24 +76,29 @@ bool BundleActiveUsageStats::HasFrontAbility() { } return false; } + bool BundleActiveUsageStats::AnyFrontServiceStarted() { return !m_frontServices.empty(); } + void BundleActiveUsageStats::IncrementTimeUsed(long timeStamp) { if (timeStamp > m_lastTimeUsed) { m_totalTimeInFront += timeStamp - m_lastTimeUsed; m_lastTimeUsed = timeStamp; } } + void BundleActiveUsageStats::IncrementServiceTimeUsed(long timeStamp) { if (timeStamp > m_lastTimeFrontServiceUsed) { m_totalTimeFrontServiceUsed += timeStamp - m_lastTimeFrontServiceUsed; m_lastTimeFrontServiceUsed = timeStamp; } } + void BundleActiveUsageStats::IncrementBundleLaunchedCount() { m_bundleLaunchedCount += 1; } + void BundleActiveUsageStats::UpdateActivity(long timeStamp, int eventId, int abilityId) { if (eventId != BundleActiveEvent::ABILITY_FOREGROUND && eventId != BundleActiveEvent::ABILITY_BACKGROUND && eventId != BundleActiveEvent::ABILITY_STOP) { @@ -119,6 +134,7 @@ void BundleActiveUsageStats::UpdateActivity(long timeStamp, int eventId, int abi break; } } + void BundleActiveUsageStats::UpdateFrontService(std::string frontServiceName, long timeStamp, int eventId) { if (eventId != BundleActiveEvent::FRONT_SERVICE_STARTTED && eventId != BundleActiveEvent::FRONT_SERVICE_STOPPED) { return; @@ -150,6 +166,7 @@ void BundleActiveUsageStats::UpdateFrontService(std::string frontServiceName, lo break; } } + void BundleActiveUsageStats::Update(std::string frontServiceName, long timeStamp, int eventId, int abilityId) { switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: @@ -182,6 +199,5 @@ void BundleActiveUsageStats::Update(std::string frontServiceName, long timeStamp m_launchedCount += 1; } } - } } \ No newline at end of file diff --git a/services/common/src/bundle_active_user_service.cpp b/services/common/src/bundle_active_user_service.cpp index f010d27..4f9d255 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -17,12 +17,12 @@ namespace OHOS { namespace BundleActive { - BundleActiveUserService::BundleActiveUserService(int userId){//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/) { m_currentStats.reserve(BundleActiveIntervalStats::INTERVAL_COUNT); //m_listener = listener; m_userId = userId; } + void BundleActiveUserService::NotifyStatsChanged() { if (!m_statsChanged) { m_statsChanged = true; @@ -65,6 +65,5 @@ void BundleActiveUserService::ReportEvent(BundleActiveEvent event) { } } } - } } \ No newline at end of file diff --git a/services/include/bundle_active_iservice.h b/services/include/bundle_active_iservice.h index bb04206..910166e 100644 --- a/services/include/bundle_active_iservice.h +++ b/services/include/bundle_active_iservice.h @@ -50,7 +50,6 @@ public: public: DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IBundleActiveService"); }; - } } diff --git a/services/include/bundle_active_service.h b/services/include/bundle_active_service.h index b52bbd0..343eada 100644 --- a/services/include/bundle_active_service.h +++ b/services/include/bundle_active_service.h @@ -29,10 +29,6 @@ public: 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; - //void onStatsUpdated() override; - //void onstatsReloaded() override; - //oid onNewUpdate(int userId) override; -public: BundleActiveService(int32_t systemAbilityId, int runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {} ~BundleActiveService() {} @@ -40,9 +36,7 @@ public: protected: void OnStart() override; void OnStop() override; - }; - } } #endif \ No newline at end of file diff --git a/services/src/bundle_active_service.cpp b/services/src/bundle_active_service.cpp index 3fdec33..84c9d3d 100644 --- a/services/src/bundle_active_service.cpp +++ b/services/src/bundle_active_service.cpp @@ -28,13 +28,12 @@ void BundleActiveService::OnStart() } BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1906] SUCCESS."); } -//void BundleActiveService::onStatsUpdated() {} -//void BundleActiveService::onstatsReloaded() {} -//void BundleActiveService::onNewUpdate(int userId) {} + 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) { BUNDLE_ACTIVE_LOGI("Report event called"); return 111; @@ -49,6 +48,5 @@ int BundleActiveService::Query(std::string& bundleName, std::string& abilityName BUNDLE_ACTIVE_LOGI("Query called"); return 222; } - } } \ No newline at end of file diff --git a/services/src/bundle_active_stub.cpp b/services/src/bundle_active_stub.cpp index d5910d4..f1caeec 100644 --- a/services/src/bundle_active_stub.cpp +++ b/services/src/bundle_active_stub.cpp @@ -18,7 +18,6 @@ namespace OHOS { namespace BundleActive { - int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) { switch(code) { case REPORT_EVENT: { @@ -51,6 +50,5 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } - } } \ No newline at end of file -- Gitee From a021f4a574f3028b1c38bc60ed12f4366ff859e2 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 11 Jan 2022 10:41:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?OTA=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- OAT.xml | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 OAT.xml diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000..b11daf5 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- Gitee From f83463065a661fc8445c6ca9520e78c3955b50e7 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 11 Jan 2022 10:55:35 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- BUILD.gn | 17 +- services/common/include/bundle_active_event.h | 22 +-- .../common/include/bundle_active_event_list.h | 4 +- .../include/bundle_active_event_stats.h | 12 +- .../include/bundle_active_event_tracker.h | 14 +- ..._stats.h => bundle_active_package_stats.h} | 59 +++---- ...l_stats.h => bundle_active_period_stats.h} | 68 ++++---- .../include/bundle_active_user_service.h | 22 ++- services/common/src/bundle_active_event.cpp | 32 ++-- .../common/src/bundle_active_event_list.cpp | 24 +-- .../common/src/bundle_active_event_stats.cpp | 38 ++--- .../src/bundle_active_event_tracker.cpp | 34 ++-- .../src/bundle_active_interval_stats.cpp | 103 ------------- ...ts.cpp => bundle_active_package_stats.cpp} | 145 +++++++++--------- .../common/src/bundle_active_period_stats.cpp | 104 +++++++++++++ .../common/src/bundle_active_user_service.cpp | 41 +++-- .../common/src/bundle_active_user_service.h | 45 ++++++ services/include/bundle_active_stub.h | 1 - 18 files changed, 405 insertions(+), 380 deletions(-) rename services/common/include/{bundle_active_usage_stats.h => bundle_active_package_stats.h} (36%) rename services/common/include/{bundle_active_interval_stats.h => bundle_active_period_stats.h} (37%) delete mode 100644 services/common/src/bundle_active_interval_stats.cpp rename services/common/src/{bundle_active_usage_stats.cpp => bundle_active_package_stats.cpp} (43%) create mode 100644 services/common/src/bundle_active_period_stats.cpp create mode 100644 services/common/src/bundle_active_user_service.h diff --git a/BUILD.gn b/BUILD.gn index f6e950f..fa3d6f6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,16 +1,3 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - import("//build/ohos.gni") import("//build/ohos/sa_profile/sa_profile.gni") @@ -89,8 +76,8 @@ ohos_shared_library("bundleactiveservice") { "services/common/src/bundle_active_event_list.cpp", "services/common/src/bundle_active_event_stats.cpp", "services/common/src/bundle_active_event_tracker.cpp", - "services/common/src/bundle_active_usage_stats.cpp", - "services/common/src/bundle_active_interval_stats.cpp", + "services/common/src/bundle_active_package_stats.cpp", + "services/common/src/bundle_active_period_stats.cpp", "services/common/src/bundle_active_user_service.cpp" ] include_dirs = [ diff --git a/services/common/include/bundle_active_event.h b/services/common/include/bundle_active_event.h index 551dcb8..4f5f2d9 100644 --- a/services/common/include/bundle_active_event.h +++ b/services/common/include/bundle_active_event.h @@ -26,8 +26,8 @@ public: 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 FRONT_SERVICE_STARTTED = 5; - static const int FRONT_SERVICE_STOPPED = 6; + 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 @@ -40,20 +40,20 @@ public: static const int KEYGUARD_SHOWN = 15; static const int KEYGUARD_HIDDEN = 16; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; - std::string m_bundleName; - std::string m_serviceName; - std::string m_abilityName; - int m_abilityId; - long m_timeStamp; - int m_eventId; - bool m_isIdle; + std::string bundleName_; + std::string longTimeTaskName_; + std::string abilityName_; + int abilityId_; + int64_t timeStamp_; + int eventId_; + bool isIdle_; BundleActiveEvent() {}; BundleActiveEvent(const BundleActiveEvent& orig); - BundleActiveEvent(int eventId, long timeStamp); + BundleActiveEvent(const int eventId, const int64_t timeStamp); std::string GetBundleName(); std::string GetAbilityName(); int GetAbilityId(); - long GetTimeStamp(); + int64_t GetTimeStamp(); int GetEventId(); bool GetIsIdle(); }; diff --git a/services/common/include/bundle_active_event_list.h b/services/common/include/bundle_active_event_list.h index 85242e2..1ac946e 100644 --- a/services/common/include/bundle_active_event_list.h +++ b/services/common/include/bundle_active_event_list.h @@ -27,10 +27,10 @@ public: int Size(); void Clear(); void Insert(BundleActiveEvent event); - int FirstIndexOnOrAfter(long timeStamp); + int FindBestIndex(int64_t timeStamp); void Merge(const BundleActiveEventList& right); private: - std::vector m_events; + std::vector events_; }; } } diff --git a/services/common/include/bundle_active_event_stats.h b/services/common/include/bundle_active_event_stats.h index 366e310..e446985 100644 --- a/services/common/include/bundle_active_event_stats.h +++ b/services/common/include/bundle_active_event_stats.h @@ -22,12 +22,12 @@ namespace OHOS { namespace BundleActive { class BundleActiveEventStats { public: - int m_eventId; - long m_beginTimeStamp; - long m_endTimeStamp; - long m_lastEventTime; - long m_totalTime; - int m_count; + int eventId_; + int64_t beginTimeStamp_; + int64_t endTimeStamp_; + int64_t lastEventTime_; + int64_t totalTime_; + int count_; BundleActiveEventStats() {}; BundleActiveEventStats(const BundleActiveEventStats& orig); int GetEventId(); diff --git a/services/common/include/bundle_active_event_tracker.h b/services/common/include/bundle_active_event_tracker.h index be13bf5..19af858 100644 --- a/services/common/include/bundle_active_event_tracker.h +++ b/services/common/include/bundle_active_event_tracker.h @@ -23,13 +23,13 @@ namespace OHOS { namespace BundleActive { class BundleActiveEventTracker { public: - long m_curStartTime; - long m_lastEventTime; - long m_duration; - long m_count; - void CommitTime(long timeStamp); - void Update(long timeStamp); - void AddToEventStats(std::vector& eventStatsList, int eventId, long beginTime, long endTime); + int64_t curStartTime_; + int64_t lastEventTime_; + int64_t duration_; + 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); BundleActiveEventTracker() {}; }; } diff --git a/services/common/include/bundle_active_usage_stats.h b/services/common/include/bundle_active_package_stats.h similarity index 36% rename from services/common/include/bundle_active_usage_stats.h rename to services/common/include/bundle_active_package_stats.h index 10eb568..9d0c9f3 100644 --- a/services/common/include/bundle_active_usage_stats.h +++ b/services/common/include/bundle_active_package_stats.h @@ -13,50 +13,51 @@ * limitations under the License. */ -#ifndef BUNDLE_ACTIVE_USAGE_STATS_H -#define BUNDLE_ACTIVE_USAGE_STATS_H +#ifndef bundle_active_package_stats_H +#define bundle_active_package_stats_H #include "bundle_active_iservice.h" #include "bundle_active_event.h" namespace OHOS { namespace BundleActive { -//bundles statistics, including activities and frontservices. -class BundleActiveUsageStats { +//bundles statistics, including Abilityies and frontservices. +class BundleActivePackageStats { public: - std::string m_bundleName; - long m_beginTimeStamp; //start time of counting - long m_endTimeStamp; //stop time of counting - long m_lastTimeUsed; //the timestamp of last launch - long m_totalTimeInFront; // the total time of using the bundle - long m_lastTimeFrontServiceUsed; - long m_totalTimeFrontServiceUsed; - int m_launchedCount; - int m_bundleLaunchedCount; - int m_lastEvent; - std::map m_abilities; // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. - std::map m_frontServices; // restore the frontservices' names using by bundle. - BundleActiveUsageStats() {}; - BundleActiveUsageStats(const BundleActiveUsageStats& orig); + 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 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. + BundleActivePackageStats() {}; + BundleActivePackageStats(const BundleActivePackageStats& orig); std::string GetBundleName(); - long GetBeginTimeStamp(); - long GetEntTimeStamp(); - long GetLastTimeUsed(); - long GetTotalTimeInFront(); - long GetLastTimeFrontServiceUsed(); - long GetTotalTimeFrontServiceUsed(); + int64_t GetBeginTimeStamp(); + int64_t GetEntTimeStamp(); + int64_t GetLastTimeUsed(); + int64_t GetTotalTimeInFront(); + int64_t GetLastTimeFrontServiceUsed(); + int64_t GetTotalTimeFrontServiceUsed(); int GetLaunchedCount(); int GetBundleLaunchedCount(); - void Update(std::string frontServiceName, long timeStamp, int eventId, int abilityId); - void IncrementTimeUsed(long timeStamp); - void IncrementServiceTimeUsed(long timeStamp); + void Update(std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const int abilityId); + void IncrementTimeUsed(const int64_t timeStamp); + void IncrementLongTimeTaskTimeUsed(const int64_t timeStamp); void IncrementBundleLaunchedCount(); private: bool HasFrontAbility(); bool AnyFrontServiceStarted(); - void UpdateActivity(long timeStamp, int eventId, int abilityId); - void UpdateFrontService(std::string frontServiceName, long timeStamp, int eventId); + void UpdateAbility(const int64_t timeStamp, const int eventId, const int abilityId); + void UpdateLongTimeTask(std::string longTimeTaskName, + const int64_t timeStamp, const int eventId); }; diff --git a/services/common/include/bundle_active_interval_stats.h b/services/common/include/bundle_active_period_stats.h similarity index 37% rename from services/common/include/bundle_active_interval_stats.h rename to services/common/include/bundle_active_period_stats.h index 1caa687..29952ad 100644 --- a/services/common/include/bundle_active_interval_stats.h +++ b/services/common/include/bundle_active_period_stats.h @@ -13,54 +13,50 @@ * limitations under the License. */ -#ifndef BUNDLE_ACTIVE_INTERVAL_STATS_H -#define BUNDLE_ACTIVE_INTERVAL_STATS_H +#ifndef bundle_active_period_stats_H +#define bundle_active_period_stats_H #include "bundle_active_iservice.h" #include "bundle_active_event.h" -#include "bundle_active_usage_stats.h" +#include "bundle_active_package_stats.h" #include "bundle_active_event_list.h" #include "bundle_active_event_tracker.h" namespace OHOS { namespace BundleActive { -class BundleActiveIntervalStats { +class BundleActivePeriodStats { public: - static const int CURRENT_MAJOR_VERSION = 1; - static const int CURRENT_MINOR_VERSION = 1; - static const int INTERVAL_DAILY = 0; - static const int INTERVAL_WEEKLY = 1; - static const int INTERVAL_MONTHLY = 2; - static const int INTERVAL_YEARLY = 3; - static const int INTERVAL_BEST = 4; - static const int INTERVAL_COUNT = 4; - static const long long DAY_IN_MILLIS = (long long)24 * 60 * 60 * 1000; - static const long long WEEK_IN_MILLIS = (long long)7 * 24 * 60 * 60 * 1000; - static const long long MONTH_IN_MILLIS = (long long)30 * 24 * 60 * 60 * 1000; - static const long long YEAR_IN_MILLIS = (long long)365 * 24 * 60 * 60 * 1000; - int majorVersion = CURRENT_MAJOR_VERSION; - int minorVersion = CURRENT_MINOR_VERSION; - long m_beginTime; - long m_endTime; - long m_lastTimeSaved; - std::map m_bundleStats; - BundleActiveEventList m_events; - std::set m_packetNamesCache; - BundleActiveEventTracker m_interactiveTracker; - BundleActiveEventTracker m_noninteractiveTracker; - BundleActiveEventTracker m_keyguardShownTracker; - BundleActiveEventTracker m_keyguardHiddenTracker; - BundleActiveUsageStats& GetOrCreateUsageStats(std::string bundleName); - BundleActiveEvent BuildEvent(std::string bundleName, std::string serviceName); - void Update(std::string bundleName, std::string serviceName, long timeStamp, int eventId, int abilityId); + static const int PERIOD_DAILY = 0; + static const int PERIOD_WEEKLY = 1; + static const int PERIOD_MONTHLY = 2; + static const int PERIOD_YEARLY = 3; + static const int PERIOD_BEST = 4; + static const int PERIOD_COUNT = 4; + static const int64_t DAY_IN_MILLIS = (int64_t)24 * 60 * 60 * 1000; + static const int64_t WEEK_IN_MILLIS = (int64_t)7 * 24 * 60 * 60 * 1000; + static const int64_t MONTH_IN_MILLIS = (int64_t)30 * 24 * 60 * 60 * 1000; + static const int64_t YEAR_IN_MILLIS = (int64_t)365 * 24 * 60 * 60 * 1000; + int64_t beginTime_; + int64_t endTime_; + int64_t lastTimeSaved_; + std::map bundleStats_; + BundleActiveEventList events_; + std::set packetNamesCache_; + BundleActiveEventTracker interactiveTracker_; + BundleActiveEventTracker noninteractiveTracker_; + BundleActiveEventTracker keyguardShownTracker_; + 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 AddEvent(BundleActiveEvent event); - void UpdateScreenInteractive(long timeStamp); - void UpdateScreenNonInteractive(long timeStamp); - void UpdateKeyguardShown(long timeStamp); - void UpdateKeyguardHidden(long timeStamp); + void UpdateScreenInteractive(const int64_t timeStamp); + void UpdateScreenNonInteractive(const int64_t timeStamp); + void UpdateKeyguardShown(const int64_t timeStamp); + void UpdateKeyguardHidden(const int64_t timeStamp); private: - void CommitTime(long timeStamp); + 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 5e8abec..e26f22a 100644 --- a/services/common/include/bundle_active_user_service.h +++ b/services/common/include/bundle_active_user_service.h @@ -18,8 +18,8 @@ #include "bundle_active_iservice.h" #include "bundle_active_event.h" -#include "bundle_active_usage_stats.h" -#include "bundle_active_interval_stats.h" +#include "bundle_active_package_stats.h" +#include "bundle_active_period_stats.h" #include "bundle_active_event_stats.h" namespace OHOS { @@ -28,18 +28,14 @@ namespace BundleActive { class BundleActiveUserService { public: BundleActiveUserService(int userId);//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/); - virtual void onStatsUpdated() = 0; - virtual void onstatsReloaded() = 0; - virtual void onNewUpdate(int userId) = 0; private: - //BundleActiveUsageDatabase m_dataBase; - int m_incrementBundleLaunch; - int m_userId; - std::vector m_currentStats; - bool m_statsChanged; - std::string m_lastBackgroundBundle; - inline static const std::vector INTERVAL_LENGTH = {BundleActiveIntervalStats::DAY_IN_MILLIS, BundleActiveIntervalStats::WEEK_IN_MILLIS, - BundleActiveIntervalStats::MONTH_IN_MILLIS, BundleActiveIntervalStats::YEAR_IN_MILLIS}; + 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}; void NotifyStatsChanged(); void ReportEvent(BundleActiveEvent event); }; diff --git a/services/common/src/bundle_active_event.cpp b/services/common/src/bundle_active_event.cpp index 4e74d3f..5925445 100644 --- a/services/common/src/bundle_active_event.cpp +++ b/services/common/src/bundle_active_event.cpp @@ -18,41 +18,41 @@ namespace OHOS { namespace BundleActive { BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) { - m_bundleName = orig.m_bundleName; - m_abilityName = orig.m_abilityName; - m_abilityId = orig.m_abilityId; - m_timeStamp = orig.m_timeStamp; - m_eventId = orig.m_eventId; - m_isIdle = orig.m_isIdle; + bundleName_ = orig.bundleName_; + abilityName_ = orig.abilityName_; + abilityId_ = orig.abilityId_; + timeStamp_ = orig.timeStamp_; + eventId_ = orig.eventId_; + isIdle_ = orig.isIdle_; } -BundleActiveEvent::BundleActiveEvent(int eventId, long timeStamp) { - m_eventId = eventId; - m_timeStamp = timeStamp; +BundleActiveEvent::BundleActiveEvent(const int eventId, const int64_t timeStamp) { + eventId_ = eventId; + timeStamp_ = timeStamp; } std::string BundleActiveEvent::GetBundleName() { - return m_bundleName; + return bundleName_; } std::string BundleActiveEvent::GetAbilityName() { - return m_abilityName; + return abilityName_; } int BundleActiveEvent::GetAbilityId() { - return m_abilityId; + return abilityId_; } -long BundleActiveEvent::GetTimeStamp() { - return m_timeStamp; +int64_t BundleActiveEvent::GetTimeStamp() { + return timeStamp_; } int BundleActiveEvent::GetEventId() { - return m_eventId; + return eventId_; } bool BundleActiveEvent::GetIsIdle() { - return m_isIdle; + return isIdle_; } } } diff --git a/services/common/src/bundle_active_event_list.cpp b/services/common/src/bundle_active_event_list.cpp index d20e3d5..1604dcc 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -22,31 +22,31 @@ BundleActiveEventList::BundleActiveEventList() { } int BundleActiveEventList::Size() { - return m_events.size(); + return events_.size(); } void BundleActiveEventList::Clear() { - m_events.clear(); + events_.clear(); } void BundleActiveEventList::Insert(BundleActiveEvent event) { - int size = m_events.size(); - if (size == 0 || event.m_timeStamp >= m_events.back().m_timeStamp) { - m_events.push_back(event); + int size = events_.size(); + if (size == 0 || event.timeStamp_ >= events_.back().timeStamp_) { + events_.push_back(event); return; } - int insertIdx = FirstIndexOnOrAfter(event.m_timeStamp); - m_events.insert(m_events.begin() + insertIdx, event); + int insertIdx = FindBestIndex(event.timeStamp_); + events_.insert(events_.begin() + insertIdx, event); } -int BundleActiveEventList::FirstIndexOnOrAfter(long timeStamp) { - int size = m_events.size(); +int BundleActiveEventList::FindBestIndex(int64_t timeStamp) { + int size = events_.size(); int result = size; int lo = 0; int hi = size - 1; while (lo <= hi) { int mid = (hi - lo) / 2 + lo; - long midTimeStamp = m_events[mid].m_timeStamp; + int64_t midTimeStamp = events_[mid].timeStamp_; if (midTimeStamp >= timeStamp) { hi = mid - 1; result = mid; @@ -58,9 +58,9 @@ int BundleActiveEventList::FirstIndexOnOrAfter(long timeStamp) { } void BundleActiveEventList::Merge(const BundleActiveEventList& right) { - int size = right.m_events.size(); + int size = right.events_.size(); for (int i = 0; i < size; i++) { - Insert(right.m_events[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 33eac44..f484b8d 100644 --- a/services/common/src/bundle_active_event_stats.cpp +++ b/services/common/src/bundle_active_event_stats.cpp @@ -18,50 +18,50 @@ namespace OHOS { namespace BundleActive { BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig) { - m_eventId = orig.m_eventId; - m_beginTimeStamp = orig.m_beginTimeStamp; - m_endTimeStamp = orig.m_endTimeStamp; - m_lastEventTime = orig.m_lastEventTime; - m_totalTime = orig.m_totalTime; - m_count = orig.m_count; + eventId_ = orig.eventId_; + beginTimeStamp_ = orig.beginTimeStamp_; + endTimeStamp_ = orig.endTimeStamp_; + lastEventTime_ = orig.lastEventTime_; + totalTime_ = orig.totalTime_; + count_ = orig.count_; } int BundleActiveEventStats::GetEventId() { - return m_eventId; + return eventId_; } int BundleActiveEventStats::GetFirstTimeStamp() { - return m_beginTimeStamp; + return beginTimeStamp_; } int BundleActiveEventStats::GetLastTimeStamp() { - return m_endTimeStamp; + return endTimeStamp_; } int BundleActiveEventStats::GetLastEventTime() { - return m_lastEventTime; + return lastEventTime_; } int BundleActiveEventStats::GetTotalTime() { - return m_totalTime; + return totalTime_; } int BundleActiveEventStats::GetCount() { - return m_count; + return count_; } void BundleActiveEventStats::add(const BundleActiveEventStats& right) { - if (m_eventId != right.m_eventId) { + if (eventId_ != right.eventId_) { return; } - if (right.m_beginTimeStamp > m_beginTimeStamp) { - m_lastEventTime = std::max(m_lastEventTime, right.m_lastEventTime); + if (right.beginTimeStamp_ > beginTimeStamp_) { + lastEventTime_ = std::max(lastEventTime_, right.lastEventTime_); } - m_beginTimeStamp = std::min(m_beginTimeStamp, right.m_beginTimeStamp); - m_endTimeStamp = std::max(m_endTimeStamp, right.m_endTimeStamp); - m_totalTime += right.m_totalTime; - m_count += right.m_count; + beginTimeStamp_ = std::min(beginTimeStamp_, right.beginTimeStamp_); + endTimeStamp_ = std::max(endTimeStamp_, right.endTimeStamp_); + totalTime_ += right.totalTime_; + 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 870a4c0..b0afe2e 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -17,31 +17,31 @@ namespace OHOS { namespace BundleActive { -void BundleActiveEventTracker::CommitTime(long timeStamp) { - if (m_curStartTime != 0) { - m_duration += timeStamp - m_curStartTime; - m_curStartTime = 0; +void BundleActiveEventTracker::CommitTime(const int64_t timeStamp) { + if (curStartTime_ != 0) { + duration_ += timeStamp - curStartTime_; + curStartTime_ = 0; } } -void BundleActiveEventTracker::Update(long timeStamp) { - if (m_curStartTime == 0) { - m_count++; +void BundleActiveEventTracker::Update(int64_t timeStamp) { + if (curStartTime_ == 0) { + count_++; } CommitTime(timeStamp); - m_curStartTime = timeStamp; - m_lastEventTime = timeStamp; + curStartTime_ = timeStamp; + lastEventTime_ = timeStamp; } -void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, int eventId, long beginTime, long endTime) { - if (m_count != 0 || m_duration != 0) { +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.m_eventId = eventId; - newEvent.m_count = m_count; - newEvent.m_totalTime = m_duration; - newEvent.m_lastEventTime = m_lastEventTime; - newEvent.m_beginTimeStamp = beginTime; - newEvent.m_endTimeStamp = endTime; + newEvent.eventId_ = eventId; + newEvent.count_ = count_; + newEvent.totalTime_ = duration_; + newEvent.lastEventTime_ = lastEventTime_; + newEvent.beginTimeStamp_ = beginTime; + newEvent.endTimeStamp_ = endTime; eventStatsList.emplace_back(newEvent); } } diff --git a/services/common/src/bundle_active_interval_stats.cpp b/services/common/src/bundle_active_interval_stats.cpp deleted file mode 100644 index f91ce88..0000000 --- a/services/common/src/bundle_active_interval_stats.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bundle_active_interval_stats.h" -#include "bundle_active_event.h" - -namespace OHOS { -namespace BundleActive { -BundleActiveUsageStats& BundleActiveIntervalStats::GetOrCreateUsageStats(std::string bundleName) { - std::map::iterator it; - it = m_bundleStats.find(bundleName); - if (it == m_bundleStats.end()) { - BundleActiveUsageStats newStats; - newStats.m_beginTimeStamp = m_beginTime; - newStats.m_endTimeStamp = m_endTime; - newStats.m_bundleName = GetCachedString(bundleName); - m_bundleStats[newStats.m_bundleName] = newStats; - } - return m_bundleStats[bundleName]; -} -BundleActiveEvent BundleActiveIntervalStats::BuildEvent(std::string bundleName, std::string serviceName) { - BundleActiveEvent newEvent; - newEvent.m_bundleName = bundleName; - if (!serviceName.empty()) { - newEvent.m_serviceName = serviceName; - } - return newEvent; -} -void BundleActiveIntervalStats::Update(std::string bundleName, std::string serviceName, long timeStamp, int eventId, int abilityId) { - if (eventId == BundleActiveEvent::DEVICE_SHUTDOWN || eventId == BundleActiveEvent::FLUSH_TO_DISK) { - for (auto usageStatsPair : m_bundleStats) { - usageStatsPair.second.Update("", timeStamp, eventId, abilityId); - } - } else { - BundleActiveUsageStats& usageStats = GetOrCreateUsageStats(bundleName); - usageStats.Update("", timeStamp, eventId, abilityId); - } - if (timeStamp > m_endTime) { - m_endTime = timeStamp; - } -} -void BundleActiveIntervalStats::AddEvent(BundleActiveEvent event) { - event.m_bundleName = GetCachedString(event.m_bundleName); - if (!event.m_serviceName.empty()) { - event.m_serviceName = GetCachedString(event.m_serviceName); - } - m_events.Insert(event); - if (event.m_timeStamp > m_endTime) { - m_endTime = event.m_timeStamp; - } -} -void BundleActiveIntervalStats::CommitTime(long timeStamp) { - m_interactiveTracker.CommitTime(timeStamp); - m_noninteractiveTracker.CommitTime(timeStamp); - m_keyguardShownTracker.CommitTime(timeStamp); - m_keyguardHiddenTracker.CommitTime(timeStamp); -} -void BundleActiveIntervalStats::UpdateScreenInteractive(long timeStamp) { - m_interactiveTracker.Update(timeStamp); - m_noninteractiveTracker.CommitTime(timeStamp); -} -void BundleActiveIntervalStats::UpdateScreenNonInteractive(long timeStamp) { - m_noninteractiveTracker.Update(timeStamp); - m_interactiveTracker.CommitTime(timeStamp); -} -void BundleActiveIntervalStats::UpdateKeyguardShown(long timeStamp) { - m_keyguardShownTracker.Update(timeStamp); - m_keyguardHiddenTracker.CommitTime(timeStamp); -} -void BundleActiveIntervalStats::UpdateKeyguardHidden(long timeStamp) { - m_keyguardHiddenTracker.Update(timeStamp); - m_keyguardShownTracker.CommitTime(timeStamp); -} -void BundleActiveIntervalStats::AddEventStatsTo(std::vector& eventStatsList) { - m_interactiveTracker.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_INTERACTIVE, m_beginTime, m_endTime); - m_noninteractiveTracker.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_NON_INTERACTIVE, m_beginTime, m_endTime); - m_keyguardShownTracker.AddToEventStats(eventStatsList, BundleActiveEvent::KEYGUARD_SHOWN, m_beginTime, m_endTime); - m_keyguardHiddenTracker.AddToEventStats(eventStatsList, BundleActiveEvent::KEYGUARD_HIDDEN, m_beginTime, m_endTime); -} -std::string BundleActiveIntervalStats::GetCachedString(std::string str) { - std::set::iterator it; - it = m_packetNamesCache.find(str); - if (it == m_packetNamesCache.end()) { - m_packetNamesCache.insert(str); - return str; - } - return *it; -} - -} -} \ No newline at end of file diff --git a/services/common/src/bundle_active_usage_stats.cpp b/services/common/src/bundle_active_package_stats.cpp similarity index 43% rename from services/common/src/bundle_active_usage_stats.cpp rename to services/common/src/bundle_active_package_stats.cpp index 17a142a..1b2005a 100644 --- a/services/common/src/bundle_active_usage_stats.cpp +++ b/services/common/src/bundle_active_package_stats.cpp @@ -13,63 +13,63 @@ * limitations under the License. */ -#include "bundle_active_usage_stats.h" +#include "bundle_active_package_stats.h" namespace OHOS { namespace BundleActive { -BundleActiveUsageStats::BundleActiveUsageStats (const BundleActiveUsageStats& orig) { - m_bundleName = orig.m_bundleName; - m_beginTimeStamp = orig.m_beginTimeStamp; - m_endTimeStamp = orig.m_endTimeStamp; - m_lastTimeUsed = orig.m_lastTimeUsed; - m_lastTimeFrontServiceUsed = orig.m_lastTimeFrontServiceUsed; - m_totalTimeFrontServiceUsed = orig.m_totalTimeFrontServiceUsed; - m_totalTimeInFront = orig.m_totalTimeInFront; - m_launchedCount = orig.m_launchedCount; - m_bundleLaunchedCount = orig.m_bundleLaunchedCount; - m_abilities = orig.m_abilities; - m_frontServices = orig.m_frontServices; - m_lastEvent = orig.m_lastEvent; +BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageStats& orig) { + bundleName_ = orig.bundleName_; + beginTimeStamp_ = orig.beginTimeStamp_; + endTimeStamp_ = orig.endTimeStamp_; + lastTimeUsed_ = orig.lastTimeUsed_; + lastTimeLongTimeTaskUsed_ = orig.lastTimeLongTimeTaskUsed_; + totalTimeLongTimeTaskUsed_ = orig.totalTimeLongTimeTaskUsed_; + totalTimeInFront_ = orig.totalTimeInFront_; + launchedCount_ = orig.launchedCount_; + bundleLaunchedCount_ = orig.bundleLaunchedCount_; + abilities_ = orig.abilities_; + frontServices_ = orig.frontServices_; + lastEvent_ = orig.lastEvent_; } -std::string BundleActiveUsageStats::GetBundleName() { - return m_bundleName; +std::string BundleActivePackageStats::GetBundleName() { + return bundleName_; } -long BundleActiveUsageStats::GetBeginTimeStamp() { - return m_beginTimeStamp; +int64_t BundleActivePackageStats::GetBeginTimeStamp() { + return beginTimeStamp_; } -long BundleActiveUsageStats::GetEntTimeStamp() { - return m_endTimeStamp; +int64_t BundleActivePackageStats::GetEntTimeStamp() { + return endTimeStamp_; } -long BundleActiveUsageStats::GetLastTimeUsed() { - return m_lastTimeUsed; +int64_t BundleActivePackageStats::GetLastTimeUsed() { + return lastTimeUsed_; } -long BundleActiveUsageStats::GetTotalTimeInFront() { - return m_totalTimeInFront; +int64_t BundleActivePackageStats::GetTotalTimeInFront() { + return totalTimeInFront_; } -long BundleActiveUsageStats::GetLastTimeFrontServiceUsed() { - return m_lastTimeFrontServiceUsed; +int64_t BundleActivePackageStats::GetLastTimeFrontServiceUsed() { + return lastTimeLongTimeTaskUsed_; } -long BundleActiveUsageStats::GetTotalTimeFrontServiceUsed() { - return m_totalTimeFrontServiceUsed; +int64_t BundleActivePackageStats::GetTotalTimeFrontServiceUsed() { + return totalTimeLongTimeTaskUsed_; } -int BundleActiveUsageStats::GetLaunchedCount() { - return m_launchedCount; +int BundleActivePackageStats::GetLaunchedCount() { + return launchedCount_; } -int BundleActiveUsageStats::GetBundleLaunchedCount() { - return m_bundleLaunchedCount; +int BundleActivePackageStats::GetBundleLaunchedCount() { + return bundleLaunchedCount_; } -bool BundleActiveUsageStats::HasFrontAbility() { - for (auto ability : m_abilities) { +bool BundleActivePackageStats::HasFrontAbility() { + for (auto ability : abilities_) { if (ability.second == BundleActiveEvent::ABILITY_FOREGROUND) { return true; } @@ -77,36 +77,36 @@ bool BundleActiveUsageStats::HasFrontAbility() { return false; } -bool BundleActiveUsageStats::AnyFrontServiceStarted() { - return !m_frontServices.empty(); +bool BundleActivePackageStats::AnyFrontServiceStarted() { + return !frontServices_.empty(); } -void BundleActiveUsageStats::IncrementTimeUsed(long timeStamp) { - if (timeStamp > m_lastTimeUsed) { - m_totalTimeInFront += timeStamp - m_lastTimeUsed; - m_lastTimeUsed = timeStamp; +void BundleActivePackageStats::IncrementTimeUsed(const int64_t timeStamp) { + if (timeStamp > lastTimeUsed_) { + totalTimeInFront_ += timeStamp - lastTimeUsed_; + lastTimeUsed_ = timeStamp; } } -void BundleActiveUsageStats::IncrementServiceTimeUsed(long timeStamp) { - if (timeStamp > m_lastTimeFrontServiceUsed) { - m_totalTimeFrontServiceUsed += timeStamp - m_lastTimeFrontServiceUsed; - m_lastTimeFrontServiceUsed = timeStamp; +void BundleActivePackageStats::IncrementLongTimeTaskTimeUsed(const int64_t timeStamp) { + if (timeStamp > lastTimeLongTimeTaskUsed_) { + totalTimeLongTimeTaskUsed_ += timeStamp - lastTimeLongTimeTaskUsed_; + lastTimeLongTimeTaskUsed_ = timeStamp; } } -void BundleActiveUsageStats::IncrementBundleLaunchedCount() { - m_bundleLaunchedCount += 1; +void BundleActivePackageStats::IncrementBundleLaunchedCount() { + bundleLaunchedCount_ += 1; } -void BundleActiveUsageStats::UpdateActivity(long timeStamp, int eventId, 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; } std::map::iterator it; - it = m_abilities.find(abilityId); - if (it != m_abilities.end()) { + 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) { @@ -121,66 +121,67 @@ void BundleActiveUsageStats::UpdateActivity(long timeStamp, int eventId, int abi switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: if (!HasFrontAbility()) { - m_lastTimeUsed = timeStamp; + lastTimeUsed_ = timeStamp; } - m_abilities[abilityId] = eventId; + abilities_[abilityId] = eventId; break; case BundleActiveEvent::ABILITY_BACKGROUND: - m_abilities[abilityId] = eventId; + abilities_[abilityId] = eventId; break; case BundleActiveEvent::ABILITY_STOP: - m_abilities.erase(abilityId); + abilities_.erase(abilityId); default: break; } } -void BundleActiveUsageStats::UpdateFrontService(std::string frontServiceName, long timeStamp, int eventId) { - if (eventId != BundleActiveEvent::FRONT_SERVICE_STARTTED && eventId != BundleActiveEvent::FRONT_SERVICE_STOPPED) { +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 = m_frontServices.find(frontServiceName); - if (it != m_frontServices.end()) { + it = frontServices_.find(longTimeTaskName); + if (it != frontServices_.end()) { int lastEventId = it->second; switch (lastEventId) { - case BundleActiveEvent::FRONT_SERVICE_STARTTED: - IncrementServiceTimeUsed(timeStamp); + case BundleActiveEvent::LONG_TIME_TASK_STARTTED: + IncrementLongTimeTaskTimeUsed(timeStamp); default: break; } } switch (eventId) { - case BundleActiveEvent::FRONT_SERVICE_STARTTED: + case BundleActiveEvent::LONG_TIME_TASK_STARTTED: if(!AnyFrontServiceStarted()) { - m_lastTimeFrontServiceUsed = timeStamp; + lastTimeLongTimeTaskUsed_ = timeStamp; } - m_frontServices[frontServiceName] = eventId; + frontServices_[longTimeTaskName] = eventId; break; - case BundleActiveEvent::FRONT_SERVICE_STOPPED: - m_frontServices.erase(frontServiceName); + case BundleActiveEvent::LONG_TIME_TASK_STOPPED: + frontServices_.erase(longTimeTaskName); default: break; } } -void BundleActiveUsageStats::Update(std::string frontServiceName, long timeStamp, int eventId, 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: case BundleActiveEvent::ABILITY_STOP: - UpdateActivity(timeStamp, eventId, abilityId); + UpdateAbility(timeStamp, eventId, abilityId); break; case BundleActiveEvent::END_OF_THE_DAY: if (HasFrontAbility()) { IncrementTimeUsed(timeStamp); } - case BundleActiveEvent::FRONT_SERVICE_STARTTED: - case BundleActiveEvent::FRONT_SERVICE_STOPPED: - UpdateFrontService(frontServiceName, timeStamp, eventId); + case BundleActiveEvent::LONG_TIME_TASK_STARTTED: + case BundleActiveEvent::LONG_TIME_TASK_STOPPED: + UpdateLongTimeTask(longTimeTaskName, timeStamp, eventId); break; case BundleActiveEvent::DEVICE_SHUTDOWN: case BundleActiveEvent::FLUSH_TO_DISK: @@ -188,15 +189,15 @@ void BundleActiveUsageStats::Update(std::string frontServiceName, long timeStamp IncrementTimeUsed(timeStamp); } if (AnyFrontServiceStarted()) { - IncrementServiceTimeUsed(timeStamp); + IncrementLongTimeTaskTimeUsed(timeStamp); } break; default: break; } - m_endTimeStamp = timeStamp; + endTimeStamp_ = timeStamp; if (eventId == BundleActiveEvent::ABILITY_FOREGROUND) { - m_launchedCount += 1; + launchedCount_ += 1; } } } diff --git a/services/common/src/bundle_active_period_stats.cpp b/services/common/src/bundle_active_period_stats.cpp new file mode 100644 index 0000000..57a408e --- /dev/null +++ b/services/common/src/bundle_active_period_stats.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_active_period_stats.h" +#include "bundle_active_event.h" + +namespace OHOS { +namespace BundleActive { +BundleActivePackageStats& BundleActivePeriodStats::GetOrCreateUsageStats(std::string bundleName) { + std::map::iterator it; + it = bundleStats_.find(bundleName); + if (it == bundleStats_.end()) { + BundleActivePackageStats newStats; + newStats.beginTimeStamp_ = beginTime_; + newStats.endTimeStamp_ = endTime_; + newStats.bundleName_ = GetCachedString(bundleName); + bundleStats_[newStats.bundleName_] = newStats; + } + return bundleStats_[bundleName]; +} + +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); + } + } else { + BundleActivePackageStats& usageStats = GetOrCreateUsageStats(bundleName); + usageStats.Update("", timeStamp, eventId, abilityId); + } + if (timeStamp > endTime_) { + endTime_ = timeStamp; + } +} + +void BundleActivePeriodStats::AddEvent(BundleActiveEvent event) { + event.bundleName_ = GetCachedString(event.bundleName_); + if (!event.longTimeTaskName_.empty()) { + event.longTimeTaskName_ = GetCachedString(event.longTimeTaskName_); + } + events_.Insert(event); + if (event.timeStamp_ > endTime_) { + endTime_ = event.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) { + interactiveTracker_.Update(timeStamp); + noninteractiveTracker_.CommitTime(timeStamp); +} + +void BundleActivePeriodStats::UpdateScreenNonInteractive(const int64_t timeStamp) { + noninteractiveTracker_.Update(timeStamp); + interactiveTracker_.CommitTime(timeStamp); +} + +void BundleActivePeriodStats::UpdateKeyguardShown(const int64_t timeStamp) { + keyguardShownTracker_.Update(timeStamp); + keyguardHiddenTracker_.CommitTime(timeStamp); +} + +void BundleActivePeriodStats::UpdateKeyguardHidden(const int64_t timeStamp) { + keyguardHiddenTracker_.Update(timeStamp); + keyguardShownTracker_.CommitTime(timeStamp); +} + +void BundleActivePeriodStats::AddEventStatsTo(std::vector& eventStatsList) { + interactiveTracker_.AddToEventStats(eventStatsList, BundleActiveEvent::SCREEN_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); + if (it == packetNamesCache_.end()) { + packetNamesCache_.insert(str); + return str; + } + return *it; +} + +} +} \ No newline at end of file diff --git a/services/common/src/bundle_active_user_service.cpp b/services/common/src/bundle_active_user_service.cpp index 4f9d255..0a488e2 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -18,48 +18,47 @@ namespace OHOS { namespace BundleActive { BundleActiveUserService::BundleActiveUserService(int userId){//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/) { - m_currentStats.reserve(BundleActiveIntervalStats::INTERVAL_COUNT); + currentStats_.reserve(BundleActivePeriodStats::PERIOD_COUNT); //m_listener = listener; - m_userId = userId; + userId_ = userId; } void BundleActiveUserService::NotifyStatsChanged() { - if (!m_statsChanged) { - m_statsChanged = true; - //m_listener.onStatsUpdated(); + if (!statsChanged_) { + statsChanged_ = true; } } void BundleActiveUserService::ReportEvent(BundleActiveEvent event) { - BundleActiveIntervalStats currentDailyStats = m_currentStats[BundleActiveIntervalStats::INTERVAL_DAILY]; - if (event.m_eventId == BundleActiveEvent::ABILITY_FOREGROUND) { - if (!event.m_bundleName.empty() && event.m_bundleName != m_lastBackgroundBundle) { - m_incrementBundleLaunch = true; + BundleActivePeriodStats currentDailyStats = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]; + if (event.eventId_ == BundleActiveEvent::ABILITY_FOREGROUND) { + if (!event.bundleName_.empty() && event.bundleName_ != lastBackgroundBundle_) { + incrementBundleLaunch_ = true; } - } else if (event.m_eventId == BundleActiveEvent::ABILITY_BACKGROUND) { - if (!event.m_bundleName.empty()) { - m_lastBackgroundBundle = event.m_bundleName; + } else if (event.eventId_ == BundleActiveEvent::ABILITY_BACKGROUND) { + if (!event.bundleName_.empty()) { + lastBackgroundBundle_ = event.bundleName_; } } - for (int i = 0; i < m_currentStats.size(); i++) { - switch (event.m_eventId) + for (int i = 0; i < currentStats_.size(); i++) { + switch (event.eventId_) { case BundleActiveEvent::SCREEN_INTERACTIVE: - m_currentStats[i].UpdateScreenInteractive(event.m_timeStamp); + currentStats_[i].UpdateScreenInteractive(event.timeStamp_); break; case BundleActiveEvent::SCREEN_NON_INTERACTIVE: - m_currentStats[i].UpdateScreenNonInteractive(event.m_timeStamp); + currentStats_[i].UpdateScreenNonInteractive(event.timeStamp_); break; case BundleActiveEvent::KEYGUARD_SHOWN: - m_currentStats[i].UpdateKeyguardShown(event.m_timeStamp); + currentStats_[i].UpdateKeyguardShown(event.timeStamp_); break; case BundleActiveEvent::KEYGUARD_HIDDEN: - m_currentStats[i].UpdateKeyguardHidden(event.m_timeStamp); + currentStats_[i].UpdateKeyguardHidden(event.timeStamp_); break; default: - m_currentStats[i].Update(event.m_bundleName, event.m_serviceName, event.m_timeStamp, event.m_eventId, event.m_abilityId); - if (m_incrementBundleLaunch) { - m_currentStats[i].m_bundleStats[event.m_bundleName].IncrementBundleLaunchedCount(); + currentStats_[i].Update(event.bundleName_, event.longTimeTaskName_, event.timeStamp_, event.eventId_, event.abilityId_); + if (incrementBundleLaunch_) { + currentStats_[i].bundleStats_[event.bundleName_].IncrementBundleLaunchedCount(); } break; } diff --git a/services/common/src/bundle_active_user_service.h b/services/common/src/bundle_active_user_service.h new file mode 100644 index 0000000..ce4df24 --- /dev/null +++ b/services/common/src/bundle_active_user_service.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BUNDLE_ACTIVE_USER_SERVICE_H +#define BUNDLE_ACTIVE_USER_SERVICE_H + +#include "bundle_active_iservice.h" +#include "bundle_active_event.h" +#include "bundle_active_package_stats.h" +#include "bundle_active_period_stats.h" +#include "bundle_active_event_stats.h" + +namespace OHOS { +namespace BundleActive { + +class BundleActiveUserService { +public: + BundleActiveUserService(int userId);//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/); +private: + //BundleActiveUsageDatabase m_dataBase; + 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}; + void NotifyStatsChanged(); + void ReportEvent(BundleActiveEvent event); +}; +} +} +#endif \ No newline at end of file diff --git a/services/include/bundle_active_stub.h b/services/include/bundle_active_stub.h index b43e436..5b1843d 100644 --- a/services/include/bundle_active_stub.h +++ b/services/include/bundle_active_stub.h @@ -29,7 +29,6 @@ public: BundleActiveStub() {}; ~BundleActiveStub() {}; }; - } } #endif -- Gitee From 8b7ccb34374c7270cc424062f4b6cdffe85840a1 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 11 Jan 2022 11:17:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../common/src/bundle_active_user_service.cpp | 1 + .../common/src/bundle_active_user_service.h | 45 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 services/common/src/bundle_active_user_service.h diff --git a/services/common/src/bundle_active_user_service.cpp b/services/common/src/bundle_active_user_service.cpp index 0a488e2..3c0f90c 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -21,6 +21,7 @@ BundleActiveUserService::BundleActiveUserService(int userId){//,/*database定义 currentStats_.reserve(BundleActivePeriodStats::PERIOD_COUNT); //m_listener = listener; userId_ = userId; + statsChanged_ = false; } void BundleActiveUserService::NotifyStatsChanged() { diff --git a/services/common/src/bundle_active_user_service.h b/services/common/src/bundle_active_user_service.h deleted file mode 100644 index ce4df24..0000000 --- a/services/common/src/bundle_active_user_service.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUNDLE_ACTIVE_USER_SERVICE_H -#define BUNDLE_ACTIVE_USER_SERVICE_H - -#include "bundle_active_iservice.h" -#include "bundle_active_event.h" -#include "bundle_active_package_stats.h" -#include "bundle_active_period_stats.h" -#include "bundle_active_event_stats.h" - -namespace OHOS { -namespace BundleActive { - -class BundleActiveUserService { -public: - BundleActiveUserService(int userId);//,/*database定义待补充*/ BundleActiveService listener/*刷数据库监听器接口实现类*/); -private: - //BundleActiveUsageDatabase m_dataBase; - 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}; - void NotifyStatsChanged(); - void ReportEvent(BundleActiveEvent event); -}; -} -} -#endif \ No newline at end of file -- Gitee