1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media; 18 19 import android.content.AttributionSourceState; 20 21 import android.media.audio.common.AudioFormat; 22 23 import android.media.AudioAttributesEx; 24 import android.media.AudioAttributesInternal; 25 import android.media.AudioConfig; 26 import android.media.AudioConfigBase; 27 import android.media.AudioDevice; 28 import android.media.AudioMix; 29 import android.media.AudioMode; 30 import android.media.AudioOffloadInfo; 31 import android.media.AudioOffloadMode; 32 import android.media.AudioPatch; 33 import android.media.AudioPolicyDeviceState; 34 import android.media.AudioPolicyForcedConfig; 35 import android.media.AudioPolicyForceUse; 36 import android.media.AudioPort; 37 import android.media.AudioPortConfig; 38 import android.media.AudioPortRole; 39 import android.media.AudioPortType; 40 import android.media.AudioProductStrategy; 41 import android.media.AudioSourceType; 42 import android.media.AudioStreamType; 43 import android.media.AudioUsage; 44 import android.media.AudioUuid; 45 import android.media.AudioVolumeGroup; 46 import android.media.DeviceRole; 47 import android.media.EffectDescriptor; 48 import android.media.GetInputForAttrResponse; 49 import android.media.GetOutputForAttrResponse; 50 import android.media.IAudioPolicyServiceClient; 51 import android.media.ICaptureStateListener; 52 import android.media.Int; 53 import android.media.SoundTriggerSession; 54 55 /** 56 * IAudioPolicyService interface (see AudioPolicyInterface for method descriptions). 57 * 58 * {@hide} 59 */ 60 interface IAudioPolicyService { onNewAudioModulesAvailable()61 oneway void onNewAudioModulesAvailable(); 62 setDeviceConnectionState(in AudioDevice device, in AudioPolicyDeviceState state, @utf8InCpp String deviceName, in AudioFormat encodedFormat)63 void setDeviceConnectionState(in AudioDevice device, 64 in AudioPolicyDeviceState state, 65 @utf8InCpp String deviceName, 66 in AudioFormat encodedFormat); 67 getDeviceConnectionState(in AudioDevice device)68 AudioPolicyDeviceState getDeviceConnectionState(in AudioDevice device); 69 handleDeviceConfigChange(in AudioDevice device, @utf8InCpp String deviceName, in AudioFormat encodedFormat)70 void handleDeviceConfigChange(in AudioDevice device, 71 @utf8InCpp String deviceName, 72 in AudioFormat encodedFormat); 73 setPhoneState(AudioMode state, int uid)74 void setPhoneState(AudioMode state, int /* uid_t */ uid); 75 setForceUse(AudioPolicyForceUse usage, AudioPolicyForcedConfig config)76 void setForceUse(AudioPolicyForceUse usage, 77 AudioPolicyForcedConfig config); 78 getForceUse(AudioPolicyForceUse usage)79 AudioPolicyForcedConfig getForceUse(AudioPolicyForceUse usage); 80 getOutput(AudioStreamType stream)81 int /* audio_io_handle_t */ getOutput(AudioStreamType stream); 82 getOutputForAttr(in AudioAttributesInternal attr, int session, in AttributionSourceState attributionSource, in AudioConfig config, int flags, int selectedDeviceId)83 GetOutputForAttrResponse getOutputForAttr(in AudioAttributesInternal attr, 84 int /* audio_session_t */ session, 85 in AttributionSourceState attributionSource, 86 in AudioConfig config, 87 int /* Bitmask, indexed by AudioOutputFlags */ flags, 88 int /* audio_port_handle_t */ selectedDeviceId); 89 startOutput(int portId)90 void startOutput(int /* audio_port_handle_t */ portId); 91 stopOutput(int portId)92 void stopOutput(int /* audio_port_handle_t */ portId); 93 releaseOutput(int portId)94 void releaseOutput(int /* audio_port_handle_t */ portId); 95 getInputForAttr(in AudioAttributesInternal attr, int input, int riid, int session, in AttributionSourceState attributionSource, in AudioConfigBase config, int flags, int selectedDeviceId)96 GetInputForAttrResponse getInputForAttr(in AudioAttributesInternal attr, 97 int /* audio_io_handle_t */ input, 98 int /* audio_unique_id_t */ riid, 99 int /* audio_session_t */ session, 100 in AttributionSourceState attributionSource, 101 in AudioConfigBase config, 102 int /* Bitmask, indexed by AudioInputFlags */ flags, 103 int /* audio_port_handle_t */ selectedDeviceId); 104 105 startInput(int portId)106 void startInput(int /* audio_port_handle_t */ portId); 107 stopInput(int portId)108 void stopInput(int /* audio_port_handle_t */ portId); 109 releaseInput(int portId)110 void releaseInput(int /* audio_port_handle_t */ portId); 111 initStreamVolume(AudioStreamType stream, int indexMin, int indexMax)112 void initStreamVolume(AudioStreamType stream, 113 int indexMin, 114 int indexMax); 115 setStreamVolumeIndex(AudioStreamType stream, int device, int index)116 void setStreamVolumeIndex(AudioStreamType stream, 117 int /* audio_devices_t */ device, 118 int index); 119 getStreamVolumeIndex(AudioStreamType stream, int device)120 int getStreamVolumeIndex(AudioStreamType stream, 121 int /* audio_devices_t */ device); 122 setVolumeIndexForAttributes(in AudioAttributesInternal attr, int device, int index)123 void setVolumeIndexForAttributes(in AudioAttributesInternal attr, 124 int /* audio_devices_t */ device, 125 int index); 126 getVolumeIndexForAttributes(in AudioAttributesInternal attr, int device)127 int getVolumeIndexForAttributes(in AudioAttributesInternal attr, 128 int /* audio_devices_t */ device); 129 getMaxVolumeIndexForAttributes(in AudioAttributesInternal attr)130 int getMaxVolumeIndexForAttributes(in AudioAttributesInternal attr); 131 getMinVolumeIndexForAttributes(in AudioAttributesInternal attr)132 int getMinVolumeIndexForAttributes(in AudioAttributesInternal attr); 133 getStrategyForStream(AudioStreamType stream)134 int /* product_strategy_t */ getStrategyForStream(AudioStreamType stream); 135 getDevicesForStream(AudioStreamType stream)136 int /* bitmask of audio_devices_t */ getDevicesForStream(AudioStreamType stream); 137 getDevicesForAttributes(in AudioAttributesEx attr)138 AudioDevice[] getDevicesForAttributes(in AudioAttributesEx attr); 139 getOutputForEffect(in EffectDescriptor desc)140 int /* audio_io_handle_t */ getOutputForEffect(in EffectDescriptor desc); 141 registerEffect(in EffectDescriptor desc, int io, int strategy, int session, int id)142 void registerEffect(in EffectDescriptor desc, 143 int /* audio_io_handle_t */ io, 144 int /* product_strategy_t */ strategy, 145 int /* audio_session_t */ session, 146 int id); 147 unregisterEffect(int id)148 void unregisterEffect(int id); 149 setEffectEnabled(int id, boolean enabled)150 void setEffectEnabled(int id, boolean enabled); 151 moveEffectsToIo(in int[] ids, int io)152 void moveEffectsToIo(in int[] ids, int /* audio_io_handle_t */ io); 153 isStreamActive(AudioStreamType stream, int inPastMs)154 boolean isStreamActive(AudioStreamType stream, int inPastMs); 155 isStreamActiveRemotely(AudioStreamType stream, int inPastMs)156 boolean isStreamActiveRemotely(AudioStreamType stream, int inPastMs); 157 isSourceActive(AudioSourceType source)158 boolean isSourceActive(AudioSourceType source); 159 160 /** 161 * On input, count represents the maximum length of the returned array. 162 * On output, count is the total number of elements, which may be larger than the array size. 163 * Passing '0' on input and inspecting the value on output is a common way of determining the 164 * number of elements without actually retrieving them. 165 */ queryDefaultPreProcessing(int audioSession, inout Int count)166 EffectDescriptor[] queryDefaultPreProcessing(int /* audio_session_t */ audioSession, 167 inout Int count); 168 addSourceDefaultEffect(in AudioUuid type, @utf8InCpp String opPackageName, in AudioUuid uuid, int priority, AudioSourceType source)169 int /* audio_unique_id_t */ addSourceDefaultEffect(in AudioUuid type, 170 @utf8InCpp String opPackageName, 171 in AudioUuid uuid, 172 int priority, 173 AudioSourceType source); 174 addStreamDefaultEffect(in AudioUuid type, @utf8InCpp String opPackageName, in AudioUuid uuid, int priority, AudioUsage usage)175 int /* audio_unique_id_t */ addStreamDefaultEffect(in AudioUuid type, 176 @utf8InCpp String opPackageName, 177 in AudioUuid uuid, 178 int priority, 179 AudioUsage usage); 180 removeSourceDefaultEffect(int id)181 void removeSourceDefaultEffect(int /* audio_unique_id_t */ id); 182 removeStreamDefaultEffect(int id)183 void removeStreamDefaultEffect(int /* audio_unique_id_t */ id); 184 setSupportedSystemUsages(in AudioUsage[] systemUsages)185 void setSupportedSystemUsages(in AudioUsage[] systemUsages); 186 setAllowedCapturePolicy(int uid, int capturePolicy)187 void setAllowedCapturePolicy(int /* uid_t */ uid, 188 int /* Bitmask of AudioFlags */ capturePolicy); 189 190 /** 191 * Check if offload is possible for given format, stream type, sample rate, 192 * bit rate, duration, video and streaming or offload property is enabled. 193 */ getOffloadSupport(in AudioOffloadInfo info)194 AudioOffloadMode getOffloadSupport(in AudioOffloadInfo info); 195 196 /** 197 * Check if direct playback is possible for given format, sample rate, channel mask and flags. 198 */ isDirectOutputSupported(in AudioConfigBase config, in AudioAttributesInternal attributes)199 boolean isDirectOutputSupported(in AudioConfigBase config, 200 in AudioAttributesInternal attributes); 201 202 /** 203 * List available audio ports and their attributes. Returns the generation. 204 * 205 * On input, count represents the maximum length of the returned array. 206 * On output, count is the total number of elements, which may be larger than the array size. 207 * Passing '0' on input and inspecting the value on output is a common way of determining the 208 * number of elements without actually retrieving them. 209 */ listAudioPorts(AudioPortRole role, AudioPortType type, inout Int count, out AudioPort[] ports)210 int listAudioPorts(AudioPortRole role, 211 AudioPortType type, 212 inout Int count, 213 out AudioPort[] ports); 214 215 /** Get attributes for a given audio port. */ getAudioPort(in AudioPort port)216 AudioPort getAudioPort(in AudioPort port); 217 218 /** 219 * Create an audio patch between several source and sink ports. 220 * The handle argument is used when updating an existing patch. 221 */ createAudioPatch(in AudioPatch patch, int handle)222 int /* audio_patch_handle_t */ createAudioPatch(in AudioPatch patch, int handle); 223 224 /** Release an audio patch. */ releaseAudioPatch(int handle)225 void releaseAudioPatch(int /* audio_patch_handle_t */ handle); 226 227 /** 228 * List existing audio patches. Returns the generation. 229 * 230 * On input, count represents the maximum length of the returned array. 231 * On output, count is the total number of elements, which may be larger than the array size. 232 * Passing '0' on input and inspecting the value on output is a common way of determining the 233 * number of elements without actually retrieving them. 234 */ listAudioPatches(inout Int count, out AudioPatch[] patches)235 int listAudioPatches(inout Int count, out AudioPatch[] patches); 236 237 /** Set audio port configuration. */ setAudioPortConfig(in AudioPortConfig config)238 void setAudioPortConfig(in AudioPortConfig config); 239 registerClient(IAudioPolicyServiceClient client)240 void registerClient(IAudioPolicyServiceClient client); 241 setAudioPortCallbacksEnabled(boolean enabled)242 void setAudioPortCallbacksEnabled(boolean enabled); 243 setAudioVolumeGroupCallbacksEnabled(boolean enabled)244 void setAudioVolumeGroupCallbacksEnabled(boolean enabled); 245 acquireSoundTriggerSession()246 SoundTriggerSession acquireSoundTriggerSession(); 247 releaseSoundTriggerSession(int session)248 void releaseSoundTriggerSession(int /* audio_session_t */ session); 249 getPhoneState()250 AudioMode getPhoneState(); 251 registerPolicyMixes(in AudioMix[] mixes, boolean registration)252 void registerPolicyMixes(in AudioMix[] mixes, boolean registration); 253 setUidDeviceAffinities(int uid, in AudioDevice[] devices)254 void setUidDeviceAffinities(int /* uid_t */ uid, in AudioDevice[] devices); 255 removeUidDeviceAffinities(int uid)256 void removeUidDeviceAffinities(int /* uid_t */ uid); 257 setUserIdDeviceAffinities(int userId, in AudioDevice[] devices)258 void setUserIdDeviceAffinities(int userId, in AudioDevice[] devices); 259 removeUserIdDeviceAffinities(int userId)260 void removeUserIdDeviceAffinities(int userId); 261 startAudioSource(in AudioPortConfig source, in AudioAttributesInternal attributes)262 int /* audio_port_handle_t */ startAudioSource(in AudioPortConfig source, 263 in AudioAttributesInternal attributes); 264 stopAudioSource(int portId)265 void stopAudioSource(int /* audio_port_handle_t */ portId); 266 setMasterMono(boolean mono)267 void setMasterMono(boolean mono); 268 getMasterMono()269 boolean getMasterMono(); 270 getStreamVolumeDB(AudioStreamType stream, int index, int device)271 float getStreamVolumeDB(AudioStreamType stream, int index, int /* audio_devices_t */ device); 272 273 /** 274 * Populates supported surround formats and their enabled state in formats and formatsEnabled. 275 * 276 * On input, count represents the maximum length of the returned array. 277 * On output, count is the total number of elements, which may be larger than the array size. 278 * Passing '0' on input and inspecting the value on output is a common way of determining the 279 * number of elements without actually retrieving them. 280 */ getSurroundFormats(inout Int count, out AudioFormat[] formats, out boolean[] formatsEnabled)281 void getSurroundFormats(inout Int count, 282 out AudioFormat[] formats, 283 out boolean[] formatsEnabled); 284 285 /** 286 * Populates the surround formats reported by the HDMI devices in formats. 287 * 288 * On input, count represents the maximum length of the returned array. 289 * On output, count is the total number of elements, which may be larger than the array size. 290 * Passing '0' on input and inspecting the value on output is a common way of determining the 291 * number of elements without actually retrieving them. 292 */ getReportedSurroundFormats(inout Int count, out AudioFormat[] formats)293 void getReportedSurroundFormats(inout Int count, 294 out AudioFormat[] formats); 295 getHwOffloadEncodingFormatsSupportedForA2DP()296 AudioFormat[] getHwOffloadEncodingFormatsSupportedForA2DP(); 297 setSurroundFormatEnabled(AudioFormat audioFormat, boolean enabled)298 void setSurroundFormatEnabled(AudioFormat audioFormat, boolean enabled); 299 setAssistantUid(int uid)300 void setAssistantUid(int /* uid_t */ uid); 301 setHotwordDetectionServiceUid(int uid)302 void setHotwordDetectionServiceUid(int /* uid_t */ uid); 303 setA11yServicesUids(in int[] uids)304 void setA11yServicesUids(in int[] /* uid_t[] */ uids); 305 setCurrentImeUid(int uid)306 void setCurrentImeUid(int /* uid_t */ uid); 307 isHapticPlaybackSupported()308 boolean isHapticPlaybackSupported(); 309 listAudioProductStrategies()310 AudioProductStrategy[] listAudioProductStrategies(); getProductStrategyFromAudioAttributes(in AudioAttributesEx aa, boolean fallbackOnDefault)311 int /* product_strategy_t */ getProductStrategyFromAudioAttributes(in AudioAttributesEx aa, 312 boolean fallbackOnDefault); 313 listAudioVolumeGroups()314 AudioVolumeGroup[] listAudioVolumeGroups(); getVolumeGroupFromAudioAttributes(in AudioAttributesEx aa, boolean fallbackOnDefault)315 int /* volume_group_t */ getVolumeGroupFromAudioAttributes(in AudioAttributesEx aa, 316 boolean fallbackOnDefault); 317 setRttEnabled(boolean enabled)318 void setRttEnabled(boolean enabled); 319 isCallScreenModeSupported()320 boolean isCallScreenModeSupported(); 321 setDevicesRoleForStrategy(int strategy, DeviceRole role, in AudioDevice[] devices)322 void setDevicesRoleForStrategy(int /* product_strategy_t */ strategy, 323 DeviceRole role, 324 in AudioDevice[] devices); 325 removeDevicesRoleForStrategy(int strategy, DeviceRole role)326 void removeDevicesRoleForStrategy(int /* product_strategy_t */ strategy, 327 DeviceRole role); 328 getDevicesForRoleAndStrategy(int strategy, DeviceRole role)329 AudioDevice[] getDevicesForRoleAndStrategy(int /* product_strategy_t */ strategy, 330 DeviceRole role); 331 setDevicesRoleForCapturePreset(AudioSourceType audioSource, DeviceRole role, in AudioDevice[] devices)332 void setDevicesRoleForCapturePreset(AudioSourceType audioSource, 333 DeviceRole role, 334 in AudioDevice[] devices); 335 addDevicesRoleForCapturePreset(AudioSourceType audioSource, DeviceRole role, in AudioDevice[] devices)336 void addDevicesRoleForCapturePreset(AudioSourceType audioSource, 337 DeviceRole role, 338 in AudioDevice[] devices); 339 removeDevicesRoleForCapturePreset(AudioSourceType audioSource, DeviceRole role, in AudioDevice[] devices)340 void removeDevicesRoleForCapturePreset(AudioSourceType audioSource, 341 DeviceRole role, 342 in AudioDevice[] devices); 343 clearDevicesRoleForCapturePreset(AudioSourceType audioSource, DeviceRole role)344 void clearDevicesRoleForCapturePreset(AudioSourceType audioSource, 345 DeviceRole role); 346 getDevicesForRoleAndCapturePreset(AudioSourceType audioSource, DeviceRole role)347 AudioDevice[] getDevicesForRoleAndCapturePreset(AudioSourceType audioSource, 348 DeviceRole role); 349 registerSoundTriggerCaptureStateListener(ICaptureStateListener listener)350 boolean registerSoundTriggerCaptureStateListener(ICaptureStateListener listener); 351 } 352