• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle.
40     std::map<std::string, int32_t> abilities_;
41     // key is name of continuous task, value is last event of this last continuous task.
42     std::map<std::string, int32_t> longTimeTasks_;
43     /*
44     * function: BundleActivePackageStats, default constructor.
45     */
46     BundleActivePackageStats();
47     /*
48     * function: ~BundleActivePackageStats, default destructor.
49     */
~BundleActivePackageStats()50     ~BundleActivePackageStats() {}
51     /*
52     * function: BundleActivePackageStats, copy constructor.
53     * parameters: orig
54     */
55     BundleActivePackageStats(const BundleActivePackageStats& orig);
56     /*
57     * function: Update, update one bundle statistics.
58     * parameters: longTimeTaskName timeStamp eventId abilityId
59     */
60     void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId,
61         const std::string& abilityId);
62     /*
63     * function: IncrementTimeUsed, increase bundle's use time.
64     * parameters: timeStamp
65     */
66     void IncrementTimeUsed(const int64_t timeStamp);
67     /*
68     * function: IncrementServiceTimeUsed, increase bundle's continuous task use time.
69     * parameters: timeStamp
70     */
71     void IncrementServiceTimeUsed(const int64_t timeStamp);
72     /*
73     * function: IncrementBundleLaunchedCount, increase bundle's launched times by 1.
74     */
75     void IncrementBundleLaunchedCount();
76     /*
77     * function: Marshalling, mashalling BundleActivePackageStats object to parcel.
78     * parameters: parcel
79     * return: result of mashalling, true means successful, flase means failed.
80     */
81     virtual bool Marshalling(Parcel &parcel) const override;
82     /*
83     * function: UnMarshalling, Unmashalling BundleActivePackageStats object from parcel.
84     * parameters: parcel
85     * return: point to a BundleActivePackageStats.
86     */
87     static std::shared_ptr<BundleActivePackageStats> UnMarshalling(Parcel &parcel);
88     /*
89     * function: ToString, change module record object to string.
90     * return: string of bundle name, last used time, total front time, last continuous task used time,
91     * total continuous task time.
92     */
93     std::string ToString();
94 
95 private:
96     bool HasFrontAbility();
97     bool AnyLongTimeTaskStarted();
98     void UpdateAbility(const int64_t timeStamp, const int32_t eventId, const std::string& abilityId);
99     void UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId);
100 };
101 }  // namespace DeviceUsageStats
102 }  // namespace OHOS
103 #endif  // BUNDLE_ACTIVE_PACKAGE_STATS_H
104 
105