• 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 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 
29 struct EventInfo {
30     int32_t pid = -1;
31     int32_t userId = -1;
32     int64_t formId = -1;
33     int32_t extensionType = -1;
34     uint32_t versionCode = 0;
35     int32_t errCode = -1;
36     std::string versionName;
37     std::string bundleName;
38     std::string moduleName;
39     std::string abilityName;
40     std::string processName;
41     int32_t abilityType = -1;
42 };
43 
44 enum class EventName {
45     // fault event
46     START_ABILITY_ERROR,
47     TERMINATE_ABILITY_ERROR,
48     START_EXTENSION_ERROR,
49     STOP_EXTENSION_ERROR,
50     CONNECT_SERVICE_ERROR,
51     DISCONNECT_SERVICE_ERROR,
52 
53     // ability behavior event
54     START_ABILITY,
55     TERMINATE_ABILITY,
56     CLOSE_ABILITY,
57     ABILITY_ONFOREGROUND,
58     ABILITY_ONBACKGROUND,
59     ABILITY_ONACTIVE,
60     ABILITY_ONINACTIVE,
61 
62     // serviceExtensionAbility behavior event
63     START_SERVICE,
64     STOP_SERVICE,
65     CONNECT_SERVICE,
66     DISCONNECT_SERVICE,
67 
68     // form behavior event
69     ADD_FORM,
70     REQUEST_FORM,
71     DELETE_FORM,
72     CASTTEMP_FORM,
73     ACQUIREFORMSTATE_FORM,
74     MESSAGE_EVENT_FORM,
75     ROUTE_EVENT_FORM,
76     BACKGROUND_EVENT_FORM,
77     RELEASE_FORM,
78     DELETE_INVALID_FORM,
79     SET_NEXT_REFRESH_TIME_FORM,
80 
81     // app behavior event
82     APP_ATTACH,
83     APP_LAUNCH,
84     APP_FOREGROUND,
85     APP_BACKGROUND,
86     APP_TERMINATE,
87 };
88 
89 class EventReport {
90 public:
91     static void SendAppEvent(const EventName &eventName, HiSysEventType type,
92         const EventInfo& eventInfo);
93     static void SendAbilityEvent(const EventName &eventName, HiSysEventType type,
94         const EventInfo& eventInfo);
95     static void SendExtensionEvent(const EventName &eventName, HiSysEventType type,
96         const EventInfo& eventInfo);
97     static void SendFormEvent(const EventName &eventName, HiSysEventType type,
98         const EventInfo& eventInfo);
99 private:
100     static std::string ConvertEventName(const EventName &eventName);
101 };
102 }  // namespace AAFWK
103 }  // namespace OHOS
104 #endif  // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
105