• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
17 #define OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
18 
19 #include <string>
20 
21 #include "hisysevent.h"
22 
23 using HiSysEventType = OHOS::HiviewDFX::HiSysEvent::EventType;
24 using HiSysEvent = OHOS::HiviewDFX::HiSysEvent;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 struct EventInfo {
29     bool isPreload = false;
30     bool shouldKillForeground = true;
31     int32_t pid = -1;
32     int32_t userId = -1;
33     int32_t extensionType = -1;
34     int32_t abilityNumber = 0;
35     int32_t abilityType = -1;
36     int32_t callerUid = -1;
37     int32_t exitResult = -1;
38     int32_t bundleType = -1;
39     int32_t startType = 0;
40     int32_t startReason = 0;
41     int32_t appUid = -1;
42     int32_t errCode = -1;
43     int32_t callerState = -1;
44     int32_t processType = -1;
45     int32_t callerPid = -1;
46     int64_t duration = 0;
47     int32_t reason = -1;
48     int32_t subReason = -1;
49     int32_t exitReason = -1;
50     int32_t preloadMode = 0;
51     int32_t appIndex = -1;
52     int32_t persistentId = 0;
53     std::string lifeCycleState;
54     uint32_t versionCode = 0;
55     uint32_t callerVersionCode = -1;
56     int64_t time = 0;
57     std::string versionName;
58     std::string bundleName;
59     std::string moduleName;
60     std::string abilityName;
61     std::string processName;
62     std::string callerProcessName;
63     std::string callerBundleName;
64     std::string callerVersionName;
65     std::string uri;
66     std::string errReason;
67     std::string lifeCycle;
68     std::string intentName;
69     std::string errMsg;
70     std::string componentName;
71     std::string partitionName;
72     std::string exitMsg = "";
73     uint64_t remainPartitionSize;
74     std::vector<std::string> fileOfFolderPath;
75     std::vector<uint64_t> fileOfFolderSize;
76 };
77 
78 enum class EventName {
79     // fault event
80     START_ABILITY_ERROR = 0,
81     TERMINATE_ABILITY_ERROR,
82     START_EXTENSION_ERROR,
83     STOP_EXTENSION_ERROR,
84     CONNECT_SERVICE_ERROR,
85     DISCONNECT_SERVICE_ERROR,
86     UI_EXTENSION_ERROR,
87     UI_SERVICE_EXTENSION_ERROR,
88     EXECUTE_INSIGHT_INTENT_ERROR,
89     STARTUP_TASK_ERROR,
90     START_ABILITY_SYSTEM_ERROR,
91 
92     // ability behavior event
93     START_ABILITY,
94     TERMINATE_ABILITY,
95     CLOSE_ABILITY,
96     ABILITY_ONFOREGROUND,
97     ABILITY_ONBACKGROUND,
98     ABILITY_ONACTIVE,
99     ABILITY_ONINACTIVE,
100     START_ABILITY_BY_APP_LINKING,
101     KILL_PROCESS_WITH_REASON,
102 
103     // serviceExtensionAbility behavior event
104     START_SERVICE,
105     STOP_SERVICE,
106     CONNECT_SERVICE,
107     DISCONNECT_SERVICE,
108     START_ABILITY_OTHER_EXTENSION,
109 
110     // app behavior event
111     APP_ATTACH,
112     APP_LAUNCH,
113     APP_FOREGROUND,
114     APP_BACKGROUND,
115     APP_TERMINATE,
116     PROCESS_START,
117     PROCESS_EXIT,
118     DRAWN_COMPLETED,
119     APP_STARTUP_TYPE,
120     PROCESS_START_FAILED,
121 
122     // key behavior event
123     GRANT_URI_PERMISSION,
124     FA_SHOW_ON_LOCK,
125     START_PRIVATE_ABILITY,
126     RESTART_PROCESS_BY_SAME_APP,
127     START_STANDARD_ABILITIES,
128 
129     // atomic service event
130     CREATE_ATOMIC_SERVICE_PROCESS,
131     ATOMIC_SERVICE_DRAWN_COMPLETE,
132 
133     // uri permission
134     SHARE_UNPRIVILEGED_FILE_URI,
135 
136     // report data
137     USER_DATA_SIZE
138 };
139 
140 class EventReport {
141 public:
142     static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
143     static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
144     static void SendAtomicServiceEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
145     static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
146     static void SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
147     static void SendAppLaunchEvent(const EventName &eventName, const EventInfo &eventInfo);
148     static void SendAppForegroundEvent(const EventName &eventName, const EventInfo &eventInfo);
149     static void SendAppBackgroundEvent(const EventName &eventName, const EventInfo &eventInfo);
150     static void SendProcessStartEvent(const EventName &eventName, const EventInfo &eventInfo);
151     static void SendProcessStartFailedEvent(const EventName &eventName, const EventInfo &eventInfo);
152     static void SendProcessExitEvent(const EventName &eventName, const EventInfo &eventInfo);
153     static void SendStartServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
154     static void SendStopServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
155     static void SendConnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
156     static void SendDisconnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
157     static void SendStartAbilityOtherExtensionEvent(const EventName &eventName, const EventInfo &eventInfo);
158     static void SendGrantUriPermissionEvent(const EventName &eventName, const EventInfo &eventInfo);
159     static void SendExecuteIntentEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
160     static void SendLaunchFrameworkEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
161     static void SendReportDataPartitionUsageEvent(const EventName &eventName, HiSysEventType type,
162         const EventInfo &eventInfo);
163 
164 private:
165     static std::string ConvertEventName(const EventName &eventName);
166     static void LogErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
167     static void LogStartErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
168     static void LogStartAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
169     static void LogTerminateAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
170     static void LogAbilityOnForegroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
171     static void LogAbilityOnBackgroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
172     static void LogAbilityOnActiveEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
173     static void LogAbilityOnInactiveEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
174     static void LogStartStandardEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
175     static void LogStartAbilityByAppLinking(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
176     static void LogUIExtensionErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
177     static void LogUIServiceExtErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
178     static void LogSystemErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
179     static void LogKillProcessWithReason(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
180 };
181 }  // namespace AAFWK
182 }  // namespace OHOS
183 #endif  // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
184