• 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 "daudio_radar.h"
17 
18 #include "hisysevent.h"
19 #include "daudio_errorcode.h"
20 #include "daudio_log.h"
21 
22 #undef DH_LOG_TAG
23 #define DH_LOG_TAG "DAudioRadar"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 IMPLEMENT_SINGLE_INSTANCE(DaudioRadar);
28 
ReportDaudioInit(const std::string & func,AudioInit bizStage,BizState bizState,int32_t errCode)29 bool DaudioRadar::ReportDaudioInit(const std::string& func, AudioInit bizStage, BizState bizState, int32_t errCode)
30 {
31     int32_t res = DH_SUCCESS;
32     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
33     if (stageRes == StageRes::STAGE_SUCC) {
34         res = HiSysEventWrite(
35             DISTRIBUTED_AUDIO,
36             DISTRIBUTED_AUDIO_BEHAVIOR,
37             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
38             ORG_PKG, ORG_PKG_NAME,
39             FUNC, func,
40             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_INIT),
41             BIZ_STAGE, static_cast<int32_t>(bizStage),
42             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
43             BIZ_STATE, static_cast<int32_t>(bizState));
44     } else {
45         res = HiSysEventWrite(
46             DISTRIBUTED_AUDIO,
47             DISTRIBUTED_AUDIO_BEHAVIOR,
48             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
49             ORG_PKG, ORG_PKG_NAME,
50             FUNC, func,
51             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_INIT),
52             BIZ_STAGE, static_cast<int32_t>(bizStage),
53             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
54             BIZ_STATE, static_cast<int32_t>(bizState),
55             ERROR_CODE, errCode);
56     }
57     if (res != DH_SUCCESS) {
58         DHLOGE("ReportDaudioInit error, res:%{public}d", res);
59         return false;
60     }
61     return true;
62 }
63 
ReportDaudioInitProgress(const std::string & func,AudioInit bizStage,int32_t errCode)64 bool DaudioRadar::ReportDaudioInitProgress(const std::string& func, AudioInit bizStage, int32_t errCode)
65 {
66     int32_t res = DH_SUCCESS;
67     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
68     if (stageRes == StageRes::STAGE_SUCC) {
69         res = HiSysEventWrite(
70             DISTRIBUTED_AUDIO,
71             DISTRIBUTED_AUDIO_BEHAVIOR,
72             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
73             ORG_PKG, ORG_PKG_NAME,
74             FUNC, func,
75             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_INIT),
76             BIZ_STAGE, static_cast<int32_t>(bizStage),
77             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
78     } else {
79         res = HiSysEventWrite(
80             DISTRIBUTED_AUDIO,
81             DISTRIBUTED_AUDIO_BEHAVIOR,
82             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
83             ORG_PKG, ORG_PKG_NAME,
84             FUNC, func,
85             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_INIT),
86             BIZ_STAGE, static_cast<int32_t>(bizStage),
87             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
88             ERROR_CODE, errCode);
89     }
90     if (res != DH_SUCCESS) {
91         DHLOGE("ReportDaudioInitProgress error, res:%{public}d", res);
92         return false;
93     }
94     return true;
95 }
96 
ReportSpeakerOpen(const std::string & func,SpeakerOpen bizStage,BizState bizState,int32_t errCode)97 bool DaudioRadar::ReportSpeakerOpen(const std::string& func, SpeakerOpen bizStage,
98     BizState bizState, int32_t errCode)
99 {
100     int32_t res = DH_SUCCESS;
101     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
102     if (stageRes == StageRes::STAGE_SUCC) {
103         res = HiSysEventWrite(
104             DISTRIBUTED_AUDIO,
105             DISTRIBUTED_AUDIO_BEHAVIOR,
106             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
107             ORG_PKG, ORG_PKG_NAME,
108             FUNC, func,
109             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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_AUDIO,
116             DISTRIBUTED_AUDIO_BEHAVIOR,
117             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
118             ORG_PKG, ORG_PKG_NAME,
119             FUNC, func,
120             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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 != DH_SUCCESS) {
127         DHLOGE("ReportSpeakerOpen error, res:%{public}d", res);
128         return false;
129     }
130     return true;
131 }
132 
ReportSpeakerOpenProgress(const std::string & func,SpeakerOpen bizStage,int32_t errCode)133 bool DaudioRadar::ReportSpeakerOpenProgress(const std::string& func, SpeakerOpen bizStage, int32_t errCode)
134 {
135     int32_t res = DH_SUCCESS;
136     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
137     if (stageRes == StageRes::STAGE_SUCC) {
138         res = HiSysEventWrite(
139             DISTRIBUTED_AUDIO,
140             DISTRIBUTED_AUDIO_BEHAVIOR,
141             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
142             ORG_PKG, ORG_PKG_NAME,
143             FUNC, func,
144             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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_AUDIO,
150             DISTRIBUTED_AUDIO_BEHAVIOR,
151             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
152             ORG_PKG, ORG_PKG_NAME,
153             FUNC, func,
154             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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 != DH_SUCCESS) {
160         DHLOGE("ReportSpeakerOpenProgress error, res:%{public}d", res);
161         return false;
162     }
163     return true;
164 }
165 
ReportSpeakerClose(const std::string & func,SpeakerClose bizStage,BizState bizState,int32_t errCode)166 bool DaudioRadar::ReportSpeakerClose(const std::string& func, SpeakerClose bizStage,
167     BizState bizState, int32_t errCode)
168 {
169     int32_t res = DH_SUCCESS;
170     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
171     if (stageRes == StageRes::STAGE_SUCC) {
172         res = HiSysEventWrite(
173             DISTRIBUTED_AUDIO,
174             DISTRIBUTED_AUDIO_BEHAVIOR,
175             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
176             ORG_PKG, ORG_PKG_NAME,
177             FUNC, func,
178             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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_AUDIO,
185             DISTRIBUTED_AUDIO_BEHAVIOR,
186             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
187             ORG_PKG, ORG_PKG_NAME,
188             FUNC, func,
189             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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 != DH_SUCCESS) {
196         DHLOGE("ReportSpeakerClose error, res:%{public}d", res);
197         return false;
198     }
199     return true;
200 }
201 
ReportSpeakerCloseProgress(const std::string & func,SpeakerClose bizStage,int32_t errCode)202 bool DaudioRadar::ReportSpeakerCloseProgress(const std::string& func, SpeakerClose bizStage, int32_t errCode)
203 {
204     int32_t res = DH_SUCCESS;
205     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
206     if (stageRes == StageRes::STAGE_SUCC) {
207         res = HiSysEventWrite(
208             DISTRIBUTED_AUDIO,
209             DISTRIBUTED_AUDIO_BEHAVIOR,
210             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
211             ORG_PKG, ORG_PKG_NAME,
212             FUNC, func,
213             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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_AUDIO,
219             DISTRIBUTED_AUDIO_BEHAVIOR,
220             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
221             ORG_PKG, ORG_PKG_NAME,
222             FUNC, func,
223             BIZ_SCENE, static_cast<int32_t>(BizScene::SPEAKER_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 != DH_SUCCESS) {
229         DHLOGE("ReportSpeakerCloseProgress error, res:%{public}d", res);
230         return false;
231     }
232     return true;
233 }
234 
ReportMicOpen(const std::string & func,MicOpen bizStage,BizState bizState,int32_t errCode)235 bool DaudioRadar::ReportMicOpen(const std::string& func, MicOpen bizStage,
236     BizState bizState, int32_t errCode)
237 {
238     int32_t res = DH_SUCCESS;
239     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
240     if (stageRes == StageRes::STAGE_SUCC) {
241         res = HiSysEventWrite(
242             DISTRIBUTED_AUDIO,
243             DISTRIBUTED_AUDIO_BEHAVIOR,
244             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
245             ORG_PKG, ORG_PKG_NAME,
246             FUNC, func,
247             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_OPEN),
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_AUDIO,
254             DISTRIBUTED_AUDIO_BEHAVIOR,
255             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
256             ORG_PKG, ORG_PKG_NAME,
257             FUNC, func,
258             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_OPEN),
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 != DH_SUCCESS) {
265         DHLOGE("ReportMicOpen error, res:%{public}d", res);
266         return false;
267     }
268     return true;
269 }
270 
ReportMicOpenProgress(const std::string & func,MicOpen bizStage,int32_t errCode)271 bool DaudioRadar::ReportMicOpenProgress(const std::string& func, MicOpen bizStage, int32_t errCode)
272 {
273     int32_t res = DH_SUCCESS;
274     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
275     if (stageRes == StageRes::STAGE_SUCC) {
276         res = HiSysEventWrite(
277             DISTRIBUTED_AUDIO,
278             DISTRIBUTED_AUDIO_BEHAVIOR,
279             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
280             ORG_PKG, ORG_PKG_NAME,
281             FUNC, func,
282             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_OPEN),
283             BIZ_STAGE, static_cast<int32_t>(bizStage),
284             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
285     } else {
286         res = HiSysEventWrite(
287             DISTRIBUTED_AUDIO,
288             DISTRIBUTED_AUDIO_BEHAVIOR,
289             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
290             ORG_PKG, ORG_PKG_NAME,
291             FUNC, func,
292             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_OPEN),
293             BIZ_STAGE, static_cast<int32_t>(bizStage),
294             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
295             ERROR_CODE, errCode);
296     }
297     if (res != DH_SUCCESS) {
298         DHLOGE("ReportMicOpenProgress error, res:%{public}d", res);
299         return false;
300     }
301     return true;
302 }
303 
ReportMicClose(const std::string & func,MicClose bizStage,BizState bizState,int32_t errCode)304 bool DaudioRadar::ReportMicClose(const std::string& func, MicClose bizStage,
305     BizState bizState, int32_t errCode)
306 {
307     int32_t res = DH_SUCCESS;
308     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
309     if (stageRes == StageRes::STAGE_SUCC) {
310         res = HiSysEventWrite(
311             DISTRIBUTED_AUDIO,
312             DISTRIBUTED_AUDIO_BEHAVIOR,
313             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
314             ORG_PKG, ORG_PKG_NAME,
315             FUNC, func,
316             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_CLOSE),
317             BIZ_STAGE, static_cast<int32_t>(bizStage),
318             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
319             BIZ_STATE, static_cast<int32_t>(bizState));
320     } else {
321         res = HiSysEventWrite(
322             DISTRIBUTED_AUDIO,
323             DISTRIBUTED_AUDIO_BEHAVIOR,
324             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
325             ORG_PKG, ORG_PKG_NAME,
326             FUNC, func,
327             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_CLOSE),
328             BIZ_STAGE, static_cast<int32_t>(bizStage),
329             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
330             BIZ_STATE, static_cast<int32_t>(bizState),
331             ERROR_CODE, errCode);
332     }
333     if (res != DH_SUCCESS) {
334         DHLOGE("ReportMicClose error, res:%{public}d", res);
335         return false;
336     }
337     return true;
338 }
339 
ReportMicCloseProgress(const std::string & func,MicClose bizStage,int32_t errCode)340 bool DaudioRadar::ReportMicCloseProgress(const std::string& func, MicClose bizStage, int32_t errCode)
341 {
342     int32_t res = DH_SUCCESS;
343     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
344     if (stageRes == StageRes::STAGE_SUCC) {
345         res = HiSysEventWrite(
346             DISTRIBUTED_AUDIO,
347             DISTRIBUTED_AUDIO_BEHAVIOR,
348             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
349             ORG_PKG, ORG_PKG_NAME,
350             FUNC, func,
351             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_CLOSE),
352             BIZ_STAGE, static_cast<int32_t>(bizStage),
353             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
354     } else {
355         res = HiSysEventWrite(
356             DISTRIBUTED_AUDIO,
357             DISTRIBUTED_AUDIO_BEHAVIOR,
358             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
359             ORG_PKG, ORG_PKG_NAME,
360             FUNC, func,
361             BIZ_SCENE, static_cast<int32_t>(BizScene::MIC_CLOSE),
362             BIZ_STAGE, static_cast<int32_t>(bizStage),
363             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
364             ERROR_CODE, errCode);
365     }
366     if (res != DH_SUCCESS) {
367         DHLOGE("ReportMicCloseProgress error, res:%{public}d", res);
368         return false;
369     }
370     return true;
371 }
372 
ReportDaudioUnInit(const std::string & func,AudioUnInit bizStage,BizState bizState,int32_t errCode)373 bool DaudioRadar::ReportDaudioUnInit(const std::string& func, AudioUnInit bizStage, BizState bizState,
374     int32_t errCode)
375 {
376     int32_t res = DH_SUCCESS;
377     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
378     if (stageRes == StageRes::STAGE_SUCC) {
379         res = HiSysEventWrite(
380             DISTRIBUTED_AUDIO,
381             DISTRIBUTED_AUDIO_BEHAVIOR,
382             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
383             ORG_PKG, ORG_PKG_NAME,
384             FUNC, func,
385             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_UNINIT),
386             BIZ_STAGE, static_cast<int32_t>(bizStage),
387             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
388             BIZ_STATE, static_cast<int32_t>(bizState));
389     } else {
390         res = HiSysEventWrite(
391             DISTRIBUTED_AUDIO,
392             DISTRIBUTED_AUDIO_BEHAVIOR,
393             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
394             ORG_PKG, ORG_PKG_NAME,
395             FUNC, func,
396             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_UNINIT),
397             BIZ_STAGE, static_cast<int32_t>(bizStage),
398             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
399             BIZ_STATE, static_cast<int32_t>(bizState),
400             ERROR_CODE, errCode);
401     }
402     if (res != DH_SUCCESS) {
403         DHLOGE("ReportDaudioUnInit error, res:%{public}d", res);
404         return false;
405     }
406     return true;
407 }
408 
ReportDaudioUnInitProgress(const std::string & func,AudioUnInit bizStage,int32_t errCode)409 bool DaudioRadar::ReportDaudioUnInitProgress(const std::string& func, AudioUnInit bizStage, int32_t errCode)
410 {
411     int32_t res = DH_SUCCESS;
412     StageRes stageRes = (errCode == DH_SUCCESS) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
413     if (stageRes == StageRes::STAGE_SUCC) {
414         res = HiSysEventWrite(
415             DISTRIBUTED_AUDIO,
416             DISTRIBUTED_AUDIO_BEHAVIOR,
417             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
418             ORG_PKG, ORG_PKG_NAME,
419             FUNC, func,
420             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_UNINIT),
421             BIZ_STAGE, static_cast<int32_t>(bizStage),
422             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
423     } else {
424         res = HiSysEventWrite(
425             DISTRIBUTED_AUDIO,
426             DISTRIBUTED_AUDIO_BEHAVIOR,
427             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
428             ORG_PKG, ORG_PKG_NAME,
429             FUNC, func,
430             BIZ_SCENE, static_cast<int32_t>(BizScene::AUDIO_UNINIT),
431             BIZ_STAGE, static_cast<int32_t>(bizStage),
432             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
433             ERROR_CODE, errCode);
434     }
435     if (res != DH_SUCCESS) {
436         DHLOGE("ReportDaudioUnInitProgress error, res:%{public}d", res);
437         return false;
438     }
439     return true;
440 }
441 } // namespace DistributedHardware
442 } // namespace OHOS