• 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_EVENT_H
17 #define BUNDLE_ACTIVE_EVENT_H
18 
19 #include <cstdint>
20 #include <iosfwd>
21 #include <memory>
22 #include "parcel.h"
23 
24 namespace OHOS {
25 namespace DeviceUsageStats {
26 class BundleActiveEvent : public Parcelable {
27 public:
28     // external events
29     static const int32_t ABILITY_FOREGROUND = 2; // onForeground() called, ability is in front.
30     static const int32_t ABILITY_BACKGROUND = 3; // onBackground() called, ability is in background.
31     static const int32_t ABILITY_STOP = 4; // onStop() called, ability is destroyed.
32     static const int32_t LONG_TIME_TASK_STARTTED = 5;
33     static const int32_t LONG_TIME_TASK_ENDED = 6;
34     static const int32_t SYSTEM_INTERACTIVE = 7;
35     static const int32_t USER_INTERACTIVE = 8;
36     // internal events
37     static const int32_t DEFAULT_EVENT_ID = 0;
38     static const int32_t END_OF_THE_DAY = 9;
39     static const int32_t SHUTDOWN = 10;
40     static const int32_t STARTUP = 11;
41     static const int32_t FLUSH = 12;
42     static const int32_t SCREEN_INTERACTIVE = 13;
43     static const int32_t SCREEN_NON_INTERACTIVE = 14;
44     static const int32_t FORM_IS_CLICKED = 15;
45     static const int32_t FORM_IS_REMOVED = 16;
46     static const int32_t KEYGUARD_SHOWN = 17;
47     static const int32_t KEYGUARD_HIDDEN = 18;
48     static const int32_t NOTIFICATION_SEEN = 19;
49     static const int32_t SYSTEM_LOCK = 20;
50     static const int32_t SYSTEM_UNLOCK = 21;
51     static const int32_t SYSTEM_SLEEP = 22;
52     static const int32_t SYSTEM_WAKEUP = 23;
53     inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony";
54     std::string bundleName_;
55     std::string continuousTaskAbilityName_;
56     std::string abilityName_;
57     std::string abilityId_;
58     std::string moduleName_;
59     std::string formName_;
60     int32_t formDimension_;
61     int64_t formId_;
62     int64_t timeStamp_;
63     int32_t eventId_;
64 
65 public:
66     /*
67     * function: BundleActiveEvent, default constructor.
68     */
69     BundleActiveEvent();
70     /*
71     * function: BundleActiveEvent, copy constructor.
72     * parameters: orig
73     */
74     BundleActiveEvent(const BundleActiveEvent& orig);
75     /*
76     * function: BundleActiveEvent, constructor using event Id, time stamp.
77     * parameters: eventId, timeStamp
78     */
79     BundleActiveEvent(int32_t eventId, int64_t timeStamp);
80     /*
81     * function: BundleActiveEvent, constructor using event Id, time stamp.
82     * parameters: eventId, bundleName.
83     */
84     BundleActiveEvent(const int32_t eventId, const std::string bundleName);
85     /*
86     * function: BundleActiveEvent, constructor of continuous task event.
87     * parameters: bundleName, continuousTaskAbilityName
88     */
89     BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName);
90     /*
91     * function: BundleActiveEvent, constructor of app ability event.
92     * parameters: bundleName, abilityName, abilityId
93     */
94     BundleActiveEvent(const std::string bundleName, const std::string abilityName, const std::string abilityId,
95         const std::string moduleName);
96     /*
97     * function: BundleActiveEvent, constructor of form event.
98     * parameters: bundleName, moduleName, formName, formDimension, formId, eventId
99     */
100     BundleActiveEvent(const std::string bundleName, const std::string moduleName,
101         const std::string formName, const int32_t formDimension, const int64_t formId, const int32_t eventId);
102     void PrintEvent(const bool debug) const;
103     /*
104     * function: operator=, override operator =.
105     * parameters: orig
106     * return: a BundleActiveEvent object same as orig.
107     */
108     BundleActiveEvent& operator=(const BundleActiveEvent& orig);
109     /*
110     * function: Marshalling, mashalling event object to parcel.
111     * parameters: parcel
112     * return: result of mashalling, true means successful, flase means failed.
113     */
114     virtual bool Marshalling(Parcel &parcel) const override;
115     /*
116     * function: UnMarshalling, Unmashalling event object from parcel.
117     * parameters: parcel
118     * return: point to a BundleActiveEvent.
119     */
120     static std::shared_ptr<BundleActiveEvent> UnMarshalling(Parcel &parcel);
121     /*
122     * function: ToString, change event object to string.
123     * return: string of bundlename, timestamp, eventid.
124     */
125     std::string ToString();
126     /**
127     * @brief get if the event is reported by bundle usage.
128     *
129     * @return return true if event reported by bundle usage.
130     */
131     static bool IsBundleEvent(const int32_t eventId);
132 };
133 }  // namespace DeviceUsageStats
134 }  // namespace OHOS
135 #endif  // BUNDLE_ACTIVE_EVENT_H
136 
137