• 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 #ifndef I_STANDARD_AUDIO_ZONE_CLIENT_FUZZER_H
17 #define I_STANDARD_AUDIO_ZONE_CLIENT_FUZZER_H
18 
19 #include "i_standard_audio_zone_client.h"
20 #include "i_audio_zone_event_dispatcher.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 class IStandardAudioZoneClientFuzz : public IStandardAudioZoneClient {
25 public:
AsObject()26     sptr<IRemoteObject> AsObject() override
27     {
28         return nullptr;
29     }
30 
OnAudioZoneAdd(const AudioZoneDescriptor & zoneDescriptor)31     void OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) override
32     {
33         recvEvent_.type = AudioZoneEventType::AUDIO_ZONE_ADD_EVENT;
34         recvEvent_.zoneId = zoneDescriptor.zoneId_;
35         Notify();
36     }
37 
OnAudioZoneRemove(int32_t zoneId)38     void OnAudioZoneRemove(int32_t zoneId) override
39     {
40         recvEvent_.type = AudioZoneEventType::AUDIO_ZONE_REMOVE_EVENT;
41         recvEvent_.zoneId = zoneId;
42         Notify();
43     }
44 
OnAudioZoneChange(int32_t zoneId,const AudioZoneDescriptor & zoneDescriptor,AudioZoneChangeReason reason)45     void OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor,
46         AudioZoneChangeReason reason) override
47     {
48         recvEvent_.type = AudioZoneEventType::AUDIO_ZONE_CHANGE_EVENT;
49         recvEvent_.zoneId = zoneId;
50         recvEvent_.zoneChangeReason = reason;
51         Notify();
52     }
53 
OnInterruptEvent(int32_t zoneId,const std::list<std::pair<AudioInterrupt,AudioFocuState>> & interrupts,AudioZoneInterruptReason reason)54     void OnInterruptEvent(int32_t zoneId,
55         const std::list<std::pair<AudioInterrupt, AudioFocuState>> &interrupts,
56         AudioZoneInterruptReason reason) override
57     {
58         recvEvent_.type = AudioZoneEventType::AUDIO_ZONE_INTERRUPT_EVENT;
59         recvEvent_.zoneId = zoneId;
60         recvEvent_.interrupts = interrupts;
61         recvEvent_.zoneInterruptReason = reason;
62         Notify();
63     }
64 
OnInterruptEvent(int32_t zoneId,const std::string & deviceTag,const std::list<std::pair<AudioInterrupt,AudioFocuState>> & interrupts,AudioZoneInterruptReason reason)65     void OnInterruptEvent(int32_t zoneId, const std::string &deviceTag,
66         const std::list<std::pair<AudioInterrupt, AudioFocuState>> &interrupts,
67         AudioZoneInterruptReason reason) override
68     {
69         recvEvent_.type = AudioZoneEventType::AUDIO_ZONE_INTERRUPT_EVENT;
70         recvEvent_.zoneId = zoneId;
71         recvEvent_.deviceTag = deviceTag;
72         recvEvent_.interrupts = interrupts;
73         recvEvent_.zoneInterruptReason = reason;
74         Notify();
75     }
76 
SetSystemVolume(const int32_t zoneId,const AudioVolumeType volumeType,const int32_t volumeLevel,const int32_t volumeFlag)77     int32_t SetSystemVolume(const int32_t zoneId, const AudioVolumeType volumeType,
78         const int32_t volumeLevel, const int32_t volumeFlag) override
79     {
80         volumeLevel_ = volumeLevel;
81         Notify();
82         return 0;
83     }
84 
GetSystemVolume(int32_t zoneId,AudioVolumeType volumeType)85     int32_t GetSystemVolume(int32_t zoneId, AudioVolumeType volumeType) override
86     {
87         Notify();
88         return volumeLevel_;
89     }
90 
Notify()91     int Notify()
92     {
93         std::unique_lock<std::mutex> lock(waitLock_);
94         waitStatus_ = 1;
95         waiter_.notify_one();
96         return 0;
97     }
98 
Wait()99     void Wait()
100     {
101         std::unique_lock<std::mutex> lock(waitLock_);
102         if (waitStatus_ == 0) {
103             waiter_.wait(lock, [this] {
104                 return waitStatus_ != 0;
105             });
106         }
107         waitStatus_ = 0;
108     }
109 
110     struct AudioZoneEvent recvEvent_;
111     std::condition_variable waiter_;
112     std::mutex waitLock_;
113     int32_t waitStatus_ = 0;
114     int32_t volumeLevel_ = 0;
115 };
116 } // namespace AudioStandard
117 } // namesapce OHOS
118 
119 #endif // I_STANDARD_AUDIO_ZONE_CLIENT_FUZZER_H