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.media.audiopolicy.AudioMix; 20 import java.util.ArrayList; 21 22 /* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET 23 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java. 24 * THANK YOU FOR YOUR COOPERATION. 25 */ 26 27 /** 28 * @hide 29 */ 30 public class AudioSystem 31 { 32 /* These values must be kept in sync with system/audio.h */ 33 /* 34 * If these are modified, please also update Settings.System.VOLUME_SETTINGS 35 * and attrs.xml and AudioManager.java. 36 */ 37 /* The default audio stream */ 38 public static final int STREAM_DEFAULT = -1; 39 /* The audio stream for phone calls */ 40 public static final int STREAM_VOICE_CALL = 0; 41 /* The audio stream for system sounds */ 42 public static final int STREAM_SYSTEM = 1; 43 /* The audio stream for the phone ring and message alerts */ 44 public static final int STREAM_RING = 2; 45 /* The audio stream for music playback */ 46 public static final int STREAM_MUSIC = 3; 47 /* The audio stream for alarms */ 48 public static final int STREAM_ALARM = 4; 49 /* The audio stream for notifications */ 50 public static final int STREAM_NOTIFICATION = 5; 51 /* @hide The audio stream for phone calls when connected on bluetooth */ 52 public static final int STREAM_BLUETOOTH_SCO = 6; 53 /* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */ 54 public static final int STREAM_SYSTEM_ENFORCED = 7; 55 /* @hide The audio stream for DTMF tones */ 56 public static final int STREAM_DTMF = 8; 57 /* @hide The audio stream for text to speech (TTS) */ 58 public static final int STREAM_TTS = 9; 59 /** 60 * @deprecated Use {@link #numStreamTypes() instead} 61 */ 62 public static final int NUM_STREAMS = 5; 63 64 // Expose only the getter method publicly so we can change it in the future 65 private static final int NUM_STREAM_TYPES = 10; 66 public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } 67 68 /* 69 * Sets the microphone mute on or off. 70 * 71 * @param on set <var>true</var> to mute the microphone; 72 * <var>false</var> to turn mute off 73 * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 74 */ 75 public static native int muteMicrophone(boolean on); 76 77 /* 78 * Checks whether the microphone mute is on or off. 79 * 80 * @return true if microphone is muted, false if it's not 81 */ 82 public static native boolean isMicrophoneMuted(); 83 84 /* modes for setPhoneState, must match AudioSystem.h audio_mode */ 85 public static final int MODE_INVALID = -2; 86 public static final int MODE_CURRENT = -1; 87 public static final int MODE_NORMAL = 0; 88 public static final int MODE_RINGTONE = 1; 89 public static final int MODE_IN_CALL = 2; 90 public static final int MODE_IN_COMMUNICATION = 3; 91 public static final int NUM_MODES = 4; 92 93 94 /* Routing bits for the former setRouting/getRouting API */ 95 /** @deprecated */ 96 @Deprecated public static final int ROUTE_EARPIECE = (1 << 0); 97 /** @deprecated */ 98 @Deprecated public static final int ROUTE_SPEAKER = (1 << 1); 99 /** @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */ 100 @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2); 101 /** @deprecated */ 102 @Deprecated public static final int ROUTE_BLUETOOTH_SCO = (1 << 2); 103 /** @deprecated */ 104 @Deprecated public static final int ROUTE_HEADSET = (1 << 3); 105 /** @deprecated */ 106 @Deprecated public static final int ROUTE_BLUETOOTH_A2DP = (1 << 4); 107 /** @deprecated */ 108 @Deprecated public static final int ROUTE_ALL = 0xFFFFFFFF; 109 110 // Keep in sync with system/core/include/system/audio.h 111 public static final int AUDIO_SESSION_ALLOCATE = 0; 112 113 /* 114 * Checks whether the specified stream type is active. 115 * 116 * return true if any track playing on this stream is active. 117 */ 118 public static native boolean isStreamActive(int stream, int inPastMs); 119 120 /* 121 * Checks whether the specified stream type is active on a remotely connected device. The notion 122 * of what constitutes a remote device is enforced by the audio policy manager of the platform. 123 * 124 * return true if any track playing on this stream is active on a remote device. 125 */ 126 public static native boolean isStreamActiveRemotely(int stream, int inPastMs); 127 128 /* 129 * Checks whether the specified audio source is active. 130 * 131 * return true if any recorder using this source is currently recording 132 */ 133 public static native boolean isSourceActive(int source); 134 135 /* 136 * Returns a new unused audio session ID 137 */ 138 public static native int newAudioSessionId(); 139 140 /* 141 * Sets a group generic audio configuration parameters. The use of these parameters 142 * are platform dependent, see libaudio 143 * 144 * param keyValuePairs list of parameters key value pairs in the form: 145 * key1=value1;key2=value2;... 146 */ 147 public static native int setParameters(String keyValuePairs); 148 149 /* 150 * Gets a group generic audio configuration parameters. The use of these parameters 151 * are platform dependent, see libaudio 152 * 153 * param keys list of parameters 154 * return value: list of parameters key value pairs in the form: 155 * key1=value1;key2=value2;... 156 */ 157 public static native String getParameters(String keys); 158 159 // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp 160 /* Command sucessful or Media server restarted. see ErrorCallback */ 161 public static final int AUDIO_STATUS_OK = 0; 162 /* Command failed or unspecified audio error. see ErrorCallback */ 163 public static final int AUDIO_STATUS_ERROR = 1; 164 /* Media server died. see ErrorCallback */ 165 public static final int AUDIO_STATUS_SERVER_DIED = 100; 166 167 private static ErrorCallback mErrorCallback; 168 169 /* 170 * Handles the audio error callback. 171 */ 172 public interface ErrorCallback 173 { 174 /* 175 * Callback for audio server errors. 176 * param error error code: 177 * - AUDIO_STATUS_OK 178 * - AUDIO_STATUS_SERVER_DIED 179 * - AUDIO_STATUS_ERROR 180 */ 181 void onError(int error); 182 }; 183 184 /* 185 * Registers a callback to be invoked when an error occurs. 186 * @param cb the callback to run 187 */ 188 public static void setErrorCallback(ErrorCallback cb) 189 { 190 synchronized (AudioSystem.class) { 191 mErrorCallback = cb; 192 if (cb != null) { 193 cb.onError(checkAudioFlinger()); 194 } 195 } 196 } 197 198 private static void errorCallbackFromNative(int error) 199 { 200 ErrorCallback errorCallback = null; 201 synchronized (AudioSystem.class) { 202 if (mErrorCallback != null) { 203 errorCallback = mErrorCallback; 204 } 205 } 206 if (errorCallback != null) { 207 errorCallback.onError(error); 208 } 209 } 210 211 /* 212 * Error codes used by public APIs (AudioTrack, AudioRecord, AudioManager ...) 213 * Must be kept in sync with frameworks/base/core/jni/android_media_AudioErrors.h 214 */ 215 public static final int SUCCESS = 0; 216 public static final int ERROR = -1; 217 public static final int BAD_VALUE = -2; 218 public static final int INVALID_OPERATION = -3; 219 public static final int PERMISSION_DENIED = -4; 220 public static final int NO_INIT = -5; 221 public static final int DEAD_OBJECT = -6; 222 223 /* 224 * AudioPolicyService methods 225 */ 226 227 // 228 // audio device definitions: must be kept in sync with values in system/core/audio.h 229 // 230 231 public static final int DEVICE_NONE = 0x0; 232 // reserved bits 233 public static final int DEVICE_BIT_IN = 0x80000000; 234 public static final int DEVICE_BIT_DEFAULT = 0x40000000; 235 // output devices, be sure to update AudioManager.java also 236 public static final int DEVICE_OUT_EARPIECE = 0x1; 237 public static final int DEVICE_OUT_SPEAKER = 0x2; 238 public static final int DEVICE_OUT_WIRED_HEADSET = 0x4; 239 public static final int DEVICE_OUT_WIRED_HEADPHONE = 0x8; 240 public static final int DEVICE_OUT_BLUETOOTH_SCO = 0x10; 241 public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20; 242 public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40; 243 public static final int DEVICE_OUT_BLUETOOTH_A2DP = 0x80; 244 public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100; 245 public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200; 246 public static final int DEVICE_OUT_AUX_DIGITAL = 0x400; 247 public static final int DEVICE_OUT_HDMI = DEVICE_OUT_AUX_DIGITAL; 248 public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800; 249 public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000; 250 public static final int DEVICE_OUT_USB_ACCESSORY = 0x2000; 251 public static final int DEVICE_OUT_USB_DEVICE = 0x4000; 252 public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000; 253 public static final int DEVICE_OUT_TELEPHONY_TX = 0x10000; 254 public static final int DEVICE_OUT_LINE = 0x20000; 255 public static final int DEVICE_OUT_HDMI_ARC = 0x40000; 256 public static final int DEVICE_OUT_SPDIF = 0x80000; 257 public static final int DEVICE_OUT_FM = 0x100000; 258 public static final int DEVICE_OUT_AUX_LINE = 0x200000; 259 public static final int DEVICE_OUT_SPEAKER_SAFE = 0x400000; 260 261 public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT; 262 263 public static final int DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | 264 DEVICE_OUT_SPEAKER | 265 DEVICE_OUT_WIRED_HEADSET | 266 DEVICE_OUT_WIRED_HEADPHONE | 267 DEVICE_OUT_BLUETOOTH_SCO | 268 DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 269 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | 270 DEVICE_OUT_BLUETOOTH_A2DP | 271 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 272 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | 273 DEVICE_OUT_HDMI | 274 DEVICE_OUT_ANLG_DOCK_HEADSET | 275 DEVICE_OUT_DGTL_DOCK_HEADSET | 276 DEVICE_OUT_USB_ACCESSORY | 277 DEVICE_OUT_USB_DEVICE | 278 DEVICE_OUT_REMOTE_SUBMIX | 279 DEVICE_OUT_TELEPHONY_TX | 280 DEVICE_OUT_LINE | 281 DEVICE_OUT_HDMI_ARC | 282 DEVICE_OUT_SPDIF | 283 DEVICE_OUT_FM | 284 DEVICE_OUT_AUX_LINE | 285 DEVICE_OUT_SPEAKER_SAFE | 286 DEVICE_OUT_DEFAULT); 287 public static final int DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | 288 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 289 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); 290 public static final int DEVICE_OUT_ALL_SCO = (DEVICE_OUT_BLUETOOTH_SCO | 291 DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 292 DEVICE_OUT_BLUETOOTH_SCO_CARKIT); 293 public static final int DEVICE_OUT_ALL_USB = (DEVICE_OUT_USB_ACCESSORY | 294 DEVICE_OUT_USB_DEVICE); 295 public static final int DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO = (DEVICE_OUT_AUX_LINE | 296 DEVICE_OUT_HDMI_ARC | 297 DEVICE_OUT_SPDIF); 298 public static final int DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER = 299 (DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO | 300 DEVICE_OUT_SPEAKER); 301 302 // input devices 303 public static final int DEVICE_IN_COMMUNICATION = DEVICE_BIT_IN | 0x1; 304 public static final int DEVICE_IN_AMBIENT = DEVICE_BIT_IN | 0x2; 305 public static final int DEVICE_IN_BUILTIN_MIC = DEVICE_BIT_IN | 0x4; 306 public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = DEVICE_BIT_IN | 0x8; 307 public static final int DEVICE_IN_WIRED_HEADSET = DEVICE_BIT_IN | 0x10; 308 public static final int DEVICE_IN_AUX_DIGITAL = DEVICE_BIT_IN | 0x20; 309 public static final int DEVICE_IN_HDMI = DEVICE_IN_AUX_DIGITAL; 310 public static final int DEVICE_IN_VOICE_CALL = DEVICE_BIT_IN | 0x40; 311 public static final int DEVICE_IN_TELEPHONY_RX = DEVICE_IN_VOICE_CALL; 312 public static final int DEVICE_IN_BACK_MIC = DEVICE_BIT_IN | 0x80; 313 public static final int DEVICE_IN_REMOTE_SUBMIX = DEVICE_BIT_IN | 0x100; 314 public static final int DEVICE_IN_ANLG_DOCK_HEADSET = DEVICE_BIT_IN | 0x200; 315 public static final int DEVICE_IN_DGTL_DOCK_HEADSET = DEVICE_BIT_IN | 0x400; 316 public static final int DEVICE_IN_USB_ACCESSORY = DEVICE_BIT_IN | 0x800; 317 public static final int DEVICE_IN_USB_DEVICE = DEVICE_BIT_IN | 0x1000; 318 public static final int DEVICE_IN_FM_TUNER = DEVICE_BIT_IN | 0x2000; 319 public static final int DEVICE_IN_TV_TUNER = DEVICE_BIT_IN | 0x4000; 320 public static final int DEVICE_IN_LINE = DEVICE_BIT_IN | 0x8000; 321 public static final int DEVICE_IN_SPDIF = DEVICE_BIT_IN | 0x10000; 322 public static final int DEVICE_IN_BLUETOOTH_A2DP = DEVICE_BIT_IN | 0x20000; 323 public static final int DEVICE_IN_LOOPBACK = DEVICE_BIT_IN | 0x40000; 324 public static final int DEVICE_IN_DEFAULT = DEVICE_BIT_IN | DEVICE_BIT_DEFAULT; 325 326 public static final int DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | 327 DEVICE_IN_AMBIENT | 328 DEVICE_IN_BUILTIN_MIC | 329 DEVICE_IN_BLUETOOTH_SCO_HEADSET | 330 DEVICE_IN_WIRED_HEADSET | 331 DEVICE_IN_HDMI | 332 DEVICE_IN_TELEPHONY_RX | 333 DEVICE_IN_BACK_MIC | 334 DEVICE_IN_REMOTE_SUBMIX | 335 DEVICE_IN_ANLG_DOCK_HEADSET | 336 DEVICE_IN_DGTL_DOCK_HEADSET | 337 DEVICE_IN_USB_ACCESSORY | 338 DEVICE_IN_USB_DEVICE | 339 DEVICE_IN_FM_TUNER | 340 DEVICE_IN_TV_TUNER | 341 DEVICE_IN_LINE | 342 DEVICE_IN_SPDIF | 343 DEVICE_IN_BLUETOOTH_A2DP | 344 DEVICE_IN_LOOPBACK | 345 DEVICE_IN_DEFAULT); 346 public static final int DEVICE_IN_ALL_SCO = DEVICE_IN_BLUETOOTH_SCO_HEADSET; 347 public static final int DEVICE_IN_ALL_USB = (DEVICE_IN_USB_ACCESSORY | 348 DEVICE_IN_USB_DEVICE); 349 350 // device states, must match AudioSystem::device_connection_state 351 public static final int DEVICE_STATE_UNAVAILABLE = 0; 352 public static final int DEVICE_STATE_AVAILABLE = 1; 353 private static final int NUM_DEVICE_STATES = 1; 354 355 public static final String DEVICE_OUT_EARPIECE_NAME = "earpiece"; 356 public static final String DEVICE_OUT_SPEAKER_NAME = "speaker"; 357 public static final String DEVICE_OUT_WIRED_HEADSET_NAME = "headset"; 358 public static final String DEVICE_OUT_WIRED_HEADPHONE_NAME = "headphone"; 359 public static final String DEVICE_OUT_BLUETOOTH_SCO_NAME = "bt_sco"; 360 public static final String DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 361 public static final String DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME = "bt_sco_carkit"; 362 public static final String DEVICE_OUT_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 363 public static final String DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME = "bt_a2dp_hp"; 364 public static final String DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME = "bt_a2dp_spk"; 365 public static final String DEVICE_OUT_AUX_DIGITAL_NAME = "aux_digital"; 366 public static final String DEVICE_OUT_HDMI_NAME = "hdmi"; 367 public static final String DEVICE_OUT_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 368 public static final String DEVICE_OUT_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 369 public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory"; 370 public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device"; 371 public static final String DEVICE_OUT_REMOTE_SUBMIX_NAME = "remote_submix"; 372 public static final String DEVICE_OUT_TELEPHONY_TX_NAME = "telephony_tx"; 373 public static final String DEVICE_OUT_LINE_NAME = "line"; 374 public static final String DEVICE_OUT_HDMI_ARC_NAME = "hmdi_arc"; 375 public static final String DEVICE_OUT_SPDIF_NAME = "spdif"; 376 public static final String DEVICE_OUT_FM_NAME = "fm_transmitter"; 377 public static final String DEVICE_OUT_AUX_LINE_NAME = "aux_line"; 378 public static final String DEVICE_OUT_SPEAKER_SAFE_NAME = "speaker_safe"; 379 380 public static final String DEVICE_IN_COMMUNICATION_NAME = "communication"; 381 public static final String DEVICE_IN_AMBIENT_NAME = "ambient"; 382 public static final String DEVICE_IN_BUILTIN_MIC_NAME = "mic"; 383 public static final String DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; 384 public static final String DEVICE_IN_WIRED_HEADSET_NAME = "headset"; 385 public static final String DEVICE_IN_AUX_DIGITAL_NAME = "aux_digital"; 386 public static final String DEVICE_IN_TELEPHONY_RX_NAME = "telephony_rx"; 387 public static final String DEVICE_IN_BACK_MIC_NAME = "back_mic"; 388 public static final String DEVICE_IN_REMOTE_SUBMIX_NAME = "remote_submix"; 389 public static final String DEVICE_IN_ANLG_DOCK_HEADSET_NAME = "analog_dock"; 390 public static final String DEVICE_IN_DGTL_DOCK_HEADSET_NAME = "digital_dock"; 391 public static final String DEVICE_IN_USB_ACCESSORY_NAME = "usb_accessory"; 392 public static final String DEVICE_IN_USB_DEVICE_NAME = "usb_device"; 393 public static final String DEVICE_IN_FM_TUNER_NAME = "fm_tuner"; 394 public static final String DEVICE_IN_TV_TUNER_NAME = "tv_tuner"; 395 public static final String DEVICE_IN_LINE_NAME = "line"; 396 public static final String DEVICE_IN_SPDIF_NAME = "spdif"; 397 public static final String DEVICE_IN_BLUETOOTH_A2DP_NAME = "bt_a2dp"; 398 public static final String DEVICE_IN_LOOPBACK_NAME = "loopback"; 399 400 public static String getOutputDeviceName(int device) 401 { 402 switch(device) { 403 case DEVICE_OUT_EARPIECE: 404 return DEVICE_OUT_EARPIECE_NAME; 405 case DEVICE_OUT_SPEAKER: 406 return DEVICE_OUT_SPEAKER_NAME; 407 case DEVICE_OUT_WIRED_HEADSET: 408 return DEVICE_OUT_WIRED_HEADSET_NAME; 409 case DEVICE_OUT_WIRED_HEADPHONE: 410 return DEVICE_OUT_WIRED_HEADPHONE_NAME; 411 case DEVICE_OUT_BLUETOOTH_SCO: 412 return DEVICE_OUT_BLUETOOTH_SCO_NAME; 413 case DEVICE_OUT_BLUETOOTH_SCO_HEADSET: 414 return DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME; 415 case DEVICE_OUT_BLUETOOTH_SCO_CARKIT: 416 return DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME; 417 case DEVICE_OUT_BLUETOOTH_A2DP: 418 return DEVICE_OUT_BLUETOOTH_A2DP_NAME; 419 case DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: 420 return DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME; 421 case DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: 422 return DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME; 423 case DEVICE_OUT_HDMI: 424 return DEVICE_OUT_HDMI_NAME; 425 case DEVICE_OUT_ANLG_DOCK_HEADSET: 426 return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME; 427 case DEVICE_OUT_DGTL_DOCK_HEADSET: 428 return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME; 429 case DEVICE_OUT_USB_ACCESSORY: 430 return DEVICE_OUT_USB_ACCESSORY_NAME; 431 case DEVICE_OUT_USB_DEVICE: 432 return DEVICE_OUT_USB_DEVICE_NAME; 433 case DEVICE_OUT_REMOTE_SUBMIX: 434 return DEVICE_OUT_REMOTE_SUBMIX_NAME; 435 case DEVICE_OUT_TELEPHONY_TX: 436 return DEVICE_OUT_TELEPHONY_TX_NAME; 437 case DEVICE_OUT_LINE: 438 return DEVICE_OUT_LINE_NAME; 439 case DEVICE_OUT_HDMI_ARC: 440 return DEVICE_OUT_HDMI_ARC_NAME; 441 case DEVICE_OUT_SPDIF: 442 return DEVICE_OUT_SPDIF_NAME; 443 case DEVICE_OUT_FM: 444 return DEVICE_OUT_FM_NAME; 445 case DEVICE_OUT_AUX_LINE: 446 return DEVICE_OUT_AUX_LINE_NAME; 447 case DEVICE_OUT_SPEAKER_SAFE: 448 return DEVICE_OUT_SPEAKER_SAFE_NAME; 449 case DEVICE_OUT_DEFAULT: 450 default: 451 return Integer.toString(device); 452 } 453 } 454 455 public static String getInputDeviceName(int device) 456 { 457 switch(device) { 458 case DEVICE_IN_COMMUNICATION: 459 return DEVICE_IN_COMMUNICATION_NAME; 460 case DEVICE_IN_AMBIENT: 461 return DEVICE_IN_AMBIENT_NAME; 462 case DEVICE_IN_BUILTIN_MIC: 463 return DEVICE_IN_BUILTIN_MIC_NAME; 464 case DEVICE_IN_BLUETOOTH_SCO_HEADSET: 465 return DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME; 466 case DEVICE_IN_WIRED_HEADSET: 467 return DEVICE_IN_WIRED_HEADSET_NAME; 468 case DEVICE_IN_AUX_DIGITAL: 469 return DEVICE_IN_AUX_DIGITAL_NAME; 470 case DEVICE_IN_TELEPHONY_RX: 471 return DEVICE_IN_TELEPHONY_RX_NAME; 472 case DEVICE_IN_BACK_MIC: 473 return DEVICE_IN_BACK_MIC_NAME; 474 case DEVICE_IN_REMOTE_SUBMIX: 475 return DEVICE_IN_REMOTE_SUBMIX_NAME; 476 case DEVICE_IN_ANLG_DOCK_HEADSET: 477 return DEVICE_IN_ANLG_DOCK_HEADSET_NAME; 478 case DEVICE_IN_DGTL_DOCK_HEADSET: 479 return DEVICE_IN_DGTL_DOCK_HEADSET_NAME; 480 case DEVICE_IN_USB_ACCESSORY: 481 return DEVICE_IN_USB_ACCESSORY_NAME; 482 case DEVICE_IN_USB_DEVICE: 483 return DEVICE_IN_USB_DEVICE_NAME; 484 case DEVICE_IN_FM_TUNER: 485 return DEVICE_IN_FM_TUNER_NAME; 486 case DEVICE_IN_TV_TUNER: 487 return DEVICE_IN_TV_TUNER_NAME; 488 case DEVICE_IN_LINE: 489 return DEVICE_IN_LINE_NAME; 490 case DEVICE_IN_SPDIF: 491 return DEVICE_IN_SPDIF_NAME; 492 case DEVICE_IN_BLUETOOTH_A2DP: 493 return DEVICE_IN_BLUETOOTH_A2DP_NAME; 494 case DEVICE_IN_LOOPBACK: 495 return DEVICE_IN_LOOPBACK_NAME; 496 case DEVICE_IN_DEFAULT: 497 default: 498 return Integer.toString(device); 499 } 500 } 501 502 // phone state, match audio_mode??? 503 public static final int PHONE_STATE_OFFCALL = 0; 504 public static final int PHONE_STATE_RINGING = 1; 505 public static final int PHONE_STATE_INCALL = 2; 506 507 // device categories config for setForceUse, must match AudioSystem::forced_config 508 public static final int FORCE_NONE = 0; 509 public static final int FORCE_SPEAKER = 1; 510 public static final int FORCE_HEADPHONES = 2; 511 public static final int FORCE_BT_SCO = 3; 512 public static final int FORCE_BT_A2DP = 4; 513 public static final int FORCE_WIRED_ACCESSORY = 5; 514 public static final int FORCE_BT_CAR_DOCK = 6; 515 public static final int FORCE_BT_DESK_DOCK = 7; 516 public static final int FORCE_ANALOG_DOCK = 8; 517 public static final int FORCE_DIGITAL_DOCK = 9; 518 public static final int FORCE_NO_BT_A2DP = 10; 519 public static final int FORCE_SYSTEM_ENFORCED = 11; 520 public static final int FORCE_HDMI_SYSTEM_AUDIO_ENFORCED = 12; 521 private static final int NUM_FORCE_CONFIG = 13; 522 public static final int FORCE_DEFAULT = FORCE_NONE; 523 524 // usage for setForceUse, must match AudioSystem::force_use 525 public static final int FOR_COMMUNICATION = 0; 526 public static final int FOR_MEDIA = 1; 527 public static final int FOR_RECORD = 2; 528 public static final int FOR_DOCK = 3; 529 public static final int FOR_SYSTEM = 4; 530 public static final int FOR_HDMI_SYSTEM_AUDIO = 5; 531 private static final int NUM_FORCE_USE = 6; 532 533 // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t 534 public static final int SYNC_EVENT_NONE = 0; 535 public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1; 536 537 public static native int setDeviceConnectionState(int device, int state, String device_address); 538 public static native int getDeviceConnectionState(int device, String device_address); 539 public static native int setPhoneState(int state); 540 public static native int setForceUse(int usage, int config); 541 public static native int getForceUse(int usage); 542 public static native int initStreamVolume(int stream, int indexMin, int indexMax); 543 public static native int setStreamVolumeIndex(int stream, int index, int device); 544 public static native int getStreamVolumeIndex(int stream, int device); 545 public static native int setMasterVolume(float value); 546 public static native float getMasterVolume(); 547 public static native int setMasterMute(boolean mute); 548 public static native boolean getMasterMute(); 549 public static native int getDevicesForStream(int stream); 550 551 // helpers for android.media.AudioManager.getProperty(), see description there for meaning 552 public static native int getPrimaryOutputSamplingRate(); 553 public static native int getPrimaryOutputFrameCount(); 554 public static native int getOutputLatency(int stream); 555 556 public static native int setLowRamDevice(boolean isLowRamDevice); 557 public static native int checkAudioFlinger(); 558 559 public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); 560 public static native int createAudioPatch(AudioPatch[] patch, 561 AudioPortConfig[] sources, AudioPortConfig[] sinks); 562 public static native int releaseAudioPatch(AudioPatch patch); 563 public static native int listAudioPatches(ArrayList<AudioPatch> patches, int[] generation); 564 public static native int setAudioPortConfig(AudioPortConfig config); 565 566 // must be kept in sync with value in include/system/audio.h 567 public static final int AUDIO_HW_SYNC_INVALID = 0; 568 569 public static native int getAudioHwSyncForSession(int sessionId); 570 571 public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); 572 } 573 574