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.TestApi; 22 import android.bluetooth.BluetoothCodecConfig; 23 import android.compat.annotation.UnsupportedAppUsage; 24 import android.content.Context; 25 import android.content.pm.PackageManager; 26 import android.media.audiofx.AudioEffect; 27 import android.media.audiopolicy.AudioMix; 28 import android.telephony.TelephonyManager; 29 import android.util.Log; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.util.ArrayList; 34 import java.util.HashSet; 35 import java.util.Map; 36 import java.util.Set; 37 38 /* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET 39 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java. 40 * THANK YOU FOR YOUR COOPERATION. 41 */ 42 43 /** 44 * @hide 45 */ 46 @TestApi 47 public class AudioSystem 48 { 49 private static final boolean DEBUG_VOLUME = false; 50 51 private static final String TAG = "AudioSystem"; 52 53 // private constructor to prevent instantiating AudioSystem AudioSystem()54 private AudioSystem() { 55 throw new UnsupportedOperationException("Trying to instantiate AudioSystem"); 56 } 57 58 /* These values must be kept in sync with system/audio.h */ 59 /* 60 * If these are modified, please also update Settings.System.VOLUME_SETTINGS 61 * and attrs.xml and AudioManager.java. 62 */ 63 /** @hide Used to identify the default audio stream volume */ 64 @TestApi 65 public static final int STREAM_DEFAULT = -1; 66 /** @hide Used to identify the volume of audio streams for phone calls */ 67 public static final int STREAM_VOICE_CALL = 0; 68 /** @hide Used to identify the volume of audio streams for system sounds */ 69 public static final int STREAM_SYSTEM = 1; 70 /** @hide Used to identify the volume of audio streams for the phone ring and message alerts */ 71 public static final int STREAM_RING = 2; 72 /** @hide Used to identify the volume of audio streams for music playback */ 73 public static final int STREAM_MUSIC = 3; 74 /** @hide Used to identify the volume of audio streams for alarms */ 75 public static final int STREAM_ALARM = 4; 76 /** @hide Used to identify the volume of audio streams for notifications */ 77 public static final int STREAM_NOTIFICATION = 5; 78 /** @hide 79 * Used to identify the volume of audio streams for phone calls when connected on bluetooth */ 80 public static final int STREAM_BLUETOOTH_SCO = 6; 81 /** @hide Used to identify the volume of audio streams for enforced system sounds in certain 82 * countries (e.g camera in Japan) */ 83 @UnsupportedAppUsage 84 public static final int STREAM_SYSTEM_ENFORCED = 7; 85 /** @hide Used to identify the volume of audio streams for DTMF tones */ 86 public static final int STREAM_DTMF = 8; 87 /** @hide Used to identify the volume of audio streams exclusively transmitted through the 88 * speaker (TTS) of the device */ 89 public static final int STREAM_TTS = 9; 90 /** @hide Used to identify the volume of audio streams for accessibility prompts */ 91 public static final int STREAM_ACCESSIBILITY = 10; 92 /** 93 * @hide 94 * @deprecated Use {@link #numStreamTypes() instead} 95 */ 96 public static final int NUM_STREAMS = 5; 97 98 /** Maximum value for AudioTrack channel count 99 * @hide public for MediaCode only, do not un-hide or change to a numeric literal 100 */ 101 public static final int OUT_CHANNEL_COUNT_MAX = native_get_FCC_8(); native_get_FCC_8()102 private static native int native_get_FCC_8(); 103 104 // Expose only the getter method publicly so we can change it in the future 105 private static final int NUM_STREAM_TYPES = 11; 106 107 /** 108 * @hide 109 * @return total number of stream types 110 */ 111 @UnsupportedAppUsage 112 @TestApi getNumStreamTypes()113 public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } 114 115 /** @hide */ 116 public static final String[] STREAM_NAMES = new String[] { 117 "STREAM_VOICE_CALL", 118 "STREAM_SYSTEM", 119 "STREAM_RING", 120 "STREAM_MUSIC", 121 "STREAM_ALARM", 122 "STREAM_NOTIFICATION", 123 "STREAM_BLUETOOTH_SCO", 124 "STREAM_SYSTEM_ENFORCED", 125 "STREAM_DTMF", 126 "STREAM_TTS", 127 "STREAM_ACCESSIBILITY" 128 }; 129 130 /** 131 * @hide 132 * Sets the microphone mute on or off. 133 * 134 * @param on set <var>true</var> to mute the microphone; 135 * <var>false</var> to turn mute off 136 * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 137 */ 138 @UnsupportedAppUsage muteMicrophone(boolean on)139 public static native int muteMicrophone(boolean on); 140 141 /** 142 * @hide 143 * Checks whether the microphone mute is on or off. 144 * 145 * @return true if microphone is muted, false if it's not 146 */ 147 @UnsupportedAppUsage isMicrophoneMuted()148 public static native boolean isMicrophoneMuted(); 149 150 /* modes for setPhoneState, must match AudioSystem.h audio_mode */ 151 /** @hide */ 152 public static final int MODE_INVALID = -2; 153 /** @hide */ 154 public static final int MODE_CURRENT = -1; 155 /** @hide */ 156 public static final int MODE_NORMAL = 0; 157 /** @hide */ 158 public static final int MODE_RINGTONE = 1; 159 /** @hide */ 160 public static final int MODE_IN_CALL = 2; 161 /** @hide */ 162 public static final int MODE_IN_COMMUNICATION = 3; 163 /** @hide */ 164 public static final int NUM_MODES = 4; 165 166 /** @hide */ modeToString(int mode)167 public static String modeToString(int mode) { 168 switch (mode) { 169 case MODE_CURRENT: return "MODE_CURRENT"; 170 case MODE_IN_CALL: return "MODE_IN_CALL"; 171 case MODE_IN_COMMUNICATION: return "MODE_IN_COMMUNICATION"; 172 case MODE_INVALID: return "MODE_INVALID"; 173 case MODE_NORMAL: return "MODE_NORMAL"; 174 case MODE_RINGTONE: return "MODE_RINGTONE"; 175 default: return "unknown mode (" + mode + ")"; 176 } 177 } 178 179 /* Formats for A2DP codecs, must match system/audio-base.h audio_format_t */ 180 /** @hide */ 181 public static final int AUDIO_FORMAT_INVALID = 0xFFFFFFFF; 182 /** @hide */ 183 public static final int AUDIO_FORMAT_DEFAULT = 0; 184 /** @hide */ 185 public static final int AUDIO_FORMAT_AAC = 0x04000000; 186 /** @hide */ 187 public static final int AUDIO_FORMAT_SBC = 0x1F000000; 188 /** @hide */ 189 public static final int AUDIO_FORMAT_APTX = 0x20000000; 190 /** @hide */ 191 public static final int AUDIO_FORMAT_APTX_HD = 0x21000000; 192 /** @hide */ 193 public static final int AUDIO_FORMAT_LDAC = 0x23000000; 194 195 /** 196 * @hide 197 * Convert audio format enum values to Bluetooth codec values 198 */ audioFormatToBluetoothSourceCodec(int audioFormat)199 public static int audioFormatToBluetoothSourceCodec(int audioFormat) { 200 switch (audioFormat) { 201 case AUDIO_FORMAT_AAC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 202 case AUDIO_FORMAT_SBC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 203 case AUDIO_FORMAT_APTX: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 204 case AUDIO_FORMAT_APTX_HD: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 205 case AUDIO_FORMAT_LDAC: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 206 default: return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; 207 } 208 } 209 210 /* Routing bits for the former setRouting/getRouting API */ 211 /** @hide @deprecated */ 212 @Deprecated public static final int ROUTE_EARPIECE = (1 << 0); 213 /** @hide @deprecated */ 214 @Deprecated public static final int ROUTE_SPEAKER = (1 << 1); 215 /** @hide @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */ 216 @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2); 217 /** @hide @deprecated */ 218 @Deprecated public static final int ROUTE_BLUETOOTH_SCO = (1 << 2); 219 /** @hide @deprecated */ 220 @Deprecated public static final int ROUTE_HEADSET = (1 << 3); 221 /** @hide @deprecated */ 222 @Deprecated public static final int ROUTE_BLUETOOTH_A2DP = (1 << 4); 223 /** @hide @deprecated */ 224 @Deprecated public static final int ROUTE_ALL = 0xFFFFFFFF; 225 226 // Keep in sync with system/media/audio/include/system/audio.h 227 /** @hide */ 228 public static final int AUDIO_SESSION_ALLOCATE = 0; 229 230 /** 231 * @hide 232 * Checks whether the specified stream type is active. 233 * 234 * return true if any track playing on this stream is active. 235 */ 236 @UnsupportedAppUsage isStreamActive(int stream, int inPastMs)237 public static native boolean isStreamActive(int stream, int inPastMs); 238 239 /** 240 * @hide 241 * Checks whether the specified stream type is active on a remotely connected device. The notion 242 * of what constitutes a remote device is enforced by the audio policy manager of the platform. 243 * 244 * return true if any track playing on this stream is active on a remote device. 245 */ isStreamActiveRemotely(int stream, int inPastMs)246 public static native boolean isStreamActiveRemotely(int stream, int inPastMs); 247 248 /** 249 * @hide 250 * Checks whether the specified audio source is active. 251 * 252 * return true if any recorder using this source is currently recording 253 */ 254 @UnsupportedAppUsage isSourceActive(int source)255 public static native boolean isSourceActive(int source); 256 257 /** 258 * @hide 259 * Returns a new unused audio session ID 260 */ newAudioSessionId()261 public static native int newAudioSessionId(); 262 263 /** 264 * @hide 265 * Returns a new unused audio player ID 266 */ newAudioPlayerId()267 public static native int newAudioPlayerId(); 268 269 /** 270 * @hide 271 * Returns a new unused audio recorder ID 272 */ newAudioRecorderId()273 public static native int newAudioRecorderId(); 274 275 276 /** 277 * @hide 278 * Sets a group generic audio configuration parameters. The use of these parameters 279 * are platform dependent, see libaudio 280 * 281 * param keyValuePairs list of parameters key value pairs in the form: 282 * key1=value1;key2=value2;... 283 */ 284 @UnsupportedAppUsage setParameters(String keyValuePairs)285 public static native int setParameters(String keyValuePairs); 286 287 /** 288 * @hide 289 * Gets a group generic audio configuration parameters. The use of these parameters 290 * are platform dependent, see libaudio 291 * 292 * param keys list of parameters 293 * return value: list of parameters key value pairs in the form: 294 * key1=value1;key2=value2;... 295 */ 296 @UnsupportedAppUsage getParameters(String keys)297 public static native String getParameters(String keys); 298 299 // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp 300 /** @hide Command successful or Media server restarted. see ErrorCallback */ 301 public static final int AUDIO_STATUS_OK = 0; 302 /** @hide Command failed or unspecified audio error. see ErrorCallback */ 303 public static final int AUDIO_STATUS_ERROR = 1; 304 /** @hide Media server died. see ErrorCallback */ 305 public static final int AUDIO_STATUS_SERVER_DIED = 100; 306 307 private static ErrorCallback sErrorCallback; 308 309 /** @hide 310 * Handles the audio error callback. 311 */ 312 public interface ErrorCallback 313 { 314 /* 315 * Callback for audio server errors. 316 * param error error code: 317 * - AUDIO_STATUS_OK 318 * - AUDIO_STATUS_SERVER_DIED 319 * - AUDIO_STATUS_ERROR 320 */ onError(int error)321 void onError(int error); 322 }; 323 324 /** 325 * @hide 326 * Registers a callback to be invoked when an error occurs. 327 * @param cb the callback to run 328 */ 329 @UnsupportedAppUsage setErrorCallback(ErrorCallback cb)330 public static void setErrorCallback(ErrorCallback cb) 331 { 332 synchronized (AudioSystem.class) { 333 sErrorCallback = cb; 334 if (cb != null) { 335 cb.onError(checkAudioFlinger()); 336 } 337 } 338 } 339 340 @UnsupportedAppUsage errorCallbackFromNative(int error)341 private static void errorCallbackFromNative(int error) 342 { 343 ErrorCallback errorCallback = null; 344 synchronized (AudioSystem.class) { 345 if (sErrorCallback != null) { 346 errorCallback = sErrorCallback; 347 } 348 } 349 if (errorCallback != null) { 350 errorCallback.onError(error); 351 } 352 } 353 354 /** 355 * @hide 356 * Handles events from the audio policy manager about dynamic audio policies 357 * @see android.media.audiopolicy.AudioPolicy 358 */ 359 public interface DynamicPolicyCallback 360 { onDynamicPolicyMixStateUpdate(String regId, int state)361 void onDynamicPolicyMixStateUpdate(String regId, int state); 362 } 363 364 //keep in sync with include/media/AudioPolicy.h 365 private final static int DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE = 0; 366 367 private static DynamicPolicyCallback sDynPolicyCallback; 368 369 /** @hide */ setDynamicPolicyCallback(DynamicPolicyCallback cb)370 public static void setDynamicPolicyCallback(DynamicPolicyCallback cb) 371 { 372 synchronized (AudioSystem.class) { 373 sDynPolicyCallback = cb; 374 native_register_dynamic_policy_callback(); 375 } 376 } 377 378 @UnsupportedAppUsage dynamicPolicyCallbackFromNative(int event, String regId, int val)379 private static void dynamicPolicyCallbackFromNative(int event, String regId, int val) 380 { 381 DynamicPolicyCallback cb = null; 382 synchronized (AudioSystem.class) { 383 if (sDynPolicyCallback != null) { 384 cb = sDynPolicyCallback; 385 } 386 } 387 if (cb != null) { 388 switch(event) { 389 case DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE: 390 cb.onDynamicPolicyMixStateUpdate(regId, val); 391 break; 392 default: 393 Log.e(TAG, "dynamicPolicyCallbackFromNative: unknown event " + event); 394 } 395 } 396 } 397 398 /** 399 * @hide 400 * Handles events from the audio policy manager about recording events 401 * @see android.media.AudioManager.AudioRecordingCallback 402 */ 403 public interface AudioRecordingCallback 404 { 405 /** 406 * Callback for recording activity notifications events 407 * @param event 408 * @param riid recording identifier 409 * @param uid uid of the client app performing the recording 410 * @param session 411 * @param source 412 * @param recordingFormat an array of ints containing respectively the client and device 413 * recording configurations (2*3 ints), followed by the patch handle: 414 * index 0: client format 415 * 1: client channel mask 416 * 2: client sample rate 417 * 3: device format 418 * 4: device channel mask 419 * 5: device sample rate 420 * 6: patch handle 421 * @param packName package name of the client app performing the recording. NOT SUPPORTED 422 */ 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)423 void onRecordingConfigurationChanged(int event, int riid, int uid, int session, int source, 424 int portId, boolean silenced, int[] recordingFormat, 425 AudioEffect.Descriptor[] clienteffects, AudioEffect.Descriptor[] effects, 426 int activeSource, String packName); 427 } 428 429 private static AudioRecordingCallback sRecordingCallback; 430 431 /** @hide */ setRecordingCallback(AudioRecordingCallback cb)432 public static void setRecordingCallback(AudioRecordingCallback cb) { 433 synchronized (AudioSystem.class) { 434 sRecordingCallback = cb; 435 native_register_recording_callback(); 436 } 437 } 438 439 /** 440 * Callback from native for recording configuration updates. 441 * @param event 442 * @param riid 443 * @param uid 444 * @param session 445 * @param source 446 * @param portId 447 * @param silenced 448 * @param recordingFormat see 449 * {@link AudioRecordingCallback#onRecordingConfigurationChanged(int, int, int, int, int, \ 450 int, boolean, int[], AudioEffect.Descriptor[], AudioEffect.Descriptor[], int, String)} 451 * for the description of the record format. 452 * @param cleintEffects 453 * @param effects 454 * @param activeSource 455 */ 456 @UnsupportedAppUsage 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)457 private static void recordingCallbackFromNative(int event, int riid, int uid, int session, 458 int source, int portId, boolean silenced, int[] recordingFormat, 459 AudioEffect.Descriptor[] clientEffects, AudioEffect.Descriptor[] effects, 460 int activeSource) { 461 AudioRecordingCallback cb = null; 462 synchronized (AudioSystem.class) { 463 cb = sRecordingCallback; 464 } 465 466 String clientEffectName = clientEffects.length == 0 ? "None" : clientEffects[0].name; 467 String effectName = effects.length == 0 ? "None" : effects[0].name; 468 469 if (cb != null) { 470 // TODO receive package name from native 471 cb.onRecordingConfigurationChanged(event, riid, uid, session, source, portId, silenced, 472 recordingFormat, clientEffects, effects, activeSource, ""); 473 } 474 } 475 476 /* 477 * Error codes used by public APIs (AudioTrack, AudioRecord, AudioManager ...) 478 * Must be kept in sync with frameworks/base/core/jni/android_media_AudioErrors.h 479 */ 480 /** @hide */ 481 public static final int SUCCESS = 0; 482 /** @hide */ 483 public static final int ERROR = -1; 484 /** @hide */ 485 public static final int BAD_VALUE = -2; 486 /** @hide */ 487 public static final int INVALID_OPERATION = -3; 488 /** @hide */ 489 public static final int PERMISSION_DENIED = -4; 490 /** @hide */ 491 public static final int NO_INIT = -5; 492 /** @hide */ 493 public static final int DEAD_OBJECT = -6; 494 /** @hide */ 495 public static final int WOULD_BLOCK = -7; 496 497 /** @hide */ 498 @IntDef({ 499 SUCCESS, 500 ERROR, 501 BAD_VALUE, 502 INVALID_OPERATION, 503 PERMISSION_DENIED, 504 NO_INIT, 505 DEAD_OBJECT, 506 WOULD_BLOCK 507 }) 508 @Retention(RetentionPolicy.SOURCE) 509 public @interface AudioSystemError {} 510 511 /** 512 * @hide 513 * Convert an int error value to its String value for readability. 514 * Accepted error values are the java AudioSystem errors, matching android_media_AudioErrors.h, 515 * which map onto the native status_t type. 516 * @param error one of the java AudioSystem errors 517 * @return a human-readable string 518 */ audioSystemErrorToString(@udioSystemError int error)519 public static String audioSystemErrorToString(@AudioSystemError int error) { 520 switch(error) { 521 case SUCCESS: 522 return "SUCCESS"; 523 case ERROR: 524 return "ERROR"; 525 case BAD_VALUE: 526 return "BAD_VALUE"; 527 case INVALID_OPERATION: 528 return "INVALID_OPERATION"; 529 case PERMISSION_DENIED: 530 return "PERMISSION_DENIED"; 531 case NO_INIT: 532 return "NO_INIT"; 533 case DEAD_OBJECT: 534 return "DEAD_OBJECT"; 535 case WOULD_BLOCK: 536 return "WOULD_BLOCK"; 537 default: 538 return ("unknown error:" + error); 539 } 540 } 541 542 /* 543 * AudioPolicyService methods 544 */ 545 546 // 547 // audio device definitions: must be kept in sync with values in system/core/audio.h 548 // 549 /** @hide */ 550 public static final int DEVICE_NONE = 0x0; 551 // reserved bits 552 /** @hide */ 553 public static final int DEVICE_BIT_IN = 0x80000000; 554 /** @hide */ 555 public static final int DEVICE_BIT_DEFAULT = 0x40000000; 556 // output devices, be sure to update AudioManager.java also 557 /** @hide */ 558 @UnsupportedAppUsage 559 public static final int DEVICE_OUT_EARPIECE = 0x1; 560 /** @hide */ 561 @UnsupportedAppUsage 562 public static final int DEVICE_OUT_SPEAKER = 0x2; 563 /** @hide */ 564 @UnsupportedAppUsage 565 public static final int DEVICE_OUT_WIRED_HEADSET = 0x4; 566 /** @hide */ 567 @UnsupportedAppUsage 568 public static final int DEVICE_OUT_WIRED_HEADPHONE = 0x8; 569 /** @hide */ 570 @UnsupportedAppUsage 571 public static final int DEVICE_OUT_BLUETOOTH_SCO = 0x10; 572 /** @hide */ 573 @UnsupportedAppUsage 574 public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20; 575 /** @hide */ 576 @UnsupportedAppUsage 577 public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40; 578 /** @hide */ 579 @UnsupportedAppUsage 580 public static final int DEVICE_OUT_BLUETOOTH_A2DP = 0x80; 581 /** @hide */ 582 @UnsupportedAppUsage 583 public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100; 584 /** @hide */ 585 @UnsupportedAppUsage 586 public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200; 587 /** @hide */ 588 @UnsupportedAppUsage 589 public static final int DEVICE_OUT_AUX_DIGITAL = 0x400; 590 /** @hide */ 591 public static final int DEVICE_OUT_HDMI = DEVICE_OUT_AUX_DIGITAL; 592 /** @hide */ 593 @UnsupportedAppUsage 594 public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800; 595 /** @hide */ 596 @UnsupportedAppUsage 597 public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000; 598 /** @hide */ 599 @UnsupportedAppUsage 600 public static final int DEVICE_OUT_USB_ACCESSORY = 0x2000; 601 /** @hide */ 602 @UnsupportedAppUsage 603 public static final int DEVICE_OUT_USB_DEVICE = 0x4000; 604 /** @hide */ 605 @UnsupportedAppUsage 606 public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000; 607 /** @hide */ 608 @UnsupportedAppUsage 609 public static final int DEVICE_OUT_TELEPHONY_TX = 0x10000; 610 /** @hide */ 611 public static final int DEVICE_OUT_LINE = 0x20000; 612 /** @hide */ 613 public static final int DEVICE_OUT_HDMI_ARC = 0x40000; 614 /** @hide */ 615 public static final int DEVICE_OUT_SPDIF = 0x80000; 616 /** @hide */ 617 @UnsupportedAppUsage 618 public static final int DEVICE_OUT_FM = 0x100000; 619 /** @hide */ 620 public static final int DEVICE_OUT_AUX_LINE = 0x200000; 621 /** @hide */ 622 public static final int DEVICE_OUT_SPEAKER_SAFE = 0x400000; 623 /** @hide */ 624 public static final int DEVICE_OUT_IP = 0x800000; 625 /** @hide */ 626 public static final int DEVICE_OUT_BUS = 0x1000000; 627 /** @hide */ 628 public static final int DEVICE_OUT_PROXY = 0x2000000; 629 /** @hide */ 630 public static final int DEVICE_OUT_USB_HEADSET = 0x4000000; 631 /** @hide */ 632 public static final int DEVICE_OUT_HEARING_AID = 0x8000000; 633 634 /** @hide */ 635 public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT; 636 637 // Deprecated in R because multiple device types are no longer accessed as a bit mask. 638 // Removing this will get lint warning about changing hidden apis. 639 /** @hide */ 640 @UnsupportedAppUsage 641 public static final int DEVICE_OUT_ALL_USB = (DEVICE_OUT_USB_ACCESSORY | 642 DEVICE_OUT_USB_DEVICE | 643 DEVICE_OUT_USB_HEADSET); 644 645 /** @hide */ 646 public static final Set<Integer> DEVICE_OUT_ALL_SET; 647 /** @hide */ 648 public static final Set<Integer> DEVICE_OUT_ALL_A2DP_SET; 649 /** @hide */ 650 public static final Set<Integer> DEVICE_OUT_ALL_SCO_SET; 651 /** @hide */ 652 public static final Set<Integer> DEVICE_OUT_ALL_USB_SET; 653 /** @hide */ 654 public static final Set<Integer> DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET; 655 /** @hide */ 656 public static final Set<Integer> DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET; 657 static { 658 DEVICE_OUT_ALL_SET = new HashSet<>(); 659 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_EARPIECE); 660 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPEAKER); 661 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_WIRED_HEADSET); 662 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_WIRED_HEADPHONE); 663 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO); 664 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET); 665 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 666 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP); 667 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES); 668 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 669 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HDMI); 670 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_ANLG_DOCK_HEADSET); 671 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_DGTL_DOCK_HEADSET); 672 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_ACCESSORY); 673 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_DEVICE); 674 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_REMOTE_SUBMIX); 675 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_TELEPHONY_TX); 676 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_LINE); 677 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HDMI_ARC); 678 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPDIF); 679 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_FM); 680 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_AUX_LINE); 681 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_SPEAKER_SAFE); 682 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_IP); 683 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_BUS); 684 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_PROXY); 685 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_USB_HEADSET); 686 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_HEARING_AID); 687 DEVICE_OUT_ALL_SET.add(DEVICE_OUT_DEFAULT); 688 689 DEVICE_OUT_ALL_A2DP_SET = new HashSet<>(); 690 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP); 691 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES); 692 DEVICE_OUT_ALL_A2DP_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 693 694 DEVICE_OUT_ALL_SCO_SET = new HashSet<>(); 695 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO); 696 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET); 697 DEVICE_OUT_ALL_SCO_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 698 699 DEVICE_OUT_ALL_USB_SET = new HashSet<>(); 700 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_ACCESSORY); 701 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_DEVICE); 702 DEVICE_OUT_ALL_USB_SET.add(DEVICE_OUT_USB_HEADSET); 703 704 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET = new HashSet<>(); 705 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_AUX_LINE); 706 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_HDMI_ARC); 707 DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET.add(DEVICE_OUT_SPDIF); 708 709 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET = new HashSet<>(); 710 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET.addAll(DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO_SET); 711 DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET.add(DEVICE_OUT_SPEAKER); 712 } 713 714 // input devices 715 /** @hide */ 716 @UnsupportedAppUsage 717 public static final int DEVICE_IN_COMMUNICATION = DEVICE_BIT_IN | 0x1; 718 /** @hide */ 719 @UnsupportedAppUsage 720 public static final int DEVICE_IN_AMBIENT = DEVICE_BIT_IN | 0x2; 721 /** @hide */ 722 @UnsupportedAppUsage 723 public static final int DEVICE_IN_BUILTIN_MIC = DEVICE_BIT_IN | 0x4; 724 /** @hide */ 725 @UnsupportedAppUsage 726 public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = DEVICE_BIT_IN | 0x8; 727 /** @hide */ 728 @UnsupportedAppUsage 729 public static final int DEVICE_IN_WIRED_HEADSET = DEVICE_BIT_IN | 0x10; 730 /** @hide */ 731 @UnsupportedAppUsage 732 public static final int DEVICE_IN_AUX_DIGITAL = DEVICE_BIT_IN | 0x20; 733 /** @hide */ 734 public static final int DEVICE_IN_HDMI = DEVICE_IN_AUX_DIGITAL; 735 /** @hide */ 736 @UnsupportedAppUsage 737 public static final int DEVICE_IN_VOICE_CALL = DEVICE_BIT_IN | 0x40; 738 /** @hide */ 739 public static final int DEVICE_IN_TELEPHONY_RX = DEVICE_IN_VOICE_CALL; 740 /** @hide */ 741 @UnsupportedAppUsage 742 public static final int DEVICE_IN_BACK_MIC = DEVICE_BIT_IN | 0x80; 743 /** @hide */ 744 @UnsupportedAppUsage 745 public static final int DEVICE_IN_REMOTE_SUBMIX = DEVICE_BIT_IN | 0x100; 746 /** @hide */ 747 @UnsupportedAppUsage 748 public static final int DEVICE_IN_ANLG_DOCK_HEADSET = DEVICE_BIT_IN | 0x200; 749 /** @hide */ 750 @UnsupportedAppUsage 751 public static final int DEVICE_IN_DGTL_DOCK_HEADSET = DEVICE_BIT_IN | 0x400; 752 /** @hide */ 753 @UnsupportedAppUsage 754 public static final int DEVICE_IN_USB_ACCESSORY = DEVICE_BIT_IN | 0x800; 755 /** @hide */ 756 @UnsupportedAppUsage 757 public static final int DEVICE_IN_USB_DEVICE = DEVICE_BIT_IN | 0x1000; 758 /** @hide */ 759 public static final int DEVICE_IN_FM_TUNER = DEVICE_BIT_IN | 0x2000; 760 /** @hide */ 761 public static final int DEVICE_IN_TV_TUNER = DEVICE_BIT_IN | 0x4000; 762 /** @hide */ 763 public static final int DEVICE_IN_LINE = DEVICE_BIT_IN | 0x8000; 764 /** @hide */ 765 public static final int DEVICE_IN_SPDIF = DEVICE_BIT_IN | 0x10000; 766 /** @hide */ 767 @UnsupportedAppUsage 768 public static final int DEVICE_IN_BLUETOOTH_A2DP = DEVICE_BIT_IN | 0x20000; 769 /** @hide */ 770 public static final int DEVICE_IN_LOOPBACK = DEVICE_BIT_IN | 0x40000; 771 /** @hide */ 772 public static final int DEVICE_IN_IP = DEVICE_BIT_IN | 0x80000; 773 /** @hide */ 774 public static final int DEVICE_IN_BUS = DEVICE_BIT_IN | 0x100000; 775 /** @hide */ 776 public static final int DEVICE_IN_PROXY = DEVICE_BIT_IN | 0x1000000; 777 /** @hide */ 778 public static final int DEVICE_IN_USB_HEADSET = DEVICE_BIT_IN | 0x2000000; 779 /** @hide */ 780 public static final int DEVICE_IN_BLUETOOTH_BLE = DEVICE_BIT_IN | 0x4000000; 781 /** @hide */ 782 public static final int DEVICE_IN_HDMI_ARC = DEVICE_BIT_IN | 0x8000000; 783 /** @hide */ 784 public static final int DEVICE_IN_ECHO_REFERENCE = DEVICE_BIT_IN | 0x10000000; 785 /** @hide */ 786 @UnsupportedAppUsage 787 public static final int DEVICE_IN_DEFAULT = DEVICE_BIT_IN | DEVICE_BIT_DEFAULT; 788 789 /** @hide */ 790 public static final Set<Integer> DEVICE_IN_ALL_SET; 791 /** @hide */ 792 public static final Set<Integer> DEVICE_IN_ALL_SCO_SET; 793 /** @hide */ 794 public static final Set<Integer> DEVICE_IN_ALL_USB_SET; 795 static { 796 DEVICE_IN_ALL_SET = new HashSet<>(); 797 DEVICE_IN_ALL_SET.add(DEVICE_IN_COMMUNICATION); 798 DEVICE_IN_ALL_SET.add(DEVICE_IN_AMBIENT); 799 DEVICE_IN_ALL_SET.add(DEVICE_IN_BUILTIN_MIC); 800 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_SCO_HEADSET); 801 DEVICE_IN_ALL_SET.add(DEVICE_IN_WIRED_HEADSET); 802 DEVICE_IN_ALL_SET.add(DEVICE_IN_HDMI); 803 DEVICE_IN_ALL_SET.add(DEVICE_IN_TELEPHONY_RX); 804 DEVICE_IN_ALL_SET.add(DEVICE_IN_BACK_MIC); 805 DEVICE_IN_ALL_SET.add(DEVICE_IN_REMOTE_SUBMIX); 806 DEVICE_IN_ALL_SET.add(DEVICE_IN_ANLG_DOCK_HEADSET); 807 DEVICE_IN_ALL_SET.add(DEVICE_IN_DGTL_DOCK_HEADSET); 808 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_ACCESSORY); 809 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_DEVICE); 810 DEVICE_IN_ALL_SET.add(DEVICE_IN_FM_TUNER); 811 DEVICE_IN_ALL_SET.add(DEVICE_IN_TV_TUNER); 812 DEVICE_IN_ALL_SET.add(DEVICE_IN_LINE); 813 DEVICE_IN_ALL_SET.add(DEVICE_IN_SPDIF); 814 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_A2DP); 815 DEVICE_IN_ALL_SET.add(DEVICE_IN_LOOPBACK); 816 DEVICE_IN_ALL_SET.add(DEVICE_IN_IP); 817 DEVICE_IN_ALL_SET.add(DEVICE_IN_BUS); 818 DEVICE_IN_ALL_SET.add(DEVICE_IN_PROXY); 819 DEVICE_IN_ALL_SET.add(DEVICE_IN_USB_HEADSET); 820 DEVICE_IN_ALL_SET.add(DEVICE_IN_BLUETOOTH_BLE); 821 DEVICE_IN_ALL_SET.add(DEVICE_IN_HDMI_ARC); 822 DEVICE_IN_ALL_SET.add(DEVICE_IN_ECHO_REFERENCE); 823 DEVICE_IN_ALL_SET.add(DEVICE_IN_DEFAULT); 824 825 DEVICE_IN_ALL_SCO_SET = new HashSet<>(); 826 DEVICE_IN_ALL_SCO_SET.add(DEVICE_IN_BLUETOOTH_SCO_HEADSET); 827 828 DEVICE_IN_ALL_USB_SET = new HashSet<>(); 829 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_ACCESSORY); 830 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_DEVICE); 831 DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_HEADSET); 832 } 833 834 // device states, must match AudioSystem::device_connection_state 835 /** @hide */ 836 @UnsupportedAppUsage 837 public static final int DEVICE_STATE_UNAVAILABLE = 0; 838 /** @hide */ 839 @UnsupportedAppUsage 840 public static final int DEVICE_STATE_AVAILABLE = 1; 841 private static final int NUM_DEVICE_STATES = 1; 842 843 /** @hide */ deviceStateToString(int state)844 public static String deviceStateToString(int state) { 845 switch (state) { 846 case DEVICE_STATE_UNAVAILABLE: return "DEVICE_STATE_UNAVAILABLE"; 847 case DEVICE_STATE_AVAILABLE: return "DEVICE_STATE_AVAILABLE"; 848 default: return "unknown state (" + state + ")"; 849 } 850 } 851 852 /** @hide */ public static final String DEVICE_OUT_EARPIECE_NAME = "earpiece"; 853 /** @hide */ public static final String DEVICE_OUT_SPEAKER_NAME = "speaker"; 854 /** @hide */ public static final String DEVICE_OUT_WIRED_HEADSET_NAME = "headset"; 855 /** @hide */ public static final String DEVICE_OUT_WIRED_HEADPHONE_NAME = "headphone"; 856 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_NAME = "bt_sco"; 857 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 858 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME = "bt_sco_carkit"; 859 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 860 /** @hide */ 861 public static final String DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME = "bt_a2dp_hp"; 862 /** @hide */ public static final String DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME = "bt_a2dp_spk"; 863 /** @hide */ public static final String DEVICE_OUT_AUX_DIGITAL_NAME = "aux_digital"; 864 /** @hide */ public static final String DEVICE_OUT_HDMI_NAME = "hdmi"; 865 /** @hide */ public static final String DEVICE_OUT_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 866 /** @hide */ public static final String DEVICE_OUT_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 867 /** @hide */ public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory"; 868 /** @hide */ public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device"; 869 /** @hide */ public static final String DEVICE_OUT_REMOTE_SUBMIX_NAME = "remote_submix"; 870 /** @hide */ public static final String DEVICE_OUT_TELEPHONY_TX_NAME = "telephony_tx"; 871 /** @hide */ public static final String DEVICE_OUT_LINE_NAME = "line"; 872 /** @hide */ public static final String DEVICE_OUT_HDMI_ARC_NAME = "hmdi_arc"; 873 /** @hide */ public static final String DEVICE_OUT_SPDIF_NAME = "spdif"; 874 /** @hide */ public static final String DEVICE_OUT_FM_NAME = "fm_transmitter"; 875 /** @hide */ public static final String DEVICE_OUT_AUX_LINE_NAME = "aux_line"; 876 /** @hide */ public static final String DEVICE_OUT_SPEAKER_SAFE_NAME = "speaker_safe"; 877 /** @hide */ public static final String DEVICE_OUT_IP_NAME = "ip"; 878 /** @hide */ public static final String DEVICE_OUT_BUS_NAME = "bus"; 879 /** @hide */ public static final String DEVICE_OUT_PROXY_NAME = "proxy"; 880 /** @hide */ public static final String DEVICE_OUT_USB_HEADSET_NAME = "usb_headset"; 881 /** @hide */ public static final String DEVICE_OUT_HEARING_AID_NAME = "hearing_aid_out"; 882 883 /** @hide */ public static final String DEVICE_IN_COMMUNICATION_NAME = "communication"; 884 /** @hide */ public static final String DEVICE_IN_AMBIENT_NAME = "ambient"; 885 /** @hide */ public static final String DEVICE_IN_BUILTIN_MIC_NAME = "mic"; 886 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 887 /** @hide */ public static final String DEVICE_IN_WIRED_HEADSET_NAME = "headset"; 888 /** @hide */ public static final String DEVICE_IN_AUX_DIGITAL_NAME = "aux_digital"; 889 /** @hide */ public static final String DEVICE_IN_TELEPHONY_RX_NAME = "telephony_rx"; 890 /** @hide */ public static final String DEVICE_IN_BACK_MIC_NAME = "back_mic"; 891 /** @hide */ public static final String DEVICE_IN_REMOTE_SUBMIX_NAME = "remote_submix"; 892 /** @hide */ public static final String DEVICE_IN_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 893 /** @hide */ public static final String DEVICE_IN_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 894 /** @hide */ public static final String DEVICE_IN_USB_ACCESSORY_NAME = "usb_accessory"; 895 /** @hide */ public static final String DEVICE_IN_USB_DEVICE_NAME = "usb_device"; 896 /** @hide */ public static final String DEVICE_IN_FM_TUNER_NAME = "fm_tuner"; 897 /** @hide */ public static final String DEVICE_IN_TV_TUNER_NAME = "tv_tuner"; 898 /** @hide */ public static final String DEVICE_IN_LINE_NAME = "line"; 899 /** @hide */ public static final String DEVICE_IN_SPDIF_NAME = "spdif"; 900 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 901 /** @hide */ public static final String DEVICE_IN_LOOPBACK_NAME = "loopback"; 902 /** @hide */ public static final String DEVICE_IN_IP_NAME = "ip"; 903 /** @hide */ public static final String DEVICE_IN_BUS_NAME = "bus"; 904 /** @hide */ public static final String DEVICE_IN_PROXY_NAME = "proxy"; 905 /** @hide */ public static final String DEVICE_IN_USB_HEADSET_NAME = "usb_headset"; 906 /** @hide */ public static final String DEVICE_IN_BLUETOOTH_BLE_NAME = "bt_ble"; 907 /** @hide */ public static final String DEVICE_IN_ECHO_REFERENCE_NAME = "echo_reference"; 908 /** @hide */ public static final String DEVICE_IN_HDMI_ARC_NAME = "hdmi_arc"; 909 910 /** @hide */ 911 @UnsupportedAppUsage getOutputDeviceName(int device)912 public static String getOutputDeviceName(int device) 913 { 914 switch(device) { 915 case DEVICE_OUT_EARPIECE: 916 return DEVICE_OUT_EARPIECE_NAME; 917 case DEVICE_OUT_SPEAKER: 918 return DEVICE_OUT_SPEAKER_NAME; 919 case DEVICE_OUT_WIRED_HEADSET: 920 return DEVICE_OUT_WIRED_HEADSET_NAME; 921 case DEVICE_OUT_WIRED_HEADPHONE: 922 return DEVICE_OUT_WIRED_HEADPHONE_NAME; 923 case DEVICE_OUT_BLUETOOTH_SCO: 924 return DEVICE_OUT_BLUETOOTH_SCO_NAME; 925 case DEVICE_OUT_BLUETOOTH_SCO_HEADSET: 926 return DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME; 927 case DEVICE_OUT_BLUETOOTH_SCO_CARKIT: 928 return DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME; 929 case DEVICE_OUT_BLUETOOTH_A2DP: 930 return DEVICE_OUT_BLUETOOTH_A2DP_NAME; 931 case DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: 932 return DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME; 933 case DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: 934 return DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME; 935 case DEVICE_OUT_HDMI: 936 return DEVICE_OUT_HDMI_NAME; 937 case DEVICE_OUT_ANLG_DOCK_HEADSET: 938 return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME; 939 case DEVICE_OUT_DGTL_DOCK_HEADSET: 940 return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME; 941 case DEVICE_OUT_USB_ACCESSORY: 942 return DEVICE_OUT_USB_ACCESSORY_NAME; 943 case DEVICE_OUT_USB_DEVICE: 944 return DEVICE_OUT_USB_DEVICE_NAME; 945 case DEVICE_OUT_REMOTE_SUBMIX: 946 return DEVICE_OUT_REMOTE_SUBMIX_NAME; 947 case DEVICE_OUT_TELEPHONY_TX: 948 return DEVICE_OUT_TELEPHONY_TX_NAME; 949 case DEVICE_OUT_LINE: 950 return DEVICE_OUT_LINE_NAME; 951 case DEVICE_OUT_HDMI_ARC: 952 return DEVICE_OUT_HDMI_ARC_NAME; 953 case DEVICE_OUT_SPDIF: 954 return DEVICE_OUT_SPDIF_NAME; 955 case DEVICE_OUT_FM: 956 return DEVICE_OUT_FM_NAME; 957 case DEVICE_OUT_AUX_LINE: 958 return DEVICE_OUT_AUX_LINE_NAME; 959 case DEVICE_OUT_SPEAKER_SAFE: 960 return DEVICE_OUT_SPEAKER_SAFE_NAME; 961 case DEVICE_OUT_IP: 962 return DEVICE_OUT_IP_NAME; 963 case DEVICE_OUT_BUS: 964 return DEVICE_OUT_BUS_NAME; 965 case DEVICE_OUT_PROXY: 966 return DEVICE_OUT_PROXY_NAME; 967 case DEVICE_OUT_USB_HEADSET: 968 return DEVICE_OUT_USB_HEADSET_NAME; 969 case DEVICE_OUT_HEARING_AID: 970 return DEVICE_OUT_HEARING_AID_NAME; 971 case DEVICE_OUT_DEFAULT: 972 default: 973 return Integer.toString(device); 974 } 975 } 976 977 /** @hide */ getInputDeviceName(int device)978 public static String getInputDeviceName(int device) 979 { 980 switch(device) { 981 case DEVICE_IN_COMMUNICATION: 982 return DEVICE_IN_COMMUNICATION_NAME; 983 case DEVICE_IN_AMBIENT: 984 return DEVICE_IN_AMBIENT_NAME; 985 case DEVICE_IN_BUILTIN_MIC: 986 return DEVICE_IN_BUILTIN_MIC_NAME; 987 case DEVICE_IN_BLUETOOTH_SCO_HEADSET: 988 return DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME; 989 case DEVICE_IN_WIRED_HEADSET: 990 return DEVICE_IN_WIRED_HEADSET_NAME; 991 case DEVICE_IN_AUX_DIGITAL: 992 return DEVICE_IN_AUX_DIGITAL_NAME; 993 case DEVICE_IN_TELEPHONY_RX: 994 return DEVICE_IN_TELEPHONY_RX_NAME; 995 case DEVICE_IN_BACK_MIC: 996 return DEVICE_IN_BACK_MIC_NAME; 997 case DEVICE_IN_REMOTE_SUBMIX: 998 return DEVICE_IN_REMOTE_SUBMIX_NAME; 999 case DEVICE_IN_ANLG_DOCK_HEADSET: 1000 return DEVICE_IN_ANLG_DOCK_HEADSET_NAME; 1001 case DEVICE_IN_DGTL_DOCK_HEADSET: 1002 return DEVICE_IN_DGTL_DOCK_HEADSET_NAME; 1003 case DEVICE_IN_USB_ACCESSORY: 1004 return DEVICE_IN_USB_ACCESSORY_NAME; 1005 case DEVICE_IN_USB_DEVICE: 1006 return DEVICE_IN_USB_DEVICE_NAME; 1007 case DEVICE_IN_FM_TUNER: 1008 return DEVICE_IN_FM_TUNER_NAME; 1009 case DEVICE_IN_TV_TUNER: 1010 return DEVICE_IN_TV_TUNER_NAME; 1011 case DEVICE_IN_LINE: 1012 return DEVICE_IN_LINE_NAME; 1013 case DEVICE_IN_SPDIF: 1014 return DEVICE_IN_SPDIF_NAME; 1015 case DEVICE_IN_BLUETOOTH_A2DP: 1016 return DEVICE_IN_BLUETOOTH_A2DP_NAME; 1017 case DEVICE_IN_LOOPBACK: 1018 return DEVICE_IN_LOOPBACK_NAME; 1019 case DEVICE_IN_IP: 1020 return DEVICE_IN_IP_NAME; 1021 case DEVICE_IN_BUS: 1022 return DEVICE_IN_BUS_NAME; 1023 case DEVICE_IN_PROXY: 1024 return DEVICE_IN_PROXY_NAME; 1025 case DEVICE_IN_USB_HEADSET: 1026 return DEVICE_IN_USB_HEADSET_NAME; 1027 case DEVICE_IN_BLUETOOTH_BLE: 1028 return DEVICE_IN_BLUETOOTH_BLE_NAME; 1029 case DEVICE_IN_ECHO_REFERENCE: 1030 return DEVICE_IN_ECHO_REFERENCE_NAME; 1031 case DEVICE_IN_HDMI_ARC: 1032 return DEVICE_IN_HDMI_ARC_NAME; 1033 case DEVICE_IN_DEFAULT: 1034 default: 1035 return Integer.toString(device); 1036 } 1037 } 1038 1039 // phone state, match audio_mode??? 1040 /** @hide */ public static final int PHONE_STATE_OFFCALL = 0; 1041 /** @hide */ public static final int PHONE_STATE_RINGING = 1; 1042 /** @hide */ public static final int PHONE_STATE_INCALL = 2; 1043 1044 // device categories config for setForceUse, must match audio_policy_forced_cfg_t 1045 /** @hide */ @UnsupportedAppUsage public static final int FORCE_NONE = 0; 1046 /** @hide */ public static final int FORCE_SPEAKER = 1; 1047 /** @hide */ public static final int FORCE_HEADPHONES = 2; 1048 /** @hide */ public static final int FORCE_BT_SCO = 3; 1049 /** @hide */ public static final int FORCE_BT_A2DP = 4; 1050 /** @hide */ public static final int FORCE_WIRED_ACCESSORY = 5; 1051 /** @hide */ @UnsupportedAppUsage public static final int FORCE_BT_CAR_DOCK = 6; 1052 /** @hide */ @UnsupportedAppUsage public static final int FORCE_BT_DESK_DOCK = 7; 1053 /** @hide */ @UnsupportedAppUsage public static final int FORCE_ANALOG_DOCK = 8; 1054 /** @hide */ @UnsupportedAppUsage public static final int FORCE_DIGITAL_DOCK = 9; 1055 /** @hide */ public static final int FORCE_NO_BT_A2DP = 10; 1056 /** @hide */ public static final int FORCE_SYSTEM_ENFORCED = 11; 1057 /** @hide */ public static final int FORCE_HDMI_SYSTEM_AUDIO_ENFORCED = 12; 1058 /** @hide */ public static final int FORCE_ENCODED_SURROUND_NEVER = 13; 1059 /** @hide */ public static final int FORCE_ENCODED_SURROUND_ALWAYS = 14; 1060 /** @hide */ public static final int FORCE_ENCODED_SURROUND_MANUAL = 15; 1061 /** @hide */ public static final int NUM_FORCE_CONFIG = 16; 1062 /** @hide */ public static final int FORCE_DEFAULT = FORCE_NONE; 1063 1064 /** @hide */ forceUseConfigToString(int config)1065 public static String forceUseConfigToString(int config) { 1066 switch (config) { 1067 case FORCE_NONE: return "FORCE_NONE"; 1068 case FORCE_SPEAKER: return "FORCE_SPEAKER"; 1069 case FORCE_HEADPHONES: return "FORCE_HEADPHONES"; 1070 case FORCE_BT_SCO: return "FORCE_BT_SCO"; 1071 case FORCE_BT_A2DP: return "FORCE_BT_A2DP"; 1072 case FORCE_WIRED_ACCESSORY: return "FORCE_WIRED_ACCESSORY"; 1073 case FORCE_BT_CAR_DOCK: return "FORCE_BT_CAR_DOCK"; 1074 case FORCE_BT_DESK_DOCK: return "FORCE_BT_DESK_DOCK"; 1075 case FORCE_ANALOG_DOCK: return "FORCE_ANALOG_DOCK"; 1076 case FORCE_DIGITAL_DOCK: return "FORCE_DIGITAL_DOCK"; 1077 case FORCE_NO_BT_A2DP: return "FORCE_NO_BT_A2DP"; 1078 case FORCE_SYSTEM_ENFORCED: return "FORCE_SYSTEM_ENFORCED"; 1079 case FORCE_HDMI_SYSTEM_AUDIO_ENFORCED: return "FORCE_HDMI_SYSTEM_AUDIO_ENFORCED"; 1080 case FORCE_ENCODED_SURROUND_NEVER: return "FORCE_ENCODED_SURROUND_NEVER"; 1081 case FORCE_ENCODED_SURROUND_ALWAYS: return "FORCE_ENCODED_SURROUND_ALWAYS"; 1082 case FORCE_ENCODED_SURROUND_MANUAL: return "FORCE_ENCODED_SURROUND_MANUAL"; 1083 default: return "unknown config (" + config + ")" ; 1084 } 1085 } 1086 1087 // usage for setForceUse, must match audio_policy_force_use_t 1088 /** @hide */ public static final int FOR_COMMUNICATION = 0; 1089 /** @hide */ public static final int FOR_MEDIA = 1; 1090 /** @hide */ public static final int FOR_RECORD = 2; 1091 /** @hide */ public static final int FOR_DOCK = 3; 1092 /** @hide */ public static final int FOR_SYSTEM = 4; 1093 /** @hide */ public static final int FOR_HDMI_SYSTEM_AUDIO = 5; 1094 /** @hide */ public static final int FOR_ENCODED_SURROUND = 6; 1095 /** @hide */ public static final int FOR_VIBRATE_RINGING = 7; 1096 private static final int NUM_FORCE_USE = 8; 1097 1098 /** @hide */ forceUseUsageToString(int usage)1099 public static String forceUseUsageToString(int usage) { 1100 switch (usage) { 1101 case FOR_COMMUNICATION: return "FOR_COMMUNICATION"; 1102 case FOR_MEDIA: return "FOR_MEDIA"; 1103 case FOR_RECORD: return "FOR_RECORD"; 1104 case FOR_DOCK: return "FOR_DOCK"; 1105 case FOR_SYSTEM: return "FOR_SYSTEM"; 1106 case FOR_HDMI_SYSTEM_AUDIO: return "FOR_HDMI_SYSTEM_AUDIO"; 1107 case FOR_ENCODED_SURROUND: return "FOR_ENCODED_SURROUND"; 1108 case FOR_VIBRATE_RINGING: return "FOR_VIBRATE_RINGING"; 1109 default: return "unknown usage (" + usage + ")" ; 1110 } 1111 } 1112 1113 /** @hide Wrapper for native methods called from AudioService */ setStreamVolumeIndexAS(int stream, int index, int device)1114 public static int setStreamVolumeIndexAS(int stream, int index, int device) { 1115 if (DEBUG_VOLUME) { 1116 Log.i(TAG, "setStreamVolumeIndex: " + STREAM_NAMES[stream] 1117 + " dev=" + Integer.toHexString(device) + " idx=" + index); 1118 } 1119 return setStreamVolumeIndex(stream, index, device); 1120 } 1121 1122 // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t 1123 /** @hide */ public static final int SYNC_EVENT_NONE = 0; 1124 /** @hide */ public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1; 1125 1126 /** 1127 * @hide 1128 * @return command completion status, one of {@link #AUDIO_STATUS_OK}, 1129 * {@link #AUDIO_STATUS_ERROR} or {@link #AUDIO_STATUS_SERVER_DIED} 1130 */ 1131 @UnsupportedAppUsage setDeviceConnectionState(int device, int state, String device_address, String device_name, int codecFormat)1132 public static native int setDeviceConnectionState(int device, int state, 1133 String device_address, String device_name, 1134 int codecFormat); 1135 /** @hide */ 1136 @UnsupportedAppUsage getDeviceConnectionState(int device, String device_address)1137 public static native int getDeviceConnectionState(int device, String device_address); 1138 /** @hide */ handleDeviceConfigChange(int device, String device_address, String device_name, int codecFormat)1139 public static native int handleDeviceConfigChange(int device, 1140 String device_address, 1141 String device_name, 1142 int codecFormat); 1143 /** @hide */ 1144 @UnsupportedAppUsage setPhoneState(int state)1145 public static native int setPhoneState(int state); 1146 /** @hide */ 1147 @UnsupportedAppUsage setForceUse(int usage, int config)1148 public static native int setForceUse(int usage, int config); 1149 /** @hide */ 1150 @UnsupportedAppUsage getForceUse(int usage)1151 public static native int getForceUse(int usage); 1152 /** @hide */ 1153 @UnsupportedAppUsage initStreamVolume(int stream, int indexMin, int indexMax)1154 public static native int initStreamVolume(int stream, int indexMin, int indexMax); 1155 @UnsupportedAppUsage setStreamVolumeIndex(int stream, int index, int device)1156 private static native int setStreamVolumeIndex(int stream, int index, int device); 1157 /** @hide */ getStreamVolumeIndex(int stream, int device)1158 public static native int getStreamVolumeIndex(int stream, int device); 1159 /** 1160 * @hide 1161 * set a volume for the given {@link AudioAttributes} and for all other stream that belong to 1162 * the same volume group. 1163 * @param attributes the {@link AudioAttributes} to be considered 1164 * @param index to be applied 1165 * @param device the volume device to be considered 1166 * @return command completion status. 1167 */ setVolumeIndexForAttributes(@onNull AudioAttributes attributes, int index, int device)1168 public static native int setVolumeIndexForAttributes(@NonNull AudioAttributes attributes, 1169 int index, int device); 1170 /** 1171 * @hide 1172 * get the volume index for the given {@link AudioAttributes}. 1173 * @param attributes the {@link AudioAttributes} to be considered 1174 * @param device the volume device to be considered 1175 * @return volume index for the given {@link AudioAttributes} and volume device. 1176 */ getVolumeIndexForAttributes(@onNull AudioAttributes attributes, int device)1177 public static native int getVolumeIndexForAttributes(@NonNull AudioAttributes attributes, 1178 int device); 1179 /** 1180 * @hide 1181 * get the minimum volume index for the given {@link AudioAttributes}. 1182 * @param attributes the {@link AudioAttributes} to be considered 1183 * @return minimum volume index for the given {@link AudioAttributes}. 1184 */ getMinVolumeIndexForAttributes(@onNull AudioAttributes attributes)1185 public static native int getMinVolumeIndexForAttributes(@NonNull AudioAttributes attributes); 1186 /** 1187 * @hide 1188 * get the maximum volume index for the given {@link AudioAttributes}. 1189 * @param attributes the {@link AudioAttributes} to be considered 1190 * @return maximum volume index for the given {@link AudioAttributes}. 1191 */ getMaxVolumeIndexForAttributes(@onNull AudioAttributes attributes)1192 public static native int getMaxVolumeIndexForAttributes(@NonNull AudioAttributes attributes); 1193 1194 /** @hide */ setMasterVolume(float value)1195 public static native int setMasterVolume(float value); 1196 /** @hide */ getMasterVolume()1197 public static native float getMasterVolume(); 1198 /** @hide */ 1199 @UnsupportedAppUsage setMasterMute(boolean mute)1200 public static native int setMasterMute(boolean mute); 1201 /** @hide */ 1202 @UnsupportedAppUsage getMasterMute()1203 public static native boolean getMasterMute(); 1204 /** @hide */ 1205 @UnsupportedAppUsage getDevicesForStream(int stream)1206 public static native int getDevicesForStream(int stream); 1207 1208 /** @hide returns true if master mono is enabled. */ getMasterMono()1209 public static native boolean getMasterMono(); 1210 /** @hide enables or disables the master mono mode. */ setMasterMono(boolean mono)1211 public static native int setMasterMono(boolean mono); 1212 /** @hide enables or disables the RTT mode. */ setRttEnabled(boolean enabled)1213 public static native int setRttEnabled(boolean enabled); 1214 1215 /** @hide returns master balance value in range -1.f -> 1.f, where 0.f is dead center. */ 1216 @TestApi getMasterBalance()1217 public static native float getMasterBalance(); 1218 /** @hide Changes the audio balance of the device. */ 1219 @TestApi setMasterBalance(float balance)1220 public static native int setMasterBalance(float balance); 1221 1222 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 1223 /** @hide */ 1224 @UnsupportedAppUsage(trackingBug = 134049522) getPrimaryOutputSamplingRate()1225 public static native int getPrimaryOutputSamplingRate(); 1226 /** @hide */ 1227 @UnsupportedAppUsage(trackingBug = 134049522) getPrimaryOutputFrameCount()1228 public static native int getPrimaryOutputFrameCount(); 1229 /** @hide */ 1230 @UnsupportedAppUsage getOutputLatency(int stream)1231 public static native int getOutputLatency(int stream); 1232 1233 /** @hide */ setLowRamDevice(boolean isLowRamDevice, long totalMemory)1234 public static native int setLowRamDevice(boolean isLowRamDevice, long totalMemory); 1235 /** @hide */ 1236 @UnsupportedAppUsage checkAudioFlinger()1237 public static native int checkAudioFlinger(); 1238 1239 /** @hide */ listAudioPorts(ArrayList<AudioPort> ports, int[] generation)1240 public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); 1241 /** @hide */ createAudioPatch(AudioPatch[] patch, AudioPortConfig[] sources, AudioPortConfig[] sinks)1242 public static native int createAudioPatch(AudioPatch[] patch, 1243 AudioPortConfig[] sources, AudioPortConfig[] sinks); 1244 /** @hide */ releaseAudioPatch(AudioPatch patch)1245 public static native int releaseAudioPatch(AudioPatch patch); 1246 /** @hide */ listAudioPatches(ArrayList<AudioPatch> patches, int[] generation)1247 public static native int listAudioPatches(ArrayList<AudioPatch> patches, int[] generation); 1248 /** @hide */ setAudioPortConfig(AudioPortConfig config)1249 public static native int setAudioPortConfig(AudioPortConfig config); 1250 1251 /** @hide */ startAudioSource(AudioPortConfig config, AudioAttributes audioAttributes)1252 public static native int startAudioSource(AudioPortConfig config, 1253 AudioAttributes audioAttributes); 1254 /** @hide */ stopAudioSource(int handle)1255 public static native int stopAudioSource(int handle); 1256 1257 // declare this instance as having a dynamic policy callback handler native_register_dynamic_policy_callback()1258 private static native final void native_register_dynamic_policy_callback(); 1259 // declare this instance as having a recording configuration update callback handler native_register_recording_callback()1260 private static native final void native_register_recording_callback(); 1261 1262 // must be kept in sync with value in include/system/audio.h 1263 /** @hide */ public static final int AUDIO_HW_SYNC_INVALID = 0; 1264 1265 /** @hide */ getAudioHwSyncForSession(int sessionId)1266 public static native int getAudioHwSyncForSession(int sessionId); 1267 1268 /** @hide */ registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register)1269 public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); 1270 1271 /** @hide see AudioPolicy.setUidDeviceAffinities() */ setUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses)1272 public static native int setUidDeviceAffinities(int uid, @NonNull int[] types, 1273 @NonNull String[] addresses); 1274 1275 /** @hide see AudioPolicy.removeUidDeviceAffinities() */ removeUidDeviceAffinities(int uid)1276 public static native int removeUidDeviceAffinities(int uid); 1277 1278 /** @hide */ systemReady()1279 public static native int systemReady(); 1280 1281 /** @hide */ getStreamVolumeDB(int stream, int index, int device)1282 public static native float getStreamVolumeDB(int stream, int index, int device); 1283 1284 /** 1285 * @hide 1286 * @see AudioManager#setAllowedCapturePolicy() 1287 */ setAllowedCapturePolicy(int uid, int flags)1288 public static native int setAllowedCapturePolicy(int uid, int flags); 1289 isOffloadSupported(@onNull AudioFormat format, @NonNull AudioAttributes attr)1290 static boolean isOffloadSupported(@NonNull AudioFormat format, @NonNull AudioAttributes attr) { 1291 return native_is_offload_supported(format.getEncoding(), format.getSampleRate(), 1292 format.getChannelMask(), format.getChannelIndexMask(), 1293 attr.getVolumeControlStream()); 1294 } 1295 native_is_offload_supported(int encoding, int sampleRate, int channelMask, int channelIndexMask, int streamType)1296 private static native boolean native_is_offload_supported(int encoding, int sampleRate, 1297 int channelMask, int channelIndexMask, int streamType); 1298 1299 /** @hide */ getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo)1300 public static native int getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo); 1301 1302 /** @hide */ getSurroundFormats(Map<Integer, Boolean> surroundFormats, boolean reported)1303 public static native int getSurroundFormats(Map<Integer, Boolean> surroundFormats, 1304 boolean reported); 1305 1306 /** 1307 * @hide 1308 * Returns a list of audio formats (codec) supported on the A2DP offload path. 1309 */ getHwOffloadEncodingFormatsSupportedForA2DP( ArrayList<Integer> formatList)1310 public static native int getHwOffloadEncodingFormatsSupportedForA2DP( 1311 ArrayList<Integer> formatList); 1312 1313 /** @hide */ setSurroundFormatEnabled(int audioFormat, boolean enabled)1314 public static native int setSurroundFormatEnabled(int audioFormat, boolean enabled); 1315 1316 /** 1317 * @hide 1318 * Communicate UID of active assistant to audio policy service. 1319 */ setAssistantUid(int uid)1320 public static native int setAssistantUid(int uid); 1321 1322 /** 1323 * @hide 1324 * Communicate UIDs of active accessibility services to audio policy service. 1325 */ setA11yServicesUids(int[] uids)1326 public static native int setA11yServicesUids(int[] uids); 1327 1328 /** 1329 * @hide 1330 * @see AudioManager#isHapticPlaybackSupported() 1331 */ isHapticPlaybackSupported()1332 public static native boolean isHapticPlaybackSupported(); 1333 1334 /** 1335 * @hide 1336 * Send audio HAL server process pids to native audioserver process for use 1337 * when generating audio HAL servers tombstones 1338 */ setAudioHalPids(int[] pids)1339 public static native int setAudioHalPids(int[] pids); 1340 1341 // Items shared with audio service 1342 1343 /** 1344 * @hide 1345 * The delay before playing a sound. This small period exists so the user 1346 * can press another key (non-volume keys, too) to have it NOT be audible. 1347 * <p> 1348 * PhoneWindow will implement this part. 1349 */ 1350 public static final int PLAY_SOUND_DELAY = 300; 1351 1352 /** 1353 * @hide 1354 * Constant to identify a focus stack entry that is used to hold the focus while the phone 1355 * is ringing or during a call. Used by com.android.internal.telephony.CallManager when 1356 * entering and exiting calls. 1357 */ 1358 public final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls"; 1359 1360 /** 1361 * @hide 1362 * @see AudioManager#setVibrateSetting(int, int) 1363 */ getValueForVibrateSetting(int existingValue, int vibrateType, int vibrateSetting)1364 public static int getValueForVibrateSetting(int existingValue, int vibrateType, 1365 int vibrateSetting) { 1366 1367 // First clear the existing setting. Each vibrate type has two bits in 1368 // the value. Note '3' is '11' in binary. 1369 existingValue &= ~(3 << (vibrateType * 2)); 1370 1371 // Set into the old value 1372 existingValue |= (vibrateSetting & 3) << (vibrateType * 2); 1373 1374 return existingValue; 1375 } 1376 1377 /** @hide */ getDefaultStreamVolume(int streamType)1378 public static int getDefaultStreamVolume(int streamType) { 1379 return DEFAULT_STREAM_VOLUME[streamType]; 1380 } 1381 1382 /** @hide */ 1383 public static int[] DEFAULT_STREAM_VOLUME = new int[] { 1384 4, // STREAM_VOICE_CALL 1385 7, // STREAM_SYSTEM 1386 5, // STREAM_RING 1387 5, // STREAM_MUSIC 1388 6, // STREAM_ALARM 1389 5, // STREAM_NOTIFICATION 1390 7, // STREAM_BLUETOOTH_SCO 1391 7, // STREAM_SYSTEM_ENFORCED 1392 5, // STREAM_DTMF 1393 5, // STREAM_TTS 1394 5, // STREAM_ACCESSIBILITY 1395 }; 1396 1397 /** @hide */ streamToString(int stream)1398 public static String streamToString(int stream) { 1399 if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream]; 1400 if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE"; 1401 return "UNKNOWN_STREAM_" + stream; 1402 } 1403 1404 /** @hide The platform has no specific capabilities */ 1405 public static final int PLATFORM_DEFAULT = 0; 1406 /** @hide The platform is voice call capable (a phone) */ 1407 public static final int PLATFORM_VOICE = 1; 1408 /** @hide The platform is a television or a set-top box */ 1409 public static final int PLATFORM_TELEVISION = 2; 1410 1411 /** 1412 * @hide 1413 * Return the platform type that this is running on. One of: 1414 * <ul> 1415 * <li>{@link #PLATFORM_VOICE}</li> 1416 * <li>{@link #PLATFORM_TELEVISION}</li> 1417 * <li>{@link #PLATFORM_DEFAULT}</li> 1418 * </ul> 1419 */ getPlatformType(Context context)1420 public static int getPlatformType(Context context) { 1421 if (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) 1422 .isVoiceCapable()) { 1423 return PLATFORM_VOICE; 1424 } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 1425 return PLATFORM_TELEVISION; 1426 } else { 1427 return PLATFORM_DEFAULT; 1428 } 1429 } 1430 1431 /** 1432 * @hide 1433 * @return whether the system uses a single volume stream. 1434 */ isSingleVolume(Context context)1435 public static boolean isSingleVolume(Context context) { 1436 boolean forceSingleVolume = context.getResources().getBoolean( 1437 com.android.internal.R.bool.config_single_volume); 1438 return getPlatformType(context) == PLATFORM_TELEVISION || forceSingleVolume; 1439 } 1440 1441 /** 1442 * @hide 1443 * Return a set of audio device types from a bit mask audio device type, which may 1444 * represent multiple audio device types. 1445 * FIXME: Remove this when getting ride of bit mask usage of audio device types. 1446 */ generateAudioDeviceTypesSet(int types)1447 public static Set<Integer> generateAudioDeviceTypesSet(int types) { 1448 Set<Integer> deviceTypes = new HashSet<>(); 1449 Set<Integer> allDeviceTypes = 1450 (types & DEVICE_BIT_IN) == 0 ? DEVICE_OUT_ALL_SET : DEVICE_IN_ALL_SET; 1451 for (int deviceType : allDeviceTypes) { 1452 if ((types & deviceType) == deviceType) { 1453 deviceTypes.add(deviceType); 1454 } 1455 } 1456 return deviceTypes; 1457 } 1458 1459 /** 1460 * @hide 1461 * Return the intersection of two audio device types collections. 1462 */ intersectionAudioDeviceTypes( @onNull Set<Integer> a, @NonNull Set<Integer> b)1463 public static Set<Integer> intersectionAudioDeviceTypes( 1464 @NonNull Set<Integer> a, @NonNull Set<Integer> b) { 1465 Set<Integer> intersection = new HashSet<>(a); 1466 intersection.retainAll(b); 1467 return intersection; 1468 } 1469 1470 /** 1471 * @hide 1472 * Return true if the audio device types collection only contains the given device type. 1473 */ isSingleAudioDeviceType(@onNull Set<Integer> types, int type)1474 public static boolean isSingleAudioDeviceType(@NonNull Set<Integer> types, int type) { 1475 return types.size() == 1 && types.contains(type); 1476 } 1477 1478 /** @hide */ 1479 public static final int DEFAULT_MUTE_STREAMS_AFFECTED = 1480 (1 << STREAM_MUSIC) | 1481 (1 << STREAM_RING) | 1482 (1 << STREAM_NOTIFICATION) | 1483 (1 << STREAM_SYSTEM) | 1484 (1 << STREAM_VOICE_CALL) | 1485 (1 << STREAM_BLUETOOTH_SCO); 1486 1487 /** 1488 * @hide 1489 * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes. 1490 * Keep in sync with core/jni/android_media_DeviceCallback.h. 1491 */ 1492 final static int NATIVE_EVENT_ROUTING_CHANGE = 1000; 1493 } 1494 1495