1eace7efcSopenharmony_ci/*
2eace7efcSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License.
5eace7efcSopenharmony_ci * You may obtain a copy of the License at
6eace7efcSopenharmony_ci *
7eace7efcSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8eace7efcSopenharmony_ci *
9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and
13eace7efcSopenharmony_ci * limitations under the License.
14eace7efcSopenharmony_ci */
15eace7efcSopenharmony_ci
16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
18eace7efcSopenharmony_ci
19eace7efcSopenharmony_ci#include <string>
20eace7efcSopenharmony_ci
21eace7efcSopenharmony_ci#include "hisysevent.h"
22eace7efcSopenharmony_ci
23eace7efcSopenharmony_ciusing HiSysEventType = OHOS::HiviewDFX::HiSysEvent::EventType;
24eace7efcSopenharmony_ciusing HiSysEvent = OHOS::HiviewDFX::HiSysEvent;
25eace7efcSopenharmony_ci
26eace7efcSopenharmony_cinamespace OHOS {
27eace7efcSopenharmony_cinamespace AAFwk {
28eace7efcSopenharmony_cistruct EventInfo {
29eace7efcSopenharmony_ci    int32_t pid = -1;
30eace7efcSopenharmony_ci    int32_t userId = -1;
31eace7efcSopenharmony_ci    int32_t extensionType = -1;
32eace7efcSopenharmony_ci    uint32_t versionCode = 0;
33eace7efcSopenharmony_ci    int32_t errCode = -1;
34eace7efcSopenharmony_ci    std::string versionName;
35eace7efcSopenharmony_ci    std::string bundleName;
36eace7efcSopenharmony_ci    std::string moduleName;
37eace7efcSopenharmony_ci    std::string abilityName;
38eace7efcSopenharmony_ci    std::string processName;
39eace7efcSopenharmony_ci    std::string callerProcessName;
40eace7efcSopenharmony_ci    std::string callerBundleName;
41eace7efcSopenharmony_ci    int32_t abilityNumber = 0;
42eace7efcSopenharmony_ci    int32_t abilityType = -1;
43eace7efcSopenharmony_ci    int64_t time = 0;
44eace7efcSopenharmony_ci    int32_t callerUid = -1;
45eace7efcSopenharmony_ci    int32_t exitResult = -1;
46eace7efcSopenharmony_ci    int32_t bundleType = -1;
47eace7efcSopenharmony_ci    int32_t startType = 0;
48eace7efcSopenharmony_ci    int32_t appUid = -1;
49eace7efcSopenharmony_ci    int32_t callerState = -1;
50eace7efcSopenharmony_ci    uint32_t callerVersionCode = -1;
51eace7efcSopenharmony_ci    std::string callerVersionName;
52eace7efcSopenharmony_ci    std::string uri;
53eace7efcSopenharmony_ci    int32_t processType = -1;
54eace7efcSopenharmony_ci    int32_t callerPid = -1;
55eace7efcSopenharmony_ci    int64_t duration = 0;
56eace7efcSopenharmony_ci    int32_t reason = -1;
57eace7efcSopenharmony_ci    int32_t subReason = -1;
58eace7efcSopenharmony_ci};
59eace7efcSopenharmony_ci
60eace7efcSopenharmony_cienum class EventName {
61eace7efcSopenharmony_ci    // fault event
62eace7efcSopenharmony_ci    START_ABILITY_ERROR = 0,
63eace7efcSopenharmony_ci    TERMINATE_ABILITY_ERROR,
64eace7efcSopenharmony_ci    START_EXTENSION_ERROR,
65eace7efcSopenharmony_ci    STOP_EXTENSION_ERROR,
66eace7efcSopenharmony_ci    CONNECT_SERVICE_ERROR,
67eace7efcSopenharmony_ci    DISCONNECT_SERVICE_ERROR,
68eace7efcSopenharmony_ci
69eace7efcSopenharmony_ci    // ability behavior event
70eace7efcSopenharmony_ci    START_ABILITY,
71eace7efcSopenharmony_ci    TERMINATE_ABILITY,
72eace7efcSopenharmony_ci    CLOSE_ABILITY,
73eace7efcSopenharmony_ci    ABILITY_ONFOREGROUND,
74eace7efcSopenharmony_ci    ABILITY_ONBACKGROUND,
75eace7efcSopenharmony_ci    ABILITY_ONACTIVE,
76eace7efcSopenharmony_ci    ABILITY_ONINACTIVE,
77eace7efcSopenharmony_ci    START_ABILITY_BY_APP_LINKING,
78eace7efcSopenharmony_ci
79eace7efcSopenharmony_ci    // serviceExtensionAbility behavior event
80eace7efcSopenharmony_ci    START_SERVICE,
81eace7efcSopenharmony_ci    STOP_SERVICE,
82eace7efcSopenharmony_ci    CONNECT_SERVICE,
83eace7efcSopenharmony_ci    DISCONNECT_SERVICE,
84eace7efcSopenharmony_ci    START_ABILITY_OTHER_EXTENSION,
85eace7efcSopenharmony_ci
86eace7efcSopenharmony_ci    // app behavior event
87eace7efcSopenharmony_ci    APP_ATTACH,
88eace7efcSopenharmony_ci    APP_LAUNCH,
89eace7efcSopenharmony_ci    APP_FOREGROUND,
90eace7efcSopenharmony_ci    APP_BACKGROUND,
91eace7efcSopenharmony_ci    APP_TERMINATE,
92eace7efcSopenharmony_ci    PROCESS_START,
93eace7efcSopenharmony_ci    PROCESS_EXIT,
94eace7efcSopenharmony_ci    DRAWN_COMPLETED,
95eace7efcSopenharmony_ci    APP_STARTUP_TYPE,
96eace7efcSopenharmony_ci    PROCESS_START_FAILED,
97eace7efcSopenharmony_ci
98eace7efcSopenharmony_ci    // key behavior event
99eace7efcSopenharmony_ci    GRANT_URI_PERMISSION,
100eace7efcSopenharmony_ci    FA_SHOW_ON_LOCK,
101eace7efcSopenharmony_ci    START_PRIVATE_ABILITY,
102eace7efcSopenharmony_ci    RESTART_PROCESS_BY_SAME_APP,
103eace7efcSopenharmony_ci    START_STANDARD_ABILITIES,
104eace7efcSopenharmony_ci
105eace7efcSopenharmony_ci    // atomic service event
106eace7efcSopenharmony_ci    CREATE_ATOMIC_SERVICE_PROCESS,
107eace7efcSopenharmony_ci    ATOMIC_SERVICE_DRAWN_COMPLETE,
108eace7efcSopenharmony_ci
109eace7efcSopenharmony_ci    // uri permission
110eace7efcSopenharmony_ci    SHARE_UNPRIVILEGED_FILE_URI
111eace7efcSopenharmony_ci};
112eace7efcSopenharmony_ci
113eace7efcSopenharmony_ciclass EventReport {
114eace7efcSopenharmony_cipublic:
115eace7efcSopenharmony_ci    static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
116eace7efcSopenharmony_ci    static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
117eace7efcSopenharmony_ci    static void SendAtomicServiceEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
118eace7efcSopenharmony_ci    static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
119eace7efcSopenharmony_ci    static void SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo);
120eace7efcSopenharmony_ci    static void SendAppLaunchEvent(const EventName &eventName, const EventInfo &eventInfo);
121eace7efcSopenharmony_ci    static void SendAppForegroundEvent(const EventName &eventName, const EventInfo &eventInfo);
122eace7efcSopenharmony_ci    static void SendAppBackgroundEvent(const EventName &eventName, const EventInfo &eventInfo);
123eace7efcSopenharmony_ci    static void SendProcessStartEvent(const EventName &eventName, const EventInfo &eventInfo);
124eace7efcSopenharmony_ci    static void SendProcessStartFailedEvent(const EventName &eventName, const EventInfo &eventInfo);
125eace7efcSopenharmony_ci    static void SendProcessExitEvent(const EventName &eventName, const EventInfo &eventInfo);
126eace7efcSopenharmony_ci    static void SendStartServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
127eace7efcSopenharmony_ci    static void SendStopServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
128eace7efcSopenharmony_ci    static void SendConnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
129eace7efcSopenharmony_ci    static void SendDisconnectServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
130eace7efcSopenharmony_ci    static void SendStartAbilityOtherExtensionEvent(const EventName &eventName, const EventInfo &eventInfo);
131eace7efcSopenharmony_ci    static void SendGrantUriPermissionEvent(const EventName &eventName, const EventInfo &eventInfo);
132eace7efcSopenharmony_ci
133eace7efcSopenharmony_ciprivate:
134eace7efcSopenharmony_ci    static std::string ConvertEventName(const EventName &eventName);
135eace7efcSopenharmony_ci    static void LogErrorEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
136eace7efcSopenharmony_ci    static void LogStartAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
137eace7efcSopenharmony_ci    static void LogTerminateAbilityEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
138eace7efcSopenharmony_ci    static void LogAbilityOnForegroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
139eace7efcSopenharmony_ci    static void LogAbilityOnBackgroundEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
140eace7efcSopenharmony_ci    static void LogAbilityOnActiveEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
141eace7efcSopenharmony_ci    static void LogStartStandardEvent(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
142eace7efcSopenharmony_ci    static void LogStartAbilityByAppLinking(const std::string &name, HiSysEventType type, const EventInfo &eventInfo);
143eace7efcSopenharmony_ci};
144eace7efcSopenharmony_ci}  // namespace AAFWK
145eace7efcSopenharmony_ci}  // namespace OHOS
146eace7efcSopenharmony_ci#endif  // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H
147