• 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 #include <string>
16 #include <thread>
17 #include <chrono>
18 #include <cstdio>
19 #include <fstream>
20 #include <streambuf>
21 #include <algorithm>
22 #include <unistd.h>
23 #include "audio_errors.h"
24 #include "hpae_manager_impl.h"
25 #include "audio_info.h"
26 #include "../fuzz_utils.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 using namespace std;
31 using namespace OHOS::AudioStandard::HPAE;
32 
33 FuzzUtils &g_fuzzUtils = FuzzUtils::GetInstance();
34 const size_t FUZZ_INPUT_SIZE_THRESHOLD = 10;
35 constexpr int32_t FRAME_LENGTH = 882;
36 constexpr int32_t TEST_STREAM_SESSION_ID = 123456;
37 static std::string g_rootPath = "/data/";
38 std::shared_ptr<HpaeManagerImpl> hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
39 
40 typedef void (*TestFuncs)();
41 
42 vector<HpaeStreamClassType> HpaeStreamClassTypeVec = {
43     HPAE_STREAM_CLASS_TYPE_INVALID,
44     HPAE_STREAM_CLASS_TYPE_PLAY,
45     HPAE_STREAM_CLASS_TYPE_RECORD,
46 };
47 
48 vector<AudioSpatialDeviceType> AudioSpatialDeviceTypeVec = {
49     EARPHONE_TYPE_NONE,
50     EARPHONE_TYPE_INEAR,
51     EARPHONE_TYPE_HALF_INEAR,
52     EARPHONE_TYPE_HEADPHONE,
53     EARPHONE_TYPE_GLASSES,
54     EARPHONE_TYPE_OTHERS,
55 };
56 
57 vector<AudioSpatializationSceneType> AudioSpatializationSceneTypeVec {
58     SPATIALIZATION_SCENE_TYPE_DEFAULT,
59     SPATIALIZATION_SCENE_TYPE_MUSIC,
60     SPATIALIZATION_SCENE_TYPE_MOVIE,
61     SPATIALIZATION_SCENE_TYPE_AUDIOBOOK,
62     SPATIALIZATION_SCENE_TYPE_MAX,
63 };
64 
65 vector<SourceType> SourceTypeVec =  {
66     SOURCE_TYPE_INVALID,
67     SOURCE_TYPE_MIC,
68     SOURCE_TYPE_VOICE_RECOGNITION,
69     SOURCE_TYPE_PLAYBACK_CAPTURE,
70     SOURCE_TYPE_WAKEUP,
71     SOURCE_TYPE_VOICE_CALL,
72     SOURCE_TYPE_VOICE_COMMUNICATION,
73     SOURCE_TYPE_ULTRASONIC,
74     SOURCE_TYPE_VIRTUAL_CAPTURE,
75     SOURCE_TYPE_VOICE_MESSAGE,
76     SOURCE_TYPE_REMOTE_CAST,
77     SOURCE_TYPE_VOICE_TRANSCRIPTION,
78     SOURCE_TYPE_CAMCORDER,
79     SOURCE_TYPE_UNPROCESSED,
80     SOURCE_TYPE_EC,
81     SOURCE_TYPE_MIC_REF,
82     SOURCE_TYPE_LIVE,
83     SOURCE_TYPE_MAX
84 };
85 
86 vector<DeviceType> DeviceTypeVec = {
87     DEVICE_TYPE_NONE,
88     DEVICE_TYPE_INVALID,
89     DEVICE_TYPE_EARPIECE,
90     DEVICE_TYPE_SPEAKER,
91     DEVICE_TYPE_WIRED_HEADSET,
92     DEVICE_TYPE_WIRED_HEADPHONES,
93     DEVICE_TYPE_BLUETOOTH_SCO,
94     DEVICE_TYPE_BLUETOOTH_A2DP,
95     DEVICE_TYPE_BLUETOOTH_A2DP_IN,
96     DEVICE_TYPE_MIC,
97     DEVICE_TYPE_WAKEUP,
98     DEVICE_TYPE_USB_HEADSET,
99     DEVICE_TYPE_DP,
100     DEVICE_TYPE_REMOTE_CAST,
101     DEVICE_TYPE_USB_DEVICE,
102     DEVICE_TYPE_ACCESSORY,
103     DEVICE_TYPE_REMOTE_DAUDIO,
104     DEVICE_TYPE_HDMI,
105     DEVICE_TYPE_LINE_DIGITAL,
106     DEVICE_TYPE_NEARLINK,
107     DEVICE_TYPE_NEARLINK_IN,
108     DEVICE_TYPE_FILE_SINK,
109     DEVICE_TYPE_FILE_SOURCE,
110     DEVICE_TYPE_EXTERN_CABLE,
111     DEVICE_TYPE_DEFAULT,
112     DEVICE_TYPE_USB_ARM_HEADSET,
113     DEVICE_TYPE_MAX,
114 };
115 
Init()116 bool Init()
117 {
118     if (hpaeManagerImpl_ == nullptr) {
119         return false;
120     }
121     hpaeManagerImpl_->manager_ = std::make_shared<HpaeManager>();
122     if (hpaeManagerImpl_->manager_ == nullptr) {
123         return false;
124     }
125     return true;
126 }
127 
GetSinkAudioModeInfo(std::string name="Speaker_File")128 AudioModuleInfo GetSinkAudioModeInfo(std::string name = "Speaker_File")
129 {
130     AudioModuleInfo audioModuleInfo;
131     audioModuleInfo.lib = "libmodule-hdi-sink.z.so";
132     audioModuleInfo.channels = "2";
133     audioModuleInfo.rate = "48000";
134     audioModuleInfo.name = name;
135     audioModuleInfo.adapterName = "file_io";
136     audioModuleInfo.className = "file_io";
137     audioModuleInfo.bufferSize = "7680";
138     audioModuleInfo.format = "s32le";
139     audioModuleInfo.fixedLatency = "1";
140     audioModuleInfo.offloadEnable = "0";
141     audioModuleInfo.networkId = "LocalDevice";
142     audioModuleInfo.fileName = g_rootPath + audioModuleInfo.adapterName + "_" + audioModuleInfo.rate + "_" +
143                                audioModuleInfo.channels + "_" + audioModuleInfo.format + ".pcm";
144     std::stringstream typeValue;
145     typeValue << static_cast<int32_t>(DEVICE_TYPE_SPEAKER);
146     audioModuleInfo.deviceType = typeValue.str();
147     return audioModuleInfo;
148 }
149 
GetRenderStreamInfo()150 HPAE::HpaeStreamInfo GetRenderStreamInfo()
151 {
152     HPAE::HpaeStreamInfo streamInfo;
153     streamInfo.channels = STEREO;
154     streamInfo.samplingRate = SAMPLE_RATE_44100;
155     streamInfo.format = SAMPLE_S16LE;
156     streamInfo.frameLen = FRAME_LENGTH;
157     streamInfo.sessionId = TEST_STREAM_SESSION_ID;
158     streamInfo.streamType = STREAM_MUSIC;
159     streamInfo.streamClassType = HPAE::HPAE_STREAM_CLASS_TYPE_PLAY;
160     return streamInfo;
161 }
162 
DeInitFuzzTest()163 void DeInitFuzzTest()
164 {
165     if (!Init() || hpaeManagerImpl_ == nullptr) {
166         return;
167     }
168     hpaeManagerImpl_->DeInit();
169 }
170 
DumpSinkInfoFuzzTest()171 void DumpSinkInfoFuzzTest()
172 {
173     if (!Init() || hpaeManagerImpl_ == nullptr) {
174         return;
175     }
176     std::string deviceName = "test_device";
177     hpaeManagerImpl_->DumpSinkInfo(deviceName);
178 }
179 
DumpSourceInfoFuzzTest()180 void DumpSourceInfoFuzzTest()
181 {
182     if (!Init() || hpaeManagerImpl_ == nullptr) {
183         return;
184     }
185     std::string deviceName = "test_device";
186     hpaeManagerImpl_->DumpSourceInfo(deviceName);
187 }
188 
DumpSinkInputsInfoFuzzTest()189 void DumpSinkInputsInfoFuzzTest()
190 {
191     if (!Init() || hpaeManagerImpl_ == nullptr) {
192         return;
193     }
194     hpaeManagerImpl_->DumpSinkInputsInfo();
195     hpaeManagerImpl_->DumpSourceOutputsInfo();
196 }
197 
ReloadAudioPortFuzzTest()198 void ReloadAudioPortFuzzTest()
199 {
200     if (!Init() || hpaeManagerImpl_ == nullptr) {
201         return;
202     }
203     AudioModuleInfo audioModuleInfo = GetSinkAudioModeInfo();
204     hpaeManagerImpl_->ReloadAudioPort(audioModuleInfo);
205 }
206 
CloseAudioPortFuzzTest()207 void CloseAudioPortFuzzTest()
208 {
209     if (!Init() || hpaeManagerImpl_ == nullptr) {
210         return;
211     }
212     int32_t audioHandleIndex = g_fuzzUtils.GetData<int32_t>();
213     hpaeManagerImpl_->CloseAudioPort(audioHandleIndex);
214 }
215 
GetSinkInfoByIdxFuzzTest()216 void GetSinkInfoByIdxFuzzTest()
217 {
218     if (!Init() || hpaeManagerImpl_ == nullptr) {
219         return;
220     }
221     HpaeSinkInfo sinkInfo;
222     HpaeSourceInfo sourceInfo;
223     int32_t ret = -1;
224     hpaeManagerImpl_->GetSinkInfoByIdx(0, [&sinkInfo, &ret](const HpaeSinkInfo &sinkInfoRet, int32_t result) {
225         sinkInfo = sinkInfoRet;
226         ret = result;
227     });
228     ret = -1;
229     hpaeManagerImpl_->GetSourceInfoByIdx(0, [&sourceInfo, &ret](const HpaeSourceInfo &sourceInfoRet, int32_t result) {
230         sourceInfo  = sourceInfoRet;
231         ret = result;
232     });
233 }
234 
HandleMsgFuzzTest()235 void HandleMsgFuzzTest()
236 {
237     if (!Init() || hpaeManagerImpl_ == nullptr) {
238         return;
239     }
240     hpaeManagerImpl_->HandleMsg();
241 }
242 
IsInitFuzzTest()243 void IsInitFuzzTest()
244 {
245     if (!Init() || hpaeManagerImpl_ == nullptr) {
246         return;
247     }
248     hpaeManagerImpl_->IsInit();
249 }
250 
IsRunningFuzzTest()251 void IsRunningFuzzTest()
252 {
253     if (!Init() || hpaeManagerImpl_ == nullptr) {
254         return;
255     }
256     hpaeManagerImpl_->IsRunning();
257 }
258 
IsMsgProcessingFuzzTest()259 void IsMsgProcessingFuzzTest()
260 {
261     if (!Init() || hpaeManagerImpl_ == nullptr) {
262         return;
263     }
264     hpaeManagerImpl_->IsMsgProcessing();
265 }
266 
SetSourceOutputMuteFuzzTest()267 void SetSourceOutputMuteFuzzTest()
268 {
269     if (!Init() || hpaeManagerImpl_ == nullptr) {
270         return;
271     }
272     int32_t uid = g_fuzzUtils.GetData<int32_t>();
273     bool setMute = g_fuzzUtils.GetData<bool>();
274     hpaeManagerImpl_->SetSourceOutputMute(uid, setMute);
275 }
276 
StartWithSyncIdFuzzTest()277 void StartWithSyncIdFuzzTest()
278 {
279     if (!Init() || hpaeManagerImpl_ == nullptr) {
280         return;
281     }
282     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % HpaeStreamClassTypeVec.size();
283     HpaeStreamClassType streamClassType = HpaeStreamClassTypeVec[index];
284     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
285     int32_t syncId = g_fuzzUtils.GetData<int32_t>();
286     hpaeManagerImpl_->StartWithSyncId(streamClassType, sessionId, syncId);
287 }
288 
ReleaseFuzzTest()289 void ReleaseFuzzTest()
290 {
291     if (!Init() || hpaeManagerImpl_ == nullptr) {
292         return;
293     }
294     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % HpaeStreamClassTypeVec.size();
295     HpaeStreamClassType streamClassType = HpaeStreamClassTypeVec[index];
296     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
297     hpaeManagerImpl_->Release(streamClassType, sessionId);
298 }
299 
GetSourceOutputInfoFuzzTest()300 void GetSourceOutputInfoFuzzTest()
301 {
302     if (!Init() || hpaeManagerImpl_ == nullptr) {
303         return;
304     }
305     HpaeStreamInfo streamInfo = GetRenderStreamInfo();
306     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
307     hpaeManagerImpl_->GetSourceOutputInfo(sessionId, streamInfo);
308 }
309 
SetRateFuzzTest()310 void SetRateFuzzTest()
311 {
312     if (!Init() || hpaeManagerImpl_ == nullptr) {
313         return;
314     }
315     int32_t rate = g_fuzzUtils.GetData<int32_t>();
316     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
317     hpaeManagerImpl_->SetRate(sessionId, rate);
318 }
319 
GetAudioEffectModeFuzzTest()320 void GetAudioEffectModeFuzzTest()
321 {
322     if (!Init() || hpaeManagerImpl_ == nullptr) {
323         return;
324     }
325     int32_t effectMode = g_fuzzUtils.GetData<int32_t>();
326     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
327     hpaeManagerImpl_->SetAudioEffectMode(sessionId, effectMode);
328     hpaeManagerImpl_->GetAudioEffectMode(sessionId, effectMode);
329 }
330 
SetPrivacyTypeFuzzTest()331 void SetPrivacyTypeFuzzTest()
332 {
333     if (!Init() || hpaeManagerImpl_ == nullptr) {
334         return;
335     }
336     int32_t privacyType = g_fuzzUtils.GetData<int32_t>();
337     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
338     hpaeManagerImpl_->SetPrivacyType(sessionId, privacyType);
339     hpaeManagerImpl_->GetPrivacyType(sessionId, privacyType);
340 }
341 
GetWritableSizeFuzzTest()342 void GetWritableSizeFuzzTest()
343 {
344     if (!Init() || hpaeManagerImpl_ == nullptr) {
345         return;
346     }
347     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
348     hpaeManagerImpl_->GetWritableSize(sessionId);
349 }
350 
UpdateSpatializationStateFuzzTest()351 void UpdateSpatializationStateFuzzTest()
352 {
353     if (!Init() || hpaeManagerImpl_ == nullptr) {
354         return;
355     }
356     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
357     bool spatializationEnabled = g_fuzzUtils.GetData<bool>();
358     bool headTrackingEnabled = g_fuzzUtils.GetData<bool>();
359     hpaeManagerImpl_->UpdateSpatializationState(sessionId, spatializationEnabled, headTrackingEnabled);
360 }
361 
UpdateMaxLengthFuzzTest()362 void UpdateMaxLengthFuzzTest()
363 {
364     if (!Init() || hpaeManagerImpl_ == nullptr) {
365         return;
366     }
367     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
368     uint32_t maxLength = g_fuzzUtils.GetData<uint32_t>();
369     hpaeManagerImpl_->UpdateMaxLength(sessionId, maxLength);
370 }
371 
SetOffloadRenderCallbackTypeFuzzTest()372 void SetOffloadRenderCallbackTypeFuzzTest()
373 {
374     if (!Init() || hpaeManagerImpl_ == nullptr) {
375         return;
376     }
377     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
378     int32_t type = g_fuzzUtils.GetData<int32_t>();
379     hpaeManagerImpl_->SetOffloadRenderCallbackType(sessionId, type);
380 }
381 
SetSpeedFuzzTest()382 void SetSpeedFuzzTest()
383 {
384     if (!Init() || hpaeManagerImpl_ == nullptr) {
385         return;
386     }
387     uint32_t sessionId = g_fuzzUtils.GetData<uint32_t>();
388     float speed = g_fuzzUtils.GetData<float>();
389     hpaeManagerImpl_->SetSpeed(sessionId, speed);
390 }
391 
SetOutputDeviceSinkFuzzTest()392 void SetOutputDeviceSinkFuzzTest()
393 {
394     if (!Init() || hpaeManagerImpl_ == nullptr) {
395         return;
396     }
397     int32_t device = g_fuzzUtils.GetData<int32_t>();
398     const std::string sinkName = "test_sink";
399     hpaeManagerImpl_->SetOutputDeviceSink(device, sinkName);
400 }
401 
UpdateSpatializationStateFuzzTest2()402 void UpdateSpatializationStateFuzzTest2()
403 {
404     if (!Init() || hpaeManagerImpl_ == nullptr) {
405         return;
406     }
407     AudioSpatializationState stateInfo;
408     stateInfo.headTrackingEnabled = g_fuzzUtils.GetData<bool>();
409     stateInfo.spatializationEnabled = g_fuzzUtils.GetData<bool>();
410     hpaeManagerImpl_->UpdateSpatializationState(stateInfo);
411 }
412 
UpdateSpatialDeviceTypeFuzzTest()413 void UpdateSpatialDeviceTypeFuzzTest()
414 {
415     if (!Init() || hpaeManagerImpl_ == nullptr) {
416         return;
417     }
418     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % AudioSpatialDeviceTypeVec.size();
419     AudioSpatialDeviceType audioSpatialDeviceType = AudioSpatialDeviceTypeVec[index];
420     hpaeManagerImpl_->UpdateSpatialDeviceType(audioSpatialDeviceType);
421 }
422 
SetSpatializationSceneTypeFuzzTest()423 void SetSpatializationSceneTypeFuzzTest()
424 {
425     if (!Init() || hpaeManagerImpl_ == nullptr) {
426         return;
427     }
428     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % AudioSpatializationSceneTypeVec.size();
429     AudioSpatializationSceneType audioSpatializationSceneType = AudioSpatializationSceneTypeVec[index];
430     hpaeManagerImpl_->SetSpatializationSceneType(audioSpatializationSceneType);
431 }
432 
EffectRotationUpdateFuzzTest()433 void EffectRotationUpdateFuzzTest()
434 {
435     if (!Init() || hpaeManagerImpl_ == nullptr) {
436         return;
437     }
438     uint32_t rotationState = g_fuzzUtils.GetData<uint32_t>();
439     hpaeManagerImpl_->EffectRotationUpdate(rotationState);
440 }
441 
SetEffectSystemVolumeFuzzTest()442 void SetEffectSystemVolumeFuzzTest()
443 {
444     if (!Init() || hpaeManagerImpl_ == nullptr) {
445         return;
446     }
447     int32_t systemVolumeType = g_fuzzUtils.GetData<int32_t>();
448     float systemVolume = g_fuzzUtils.GetData<float>();
449     hpaeManagerImpl_->SetEffectSystemVolume(systemVolumeType, systemVolume);
450 }
451 
SetAbsVolumeStateToEffectFuzzTest()452 void SetAbsVolumeStateToEffectFuzzTest()
453 {
454     if (!Init() || hpaeManagerImpl_ == nullptr) {
455         return;
456     }
457     bool absVolumeState = g_fuzzUtils.GetData<bool>();
458     hpaeManagerImpl_->SetAbsVolumeStateToEffect(absVolumeState);
459 }
460 
SetAudioEffectPropertyFuzzTest()461 void SetAudioEffectPropertyFuzzTest()
462 {
463     if (!Init() || hpaeManagerImpl_ == nullptr) {
464         return;
465     }
466     AudioEffectPropertyArrayV3 propertyArrayV3;
467     AudioEffectPropertyArray propertyArray;
468     hpaeManagerImpl_->SetAudioEffectProperty(propertyArrayV3);
469     hpaeManagerImpl_->SetAudioEffectProperty(propertyArray);
470 }
471 
SetOutputDeviceFuzzTest()472 void SetOutputDeviceFuzzTest()
473 {
474     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
475     if (hpaeManagerImpl_ == nullptr) {
476         return;
477     }
478     uint32_t renderId = g_fuzzUtils.GetData<uint32_t>();
479     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % DeviceTypeVec.size();
480     DeviceType outputDevice = DeviceTypeVec[index];
481     hpaeManagerImpl_->SetOutputDevice(renderId, outputDevice);
482 }
483 
SetVolumeInfoFuzzTest()484 void SetVolumeInfoFuzzTest()
485 {
486     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
487     if (hpaeManagerImpl_ == nullptr) {
488         return;
489     }
490     std::vector<AudioVolumeType> validVolumeTypes;
491     for (int32_t type = static_cast<int32_t>(AudioStreamType::STREAM_DEFAULT);
492          type <= static_cast<int32_t>(AudioStreamType::STREAM_APP);
493          ++type) {
494         validVolumeTypes.push_back(static_cast<AudioVolumeType>(type));
495     }
496     uint32_t typeIndex = g_fuzzUtils.GetData<uint32_t>() % validVolumeTypes.size();
497     AudioVolumeType volumeType = validVolumeTypes[typeIndex];
498     float systemVol = g_fuzzUtils.GetData<float>();
499     systemVol = std::clamp(systemVol, 0.0f, 1.0f);
500     hpaeManagerImpl_->SetVolumeInfo(volumeType, systemVol);
501 }
502 
SetMicrophoneMuteInfoFuzzTest()503 void SetMicrophoneMuteInfoFuzzTest()
504 {
505     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
506     if (hpaeManagerImpl_ == nullptr) {
507         return;
508     }
509     bool isMute = g_fuzzUtils.GetData<bool>();
510     hpaeManagerImpl_->SetMicrophoneMuteInfo(isMute);
511 }
512 
SetAudioEnhancePropertyFuzzTest()513 void SetAudioEnhancePropertyFuzzTest()
514 {
515     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
516     if (hpaeManagerImpl_ == nullptr) {
517         return;
518     }
519     AudioEffectPropertyArrayV3 propertyArrayV3;
520     AudioEnhancePropertyArray propertyArray;
521     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % DeviceTypeVec.size();
522     DeviceType outputDevice = DeviceTypeVec[index];
523     hpaeManagerImpl_->SetAudioEnhanceProperty(propertyArrayV3, outputDevice);
524     hpaeManagerImpl_->SetAudioEnhanceProperty(propertyArray, outputDevice);
525 }
526 
UpdateExtraSceneTypeFuzzTest()527 void UpdateExtraSceneTypeFuzzTest()
528 {
529     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
530     if (hpaeManagerImpl_ == nullptr) {
531         return;
532     }
533     std::string mainkey = "audio_effect";
534     std::string subkey = "extra_scene_type";
535     std::string extraSceneType = "default";
536     hpaeManagerImpl_->UpdateExtraSceneType(mainkey, subkey, extraSceneType);
537 }
538 
NotifySettingsDataReadyFuzzTest()539 void NotifySettingsDataReadyFuzzTest()
540 {
541     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
542     if (hpaeManagerImpl_ == nullptr) {
543         return;
544     }
545     hpaeManagerImpl_->NotifySettingsDataReady();
546 }
547 
NotifyAccountsChangedFuzzTest()548 void NotifyAccountsChangedFuzzTest()
549 {
550     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
551     if (hpaeManagerImpl_ == nullptr) {
552         return;
553     }
554     hpaeManagerImpl_->NotifyAccountsChanged();
555 }
556 
IsAcousticEchoCancelerSupportedFuzzTest()557 void IsAcousticEchoCancelerSupportedFuzzTest()
558 {
559     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
560     if (hpaeManagerImpl_ == nullptr) {
561         return;
562     }
563     uint32_t index = g_fuzzUtils.GetData<uint32_t>() % SourceTypeVec.size();
564     SourceType sourceType = SourceTypeVec[index];
565     hpaeManagerImpl_->IsAcousticEchoCancelerSupported(sourceType);
566 }
567 
UpdateCollaborativeStateFuzzTest()568 void UpdateCollaborativeStateFuzzTest()
569 {
570     hpaeManagerImpl_ = std::make_shared<HpaeManagerImpl>();
571     if (hpaeManagerImpl_ == nullptr) {
572         return;
573     }
574     bool isCollaborationEnabled = g_fuzzUtils.GetData<bool>();
575     hpaeManagerImpl_->UpdateCollaborativeState(isCollaborationEnabled);
576 }
577 
578 vector<TestFuncs> g_testFuncs = {
579     DeInitFuzzTest,
580     DumpSinkInfoFuzzTest,
581     DumpSourceInfoFuzzTest,
582     DumpSinkInputsInfoFuzzTest,
583     ReloadAudioPortFuzzTest,
584     CloseAudioPortFuzzTest,
585     GetSinkInfoByIdxFuzzTest,
586     HandleMsgFuzzTest,
587     IsInitFuzzTest,
588     IsRunningFuzzTest,
589     IsMsgProcessingFuzzTest,
590     SetSourceOutputMuteFuzzTest,
591     StartWithSyncIdFuzzTest,
592     ReleaseFuzzTest,
593     GetSourceOutputInfoFuzzTest,
594     SetRateFuzzTest,
595     GetAudioEffectModeFuzzTest,
596     SetPrivacyTypeFuzzTest,
597     GetWritableSizeFuzzTest,
598     UpdateSpatializationStateFuzzTest,
599     UpdateMaxLengthFuzzTest,
600     SetOffloadRenderCallbackTypeFuzzTest,
601     SetSpeedFuzzTest,
602     SetOutputDeviceSinkFuzzTest,
603     UpdateSpatializationStateFuzzTest2,
604     UpdateSpatialDeviceTypeFuzzTest,
605     SetSpatializationSceneTypeFuzzTest,
606     EffectRotationUpdateFuzzTest,
607     SetEffectSystemVolumeFuzzTest,
608     SetAbsVolumeStateToEffectFuzzTest,
609     SetAudioEffectPropertyFuzzTest,
610     SetOutputDeviceFuzzTest,
611     SetVolumeInfoFuzzTest,
612     SetMicrophoneMuteInfoFuzzTest,
613     SetAudioEnhancePropertyFuzzTest,
614     UpdateExtraSceneTypeFuzzTest,
615     NotifySettingsDataReadyFuzzTest,
616     NotifyAccountsChangedFuzzTest,
617     IsAcousticEchoCancelerSupportedFuzzTest,
618     UpdateCollaborativeStateFuzzTest,
619 };
620 } // namespace AudioStandard
621 } // namesapce OHOS
622 
623 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)624 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
625 {
626     if (size < OHOS::AudioStandard::FUZZ_INPUT_SIZE_THRESHOLD) {
627         return 0;
628     }
629 
630     OHOS::AudioStandard::g_fuzzUtils.fuzzTest(data, size, OHOS::AudioStandard::g_testFuncs);
631     return 0;
632 }