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 "dcamera_radar.h"
17
18 #include "hisysevent.h"
19 #include "securec.h"
20
21 #include "anonymous_string.h"
22 #include "dcamera_hisysevent_adapter.h"
23 #include "distributed_camera_errno.h"
24 #include "distributed_hardware_log.h"
25
26 namespace OHOS {
27 namespace DistributedHardware {
28 IMPLEMENT_SINGLE_INSTANCE(DcameraRadar);
29
ReportDcameraInit(const std::string & func,CameraInit bizStage,BizState bizState,int32_t errCode)30 bool DcameraRadar::ReportDcameraInit(const std::string& func, CameraInit bizStage, BizState bizState, int32_t errCode)
31 {
32 int32_t res = DCAMERA_OK;
33 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
34 if (stageRes == StageRes::STAGE_SUCC) {
35 res = HiSysEventWrite(
36 DISTRIBUTED_CAMERA,
37 DISTRIBUTED_CAMERA_BEHAVIOR,
38 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
39 ORG_PKG, ORG_PKG_NAME,
40 FUNC, func,
41 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_INIT),
42 BIZ_STAGE, static_cast<int32_t>(bizStage),
43 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
44 BIZ_STATE, static_cast<int32_t>(bizState));
45 } else {
46 res = HiSysEventWrite(
47 DISTRIBUTED_CAMERA,
48 DISTRIBUTED_CAMERA_BEHAVIOR,
49 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
50 ORG_PKG, ORG_PKG_NAME,
51 FUNC, func,
52 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_INIT),
53 BIZ_STAGE, static_cast<int32_t>(bizStage),
54 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
55 BIZ_STATE, static_cast<int32_t>(bizState),
56 ERROR_CODE, errCode);
57 }
58 if (res != DCAMERA_OK) {
59 DHLOGE("ReportDcameraInit error, res:%{public}d", res);
60 return false;
61 }
62 return true;
63 }
64
ReportDcameraInitProgress(const std::string & func,CameraInit bizStage,int32_t errCode)65 bool DcameraRadar::ReportDcameraInitProgress(const std::string& func, CameraInit bizStage, int32_t errCode)
66 {
67 int32_t res = DCAMERA_OK;
68 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
69 if (stageRes == StageRes::STAGE_SUCC) {
70 res = HiSysEventWrite(
71 DISTRIBUTED_CAMERA,
72 DISTRIBUTED_CAMERA_BEHAVIOR,
73 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
74 ORG_PKG, ORG_PKG_NAME,
75 FUNC, func,
76 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_INIT),
77 BIZ_STAGE, static_cast<int32_t>(bizStage),
78 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
79 } else {
80 res = HiSysEventWrite(
81 DISTRIBUTED_CAMERA,
82 DISTRIBUTED_CAMERA_BEHAVIOR,
83 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
84 ORG_PKG, ORG_PKG_NAME,
85 FUNC, func,
86 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_INIT),
87 BIZ_STAGE, static_cast<int32_t>(bizStage),
88 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
89 ERROR_CODE, errCode);
90 }
91 if (res != DCAMERA_OK) {
92 DHLOGE("ReportDcameraInitProgress error, res:%{public}d", res);
93 return false;
94 }
95 return true;
96 }
97
ReportDcameraOpen(const std::string & func,CameraOpen bizStage,BizState bizState,int32_t errCode)98 bool DcameraRadar::ReportDcameraOpen(const std::string& func, CameraOpen bizStage, BizState bizState, int32_t errCode)
99 {
100 int32_t res = DCAMERA_OK;
101 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
102 if (stageRes == StageRes::STAGE_SUCC) {
103 res = HiSysEventWrite(
104 DISTRIBUTED_CAMERA,
105 DISTRIBUTED_CAMERA_BEHAVIOR,
106 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
107 ORG_PKG, ORG_PKG_NAME,
108 FUNC, func,
109 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_OPEN),
110 BIZ_STAGE, static_cast<int32_t>(bizStage),
111 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
112 BIZ_STATE, static_cast<int32_t>(bizState));
113 } else {
114 res = HiSysEventWrite(
115 DISTRIBUTED_CAMERA,
116 DISTRIBUTED_CAMERA_BEHAVIOR,
117 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
118 ORG_PKG, ORG_PKG_NAME,
119 FUNC, func,
120 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_OPEN),
121 BIZ_STAGE, static_cast<int32_t>(bizStage),
122 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
123 BIZ_STATE, static_cast<int32_t>(bizState),
124 ERROR_CODE, errCode);
125 }
126 if (res != DCAMERA_OK) {
127 DHLOGE("ReportDcameraOpen error, res:%{public}d", res);
128 return false;
129 }
130 return true;
131 }
132
ReportDcameraOpenProgress(const std::string & func,CameraOpen bizStage,int32_t errCode)133 bool DcameraRadar::ReportDcameraOpenProgress(const std::string& func, CameraOpen bizStage, int32_t errCode)
134 {
135 int32_t res = DCAMERA_OK;
136 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
137 if (stageRes == StageRes::STAGE_SUCC) {
138 res = HiSysEventWrite(
139 DISTRIBUTED_CAMERA,
140 DISTRIBUTED_CAMERA_BEHAVIOR,
141 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
142 ORG_PKG, ORG_PKG_NAME,
143 FUNC, func,
144 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_OPEN),
145 BIZ_STAGE, static_cast<int32_t>(bizStage),
146 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
147 } else {
148 res = HiSysEventWrite(
149 DISTRIBUTED_CAMERA,
150 DISTRIBUTED_CAMERA_BEHAVIOR,
151 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
152 ORG_PKG, ORG_PKG_NAME,
153 FUNC, func,
154 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_OPEN),
155 BIZ_STAGE, static_cast<int32_t>(bizStage),
156 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
157 ERROR_CODE, errCode);
158 }
159 if (res != DCAMERA_OK) {
160 DHLOGE("ReportDcameraOpenProgress error, res:%{public}d", res);
161 return false;
162 }
163 return true;
164 }
165
ReportDcameraClose(const std::string & func,CameraClose bizStage,BizState bizState,int32_t errCode)166 bool DcameraRadar::ReportDcameraClose(const std::string& func, CameraClose bizStage, BizState bizState,
167 int32_t errCode)
168 {
169 int32_t res = DCAMERA_OK;
170 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
171 if (stageRes == StageRes::STAGE_SUCC) {
172 res = HiSysEventWrite(
173 DISTRIBUTED_CAMERA,
174 DISTRIBUTED_CAMERA_BEHAVIOR,
175 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
176 ORG_PKG, ORG_PKG_NAME,
177 FUNC, func,
178 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_CLOSE),
179 BIZ_STAGE, static_cast<int32_t>(bizStage),
180 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
181 BIZ_STATE, static_cast<int32_t>(bizState));
182 } else {
183 res = HiSysEventWrite(
184 DISTRIBUTED_CAMERA,
185 DISTRIBUTED_CAMERA_BEHAVIOR,
186 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
187 ORG_PKG, ORG_PKG_NAME,
188 FUNC, func,
189 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_CLOSE),
190 BIZ_STAGE, static_cast<int32_t>(bizStage),
191 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
192 BIZ_STATE, static_cast<int32_t>(bizState),
193 ERROR_CODE, errCode);
194 }
195 if (res != DCAMERA_OK) {
196 DHLOGE("ReportDcameraClose error, res:%{public}d", res);
197 return false;
198 }
199 return true;
200 }
201
ReportDcameraCloseProgress(const std::string & func,CameraClose bizStage,int32_t errCode)202 bool DcameraRadar::ReportDcameraCloseProgress(const std::string& func, CameraClose bizStage, int32_t errCode)
203 {
204 int32_t res = DCAMERA_OK;
205 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
206 if (stageRes == StageRes::STAGE_SUCC) {
207 res = HiSysEventWrite(
208 DISTRIBUTED_CAMERA,
209 DISTRIBUTED_CAMERA_BEHAVIOR,
210 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
211 ORG_PKG, ORG_PKG_NAME,
212 FUNC, func,
213 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_CLOSE),
214 BIZ_STAGE, static_cast<int32_t>(bizStage),
215 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
216 } else {
217 res = HiSysEventWrite(
218 DISTRIBUTED_CAMERA,
219 DISTRIBUTED_CAMERA_BEHAVIOR,
220 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
221 ORG_PKG, ORG_PKG_NAME,
222 FUNC, func,
223 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_CLOSE),
224 BIZ_STAGE, static_cast<int32_t>(bizStage),
225 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
226 ERROR_CODE, errCode);
227 }
228 if (res != DCAMERA_OK) {
229 DHLOGE("ReportDcameraCloseProgress error, res:%{public}d", res);
230 return false;
231 }
232 return true;
233 }
234
ReportDcameraUnInit(const std::string & func,CameraUnInit bizStage,BizState bizState,int32_t errCode)235 bool DcameraRadar::ReportDcameraUnInit(const std::string& func, CameraUnInit bizStage, BizState bizState,
236 int32_t errCode)
237 {
238 int32_t res = DCAMERA_OK;
239 StageRes stageRes = (errCode == DCAMERA_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
240 if (stageRes == StageRes::STAGE_SUCC) {
241 res = HiSysEventWrite(
242 DISTRIBUTED_CAMERA,
243 DISTRIBUTED_CAMERA_BEHAVIOR,
244 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
245 ORG_PKG, ORG_PKG_NAME,
246 FUNC, func,
247 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_UNINIT),
248 BIZ_STAGE, static_cast<int32_t>(bizStage),
249 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
250 BIZ_STATE, static_cast<int32_t>(bizState));
251 } else {
252 res = HiSysEventWrite(
253 DISTRIBUTED_CAMERA,
254 DISTRIBUTED_CAMERA_BEHAVIOR,
255 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
256 ORG_PKG, ORG_PKG_NAME,
257 FUNC, func,
258 BIZ_SCENE, static_cast<int32_t>(BizScene::CAMERA_UNINIT),
259 BIZ_STAGE, static_cast<int32_t>(bizStage),
260 STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
261 BIZ_STATE, static_cast<int32_t>(bizState),
262 ERROR_CODE, errCode);
263 }
264 if (res != DCAMERA_OK) {
265 DHLOGE("ReportDcameraUnInit error, res:%{public}d", res);
266 return false;
267 }
268 return true;
269 }
270 } // namespace DistributedHardware
271 } // namespace OHOS