1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BUNDLE_ACTIVE_PERIOD_STATS_H 17 #define BUNDLE_ACTIVE_PERIOD_STATS_H 18 19 #include <memory> 20 21 #include "ibundle_active_service.h" 22 #include "bundle_active_event.h" 23 #include "bundle_active_package_stats.h" 24 #include "bundle_active_event_list.h" 25 #include "bundle_active_event_tracker.h" 26 27 28 namespace OHOS { 29 namespace DeviceUsageStats { 30 class BundleActivePeriodStats { 31 public: 32 static const int32_t PERIOD_DAILY = 0; 33 static const int32_t PERIOD_WEEKLY = 1; 34 static const int32_t PERIOD_MONTHLY = 2; 35 static const int32_t PERIOD_YEARLY = 3; 36 static const int32_t PERIOD_BEST = 4; 37 static const int32_t PERIOD_COUNT = 4; 38 int64_t beginTime_; 39 int64_t endTime_; 40 int64_t lastTimeSaved_; 41 int32_t userId_; 42 std::map<std::string, std::shared_ptr<BundleActivePackageStats>> bundleStats_; 43 BundleActiveEventList events_; 44 std::set<std::string> packetNamesCache_; 45 BundleActiveEventTracker interactiveTracker_; 46 BundleActiveEventTracker noninteractiveTracker_; 47 BundleActiveEventTracker keyguardShownTracker_; 48 BundleActiveEventTracker keyguardHiddenTracker_; 49 /* 50 * function: BundleActivePeriodStats,default constructor. 51 */ 52 BundleActivePeriodStats(); 53 /* 54 * function: GetOrCreateUsageStats, get or create bundle usage statistics object of a bundle. 55 * parameters: bundleName 56 * return: point to bundle usage statistics object. 57 */ 58 std::shared_ptr<BundleActivePackageStats> GetOrCreateUsageStats(const std::string& bundleName); 59 /* 60 * function: Update, update usage statistics of specific bundle. 61 * parameters: bundleName, longTimeTaskName, timeStamp, eventId, abilityId 62 */ 63 void Update(const std::string bundleName, const std::string longTimeTaskName, const int64_t timeStamp, 64 const int32_t eventId, const std::string abilityId); 65 /* 66 * function: AddEvent, add a event to member events_. 67 * parameters: event 68 */ 69 void AddEvent(BundleActiveEvent event); 70 /* 71 * function: UpdateScreenInteractive, update screen interactive time. 72 * parameters: timeStamp 73 */ 74 void UpdateScreenInteractive(const int64_t timeStamp); 75 /* 76 * function: UpdateScreenNonInteractive, update screen non interactive time. 77 * parameters: timeStamp 78 */ 79 void UpdateScreenNonInteractive(const int64_t timeStamp); 80 /* 81 * function: UpdateKeyguardShown, key guard shown time. 82 * parameters: timeStamp 83 */ 84 void UpdateKeyguardShown(const int64_t timeStamp); 85 /* 86 * function: UpdateKeyguardHidden, key guard hidden time. 87 * parameters: timeStamp 88 */ 89 void UpdateKeyguardHidden(const int64_t timeStamp); 90 /* 91 * function: CommitTime, key guard hidden time. 92 * parameters: timeStamp 93 */ 94 void CommitTime(const int64_t timeStamp); 95 /* 96 * function: AddEventStatsTo, add all time to eventStatsList. 97 * parameters: eventStatsList 98 */ 99 void AddEventStatsTo(std::vector<BundleActiveEventStats>& eventStatsList); 100 /* 101 * function: GetCachedString, store string to cache. 102 * parameters: str 103 * return: string 104 */ 105 std::string GetCachedString(std::string str); 106 }; 107 } // namespace DeviceUsageStats 108 } // namespace OHOS 109 #endif // BUNDLE_ACTIVE_PERIOD_STATS_H 110 111