diff --git a/BUILD.gn b/BUILD.gn index f6e950f621681213de576d79ac609561cbf206c4..fa3d6f6591eb40e29baf97bca530c751de46a3e0 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/OAT.xml b/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..b11daf5274a1b8efb7d7851c97861d0d8bf5d059 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/interfaces/innerkits/.gitkeep b/interfaces/innerkits/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 20fb365728078d3be266085fab9462a960dfc477..1576288a21f001a1027cc1ecabd33b779b61c380 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 a12e1d9fbd32a06b54864f78271ff8eb7522caad..ac9d22cadbe884479a24afd7d8606580363ad3be 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 0540c44dd9111b9552f59de738ba8c53ef637bac..9f9d8354fa8536850911cdd0da7886c97230c3e1 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 1187cbdfa325f49bfdd691cb8212beb52404060e..4b941b8a46444ed530b9f96c274e666347af34d1 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 7d3158f1946fdf25ecda5c48b138634c04e1dce3..4f5f2d9d3c601327bf05527d3eb544cac752440b 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 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 CONTINUE_PREVIOUS_DAY = 21; static const int DEVICE_SHUTDOWN = 10; static const int DEVICE_STARTUP = 11; static const int FLUSH_TO_DISK = 12; @@ -45,26 +40,24 @@ 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; - -public: + 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(); }; - } } + #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 e8c007620942e35ea2d3dc70c671027185d41c49..1ac946e744b58f1eceb6b8f4fccfff3d9dfbc552 100644 --- a/services/common/include/bundle_active_event_list.h +++ b/services/common/include/bundle_active_event_list.h @@ -27,12 +27,11 @@ 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_; }; - } } #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 e7a789e75568eec0eb634e012f77cf0b89abaf67..e4469854d4833cbbab825145bb253225c01bc470 100644 --- a/services/common/include/bundle_active_event_stats.h +++ b/services/common/include/bundle_active_event_stats.h @@ -20,15 +20,14 @@ 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(); @@ -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 09dc98a96dec1d336fd464d3137041a977f31142..19af858521c5e1a4804173bf26804643847e06bb 100644 --- a/services/common/include/bundle_active_event_tracker.h +++ b/services/common/include/bundle_active_event_tracker.h @@ -21,19 +21,17 @@ 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() {}; }; - } } #endif \ No newline at end of file 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 f97e3b8a0dce792cfe4c04c7ef8aef6fc353a3c2..9d0c9f3d34c996a69e79fc06fb11a1146cca1d9e 100644 --- a/services/common/include/bundle_active_usage_stats.h +++ b/services/common/include/bundle_active_package_stats.h @@ -13,54 +13,54 @@ * 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); }; - } } #endif 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 ea7e74ecc30f2e0881c7f062519da0629bc9ee4d..29952ad4fb9a06276b720daf84e165b060598455 100644 --- a/services/common/include/bundle_active_interval_stats.h +++ b/services/common/include/bundle_active_period_stats.h @@ -13,61 +13,54 @@ * 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); }; - } } #endif \ No newline at end of file diff --git a/services/common/include/bundle_active_user_service.h b/services/common/include/bundle_active_user_service.h index 3e68c0352907d996c3dafc846b242446c6bc9e5c..e26f22a118e37e01d01ae9355a046a020966cef8 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 { @@ -27,27 +27,18 @@ 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; - //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}; + 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/common/src/bundle_active_event.cpp b/services/common/src/bundle_active_event.cpp index e8b3e2ef4931e4831f0e62ecaca0ce9d8f8fbb9e..592544512c3befd838365fabcc942d0046840063 100644 --- a/services/common/src/bundle_active_event.cpp +++ b/services/common/src/bundle_active_event.cpp @@ -17,44 +17,42 @@ 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 9b58f81054a0be68d9b82cdffd69939017f02918..1604dcc2caeac1c6c24007c5925f530ef58121b7 100644 --- a/services/common/src/bundle_active_event_list.cpp +++ b/services/common/src/bundle_active_event_list.cpp @@ -20,29 +20,33 @@ namespace BundleActive { 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; @@ -52,12 +56,12 @@ int BundleActiveEventList::FirstIndexOnOrAfter(long timeStamp) { } return result; } + 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]); } } - } } \ 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 3e162cecd745ed2a869bface2b7fd89fff131976..f484b8dc04d2b0735e94faef44439cea66b85aa6 100644 --- a/services/common/src/bundle_active_event_stats.cpp +++ b/services/common/src/bundle_active_event_stats.cpp @@ -17,47 +17,51 @@ 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 239226f55f2d0c8c9b5615d707c6f8645392c764..b0afe2e94708284e89efd912323cb4d6a2191caa 100644 --- a/services/common/src/bundle_active_event_tracker.cpp +++ b/services/common/src/bundle_active_event_tracker.cpp @@ -17,32 +17,33 @@ 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); } } - } } \ No newline at end of file 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 c73b8b120b2315fd487e89927010bd679723d7e2..0000000000000000000000000000000000000000 --- a/services/common/src/bundle_active_interval_stats.cpp +++ /dev/null @@ -1,104 +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 c39c8f464ce4eab6027cc81709d57a1212dc861a..1b2005aa865ef3c968ef8a10a2e9f5b31bae6e0b 100644 --- a/services/common/src/bundle_active_usage_stats.cpp +++ b/services/common/src/bundle_active_package_stats.cpp @@ -13,85 +13,100 @@ * 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; } } 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) { @@ -106,64 +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: @@ -171,17 +189,16 @@ 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; } } - } } \ No newline at end of file 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 0000000000000000000000000000000000000000..57a408e23b0d1141761436217deae069f600ac9a --- /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 f010d2753f91391aefbc2a46f16dd6c1eaf6d8e8..3c0f90cc3b1bef3237cfd459ea082207fed28f98 100644 --- a/services/common/src/bundle_active_user_service.cpp +++ b/services/common/src/bundle_active_user_service.cpp @@ -17,54 +17,53 @@ 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; + statsChanged_ = false; } + 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; } } } - } } \ No newline at end of file diff --git a/services/include/bundle_active_iservice.h b/services/include/bundle_active_iservice.h index bb042068bdc361af915d857d5db8cf9ccd05a148..910166efc7e616f86c16ea9a40e4ebaed6835c50 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 b52bbd0fd712eced62857427af42aa3d46fa62a4..343eada3285315504bc0492af0be634af09e401c 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/include/bundle_active_stub.h b/services/include/bundle_active_stub.h index b43e436bd6fa057f8d41c047aeb83dcd11e027a6..5b1843da9510199ede9f49117cacfd7912973e53 100644 --- a/services/include/bundle_active_stub.h +++ b/services/include/bundle_active_stub.h @@ -29,7 +29,6 @@ public: BundleActiveStub() {}; ~BundleActiveStub() {}; }; - } } #endif diff --git a/services/src/bundle_active_service.cpp b/services/src/bundle_active_service.cpp index 3fdec33b39d0e90b5aca61456d2a9456fc73a35d..84c9d3d17124d0a3b4e91b63b19bfee4dae78f2a 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 d5910d456e6e4357cd37a196fbbdfe648903fea3..f1caeecbb585055fd27c168aff2c7943efc8277f 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