• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <iostream>
17 #include <cstddef>
18 #include <cstdint>
19 #include "audio_info.h"
20 #define private public
21 #include "audio_policy_server.h"
22 #undef private
23 #include "audio_policy_service.h"
24 using namespace std;
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 using namespace std;
29 const int32_t LIMITSIZE = 4;
30 const int32_t SYSTEM_ABILITY_ID = 3009;
31 const bool RUN_ON_CREATE = false;
32 
AudioBluetoothManagerFuzzTest(const uint8_t * rawData,size_t size)33 void AudioBluetoothManagerFuzzTest(const uint8_t *rawData, size_t size)
34 {
35     if (rawData == nullptr || size < LIMITSIZE) {
36         return;
37     }
38 
39     std::shared_ptr<AudioPolicyServer> AudioPolicyServerPtr =
40         std::make_shared<AudioPolicyServer>(SYSTEM_ABILITY_ID, RUN_ON_CREATE);
41 
42     DeviceType devType = *reinterpret_cast<const DeviceType *>(rawData);
43     bool isConnected = *reinterpret_cast<const bool *>(rawData);
44     std::string macAddress(reinterpret_cast<const char*>(rawData), size);
45     std::string deviceName(reinterpret_cast<const char*>(rawData), size);
46 
47     AudioStreamInfo audioStreamInfo = {};
48     audioStreamInfo.samplingRate = *reinterpret_cast<const AudioSamplingRate *>(rawData);
49     audioStreamInfo.encoding = *reinterpret_cast<const AudioEncodingType *>(rawData);
50     audioStreamInfo.format = *reinterpret_cast<const AudioSampleFormat *>(rawData);
51     audioStreamInfo.channels = *reinterpret_cast<const AudioChannel *>(rawData);
52 
53     AudioPolicyServerPtr->audioPolicyService_
54         .OnDeviceStatusUpdated(devType, isConnected, macAddress, deviceName, audioStreamInfo);
55 
56     AudioPolicyServerPtr->audioPolicyService_
57         .OnDeviceConfigurationChanged(devType, macAddress, deviceName, audioStreamInfo);
58 }
59 } // namespace AudioStandard
60 } // namesapce OHOS
61 
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
64 {
65     /* Run your code on data */
66     OHOS::AudioStandard::AudioBluetoothManagerFuzzTest(data, size);
67     return 0;
68 }
69