AudioSystem.java revision 2ba92c71b5684dce700cf848bf157153c156df1d
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 17package android.media; 18 19 20/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET 21 * TO UPDATE THE CORRESPONDING NATIVE GLUE. THANK YOU FOR YOUR COOPERATION 22 */ 23 24/** 25 * @hide 26 */ 27public class AudioSystem 28{ 29 /* FIXME: Need to finalize this and correlate with native layer */ 30 /* 31 * If these are modified, please also update Settings.System.VOLUME_SETTINGS 32 * and attrs.xml 33 */ 34 /* The audio stream for phone calls */ 35 public static final int STREAM_VOICE_CALL = 0; 36 /* The audio stream for system sounds */ 37 public static final int STREAM_SYSTEM = 1; 38 /* The audio stream for the phone ring and message alerts */ 39 public static final int STREAM_RING = 2; 40 /* The audio stream for music playback */ 41 public static final int STREAM_MUSIC = 3; 42 /* The audio stream for alarms */ 43 public static final int STREAM_ALARM = 4; 44 /* The audio stream for notifications */ 45 public static final int STREAM_NOTIFICATION = 5; 46 /* @hide The audio stream for phone calls when connected on bluetooth */ 47 public static final int STREAM_BLUETOOTH_SCO = 6; 48 /* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */ 49 public static final int STREAM_SYSTEM_ENFORCED = 7; 50 /* @hide The audio stream for DTMF tones */ 51 public static final int STREAM_DTMF = 8; 52 /* @hide The audio stream for text to speech (TTS) */ 53 public static final int STREAM_TTS = 9; 54 /** 55 * @deprecated Use {@link #numStreamTypes() instead} 56 */ 57 public static final int NUM_STREAMS = 5; 58 59 // Expose only the getter method publicly so we can change it in the future 60 private static final int NUM_STREAM_TYPES = 10; 61 public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } 62 63 /* 64 * Sets the microphone mute on or off. 65 * 66 * param on set <var>true</var> to mute the microphone; 67 * <var>false</var> to turn mute off 68 * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 69 */ 70 public static native int muteMicrophone(boolean on); 71 72 /* 73 * Checks whether the microphone mute is on or off. 74 * 75 * return true if microphone is muted, false if it's not 76 */ 77 public static native boolean isMicrophoneMuted(); 78 79 /* 80 * Sets the audio mode. 81 * 82 * param mode the requested audio mode (NORMAL, RINGTONE, or IN_CALL). 83 * Informs the HAL about the current audio state so that 84 * it can route the audio appropriately. 85 * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 86 */ 87 /** @deprecated use {@link #setPhoneState(int)} */ 88 public static int setMode(int mode) { 89 return AUDIO_STATUS_ERROR; 90 } 91 /* 92 * Returns the current audio mode. 93 * 94 * return the current audio mode (NORMAL, RINGTONE, or IN_CALL). 95 * Returns the current current audio state from the HAL. 96 * 97 */ 98 /** @deprecated Do not use. */ 99 public static int getMode() { 100 return MODE_INVALID; 101 } 102 103 /* modes for setPhoneState */ 104 public static final int MODE_INVALID = -2; 105 public static final int MODE_CURRENT = -1; 106 public static final int MODE_NORMAL = 0; 107 public static final int MODE_RINGTONE = 1; 108 public static final int MODE_IN_CALL = 2; 109 public static final int MODE_IN_COMMUNICATION = 3; 110 public static final int NUM_MODES = 4; 111 112 113 /* Routing bits for setRouting/getRouting API */ 114 /** @deprecated */ 115 @Deprecated public static final int ROUTE_EARPIECE = (1 << 0); 116 /** @deprecated */ 117 @Deprecated public static final int ROUTE_SPEAKER = (1 << 1); 118 /** @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */ 119 @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2); 120 /** @deprecated */ 121 @Deprecated public static final int ROUTE_BLUETOOTH_SCO = (1 << 2); 122 /** @deprecated */ 123 @Deprecated public static final int ROUTE_HEADSET = (1 << 3); 124 /** @deprecated */ 125 @Deprecated public static final int ROUTE_BLUETOOTH_A2DP = (1 << 4); 126 /** @deprecated */ 127 @Deprecated public static final int ROUTE_ALL = 0xFFFFFFFF; 128 129 /* 130 * Sets the audio routing for a specified mode 131 * 132 * param mode audio mode to change route. E.g., MODE_RINGTONE. 133 * param routes bit vector of routes requested, created from one or 134 * more of ROUTE_xxx types. Set bits indicate that route should be on 135 * param mask bit vector of routes to change, created from one or more of 136 * ROUTE_xxx types. Unset bits indicate the route should be left unchanged 137 * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR 138 */ 139 /** @deprecated use {@link #setDeviceConnectionState(int,int,String)} */ 140 public static int setRouting(int mode, int routes, int mask) { 141 return AUDIO_STATUS_ERROR; 142 } 143 144 /* 145 * Returns the current audio routing bit vector for a specified mode. 146 * 147 * param mode audio mode to change route (e.g., MODE_RINGTONE) 148 * return an audio route bit vector that can be compared with ROUTE_xxx 149 * bits 150 */ 151 /** @deprecated use {@link #getDeviceConnectionState(int,String)} */ 152 public static int getRouting(int mode) { 153 return 0; 154 } 155 156 /* 157 * Checks whether the specified stream type is active. 158 * 159 * return true if any track playing on this stream is active. 160 */ 161 public static native boolean isStreamActive(int stream); 162 163 /* 164 * Sets a group generic audio configuration parameters. The use of these parameters 165 * are platform dependant, see libaudio 166 * 167 * param keyValuePairs list of parameters key value pairs in the form: 168 * key1=value1;key2=value2;... 169 */ 170 public static native int setParameters(String keyValuePairs); 171 172 /* 173 * Gets a group generic audio configuration parameters. The use of these parameters 174 * are platform dependant, see libaudio 175 * 176 * param keys list of parameters 177 * return value: list of parameters key value pairs in the form: 178 * key1=value1;key2=value2;... 179 */ 180 public static native String getParameters(String keys); 181 182 /* 183 private final static String TAG = "audio"; 184 185 private void log(String msg) { 186 Log.d(TAG, "[AudioSystem] " + msg); 187 } 188 */ 189 190 // These match the enum in libs/android_runtime/android_media_AudioSystem.cpp 191 /* Command sucessful or Media server restarted. see ErrorCallback */ 192 public static final int AUDIO_STATUS_OK = 0; 193 /* Command failed or unspecified audio error. see ErrorCallback */ 194 public static final int AUDIO_STATUS_ERROR = 1; 195 /* Media server died. see ErrorCallback */ 196 public static final int AUDIO_STATUS_SERVER_DIED = 100; 197 198 private static ErrorCallback mErrorCallback; 199 200 /* 201 * Handles the audio error callback. 202 */ 203 public interface ErrorCallback 204 { 205 /* 206 * Callback for audio server errors. 207 * param error error code: 208 * - AUDIO_STATUS_OK 209 * - AUDIO_STATUS_SERVER_DIED 210 * - AUDIO_STATUS_ERROR 211 */ 212 void onError(int error); 213 }; 214 215 /* 216 * Registers a callback to be invoked when an error occurs. 217 * param cb the callback to run 218 */ 219 public static void setErrorCallback(ErrorCallback cb) 220 { 221 mErrorCallback = cb; 222 } 223 224 private static void errorCallbackFromNative(int error) 225 { 226 if (mErrorCallback != null) { 227 mErrorCallback.onError(error); 228 } 229 } 230 231 /* 232 * AudioPolicyService methods 233 */ 234 235 // output devices 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_DEFAULT = 0x8000; 248 // input devices 249 public static final int DEVICE_IN_COMMUNICATION = 0x10000; 250 public static final int DEVICE_IN_AMBIENT = 0x20000; 251 public static final int DEVICE_IN_BUILTIN_MIC1 = 0x40000; 252 public static final int DEVICE_IN_BUILTIN_MIC2 = 0x80000; 253 public static final int DEVICE_IN_MIC_ARRAY = 0x100000; 254 public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x200000; 255 public static final int DEVICE_IN_WIRED_HEADSET = 0x400000; 256 public static final int DEVICE_IN_AUX_DIGITAL = 0x800000; 257 public static final int DEVICE_IN_DEFAULT = 0x80000000; 258 259 // device states 260 public static final int DEVICE_STATE_UNAVAILABLE = 0; 261 public static final int DEVICE_STATE_AVAILABLE = 1; 262 263 // phone state 264 public static final int PHONE_STATE_OFFCALL = 0; 265 public static final int PHONE_STATE_RINGING = 1; 266 public static final int PHONE_STATE_INCALL = 2; 267 268 // config for setForceUse 269 public static final int FORCE_NONE = 0; 270 public static final int FORCE_SPEAKER = 1; 271 public static final int FORCE_HEADPHONES = 2; 272 public static final int FORCE_BT_SCO = 3; 273 public static final int FORCE_BT_A2DP = 4; 274 public static final int FORCE_WIRED_ACCESSORY = 5; 275 public static final int FORCE_BT_CAR_DOCK = 6; 276 public static final int FORCE_BT_DESK_DOCK = 7; 277 public static final int FORCE_DEFAULT = FORCE_NONE; 278 279 // usage for serForceUse 280 public static final int FOR_COMMUNICATION = 0; 281 public static final int FOR_MEDIA = 1; 282 public static final int FOR_RECORD = 2; 283 public static final int FOR_DOCK = 3; 284 285 public static native int setDeviceConnectionState(int device, int state, String device_address); 286 public static native int getDeviceConnectionState(int device, String device_address); 287 public static native int setPhoneState(int state); 288 public static native int setRingerMode(int mode, int mask); 289 public static native int setForceUse(int usage, int config); 290 public static native int getForceUse(int usage); 291 public static native int initStreamVolume(int stream, int indexMin, int indexMax); 292 public static native int setStreamVolumeIndex(int stream, int index); 293 public static native int getStreamVolumeIndex(int stream); 294} 295