• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 APPSPAWN_HISYSEVENT_ADAPTER_H
17 #define APPSPAWN_HISYSEVENT_ADAPTER_H
18 
19 #include "appspawn_utils.h"
20 #include "loop_event.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 // 错误码定义规范:子系统ID(28-21位)| 模块ID(20-16位)| 具体错误ID(15-0位)
28 #define APPSPAWN_HISYSEVENT_REPORT_TIME (24 * 60 * 60 * 1000)   // 24h
29 #define SUBSYS_STARTUP_ID   39
30 #define SUBSYSTEM_BIT_NUM   21
31 #define MODULE_BIT_NUM  16
32 #define ERR_MODULE_APPSPAWN 0x00
33 #define ERR_MODULE_INIT 0x10
34 #define ERR_APPSPAWN_BASE   ((SUBSYS_STARTUP_ID << SUBSYSTEM_BIT_NUM) | (ERR_MODULE_APPSPAWN << MODULE_BIT_NUM))
35 #define ERR_INIT_BASE   ((SUBSYS_STARTUP_ID << SUBSYSTEM_BIT_NUM) | (ERR_MODULE_INIT << MODULE_BIT_NUM))
36 
37 typedef enum {
38     // errcode for handle msg, reserved 128, 0x0001-0x0080
39     ERR_APPSPAWN_MSG_TOO_LONG = ERR_APPSPAWN_BASE + 0x0001, // 81788929
40     ERR_APPSPAWN_MSG_INVALID_HANDLE,
41     ERR_APPSPAWN_MSG_CREATE_MSG_FAILED,
42     ERR_APPSPAWN_COPY_MSG_FAILED,
43     ERR_APPSPAWN_ALLOC_MEMORY_FAILED,
44     ERR_APPSPAWN_MSG_DECODE_MSG_FAILED,
45 
46     // errcode for hnp, reserved 128, 0x0081 - 0x0100
47     ERR_APPSPAWN_HNP = ERR_APPSPAWN_BASE + 0x0081,
48 
49     // errcode for device_dug, reserved 128, 0x0101 - 0x0180
50     ERR_APPSPAWN_DEVICE_DUG = ERR_APPSPAWN_BASE + 0x0101,
51 
52     // errcode for process_exit, reserved 128, 0x0181 - 0x0200
53     ERR_APPSPAWN_PROCESS_EXIT = ERR_APPSPAWN_BASE + 0x0181,
54 
55     // errcode for prefork, reserved 128, 0x0201 - 0x0280
56     ERR_APPSPAWN_PREFORK = ERR_APPSPAWN_BASE + 0x0201,
57 
58     // errcode for sandbox, reserved 128, 0x0281 - 0x0300
59     ERR_APPSPAWN_SANDBOX = ERR_APPSPAWN_BASE + 0x0281,
60 
61     // errcode for set permission, reserved 128, 0x0301 - 0x0380
62     ERR_APPSPAWN_SET_PERMISSION = ERR_APPSPAWN_BASE + 0x0301,
63     ERR_APPSPAWN_SET_INTE_PERMISSION_FAIL,
64     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_KEEP_CAP_FAIL,
65     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_XPM_FAIL,
66     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_PROCESSNAME_FAIL,
67     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_UIDGID_FAIL,
68     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_FD_FAIL,
69     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_CAP_FAIL,
70     ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_SELINUXCON_FAIL,
71 
72     // errorcode for spawn child process fail, reserved 128, 0x0381 - 0x0400
73     ERR_APPSPAWN_SPAWN_FAIL = ERR_APPSPAWN_BASE + 0x0381,
74     ERR_APPSPAWN_SPAWN_TIMEOUT,
75     ERR_APPSPAWN_CHILD_CRASH,
76     ERR_APPSPAWN_CHILD_MOUNT_FAILED,
77     ERR_APPSPAWN_MAX_FAILURES_EXCEEDED,
78 } AppSpawnHisysErrorCode;
79 
80 typedef struct {
81     uint32_t eventCount;
82     uint32_t maxDuration;
83     uint32_t minDuration;
84     uint32_t totalDuration;
85 } AppSpawnHisysevent;
86 
87 typedef struct {
88     AppSpawnHisysevent bootEvent; // bootStage
89     AppSpawnHisysevent manualEvent; // bootFinished
90 } AppSpawnHisyseventInfo;
91 
92 #define FUNC_REPORT_DURATION (20 * 1000)
93 #define SPAWN_DURATION (120 * 1000)
94 #define SPAWN_COLDRUN_DURATION (5 * 1000 * 1000)
95 
96 #define UNLOCK_SUCCESS "UNLOCK_SUCCESS"
97 #define LOCK_SUCCESS "LOCK_SUCCESS"
98 #define APPSPAWN_MAX_FAILURES_EXCEEDED "APPSPAWN_MAX_FAILURES_EXCEEDED"
99 AppSpawnHisyseventInfo *InitHisyseventTimer(void);
100 AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(void);
101 void AddStatisticEventInfo(AppSpawnHisyseventInfo *hisyseventInfo, uint32_t duration, bool stage);
102 void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo);
103 
104 void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode, int32_t spawnResult);
105 void ReportMountFail(const char* bundleName, const char* srcPath, const char* targetPath,
106     int32_t spawnResult);
107 void ReportKeyEvent(const char *eventName);
108 void ReportAbnormalDuration(const char* funcName, uint64_t duration);
109 void ReportSpawnStatisticDuration(const TimerHandle taskHandle, void* content);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 #endif // APPSPAWN_HISYSEVENT_ADAPTER_H