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_PACKAGE_STATS_H 17 #define BUNDLE_ACTIVE_PACKAGE_STATS_H 18 19 #include <cstdint> 20 #include <iosfwd> 21 #include <map> 22 #include <memory> 23 #include "parcel.h" 24 25 namespace OHOS { 26 namespace DeviceUsageStats { 27 class BundleActivePackageStats : public Parcelable { 28 public: 29 std::string bundleName_; 30 int64_t beginTimeStamp_; // start time of counting 31 int64_t endTimeStamp_; // stop time of counting 32 int64_t lastTimeUsed_; // the timestamp of last launch 33 int64_t totalInFrontTime_; // the total time of using the bundle 34 int64_t lastContiniousTaskUsed_; 35 int64_t totalContiniousTaskUsedTime_; 36 int32_t startCount_; 37 int32_t bundleStartedCount_; 38 int32_t lastEvent_; 39 int32_t userId_; 40 int32_t uid_; 41 int32_t appIndex_; 42 // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. 43 std::map<std::string, int32_t> abilities_; 44 // key is name of continuous task, value is last event of this last continuous task. 45 std::map<std::string, int32_t> longTimeTasks_; 46 /* 47 * function: BundleActivePackageStats, default constructor. 48 */ 49 BundleActivePackageStats(); 50 /* 51 * function: ~BundleActivePackageStats, default destructor. 52 */ ~BundleActivePackageStats()53 ~BundleActivePackageStats() {} 54 /* 55 * function: BundleActivePackageStats, copy constructor. 56 * parameters: orig 57 */ 58 BundleActivePackageStats(const BundleActivePackageStats& orig); 59 /* 60 * function: Update, update one bundle statistics. 61 * parameters: longTimeTaskName timeStamp eventId abilityId 62 */ 63 void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId, 64 const std::string& abilityId, const int32_t uid); 65 /* 66 * function: IncrementTimeUsed, increase bundle's use time. 67 * parameters: timeStamp 68 */ 69 void IncrementTimeUsed(const int64_t timeStamp); 70 /* 71 * function: IncrementServiceTimeUsed, increase bundle's continuous task use time. 72 * parameters: timeStamp 73 */ 74 void IncrementServiceTimeUsed(const int64_t timeStamp); 75 /* 76 * function: IncrementBundleLaunchedCount, increase bundle's launched times by 1. 77 */ 78 void IncrementBundleLaunchedCount(); 79 /* 80 * function: Marshalling, mashalling BundleActivePackageStats object to parcel. 81 * parameters: parcel 82 * return: result of mashalling, true means successful, flase means failed. 83 */ 84 virtual bool Marshalling(Parcel &parcel) const override; 85 /* 86 * function: Unmarshalling, Unmashalling BundleActivePackageStats object from parcel. 87 * parameters: parcel 88 * return: point to a BundleActivePackageStats. 89 */ 90 static BundleActivePackageStats *Unmarshalling(Parcel &parcel); 91 /* 92 * function: ToString, change module record object to string. 93 * return: string of bundle name, last used time, total front time, last continuous task used time, 94 * total continuous task time. 95 */ 96 std::string ToString(); 97 98 private: 99 bool HasFrontAbility(); 100 bool AnyLongTimeTaskStarted(); 101 void UpdateAbility(const int64_t timeStamp, const int32_t eventId, const std::string& abilityId); 102 void UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId); 103 }; 104 } // namespace DeviceUsageStats 105 } // namespace OHOS 106 #endif // BUNDLE_ACTIVE_PACKAGE_STATS_H 107 108