• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_AUDIO_POLICY_INTERFACE_H
17 #define I_AUDIO_POLICY_INTERFACE_H
18 #define HDI_INVALID_ID 0xFFFFFFFF
19 
20 #include "audio_adapter_info.h"
21 #include "audio_policy_manager.h"
22 #include "audio_policy_ipc_interface_code.h"
23 #include "audio_stream_removed_callback.h"
24 #include "audio_volume_config.h"
25 #include "volume_data_maintainer.h"
26 #include "audio_manager_base.h"
27 #include "audio_pipe_info.h"
28 #include "istandard_audio_service.h"
29 
30 #include <memory>
31 #include <string>
32 
33 namespace OHOS {
34 namespace AudioStandard {
35 class IAudioPolicyInterface {
36 public:
~IAudioPolicyInterface()37     virtual ~IAudioPolicyInterface() {}
38 
39     virtual bool Init() = 0;
40 
41     virtual void Deinit(void) = 0;
42 
43     virtual void InitKVStore() = 0;
44 
45     virtual bool ConnectServiceAdapter() = 0;
46 
47     virtual int32_t GetMaxVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE) = 0;
48 
49     virtual int32_t GetMinVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE) = 0;
50 
51     virtual int32_t SetSystemVolumeLevel(AudioStreamType streamType, int32_t volumeLevel) = 0;
52 
53     virtual int32_t SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel) = 0;
54 
55     virtual int32_t SetAppVolumeMuted(int32_t appUid, bool muted) = 0;
56 
57     virtual int32_t IsAppVolumeMute(int32_t appUid, bool owned, bool &isMute) = 0;
58 
59     virtual int32_t SetAppRingMuted(int32_t appUid, bool muted) = 0;
60 
61     virtual bool IsAppRingMuted(int32_t appUid) = 0;
62 
63     virtual int32_t GetSystemVolumeLevel(AudioStreamType streamType) = 0;
64 
65     virtual int32_t GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel) = 0;
66 
67     virtual int32_t SetAdjustVolumeForZone(int32_t zoneId) = 0;
68 
69     virtual int32_t GetVolumeAdjustZoneId() = 0;
70 
71     virtual int32_t SetZoneVolumeLevel(int32_t zoneId, AudioStreamType streamType, int32_t volumeLevel) = 0;
72 
73     virtual int32_t GetZoneVolumeLevel(int32_t zoneId, AudioStreamType streamType) = 0;
74 
75     virtual int32_t SetZoneMute(int32_t zoneId, AudioStreamType streamType, bool mute,
76         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN,
77         const DeviceType &deviceType = DEVICE_TYPE_NONE) = 0;
78 
79     virtual bool GetZoneMute(int32_t zoneId, AudioStreamType streamType) = 0;
80 
81     virtual int32_t GetSystemVolumeLevelNoMuteState(AudioStreamType streamType) = 0;
82 
83     virtual float GetSystemVolumeDb(AudioStreamType streamType) = 0;
84 
85     virtual int32_t SetStreamMute(AudioStreamType streamType, bool mute,
86         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, const DeviceType &deviceType = DEVICE_TYPE_NONE,
87         std::string networkId = LOCAL_NETWORK_ID) = 0;
88 
89     virtual int32_t SetInnerStreamMute(AudioStreamType streamType, bool mute,
90         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN) = 0;
91 
92     virtual int32_t SetSourceOutputStreamMute(int32_t uid, bool setMute) = 0;
93 
94     virtual bool GetStreamMute(AudioStreamType streamType) = 0;
95 
96     virtual std::vector<SinkInfo> GetAllSinks() = 0;
97 
98     virtual void GetAllSinkInputs(std::vector<SinkInput> &sinkInputs) = 0;
99 
100     virtual std::vector<SourceOutput> GetAllSourceOutputs() = 0;
101 
102     virtual AudioIOHandle OpenAudioPort(std::shared_ptr<AudioPipeInfo> pipeInfo, uint32_t &paIndex) = 0;
103 
104     virtual AudioIOHandle OpenAudioPort(const AudioModuleInfo &audioPortInfo, uint32_t &paIndex) = 0;
105 
106     virtual AudioIOHandle ReloadAudioPort(const AudioModuleInfo &audioPortInfo, uint32_t &paIndex) = 0;
107 
108     virtual int32_t CloseAudioPort(AudioIOHandle ioHandle, uint32_t paIndex = HDI_INVALID_ID) = 0;
109 
110     virtual int32_t SelectDevice(DeviceRole deviceRole, InternalDeviceType deviceType, std::string name) = 0;
111 
112     virtual int32_t SetDeviceActive(InternalDeviceType deviceType,
113                                     std::string name, bool active, DeviceFlag flag = ALL_DEVICES_FLAG) = 0;
114 
115     virtual int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) = 0;
116 
117     virtual int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId,
118         uint32_t sourceIndex, std::string sourceName) = 0;
119 
120     virtual int32_t SetRingerMode(AudioRingerMode ringerMode) = 0;
121 
122     virtual AudioRingerMode GetRingerMode() const = 0;
123 
124     virtual int32_t SetAudioStreamRemovedCallback(AudioStreamRemovedCallback *callback) = 0;
125 
126     virtual int32_t SuspendAudioDevice(std::string &name, bool isSuspend) = 0;
127 
128     virtual void SetVolumeForSwitchDevice(AudioDeviceDescriptor deviceDescriptor) = 0;
129 
130     virtual bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) = 0;
131 
132     virtual float CalculateVolumeDb(int32_t volumeLevel, int32_t maxDegree = 0) = 0;
133 
134     virtual int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) = 0;
135 
136     virtual std::string GetSystemSoundUri(const std::string &key) = 0;
137 
138     virtual float GetMinStreamVolume() const = 0;
139 
140     virtual float GetMaxStreamVolume() const = 0;
141 
142     virtual bool IsVolumeUnadjustable() = 0;
143 
144     virtual void GetStreamVolumeInfoMap(StreamVolumeInfoMap &streamVolumeInfos) = 0;
145 
146     virtual void SetAbsVolumeScene(bool isAbsVolumeScene) = 0;
147 
148     virtual bool IsAbsVolumeScene() const = 0;
149 
150     virtual void SetAbsVolumeMute(bool mute) = 0;
151 
152     virtual void SetDataShareReady(std::atomic<bool> isDataShareReady) = 0;
153 
154     virtual bool IsAbsVolumeMute() const = 0;
155 
156     virtual float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType) = 0;
157 
158     virtual std::string GetModuleArgs(const AudioModuleInfo &audioModuleInfo) const = 0;
159 
160     virtual void ResetRemoteCastDeviceVolume() = 0;
161 
162     virtual void HandleDpConnection() = 0;
163 
164     virtual int32_t DoRestoreData() = 0;
165 
166     virtual SafeStatus GetCurrentDeviceSafeStatus(DeviceType deviceType) = 0;
167 
168     virtual int64_t GetCurentDeviceSafeTime(DeviceType deviceType) = 0;
169 
170     virtual int32_t SetDeviceSafeStatus(DeviceType deviceType, SafeStatus status) = 0;
171 
172     virtual int32_t SetDeviceSafeTime(DeviceType deviceType, int64_t time) = 0;
173 
174     virtual int32_t SetRestoreVolumeLevel(DeviceType deviceType, int32_t volume) = 0;
175 
176     virtual int32_t GetRestoreVolumeLevel(DeviceType deviceType) = 0;
177 
178     virtual int32_t GetSafeVolumeLevel() const = 0;
179 
180     virtual int32_t GetSafeVolumeTimeout() const = 0;
181 
182     virtual void SafeVolumeDump(std::string &dumpString) = 0;
183 
184     virtual void SetActiveDeviceDescriptor(AudioDeviceDescriptor deviceDescriptor) = 0;
185 
186     virtual DeviceType GetActiveDevice() = 0;
187 
188     virtual DeviceCategory GetCurrentOutputDeviceCategory() = 0;
189 
190     virtual AudioDeviceDescriptor GetActiveDeviceDescriptor() = 0;
191 
192     virtual void NotifyAccountsChanged(const int &id) = 0;
193 
194     virtual int32_t GetCurActivateCount() const = 0;
195 
196     virtual void HandleKvData(bool isFirstBoot) = 0;
197 
198     virtual int32_t SetPersistMicMuteState(const bool isMute) = 0;
199 
200     virtual int32_t GetPersistMicMuteState(bool &isMute) = 0;
201 
202     virtual void HandleSaveVolume(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel,
203         std::string networkId) = 0;
204 
205     virtual void HandleSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, int32_t volumeDegree,
206         std::string networkId) = 0;
207 
208     virtual void HandleStreamMuteStatus(AudioStreamType streamType, bool mute,
209         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN,
210         const DeviceType &deviceType = DEVICE_TYPE_NONE,
211         std::string networkId = LOCAL_NETWORK_ID) = 0;
212 
213     virtual void HandleRingerMode(AudioRingerMode ringerMode) = 0;
214 
215     virtual void SetAudioServerProxy(sptr<IStandardAudioService> gsp) = 0;
216 
217     virtual void SetOffloadSessionId(uint32_t sessionId) = 0;
218 
219     virtual void ResetOffloadSessionId() = 0;
220 
221     virtual int32_t SetDoubleRingVolumeDb(const AudioStreamType &streamType, const int32_t &volumeLevel) = 0;
222 
223     virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) const = 0;
224 
225     virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) const = 0;
226 
227     virtual int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray,
228         DeviceType deviceType = DEVICE_TYPE_NONE) const = 0;
229 
230     virtual int32_t GetDeviceVolume(DeviceType deviceType, AudioStreamType streamType) = 0;
231 
232     virtual void SaveRingerModeInfo(AudioRingerMode ringMode, std::string callerName, std::string invocationTime) = 0;
233 
234     virtual void GetRingerModeInfo(std::vector<RingerModeAdjustInfo> &ringerModeInfo) = 0;
235 
236     virtual std::vector<AdjustStreamVolumeInfo> GetStreamVolumeInfo(AdjustStreamVolume volumeType) = 0;
237 
238     virtual std::shared_ptr<AllDeviceVolumeInfo> GetAllDeviceVolumeInfo(DeviceType deviceType,
239         AudioStreamType streamType) = 0;
240 
241     virtual void UpdateSafeVolumeByS4() = 0;
242 
243     virtual int32_t SaveSpecifiedDeviceVolume(AudioStreamType streamType, int32_t volumeLevel,
244         DeviceType deviceType) = 0;
245 
246     virtual int32_t UpdateCollaborativeState(bool isCollaborationEnabled) = 0;
247     virtual void RegisterDoNotDisturbStatus() = 0;
248     virtual void RegisterDoNotDisturbStatusWhiteList() = 0;
249     virtual int32_t SetQueryDeviceVolumeBehaviorCallback(const sptr<IRemoteObject> &object) = 0;
250 
251     virtual void SetSleVoiceStatusFlag(bool isSleVoiceStatus) = 0;
252     virtual int32_t SetSystemVolumeDegree(AudioStreamType streamType, int32_t volumeDegree) = 0;
253     virtual int32_t GetSystemVolumeDegree(AudioStreamType streamType) = 0;
254     virtual int32_t GetMinVolumeDegree(AudioVolumeType volumeType) = 0;
255 };
256 } // namespace AudioStandard
257 } // namespace OHOS
258 
259 #endif // I_AUDIO_POLICY_INTERFACE_H
260