• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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     int32_t pid = -1;
30     int32_t userId = -1;
31     int32_t extensionType = -1;
32     uint32_t versionCode = 0;
33     int32_t errCode = -1;
34     std::string versionName;
35     std::string bundleName;
36     std::string moduleName;
37     std::string abilityName;
38     std::string processName;
39     std::string callerProcessName;
40     std::string callerBundleName;
41     int32_t abilityType = -1;
42     int64_t time = 0;
43     int32_t callerUid = -1;
44     int32_t exitResult = -1;
45     int32_t bundleType = -1;
46     int32_t startType = 0;
47 };
48 
49 enum class EventName {
50     // fault event
51     START_ABILITY_ERROR,
52     TERMINATE_ABILITY_ERROR,
53     START_EXTENSION_ERROR,
54     STOP_EXTENSION_ERROR,
55     CONNECT_SERVICE_ERROR,
56     DISCONNECT_SERVICE_ERROR,
57     CLOSE_UI_ABILITY_BY_SCB_ERROR,
58 
59     // ability behavior event
60     START_ABILITY,
61     TERMINATE_ABILITY,
62     CLOSE_ABILITY,
63     CLOSE_UI_ABILITY_BY_SCB,
64     ABILITY_ONFOREGROUND,
65     ABILITY_ONBACKGROUND,
66     ABILITY_ONACTIVE,
67     ABILITY_ONINACTIVE,
68 
69     // serviceExtensionAbility behavior event
70     START_SERVICE,
71     STOP_SERVICE,
72     CONNECT_SERVICE,
73     DISCONNECT_SERVICE,
74 
75     // app behavior event
76     APP_ATTACH,
77     APP_LAUNCH,
78     APP_FOREGROUND,
79     APP_BACKGROUND,
80     APP_TERMINATE,
81     PROCESS_START,
82     PROCESS_EXIT,
83     DRAWN_COMPLETED,
84     APP_STARTUP_TYPE,
85 };
86 
87 class EventReport {
88 public:
89     static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
90     static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
91     static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
92 
93 private:
94     static std::string ConvertEventName(const EventName &eventName);
95 };
96 }  // namespace AAFWK
97 }  // namespace OHOS
98 #endif  // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
99