• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "init_hisysevent.h"
17 #include "hisysevent_c.h"
18 #include "plugin_adapter.h"
19 #include "securec.h"
20 #include "init_log.h"
21 #include "init_utils.h"
22 
23 #define STARTUP_DOMAIN "INIT"
24 
ReportStartupInitReport(int64_t count)25 void ReportStartupInitReport(int64_t count)
26 {
27     HiSysEventParam params[] = {
28         {
29             .name = "NUMBER_CFG",
30             .t = HISYSEVENT_INT64,
31             .v = { .i64 = count },
32             .arraySize = 0,
33         }
34     };
35     int ret = OH_HiSysEvent_Write(STARTUP_DOMAIN, "STARTUP_INIT_REPORT",
36         HISYSEVENT_STATISTIC, params, sizeof(params) / sizeof(params[0]));
37     PLUGIN_ONLY_LOG(ret == 0, "Failed to write event ret %d", ret);
38 }
39 
ReportServiceStart(char * serviceName,int64_t pid)40 void ReportServiceStart(char *serviceName, int64_t pid)
41 {
42     if (!IsBootCompleted()) {
43         return;
44     }
45     if (serviceName == NULL) {
46         INIT_LOGE("serviceName is NULL");
47         return;
48     }
49     HiSysEventParam params[] = {
50         {
51             .name = "SERVICE_NAME",
52             .t = HISYSEVENT_STRING,
53             .v = { .s = serviceName },
54             .arraySize = 0,
55         },
56         {
57             .name = "SERVICE_PID",
58             .t = HISYSEVENT_INT64,
59             .v = { .i64 = pid },
60             .arraySize = 0,
61         }
62     };
63     int ret = OH_HiSysEvent_Write(STARTUP_DOMAIN, "PROCESS_START",
64         HISYSEVENT_BEHAVIOR, params, sizeof(params) / sizeof(params[0]));
65     PLUGIN_ONLY_LOG(ret == 0, "Failed to write event ret %d", ret);
66 }
67 
ReportStartupReboot(const char * argv)68 void ReportStartupReboot(const char *argv)
69 {
70     if (argv == NULL) {
71         INIT_LOGE("ReportStartupReboot failed, argv is NULL");
72         return;
73     }
74     char mode[32] = {0};
75     if (strcpy_s(mode, sizeof(mode), argv) != 0) {
76         INIT_LOGE("Failed to copy argv");
77         return;
78     }
79     HiSysEventParam params[] = {
80         {
81             .name = "REBOOT_MODE",
82             .t = HISYSEVENT_STRING,
83             .v = { .s = mode },
84             .arraySize = 0,
85         }
86     };
87     int ret = OH_HiSysEvent_Write(STARTUP_DOMAIN, "STARTUP_REBOOT",
88         HISYSEVENT_BEHAVIOR, params, sizeof(params) / sizeof(params[0]));
89     PLUGIN_ONLY_LOG(ret == 0, "Failed to write event ret %d", ret);
90 }
91 
ReportChildProcessExit(const char * serviceName,int pid,int err)92 void ReportChildProcessExit(const char *serviceName, int pid, int err)
93 {
94     if (!IsBootCompleted()) {
95         return;
96     }
97     if (serviceName == NULL) {
98         INIT_LOGE("ReportChildProcessExit failed, serviceName is NULL");
99         return;
100     }
101     char tempServiceName[32] = {0};
102     if (strcpy_s(tempServiceName, sizeof(tempServiceName), serviceName) != 0) {
103         INIT_LOGE("Failed to copy serviceName");
104         return;
105     }
106     HiSysEventParam params[] = {
107         {
108             .name = "PROCESS_NAME",
109             .t = HISYSEVENT_STRING,
110             .v = { .s = tempServiceName },
111             .arraySize = 0,
112         },
113         {
114             .name = "PID",
115             .t = HISYSEVENT_INT64,
116             .v = { .i64 = pid },
117             .arraySize = 0,
118         },
119         {
120             .name = "EXIT_CODE",
121             .t = HISYSEVENT_INT64,
122             .v = { .i64 = err },
123             .arraySize = 0,
124         }
125     };
126     int ret = OH_HiSysEvent_Write(STARTUP_DOMAIN, "CHILD_PROCESS_EXIT",
127         HISYSEVENT_BEHAVIOR, params, sizeof(params) / sizeof(params[0]));
128     PLUGIN_ONLY_LOG(ret == 0, "Failed to write event ret %d", ret);
129 }
130