• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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  */
27 public 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;
getNumStreamTypes()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      */
muteMicrophone(boolean on)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      */
isMicrophoneMuted()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)} */
setMode(int mode)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. */
getMode()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 NUM_MODES               = 3;
110 
111 
112     /* Routing bits for setRouting/getRouting API */
113     /** @deprecated */
114     @Deprecated public static final int ROUTE_EARPIECE          = (1 << 0);
115     /** @deprecated */
116     @Deprecated public static final int ROUTE_SPEAKER           = (1 << 1);
117     /** @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */
118     @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2);
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;
127 
128     /*
129      * Sets the audio routing for a specified mode
130      *
131      * param mode   audio mode to change route. E.g., MODE_RINGTONE.
132      * param routes bit vector of routes requested, created from one or
133      *               more of ROUTE_xxx types. Set bits indicate that route should be on
134      * param mask   bit vector of routes to change, created from one or more of
135      * ROUTE_xxx types. Unset bits indicate the route should be left unchanged
136      * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
137      */
138     /** @deprecated use {@link #setDeviceConnectionState(int,int,String)} */
setRouting(int mode, int routes, int mask)139     public static int setRouting(int mode, int routes, int mask) {
140         return AUDIO_STATUS_ERROR;
141     }
142 
143     /*
144      * Returns the current audio routing bit vector for a specified mode.
145      *
146      * param mode audio mode to change route (e.g., MODE_RINGTONE)
147      * return an audio route bit vector that can be compared with ROUTE_xxx
148      * bits
149      */
150     /** @deprecated use {@link #getDeviceConnectionState(int,String)} */
getRouting(int mode)151     public static int getRouting(int mode) {
152         return 0;
153     }
154 
155     /*
156      * Checks whether any music is active.
157      *
158      * return true if any music tracks are active.
159      */
isMusicActive()160     public static native boolean isMusicActive();
161 
162     /*
163      * Sets a group generic audio configuration parameters. The use of these parameters
164      * are platform dependant, see libaudio
165      *
166      * param keyValuePairs  list of parameters key value pairs in the form:
167      *    key1=value1;key2=value2;...
168      */
setParameters(String keyValuePairs)169     public static native int setParameters(String keyValuePairs);
170 
171     /*
172      * Gets a group generic audio configuration parameters. The use of these parameters
173      * are platform dependant, see libaudio
174      *
175      * param keys  list of parameters
176      * return value: list of parameters key value pairs in the form:
177      *    key1=value1;key2=value2;...
178      */
getParameters(String keys)179     public static native String getParameters(String keys);
180 
181     /*
182     private final static String TAG = "audio";
183 
184     private void log(String msg) {
185         Log.d(TAG, "[AudioSystem] " + msg);
186     }
187     */
188 
189     // These match the enum in libs/android_runtime/android_media_AudioSystem.cpp
190     /* Command sucessful or Media server restarted. see ErrorCallback */
191     public static final int AUDIO_STATUS_OK = 0;
192     /* Command failed or unspecified audio error.  see ErrorCallback */
193     public static final int AUDIO_STATUS_ERROR = 1;
194     /* Media server died. see ErrorCallback */
195     public static final int AUDIO_STATUS_SERVER_DIED = 100;
196 
197     private static ErrorCallback mErrorCallback;
198 
199     /*
200      * Handles the audio error callback.
201      */
202     public interface ErrorCallback
203     {
204         /*
205          * Callback for audio server errors.
206          * param error   error code:
207          * - AUDIO_STATUS_OK
208          * - AUDIO_STATUS_SERVER_DIED
209          * - AUDIO_STATUS_ERROR
210          */
onError(int error)211         void onError(int error);
212     };
213 
214     /*
215      * Registers a callback to be invoked when an error occurs.
216      * param cb the callback to run
217      */
setErrorCallback(ErrorCallback cb)218     public static void setErrorCallback(ErrorCallback cb)
219     {
220         mErrorCallback = cb;
221     }
222 
errorCallbackFromNative(int error)223     private static void errorCallbackFromNative(int error)
224     {
225         if (mErrorCallback != null) {
226             mErrorCallback.onError(error);
227         }
228     }
229 
230     /*
231      * AudioPolicyService methods
232      */
233 
234     // output devices
235     public static final int DEVICE_OUT_EARPIECE = 0x1;
236     public static final int DEVICE_OUT_SPEAKER = 0x2;
237     public static final int DEVICE_OUT_WIRED_HEADSET = 0x4;
238     public static final int DEVICE_OUT_WIRED_HEADPHONE = 0x8;
239     public static final int DEVICE_OUT_BLUETOOTH_SCO = 0x10;
240     public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20;
241     public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40;
242     public static final int DEVICE_OUT_BLUETOOTH_A2DP = 0x80;
243     public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100;
244     public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200;
245     public static final int DEVICE_OUT_AUX_DIGITAL = 0x400;
246     public static final int DEVICE_OUT_DEFAULT = 0x8000;
247     // input devices
248     public static final int DEVICE_IN_COMMUNICATION = 0x10000;
249     public static final int DEVICE_IN_AMBIENT = 0x20000;
250     public static final int DEVICE_IN_BUILTIN_MIC1 = 0x40000;
251     public static final int DEVICE_IN_BUILTIN_MIC2 = 0x80000;
252     public static final int DEVICE_IN_MIC_ARRAY = 0x100000;
253     public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x200000;
254     public static final int DEVICE_IN_WIRED_HEADSET = 0x400000;
255     public static final int DEVICE_IN_AUX_DIGITAL = 0x800000;
256     public static final int DEVICE_IN_DEFAULT = 0x80000000;
257 
258     // device states
259     public static final int DEVICE_STATE_UNAVAILABLE = 0;
260     public static final int DEVICE_STATE_AVAILABLE = 1;
261 
262     // phone state
263     public static final int PHONE_STATE_OFFCALL = 0;
264     public static final int PHONE_STATE_RINGING = 1;
265     public static final int PHONE_STATE_INCALL = 2;
266 
267     // config for setForceUse
268     public static final int FORCE_NONE = 0;
269     public static final int FORCE_SPEAKER = 1;
270     public static final int FORCE_HEADPHONES = 2;
271     public static final int FORCE_BT_SCO = 3;
272     public static final int FORCE_BT_A2DP = 4;
273     public static final int FORCE_WIRED_ACCESSORY = 5;
274     public static final int FORCE_DEFAULT = FORCE_NONE;
275 
276     // usage for serForceUse
277     public static final int FOR_COMMUNICATION = 0;
278     public static final int FOR_MEDIA = 1;
279     public static final int FOR_RECORD = 2;
280 
setDeviceConnectionState(int device, int state, String device_address)281     public static native int setDeviceConnectionState(int device, int state, String device_address);
getDeviceConnectionState(int device, String device_address)282     public static native int getDeviceConnectionState(int device, String device_address);
setPhoneState(int state)283     public static native int setPhoneState(int state);
setRingerMode(int mode, int mask)284     public static native int setRingerMode(int mode, int mask);
setForceUse(int usage, int config)285     public static native int setForceUse(int usage, int config);
getForceUse(int usage)286     public static native int getForceUse(int usage);
initStreamVolume(int stream, int indexMin, int indexMax)287     public static native int initStreamVolume(int stream, int indexMin, int indexMax);
setStreamVolumeIndex(int stream, int index)288     public static native int setStreamVolumeIndex(int stream, int index);
getStreamVolumeIndex(int stream)289     public static native int getStreamVolumeIndex(int stream);
290 }
291