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 #define LOG_TAG "UdmfRadarReporter"
16 
17 #include "udmf_radar_reporter.h"
18 
19 namespace OHOS {
20 namespace UDMF {
21 using namespace RadarReporter;
ReportNormal(const std::string & func,int32_t scene,int32_t stage,int32_t stageRes,int32_t state)22 void RadarReporterAdapter::ReportNormal(const std::string &func, int32_t scene,
23                                         int32_t stage, int32_t stageRes, int32_t state)
24 {
25     struct HiSysEventParam params[] = {
26         { .name = { "ORG_PKG" },
27             .t = HISYSEVENT_STRING,
28             .v = { .s = const_cast<char *>(ORG_PKG) },
29             .arraySize = 0 },
30         { .name = { "FUNC" },
31             .t = HISYSEVENT_STRING,
32             .v = { .s = const_cast<char *>(func.c_str()) },
33             .arraySize = 0 },
34         { .name = { "BIZ_SCENE" },
35             .t = HISYSEVENT_INT32,
36             .v = { .i32 = scene },
37             .arraySize = 0 },
38         { .name = { "BIZ_STAGE" },
39             .t = HISYSEVENT_INT32,
40             .v = { .i32 = stage },
41             .arraySize = 0 },
42         { .name = { "STAGE_RES" },
43             .t = HISYSEVENT_INT32,
44             .v = { .i32 = stageRes },
45             .arraySize = 0 },
46         { .name = { "BIZ_STATE" },
47             .t = HISYSEVENT_INT32,
48             .v = { .i32 = state },
49             .arraySize = 0 }
50     };
51     OH_HiSysEvent_Write(
52         DOMAIN,
53         EVENT_NAME,
54         HISYSEVENT_BEHAVIOR,
55         params,
56         sizeof(params) / sizeof(params[0])
57     );
58 }
59 
ReportFail(const std::string & func,int32_t scene,int32_t stage,int32_t stageRes,int32_t errorCode,int32_t state)60 void RadarReporterAdapter::ReportFail(
61     const std::string &func, int32_t scene, int32_t stage, int32_t stageRes, int32_t errorCode, int32_t state)
62 {
63     struct HiSysEventParam params[] = {
64         { .name = { "ORG_PKG" },
65             .t = HISYSEVENT_STRING,
66             .v = { .s = const_cast<char *>(ORG_PKG) },
67             .arraySize = 0 },
68         { .name = { "FUNC" },
69             .t = HISYSEVENT_STRING,
70             .v = { .s = const_cast<char *>(func.c_str()) },
71             .arraySize = 0 },
72         { .name = { "BIZ_SCENE" },
73             .t = HISYSEVENT_INT32,
74             .v = { .i32 = scene },
75             .arraySize = 0 },
76         { .name = { "BIZ_STAGE" },
77             .t = HISYSEVENT_INT32,
78             .v = { .i32 = stage },
79             .arraySize = 0 },
80         { .name = { "STAGE_RES" },
81             .t = HISYSEVENT_INT32,
82             .v = { .i32 = stageRes },
83             .arraySize = 0 },
84         { .name = { "ERROR_CODE" },
85             .t = HISYSEVENT_INT32,
86             .v = { .i32 = stageRes },
87             .arraySize = 0 },
88         { .name = { "BIZ_STATE" },
89             .t = HISYSEVENT_INT32,
90             .v = { .i32 = state },
91             .arraySize = 0 }
92     };
93     OH_HiSysEvent_Write(
94         DOMAIN,
95         EVENT_NAME,
96         HISYSEVENT_BEHAVIOR,
97         params,
98         sizeof(params) / sizeof(params[0])
99     );
100 }
101 
ReportFail(const std::string & func,int32_t scene,int32_t stage,int32_t stageRes,int32_t errorCode)102 void RadarReporterAdapter::ReportFail(
103     const std::string &func, int32_t scene, int32_t stage, int32_t stageRes, int32_t errorCode)
104 {
105     struct HiSysEventParam params[] = {
106         { .name = { "ORG_PKG" },
107             .t = HISYSEVENT_STRING,
108             .v = { .s = const_cast<char *>(ORG_PKG) },
109             .arraySize = 0 },
110         { .name = { "FUNC" },
111             .t = HISYSEVENT_STRING,
112             .v = { .s = const_cast<char *>(func.c_str()) },
113             .arraySize = 0 },
114         { .name = { "BIZ_SCENE" },
115             .t = HISYSEVENT_INT32,
116             .v = { .i32 = scene },
117             .arraySize = 0 },
118         { .name = { "BIZ_STAGE" },
119             .t = HISYSEVENT_INT32,
120             .v = { .i32 = stage },
121             .arraySize = 0 },
122         { .name = { "STAGE_RES" },
123             .t = HISYSEVENT_INT32,
124             .v = { .i32 = stageRes },
125             .arraySize = 0 },
126         { .name = { "ERROR_CODE" },
127             .t = HISYSEVENT_INT32,
128             .v = { .i32 = errorCode },
129             .arraySize = 0 }
130     };
131     OH_HiSysEvent_Write(
132         DOMAIN,
133         EVENT_NAME,
134         HISYSEVENT_BEHAVIOR,
135         params,
136         sizeof(params) / sizeof(params[0])
137     );
138 }
139 }
140 }
141