1 /* 2 * Copyright (C) 2006 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.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.RequiresPermission; 23 import android.annotation.TestApi; 24 import android.bluetooth.BluetoothCodecConfig; 25 import android.bluetooth.BluetoothLeAudioCodecConfig; 26 import android.compat.annotation.UnsupportedAppUsage; 27 import android.content.Context; 28 import android.content.pm.PackageManager; 29 import android.media.audio.common.AidlConversion; 30 import android.media.audiofx.AudioEffect; 31 import android.media.audiopolicy.AudioMix; 32 import android.media.audiopolicy.AudioMixingRule; 33 import android.media.audiopolicy.AudioProductStrategy; 34 import android.os.Build; 35 import android.os.IBinder; 36 import android.os.Parcel; 37 import android.os.Vibrator; 38 import android.telephony.TelephonyManager; 39 import android.util.IntArray; 40 import android.util.Log; 41 import android.util.Pair; 42 43 import com.android.internal.annotations.GuardedBy; 44 45 import java.lang.annotation.Retention; 46 import java.lang.annotation.RetentionPolicy; 47 import java.util.ArrayList; 48 import java.util.HashSet; 49 import java.util.List; 50 import java.util.Map; 51 import java.util.Objects; 52 import java.util.Set; 53 import java.util.TreeSet; 54 55 /* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET 56 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java. 57 * THANK YOU FOR YOUR COOPERATION. 58 */ 59 60 /** 61 * @hide 62 */ 63 @TestApi 64 public class AudioSystem 65 { 66 private static final boolean DEBUG_VOLUME = false; 67 68 private static final String TAG = "AudioSystem"; 69 70 // private constructor to prevent instantiating AudioSystem AudioSystem()71 private AudioSystem() { 72 throw new UnsupportedOperationException("Trying to instantiate AudioSystem"); 73 } 74 75 /* These values must be kept in sync with system/media/audio/include/system/audio-hal-enums.h */ 76 /* 77 * If these are modified, please also update Settings.System.VOLUME_SETTINGS 78 * and attrs.xml and AudioManager.java. 79 */ 80 /** @hide Used to identify the default audio stream volume */ 81 @TestApi 82 public static final int STREAM_DEFAULT = -1; 83 /** @hide Used to identify the volume of audio streams for phone calls */ 84 public static final int STREAM_VOICE_CALL = 0; 85 /** @hide Used to identify the volume of audio streams for system sounds */ 86 public static final int STREAM_SYSTEM = 1; 87 /** @hide Used to identify the volume of audio streams for the phone ring and message alerts */ 88 public static final int STREAM_RING = 2; 89 /** @hide Used to identify the volume of audio streams for music playback */ 90 public static final int STREAM_MUSIC = 3; 91 /** @hide Used to identify the volume of audio streams for alarms */ 92 public static final int STREAM_ALARM = 4; 93 /** @hide Used to identify the volume of audio streams for notifications */ 94 public static final int STREAM_NOTIFICATION = 5; 95 /** @hide 96 * Used to identify the volume of audio streams for phone calls when connected on bluetooth 97 * @deprecated use {@link #STREAM_VOICE_CALL} instead */ 98 public static final int STREAM_BLUETOOTH_SCO = 6; 99 /** @hide Used to identify the volume of audio streams for enforced system sounds in certain 100 * countries (e.g camera in Japan) */ 101 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 102 public static final int STREAM_SYSTEM_ENFORCED = 7; 103 /** @hide Used to identify the volume of audio streams for DTMF tones */ 104 public static final int STREAM_DTMF = 8; 105 /** @hide Used to identify the volume of audio streams exclusively transmitted through the 106 * speaker (TTS) of the device */ 107 public static final int STREAM_TTS = 9; 108 /** @hide Used to identify the volume of audio streams for accessibility prompts */ 109 public static final int STREAM_ACCESSIBILITY = 10; 110 /** @hide Used to identify the volume of audio streams for virtual assistant */ 111 public static final int STREAM_ASSISTANT = 11; 112 /** 113 * @hide 114 * @deprecated Use {@link #numStreamTypes()} instead 115 */ 116 public static final int NUM_STREAMS = 5; 117 118 /* 119 * Framework static final constants that are primitives or Strings 120 * accessed by CTS tests or internal applications must be set from methods 121 * (or in a static block) to prevent Java compile-time replacement. 122 * We set them from methods so they are read from the device framework. 123 * Do not un-hide or change to a numeric literal. 124 */ 125 126 /** Maximum value for AudioTrack channel count 127 * @hide 128 */ 129 public static final int OUT_CHANNEL_COUNT_MAX = native_getMaxChannelCount(); native_getMaxChannelCount()130 private static native int native_getMaxChannelCount(); 131 132 /** Maximum value for sample rate, used by AudioFormat. 133 * @hide 134 */ 135 public static final int SAMPLE_RATE_HZ_MAX = native_getMaxSampleRate(); native_getMaxSampleRate()136 private static native int native_getMaxSampleRate(); 137 138 /** Minimum value for sample rate, used by AudioFormat. 139 * @hide 140 */ 141 public static final int SAMPLE_RATE_HZ_MIN = native_getMinSampleRate(); native_getMinSampleRate()142 private static native int native_getMinSampleRate(); 143 144 /** @hide */ 145 public static final int FCC_24 = 24; // fixed channel count 24; do not change. 146 147 // Expose only the getter method publicly so we can change it in the future 148 private static final int NUM_STREAM_TYPES = 12; 149 150 /** 151 * @hide 152 * @return total number of stream types 153 */ 154 @UnsupportedAppUsage 155 @TestApi getNumStreamTypes()156 public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } 157 158 /** @hide */ 159 public static final String[] STREAM_NAMES = new String[] { 160 "STREAM_VOICE_CALL", 161 "STREAM_SYSTEM", 162 "STREAM_RING", 163 "STREAM_MUSIC", 164 "STREAM_ALARM", 165 "STREAM_NOTIFICATION", 166 "STREAM_BLUETOOTH_SCO", 167 "STREAM_SYSTEM_ENFORCED", 168 "STREAM_DTMF", 169 "STREAM_TTS", 170 "STREAM_ACCESSIBILITY", 171 "STREAM_ASSISTANT" 172 }; 173 174 /** 175 * @hide 176 * Sets the microphone mute on or off. 177 * 178 * @param on set <var>true</var> to mute the microphone; 179 * <var>false</var> to turn mute off 180 * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 181 */ 182 @UnsupportedAppUsage muteMicrophone(boolean on)183 public static native int muteMicrophone(boolean on); 184 185 /** 186 * @hide 187 * Checks whether the microphone mute is on or off. 188 * 189 * @return true if microphone is muted, false if it's not 190 */ 191 @UnsupportedAppUsage isMicrophoneMuted()192 public static native boolean isMicrophoneMuted(); 193 194 /* modes for setPhoneState, must match AudioSystem.h audio_mode */ 195 /** @hide */ 196 public static final int MODE_INVALID = -2; 197 /** @hide */ 198 public static final int MODE_CURRENT = -1; 199 /** @hide */ 200 public static final int MODE_NORMAL = 0; 201 /** @hide */ 202 public static final int MODE_RINGTONE = 1; 203 /** @hide */ 204 public static final int MODE_IN_CALL = 2; 205 /** @hide */ 206 public static final int MODE_IN_COMMUNICATION = 3; 207 /** @hide */ 208 public static final int MODE_CALL_SCREENING = 4; 209 /** @hide */ 210 public static final int MODE_CALL_REDIRECT = 5; 211 /** @hide */ 212 public static final int MODE_COMMUNICATION_REDIRECT = 6; 213 /** @hide */ 214 public static final int NUM_MODES = 7; 215 216 /** @hide */ modeToString(int mode)217 public static String modeToString(int mode) { 218 switch (mode) { 219 case MODE_CURRENT: return "MODE_CURRENT"; 220 case MODE_IN_CALL: return "MODE_IN_CALL"; 221 case MODE_IN_COMMUNICATION: return "MODE_IN_COMMUNICATION"; 222 case MODE_INVALID: return "MODE_INVALID"; 223 case MODE_NORMAL: return "MODE_NORMAL"; 224 case MODE_RINGTONE: return "MODE_RINGTONE"; 225 case MODE_CALL_SCREENING: return "MODE_CALL_SCREENING"; 226 case MODE_CALL_REDIRECT: return "MODE_CALL_REDIRECT"; 227 case MODE_COMMUNICATION_REDIRECT: return "MODE_COMMUNICATION_REDIRECT"; 228 default: return "unknown mode (" + mode + ")"; 229 } 230 } 231 232 /* Formats for A2DP codecs, must match system/audio-base.h audio_format_t */ 233 /** @hide */ 234 public static final int AUDIO_FORMAT_INVALID = 0xFFFFFFFF; 235 /** @hide */ 236 public static final int AUDIO_FORMAT_DEFAULT = 0; 237 /** @hide */ 238 public static final int AUDIO_FORMAT_AAC = 0x04000000; 239 /** @hide */ 240 public static final int AUDIO_FORMAT_SBC = 0x1F000000; 241 /** @hide */ 242 public static final int AUDIO_FORMAT_APTX = 0x20000000; 243 /** @hide */ 244 public static final int AUDIO_FORMAT_APTX_HD = 0x21000000; 245 /** @hide */ 246 public static final int AUDIO_FORMAT_LDAC = 0x23000000; 247 /** @hide */ 248 public static final int AUDIO_FORMAT_LC3 = 0x2B000000; 249 /** @hide */ 250 public static final int AUDIO_FORMAT_OPUS = 0x08000000; 251 252 253 /** @hide */ 254 @IntDef(flag = false, prefix = "AUDIO_FORMAT_", value = { 255 AUDIO_FORMAT_INVALID, 256 AUDIO_FORMAT_DEFAULT, 257 AUDIO_FORMAT_AAC, 258 AUDIO_FORMAT_SBC, 259 AUDIO_FORMAT_APTX, 260 AUDIO_FORMAT_APTX_HD, 261 AUDIO_FORMAT_LDAC, 262 AUDIO_FORMAT_LC3, 263 AUDIO_FORMAT_OPUS 264 } 265 ) 266 @Retention(RetentionPolicy.SOURCE) 267 public @interface AudioFormatNativeEnumForBtCodec {} 268 269 /** @hide */ 270 @IntDef(flag = false, prefix = "AUDIO_FORMAT_", value = { 271 AUDIO_FORMAT_LC3} 272 ) 273 @Retention(RetentionPolicy.SOURCE) 274 public @interface AudioFormatNativeEnumForBtLeAudioCodec {} 275 276 /** @hide */ 277 @IntDef(flag = false, prefix = "DEVICE_", value = { 278 DEVICE_OUT_BLUETOOTH_A2DP, 279 DEVICE_OUT_BLE_HEADSET, 280 DEVICE_OUT_BLE_BROADCAST} 281 ) 282 @Retention(RetentionPolicy.SOURCE) 283 public @interface BtOffloadDeviceType {} 284 285 /** 286 * @hide 287 * Convert audio format enum values to Bluetooth codec values 288 */ audioFormatToBluetoothSourceCodec( @udioFormatNativeEnumForBtCodec int audioFormat)289 public static int audioFormatToBluetoothSourceCodec( 290 @AudioFormatNativeEnumForBtCodec int audioFormat) { 291 switch (audioFormat) { 292 case AUDIO_FORMAT_AAC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 293 case AUDIO_FORMAT_SBC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 294 case AUDIO_FORMAT_APTX: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 295 case AUDIO_FORMAT_APTX_HD: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 296 case AUDIO_FORMAT_LDAC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 297 case AUDIO_FORMAT_LC3: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3; 298 case AUDIO_FORMAT_OPUS: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS; 299 default: 300 Log.e(TAG, "Unknown audio format 0x" + Integer.toHexString(audioFormat) 301 + " for conversion to BT codec"); 302 return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; 303 } 304 } 305 306 /** 307 * @hide 308 * Convert audio format enum values to Bluetooth LE audio codec values 309 */ audioFormatToBluetoothLeAudioSourceCodec( @udioFormatNativeEnumForBtLeAudioCodec int audioFormat)310 public static int audioFormatToBluetoothLeAudioSourceCodec( 311 @AudioFormatNativeEnumForBtLeAudioCodec int audioFormat) { 312 switch (audioFormat) { 313 case AUDIO_FORMAT_LC3: return BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3; 314 default: 315 Log.e(TAG, "Unknown audio format 0x" + Integer.toHexString(audioFormat) 316 + " for conversion to BT LE audio codec"); 317 return BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID; 318 } 319 } 320 321 /** 322 * @hide 323 * Convert an A2DP Bluetooth codec to an audio format enum 324 * @param btCodec the codec to convert. 325 * @return the audio format, or {@link #AUDIO_FORMAT_DEFAULT} if unknown 326 */ bluetoothA2dpCodecToAudioFormat( int btCodec)327 public static @AudioFormatNativeEnumForBtCodec int bluetoothA2dpCodecToAudioFormat( 328 int btCodec) { 329 switch (btCodec) { 330 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC: 331 return AudioSystem.AUDIO_FORMAT_SBC; 332 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC: 333 return AudioSystem.AUDIO_FORMAT_AAC; 334 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX: 335 return AudioSystem.AUDIO_FORMAT_APTX; 336 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD: 337 return AudioSystem.AUDIO_FORMAT_APTX_HD; 338 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC: 339 return AudioSystem.AUDIO_FORMAT_LDAC; 340 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3: 341 return AudioSystem.AUDIO_FORMAT_LC3; 342 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS: 343 return AudioSystem.AUDIO_FORMAT_OPUS; 344 default: 345 Log.e(TAG, "Unknown A2DP BT codec 0x" + Integer.toHexString(btCodec) 346 + " for conversion to audio format"); 347 // TODO returning DEFAULT is the current behavior, should this return INVALID? 348 return AudioSystem.AUDIO_FORMAT_DEFAULT; 349 } 350 } 351 352 /** 353 * @hide 354 * Convert a LE Audio Bluetooth codec to an audio format enum 355 * @param btCodec the codec to convert. 356 * @return the audio format, or {@link #AUDIO_FORMAT_DEFAULT} if unknown 357 */ bluetoothLeCodecToAudioFormat(int btCodec)358 public static @AudioFormatNativeEnumForBtCodec int bluetoothLeCodecToAudioFormat(int btCodec) { 359 switch (btCodec) { 360 case BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3: 361 return AudioSystem.AUDIO_FORMAT_LC3; 362 default: 363 Log.e(TAG, "Unknown LE Audio BT codec 0x" + Integer.toHexString(btCodec) 364 + " for conversion to audio format"); 365 // TODO returning DEFAULT is the current behavior, should this return INVALID? 366 return AudioSystem.AUDIO_FORMAT_DEFAULT; 367 } 368 } 369 370 /** 371 * @hide 372 * Convert a native audio format integer constant to a string. 373 */ audioFormatToString(int audioFormat)374 public static String audioFormatToString(int audioFormat) { 375 switch (audioFormat) { 376 case /* AUDIO_FORMAT_INVALID */ 0xFFFFFFFF: 377 return "AUDIO_FORMAT_INVALID"; 378 case /* AUDIO_FORMAT_DEFAULT */ 0: 379 return "AUDIO_FORMAT_DEFAULT"; 380 case /* AUDIO_FORMAT_MP3 */ 0x01000000: 381 return "AUDIO_FORMAT_MP3"; 382 case /* AUDIO_FORMAT_AMR_NB */ 0x02000000: 383 return "AUDIO_FORMAT_AMR_NB"; 384 case /* AUDIO_FORMAT_AMR_WB */ 0x03000000: 385 return "AUDIO_FORMAT_AMR_WB"; 386 case /* AUDIO_FORMAT_AAC */ 0x04000000: 387 return "AUDIO_FORMAT_AAC"; 388 case /* AUDIO_FORMAT_HE_AAC_V1 */ 0x05000000: 389 return "AUDIO_FORMAT_HE_AAC_V1"; 390 case /* AUDIO_FORMAT_HE_AAC_V2 */ 0x06000000: 391 return "AUDIO_FORMAT_HE_AAC_V2"; 392 case /* AUDIO_FORMAT_VORBIS */ 0x07000000: 393 return "AUDIO_FORMAT_VORBIS"; 394 case /* AUDIO_FORMAT_OPUS */ 0x08000000: 395 return "AUDIO_FORMAT_OPUS"; 396 case /* AUDIO_FORMAT_AC3 */ 0x09000000: 397 return "AUDIO_FORMAT_AC3"; 398 case /* AUDIO_FORMAT_E_AC3 */ 0x0A000000: 399 return "AUDIO_FORMAT_E_AC3"; 400 case /* AUDIO_FORMAT_DTS */ 0x0B000000: 401 return "AUDIO_FORMAT_DTS"; 402 case /* AUDIO_FORMAT_DTS_HD */ 0x0C000000: 403 return "AUDIO_FORMAT_DTS_HD"; 404 case /* AUDIO_FORMAT_IEC61937 */ 0x0D000000: 405 return "AUDIO_FORMAT_IEC61937"; 406 case /* AUDIO_FORMAT_DOLBY_TRUEHD */ 0x0E000000: 407 return "AUDIO_FORMAT_DOLBY_TRUEHD"; 408 case /* AUDIO_FORMAT_EVRC */ 0x10000000: 409 return "AUDIO_FORMAT_EVRC"; 410 case /* AUDIO_FORMAT_EVRCB */ 0x11000000: 411 return "AUDIO_FORMAT_EVRCB"; 412 case /* AUDIO_FORMAT_EVRCWB */ 0x12000000: 413 return "AUDIO_FORMAT_EVRCWB"; 414 case /* AUDIO_FORMAT_EVRCNW */ 0x13000000: 415 return "AUDIO_FORMAT_EVRCNW"; 416 case /* AUDIO_FORMAT_AAC_ADIF */ 0x14000000: 417 return "AUDIO_FORMAT_AAC_ADIF"; 418 case /* AUDIO_FORMAT_WMA */ 0x15000000: 419 return "AUDIO_FORMAT_WMA"; 420 case /* AUDIO_FORMAT_WMA_PRO */ 0x16000000: 421 return "AUDIO_FORMAT_WMA_PRO"; 422 case /* AUDIO_FORMAT_AMR_WB_PLUS */ 0x17000000: 423 return "AUDIO_FORMAT_AMR_WB_PLUS"; 424 case /* AUDIO_FORMAT_MP2 */ 0x18000000: 425 return "AUDIO_FORMAT_MP2"; 426 case /* AUDIO_FORMAT_QCELP */ 0x19000000: 427 return "AUDIO_FORMAT_QCELP"; 428 case /* AUDIO_FORMAT_DSD */ 0x1A000000: 429 return "AUDIO_FORMAT_DSD"; 430 case /* AUDIO_FORMAT_FLAC */ 0x1B000000: 431 return "AUDIO_FORMAT_FLAC"; 432 case /* AUDIO_FORMAT_ALAC */ 0x1C000000: 433 return "AUDIO_FORMAT_ALAC"; 434 case /* AUDIO_FORMAT_APE */ 0x1D000000: 435 return "AUDIO_FORMAT_APE"; 436 case /* AUDIO_FORMAT_AAC_ADTS */ 0x1E000000: 437 return "AUDIO_FORMAT_AAC_ADTS"; 438 case /* AUDIO_FORMAT_SBC */ 0x1F000000: 439 return "AUDIO_FORMAT_SBC"; 440 case /* AUDIO_FORMAT_APTX */ 0x20000000: 441 return "AUDIO_FORMAT_APTX"; 442 case /* AUDIO_FORMAT_APTX_HD */ 0x21000000: 443 return "AUDIO_FORMAT_APTX_HD"; 444 case /* AUDIO_FORMAT_AC4 */ 0x22000000: 445 return "AUDIO_FORMAT_AC4"; 446 case /* AUDIO_FORMAT_LDAC */ 0x23000000: 447 return "AUDIO_FORMAT_LDAC"; 448 case /* AUDIO_FORMAT_MAT */ 0x24000000: 449 return "AUDIO_FORMAT_MAT"; 450 case /* AUDIO_FORMAT_AAC_LATM */ 0x25000000: 451 return "AUDIO_FORMAT_AAC_LATM"; 452 case /* AUDIO_FORMAT_CELT */ 0x26000000: 453 return "AUDIO_FORMAT_CELT"; 454 case /* AUDIO_FORMAT_APTX_ADAPTIVE */ 0x27000000: 455 return "AUDIO_FORMAT_APTX_ADAPTIVE"; 456 case /* AUDIO_FORMAT_LHDC */ 0x28000000: 457 return "AUDIO_FORMAT_LHDC"; 458 case /* AUDIO_FORMAT_LHDC_LL */ 0x29000000: 459 return "AUDIO_FORMAT_LHDC_LL"; 460 case /* AUDIO_FORMAT_APTX_TWSP */ 0x2A000000: 461 return "AUDIO_FORMAT_APTX_TWSP"; 462 case /* AUDIO_FORMAT_LC3 */ 0x2B000000: 463 return "AUDIO_FORMAT_LC3"; 464 case /* AUDIO_FORMAT_MPEGH */ 0x2C000000: 465 return "AUDIO_FORMAT_MPEGH"; 466 case /* AUDIO_FORMAT_IEC60958 */ 0x2D000000: 467 return "AUDIO_FORMAT_IEC60958"; 468 case /* AUDIO_FORMAT_DTS_UHD */ 0x2E000000: 469 return "AUDIO_FORMAT_DTS_UHD"; 470 case /* AUDIO_FORMAT_DRA */ 0x2F000000: 471 return "AUDIO_FORMAT_DRA"; 472 case /* AUDIO_FORMAT_APTX_ADAPTIVE_QLEA */ 0x30000000: 473 return "AUDIO_FORMAT_APTX_ADAPTIVE_QLEA"; 474 case /* AUDIO_FORMAT_APTX_ADAPTIVE_R4 */ 0x31000000: 475 return "AUDIO_FORMAT_APTX_ADAPTIVE_R4"; 476 case /* AUDIO_FORMAT_DTS_HD_MA */ 0x32000000: 477 return "AUDIO_FORMAT_DTS_HD_MA"; 478 case /* AUDIO_FORMAT_DTS_UHD_P2 */ 0x33000000: 479 return "AUDIO_FORMAT_DTS_UHD_P2"; 480 481 /* Aliases */ 482 case /* AUDIO_FORMAT_PCM_16_BIT */ 0x1: 483 return "AUDIO_FORMAT_PCM_16_BIT"; // (PCM | PCM_SUB_16_BIT) 484 case /* AUDIO_FORMAT_PCM_8_BIT */ 0x2: 485 return "AUDIO_FORMAT_PCM_8_BIT"; // (PCM | PCM_SUB_8_BIT) 486 case /* AUDIO_FORMAT_PCM_32_BIT */ 0x3: 487 return "AUDIO_FORMAT_PCM_32_BIT"; // (PCM | PCM_SUB_32_BIT) 488 case /* AUDIO_FORMAT_PCM_8_24_BIT */ 0x4: 489 return "AUDIO_FORMAT_PCM_8_24_BIT"; // (PCM | PCM_SUB_8_24_BIT) 490 case /* AUDIO_FORMAT_PCM_FLOAT */ 0x5: 491 return "AUDIO_FORMAT_PCM_FLOAT"; // (PCM | PCM_SUB_FLOAT) 492 case /* AUDIO_FORMAT_PCM_24_BIT_PACKED */ 0x6: 493 return "AUDIO_FORMAT_PCM_24_BIT_PACKED"; // (PCM | PCM_SUB_24_BIT_PACKED) 494 case /* AUDIO_FORMAT_AAC_MAIN */ 0x4000001: 495 return "AUDIO_FORMAT_AAC_MAIN"; // (AAC | AAC_SUB_MAIN) 496 case /* AUDIO_FORMAT_AAC_LC */ 0x4000002: 497 return "AUDIO_FORMAT_AAC_LC"; // (AAC | AAC_SUB_LC) 498 case /* AUDIO_FORMAT_AAC_SSR */ 0x4000004: 499 return "AUDIO_FORMAT_AAC_SSR"; // (AAC | AAC_SUB_SSR) 500 case /* AUDIO_FORMAT_AAC_LTP */ 0x4000008: 501 return "AUDIO_FORMAT_AAC_LTP"; // (AAC | AAC_SUB_LTP) 502 case /* AUDIO_FORMAT_AAC_HE_V1 */ 0x4000010: 503 return "AUDIO_FORMAT_AAC_HE_V1"; // (AAC | AAC_SUB_HE_V1) 504 case /* AUDIO_FORMAT_AAC_SCALABLE */ 0x4000020: 505 return "AUDIO_FORMAT_AAC_SCALABLE"; // (AAC | AAC_SUB_SCALABLE) 506 case /* AUDIO_FORMAT_AAC_ERLC */ 0x4000040: 507 return "AUDIO_FORMAT_AAC_ERLC"; // (AAC | AAC_SUB_ERLC) 508 case /* AUDIO_FORMAT_AAC_LD */ 0x4000080: 509 return "AUDIO_FORMAT_AAC_LD"; // (AAC | AAC_SUB_LD) 510 case /* AUDIO_FORMAT_AAC_HE_V2 */ 0x4000100: 511 return "AUDIO_FORMAT_AAC_HE_V2"; // (AAC | AAC_SUB_HE_V2) 512 case /* AUDIO_FORMAT_AAC_ELD */ 0x4000200: 513 return "AUDIO_FORMAT_AAC_ELD"; // (AAC | AAC_SUB_ELD) 514 case /* AUDIO_FORMAT_AAC_XHE */ 0x4000300: 515 return "AUDIO_FORMAT_AAC_XHE"; // (AAC | AAC_SUB_XHE) 516 case /* AUDIO_FORMAT_AAC_ADTS_MAIN */ 0x1e000001: 517 return "AUDIO_FORMAT_AAC_ADTS_MAIN"; // (AAC_ADTS | AAC_SUB_MAIN) 518 case /* AUDIO_FORMAT_AAC_ADTS_LC */ 0x1e000002: 519 return "AUDIO_FORMAT_AAC_ADTS_LC"; // (AAC_ADTS | AAC_SUB_LC) 520 case /* AUDIO_FORMAT_AAC_ADTS_SSR */ 0x1e000004: 521 return "AUDIO_FORMAT_AAC_ADTS_SSR"; // (AAC_ADTS | AAC_SUB_SSR) 522 case /* AUDIO_FORMAT_AAC_ADTS_LTP */ 0x1e000008: 523 return "AUDIO_FORMAT_AAC_ADTS_LTP"; // (AAC_ADTS | AAC_SUB_LTP) 524 case /* AUDIO_FORMAT_AAC_ADTS_HE_V1 */ 0x1e000010: 525 return "AUDIO_FORMAT_AAC_ADTS_HE_V1"; // (AAC_ADTS | AAC_SUB_HE_V1) 526 case /* AUDIO_FORMAT_AAC_ADTS_SCALABLE */ 0x1e000020: 527 return "AUDIO_FORMAT_AAC_ADTS_SCALABLE"; // (AAC_ADTS | AAC_SUB_SCALABLE) 528 case /* AUDIO_FORMAT_AAC_ADTS_ERLC */ 0x1e000040: 529 return "AUDIO_FORMAT_AAC_ADTS_ERLC"; // (AAC_ADTS | AAC_SUB_ERLC) 530 case /* AUDIO_FORMAT_AAC_ADTS_LD */ 0x1e000080: 531 return "AUDIO_FORMAT_AAC_ADTS_LD"; // (AAC_ADTS | AAC_SUB_LD) 532 case /* AUDIO_FORMAT_AAC_ADTS_HE_V2 */ 0x1e000100: 533 return "AUDIO_FORMAT_AAC_ADTS_HE_V2"; // (AAC_ADTS | AAC_SUB_HE_V2) 534 case /* AUDIO_FORMAT_AAC_ADTS_ELD */ 0x1e000200: 535 return "AUDIO_FORMAT_AAC_ADTS_ELD"; // (AAC_ADTS | AAC_SUB_ELD) 536 case /* AUDIO_FORMAT_AAC_ADTS_XHE */ 0x1e000300: 537 return "AUDIO_FORMAT_AAC_ADTS_XHE"; // (AAC_ADTS | AAC_SUB_XHE) 538 case /* AUDIO_FORMAT_AAC_LATM_LC */ 0x25000002: 539 return "AUDIO_FORMAT_AAC_LATM_LC"; // (AAC_LATM | AAC_SUB_LC) 540 case /* AUDIO_FORMAT_AAC_LATM_HE_V1 */ 0x25000010: 541 return "AUDIO_FORMAT_AAC_LATM_HE_V1"; // (AAC_LATM | AAC_SUB_HE_V1) 542 case /* AUDIO_FORMAT_AAC_LATM_HE_V2 */ 0x25000100: 543 return "AUDIO_FORMAT_AAC_LATM_HE_V2"; // (AAC_LATM | AAC_SUB_HE_V2) 544 case /* AUDIO_FORMAT_E_AC3_JOC */ 0xA000001: 545 return "AUDIO_FORMAT_E_AC3_JOC"; // (E_AC3 | E_AC3_SUB_JOC) 546 case /* AUDIO_FORMAT_AC4_L4 */ 0x22000001: 547 return "AUDIO_FORMAT_AC4_L4"; // (AC4 | AC4_SUB_L4) 548 case /* AUDIO_FORMAT_MAT_1_0 */ 0x24000001: 549 return "AUDIO_FORMAT_MAT_1_0"; // (MAT | MAT_SUB_1_0) 550 case /* AUDIO_FORMAT_MAT_2_0 */ 0x24000002: 551 return "AUDIO_FORMAT_MAT_2_0"; // (MAT | MAT_SUB_2_0) 552 case /* AUDIO_FORMAT_MAT_2_1 */ 0x24000003: 553 return "AUDIO_FORMAT_MAT_2_1"; // (MAT | MAT_SUB_2_1) 554 case /* AUDIO_FORMAT_MPEGH_SUB_BL_L3 */ 0x2C000013: 555 return "AUDIO_FORMAT_MPEGH_SUB_BL_L3"; 556 case /* AUDIO_FORMAT_MPEGH_SUB_BL_L4 */ 0x2C000014: 557 return "AUDIO_FORMAT_MPEGH_SUB_BL_L4"; 558 case /* AUDIO_FORMAT_MPEGH_SUB_LC_L3 */ 0x2C000023: 559 return "AUDIO_FORMAT_MPEGH_SUB_LC_L3"; 560 case /* AUDIO_FORMAT_MPEGH_SUB_LC_L4 */ 0x2C000024: 561 return "AUDIO_FORMAT_MPEGH_SUB_LC_L4"; 562 case /* AUDIO_FORMAT_IAMF_SIMPLE_OPUS */ 0x34010001: 563 return "AUDIO_FORMAT_IAMF_SIMPLE_OPUS"; 564 case /* AUDIO_FORMAT_IAMF_SIMPLE_AAC */ 0x34010002: 565 return "AUDIO_FORMAT_IAMF_SIMPLE_AAC"; 566 case /* AUDIO_FORMAT_IAMF_SIMPLE_FLAC */ 0x34010004: 567 return "AUDIO_FORMAT_IAMF_SIMPLE_FLAC"; 568 case /* AUDIO_FORMAT_IAMF_SIMPLE_PCM */ 0x34010008: 569 return "AUDIO_FORMAT_IAMF_SIMPLE_PCM"; 570 case /* AUDIO_FORMAT_IAMF_BASE_OPUS */ 0x34020001: 571 return "AUDIO_FORMAT_IAMF_BASE_OPUS"; 572 case /* AUDIO_FORMAT_IAMF_BASE_AAC */ 0x34020002: 573 return "AUDIO_FORMAT_IAMF_BASE_AAC"; 574 case /* AUDIO_FORMAT_IAMF_BASE_FLAC */ 0x34020004: 575 return "AUDIO_FORMAT_IAMF_BASE_FLAC"; 576 case /* AUDIO_FORMAT_IAMF_BASE_PCM */ 0x34020008: 577 return "AUDIO_FORMAT_IAMF_BASE_PCM"; 578 case /* AUDIO_FORMAT_IAMF_BASE_ENHANCED_OPUS */ 0x34040001: 579 return "AUDIO_FORMAT_IAMF_BASE_ENHANCED_OPUS"; 580 case /* AUDIO_FORMAT_IAMF_BASE_ENHANCED_AAC */ 0x34040002: 581 return "AUDIO_FORMAT_IAMF_BASE_ENHANCED_AAC"; 582 case /* AUDIO_FORMAT_IAMF_BASE_ENHANCED_FLAC */ 0x34040004: 583 return "AUDIO_FORMAT_IAMF_BASE_ENHANCED_FLAC"; 584 case /* AUDIO_FORMAT_IAMF_BASE_ENHANCED_PCM */ 0x34040008: 585 return "AUDIO_FORMAT_IAMF_BASE_ENHANCED_PCM"; 586 default: 587 return "AUDIO_FORMAT_(" + audioFormat + ")"; 588 } 589 } 590 591 /* Routing bits for the former setRouting/getRouting API */ 592 /** @hide @deprecated */ 593 @Deprecated public static final int ROUTE_EARPIECE = (1 << 0); 594 /** @hide @deprecated */ 595 @Deprecated public static final int ROUTE_SPEAKER = (1 << 1); 596 /** @hide @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */ 597 @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2); 598 /** @hide @deprecated */ 599 @Deprecated public static final int ROUTE_BLUETOOTH_SCO = (1 << 2); 600 /** @hide @deprecated */ 601 @Deprecated public static final int ROUTE_HEADSET = (1 << 3); 602 /** @hide @deprecated */ 603 @Deprecated public static final int ROUTE_BLUETOOTH_A2DP = (1 << 4); 604 /** @hide @deprecated */ 605 @Deprecated public static final int ROUTE_ALL = 0xFFFFFFFF; 606 607 // Keep in sync with system/media/audio/include/system/audio.h 608 /** @hide */ 609 public static final int AUDIO_SESSION_ALLOCATE = 0; 610 611 /** 612 * @hide 613 * Checks whether the specified stream type is active. 614 * 615 * return true if any track playing on this stream is active. 616 */ 617 @UnsupportedAppUsage isStreamActive(int stream, int inPastMs)618 public static native boolean isStreamActive(int stream, int inPastMs); 619 620 /** 621 * @hide 622 * Checks whether the specified stream type is active on a remotely connected device. The notion 623 * of what constitutes a remote device is enforced by the audio policy manager of the platform. 624 * 625 * return true if any track playing on this stream is active on a remote device. 626 */ isStreamActiveRemotely(int stream, int inPastMs)627 public static native boolean isStreamActiveRemotely(int stream, int inPastMs); 628 629 /** 630 * @hide 631 * Checks whether the specified audio source is active. 632 * 633 * return true if any recorder using this source is currently recording 634 */ 635 @UnsupportedAppUsage isSourceActive(int source)636 public static native boolean isSourceActive(int source); 637 638 /** 639 * @hide 640 * Returns a new unused audio session ID 641 */ newAudioSessionId()642 public static native int newAudioSessionId(); 643 644 /** 645 * @hide 646 * Returns a new unused audio player ID 647 */ newAudioPlayerId()648 public static native int newAudioPlayerId(); 649 650 /** 651 * @hide 652 * Returns a new unused audio recorder ID 653 */ newAudioRecorderId()654 public static native int newAudioRecorderId(); 655 656 657 /** 658 * @hide 659 * Sets a group generic audio configuration parameters. The use of these parameters 660 * are platform dependent, see libaudio 661 * 662 * param keyValuePairs list of parameters key value pairs in the form: 663 * key1=value1;key2=value2;... 664 */ 665 @UnsupportedAppUsage setParameters(String keyValuePairs)666 public static native int setParameters(String keyValuePairs); 667 668 /** 669 * @hide 670 * Gets a group generic audio configuration parameters. The use of these parameters 671 * are platform dependent, see libaudio 672 * 673 * param keys list of parameters 674 * return value: list of parameters key value pairs in the form: 675 * key1=value1;key2=value2;... 676 */ 677 @UnsupportedAppUsage getParameters(String keys)678 public static native String getParameters(String keys); 679 680 // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp 681 /** @hide Command successful or Media server restarted. see ErrorCallback */ 682 public static final int AUDIO_STATUS_OK = 0; 683 /** @hide Command failed or unspecified audio error. see ErrorCallback */ 684 public static final int AUDIO_STATUS_ERROR = 1; 685 /** @hide Media server died. see ErrorCallback */ 686 public static final int AUDIO_STATUS_SERVER_DIED = 100; 687 688 // all accesses must be synchronized (AudioSystem.class) 689 private static ErrorCallback sErrorCallback; 690 691 /** @hide 692 * Handles the audio error callback. 693 */ 694 public interface ErrorCallback 695 { 696 /* 697 * Callback for audio server errors. 698 * param error error code: 699 * - AUDIO_STATUS_OK 700 * - AUDIO_STATUS_SERVER_DIED 701 * - AUDIO_STATUS_ERROR 702 */ onError(int error)703 void onError(int error); 704 }; 705 706 /** 707 * @hide 708 * Registers a callback to be invoked when an error occurs. 709 * @param cb the callback to run 710 */ 711 @UnsupportedAppUsage setErrorCallback(ErrorCallback cb)712 public static void setErrorCallback(ErrorCallback cb) 713 { 714 synchronized (AudioSystem.class) { 715 sErrorCallback = cb; 716 if (cb != null) { 717 cb.onError(checkAudioFlinger()); 718 } 719 } 720 } 721 722 @UnsupportedAppUsage errorCallbackFromNative(int error)723 private static void errorCallbackFromNative(int error) 724 { 725 ErrorCallback errorCallback; 726 synchronized (AudioSystem.class) { 727 errorCallback = sErrorCallback; 728 } 729 if (errorCallback != null) { 730 errorCallback.onError(error); 731 } 732 } 733 734 /** 735 * @hide 736 * Handles events from the audio policy manager about dynamic audio policies 737 * @see android.media.audiopolicy.AudioPolicy 738 */ 739 public interface DynamicPolicyCallback 740 { onDynamicPolicyMixStateUpdate(String regId, int state)741 void onDynamicPolicyMixStateUpdate(String regId, int state); 742 } 743 744 //keep in sync with include/media/AudioPolicy.h 745 private final static int DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE = 0; 746 747 // all accesses must be synchronized (AudioSystem.class) 748 private static DynamicPolicyCallback sDynPolicyCallback; 749 750 /** @hide */ setDynamicPolicyCallback(DynamicPolicyCallback cb)751 public static void setDynamicPolicyCallback(DynamicPolicyCallback cb) 752 { 753 synchronized (AudioSystem.class) { 754 sDynPolicyCallback = cb; 755 native_register_dynamic_policy_callback(); 756 } 757 } 758 759 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) dynamicPolicyCallbackFromNative(int event, String regId, int val)760 private static void dynamicPolicyCallbackFromNative(int event, String regId, int val) 761 { 762 DynamicPolicyCallback cb; 763 synchronized (AudioSystem.class) { 764 cb = sDynPolicyCallback; 765 } 766 if (cb != null) { 767 switch(event) { 768 case DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE: 769 cb.onDynamicPolicyMixStateUpdate(regId, val); 770 break; 771 default: 772 Log.e(TAG, "dynamicPolicyCallbackFromNative: unknown event " + event); 773 } 774 } 775 } 776 777 /** 778 * @hide 779 * Handles events from the audio policy manager about recording events 780 * @see android.media.AudioManager.AudioRecordingCallback 781 */ 782 public interface AudioRecordingCallback 783 { 784 /** 785 * Callback for recording activity notifications events 786 * @param event 787 * @param riid recording identifier 788 * @param uid uid of the client app performing the recording 789 * @param session 790 * @param source 791 * @param recordingFormat an array of ints containing respectively the client and device 792 * recording configurations (2*3 ints), followed by the patch handle: 793 * index 0: client format 794 * 1: client channel mask 795 * 2: client sample rate 796 * 3: device format 797 * 4: device channel mask 798 * 5: device sample rate 799 * 6: patch handle 800 * @param packName package name of the client app performing the recording. NOT SUPPORTED 801 */ onRecordingConfigurationChanged(int event, int riid, int uid, int session, int source, int portId, boolean silenced, int[] recordingFormat, AudioEffect.Descriptor[] clienteffects, AudioEffect.Descriptor[] effects, int activeSource, String packName)802 void onRecordingConfigurationChanged(int event, int riid, int uid, int session, int source, 803 int portId, boolean silenced, int[] recordingFormat, 804 AudioEffect.Descriptor[] clienteffects, AudioEffect.Descriptor[] effects, 805 int activeSource, String packName); 806 } 807 808 // all accesses must be synchronized (AudioSystem.class) 809 private static AudioRecordingCallback sRecordingCallback; 810 811 /** @hide */ setRecordingCallback(AudioRecordingCallback cb)812 public static void setRecordingCallback(AudioRecordingCallback cb) { 813 synchronized (AudioSystem.class) { 814 sRecordingCallback = cb; 815 native_register_recording_callback(); 816 } 817 } 818 819 /** 820 * Callback from native for recording configuration updates. 821 * @param event 822 * @param riid 823 * @param uid 824 * @param session 825 * @param source 826 * @param portId 827 * @param silenced 828 * @param recordingFormat see 829 * {@link AudioRecordingCallback#onRecordingConfigurationChanged(int, int, int, int, int, \ 830 int, boolean, int[], AudioEffect.Descriptor[], AudioEffect.Descriptor[], int, String)} 831 * for the description of the record format. 832 * @param cleintEffects 833 * @param effects 834 * @param activeSource 835 */ 836 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) recordingCallbackFromNative(int event, int riid, int uid, int session, int source, int portId, boolean silenced, int[] recordingFormat, AudioEffect.Descriptor[] clientEffects, AudioEffect.Descriptor[] effects, int activeSource)837 private static void recordingCallbackFromNative(int event, int riid, int uid, int session, 838 int source, int portId, boolean silenced, int[] recordingFormat, 839 AudioEffect.Descriptor[] clientEffects, AudioEffect.Descriptor[] effects, 840 int activeSource) { 841 AudioRecordingCallback cb; 842 synchronized (AudioSystem.class) { 843 cb = sRecordingCallback; 844 } 845 846 String clientEffectName = clientEffects.length == 0 ? "None" : clientEffects[0].name; 847 String effectName = effects.length == 0 ? "None" : effects[0].name; 848 849 if (cb != null) { 850 ArrayList<AudioPatch> audioPatches = new ArrayList<>(); 851 if (AudioManager.listAudioPatches(audioPatches) == AudioManager.SUCCESS) { 852 boolean patchFound = false; 853 int patchHandle = recordingFormat[6]; 854 for (AudioPatch patch : audioPatches) { 855 if (patch.id() == patchHandle) { 856 patchFound = true; 857 break; 858 } 859 } 860 if (!patchFound) { 861 // The cached audio patches in AudioManager is not up-to-date. 862 // Reset audio port generation to ensure callback side can 863 // get up-to-date audio port information. 864 AudioManager.resetAudioPortGeneration(); 865 } 866 } 867 // TODO receive package name from native 868 cb.onRecordingConfigurationChanged(event, riid, uid, session, source, portId, silenced, 869 recordingFormat, clientEffects, effects, activeSource, ""); 870 } 871 } 872 873 /** 874 * @hide 875 * Handles events from the audio policy manager about routing events 876 */ 877 public interface RoutingUpdateCallback { 878 /** 879 * Callback to notify a routing update event occurred 880 */ onRoutingUpdated()881 void onRoutingUpdated(); 882 } 883 884 @GuardedBy("AudioSystem.class") 885 private static RoutingUpdateCallback sRoutingUpdateCallback; 886 887 /** @hide */ setRoutingCallback(RoutingUpdateCallback cb)888 public static void setRoutingCallback(RoutingUpdateCallback cb) { 889 synchronized (AudioSystem.class) { 890 sRoutingUpdateCallback = cb; 891 native_register_routing_callback(); 892 } 893 } 894 routingCallbackFromNative()895 private static void routingCallbackFromNative() { 896 final RoutingUpdateCallback cb; 897 synchronized (AudioSystem.class) { 898 cb = sRoutingUpdateCallback; 899 } 900 if (cb == null) { 901 Log.e(TAG, "routing update from APM was not captured"); 902 return; 903 } 904 cb.onRoutingUpdated(); 905 } 906 907 /** 908 * @hide 909 * Handles requests from the audio policy manager to (re-)initialize the volume ranges 910 */ 911 public interface VolumeRangeInitRequestCallback { 912 /** 913 * Callback to notify volume ranges need to be initialized 914 */ onVolumeRangeInitializationRequested()915 void onVolumeRangeInitializationRequested(); 916 } 917 918 @GuardedBy("AudioSystem.class") 919 private static VolumeRangeInitRequestCallback sVolRangeInitReqCallback; 920 921 /** @hide */ setVolumeRangeInitRequestCallback(VolumeRangeInitRequestCallback cb)922 public static void setVolumeRangeInitRequestCallback(VolumeRangeInitRequestCallback cb) { 923 synchronized (AudioSystem.class) { 924 sVolRangeInitReqCallback = cb; 925 native_register_vol_range_init_req_callback(); 926 } 927 } 928 volRangeInitReqCallbackFromNative()929 private static void volRangeInitReqCallbackFromNative() { 930 final VolumeRangeInitRequestCallback cb; 931 synchronized (AudioSystem.class) { 932 cb = sVolRangeInitReqCallback; 933 } 934 if (cb == null) { 935 Log.e(TAG, "APM requested volume range initialization, but no callback found"); 936 return; 937 } 938 cb.onVolumeRangeInitializationRequested(); 939 } 940 941 /* 942 * Error codes used by public APIs (AudioTrack, AudioRecord, AudioManager ...) 943 * Must be kept in sync with frameworks/base/core/jni/android_media_AudioErrors.h 944 */ 945 /** @hide */ 946 public static final int SUCCESS = 0; 947 /** @hide */ 948 public static final int ERROR = -1; 949 /** @hide */ 950 public static final int BAD_VALUE = -2; 951 /** @hide */ 952 public static final int INVALID_OPERATION = -3; 953 /** @hide */ 954 public static final int PERMISSION_DENIED = -4; 955 /** @hide */ 956 public static final int NO_INIT = -5; 957 /** @hide */ 958 public static final int DEAD_OBJECT = -6; 959 /** @hide */ 960 public static final int WOULD_BLOCK = -7; 961 962 /** @hide */ 963 @IntDef({ 964 SUCCESS, 965 ERROR, 966 BAD_VALUE, 967 INVALID_OPERATION, 968 PERMISSION_DENIED, 969 NO_INIT, 970 DEAD_OBJECT, 971 WOULD_BLOCK 972 }) 973 @Retention(RetentionPolicy.SOURCE) 974 public @interface AudioSystemError {} 975 976 /** 977 * @hide 978 * Convert an int error value to its String value for readability. 979 * Accepted error values are the java AudioSystem errors, matching android_media_AudioErrors.h, 980 * which map onto the native status_t type. 981 * @param error one of the java AudioSystem errors 982 * @return a human-readable string 983 */ audioSystemErrorToString(@udioSystemError int error)984 public static String audioSystemErrorToString(@AudioSystemError int error) { 985 switch(error) { 986 case SUCCESS: 987 return "SUCCESS"; 988 case ERROR: 989 return "ERROR"; 990 case BAD_VALUE: 991 return "BAD_VALUE"; 992 case INVALID_OPERATION: 993 return "INVALID_OPERATION"; 994 case PERMISSION_DENIED: 995 return "PERMISSION_DENIED"; 996 case NO_INIT: 997 return "NO_INIT"; 998 case DEAD_OBJECT: 999 return "DEAD_OBJECT"; 1000 case WOULD_BLOCK: 1001 return "WOULD_BLOCK"; 1002 default: 1003 return ("unknown error:" + error); 1004 } 1005 } 1006 1007 /* 1008 * AudioPolicyService methods 1009 */ 1010 1011 // 1012 // audio device definitions: must be kept in sync with values 1013 // in system/media/audio/include/system/audio-hal-enums.h 1014 // 1015 /** @hide */ 1016 public static final int DEVICE_NONE = 0x0; 1017 // reserved bits 1018 /** @hide */ 1019 public static final int DEVICE_BIT_IN = 0x80000000; 1020 /** @hide */ 1021 public static final int DEVICE_BIT_DEFAULT = 0x40000000; 1022 // output devices, be sure to update AudioManager.java also 1023 /** @hide */ 1024 @UnsupportedAppUsage 1025 public static final int DEVICE_OUT_EARPIECE = 0x1; 1026 /** @hide */ 1027 @UnsupportedAppUsage 1028 public static final int DEVICE_OUT_SPEAKER = 0x2; 1029 /** @hide */ 1030 @UnsupportedAppUsage 1031 public static final int DEVICE_OUT_WIRED_HEADSET = 0x4; 1032 /** @hide */ 1033 @UnsupportedAppUsage 1034 public static final int DEVICE_OUT_WIRED_HEADPHONE = 0x8; 1035 /** @hide */ 1036 @UnsupportedAppUsage 1037 public static final int DEVICE_OUT_BLUETOOTH_SCO = 0x10; 1038 /** @hide */ 1039 @UnsupportedAppUsage 1040 public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20; 1041 /** @hide */ 1042 @UnsupportedAppUsage 1043 public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40; 1044 /** @hide */ 1045 @UnsupportedAppUsage 1046 public static final int DEVICE_OUT_BLUETOOTH_A2DP = 0x80; 1047 /** @hide */ 1048 @UnsupportedAppUsage 1049 public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100; 1050 /** @hide */ 1051 @UnsupportedAppUsage 1052 public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200; 1053 /** @hide */ 1054 @UnsupportedAppUsage 1055 public static final int DEVICE_OUT_AUX_DIGITAL = 0x400; 1056 /** @hide */ 1057 public static final int DEVICE_OUT_HDMI = DEVICE_OUT_AUX_DIGITAL; 1058 /** @hide */ 1059 @UnsupportedAppUsage 1060 public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800; 1061 /** @hide */ 1062 @UnsupportedAppUsage 1063 public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000; 1064 /** @hide */ 1065 @UnsupportedAppUsage 1066 public static final int DEVICE_OUT_USB_ACCESSORY = 0x2000; 1067 /** @hide */ 1068 @UnsupportedAppUsage 1069 public static final int DEVICE_OUT_USB_DEVICE = 0x4000; 1070 /** @hide */ 1071 @UnsupportedAppUsage 1072 public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000; 1073 /** @hide */ 1074 @UnsupportedAppUsage 1075 public static final int DEVICE_OUT_TELEPHONY_TX = 0x10000; 1076 /** @hide */ 1077 public static final int DEVICE_OUT_LINE = 0x20000; 1078 /** @hide */ 1079 public static final int DEVICE_OUT_HDMI_ARC = 0x40000; 1080 /** @hide */ 1081 public static final int DEVICE_OUT_HDMI_EARC = 0x40001; 1082 /** @hide */ 1083 public static final int DEVICE_OUT_SPDIF = 0x80000; 1084 /** @hide */ 1085 @UnsupportedAppUsage 1086 public static final int DEVICE_OUT_FM = 0x100000; 1087 /** @hide */ 1088 public static final int DEVICE_OUT_AUX_LINE = 0x200000; 1089 /** @hide */ 1090 public static final int DEVICE_OUT_SPEAKER_SAFE = 0x400000; 1091 /** @hide */ 1092 public static final int DEVICE_OUT_IP = 0x800000; 1093 /** @hide */ 1094 public static final int DEVICE_OUT_MULTICHANNEL_GROUP = 0x800001; 1095 /** @hide */ 1096 public static final int DEVICE_OUT_BUS = 0x1000000; 1097 /** @hide */ 1098 public static final int DEVICE_OUT_PROXY = 0x2000000; 1099 /** @hide */ 1100 public static final int DEVICE_OUT_USB_HEADSET = 0x4000000; 1101 /** @hide */ 1102 public static final int DEVICE_OUT_HEARING_AID = 0x8000000; 1103 /** @hide */ 1104 public static final int DEVICE_OUT_ECHO_CANCELLER = 0x10000000; 1105 /** @hide */ 1106 public static final int DEVICE_OUT_BLE_HEADSET = 0x20000000; 1107 /** @hide */ 1108 public static final int DEVICE_OUT_BLE_SPEAKER = 0x20000001; 1109 /** @hide */ 1110 public static final int DEVICE_OUT_BLE_BROADCAST = 0x20000002; 1111 1112 /** @hide */ 1113 public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT; 1114 1115 // Deprecated in R because multiple device types are no longer accessed as a bit mask. 1116 // Removing this will get lint warning about changing hidden apis. 1117 /** @hide */ 1118 @UnsupportedAppUsage 1119 public static final int DEVICE_OUT_ALL_USB = (DEVICE_OUT_USB_ACCESSORY | 1120 DEVICE_OUT_USB_DEVICE | 1121 DEVICE_OUT_USB_HEADSET); 1122 1123 /** @hide */ 1124 public static final Set<Integer> DEVICE_OUT_ALL_SET; 1125 /** @hide */ 1126 public static final Set<Integer> DEVICE_OUT_ALL_A2DP_SET; 1127 /** @hide */ 1128 public static final Set<Integer> DEVICE_OUT_ALL_SCO_SET; 1129 /** @hide */ 1130 public static final Set<Integer> DEVICE_OUT_ALL_USB_SET; 1131 /** @hide */ 1132 public static final Set<Integer> DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET; 1133 /** @hide */ 1134 public static final Set<Integer> DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET; 1135 /** @hide */ 1136 public static final Set<Integer> DEVICE_OUT_ALL_BLE_SET; 1137 /** @hide */ 1138 public static final Set<Integer> DEVICE_OUT_PICK_FOR_VOLUME_SET; 1139 1140 static { 1141 DEVICE_OUT_ALL_SET = new HashSet<>(); 1142 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_EARPIECE); 1143 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPEAKER); 1144 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_WIRED_HEADSET); 1145 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_WIRED_HEADPHONE); 1146 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO); 1147 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET); 1148 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 1149 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP); 1150 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES); 1151 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 1152 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HDMI); 1153 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_ANLG_DOCK_HEADSET); 1154 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_DGTL_DOCK_HEADSET); 1155 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_ACCESSORY); 1156 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_DEVICE); 1157 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_REMOTE_SUBMIX); 1158 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_TELEPHONY_TX); 1159 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_LINE); 1160 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HDMI_ARC); 1161 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HDMI_EARC); 1162 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPDIF); 1163 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_FM); 1164 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_AUX_LINE); 1165 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPEAKER_SAFE); 1166 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_IP); 1167 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_MULTICHANNEL_GROUP); 1168 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BUS); 1169 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_PROXY); 1170 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_HEADSET); 1171 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HEARING_AID); 1172 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_ECHO_CANCELLER); 1173 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLE_HEADSET); 1174 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLE_SPEAKER); 1175 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLE_BROADCAST); 1176 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_DEFAULT); 1177 1178 DEVICE_OUT_ALL_A2DP_SET = new HashSet<>(); 1179 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP); 1180 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES); 1181 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 1182 1183 DEVICE_OUT_ALL_SCO_SET = new HashSet<>(); 1184 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO); 1185 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET); 1186 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 1187 1188 DEVICE_OUT_ALL_USB_SET = new HashSet<>(); 1189 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_ACCESSORY); 1190 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_DEVICE); 1191 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_HEADSET); 1192 1193 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET = new HashSet<>(); 1194 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_AUX_LINE); 1195 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_HDMI_ARC); 1196 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_HDMI_EARC); 1197 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_SPDIF); 1198 1199 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET = new HashSet<>(); 1200 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET.addAll(DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET); 1201 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET.add(DEVICE_OUT_SPEAKER); 1202 1203 DEVICE_OUT_ALL_BLE_SET = new HashSet<>(); 1204 DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_HEADSET); 1205 DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_SPEAKER); 1206 DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_BROADCAST); 1207 1208 DEVICE_OUT_PICK_FOR_VOLUME_SET = new HashSet<>(); 1209 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_WIRED_HEADSET); 1210 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_WIRED_HEADPHONE); 1211 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_USB_DEVICE); 1212 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_USB_HEADSET); 1213 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP); 1214 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES); 1215 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 1216 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO); 1217 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET); 1218 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 1219 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_HEARING_AID); 1220 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_HEADSET); 1221 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_SPEAKER); 1222 DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_BROADCAST); 1223 } 1224 1225 // input devices 1226 /** @hide */ 1227 @UnsupportedAppUsage 1228 public static final int DEVICE_IN_COMMUNICATION = DEVICE_BIT_IN | 0x1; 1229 /** @hide */ 1230 @UnsupportedAppUsage 1231 public static final int DEVICE_IN_AMBIENT = DEVICE_BIT_IN | 0x2; 1232 /** @hide */ 1233 @UnsupportedAppUsage 1234 public static final int DEVICE_IN_BUILTIN_MIC = DEVICE_BIT_IN | 0x4; 1235 /** @hide */ 1236 @UnsupportedAppUsage 1237 public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = DEVICE_BIT_IN | 0x8; 1238 /** @hide */ 1239 @UnsupportedAppUsage 1240 public static final int DEVICE_IN_WIRED_HEADSET = DEVICE_BIT_IN | 0x10; 1241 /** @hide */ 1242 @UnsupportedAppUsage 1243 public static final int DEVICE_IN_AUX_DIGITAL = DEVICE_BIT_IN | 0x20; 1244 /** @hide */ 1245 public static final int DEVICE_IN_HDMI = DEVICE_IN_AUX_DIGITAL; 1246 /** @hide */ 1247 @UnsupportedAppUsage 1248 public static final int DEVICE_IN_VOICE_CALL = DEVICE_BIT_IN | 0x40; 1249 /** @hide */ 1250 public static final int DEVICE_IN_TELEPHONY_RX = DEVICE_IN_VOICE_CALL; 1251 /** @hide */ 1252 @UnsupportedAppUsage 1253 public static final int DEVICE_IN_BACK_MIC = DEVICE_BIT_IN | 0x80; 1254 /** @hide */ 1255 @UnsupportedAppUsage 1256 public static final int DEVICE_IN_REMOTE_SUBMIX = DEVICE_BIT_IN | 0x100; 1257 /** @hide */ 1258 @UnsupportedAppUsage 1259 public static final int DEVICE_IN_ANLG_DOCK_HEADSET = DEVICE_BIT_IN | 0x200; 1260 /** @hide */ 1261 @UnsupportedAppUsage 1262 public static final int DEVICE_IN_DGTL_DOCK_HEADSET = DEVICE_BIT_IN | 0x400; 1263 /** @hide */ 1264 @UnsupportedAppUsage 1265 public static final int DEVICE_IN_USB_ACCESSORY = DEVICE_BIT_IN | 0x800; 1266 /** @hide */ 1267 @UnsupportedAppUsage 1268 public static final int DEVICE_IN_USB_DEVICE = DEVICE_BIT_IN | 0x1000; 1269 /** @hide */ 1270 public static final int DEVICE_IN_FM_TUNER = DEVICE_BIT_IN | 0x2000; 1271 /** @hide */ 1272 public static final int DEVICE_IN_TV_TUNER = DEVICE_BIT_IN | 0x4000; 1273 /** @hide */ 1274 public static final int DEVICE_IN_LINE = DEVICE_BIT_IN | 0x8000; 1275 /** @hide */ 1276 public static final int DEVICE_IN_SPDIF = DEVICE_BIT_IN | 0x10000; 1277 /** @hide */ 1278 @UnsupportedAppUsage 1279 public static final int DEVICE_IN_BLUETOOTH_A2DP = DEVICE_BIT_IN | 0x20000; 1280 /** @hide */ 1281 public static final int DEVICE_IN_LOOPBACK = DEVICE_BIT_IN | 0x40000; 1282 /** @hide */ 1283 public static final int DEVICE_IN_IP = DEVICE_BIT_IN | 0x80000; 1284 /** @hide */ 1285 public static final int DEVICE_IN_BUS = DEVICE_BIT_IN | 0x100000; 1286 /** @hide */ 1287 public static final int DEVICE_IN_PROXY = DEVICE_BIT_IN | 0x1000000; 1288 /** @hide */ 1289 public static final int DEVICE_IN_USB_HEADSET = DEVICE_BIT_IN | 0x2000000; 1290 /** @hide */ 1291 public static final int DEVICE_IN_BLUETOOTH_BLE = DEVICE_BIT_IN | 0x4000000; 1292 /** @hide */ 1293 public static final int DEVICE_IN_HDMI_ARC = DEVICE_BIT_IN | 0x8000000; 1294 /** @hide */ 1295 public static final int DEVICE_IN_HDMI_EARC = DEVICE_BIT_IN | 0x8000001; 1296 /** @hide */ 1297 public static final int DEVICE_IN_ECHO_REFERENCE = DEVICE_BIT_IN | 0x10000000; 1298 /** @hide */ 1299 public static final int DEVICE_IN_BLE_HEADSET = DEVICE_BIT_IN | 0x20000000; 1300 /** @hide */ 1301 @UnsupportedAppUsage 1302 public static final int DEVICE_IN_DEFAULT = DEVICE_BIT_IN | DEVICE_BIT_DEFAULT; 1303 1304 /** @hide */ 1305 public static final Set<Integer> DEVICE_IN_ALL_SET; 1306 /** @hide */ 1307 public static final Set<Integer> DEVICE_IN_ALL_SCO_SET; 1308 /** @hide */ 1309 public static final Set<Integer> DEVICE_IN_ALL_USB_SET; 1310 /** @hide */ 1311 public static final Set<Integer> DEVICE_IN_ALL_BLE_SET; 1312 1313 static { 1314 DEVICE_IN_ALL_SET = new HashSet<>(); 1315 DEVICE_IN_ALL_SET.add(DEVICE_IN_COMMUNICATION); 1316 DEVICE_IN_ALL_SET.add(DEVICE_IN_AMBIENT); 1317 DEVICE_IN_ALL_SET.add(DEVICE_IN_BUILTIN_MIC); 1318 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_SCO_HEADSET); 1319 DEVICE_IN_ALL_SET.add(DEVICE_IN_WIRED_HEADSET); 1320 DEVICE_IN_ALL_SET.add(DEVICE_IN_HDMI); 1321 DEVICE_IN_ALL_SET.add(DEVICE_IN_TELEPHONY_RX); 1322 DEVICE_IN_ALL_SET.add(DEVICE_IN_BACK_MIC); 1323 DEVICE_IN_ALL_SET.add(DEVICE_IN_REMOTE_SUBMIX); 1324 DEVICE_IN_ALL_SET.add(DEVICE_IN_ANLG_DOCK_HEADSET); 1325 DEVICE_IN_ALL_SET.add(DEVICE_IN_DGTL_DOCK_HEADSET); 1326 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_ACCESSORY); 1327 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_DEVICE); 1328 DEVICE_IN_ALL_SET.add(DEVICE_IN_FM_TUNER); 1329 DEVICE_IN_ALL_SET.add(DEVICE_IN_TV_TUNER); 1330 DEVICE_IN_ALL_SET.add(DEVICE_IN_LINE); 1331 DEVICE_IN_ALL_SET.add(DEVICE_IN_SPDIF); 1332 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_A2DP); 1333 DEVICE_IN_ALL_SET.add(DEVICE_IN_LOOPBACK); 1334 DEVICE_IN_ALL_SET.add(DEVICE_IN_IP); 1335 DEVICE_IN_ALL_SET.add(DEVICE_IN_BUS); 1336 DEVICE_IN_ALL_SET.add(DEVICE_IN_PROXY); 1337 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_HEADSET); 1338 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_BLE); 1339 DEVICE_IN_ALL_SET.add(DEVICE_IN_HDMI_ARC); 1340 DEVICE_IN_ALL_SET.add(DEVICE_IN_HDMI_EARC); 1341 DEVICE_IN_ALL_SET.add(DEVICE_IN_ECHO_REFERENCE); 1342 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLE_HEADSET); 1343 DEVICE_IN_ALL_SET.add(DEVICE_IN_DEFAULT); 1344 1345 DEVICE_IN_ALL_SCO_SET = new HashSet<>(); 1346 DEVICE_IN_ALL_SCO_SET.add(DEVICE_IN_BLUETOOTH_SCO_HEADSET); 1347 1348 DEVICE_IN_ALL_USB_SET = new HashSet<>(); 1349 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_ACCESSORY); 1350 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_DEVICE); 1351 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_HEADSET); 1352 1353 DEVICE_IN_ALL_BLE_SET = new HashSet<>(); 1354 DEVICE_IN_ALL_BLE_SET.add(DEVICE_IN_BLE_HEADSET); 1355 } 1356 1357 /** @hide */ isInputDevice(int deviceType)1358 public static boolean isInputDevice(int deviceType) { 1359 return (deviceType & DEVICE_BIT_IN) == DEVICE_BIT_IN; 1360 } 1361 1362 /** @hide */ isBluetoothDevice(int deviceType)1363 public static boolean isBluetoothDevice(int deviceType) { 1364 return isBluetoothA2dpOutDevice(deviceType) 1365 || isBluetoothScoDevice(deviceType) 1366 || isBluetoothLeDevice(deviceType); 1367 } 1368 1369 /** @hide */ isBluetoothOutDevice(int deviceType)1370 public static boolean isBluetoothOutDevice(int deviceType) { 1371 return isBluetoothA2dpOutDevice(deviceType) 1372 || isBluetoothScoOutDevice(deviceType) 1373 || isBluetoothLeOutDevice(deviceType); 1374 } 1375 1376 /** @hide */ isBluetoothInDevice(int deviceType)1377 public static boolean isBluetoothInDevice(int deviceType) { 1378 return isBluetoothScoInDevice(deviceType) 1379 || isBluetoothLeInDevice(deviceType); 1380 } 1381 1382 /** @hide */ isBluetoothA2dpOutDevice(int deviceType)1383 public static boolean isBluetoothA2dpOutDevice(int deviceType) { 1384 return DEVICE_OUT_ALL_A2DP_SET.contains(deviceType); 1385 } 1386 1387 /** @hide */ isBluetoothScoOutDevice(int deviceType)1388 public static boolean isBluetoothScoOutDevice(int deviceType) { 1389 return DEVICE_OUT_ALL_SCO_SET.contains(deviceType); 1390 } 1391 1392 /** @hide */ isBluetoothScoInDevice(int deviceType)1393 public static boolean isBluetoothScoInDevice(int deviceType) { 1394 return DEVICE_IN_ALL_SCO_SET.contains(deviceType); 1395 } 1396 1397 /** @hide */ isBluetoothScoDevice(int deviceType)1398 public static boolean isBluetoothScoDevice(int deviceType) { 1399 return isBluetoothScoOutDevice(deviceType) 1400 || isBluetoothScoInDevice(deviceType); 1401 } 1402 1403 /** @hide */ isBluetoothLeOutDevice(int deviceType)1404 public static boolean isBluetoothLeOutDevice(int deviceType) { 1405 return DEVICE_OUT_ALL_BLE_SET.contains(deviceType); 1406 } 1407 1408 /** @hide */ isBluetoothLeInDevice(int deviceType)1409 public static boolean isBluetoothLeInDevice(int deviceType) { 1410 return DEVICE_IN_ALL_BLE_SET.contains(deviceType); 1411 } 1412 1413 /** @hide */ isBluetoothLeDevice(int deviceType)1414 public static boolean isBluetoothLeDevice(int deviceType) { 1415 return isBluetoothLeOutDevice(deviceType) 1416 || isBluetoothLeInDevice(deviceType); 1417 } 1418 1419 /** @hide */ isRemoteSubmixDevice(int deviceType)1420 public static boolean isRemoteSubmixDevice(int deviceType) { 1421 return deviceType == DEVICE_IN_REMOTE_SUBMIX || deviceType == DEVICE_OUT_REMOTE_SUBMIX; 1422 } 1423 1424 /** @hide */ 1425 public static final String LEGACY_REMOTE_SUBMIX_ADDRESS = "0"; 1426 1427 // device states, must match AudioSystem::device_connection_state 1428 /** @hide */ 1429 @UnsupportedAppUsage 1430 public static final int DEVICE_STATE_UNAVAILABLE = 0; 1431 /** @hide */ 1432 @UnsupportedAppUsage 1433 public static final int DEVICE_STATE_AVAILABLE = 1; 1434 private static final int NUM_DEVICE_STATES = 1; 1435 1436 /** @hide */ deviceStateToString(int state)1437 public static String deviceStateToString(int state) { 1438 switch (state) { 1439 case DEVICE_STATE_UNAVAILABLE: return "DEVICE_STATE_UNAVAILABLE"; 1440 case DEVICE_STATE_AVAILABLE: return "DEVICE_STATE_AVAILABLE"; 1441 default: return "unknown state (" + state + ")"; 1442 } 1443 } 1444 1445 /** @hide */ public static final String DEVICE_OUT_EARPIECE_NAME = "earpiece"; 1446 /** @hide */ public static final String DEVICE_OUT_SPEAKER_NAME = "speaker"; 1447 /** @hide */ public static final String DEVICE_OUT_WIRED_HEADSET_NAME = "headset"; 1448 /** @hide */ public static final String DEVICE_OUT_WIRED_HEADPHONE_NAME = "headphone"; 1449 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_NAME = "bt_sco"; 1450 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 1451 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME = "bt_sco_carkit"; 1452 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 1453 /** @hide */ 1454 public static final String DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME = "bt_a2dp_hp"; 1455 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME = "bt_a2dp_spk"; 1456 /** @hide */ public static final String DEVICE_OUT_AUX_DIGITAL_NAME = "aux_digital"; 1457 /** @hide */ public static final String DEVICE_OUT_HDMI_NAME = "hdmi"; 1458 /** @hide */ public static final String DEVICE_OUT_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 1459 /** @hide */ public static final String DEVICE_OUT_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 1460 /** @hide */ public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory"; 1461 /** @hide */ public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device"; 1462 /** @hide */ public static final String DEVICE_OUT_REMOTE_SUBMIX_NAME = "remote_submix"; 1463 /** @hide */ public static final String DEVICE_OUT_TELEPHONY_TX_NAME = "telephony_tx"; 1464 /** @hide */ public static final String DEVICE_OUT_LINE_NAME = "line"; 1465 /** @hide */ public static final String DEVICE_OUT_HDMI_ARC_NAME = "hdmi_arc"; 1466 /** @hide */ public static final String DEVICE_OUT_HDMI_EARC_NAME = "hdmi_earc"; 1467 /** @hide */ public static final String DEVICE_OUT_SPDIF_NAME = "spdif"; 1468 /** @hide */ public static final String DEVICE_OUT_FM_NAME = "fm_transmitter"; 1469 /** @hide */ public static final String DEVICE_OUT_AUX_LINE_NAME = "aux_line"; 1470 /** @hide */ public static final String DEVICE_OUT_SPEAKER_SAFE_NAME = "speaker_safe"; 1471 /** @hide */ public static final String DEVICE_OUT_IP_NAME = "ip"; 1472 /** @hide */ 1473 public static final String DEVICE_OUT_MULTICHANNEL_GROUP_NAME = "multichannel_group"; 1474 /** @hide */ public static final String DEVICE_OUT_BUS_NAME = "bus"; 1475 /** @hide */ public static final String DEVICE_OUT_PROXY_NAME = "proxy"; 1476 /** @hide */ public static final String DEVICE_OUT_USB_HEADSET_NAME = "usb_headset"; 1477 /** @hide */ public static final String DEVICE_OUT_HEARING_AID_NAME = "hearing_aid_out"; 1478 /** @hide */ public static final String DEVICE_OUT_ECHO_CANCELLER_NAME = "echo_canceller"; 1479 /** @hide */ public static final String DEVICE_OUT_BLE_HEADSET_NAME = "ble_headset"; 1480 /** @hide */ public static final String DEVICE_OUT_BLE_SPEAKER_NAME = "ble_speaker"; 1481 /** @hide */ public static final String DEVICE_OUT_BLE_BROADCAST_NAME = "ble_broadcast"; 1482 1483 /** @hide */ public static final String DEVICE_IN_COMMUNICATION_NAME = "communication"; 1484 /** @hide */ public static final String DEVICE_IN_AMBIENT_NAME = "ambient"; 1485 /** @hide */ public static final String DEVICE_IN_BUILTIN_MIC_NAME = "mic"; 1486 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 1487 /** @hide */ public static final String DEVICE_IN_WIRED_HEADSET_NAME = "headset"; 1488 /** @hide */ public static final String DEVICE_IN_AUX_DIGITAL_NAME = "aux_digital"; 1489 /** @hide */ public static final String DEVICE_IN_TELEPHONY_RX_NAME = "telephony_rx"; 1490 /** @hide */ public static final String DEVICE_IN_BACK_MIC_NAME = "back_mic"; 1491 /** @hide */ public static final String DEVICE_IN_REMOTE_SUBMIX_NAME = "remote_submix"; 1492 /** @hide */ public static final String DEVICE_IN_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 1493 /** @hide */ public static final String DEVICE_IN_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 1494 /** @hide */ public static final String DEVICE_IN_USB_ACCESSORY_NAME = "usb_accessory"; 1495 /** @hide */ public static final String DEVICE_IN_USB_DEVICE_NAME = "usb_device"; 1496 /** @hide */ public static final String DEVICE_IN_FM_TUNER_NAME = "fm_tuner"; 1497 /** @hide */ public static final String DEVICE_IN_TV_TUNER_NAME = "tv_tuner"; 1498 /** @hide */ public static final String DEVICE_IN_LINE_NAME = "line"; 1499 /** @hide */ public static final String DEVICE_IN_SPDIF_NAME = "spdif"; 1500 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 1501 /** @hide */ public static final String DEVICE_IN_LOOPBACK_NAME = "loopback"; 1502 /** @hide */ public static final String DEVICE_IN_IP_NAME = "ip"; 1503 /** @hide */ public static final String DEVICE_IN_BUS_NAME = "bus"; 1504 /** @hide */ public static final String DEVICE_IN_PROXY_NAME = "proxy"; 1505 /** @hide */ public static final String DEVICE_IN_USB_HEADSET_NAME = "usb_headset"; 1506 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_BLE_NAME = "bt_ble"; 1507 /** @hide */ public static final String DEVICE_IN_ECHO_REFERENCE_NAME = "echo_reference"; 1508 /** @hide */ public static final String DEVICE_IN_HDMI_ARC_NAME = "hdmi_arc"; 1509 /** @hide */ public static final String DEVICE_IN_HDMI_EARC_NAME = "hdmi_earc"; 1510 /** @hide */ public static final String DEVICE_IN_BLE_HEADSET_NAME = "ble_headset"; 1511 1512 /** @hide */ 1513 @UnsupportedAppUsage getOutputDeviceName(int device)1514 public static String getOutputDeviceName(int device) 1515 { 1516 switch(device) { 1517 case DEVICE_OUT_EARPIECE: 1518 return DEVICE_OUT_EARPIECE_NAME; 1519 case DEVICE_OUT_SPEAKER: 1520 return DEVICE_OUT_SPEAKER_NAME; 1521 case DEVICE_OUT_WIRED_HEADSET: 1522 return DEVICE_OUT_WIRED_HEADSET_NAME; 1523 case DEVICE_OUT_WIRED_HEADPHONE: 1524 return DEVICE_OUT_WIRED_HEADPHONE_NAME; 1525 case DEVICE_OUT_BLUETOOTH_SCO: 1526 return DEVICE_OUT_BLUETOOTH_SCO_NAME; 1527 case DEVICE_OUT_BLUETOOTH_SCO_HEADSET: 1528 return DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME; 1529 case DEVICE_OUT_BLUETOOTH_SCO_CARKIT: 1530 return DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME; 1531 case DEVICE_OUT_BLUETOOTH_A2DP: 1532 return DEVICE_OUT_BLUETOOTH_A2DP_NAME; 1533 case DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: 1534 return DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME; 1535 case DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: 1536 return DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME; 1537 case DEVICE_OUT_HDMI: 1538 return DEVICE_OUT_HDMI_NAME; 1539 case DEVICE_OUT_ANLG_DOCK_HEADSET: 1540 return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME; 1541 case DEVICE_OUT_DGTL_DOCK_HEADSET: 1542 return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME; 1543 case DEVICE_OUT_USB_ACCESSORY: 1544 return DEVICE_OUT_USB_ACCESSORY_NAME; 1545 case DEVICE_OUT_USB_DEVICE: 1546 return DEVICE_OUT_USB_DEVICE_NAME; 1547 case DEVICE_OUT_REMOTE_SUBMIX: 1548 return DEVICE_OUT_REMOTE_SUBMIX_NAME; 1549 case DEVICE_OUT_TELEPHONY_TX: 1550 return DEVICE_OUT_TELEPHONY_TX_NAME; 1551 case DEVICE_OUT_LINE: 1552 return DEVICE_OUT_LINE_NAME; 1553 case DEVICE_OUT_HDMI_ARC: 1554 return DEVICE_OUT_HDMI_ARC_NAME; 1555 case DEVICE_OUT_HDMI_EARC: 1556 return DEVICE_OUT_HDMI_EARC_NAME; 1557 case DEVICE_OUT_SPDIF: 1558 return DEVICE_OUT_SPDIF_NAME; 1559 case DEVICE_OUT_FM: 1560 return DEVICE_OUT_FM_NAME; 1561 case DEVICE_OUT_AUX_LINE: 1562 return DEVICE_OUT_AUX_LINE_NAME; 1563 case DEVICE_OUT_SPEAKER_SAFE: 1564 return DEVICE_OUT_SPEAKER_SAFE_NAME; 1565 case DEVICE_OUT_IP: 1566 return DEVICE_OUT_IP_NAME; 1567 case DEVICE_OUT_MULTICHANNEL_GROUP: 1568 return DEVICE_OUT_MULTICHANNEL_GROUP_NAME; 1569 case DEVICE_OUT_BUS: 1570 return DEVICE_OUT_BUS_NAME; 1571 case DEVICE_OUT_PROXY: 1572 return DEVICE_OUT_PROXY_NAME; 1573 case DEVICE_OUT_USB_HEADSET: 1574 return DEVICE_OUT_USB_HEADSET_NAME; 1575 case DEVICE_OUT_HEARING_AID: 1576 return DEVICE_OUT_HEARING_AID_NAME; 1577 case DEVICE_OUT_ECHO_CANCELLER: 1578 return DEVICE_OUT_ECHO_CANCELLER_NAME; 1579 case DEVICE_OUT_BLE_HEADSET: 1580 return DEVICE_OUT_BLE_HEADSET_NAME; 1581 case DEVICE_OUT_BLE_SPEAKER: 1582 return DEVICE_OUT_BLE_SPEAKER_NAME; 1583 case DEVICE_OUT_BLE_BROADCAST: 1584 return DEVICE_OUT_BLE_BROADCAST_NAME; 1585 case DEVICE_OUT_DEFAULT: 1586 default: 1587 return "0x" + Integer.toHexString(device); 1588 } 1589 } 1590 1591 /** @hide */ getInputDeviceName(int device)1592 public static String getInputDeviceName(int device) 1593 { 1594 switch(device) { 1595 case DEVICE_IN_COMMUNICATION: 1596 return DEVICE_IN_COMMUNICATION_NAME; 1597 case DEVICE_IN_AMBIENT: 1598 return DEVICE_IN_AMBIENT_NAME; 1599 case DEVICE_IN_BUILTIN_MIC: 1600 return DEVICE_IN_BUILTIN_MIC_NAME; 1601 case DEVICE_IN_BLUETOOTH_SCO_HEADSET: 1602 return DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME; 1603 case DEVICE_IN_WIRED_HEADSET: 1604 return DEVICE_IN_WIRED_HEADSET_NAME; 1605 case DEVICE_IN_AUX_DIGITAL: 1606 return DEVICE_IN_AUX_DIGITAL_NAME; 1607 case DEVICE_IN_TELEPHONY_RX: 1608 return DEVICE_IN_TELEPHONY_RX_NAME; 1609 case DEVICE_IN_BACK_MIC: 1610 return DEVICE_IN_BACK_MIC_NAME; 1611 case DEVICE_IN_REMOTE_SUBMIX: 1612 return DEVICE_IN_REMOTE_SUBMIX_NAME; 1613 case DEVICE_IN_ANLG_DOCK_HEADSET: 1614 return DEVICE_IN_ANLG_DOCK_HEADSET_NAME; 1615 case DEVICE_IN_DGTL_DOCK_HEADSET: 1616 return DEVICE_IN_DGTL_DOCK_HEADSET_NAME; 1617 case DEVICE_IN_USB_ACCESSORY: 1618 return DEVICE_IN_USB_ACCESSORY_NAME; 1619 case DEVICE_IN_USB_DEVICE: 1620 return DEVICE_IN_USB_DEVICE_NAME; 1621 case DEVICE_IN_FM_TUNER: 1622 return DEVICE_IN_FM_TUNER_NAME; 1623 case DEVICE_IN_TV_TUNER: 1624 return DEVICE_IN_TV_TUNER_NAME; 1625 case DEVICE_IN_LINE: 1626 return DEVICE_IN_LINE_NAME; 1627 case DEVICE_IN_SPDIF: 1628 return DEVICE_IN_SPDIF_NAME; 1629 case DEVICE_IN_BLUETOOTH_A2DP: 1630 return DEVICE_IN_BLUETOOTH_A2DP_NAME; 1631 case DEVICE_IN_LOOPBACK: 1632 return DEVICE_IN_LOOPBACK_NAME; 1633 case DEVICE_IN_IP: 1634 return DEVICE_IN_IP_NAME; 1635 case DEVICE_IN_BUS: 1636 return DEVICE_IN_BUS_NAME; 1637 case DEVICE_IN_PROXY: 1638 return DEVICE_IN_PROXY_NAME; 1639 case DEVICE_IN_USB_HEADSET: 1640 return DEVICE_IN_USB_HEADSET_NAME; 1641 case DEVICE_IN_BLUETOOTH_BLE: 1642 return DEVICE_IN_BLUETOOTH_BLE_NAME; 1643 case DEVICE_IN_ECHO_REFERENCE: 1644 return DEVICE_IN_ECHO_REFERENCE_NAME; 1645 case DEVICE_IN_HDMI_ARC: 1646 return DEVICE_IN_HDMI_ARC_NAME; 1647 case DEVICE_IN_HDMI_EARC: 1648 return DEVICE_IN_HDMI_EARC_NAME; 1649 case DEVICE_IN_BLE_HEADSET: 1650 return DEVICE_IN_BLE_HEADSET_NAME; 1651 case DEVICE_IN_DEFAULT: 1652 default: 1653 return Integer.toString(device); 1654 } 1655 } 1656 1657 /** 1658 * @hide 1659 * Returns a human readable name for a given device type 1660 * @param device a native device type, NOT an AudioDeviceInfo type 1661 * @return a string describing the device type 1662 */ getDeviceName(int device)1663 public static @NonNull String getDeviceName(int device) { 1664 if (isInputDevice(device)) { 1665 return getInputDeviceName(device); 1666 } 1667 return getOutputDeviceName(device); 1668 } 1669 1670 // phone state, match audio_mode??? 1671 /** @hide */ public static final int PHONE_STATE_OFFCALL = 0; 1672 /** @hide */ public static final int PHONE_STATE_RINGING = 1; 1673 /** @hide */ public static final int PHONE_STATE_INCALL = 2; 1674 1675 // device categories config for setForceUse, must match audio_policy_forced_cfg_t 1676 /** @hide */ @UnsupportedAppUsage public static final int FORCE_NONE = 0; 1677 /** @hide */ public static final int FORCE_SPEAKER = 1; 1678 /** @hide */ public static final int FORCE_HEADPHONES = 2; 1679 /** @hide */ public static final int FORCE_BT_SCO = 3; 1680 /** @hide */ public static final int FORCE_BT_A2DP = 4; 1681 /** @hide */ public static final int FORCE_WIRED_ACCESSORY = 5; 1682 /** @hide */ @UnsupportedAppUsage public static final int FORCE_BT_CAR_DOCK = 6; 1683 /** @hide */ @UnsupportedAppUsage public static final int FORCE_BT_DESK_DOCK = 7; 1684 /** @hide */ @UnsupportedAppUsage public static final int FORCE_ANALOG_DOCK = 8; 1685 /** @hide */ @UnsupportedAppUsage public static final int FORCE_DIGITAL_DOCK = 9; 1686 /** @hide */ public static final int FORCE_NO_BT_A2DP = 10; 1687 /** @hide */ public static final int FORCE_SYSTEM_ENFORCED = 11; 1688 /** @hide */ public static final int FORCE_HDMI_SYSTEM_AUDIO_ENFORCED = 12; 1689 /** @hide */ public static final int FORCE_ENCODED_SURROUND_NEVER = 13; 1690 /** @hide */ public static final int FORCE_ENCODED_SURROUND_ALWAYS = 14; 1691 /** @hide */ public static final int FORCE_ENCODED_SURROUND_MANUAL = 15; 1692 /** @hide */ public static final int FORCE_BT_BLE = 16; 1693 /** @hide */ public static final int NUM_FORCE_CONFIG = 17; 1694 /** @hide */ public static final int FORCE_DEFAULT = FORCE_NONE; 1695 1696 /** @hide */ forceUseConfigToString(int config)1697 public static String forceUseConfigToString(int config) { 1698 switch (config) { 1699 case FORCE_NONE: return "FORCE_NONE"; 1700 case FORCE_SPEAKER: return "FORCE_SPEAKER"; 1701 case FORCE_HEADPHONES: return "FORCE_HEADPHONES"; 1702 case FORCE_BT_SCO: return "FORCE_BT_SCO"; 1703 case FORCE_BT_A2DP: return "FORCE_BT_A2DP"; 1704 case FORCE_WIRED_ACCESSORY: return "FORCE_WIRED_ACCESSORY"; 1705 case FORCE_BT_CAR_DOCK: return "FORCE_BT_CAR_DOCK"; 1706 case FORCE_BT_DESK_DOCK: return "FORCE_BT_DESK_DOCK"; 1707 case FORCE_ANALOG_DOCK: return "FORCE_ANALOG_DOCK"; 1708 case FORCE_DIGITAL_DOCK: return "FORCE_DIGITAL_DOCK"; 1709 case FORCE_NO_BT_A2DP: return "FORCE_NO_BT_A2DP"; 1710 case FORCE_SYSTEM_ENFORCED: return "FORCE_SYSTEM_ENFORCED"; 1711 case FORCE_HDMI_SYSTEM_AUDIO_ENFORCED: return "FORCE_HDMI_SYSTEM_AUDIO_ENFORCED"; 1712 case FORCE_ENCODED_SURROUND_NEVER: return "FORCE_ENCODED_SURROUND_NEVER"; 1713 case FORCE_ENCODED_SURROUND_ALWAYS: return "FORCE_ENCODED_SURROUND_ALWAYS"; 1714 case FORCE_ENCODED_SURROUND_MANUAL: return "FORCE_ENCODED_SURROUND_MANUAL"; 1715 case FORCE_BT_BLE: return "FORCE_BT_BLE"; 1716 default: return "unknown config (" + config + ")" ; 1717 } 1718 } 1719 1720 // usage for setForceUse, must match audio_policy_force_use_t 1721 /** @hide */ public static final int FOR_COMMUNICATION = 0; 1722 /** @hide */ public static final int FOR_MEDIA = 1; 1723 /** @hide */ public static final int FOR_RECORD = 2; 1724 /** @hide */ public static final int FOR_DOCK = 3; 1725 /** @hide */ public static final int FOR_SYSTEM = 4; 1726 /** @hide */ public static final int FOR_HDMI_SYSTEM_AUDIO = 5; 1727 /** @hide */ public static final int FOR_ENCODED_SURROUND = 6; 1728 /** @hide */ public static final int FOR_VIBRATE_RINGING = 7; 1729 private static final int NUM_FORCE_USE = 8; 1730 1731 // Device role in audio policy 1732 public static final int DEVICE_ROLE_NONE = 0; 1733 public static final int DEVICE_ROLE_PREFERRED = 1; 1734 public static final int DEVICE_ROLE_DISABLED = 2; 1735 1736 /** @hide */ forceUseUsageToString(int usage)1737 public static String forceUseUsageToString(int usage) { 1738 switch (usage) { 1739 case FOR_COMMUNICATION: return "FOR_COMMUNICATION"; 1740 case FOR_MEDIA: return "FOR_MEDIA"; 1741 case FOR_RECORD: return "FOR_RECORD"; 1742 case FOR_DOCK: return "FOR_DOCK"; 1743 case FOR_SYSTEM: return "FOR_SYSTEM"; 1744 case FOR_HDMI_SYSTEM_AUDIO: return "FOR_HDMI_SYSTEM_AUDIO"; 1745 case FOR_ENCODED_SURROUND: return "FOR_ENCODED_SURROUND"; 1746 case FOR_VIBRATE_RINGING: return "FOR_VIBRATE_RINGING"; 1747 default: return "unknown usage (" + usage + ")" ; 1748 } 1749 } 1750 1751 /** @hide Wrapper for native methods called from AudioService */ setStreamVolumeIndexAS(int stream, int index, boolean muted, int device)1752 public static int setStreamVolumeIndexAS(int stream, int index, boolean muted, int device) { 1753 if (DEBUG_VOLUME) { 1754 Log.i(TAG, "setStreamVolumeIndex: " + STREAM_NAMES[stream] 1755 + " dev=" + Integer.toHexString(device) + " idx=" + index + " muted=" + muted); 1756 } 1757 return setStreamVolumeIndex(stream, index, muted, device); 1758 } 1759 1760 // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t 1761 /** @hide */ public static final int SYNC_EVENT_NONE = 0; 1762 /** @hide */ public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1; 1763 /** @hide 1764 * Not used by native implementation. 1765 * See {@link AudioRecord.Builder#setSharedAudioEvent(MediaSyncEvent) */ 1766 public static final int SYNC_EVENT_SHARE_AUDIO_HISTORY = 100; 1767 1768 /** 1769 * @hide 1770 * @return command completion status, one of {@link #AUDIO_STATUS_OK}, 1771 * {@link #AUDIO_STATUS_ERROR} or {@link #AUDIO_STATUS_SERVER_DIED} 1772 */ 1773 @UnsupportedAppUsage setDeviceConnectionState(AudioDeviceAttributes attributes, int state, int codecFormat)1774 public static int setDeviceConnectionState(AudioDeviceAttributes attributes, int state, 1775 int codecFormat) { 1776 return setDeviceConnectionState(attributes, state, codecFormat, false /*deviceSwitch*/); 1777 } 1778 1779 /** 1780 * @hide 1781 */ setDeviceConnectionState(AudioDeviceAttributes attributes, int state, int codecFormat, boolean deviceSwitch)1782 public static int setDeviceConnectionState(AudioDeviceAttributes attributes, int state, 1783 int codecFormat, boolean deviceSwitch) { 1784 android.media.audio.common.AudioPort port = 1785 AidlConversion.api2aidl_AudioDeviceAttributes_AudioPort(attributes); 1786 Parcel parcel = Parcel.obtain(); 1787 port.writeToParcel(parcel, 0); 1788 parcel.setDataPosition(0); 1789 try { 1790 return setDeviceConnectionState(state, parcel, codecFormat, deviceSwitch); 1791 } finally { 1792 parcel.recycle(); 1793 } 1794 } 1795 /** 1796 * @hide 1797 */ 1798 @UnsupportedAppUsage setDeviceConnectionState(int state, Parcel parcel, int codecFormat, boolean deviceSwitch)1799 public static native int setDeviceConnectionState(int state, Parcel parcel, int codecFormat, 1800 boolean deviceSwitch); 1801 1802 1803 /** @hide */ 1804 @UnsupportedAppUsage getDeviceConnectionState(int device, String device_address)1805 public static native int getDeviceConnectionState(int device, String device_address); 1806 /** @hide */ handleDeviceConfigChange(int device, String device_address, String device_name, int codecFormat)1807 public static native int handleDeviceConfigChange(int device, 1808 String device_address, 1809 String device_name, 1810 int codecFormat); 1811 /** @hide */ 1812 @UnsupportedAppUsage setPhoneState(int state)1813 public static int setPhoneState(int state) { 1814 Log.w(TAG, "Do not use this method! Use AudioManager.setMode() instead."); 1815 return 0; 1816 } 1817 /** 1818 * @hide 1819 * Send the current audio mode to audio policy manager and audio HAL. 1820 * @param state the audio mode 1821 * @param uid the UID of the app owning the audio mode 1822 * @return command completion status. 1823 */ setPhoneState(int state, int uid)1824 public static native int setPhoneState(int state, int uid); 1825 /** @hide */ 1826 @UnsupportedAppUsage setForceUse(int usage, int config)1827 public static native int setForceUse(int usage, int config); 1828 /** @hide */ 1829 @UnsupportedAppUsage getForceUse(int usage)1830 public static native int getForceUse(int usage); 1831 /** @hide */ 1832 @UnsupportedAppUsage setDeviceAbsoluteVolumeEnabled(int nativeDeviceType, @NonNull String address, boolean enabled, int streamToDriveAbs)1833 public static native int setDeviceAbsoluteVolumeEnabled(int nativeDeviceType, 1834 @NonNull String address, boolean enabled, int streamToDriveAbs); 1835 /** @hide */ 1836 @UnsupportedAppUsage initStreamVolume(int stream, int indexMin, int indexMax)1837 public static native int initStreamVolume(int stream, int indexMin, int indexMax); 1838 @UnsupportedAppUsage setStreamVolumeIndex(int stream, int index, boolean muted, int device)1839 private static native int setStreamVolumeIndex(int stream, int index, boolean muted, 1840 int device); 1841 /** @hide */ getStreamVolumeIndex(int stream, int device)1842 public static native int getStreamVolumeIndex(int stream, int device); 1843 /** 1844 * @hide 1845 * set a volume for the given {@link AudioAttributes} and for all other stream that belong to 1846 * the same volume group. 1847 * @param attributes the {@link AudioAttributes} to be considered 1848 * @param index to be applied 1849 * @param device the volume device to be considered 1850 * @return command completion status. 1851 */ setVolumeIndexForAttributes(@onNull AudioAttributes attributes, int index, boolean muted, int device)1852 public static native int setVolumeIndexForAttributes(@NonNull AudioAttributes attributes, 1853 int index, boolean muted, int device); 1854 /** 1855 * @hide 1856 * get the volume index for the given {@link AudioAttributes}. 1857 * @param attributes the {@link AudioAttributes} to be considered 1858 * @param device the volume device to be considered 1859 * @return volume index for the given {@link AudioAttributes} and volume device. 1860 */ getVolumeIndexForAttributes(@onNull AudioAttributes attributes, int device)1861 public static native int getVolumeIndexForAttributes(@NonNull AudioAttributes attributes, 1862 int device); 1863 /** 1864 * @hide 1865 * get the minimum volume index for the given {@link AudioAttributes}. 1866 * @param attributes the {@link AudioAttributes} to be considered 1867 * @return minimum volume index for the given {@link AudioAttributes}. 1868 */ getMinVolumeIndexForAttributes(@onNull AudioAttributes attributes)1869 public static native int getMinVolumeIndexForAttributes(@NonNull AudioAttributes attributes); 1870 /** 1871 * @hide 1872 * get the maximum volume index for the given {@link AudioAttributes}. 1873 * @param attributes the {@link AudioAttributes} to be considered 1874 * @return maximum volume index for the given {@link AudioAttributes}. 1875 */ getMaxVolumeIndexForAttributes(@onNull AudioAttributes attributes)1876 public static native int getMaxVolumeIndexForAttributes(@NonNull AudioAttributes attributes); 1877 1878 /** @hide */ setMasterVolume(float value)1879 public static native int setMasterVolume(float value); 1880 /** @hide */ getMasterVolume()1881 public static native float getMasterVolume(); 1882 /** @hide */ 1883 @UnsupportedAppUsage setMasterMute(boolean mute)1884 public static native int setMasterMute(boolean mute); 1885 /** @hide */ 1886 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getMasterMute()1887 public static native boolean getMasterMute(); 1888 /** @hide 1889 * Only used (unsupported) for legacy apps. 1890 * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices 1891 * will have multi-bit device types. 1892 * Use {@link AudioManager#getDevicesForAttributes(AudioAttributes)} instead. 1893 */ 1894 @UnsupportedAppUsage 1895 @Deprecated getDevicesForStream(int stream)1896 public static int getDevicesForStream(int stream) { 1897 final AudioAttributes attr = 1898 AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType(stream); 1899 return getDeviceMaskFromSet(generateAudioDeviceTypesSet( 1900 getDevicesForAttributes(attr, true /* forVolume */))); 1901 } 1902 1903 /** @hide 1904 * Conversion from a device set to a bit mask. 1905 * 1906 * Legacy compatibility method (use a device list instead of a bit mask). 1907 * Conversion to bit mask skips multi-bit (S and later) internal device types 1908 * (e.g. AudioSystem.DEVICE_OUT* or AudioManager.DEVICE_OUT*) for legacy 1909 * compatibility reasons. Legacy apps will not understand these new device types 1910 * and it will raise false matches with old device types. 1911 */ getDeviceMaskFromSet(@onNull Set<Integer> deviceSet)1912 public static int getDeviceMaskFromSet(@NonNull Set<Integer> deviceSet) { 1913 int deviceMask = DEVICE_NONE; // zero. 1914 int deviceInChecksum = DEVICE_BIT_IN; 1915 for (Integer device : deviceSet) { 1916 if ((device & (device - 1) & ~DEVICE_BIT_IN) != 0) { 1917 Log.v(TAG, "getDeviceMaskFromSet skipping multi-bit device value " + device); 1918 continue; 1919 } 1920 deviceMask |= device; 1921 deviceInChecksum &= device; 1922 } 1923 // Validate that deviceSet is either ALL input devices or ALL output devices. 1924 // We check that the "OR" of all the DEVICE_BIT_INs == the "AND" of all DEVICE_BIT_INs. 1925 if (!deviceSet.isEmpty() && deviceInChecksum != (deviceMask & DEVICE_BIT_IN)) { 1926 Log.e(TAG, "getDeviceMaskFromSet: Invalid set: " + deviceSetToString(deviceSet)); 1927 } 1928 return deviceMask; 1929 } 1930 1931 /** @hide */ 1932 @NonNull deviceSetToString(@onNull Set<Integer> devices)1933 public static String deviceSetToString(@NonNull Set<Integer> devices) { 1934 int n = 0; 1935 StringBuilder sb = new StringBuilder(); 1936 for (Integer device : devices) { 1937 if (n++ > 0) { 1938 sb.append(", "); 1939 } 1940 sb.append(AudioSystem.getDeviceName(device)); 1941 sb.append("(" + Integer.toHexString(device) + ")"); 1942 } 1943 return sb.toString(); 1944 } 1945 1946 /** 1947 * @hide 1948 * Do not use directly, see {@link AudioManager#getDevicesForAttributes(AudioAttributes)} 1949 * Get the audio devices that would be used for the routing of the given audio attributes. 1950 * @param attributes the {@link AudioAttributes} for which the routing is being queried 1951 * @return an empty list if there was an issue with the request, a list of audio devices 1952 * otherwise (typically one device, except for duplicated paths). 1953 */ getDevicesForAttributes( @onNull AudioAttributes attributes, boolean forVolume)1954 public static @NonNull ArrayList<AudioDeviceAttributes> getDevicesForAttributes( 1955 @NonNull AudioAttributes attributes, boolean forVolume) { 1956 Objects.requireNonNull(attributes); 1957 final AudioDeviceAttributes[] devices = new AudioDeviceAttributes[MAX_DEVICE_ROUTING]; 1958 final int res = getDevicesForAttributes(attributes, devices, forVolume); 1959 final ArrayList<AudioDeviceAttributes> routeDevices = new ArrayList<>(); 1960 if (res != SUCCESS) { 1961 Log.e(TAG, "error " + res + " in getDevicesForAttributes attributes: " + attributes 1962 + " forVolume: " + forVolume); 1963 return routeDevices; 1964 } 1965 1966 for (AudioDeviceAttributes device : devices) { 1967 if (device != null) { 1968 routeDevices.add(device); 1969 } 1970 } 1971 return routeDevices; 1972 } 1973 1974 /** 1975 * Maximum number of audio devices a track is ever routed to, determines the size of the 1976 * array passed to {@link #getDevicesForAttributes(AudioAttributes, AudioDeviceAttributes[])} 1977 */ 1978 private static final int MAX_DEVICE_ROUTING = 4; 1979 getDevicesForAttributes(@onNull AudioAttributes aa, @NonNull AudioDeviceAttributes[] devices, boolean forVolume)1980 private static native int getDevicesForAttributes(@NonNull AudioAttributes aa, 1981 @NonNull AudioDeviceAttributes[] devices, 1982 boolean forVolume); 1983 1984 /** @hide returns true if master mono is enabled. */ getMasterMono()1985 public static native boolean getMasterMono(); 1986 /** @hide enables or disables the master mono mode. */ setMasterMono(boolean mono)1987 public static native int setMasterMono(boolean mono); 1988 /** @hide enables or disables the RTT mode. */ setRttEnabled(boolean enabled)1989 public static native int setRttEnabled(boolean enabled); 1990 1991 /** @hide returns master balance value in range -1.f -> 1.f, where 0.f is dead center. */ 1992 @TestApi 1993 @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS) getMasterBalance()1994 public static native float getMasterBalance(); 1995 /** @hide Changes the audio balance of the device. */ 1996 @TestApi 1997 @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS) setMasterBalance(float balance)1998 public static native int setMasterBalance(float balance); 1999 2000 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 2001 /** @hide */ 2002 @UnsupportedAppUsage(trackingBug = 134049522) getPrimaryOutputSamplingRate()2003 public static native int getPrimaryOutputSamplingRate(); 2004 /** @hide */ 2005 @UnsupportedAppUsage(trackingBug = 134049522) getPrimaryOutputFrameCount()2006 public static native int getPrimaryOutputFrameCount(); 2007 /** @hide */ 2008 @UnsupportedAppUsage getOutputLatency(int stream)2009 public static native int getOutputLatency(int stream); 2010 2011 /** @hide */ setLowRamDevice(boolean isLowRamDevice, long totalMemory)2012 public static native int setLowRamDevice(boolean isLowRamDevice, long totalMemory); 2013 /** @hide */ 2014 @UnsupportedAppUsage checkAudioFlinger()2015 public static native int checkAudioFlinger(); 2016 /** @hide */ setAudioFlingerBinder(IBinder audioFlinger)2017 public static native void setAudioFlingerBinder(IBinder audioFlinger); 2018 2019 /** @hide */ listAudioPorts(ArrayList<AudioPort> ports, int[] generation)2020 public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); 2021 /** @hide */ getSupportedDeviceTypes(int flags, IntArray internalDeviceTypes)2022 public static native int getSupportedDeviceTypes(int flags, IntArray internalDeviceTypes); 2023 /** @hide */ createAudioPatch(AudioPatch[] patch, AudioPortConfig[] sources, AudioPortConfig[] sinks)2024 public static native int createAudioPatch(AudioPatch[] patch, 2025 AudioPortConfig[] sources, AudioPortConfig[] sinks); 2026 /** @hide */ releaseAudioPatch(AudioPatch patch)2027 public static native int releaseAudioPatch(AudioPatch patch); 2028 /** @hide */ listAudioPatches(ArrayList<AudioPatch> patches, int[] generation)2029 public static native int listAudioPatches(ArrayList<AudioPatch> patches, int[] generation); 2030 /** @hide */ setAudioPortConfig(AudioPortConfig config)2031 public static native int setAudioPortConfig(AudioPortConfig config); 2032 2033 /** @hide */ startAudioSource(AudioPortConfig config, AudioAttributes audioAttributes)2034 public static native int startAudioSource(AudioPortConfig config, 2035 AudioAttributes audioAttributes); 2036 /** @hide */ stopAudioSource(int handle)2037 public static native int stopAudioSource(int handle); 2038 2039 // declare this instance as having a dynamic policy callback handler native_register_dynamic_policy_callback()2040 private static native final void native_register_dynamic_policy_callback(); 2041 // declare this instance as having a recording configuration update callback handler native_register_recording_callback()2042 private static native final void native_register_recording_callback(); 2043 // declare this instance as having a routing update callback handler native_register_routing_callback()2044 private static native void native_register_routing_callback(); 2045 // declare this instance as having a volume range init request handler native_register_vol_range_init_req_callback()2046 private static native void native_register_vol_range_init_req_callback(); 2047 2048 // must be kept in sync with value in include/system/audio.h 2049 /** @hide */ public static final int AUDIO_HW_SYNC_INVALID = 0; 2050 2051 /** @hide */ getAudioHwSyncForSession(int sessionId)2052 public static native int getAudioHwSyncForSession(int sessionId); 2053 2054 /** @hide */ registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register)2055 public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); 2056 2057 /** @hide */ getRegisteredPolicyMixes(@onNull List<AudioMix> devices)2058 public static native int getRegisteredPolicyMixes(@NonNull List<AudioMix> devices); 2059 2060 /** @hide */ updatePolicyMixes( AudioMix[] mixes, AudioMixingRule[] updatedMixingRules)2061 public static native int updatePolicyMixes( 2062 AudioMix[] mixes, 2063 AudioMixingRule[] updatedMixingRules); 2064 2065 /** @hide see AudioPolicy.setUidDeviceAffinities() */ setUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses)2066 public static native int setUidDeviceAffinities(int uid, @NonNull int[] types, 2067 @NonNull String[] addresses); 2068 2069 /** @hide see AudioPolicy.removeUidDeviceAffinities() */ removeUidDeviceAffinities(int uid)2070 public static native int removeUidDeviceAffinities(int uid); 2071 2072 /** @hide see AudioPolicy.setUserIdDeviceAffinities() */ setUserIdDeviceAffinities(int userId, @NonNull int[] types, @NonNull String[] addresses)2073 public static native int setUserIdDeviceAffinities(int userId, @NonNull int[] types, 2074 @NonNull String[] addresses); 2075 2076 /** @hide see AudioPolicy.removeUserIdDeviceAffinities() */ removeUserIdDeviceAffinities(int userId)2077 public static native int removeUserIdDeviceAffinities(int userId); 2078 2079 /** @hide */ systemReady()2080 public static native int systemReady(); 2081 2082 /** @hide */ getStreamVolumeDB(int stream, int index, int device)2083 public static native float getStreamVolumeDB(int stream, int index, int device); 2084 2085 /** 2086 * @hide 2087 * Communicate supported system usages to audio policy service. 2088 */ setSupportedSystemUsages(int[] systemUsages)2089 public static native int setSupportedSystemUsages(int[] systemUsages); 2090 2091 /** 2092 * @hide 2093 * @see AudioManager#setAllowedCapturePolicy() 2094 */ setAllowedCapturePolicy(int uid, int flags)2095 public static native int setAllowedCapturePolicy(int uid, int flags); 2096 2097 /** 2098 * @hide 2099 * Direct playback modes supported by audio HAL implementation. 2100 */ 2101 public static final int DIRECT_NOT_SUPPORTED = 0; 2102 public static final int DIRECT_OFFLOAD_SUPPORTED = 1; 2103 public static final int DIRECT_OFFLOAD_GAPLESS_SUPPORTED = 3; 2104 public static final int DIRECT_BITSTREAM_SUPPORTED = 4; 2105 2106 /** 2107 * @hide 2108 * Compressed audio offload decoding modes supported by audio HAL implementation. 2109 * Keep in sync with system/media/include/media/audio.h. 2110 */ 2111 public static final int OFFLOAD_NOT_SUPPORTED = DIRECT_NOT_SUPPORTED; 2112 public static final int OFFLOAD_SUPPORTED = DIRECT_OFFLOAD_SUPPORTED; 2113 public static final int OFFLOAD_GAPLESS_SUPPORTED = 2; 2114 2115 /** 2116 * @hide 2117 * Returns how direct playback of an audio format is currently available on the device. 2118 * @param format the audio format (codec, sample rate, channels) being checked. 2119 * @param attributes the {@link AudioAttributes} to be used for playback 2120 * @return the direct playback mode available with given format and attributes. Any combination 2121 * of {@link #DIRECT_NOT_SUPPORTED}, {@link #DIRECT_OFFLOAD_SUPPORTED}, 2122 * {@link #DIRECT_OFFLOAD_GAPLESS_SUPPORTED} and {@link #DIRECT_BITSTREAM_SUPPORTED}. 2123 */ getDirectPlaybackSupport( @onNull AudioFormat format, @NonNull AudioAttributes attributes)2124 public static native int getDirectPlaybackSupport( 2125 @NonNull AudioFormat format, @NonNull AudioAttributes attributes); 2126 getOffloadSupport(@onNull AudioFormat format, @NonNull AudioAttributes attr)2127 static int getOffloadSupport(@NonNull AudioFormat format, @NonNull AudioAttributes attr) { 2128 return native_get_offload_support(format.getEncoding(), format.getSampleRate(), 2129 format.getChannelMask(), format.getChannelIndexMask(), 2130 attr.getVolumeControlStream()); 2131 } 2132 native_get_offload_support(int encoding, int sampleRate, int channelMask, int channelIndexMask, int streamType)2133 private static native int native_get_offload_support(int encoding, int sampleRate, 2134 int channelMask, int channelIndexMask, int streamType); 2135 2136 /** @hide */ getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo)2137 public static native int getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo); 2138 2139 /** @hide */ getSurroundFormats(Map<Integer, Boolean> surroundFormats)2140 public static native int getSurroundFormats(Map<Integer, Boolean> surroundFormats); 2141 2142 /** @hide */ getReportedSurroundFormats(ArrayList<Integer> surroundFormats)2143 public static native int getReportedSurroundFormats(ArrayList<Integer> surroundFormats); 2144 2145 /** 2146 * @hide 2147 * Returns a list of audio formats (codec) supported on the A2DP and LE audio offload path. 2148 */ getHwOffloadFormatsSupportedForBluetoothMedia( @tOffloadDeviceType int deviceType, ArrayList<Integer> formatList)2149 public static native int getHwOffloadFormatsSupportedForBluetoothMedia( 2150 @BtOffloadDeviceType int deviceType, ArrayList<Integer> formatList); 2151 2152 /** @hide */ setSurroundFormatEnabled(int audioFormat, boolean enabled)2153 public static native int setSurroundFormatEnabled(int audioFormat, boolean enabled); 2154 2155 /** 2156 * @hide 2157 * Communicate UIDs of the active assistant to audio policy service. 2158 */ setActiveAssistantServicesUids(int[] uids)2159 public static native int setActiveAssistantServicesUids(int[] uids); 2160 2161 /** 2162 * @hide 2163 * Communicate UIDs of assistant to audio policy service. 2164 */ setAssistantServicesUids(int[] uids)2165 public static native int setAssistantServicesUids(int[] uids); 2166 2167 /** 2168 * @hide 2169 * Communicate UIDs of active accessibility services to audio policy service. 2170 */ setA11yServicesUids(int[] uids)2171 public static native int setA11yServicesUids(int[] uids); 2172 2173 /** 2174 * @hide 2175 * Communicate UID of current InputMethodService to audio policy service. 2176 */ setCurrentImeUid(int uid)2177 public static native int setCurrentImeUid(int uid); 2178 2179 2180 /** 2181 * @hide 2182 * @see AudioManager#isHapticPlaybackSupported() 2183 */ isHapticPlaybackSupported()2184 public static native boolean isHapticPlaybackSupported(); 2185 2186 /** 2187 * @hide 2188 * @see AudioManager#isUltrasoundSupported() 2189 */ isUltrasoundSupported()2190 public static native boolean isUltrasoundSupported(); 2191 2192 /** 2193 * @hide 2194 * Send audio HAL server process pids to native audioserver process for use 2195 * when generating audio HAL servers tombstones 2196 */ setAudioHalPids(int[] pids)2197 public static native int setAudioHalPids(int[] pids); 2198 2199 /** 2200 * @hide 2201 * @see AudioManager#isCallScreeningModeSupported() 2202 */ isCallScreeningModeSupported()2203 public static native boolean isCallScreeningModeSupported(); 2204 2205 // use case routing by product strategy 2206 2207 /** 2208 * @hide 2209 * Set device as role for product strategy. 2210 * @param strategy the id of the strategy to configure 2211 * @param role the role of the devices 2212 * @param devices the list of devices to be set as role for the given strategy 2213 * @return {@link #SUCCESS} if successfully set 2214 */ setDevicesRoleForStrategy( int strategy, int role, @NonNull List<AudioDeviceAttributes> devices)2215 public static int setDevicesRoleForStrategy( 2216 int strategy, int role, @NonNull List<AudioDeviceAttributes> devices) { 2217 if (devices.isEmpty()) { 2218 return BAD_VALUE; 2219 } 2220 int[] types = new int[devices.size()]; 2221 String[] addresses = new String[devices.size()]; 2222 for (int i = 0; i < devices.size(); ++i) { 2223 types[i] = devices.get(i).getInternalType(); 2224 addresses[i] = devices.get(i).getAddress(); 2225 } 2226 return setDevicesRoleForStrategy(strategy, role, types, addresses); 2227 } 2228 2229 /** 2230 * @hide 2231 * Set device as role for product strategy. 2232 * @param strategy the id of the strategy to configure 2233 * @param role the role of the devices 2234 * @param types all device types 2235 * @param addresses all device addresses 2236 * @return {@link #SUCCESS} if successfully set 2237 */ setDevicesRoleForStrategy( int strategy, int role, @NonNull int[] types, @NonNull String[] addresses)2238 private static native int setDevicesRoleForStrategy( 2239 int strategy, int role, @NonNull int[] types, @NonNull String[] addresses); 2240 2241 /** 2242 * @hide 2243 * Remove device as role for product strategy. 2244 * @param strategy the id of the strategy to configure 2245 * @param role the role of the devices 2246 * @param devices the list of devices to be removed as role for the given strategy 2247 * @return {@link #SUCCESS} if successfully set 2248 */ removeDevicesRoleForStrategy( int strategy, int role, @NonNull List<AudioDeviceAttributes> devices)2249 public static int removeDevicesRoleForStrategy( 2250 int strategy, int role, @NonNull List<AudioDeviceAttributes> devices) { 2251 if (devices.isEmpty()) { 2252 return BAD_VALUE; 2253 } 2254 int[] types = new int[devices.size()]; 2255 String[] addresses = new String[devices.size()]; 2256 for (int i = 0; i < devices.size(); ++i) { 2257 types[i] = devices.get(i).getInternalType(); 2258 addresses[i] = devices.get(i).getAddress(); 2259 } 2260 return removeDevicesRoleForStrategy(strategy, role, types, addresses); 2261 } 2262 2263 /** 2264 * @hide 2265 * Remove devices as role for the strategy 2266 * @param strategy the id of the strategy to configure 2267 * @param role the role of the devices 2268 * @param types all device types 2269 * @param addresses all device addresses 2270 * @return {@link #SUCCESS} if successfully removed 2271 */ removeDevicesRoleForStrategy( int strategy, int role, @NonNull int[] types, @NonNull String[] addresses)2272 public static native int removeDevicesRoleForStrategy( 2273 int strategy, int role, @NonNull int[] types, @NonNull String[] addresses); 2274 2275 /** 2276 * @hide 2277 * Remove all devices as role for the strategy 2278 * @param strategy the id of the strategy to configure 2279 * @param role the role of the devices 2280 * @return {@link #SUCCESS} if successfully removed 2281 */ clearDevicesRoleForStrategy(int strategy, int role)2282 public static native int clearDevicesRoleForStrategy(int strategy, int role); 2283 2284 /** 2285 * @hide 2286 * Query previously set devices as role for a strategy 2287 * @param strategy the id of the strategy to query for 2288 * @param role the role of the devices 2289 * @param devices a list that will contain the devices of role 2290 * @return {@link #SUCCESS} if there is a preferred device and it was successfully retrieved 2291 * and written to the array 2292 */ getDevicesForRoleAndStrategy( int strategy, int role, @NonNull List<AudioDeviceAttributes> devices)2293 public static native int getDevicesForRoleAndStrategy( 2294 int strategy, int role, @NonNull List<AudioDeviceAttributes> devices); 2295 2296 // use case routing by capture preset 2297 populateInputDevicesTypeAndAddress( @onNull List<AudioDeviceAttributes> devices)2298 private static Pair<int[], String[]> populateInputDevicesTypeAndAddress( 2299 @NonNull List<AudioDeviceAttributes> devices) { 2300 int[] types = new int[devices.size()]; 2301 String[] addresses = new String[devices.size()]; 2302 for (int i = 0; i < devices.size(); ++i) { 2303 types[i] = devices.get(i).getInternalType(); 2304 if (types[i] == AudioSystem.DEVICE_NONE) { 2305 types[i] = AudioDeviceInfo.convertDeviceTypeToInternalInputDevice( 2306 devices.get(i).getType(), devices.get(i).getAddress()); 2307 } 2308 addresses[i] = devices.get(i).getAddress(); 2309 } 2310 return new Pair<int[], String[]>(types, addresses); 2311 } 2312 2313 /** 2314 * @hide 2315 * Set devices as role for capture preset. 2316 * @param capturePreset the capture preset to configure 2317 * @param role the role of the devices 2318 * @param devices the list of devices to be set as role for the given capture preset 2319 * @return {@link #SUCCESS} if successfully set 2320 */ setDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices)2321 public static int setDevicesRoleForCapturePreset( 2322 int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices) { 2323 if (devices.isEmpty()) { 2324 return BAD_VALUE; 2325 } 2326 Pair<int[], String[]> typeAddresses = populateInputDevicesTypeAndAddress(devices); 2327 return setDevicesRoleForCapturePreset( 2328 capturePreset, role, typeAddresses.first, typeAddresses.second); 2329 } 2330 2331 /** 2332 * @hide 2333 * Set devices as role for capture preset. 2334 * @param capturePreset the capture preset to configure 2335 * @param role the role of the devices 2336 * @param types all device types 2337 * @param addresses all device addresses 2338 * @return {@link #SUCCESS} if successfully set 2339 */ setDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses)2340 private static native int setDevicesRoleForCapturePreset( 2341 int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses); 2342 2343 /** 2344 * @hide 2345 * Add devices as role for capture preset. 2346 * @param capturePreset the capture preset to configure 2347 * @param role the role of the devices 2348 * @param devices the list of devices to be added as role for the given capture preset 2349 * @return {@link #SUCCESS} if successfully add 2350 */ addDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices)2351 public static int addDevicesRoleForCapturePreset( 2352 int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices) { 2353 if (devices.isEmpty()) { 2354 return BAD_VALUE; 2355 } 2356 Pair<int[], String[]> typeAddresses = populateInputDevicesTypeAndAddress(devices); 2357 return addDevicesRoleForCapturePreset( 2358 capturePreset, role, typeAddresses.first, typeAddresses.second); 2359 } 2360 2361 /** 2362 * @hide 2363 * Add devices as role for capture preset. 2364 * @param capturePreset the capture preset to configure 2365 * @param role the role of the devices 2366 * @param types all device types 2367 * @param addresses all device addresses 2368 * @return {@link #SUCCESS} if successfully set 2369 */ addDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses)2370 private static native int addDevicesRoleForCapturePreset( 2371 int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses); 2372 2373 /** 2374 * @hide 2375 * Remove devices as role for the capture preset 2376 * @param capturePreset the capture preset to configure 2377 * @param role the role of the devices 2378 * @param devices the devices to be removed 2379 * @return {@link #SUCCESS} if successfully removed 2380 */ removeDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices)2381 public static int removeDevicesRoleForCapturePreset( 2382 int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices) { 2383 if (devices.isEmpty()) { 2384 return BAD_VALUE; 2385 } 2386 Pair<int[], String[]> typeAddresses = populateInputDevicesTypeAndAddress(devices); 2387 return removeDevicesRoleForCapturePreset( 2388 capturePreset, role, typeAddresses.first, typeAddresses.second); 2389 } 2390 2391 /** 2392 * @hide 2393 * Remove devices as role for capture preset. 2394 * @param capturePreset the capture preset to configure 2395 * @param role the role of the devices 2396 * @param types all device types 2397 * @param addresses all device addresses 2398 * @return {@link #SUCCESS} if successfully set 2399 */ removeDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses)2400 private static native int removeDevicesRoleForCapturePreset( 2401 int capturePreset, int role, @NonNull int[] types, @NonNull String[] addresses); 2402 2403 /** 2404 * @hide 2405 * Remove all devices as role for the capture preset 2406 * @param capturePreset the capture preset to configure 2407 * @param role the role of the devices 2408 * @return {@link #SUCCESS} if successfully removed 2409 */ clearDevicesRoleForCapturePreset(int capturePreset, int role)2410 public static native int clearDevicesRoleForCapturePreset(int capturePreset, int role); 2411 2412 /** 2413 * @hide 2414 * Query previously set devices as role for a capture preset 2415 * @param capturePreset the capture preset to query for 2416 * @param role the role of the devices 2417 * @param devices a list that will contain the devices of role 2418 * @return {@link #SUCCESS} if there is a preferred device and it was successfully retrieved 2419 * and written to the array 2420 */ getDevicesForRoleAndCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices)2421 public static native int getDevicesForRoleAndCapturePreset( 2422 int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices); 2423 2424 /** 2425 * @hide 2426 * Set the vibrators' information. The value will be used to initialize HapticGenerator. 2427 * @param vibrators a list of all available vibrators 2428 * @return command completion status 2429 */ setVibratorInfos(@onNull List<Vibrator> vibrators)2430 public static native int setVibratorInfos(@NonNull List<Vibrator> vibrators); 2431 2432 /** 2433 * @hide 2434 * If a spatializer effect is present on the platform, this will return an 2435 * ISpatializer interface to control this feature. 2436 * If no spatializer is present, a null interface is returned. 2437 * The INativeSpatializerCallback passed must not be null. 2438 * Only one ISpatializer interface can exist at a given time. The native audio policy 2439 * service will reject the request if an interface was already acquired and previous owner 2440 * did not die or call ISpatializer.release(). 2441 * @param callback the callback to receive state updates if the ISpatializer 2442 * interface is acquired. 2443 * @return the ISpatializer interface made available to control the 2444 * platform spatializer 2445 */ 2446 @Nullable getSpatializer(INativeSpatializerCallback callback)2447 public static ISpatializer getSpatializer(INativeSpatializerCallback callback) { 2448 return ISpatializer.Stub.asInterface(nativeGetSpatializer(callback)); 2449 } nativeGetSpatializer(INativeSpatializerCallback callback)2450 private static native IBinder nativeGetSpatializer(INativeSpatializerCallback callback); 2451 2452 /** 2453 * @hide 2454 * Queries if some kind of spatialization will be performed if the audio playback context 2455 * described by the provided arguments is present. 2456 * The context is made of: 2457 * - The audio attributes describing the playback use case. 2458 * - The audio configuration describing the audio format, channels, sampling rate ... 2459 * - The devices describing the sink audio device selected for playback. 2460 * All arguments are optional and only the specified arguments are used to match against 2461 * supported criteria. For instance, supplying no argument will tell if spatialization is 2462 * supported or not in general. 2463 * @param attributes audio attributes describing the playback use case 2464 * @param format audio configuration describing the audio format, channels, sampling rate... 2465 * @param devices the sink audio device selected for playback 2466 * @return true if spatialization is enabled for this context, false otherwise. 2467 */ canBeSpatialized(AudioAttributes attributes, AudioFormat format, AudioDeviceAttributes[] devices)2468 public static native boolean canBeSpatialized(AudioAttributes attributes, 2469 AudioFormat format, 2470 AudioDeviceAttributes[] devices); 2471 2472 /** 2473 * @hide 2474 * Register the sound dose callback with the audio server and returns the binder to the 2475 * ISoundDose interface. 2476 * 2477 * @return ISoundDose interface with registered callback. 2478 */ 2479 @Nullable getSoundDoseInterface(ISoundDoseCallback callback)2480 public static ISoundDose getSoundDoseInterface(ISoundDoseCallback callback) { 2481 return ISoundDose.Stub.asInterface(nativeGetSoundDose(callback)); 2482 } 2483 nativeGetSoundDose(ISoundDoseCallback callback)2484 private static native IBinder nativeGetSoundDose(ISoundDoseCallback callback); 2485 2486 /** 2487 * @hide 2488 * @param attributes audio attributes describing the playback use case 2489 * @param audioProfilesList the list of AudioProfiles that can be played as direct output 2490 * @return {@link #SUCCESS} if the list of AudioProfiles was successfully created (can be empty) 2491 */ getDirectProfilesForAttributes(@onNull AudioAttributes attributes, @NonNull ArrayList<AudioProfile> audioProfilesList)2492 public static native int getDirectProfilesForAttributes(@NonNull AudioAttributes attributes, 2493 @NonNull ArrayList<AudioProfile> audioProfilesList); 2494 2495 // Items shared with audio service 2496 2497 /** 2498 * @hide 2499 * The delay before playing a sound. This small period exists so the user 2500 * can press another key (non-volume keys, too) to have it NOT be audible. 2501 * <p> 2502 * PhoneWindow will implement this part. 2503 */ 2504 public static final int PLAY_SOUND_DELAY = 300; 2505 2506 /** 2507 * @hide 2508 * Constant to identify a focus stack entry that is used to hold the focus while the phone 2509 * is ringing or during a call. Used by com.android.internal.telephony.CallManager when 2510 * entering and exiting calls. 2511 */ 2512 public final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls"; 2513 2514 /** 2515 * @hide 2516 * @see AudioManager#setVibrateSetting(int, int) 2517 */ getValueForVibrateSetting(int existingValue, int vibrateType, int vibrateSetting)2518 public static int getValueForVibrateSetting(int existingValue, int vibrateType, 2519 int vibrateSetting) { 2520 2521 // First clear the existing setting. Each vibrate type has two bits in 2522 // the value. Note '3' is '11' in binary. 2523 existingValue &= ~(3 << (vibrateType * 2)); 2524 2525 // Set into the old value 2526 existingValue |= (vibrateSetting & 3) << (vibrateType * 2); 2527 2528 return existingValue; 2529 } 2530 2531 /** @hide */ getDefaultStreamVolume(int streamType)2532 public static int getDefaultStreamVolume(int streamType) { 2533 return DEFAULT_STREAM_VOLUME[streamType]; 2534 } 2535 2536 /** @hide */ 2537 public static int[] DEFAULT_STREAM_VOLUME = new int[] { 2538 4, // STREAM_VOICE_CALL 2539 7, // STREAM_SYSTEM 2540 5, // STREAM_RING // configured in AudioService by config_audio_notif_vol_default 2541 5, // STREAM_MUSIC 2542 6, // STREAM_ALARM 2543 5, // STREAM_NOTIFICATION // configured in AudioService by config_audio_ring_vol_default 2544 7, // STREAM_BLUETOOTH_SCO 2545 7, // STREAM_SYSTEM_ENFORCED 2546 5, // STREAM_DTMF 2547 5, // STREAM_TTS 2548 5, // STREAM_ACCESSIBILITY 2549 5, // STREAM_ASSISTANT 2550 }; 2551 2552 /** @hide */ 2553 @TestApi streamToString(int stream)2554 public static @NonNull String streamToString(int stream) { 2555 if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream]; 2556 if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE"; 2557 return "UNKNOWN_STREAM_" + stream; 2558 } 2559 2560 /** @hide The platform has no specific capabilities */ 2561 public static final int PLATFORM_DEFAULT = 0; 2562 /** @hide The platform is voice call capable (a phone) */ 2563 public static final int PLATFORM_VOICE = 1; 2564 /** @hide The platform is a television or a set-top box */ 2565 public static final int PLATFORM_TELEVISION = 2; 2566 /** @hide The platform is automotive */ 2567 public static final int PLATFORM_AUTOMOTIVE = 3; 2568 2569 /** 2570 * @hide 2571 * Return the platform type that this is running on. One of: 2572 * <ul> 2573 * <li>{@link #PLATFORM_VOICE}</li> 2574 * <li>{@link #PLATFORM_TELEVISION}</li> 2575 * <li>{@link #PLATFORM_DEFAULT}</li> 2576 * </ul> 2577 */ getPlatformType(Context context)2578 public static int getPlatformType(Context context) { 2579 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { 2580 return PLATFORM_AUTOMOTIVE; 2581 } else if ((context.getSystemService(TelephonyManager.class)).isVoiceCapable()) { 2582 return PLATFORM_VOICE; 2583 } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 2584 return PLATFORM_TELEVISION; 2585 } else { 2586 return PLATFORM_DEFAULT; 2587 } 2588 } 2589 2590 /** 2591 * @hide 2592 * @return whether the system uses a single volume stream. 2593 */ isSingleVolume(Context context)2594 public static boolean isSingleVolume(Context context) { 2595 boolean forceSingleVolume = context.getResources().getBoolean( 2596 com.android.internal.R.bool.config_single_volume); 2597 return getPlatformType(context) == PLATFORM_TELEVISION || forceSingleVolume; 2598 } 2599 2600 /** 2601 * @hide 2602 * Return a set of audio device types from a list of audio device attributes, which may 2603 * represent multiple audio device types. 2604 */ 2605 @NonNull generateAudioDeviceTypesSet( @onNull List<AudioDeviceAttributes> deviceList)2606 public static Set<Integer> generateAudioDeviceTypesSet( 2607 @NonNull List<AudioDeviceAttributes> deviceList) { 2608 Set<Integer> deviceTypes = new TreeSet<>(); 2609 for (AudioDeviceAttributes device : deviceList) { 2610 deviceTypes.add(device.getInternalType()); 2611 } 2612 return deviceTypes; 2613 } 2614 2615 /** 2616 * @hide 2617 * Return the intersection of two audio device types collections. 2618 */ intersectionAudioDeviceTypes( @onNull Set<Integer> a, @NonNull Set<Integer> b)2619 public static Set<Integer> intersectionAudioDeviceTypes( 2620 @NonNull Set<Integer> a, @NonNull Set<Integer> b) { 2621 Set<Integer> intersection = new TreeSet<>(a); 2622 intersection.retainAll(b); 2623 return intersection; 2624 } 2625 2626 /** 2627 * @hide 2628 * Return true if the audio device types collection only contains the given device type. 2629 */ isSingleAudioDeviceType(@onNull Set<Integer> types, int type)2630 public static boolean isSingleAudioDeviceType(@NonNull Set<Integer> types, int type) { 2631 return types.size() == 1 && types.contains(type); 2632 } 2633 2634 /** 2635 * @hide 2636 * Return true if the audio device type is a Bluetooth LE Audio device. 2637 */ isLeAudioDeviceType(int type)2638 public static boolean isLeAudioDeviceType(int type) { 2639 return DEVICE_OUT_ALL_BLE_SET.contains(type); 2640 } 2641 2642 /** @hide */ 2643 public static final int DEFAULT_MUTE_STREAMS_AFFECTED = 2644 (1 << STREAM_MUSIC) | 2645 (1 << STREAM_RING) | 2646 (1 << STREAM_NOTIFICATION) | 2647 (1 << STREAM_SYSTEM) | 2648 (1 << STREAM_VOICE_CALL) | 2649 (1 << STREAM_BLUETOOTH_SCO); 2650 2651 /** 2652 * @hide 2653 * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes. 2654 * Keep in sync with core/jni/android_media_DeviceCallback.h. 2655 */ 2656 final static int NATIVE_EVENT_ROUTING_CHANGE = 1000; 2657 2658 /** 2659 * @hide 2660 * Query the mixer attributes that can be set as preferred mixer attributes for the given 2661 * device. 2662 */ getSupportedMixerAttributes( int deviceId, @NonNull List<AudioMixerAttributes> mixerAttrs)2663 public static native int getSupportedMixerAttributes( 2664 int deviceId, @NonNull List<AudioMixerAttributes> mixerAttrs); 2665 2666 /** 2667 * @hide 2668 * Set preferred mixer attributes for a given device when playing particular 2669 * audio attributes. 2670 */ setPreferredMixerAttributes( @onNull AudioAttributes attributes, int portId, int uid, @NonNull AudioMixerAttributes mixerAttributes)2671 public static native int setPreferredMixerAttributes( 2672 @NonNull AudioAttributes attributes, 2673 int portId, 2674 int uid, 2675 @NonNull AudioMixerAttributes mixerAttributes); 2676 2677 /** 2678 * @hide 2679 * Get preferred mixer attributes that is previously set via 2680 * {link #setPreferredMixerAttributes}. 2681 */ getPreferredMixerAttributes( @onNull AudioAttributes attributes, int portId, List<AudioMixerAttributes> mixerAttributesList)2682 public static native int getPreferredMixerAttributes( 2683 @NonNull AudioAttributes attributes, int portId, 2684 List<AudioMixerAttributes> mixerAttributesList); 2685 2686 /** 2687 * @hide 2688 * Clear preferred mixer attributes that is previously set via 2689 * {@link #setPreferredMixerAttributes} 2690 */ clearPreferredMixerAttributes( @onNull AudioAttributes attributes, int portId, int uid)2691 public static native int clearPreferredMixerAttributes( 2692 @NonNull AudioAttributes attributes, int portId, int uid); 2693 2694 2695 /** 2696 * Requests if the implementation supports controlling the latency modes 2697 * over the Bluetooth A2DP or LE Audio links. 2698 * 2699 * @return true if supported, false otherwise 2700 * 2701 * @hide 2702 */ supportsBluetoothVariableLatency()2703 public static native boolean supportsBluetoothVariableLatency(); 2704 2705 /** 2706 * Enables or disables the variable Bluetooth latency control mechanism in the 2707 * audio framework and the audio HAL. This does not apply to the latency mode control 2708 * on the spatializer output as this is a built-in feature. 2709 * 2710 * @hide 2711 */ setBluetoothVariableLatencyEnabled(boolean enabled)2712 public static native int setBluetoothVariableLatencyEnabled(boolean enabled); 2713 2714 /** 2715 * Indicates if the variable Bluetooth latency control mechanism is enabled or disabled. 2716 * @hide 2717 */ isBluetoothVariableLatencyEnabled()2718 public static native boolean isBluetoothVariableLatencyEnabled(); 2719 2720 /** 2721 * Register a native listener for system property sysprop 2722 * @param callback the listener which fires when the property changes 2723 * @return a native handle for use in subsequent methods 2724 * @hide 2725 */ listenForSystemPropertyChange(String sysprop, Runnable callback)2726 public static native long listenForSystemPropertyChange(String sysprop, Runnable callback); 2727 2728 /** 2729 * Trigger a sysprop listener update, if the property has been updated: synchronously validating 2730 * there are no pending sysprop changes. 2731 * @param handle the handle returned by {@link listenForSystemPropertyChange} 2732 * @hide 2733 */ triggerSystemPropertyUpdate(long handle)2734 public static native void triggerSystemPropertyUpdate(long handle); 2735 2736 /** 2737 * Registers the given {@link INativeAudioVolumeGroupCallback} to native audioserver. 2738 * @param callback to register 2739 * @return {@link #SUCCESS} if successfully registered. 2740 * 2741 * @hide 2742 */ registerAudioVolumeGroupCallback( INativeAudioVolumeGroupCallback callback)2743 public static native int registerAudioVolumeGroupCallback( 2744 INativeAudioVolumeGroupCallback callback); 2745 2746 /** 2747 * Unegisters the given {@link INativeAudioVolumeGroupCallback} from native audioserver 2748 * previously registered via {@link #registerAudioVolumeGroupCallback}. 2749 * @param callback to register 2750 * @return {@link #SUCCESS} if successfully registered. 2751 * 2752 * @hide 2753 */ unregisterAudioVolumeGroupCallback( INativeAudioVolumeGroupCallback callback)2754 public static native int unregisterAudioVolumeGroupCallback( 2755 INativeAudioVolumeGroupCallback callback); 2756 } 2757