The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.pm.PackageManager; |
Eric Laurent | 7f5eb9f | 2014-12-01 19:36:30 -0800 | [diff] [blame] | 21 | import android.media.audiopolicy.AudioMix; |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 22 | import android.util.Log; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 23 | |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 24 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | /* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 27 | * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java. |
| 28 | * THANK YOU FOR YOUR COOPERATION. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | /** |
| 32 | * @hide |
| 33 | */ |
| 34 | public class AudioSystem |
| 35 | { |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 36 | private static final String TAG = "AudioSystem"; |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 37 | /* These values must be kept in sync with system/audio.h */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | /* |
| 39 | * If these are modified, please also update Settings.System.VOLUME_SETTINGS |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 40 | * and attrs.xml and AudioManager.java. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | */ |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 42 | /* The default audio stream */ |
| 43 | public static final int STREAM_DEFAULT = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | /* The audio stream for phone calls */ |
| 45 | public static final int STREAM_VOICE_CALL = 0; |
| 46 | /* The audio stream for system sounds */ |
| 47 | public static final int STREAM_SYSTEM = 1; |
| 48 | /* The audio stream for the phone ring and message alerts */ |
| 49 | public static final int STREAM_RING = 2; |
| 50 | /* The audio stream for music playback */ |
| 51 | public static final int STREAM_MUSIC = 3; |
| 52 | /* The audio stream for alarms */ |
| 53 | public static final int STREAM_ALARM = 4; |
| 54 | /* The audio stream for notifications */ |
| 55 | public static final int STREAM_NOTIFICATION = 5; |
| 56 | /* @hide The audio stream for phone calls when connected on bluetooth */ |
| 57 | public static final int STREAM_BLUETOOTH_SCO = 6; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 58 | /* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */ |
| 59 | public static final int STREAM_SYSTEM_ENFORCED = 7; |
| 60 | /* @hide The audio stream for DTMF tones */ |
| 61 | public static final int STREAM_DTMF = 8; |
| 62 | /* @hide The audio stream for text to speech (TTS) */ |
| 63 | public static final int STREAM_TTS = 9; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | /** |
| 65 | * @deprecated Use {@link #numStreamTypes() instead} |
| 66 | */ |
| 67 | public static final int NUM_STREAMS = 5; |
| 68 | |
| 69 | // Expose only the getter method publicly so we can change it in the future |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 70 | private static final int NUM_STREAM_TYPES = 10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } |
| 72 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 73 | public static final String[] STREAM_NAMES = new String[] { |
| 74 | "STREAM_VOICE_CALL", |
| 75 | "STREAM_SYSTEM", |
| 76 | "STREAM_RING", |
| 77 | "STREAM_MUSIC", |
| 78 | "STREAM_ALARM", |
| 79 | "STREAM_NOTIFICATION", |
| 80 | "STREAM_BLUETOOTH_SCO", |
| 81 | "STREAM_SYSTEM_ENFORCED", |
| 82 | "STREAM_DTMF", |
| 83 | "STREAM_TTS" |
| 84 | }; |
| 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | /* |
| 87 | * Sets the microphone mute on or off. |
| 88 | * |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 89 | * @param on set <var>true</var> to mute the microphone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | * <var>false</var> to turn mute off |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 91 | * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | */ |
| 93 | public static native int muteMicrophone(boolean on); |
| 94 | |
| 95 | /* |
| 96 | * Checks whether the microphone mute is on or off. |
| 97 | * |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 98 | * @return true if microphone is muted, false if it's not |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | */ |
| 100 | public static native boolean isMicrophoneMuted(); |
| 101 | |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 102 | /* modes for setPhoneState, must match AudioSystem.h audio_mode */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | public static final int MODE_INVALID = -2; |
| 104 | public static final int MODE_CURRENT = -1; |
| 105 | public static final int MODE_NORMAL = 0; |
| 106 | public static final int MODE_RINGTONE = 1; |
| 107 | public static final int MODE_IN_CALL = 2; |
Jean-Michel Trivi | 8f677d6 | 2010-11-15 12:11:32 -0800 | [diff] [blame] | 108 | public static final int MODE_IN_COMMUNICATION = 3; |
| 109 | public static final int NUM_MODES = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 112 | /* Routing bits for the former setRouting/getRouting API */ |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 113 | /** @deprecated */ |
| 114 | @Deprecated public static final int ROUTE_EARPIECE = (1 << 0); |
| 115 | /** @deprecated */ |
| 116 | @Deprecated public static final int ROUTE_SPEAKER = (1 << 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | /** @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */ |
| 118 | @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 119 | /** @deprecated */ |
| 120 | @Deprecated public static final int ROUTE_BLUETOOTH_SCO = (1 << 2); |
| 121 | /** @deprecated */ |
| 122 | @Deprecated public static final int ROUTE_HEADSET = (1 << 3); |
| 123 | /** @deprecated */ |
| 124 | @Deprecated public static final int ROUTE_BLUETOOTH_A2DP = (1 << 4); |
| 125 | /** @deprecated */ |
| 126 | @Deprecated public static final int ROUTE_ALL = 0xFFFFFFFF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
Rom Lemarchand | b2b2923 | 2015-04-03 15:11:28 -0700 | [diff] [blame] | 128 | // Keep in sync with system/media/audio/include/system/audio.h |
Glenn Kasten | 60bd67f | 2012-06-25 16:11:37 -0700 | [diff] [blame] | 129 | public static final int AUDIO_SESSION_ALLOCATE = 0; |
| 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | /* |
Eric Laurent | 23f25cd | 2010-01-25 08:49:09 -0800 | [diff] [blame] | 132 | * Checks whether the specified stream type is active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | * |
Eric Laurent | 23f25cd | 2010-01-25 08:49:09 -0800 | [diff] [blame] | 134 | * return true if any track playing on this stream is active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | */ |
Eric Laurent | 25101b0 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 136 | public static native boolean isStreamActive(int stream, int inPastMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
| 138 | /* |
Jean-Michel Trivi | 679d504 | 2013-02-04 16:24:09 -0800 | [diff] [blame] | 139 | * Checks whether the specified stream type is active on a remotely connected device. The notion |
| 140 | * of what constitutes a remote device is enforced by the audio policy manager of the platform. |
| 141 | * |
| 142 | * return true if any track playing on this stream is active on a remote device. |
| 143 | */ |
| 144 | public static native boolean isStreamActiveRemotely(int stream, int inPastMs); |
| 145 | |
| 146 | /* |
Jean-Michel Trivi | d677054 | 2012-10-10 12:03:41 -0700 | [diff] [blame] | 147 | * Checks whether the specified audio source is active. |
| 148 | * |
| 149 | * return true if any recorder using this source is currently recording |
| 150 | */ |
| 151 | public static native boolean isSourceActive(int source); |
| 152 | |
| 153 | /* |
Jean-Michel Trivi | 8a21f5d | 2014-06-05 15:03:52 -0700 | [diff] [blame] | 154 | * Returns a new unused audio session ID |
| 155 | */ |
| 156 | public static native int newAudioSessionId(); |
| 157 | |
| 158 | /* |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 159 | * Sets a group generic audio configuration parameters. The use of these parameters |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 160 | * are platform dependent, see libaudio |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | * |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 162 | * param keyValuePairs list of parameters key value pairs in the form: |
| 163 | * key1=value1;key2=value2;... |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | */ |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 165 | public static native int setParameters(String keyValuePairs); |
| 166 | |
| 167 | /* |
| 168 | * Gets a group generic audio configuration parameters. The use of these parameters |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 169 | * are platform dependent, see libaudio |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 170 | * |
| 171 | * param keys list of parameters |
| 172 | * return value: list of parameters key value pairs in the form: |
| 173 | * key1=value1;key2=value2;... |
| 174 | */ |
| 175 | public static native String getParameters(String keys); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 177 | // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /* Command sucessful or Media server restarted. see ErrorCallback */ |
| 179 | public static final int AUDIO_STATUS_OK = 0; |
| 180 | /* Command failed or unspecified audio error. see ErrorCallback */ |
| 181 | public static final int AUDIO_STATUS_ERROR = 1; |
| 182 | /* Media server died. see ErrorCallback */ |
| 183 | public static final int AUDIO_STATUS_SERVER_DIED = 100; |
| 184 | |
| 185 | private static ErrorCallback mErrorCallback; |
| 186 | |
| 187 | /* |
| 188 | * Handles the audio error callback. |
| 189 | */ |
| 190 | public interface ErrorCallback |
| 191 | { |
| 192 | /* |
| 193 | * Callback for audio server errors. |
| 194 | * param error error code: |
| 195 | * - AUDIO_STATUS_OK |
| 196 | * - AUDIO_STATUS_SERVER_DIED |
Eric Laurent | ef02827 | 2009-04-21 07:56:33 -0700 | [diff] [blame] | 197 | * - AUDIO_STATUS_ERROR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | */ |
| 199 | void onError(int error); |
| 200 | }; |
| 201 | |
| 202 | /* |
| 203 | * Registers a callback to be invoked when an error occurs. |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 204 | * @param cb the callback to run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | */ |
| 206 | public static void setErrorCallback(ErrorCallback cb) |
| 207 | { |
Eric Laurent | a25c5d8 | 2011-02-10 11:04:34 -0800 | [diff] [blame] | 208 | synchronized (AudioSystem.class) { |
| 209 | mErrorCallback = cb; |
Eric Laurent | dfb881f | 2013-07-18 14:41:39 -0700 | [diff] [blame] | 210 | if (cb != null) { |
| 211 | cb.onError(checkAudioFlinger()); |
| 212 | } |
Eric Laurent | a25c5d8 | 2011-02-10 11:04:34 -0800 | [diff] [blame] | 213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | private static void errorCallbackFromNative(int error) |
| 217 | { |
Eric Laurent | a25c5d8 | 2011-02-10 11:04:34 -0800 | [diff] [blame] | 218 | ErrorCallback errorCallback = null; |
| 219 | synchronized (AudioSystem.class) { |
| 220 | if (mErrorCallback != null) { |
| 221 | errorCallback = mErrorCallback; |
| 222 | } |
| 223 | } |
| 224 | if (errorCallback != null) { |
| 225 | errorCallback.onError(error); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | } |
| 227 | } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 228 | |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 229 | /** |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 230 | * Handles events from the audio policy manager about dynamic audio policies |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 231 | * @see android.media.audiopolicy.AudioPolicy |
| 232 | */ |
| 233 | public interface DynamicPolicyCallback |
| 234 | { |
| 235 | void onDynamicPolicyMixStateUpdate(String regId, int state); |
| 236 | } |
| 237 | |
| 238 | //keep in sync with include/media/AudioPolicy.h |
| 239 | private final static int DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE = 0; |
| 240 | |
| 241 | private static DynamicPolicyCallback sDynPolicyCallback; |
| 242 | |
| 243 | public static void setDynamicPolicyCallback(DynamicPolicyCallback cb) |
| 244 | { |
| 245 | synchronized (AudioSystem.class) { |
| 246 | sDynPolicyCallback = cb; |
| 247 | native_register_dynamic_policy_callback(); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | private static void dynamicPolicyCallbackFromNative(int event, String regId, int val) |
| 252 | { |
| 253 | DynamicPolicyCallback cb = null; |
| 254 | synchronized (AudioSystem.class) { |
| 255 | if (sDynPolicyCallback != null) { |
| 256 | cb = sDynPolicyCallback; |
| 257 | } |
| 258 | } |
| 259 | if (cb != null) { |
| 260 | switch(event) { |
| 261 | case DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE: |
| 262 | cb.onDynamicPolicyMixStateUpdate(regId, val); |
| 263 | break; |
| 264 | default: |
| 265 | Log.e(TAG, "dynamicPolicyCallbackFromNative: unknown event " + event); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 270 | /** |
| 271 | * Handles events from the audio policy manager about recording events |
| 272 | * @see android.media.AudioManager.AudioRecordingCallback |
| 273 | */ |
| 274 | public interface AudioRecordingCallback |
| 275 | { |
Jean-Michel Trivi | 33fd816 | 2016-02-22 10:52:41 -0800 | [diff] [blame] | 276 | /** |
| 277 | * Callback for recording activity notifications events |
| 278 | * @param event |
| 279 | * @param session |
| 280 | * @param source |
| 281 | * @param recordingFormat an array of ints containing respectively the client and device |
Jean-Michel Trivi | 8ab7280 | 2016-02-25 16:31:45 -0800 | [diff] [blame] | 282 | * recording configurations (2*3 ints), followed by the patch handle: |
| 283 | * index 0: client format |
| 284 | * 1: client channel mask |
| 285 | * 2: client sample rate |
| 286 | * 3: device format |
| 287 | * 4: device channel mask |
| 288 | * 5: device sample rate |
| 289 | * 6: patch handle |
Jean-Michel Trivi | 33fd816 | 2016-02-22 10:52:41 -0800 | [diff] [blame] | 290 | */ |
| 291 | void onRecordingConfigurationChanged(int event, int session, int source, |
| 292 | int[] recordingFormat); |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | private static AudioRecordingCallback sRecordingCallback; |
| 296 | |
| 297 | public static void setRecordingCallback(AudioRecordingCallback cb) { |
| 298 | synchronized (AudioSystem.class) { |
| 299 | sRecordingCallback = cb; |
| 300 | native_register_recording_callback(); |
| 301 | } |
| 302 | } |
| 303 | |
Jean-Michel Trivi | 33fd816 | 2016-02-22 10:52:41 -0800 | [diff] [blame] | 304 | /** |
| 305 | * Callback from native for recording configuration updates. |
| 306 | * @param event |
| 307 | * @param session |
| 308 | * @param source |
| 309 | * @param recordingFormat see |
| 310 | * {@link AudioRecordingCallback#onRecordingConfigurationChanged(int, int, int, int[])} for |
| 311 | * the description of the record format. |
| 312 | */ |
| 313 | private static void recordingCallbackFromNative(int event, int session, int source, |
| 314 | int[] recordingFormat) { |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 315 | AudioRecordingCallback cb = null; |
| 316 | synchronized (AudioSystem.class) { |
| 317 | cb = sRecordingCallback; |
| 318 | } |
| 319 | if (cb != null) { |
Jean-Michel Trivi | 33fd816 | 2016-02-22 10:52:41 -0800 | [diff] [blame] | 320 | cb.onRecordingConfigurationChanged(event, session, source, recordingFormat); |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 321 | } |
| 322 | } |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 323 | |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 324 | /* |
| 325 | * Error codes used by public APIs (AudioTrack, AudioRecord, AudioManager ...) |
| 326 | * Must be kept in sync with frameworks/base/core/jni/android_media_AudioErrors.h |
| 327 | */ |
| 328 | public static final int SUCCESS = 0; |
| 329 | public static final int ERROR = -1; |
| 330 | public static final int BAD_VALUE = -2; |
| 331 | public static final int INVALID_OPERATION = -3; |
| 332 | public static final int PERMISSION_DENIED = -4; |
| 333 | public static final int NO_INIT = -5; |
| 334 | public static final int DEAD_OBJECT = -6; |
Eric Laurent | 4e1ccd3 | 2015-07-02 12:09:44 -0700 | [diff] [blame] | 335 | public static final int WOULD_BLOCK = -7; |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 336 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 337 | /* |
| 338 | * AudioPolicyService methods |
| 339 | */ |
| 340 | |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 341 | // |
| 342 | // audio device definitions: must be kept in sync with values in system/core/audio.h |
| 343 | // |
| 344 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 345 | public static final int DEVICE_NONE = 0x0; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 346 | // reserved bits |
| 347 | public static final int DEVICE_BIT_IN = 0x80000000; |
| 348 | public static final int DEVICE_BIT_DEFAULT = 0x40000000; |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 349 | // output devices, be sure to update AudioManager.java also |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 350 | public static final int DEVICE_OUT_EARPIECE = 0x1; |
| 351 | public static final int DEVICE_OUT_SPEAKER = 0x2; |
| 352 | public static final int DEVICE_OUT_WIRED_HEADSET = 0x4; |
| 353 | public static final int DEVICE_OUT_WIRED_HEADPHONE = 0x8; |
| 354 | public static final int DEVICE_OUT_BLUETOOTH_SCO = 0x10; |
| 355 | public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20; |
| 356 | public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40; |
| 357 | public static final int DEVICE_OUT_BLUETOOTH_A2DP = 0x80; |
| 358 | public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100; |
| 359 | public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200; |
| 360 | public static final int DEVICE_OUT_AUX_DIGITAL = 0x400; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 361 | public static final int DEVICE_OUT_HDMI = DEVICE_OUT_AUX_DIGITAL; |
Praveen Bharathi | 21e941b | 2010-10-06 15:23:14 -0500 | [diff] [blame] | 362 | public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800; |
| 363 | public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000; |
Eric Laurent | 59f4827 | 2012-04-05 19:42:21 -0700 | [diff] [blame] | 364 | public static final int DEVICE_OUT_USB_ACCESSORY = 0x2000; |
| 365 | public static final int DEVICE_OUT_USB_DEVICE = 0x4000; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 366 | public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 367 | public static final int DEVICE_OUT_TELEPHONY_TX = 0x10000; |
| 368 | public static final int DEVICE_OUT_LINE = 0x20000; |
| 369 | public static final int DEVICE_OUT_HDMI_ARC = 0x40000; |
| 370 | public static final int DEVICE_OUT_SPDIF = 0x80000; |
| 371 | public static final int DEVICE_OUT_FM = 0x100000; |
Jungshik Jang | 12307ca | 2014-07-15 19:27:56 +0900 | [diff] [blame] | 372 | public static final int DEVICE_OUT_AUX_LINE = 0x200000; |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 373 | public static final int DEVICE_OUT_SPEAKER_SAFE = 0x400000; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 374 | public static final int DEVICE_OUT_IP = 0x800000; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 375 | public static final int DEVICE_OUT_BUS = 0x1000000; |
Eric Laurent | 59f4827 | 2012-04-05 19:42:21 -0700 | [diff] [blame] | 376 | |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 377 | public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT; |
Jean-Michel Trivi | 2ac2afe | 2012-08-21 11:16:55 -0700 | [diff] [blame] | 378 | |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 379 | public static final int DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | |
| 380 | DEVICE_OUT_SPEAKER | |
| 381 | DEVICE_OUT_WIRED_HEADSET | |
| 382 | DEVICE_OUT_WIRED_HEADPHONE | |
| 383 | DEVICE_OUT_BLUETOOTH_SCO | |
| 384 | DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
| 385 | DEVICE_OUT_BLUETOOTH_SCO_CARKIT | |
| 386 | DEVICE_OUT_BLUETOOTH_A2DP | |
| 387 | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 388 | DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 389 | DEVICE_OUT_HDMI | |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 390 | DEVICE_OUT_ANLG_DOCK_HEADSET | |
| 391 | DEVICE_OUT_DGTL_DOCK_HEADSET | |
Eric Laurent | 59f4827 | 2012-04-05 19:42:21 -0700 | [diff] [blame] | 392 | DEVICE_OUT_USB_ACCESSORY | |
| 393 | DEVICE_OUT_USB_DEVICE | |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 394 | DEVICE_OUT_REMOTE_SUBMIX | |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 395 | DEVICE_OUT_TELEPHONY_TX | |
| 396 | DEVICE_OUT_LINE | |
| 397 | DEVICE_OUT_HDMI_ARC | |
| 398 | DEVICE_OUT_SPDIF | |
| 399 | DEVICE_OUT_FM | |
Jungshik Jang | 12307ca | 2014-07-15 19:27:56 +0900 | [diff] [blame] | 400 | DEVICE_OUT_AUX_LINE | |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 401 | DEVICE_OUT_SPEAKER_SAFE | |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 402 | DEVICE_OUT_IP | |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 403 | DEVICE_OUT_BUS | |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 404 | DEVICE_OUT_DEFAULT); |
| 405 | public static final int DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | |
| 406 | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 407 | DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER); |
Eric Laurent | 59f4827 | 2012-04-05 19:42:21 -0700 | [diff] [blame] | 408 | public static final int DEVICE_OUT_ALL_SCO = (DEVICE_OUT_BLUETOOTH_SCO | |
| 409 | DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
| 410 | DEVICE_OUT_BLUETOOTH_SCO_CARKIT); |
| 411 | public static final int DEVICE_OUT_ALL_USB = (DEVICE_OUT_USB_ACCESSORY | |
| 412 | DEVICE_OUT_USB_DEVICE); |
Jungshik Jang | 12307ca | 2014-07-15 19:27:56 +0900 | [diff] [blame] | 413 | public static final int DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO = (DEVICE_OUT_AUX_LINE | |
Jungshik Jang | 41d9746 | 2014-06-30 22:26:29 +0900 | [diff] [blame] | 414 | DEVICE_OUT_HDMI_ARC | |
| 415 | DEVICE_OUT_SPDIF); |
Jungshik Jang | 6f34f5a | 2014-07-08 21:17:29 +0900 | [diff] [blame] | 416 | public static final int DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER = |
| 417 | (DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO | |
| 418 | DEVICE_OUT_SPEAKER); |
Eric Laurent | 59f4827 | 2012-04-05 19:42:21 -0700 | [diff] [blame] | 419 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 420 | // input devices |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 421 | public static final int DEVICE_IN_COMMUNICATION = DEVICE_BIT_IN | 0x1; |
| 422 | public static final int DEVICE_IN_AMBIENT = DEVICE_BIT_IN | 0x2; |
| 423 | public static final int DEVICE_IN_BUILTIN_MIC = DEVICE_BIT_IN | 0x4; |
| 424 | public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = DEVICE_BIT_IN | 0x8; |
| 425 | public static final int DEVICE_IN_WIRED_HEADSET = DEVICE_BIT_IN | 0x10; |
| 426 | public static final int DEVICE_IN_AUX_DIGITAL = DEVICE_BIT_IN | 0x20; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 427 | public static final int DEVICE_IN_HDMI = DEVICE_IN_AUX_DIGITAL; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 428 | public static final int DEVICE_IN_VOICE_CALL = DEVICE_BIT_IN | 0x40; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 429 | public static final int DEVICE_IN_TELEPHONY_RX = DEVICE_IN_VOICE_CALL; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 430 | public static final int DEVICE_IN_BACK_MIC = DEVICE_BIT_IN | 0x80; |
| 431 | public static final int DEVICE_IN_REMOTE_SUBMIX = DEVICE_BIT_IN | 0x100; |
| 432 | public static final int DEVICE_IN_ANLG_DOCK_HEADSET = DEVICE_BIT_IN | 0x200; |
| 433 | public static final int DEVICE_IN_DGTL_DOCK_HEADSET = DEVICE_BIT_IN | 0x400; |
| 434 | public static final int DEVICE_IN_USB_ACCESSORY = DEVICE_BIT_IN | 0x800; |
| 435 | public static final int DEVICE_IN_USB_DEVICE = DEVICE_BIT_IN | 0x1000; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 436 | public static final int DEVICE_IN_FM_TUNER = DEVICE_BIT_IN | 0x2000; |
| 437 | public static final int DEVICE_IN_TV_TUNER = DEVICE_BIT_IN | 0x4000; |
| 438 | public static final int DEVICE_IN_LINE = DEVICE_BIT_IN | 0x8000; |
| 439 | public static final int DEVICE_IN_SPDIF = DEVICE_BIT_IN | 0x10000; |
Mike Lockwood | 0a40ec2 | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 440 | public static final int DEVICE_IN_BLUETOOTH_A2DP = DEVICE_BIT_IN | 0x20000; |
Terry Heo | 112c19e | 2014-07-07 10:25:38 +0900 | [diff] [blame] | 441 | public static final int DEVICE_IN_LOOPBACK = DEVICE_BIT_IN | 0x40000; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 442 | public static final int DEVICE_IN_IP = DEVICE_BIT_IN | 0x80000; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 443 | public static final int DEVICE_IN_BUS = DEVICE_BIT_IN | 0x100000; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 444 | public static final int DEVICE_IN_DEFAULT = DEVICE_BIT_IN | DEVICE_BIT_DEFAULT; |
| 445 | |
| 446 | public static final int DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | |
| 447 | DEVICE_IN_AMBIENT | |
| 448 | DEVICE_IN_BUILTIN_MIC | |
| 449 | DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
| 450 | DEVICE_IN_WIRED_HEADSET | |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 451 | DEVICE_IN_HDMI | |
| 452 | DEVICE_IN_TELEPHONY_RX | |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 453 | DEVICE_IN_BACK_MIC | |
| 454 | DEVICE_IN_REMOTE_SUBMIX | |
| 455 | DEVICE_IN_ANLG_DOCK_HEADSET | |
| 456 | DEVICE_IN_DGTL_DOCK_HEADSET | |
| 457 | DEVICE_IN_USB_ACCESSORY | |
| 458 | DEVICE_IN_USB_DEVICE | |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 459 | DEVICE_IN_FM_TUNER | |
| 460 | DEVICE_IN_TV_TUNER | |
| 461 | DEVICE_IN_LINE | |
| 462 | DEVICE_IN_SPDIF | |
Mike Lockwood | 0a40ec2 | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 463 | DEVICE_IN_BLUETOOTH_A2DP | |
Terry Heo | 112c19e | 2014-07-07 10:25:38 +0900 | [diff] [blame] | 464 | DEVICE_IN_LOOPBACK | |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 465 | DEVICE_IN_IP | |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 466 | DEVICE_IN_BUS | |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 467 | DEVICE_IN_DEFAULT); |
| 468 | public static final int DEVICE_IN_ALL_SCO = DEVICE_IN_BLUETOOTH_SCO_HEADSET; |
Paul McLean | c837a45 | 2014-04-09 09:04:43 -0700 | [diff] [blame] | 469 | public static final int DEVICE_IN_ALL_USB = (DEVICE_IN_USB_ACCESSORY | |
| 470 | DEVICE_IN_USB_DEVICE); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 471 | |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 472 | // device states, must match AudioSystem::device_connection_state |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 473 | public static final int DEVICE_STATE_UNAVAILABLE = 0; |
| 474 | public static final int DEVICE_STATE_AVAILABLE = 1; |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 475 | private static final int NUM_DEVICE_STATES = 1; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 476 | |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 477 | public static final String DEVICE_OUT_EARPIECE_NAME = "earpiece"; |
| 478 | public static final String DEVICE_OUT_SPEAKER_NAME = "speaker"; |
| 479 | public static final String DEVICE_OUT_WIRED_HEADSET_NAME = "headset"; |
| 480 | public static final String DEVICE_OUT_WIRED_HEADPHONE_NAME = "headphone"; |
| 481 | public static final String DEVICE_OUT_BLUETOOTH_SCO_NAME = "bt_sco"; |
| 482 | public static final String DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; |
| 483 | public static final String DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME = "bt_sco_carkit"; |
| 484 | public static final String DEVICE_OUT_BLUETOOTH_A2DP_NAME = "bt_a2dp"; |
| 485 | public static final String DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME = "bt_a2dp_hp"; |
| 486 | public static final String DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME = "bt_a2dp_spk"; |
| 487 | public static final String DEVICE_OUT_AUX_DIGITAL_NAME = "aux_digital"; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 488 | public static final String DEVICE_OUT_HDMI_NAME = "hdmi"; |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 489 | public static final String DEVICE_OUT_ANLG_DOCK_HEADSET_NAME = "analog_dock"; |
| 490 | public static final String DEVICE_OUT_DGTL_DOCK_HEADSET_NAME = "digital_dock"; |
Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 491 | public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory"; |
| 492 | public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device"; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 493 | public static final String DEVICE_OUT_REMOTE_SUBMIX_NAME = "remote_submix"; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 494 | public static final String DEVICE_OUT_TELEPHONY_TX_NAME = "telephony_tx"; |
| 495 | public static final String DEVICE_OUT_LINE_NAME = "line"; |
| 496 | public static final String DEVICE_OUT_HDMI_ARC_NAME = "hmdi_arc"; |
| 497 | public static final String DEVICE_OUT_SPDIF_NAME = "spdif"; |
| 498 | public static final String DEVICE_OUT_FM_NAME = "fm_transmitter"; |
John Spurlock | 2b29bc4 | 2014-08-26 16:40:35 -0400 | [diff] [blame] | 499 | public static final String DEVICE_OUT_AUX_LINE_NAME = "aux_line"; |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 500 | public static final String DEVICE_OUT_SPEAKER_SAFE_NAME = "speaker_safe"; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 501 | public static final String DEVICE_OUT_IP_NAME = "ip"; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 502 | public static final String DEVICE_OUT_BUS_NAME = "bus"; |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 503 | |
| 504 | public static final String DEVICE_IN_COMMUNICATION_NAME = "communication"; |
| 505 | public static final String DEVICE_IN_AMBIENT_NAME = "ambient"; |
| 506 | public static final String DEVICE_IN_BUILTIN_MIC_NAME = "mic"; |
| 507 | public static final String DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME = "bt_sco_hs"; |
| 508 | public static final String DEVICE_IN_WIRED_HEADSET_NAME = "headset"; |
| 509 | public static final String DEVICE_IN_AUX_DIGITAL_NAME = "aux_digital"; |
| 510 | public static final String DEVICE_IN_TELEPHONY_RX_NAME = "telephony_rx"; |
| 511 | public static final String DEVICE_IN_BACK_MIC_NAME = "back_mic"; |
| 512 | public static final String DEVICE_IN_REMOTE_SUBMIX_NAME = "remote_submix"; |
| 513 | public static final String DEVICE_IN_ANLG_DOCK_HEADSET_NAME = "analog_dock"; |
| 514 | public static final String DEVICE_IN_DGTL_DOCK_HEADSET_NAME = "digital_dock"; |
| 515 | public static final String DEVICE_IN_USB_ACCESSORY_NAME = "usb_accessory"; |
| 516 | public static final String DEVICE_IN_USB_DEVICE_NAME = "usb_device"; |
| 517 | public static final String DEVICE_IN_FM_TUNER_NAME = "fm_tuner"; |
| 518 | public static final String DEVICE_IN_TV_TUNER_NAME = "tv_tuner"; |
| 519 | public static final String DEVICE_IN_LINE_NAME = "line"; |
| 520 | public static final String DEVICE_IN_SPDIF_NAME = "spdif"; |
| 521 | public static final String DEVICE_IN_BLUETOOTH_A2DP_NAME = "bt_a2dp"; |
| 522 | public static final String DEVICE_IN_LOOPBACK_NAME = "loopback"; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 523 | public static final String DEVICE_IN_IP_NAME = "ip"; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 524 | public static final String DEVICE_IN_BUS_NAME = "bus"; |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 525 | |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 526 | public static String getOutputDeviceName(int device) |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 527 | { |
| 528 | switch(device) { |
| 529 | case DEVICE_OUT_EARPIECE: |
| 530 | return DEVICE_OUT_EARPIECE_NAME; |
| 531 | case DEVICE_OUT_SPEAKER: |
| 532 | return DEVICE_OUT_SPEAKER_NAME; |
| 533 | case DEVICE_OUT_WIRED_HEADSET: |
| 534 | return DEVICE_OUT_WIRED_HEADSET_NAME; |
| 535 | case DEVICE_OUT_WIRED_HEADPHONE: |
| 536 | return DEVICE_OUT_WIRED_HEADPHONE_NAME; |
| 537 | case DEVICE_OUT_BLUETOOTH_SCO: |
| 538 | return DEVICE_OUT_BLUETOOTH_SCO_NAME; |
| 539 | case DEVICE_OUT_BLUETOOTH_SCO_HEADSET: |
| 540 | return DEVICE_OUT_BLUETOOTH_SCO_HEADSET_NAME; |
| 541 | case DEVICE_OUT_BLUETOOTH_SCO_CARKIT: |
| 542 | return DEVICE_OUT_BLUETOOTH_SCO_CARKIT_NAME; |
| 543 | case DEVICE_OUT_BLUETOOTH_A2DP: |
| 544 | return DEVICE_OUT_BLUETOOTH_A2DP_NAME; |
| 545 | case DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: |
| 546 | return DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES_NAME; |
| 547 | case DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: |
| 548 | return DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER_NAME; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 549 | case DEVICE_OUT_HDMI: |
| 550 | return DEVICE_OUT_HDMI_NAME; |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 551 | case DEVICE_OUT_ANLG_DOCK_HEADSET: |
| 552 | return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME; |
| 553 | case DEVICE_OUT_DGTL_DOCK_HEADSET: |
| 554 | return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME; |
Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 555 | case DEVICE_OUT_USB_ACCESSORY: |
| 556 | return DEVICE_OUT_USB_ACCESSORY_NAME; |
| 557 | case DEVICE_OUT_USB_DEVICE: |
| 558 | return DEVICE_OUT_USB_DEVICE_NAME; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 559 | case DEVICE_OUT_REMOTE_SUBMIX: |
| 560 | return DEVICE_OUT_REMOTE_SUBMIX_NAME; |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 561 | case DEVICE_OUT_TELEPHONY_TX: |
| 562 | return DEVICE_OUT_TELEPHONY_TX_NAME; |
| 563 | case DEVICE_OUT_LINE: |
| 564 | return DEVICE_OUT_LINE_NAME; |
| 565 | case DEVICE_OUT_HDMI_ARC: |
| 566 | return DEVICE_OUT_HDMI_ARC_NAME; |
| 567 | case DEVICE_OUT_SPDIF: |
| 568 | return DEVICE_OUT_SPDIF_NAME; |
| 569 | case DEVICE_OUT_FM: |
| 570 | return DEVICE_OUT_FM_NAME; |
John Spurlock | 2b29bc4 | 2014-08-26 16:40:35 -0400 | [diff] [blame] | 571 | case DEVICE_OUT_AUX_LINE: |
| 572 | return DEVICE_OUT_AUX_LINE_NAME; |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 573 | case DEVICE_OUT_SPEAKER_SAFE: |
| 574 | return DEVICE_OUT_SPEAKER_SAFE_NAME; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 575 | case DEVICE_OUT_IP: |
| 576 | return DEVICE_OUT_IP_NAME; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 577 | case DEVICE_OUT_BUS: |
| 578 | return DEVICE_OUT_BUS_NAME; |
Eric Laurent | 53082ec | 2012-08-28 14:27:29 -0700 | [diff] [blame] | 579 | case DEVICE_OUT_DEFAULT: |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 580 | default: |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 581 | return Integer.toString(device); |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 585 | public static String getInputDeviceName(int device) |
| 586 | { |
| 587 | switch(device) { |
| 588 | case DEVICE_IN_COMMUNICATION: |
| 589 | return DEVICE_IN_COMMUNICATION_NAME; |
| 590 | case DEVICE_IN_AMBIENT: |
| 591 | return DEVICE_IN_AMBIENT_NAME; |
| 592 | case DEVICE_IN_BUILTIN_MIC: |
| 593 | return DEVICE_IN_BUILTIN_MIC_NAME; |
| 594 | case DEVICE_IN_BLUETOOTH_SCO_HEADSET: |
| 595 | return DEVICE_IN_BLUETOOTH_SCO_HEADSET_NAME; |
| 596 | case DEVICE_IN_WIRED_HEADSET: |
| 597 | return DEVICE_IN_WIRED_HEADSET_NAME; |
| 598 | case DEVICE_IN_AUX_DIGITAL: |
| 599 | return DEVICE_IN_AUX_DIGITAL_NAME; |
| 600 | case DEVICE_IN_TELEPHONY_RX: |
| 601 | return DEVICE_IN_TELEPHONY_RX_NAME; |
| 602 | case DEVICE_IN_BACK_MIC: |
| 603 | return DEVICE_IN_BACK_MIC_NAME; |
| 604 | case DEVICE_IN_REMOTE_SUBMIX: |
| 605 | return DEVICE_IN_REMOTE_SUBMIX_NAME; |
| 606 | case DEVICE_IN_ANLG_DOCK_HEADSET: |
| 607 | return DEVICE_IN_ANLG_DOCK_HEADSET_NAME; |
| 608 | case DEVICE_IN_DGTL_DOCK_HEADSET: |
| 609 | return DEVICE_IN_DGTL_DOCK_HEADSET_NAME; |
| 610 | case DEVICE_IN_USB_ACCESSORY: |
| 611 | return DEVICE_IN_USB_ACCESSORY_NAME; |
| 612 | case DEVICE_IN_USB_DEVICE: |
| 613 | return DEVICE_IN_USB_DEVICE_NAME; |
| 614 | case DEVICE_IN_FM_TUNER: |
| 615 | return DEVICE_IN_FM_TUNER_NAME; |
| 616 | case DEVICE_IN_TV_TUNER: |
| 617 | return DEVICE_IN_TV_TUNER_NAME; |
| 618 | case DEVICE_IN_LINE: |
| 619 | return DEVICE_IN_LINE_NAME; |
| 620 | case DEVICE_IN_SPDIF: |
| 621 | return DEVICE_IN_SPDIF_NAME; |
| 622 | case DEVICE_IN_BLUETOOTH_A2DP: |
| 623 | return DEVICE_IN_BLUETOOTH_A2DP_NAME; |
| 624 | case DEVICE_IN_LOOPBACK: |
| 625 | return DEVICE_IN_LOOPBACK_NAME; |
Eric Laurent | 1e725f8 | 2015-07-01 16:38:22 -0700 | [diff] [blame] | 626 | case DEVICE_IN_IP: |
| 627 | return DEVICE_IN_IP_NAME; |
Jean-Michel Trivi | 93687f2 | 2016-02-18 10:16:07 -0800 | [diff] [blame] | 628 | case DEVICE_IN_BUS: |
| 629 | return DEVICE_IN_BUS_NAME; |
Mike Lockwood | 07cd124 | 2014-10-27 13:34:45 -0700 | [diff] [blame] | 630 | case DEVICE_IN_DEFAULT: |
| 631 | default: |
| 632 | return Integer.toString(device); |
| 633 | } |
| 634 | } |
Eric Laurent | 948d327 | 2014-05-16 15:18:45 -0700 | [diff] [blame] | 635 | |
Glenn Kasten | ed0079d | 2011-04-04 10:50:50 -0700 | [diff] [blame] | 636 | // phone state, match audio_mode??? |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 637 | public static final int PHONE_STATE_OFFCALL = 0; |
| 638 | public static final int PHONE_STATE_RINGING = 1; |
| 639 | public static final int PHONE_STATE_INCALL = 2; |
| 640 | |
Phil Burk | ac0f704 | 2016-02-24 12:19:08 -0800 | [diff] [blame] | 641 | // device categories config for setForceUse, must match audio_policy_forced_cfg_t |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 642 | public static final int FORCE_NONE = 0; |
| 643 | public static final int FORCE_SPEAKER = 1; |
| 644 | public static final int FORCE_HEADPHONES = 2; |
| 645 | public static final int FORCE_BT_SCO = 3; |
| 646 | public static final int FORCE_BT_A2DP = 4; |
| 647 | public static final int FORCE_WIRED_ACCESSORY = 5; |
Eric Laurent | eb14a78 | 2009-12-17 03:12:59 -0800 | [diff] [blame] | 648 | public static final int FORCE_BT_CAR_DOCK = 6; |
| 649 | public static final int FORCE_BT_DESK_DOCK = 7; |
Praveen Bharathi | 21e941b | 2010-10-06 15:23:14 -0500 | [diff] [blame] | 650 | public static final int FORCE_ANALOG_DOCK = 8; |
| 651 | public static final int FORCE_DIGITAL_DOCK = 9; |
Eric Laurent | 7847211 | 2012-05-21 08:57:21 -0700 | [diff] [blame] | 652 | public static final int FORCE_NO_BT_A2DP = 10; |
Jean-Michel Trivi | c203ecf | 2012-10-11 10:13:50 -0700 | [diff] [blame] | 653 | public static final int FORCE_SYSTEM_ENFORCED = 11; |
Jungshik Jang | 12307ca | 2014-07-15 19:27:56 +0900 | [diff] [blame] | 654 | public static final int FORCE_HDMI_SYSTEM_AUDIO_ENFORCED = 12; |
Phil Burk | ac0f704 | 2016-02-24 12:19:08 -0800 | [diff] [blame] | 655 | public static final int FORCE_ENCODED_SURROUND_NEVER = 13; |
| 656 | public static final int FORCE_ENCODED_SURROUND_ALWAYS = 14; |
| 657 | public static final int NUM_FORCE_CONFIG = 15; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 658 | public static final int FORCE_DEFAULT = FORCE_NONE; |
| 659 | |
Phil Burk | ac0f704 | 2016-02-24 12:19:08 -0800 | [diff] [blame] | 660 | // usage for setForceUse, must match audio_policy_force_use_t |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 661 | public static final int FOR_COMMUNICATION = 0; |
| 662 | public static final int FOR_MEDIA = 1; |
| 663 | public static final int FOR_RECORD = 2; |
Jean-Michel Trivi | 6154412 | 2009-12-07 18:40:56 -0800 | [diff] [blame] | 664 | public static final int FOR_DOCK = 3; |
Eric Laurent | dd45d01 | 2012-10-08 09:04:34 -0700 | [diff] [blame] | 665 | public static final int FOR_SYSTEM = 4; |
Jungshik Jang | 12307ca | 2014-07-15 19:27:56 +0900 | [diff] [blame] | 666 | public static final int FOR_HDMI_SYSTEM_AUDIO = 5; |
Phil Burk | ac0f704 | 2016-02-24 12:19:08 -0800 | [diff] [blame] | 667 | public static final int FOR_ENCODED_SURROUND = 6; |
| 668 | private static final int NUM_FORCE_USE = 7; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 669 | |
Eric Laurent | 505e5c8 | 2012-03-29 15:19:36 -0700 | [diff] [blame] | 670 | // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t |
| 671 | public static final int SYNC_EVENT_NONE = 0; |
| 672 | public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1; |
| 673 | |
Jean-Michel Trivi | 6d00e41 | 2015-08-03 17:26:01 -0700 | [diff] [blame] | 674 | /** |
| 675 | * @return command completion status, one of {@link #AUDIO_STATUS_OK}, |
| 676 | * {@link #AUDIO_STATUS_ERROR} or {@link #AUDIO_STATUS_SERVER_DIED} |
| 677 | */ |
Paul McLean | 10804eb | 2015-01-28 11:16:35 -0800 | [diff] [blame] | 678 | public static native int setDeviceConnectionState(int device, int state, |
| 679 | String device_address, String device_name); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 680 | public static native int getDeviceConnectionState(int device, String device_address); |
| 681 | public static native int setPhoneState(int state); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 682 | public static native int setForceUse(int usage, int config); |
| 683 | public static native int getForceUse(int usage); |
| 684 | public static native int initStreamVolume(int stream, int indexMin, int indexMax); |
Eric Laurent | 9bc8358d | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 685 | public static native int setStreamVolumeIndex(int stream, int index, int device); |
| 686 | public static native int getStreamVolumeIndex(int stream, int device); |
Mike Lockwood | cbdb49d | 2011-10-20 12:54:05 -0400 | [diff] [blame] | 687 | public static native int setMasterVolume(float value); |
| 688 | public static native float getMasterVolume(); |
| 689 | public static native int setMasterMute(boolean mute); |
| 690 | public static native boolean getMasterMute(); |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 691 | public static native int getDevicesForStream(int stream); |
Glenn Kasten | c6c4365 | 2012-09-24 17:32:30 -0700 | [diff] [blame] | 692 | |
Andy Hung | f04b84d | 2015-12-18 17:33:27 -0800 | [diff] [blame] | 693 | /** @hide returns true if master mono is enabled. */ |
| 694 | public static native boolean getMasterMono(); |
| 695 | /** @hide enables or disables the master mono mode. */ |
| 696 | public static native int setMasterMono(boolean mono); |
| 697 | |
Glenn Kasten | c6c4365 | 2012-09-24 17:32:30 -0700 | [diff] [blame] | 698 | // helpers for android.media.AudioManager.getProperty(), see description there for meaning |
| 699 | public static native int getPrimaryOutputSamplingRate(); |
| 700 | public static native int getPrimaryOutputFrameCount(); |
Oliver Woodman | 61dcdf3 | 2013-06-26 12:43:36 +0100 | [diff] [blame] | 701 | public static native int getOutputLatency(int stream); |
Glenn Kasten | c6c4365 | 2012-09-24 17:32:30 -0700 | [diff] [blame] | 702 | |
Glenn Kasten | fd116ad | 2013-07-12 17:10:39 -0700 | [diff] [blame] | 703 | public static native int setLowRamDevice(boolean isLowRamDevice); |
Eric Laurent | dfb881f | 2013-07-18 14:41:39 -0700 | [diff] [blame] | 704 | public static native int checkAudioFlinger(); |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 705 | |
| 706 | public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); |
| 707 | public static native int createAudioPatch(AudioPatch[] patch, |
| 708 | AudioPortConfig[] sources, AudioPortConfig[] sinks); |
| 709 | public static native int releaseAudioPatch(AudioPatch patch); |
| 710 | public static native int listAudioPatches(ArrayList<AudioPatch> patches, int[] generation); |
Eric Laurent | 3a24199 | 2014-05-19 19:33:26 -0700 | [diff] [blame] | 711 | public static native int setAudioPortConfig(AudioPortConfig config); |
Eric Laurent | b634e1b | 2014-08-01 14:44:46 -0700 | [diff] [blame] | 712 | |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 713 | // declare this instance as having a dynamic policy callback handler |
| 714 | private static native final void native_register_dynamic_policy_callback(); |
Jean-Michel Trivi | d3c71f0 | 2015-12-07 11:59:31 -0800 | [diff] [blame] | 715 | // declare this instance as having a recording configuration update callback handler |
| 716 | private static native final void native_register_recording_callback(); |
Jean-Michel Trivi | 5a56109 | 2015-04-23 18:48:08 -0700 | [diff] [blame] | 717 | |
Eric Laurent | b634e1b | 2014-08-01 14:44:46 -0700 | [diff] [blame] | 718 | // must be kept in sync with value in include/system/audio.h |
| 719 | public static final int AUDIO_HW_SYNC_INVALID = 0; |
| 720 | |
| 721 | public static native int getAudioHwSyncForSession(int sessionId); |
Eric Laurent | 7f5eb9f | 2014-12-01 19:36:30 -0800 | [diff] [blame] | 722 | |
| 723 | public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 724 | |
Eric Laurent | 0867bed | 2015-05-20 14:49:08 -0700 | [diff] [blame] | 725 | public static native int systemReady(); |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 726 | |
| 727 | // Items shared with audio service |
| 728 | |
| 729 | /** |
| 730 | * The delay before playing a sound. This small period exists so the user |
| 731 | * can press another key (non-volume keys, too) to have it NOT be audible. |
| 732 | * <p> |
| 733 | * PhoneWindow will implement this part. |
| 734 | */ |
| 735 | public static final int PLAY_SOUND_DELAY = 300; |
| 736 | |
| 737 | /** |
| 738 | * Constant to identify a focus stack entry that is used to hold the focus while the phone |
| 739 | * is ringing or during a call. Used by com.android.internal.telephony.CallManager when |
| 740 | * entering and exiting calls. |
| 741 | */ |
| 742 | public final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls"; |
| 743 | |
| 744 | /** |
| 745 | * @see AudioManager#setVibrateSetting(int, int) |
| 746 | */ |
| 747 | public static int getValueForVibrateSetting(int existingValue, int vibrateType, |
| 748 | int vibrateSetting) { |
| 749 | |
| 750 | // First clear the existing setting. Each vibrate type has two bits in |
| 751 | // the value. Note '3' is '11' in binary. |
| 752 | existingValue &= ~(3 << (vibrateType * 2)); |
| 753 | |
| 754 | // Set into the old value |
| 755 | existingValue |= (vibrateSetting & 3) << (vibrateType * 2); |
| 756 | |
| 757 | return existingValue; |
| 758 | } |
| 759 | |
| 760 | public static int getDefaultStreamVolume(int streamType) { |
| 761 | return DEFAULT_STREAM_VOLUME[streamType]; |
| 762 | } |
| 763 | |
| 764 | public static int[] DEFAULT_STREAM_VOLUME = new int[] { |
| 765 | 4, // STREAM_VOICE_CALL |
| 766 | 7, // STREAM_SYSTEM |
| 767 | 5, // STREAM_RING |
| 768 | 11, // STREAM_MUSIC |
| 769 | 6, // STREAM_ALARM |
| 770 | 5, // STREAM_NOTIFICATION |
| 771 | 7, // STREAM_BLUETOOTH_SCO |
| 772 | 7, // STREAM_SYSTEM_ENFORCED |
| 773 | 11, // STREAM_DTMF |
| 774 | 11 // STREAM_TTS |
| 775 | }; |
| 776 | |
| 777 | public static String streamToString(int stream) { |
| 778 | if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream]; |
| 779 | if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE"; |
| 780 | return "UNKNOWN_STREAM_" + stream; |
| 781 | } |
| 782 | |
| 783 | /** The platform has no specific capabilities */ |
| 784 | public static final int PLATFORM_DEFAULT = 0; |
| 785 | /** The platform is voice call capable (a phone) */ |
| 786 | public static final int PLATFORM_VOICE = 1; |
| 787 | /** The platform is a television or a set-top box */ |
| 788 | public static final int PLATFORM_TELEVISION = 2; |
| 789 | |
| 790 | /** |
| 791 | * Return the platform type that this is running on. One of: |
| 792 | * <ul> |
| 793 | * <li>{@link #PLATFORM_VOICE}</li> |
| 794 | * <li>{@link #PLATFORM_TELEVISION}</li> |
| 795 | * <li>{@link #PLATFORM_DEFAULT}</li> |
| 796 | * </ul> |
| 797 | */ |
| 798 | public static int getPlatformType(Context context) { |
| 799 | if (context.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) { |
| 800 | return PLATFORM_VOICE; |
| 801 | } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { |
| 802 | return PLATFORM_TELEVISION; |
| 803 | } else { |
| 804 | return PLATFORM_DEFAULT; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | public static final int DEFAULT_MUTE_STREAMS_AFFECTED = |
| 809 | (1 << STREAM_MUSIC) | |
| 810 | (1 << STREAM_RING) | |
| 811 | (1 << STREAM_NOTIFICATION) | |
| 812 | (1 << STREAM_SYSTEM); |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 813 | |
| 814 | /** |
| 815 | * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes. |
| 816 | * Keep in sync with core/jni/android_media_DeviceCallback.h. |
| 817 | */ |
| 818 | final static int NATIVE_EVENT_ROUTING_CHANGE = 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 820 | |