• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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     int32_t pid = -1;
31     int32_t userId = -1;
32     int32_t extensionType = -1;
33     int32_t abilityNumber = 0;
34     int32_t abilityType = -1;
35     int32_t callerUid = -1;
36     int32_t exitResult = -1;
37     int32_t bundleType = -1;
38     int32_t startType = 0;
39     int32_t startReason = 0;
40     int32_t appUid = -1;
41     int32_t errCode = -1;
42     int32_t callerState = -1;
43     int32_t processType = -1;
44     int32_t callerPid = -1;
45     int64_t duration = 0;
46     int32_t reason = -1;
47     int32_t subReason = -1;
48     int32_t exitReason = -1;
49     int32_t preloadMode = 0;
50     uint32_t versionCode = 0;
51     uint32_t callerVersionCode = -1;
52     int64_t time = 0;
53     std::string versionName;
54     std::string bundleName;
55     std::string moduleName;
56     std::string abilityName;
57     std::string processName;
58     std::string callerProcessName;
59     std::string callerBundleName;
60     std::string callerVersionName;
61     std::string uri;
62 };
63 
64 enum class EventName {
65     // fault event
66     START_ABILITY_ERROR = 0,
67     TERMINATE_ABILITY_ERROR,
68     START_EXTENSION_ERROR,
69     STOP_EXTENSION_ERROR,
70     CONNECT_SERVICE_ERROR,
71     DISCONNECT_SERVICE_ERROR,
72 
73     // ability behavior event
74     START_ABILITY,
75     TERMINATE_ABILITY,
76     CLOSE_ABILITY,
77     ABILITY_ONFOREGROUND,
78     ABILITY_ONBACKGROUND,
79     ABILITY_ONACTIVE,
80     ABILITY_ONINACTIVE,
81     START_ABILITY_BY_APP_LINKING,
82 
83     // serviceExtensionAbility behavior event
84     START_SERVICE,
85     STOP_SERVICE,
86     CONNECT_SERVICE,
87     DISCONNECT_SERVICE,
88     START_ABILITY_OTHER_EXTENSION,
89 
90     // app behavior event
91     APP_ATTACH,
92     APP_LAUNCH,
93     APP_FOREGROUND,
94     APP_BACKGROUND,
95     APP_TERMINATE,
96     PROCESS_START,
97     PROCESS_EXIT,
98     DRAWN_COMPLETED,
99     APP_STARTUP_TYPE,
100     PROCESS_START_FAILED,
101 
102     // key behavior event
103     GRANT_URI_PERMISSION,
104     FA_SHOW_ON_LOCK,
105     START_PRIVATE_ABILITY,
106     RESTART_PROCESS_BY_SAME_APP,
107     START_STANDARD_ABILITIES,
108 
109     // atomic service event
110     CREATE_ATOMIC_SERVICE_PROCESS,
111     ATOMIC_SERVICE_DRAWN_COMPLETE,
112 
113     // uri permission
114     SHARE_UNPRIVILEGED_FILE_URI
115 };
116 
117 class EventReport {
118 public:
119     static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
120     static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
121     static void SendAtomicServiceEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
122     static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
123     static void SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
124     static void SendAppLaunchEvent(const EventName &eventName, const EventInfo &eventInfo);
125     static void SendAppForegroundEvent(const EventName &eventName, const EventInfo &eventInfo);
126     static void SendAppBackgroundEvent(const EventName &eventName, const EventInfo &eventInfo);
127     static void SendProcessStartEvent(const EventName &eventName, const EventInfo &eventInfo);
128     static void SendProcessStartFailedEvent(const EventName &eventName, const EventInfo &eventInfo);
129     static void SendProcessExitEvent(const EventName &eventName, const EventInfo &eventInfo);
130     static void SendStartServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
131     static void SendStopServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
132     static void SendConnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
133     static void SendDisconnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
134     static void SendStartAbilityOtherExtensionEvent(const EventName &eventName, const EventInfo &eventInfo);
135     static void SendGrantUriPermissionEvent(const EventName &eventName, const EventInfo &eventInfo);
136 
137 private:
138     static std::string ConvertEventName(const EventName &eventName);
139     static void LogErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
140     static void LogStartAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
141     static void LogTerminateAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
142     static void LogAbilityOnForegroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
143     static void LogAbilityOnBackgroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
144     static void LogAbilityOnActiveEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
145     static void LogStartStandardEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
146     static void LogStartAbilityByAppLinking(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
147 };
148 }  // namespace AAFWK
149 }  // namespace OHOS
150 #endif  // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
151