blob: f597440ccbb3e936c552fbfc29f8ce30d5ffe373 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
John Spurlock61560172015-02-06 19:46:04 -050019import android.content.Context;
20import android.content.pm.PackageManager;
Eric Laurent7f5eb9f2014-12-01 19:36:30 -080021import android.media.audiopolicy.AudioMix;
Jean-Michel Trivi5a561092015-04-23 18:48:08 -070022import android.util.Log;
John Spurlock61560172015-02-06 19:46:04 -050023
Eric Laurentb69681c2014-05-19 19:02:51 -070024import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
Glenn Kasten8b4b97a2011-02-04 13:54:26 -080027 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java.
28 * THANK YOU FOR YOUR COOPERATION.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029 */
30
31/**
32 * @hide
33 */
34public class AudioSystem
35{
Jean-Michel Trivi5a561092015-04-23 18:48:08 -070036 private static final String TAG = "AudioSystem";
Jean-Michel Trivia1d80e32014-06-18 08:18:41 -070037 /* These values must be kept in sync with system/audio.h */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 /*
39 * If these are modified, please also update Settings.System.VOLUME_SETTINGS
Glenn Kasten8b4b97a2011-02-04 13:54:26 -080040 * and attrs.xml and AudioManager.java.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 */
Jean-Michel Trivia1d80e32014-06-18 08:18:41 -070042 /* The default audio stream */
43 public static final int STREAM_DEFAULT = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 /* 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 Laurenta553c252009-07-17 12:17:14 -070058 /* @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 Project9066cfe2009-03-03 19:31:44 -080064 /**
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 Laurenta553c252009-07-17 12:17:14 -070070 private static final int NUM_STREAM_TYPES = 10;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; }
72
John Spurlock61560172015-02-06 19:46:04 -050073 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 Project9066cfe2009-03-03 19:31:44 -080086 /*
87 * Sets the microphone mute on or off.
88 *
Glenn Kastened0079d2011-04-04 10:50:50 -070089 * @param on set <var>true</var> to mute the microphone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 * <var>false</var> to turn mute off
Glenn Kastened0079d2011-04-04 10:50:50 -070091 * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 */
93 public static native int muteMicrophone(boolean on);
94
95 /*
96 * Checks whether the microphone mute is on or off.
97 *
Glenn Kastened0079d2011-04-04 10:50:50 -070098 * @return true if microphone is muted, false if it's not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 */
100 public static native boolean isMicrophoneMuted();
101
Glenn Kastened0079d2011-04-04 10:50:50 -0700102 /* modes for setPhoneState, must match AudioSystem.h audio_mode */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 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 Trivi8f677d62010-11-15 12:11:32 -0800108 public static final int MODE_IN_COMMUNICATION = 3;
109 public static final int NUM_MODES = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110
111
Glenn Kastened0079d2011-04-04 10:50:50 -0700112 /* Routing bits for the former setRouting/getRouting API */
Eric Laurenta553c252009-07-17 12:17:14 -0700113 /** @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 Project9066cfe2009-03-03 19:31:44 -0800117 /** @deprecated use {@link #ROUTE_BLUETOOTH_SCO} */
118 @Deprecated public static final int ROUTE_BLUETOOTH = (1 << 2);
Eric Laurenta553c252009-07-17 12:17:14 -0700119 /** @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 Project9066cfe2009-03-03 19:31:44 -0800127
Rom Lemarchandb2b29232015-04-03 15:11:28 -0700128 // Keep in sync with system/media/audio/include/system/audio.h
Glenn Kasten60bd67f2012-06-25 16:11:37 -0700129 public static final int AUDIO_SESSION_ALLOCATE = 0;
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 /*
Eric Laurent23f25cd2010-01-25 08:49:09 -0800132 * Checks whether the specified stream type is active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 *
Eric Laurent23f25cd2010-01-25 08:49:09 -0800134 * return true if any track playing on this stream is active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 */
Eric Laurent25101b02011-02-02 09:33:30 -0800136 public static native boolean isStreamActive(int stream, int inPastMs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
138 /*
Jean-Michel Trivi679d5042013-02-04 16:24:09 -0800139 * 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 Trivid6770542012-10-10 12:03:41 -0700147 * 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 Trivi8a21f5d2014-06-05 15:03:52 -0700154 * Returns a new unused audio session ID
155 */
156 public static native int newAudioSessionId();
157
158 /*
Eric Laurenta553c252009-07-17 12:17:14 -0700159 * Sets a group generic audio configuration parameters. The use of these parameters
Glenn Kastened0079d2011-04-04 10:50:50 -0700160 * are platform dependent, see libaudio
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 *
Eric Laurenta553c252009-07-17 12:17:14 -0700162 * param keyValuePairs list of parameters key value pairs in the form:
163 * key1=value1;key2=value2;...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 */
Eric Laurenta553c252009-07-17 12:17:14 -0700165 public static native int setParameters(String keyValuePairs);
166
167 /*
168 * Gets a group generic audio configuration parameters. The use of these parameters
Glenn Kastened0079d2011-04-04 10:50:50 -0700169 * are platform dependent, see libaudio
Eric Laurenta553c252009-07-17 12:17:14 -0700170 *
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 Project9066cfe2009-03-03 19:31:44 -0800176
Glenn Kastened0079d2011-04-04 10:50:50 -0700177 // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /* 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 Laurentef028272009-04-21 07:56:33 -0700197 * - AUDIO_STATUS_ERROR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 */
199 void onError(int error);
200 };
201
202 /*
203 * Registers a callback to be invoked when an error occurs.
Glenn Kastened0079d2011-04-04 10:50:50 -0700204 * @param cb the callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 */
206 public static void setErrorCallback(ErrorCallback cb)
207 {
Eric Laurenta25c5d82011-02-10 11:04:34 -0800208 synchronized (AudioSystem.class) {
209 mErrorCallback = cb;
Eric Laurentdfb881f2013-07-18 14:41:39 -0700210 if (cb != null) {
211 cb.onError(checkAudioFlinger());
212 }
Eric Laurenta25c5d82011-02-10 11:04:34 -0800213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
215
216 private static void errorCallbackFromNative(int error)
217 {
Eric Laurenta25c5d82011-02-10 11:04:34 -0800218 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 Project9066cfe2009-03-03 19:31:44 -0800226 }
227 }
Eric Laurenta553c252009-07-17 12:17:14 -0700228
Jean-Michel Trivi5a561092015-04-23 18:48:08 -0700229 /**
Jean-Michel Trivid3c71f02015-12-07 11:59:31 -0800230 * Handles events from the audio policy manager about dynamic audio policies
Jean-Michel Trivi5a561092015-04-23 18:48:08 -0700231 * @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 Trivid3c71f02015-12-07 11:59:31 -0800270 /**
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 Trivi33fd8162016-02-22 10:52:41 -0800276 /**
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 Trivi8ab72802016-02-25 16:31:45 -0800282 * 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 Trivi33fd8162016-02-22 10:52:41 -0800290 */
291 void onRecordingConfigurationChanged(int event, int session, int source,
292 int[] recordingFormat);
Jean-Michel Trivid3c71f02015-12-07 11:59:31 -0800293 }
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 Trivi33fd8162016-02-22 10:52:41 -0800304 /**
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 Trivid3c71f02015-12-07 11:59:31 -0800315 AudioRecordingCallback cb = null;
316 synchronized (AudioSystem.class) {
317 cb = sRecordingCallback;
318 }
319 if (cb != null) {
Jean-Michel Trivi33fd8162016-02-22 10:52:41 -0800320 cb.onRecordingConfigurationChanged(event, session, source, recordingFormat);
Jean-Michel Trivid3c71f02015-12-07 11:59:31 -0800321 }
322 }
Jean-Michel Trivi5a561092015-04-23 18:48:08 -0700323
Eric Laurentbc11a692014-05-16 12:19:25 -0700324 /*
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 Laurent4e1ccd32015-07-02 12:09:44 -0700335 public static final int WOULD_BLOCK = -7;
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800336
Eric Laurenta553c252009-07-17 12:17:14 -0700337 /*
338 * AudioPolicyService methods
339 */
340
Eric Laurent53082ec2012-08-28 14:27:29 -0700341 //
342 // audio device definitions: must be kept in sync with values in system/core/audio.h
343 //
344
Wonsik Kimd7c29182014-05-27 10:38:21 +0900345 public static final int DEVICE_NONE = 0x0;
Eric Laurent53082ec2012-08-28 14:27:29 -0700346 // reserved bits
347 public static final int DEVICE_BIT_IN = 0x80000000;
348 public static final int DEVICE_BIT_DEFAULT = 0x40000000;
Glenn Kasten8b4b97a2011-02-04 13:54:26 -0800349 // output devices, be sure to update AudioManager.java also
Eric Laurenta553c252009-07-17 12:17:14 -0700350 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 Laurent948d3272014-05-16 15:18:45 -0700361 public static final int DEVICE_OUT_HDMI = DEVICE_OUT_AUX_DIGITAL;
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500362 public static final int DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800;
363 public static final int DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000;
Eric Laurent59f48272012-04-05 19:42:21 -0700364 public static final int DEVICE_OUT_USB_ACCESSORY = 0x2000;
365 public static final int DEVICE_OUT_USB_DEVICE = 0x4000;
Eric Laurent53082ec2012-08-28 14:27:29 -0700366 public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000;
Eric Laurent948d3272014-05-16 15:18:45 -0700367 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 Jang12307ca2014-07-15 19:27:56 +0900372 public static final int DEVICE_OUT_AUX_LINE = 0x200000;
Mike Lockwood07cd1242014-10-27 13:34:45 -0700373 public static final int DEVICE_OUT_SPEAKER_SAFE = 0x400000;
Eric Laurent1e725f82015-07-01 16:38:22 -0700374 public static final int DEVICE_OUT_IP = 0x800000;
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800375 public static final int DEVICE_OUT_BUS = 0x1000000;
Eric Laurent59f48272012-04-05 19:42:21 -0700376
Eric Laurent53082ec2012-08-28 14:27:29 -0700377 public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT;
Jean-Michel Trivi2ac2afe2012-08-21 11:16:55 -0700378
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800379 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 Laurent948d3272014-05-16 15:18:45 -0700389 DEVICE_OUT_HDMI |
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800390 DEVICE_OUT_ANLG_DOCK_HEADSET |
391 DEVICE_OUT_DGTL_DOCK_HEADSET |
Eric Laurent59f48272012-04-05 19:42:21 -0700392 DEVICE_OUT_USB_ACCESSORY |
393 DEVICE_OUT_USB_DEVICE |
Eric Laurent53082ec2012-08-28 14:27:29 -0700394 DEVICE_OUT_REMOTE_SUBMIX |
Eric Laurent948d3272014-05-16 15:18:45 -0700395 DEVICE_OUT_TELEPHONY_TX |
396 DEVICE_OUT_LINE |
397 DEVICE_OUT_HDMI_ARC |
398 DEVICE_OUT_SPDIF |
399 DEVICE_OUT_FM |
Jungshik Jang12307ca2014-07-15 19:27:56 +0900400 DEVICE_OUT_AUX_LINE |
Mike Lockwood07cd1242014-10-27 13:34:45 -0700401 DEVICE_OUT_SPEAKER_SAFE |
Eric Laurent1e725f82015-07-01 16:38:22 -0700402 DEVICE_OUT_IP |
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800403 DEVICE_OUT_BUS |
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800404 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 Laurent59f48272012-04-05 19:42:21 -0700408 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 Jang12307ca2014-07-15 19:27:56 +0900413 public static final int DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO = (DEVICE_OUT_AUX_LINE |
Jungshik Jang41d97462014-06-30 22:26:29 +0900414 DEVICE_OUT_HDMI_ARC |
415 DEVICE_OUT_SPDIF);
Jungshik Jang6f34f5a2014-07-08 21:17:29 +0900416 public static final int DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER =
417 (DEVICE_OUT_ALL_HDMI_SYSTEM_AUDIO |
418 DEVICE_OUT_SPEAKER);
Eric Laurent59f48272012-04-05 19:42:21 -0700419
Eric Laurenta553c252009-07-17 12:17:14 -0700420 // input devices
Eric Laurent53082ec2012-08-28 14:27:29 -0700421 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 Laurent948d3272014-05-16 15:18:45 -0700427 public static final int DEVICE_IN_HDMI = DEVICE_IN_AUX_DIGITAL;
Eric Laurent53082ec2012-08-28 14:27:29 -0700428 public static final int DEVICE_IN_VOICE_CALL = DEVICE_BIT_IN | 0x40;
Eric Laurent948d3272014-05-16 15:18:45 -0700429 public static final int DEVICE_IN_TELEPHONY_RX = DEVICE_IN_VOICE_CALL;
Eric Laurent53082ec2012-08-28 14:27:29 -0700430 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 Laurent948d3272014-05-16 15:18:45 -0700436 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 Lockwood0a40ec22014-05-21 10:08:50 -0700440 public static final int DEVICE_IN_BLUETOOTH_A2DP = DEVICE_BIT_IN | 0x20000;
Terry Heo112c19e2014-07-07 10:25:38 +0900441 public static final int DEVICE_IN_LOOPBACK = DEVICE_BIT_IN | 0x40000;
Eric Laurent1e725f82015-07-01 16:38:22 -0700442 public static final int DEVICE_IN_IP = DEVICE_BIT_IN | 0x80000;
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800443 public static final int DEVICE_IN_BUS = DEVICE_BIT_IN | 0x100000;
Eric Laurent53082ec2012-08-28 14:27:29 -0700444 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 Laurent948d3272014-05-16 15:18:45 -0700451 DEVICE_IN_HDMI |
452 DEVICE_IN_TELEPHONY_RX |
Eric Laurent53082ec2012-08-28 14:27:29 -0700453 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 Laurent948d3272014-05-16 15:18:45 -0700459 DEVICE_IN_FM_TUNER |
460 DEVICE_IN_TV_TUNER |
461 DEVICE_IN_LINE |
462 DEVICE_IN_SPDIF |
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700463 DEVICE_IN_BLUETOOTH_A2DP |
Terry Heo112c19e2014-07-07 10:25:38 +0900464 DEVICE_IN_LOOPBACK |
Eric Laurent1e725f82015-07-01 16:38:22 -0700465 DEVICE_IN_IP |
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800466 DEVICE_IN_BUS |
Eric Laurent53082ec2012-08-28 14:27:29 -0700467 DEVICE_IN_DEFAULT);
468 public static final int DEVICE_IN_ALL_SCO = DEVICE_IN_BLUETOOTH_SCO_HEADSET;
Paul McLeanc837a452014-04-09 09:04:43 -0700469 public static final int DEVICE_IN_ALL_USB = (DEVICE_IN_USB_ACCESSORY |
470 DEVICE_IN_USB_DEVICE);
Eric Laurenta553c252009-07-17 12:17:14 -0700471
Glenn Kastened0079d2011-04-04 10:50:50 -0700472 // device states, must match AudioSystem::device_connection_state
Eric Laurenta553c252009-07-17 12:17:14 -0700473 public static final int DEVICE_STATE_UNAVAILABLE = 0;
474 public static final int DEVICE_STATE_AVAILABLE = 1;
Glenn Kastened0079d2011-04-04 10:50:50 -0700475 private static final int NUM_DEVICE_STATES = 1;
Eric Laurenta553c252009-07-17 12:17:14 -0700476
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800477 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 Laurent948d3272014-05-16 15:18:45 -0700488 public static final String DEVICE_OUT_HDMI_NAME = "hdmi";
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800489 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 Laurentbffc3d12012-05-07 17:43:49 -0700491 public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory";
492 public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device";
Eric Laurent53082ec2012-08-28 14:27:29 -0700493 public static final String DEVICE_OUT_REMOTE_SUBMIX_NAME = "remote_submix";
Eric Laurent948d3272014-05-16 15:18:45 -0700494 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 Spurlock2b29bc42014-08-26 16:40:35 -0400499 public static final String DEVICE_OUT_AUX_LINE_NAME = "aux_line";
Mike Lockwood07cd1242014-10-27 13:34:45 -0700500 public static final String DEVICE_OUT_SPEAKER_SAFE_NAME = "speaker_safe";
Eric Laurent1e725f82015-07-01 16:38:22 -0700501 public static final String DEVICE_OUT_IP_NAME = "ip";
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800502 public static final String DEVICE_OUT_BUS_NAME = "bus";
Mike Lockwood07cd1242014-10-27 13:34:45 -0700503
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 Laurent1e725f82015-07-01 16:38:22 -0700523 public static final String DEVICE_IN_IP_NAME = "ip";
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800524 public static final String DEVICE_IN_BUS_NAME = "bus";
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800525
Eric Laurent948d3272014-05-16 15:18:45 -0700526 public static String getOutputDeviceName(int device)
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800527 {
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 Laurent948d3272014-05-16 15:18:45 -0700549 case DEVICE_OUT_HDMI:
550 return DEVICE_OUT_HDMI_NAME;
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800551 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 Laurentbffc3d12012-05-07 17:43:49 -0700555 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 Laurent53082ec2012-08-28 14:27:29 -0700559 case DEVICE_OUT_REMOTE_SUBMIX:
560 return DEVICE_OUT_REMOTE_SUBMIX_NAME;
Eric Laurent948d3272014-05-16 15:18:45 -0700561 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 Spurlock2b29bc42014-08-26 16:40:35 -0400571 case DEVICE_OUT_AUX_LINE:
572 return DEVICE_OUT_AUX_LINE_NAME;
Mike Lockwood07cd1242014-10-27 13:34:45 -0700573 case DEVICE_OUT_SPEAKER_SAFE:
574 return DEVICE_OUT_SPEAKER_SAFE_NAME;
Eric Laurent1e725f82015-07-01 16:38:22 -0700575 case DEVICE_OUT_IP:
576 return DEVICE_OUT_IP_NAME;
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800577 case DEVICE_OUT_BUS:
578 return DEVICE_OUT_BUS_NAME;
Eric Laurent53082ec2012-08-28 14:27:29 -0700579 case DEVICE_OUT_DEFAULT:
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800580 default:
Mike Lockwood07cd1242014-10-27 13:34:45 -0700581 return Integer.toString(device);
Eric Laurent9bc8358d2011-11-18 16:43:31 -0800582 }
583 }
584
Mike Lockwood07cd1242014-10-27 13:34:45 -0700585 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 Laurent1e725f82015-07-01 16:38:22 -0700626 case DEVICE_IN_IP:
627 return DEVICE_IN_IP_NAME;
Jean-Michel Trivi93687f22016-02-18 10:16:07 -0800628 case DEVICE_IN_BUS:
629 return DEVICE_IN_BUS_NAME;
Mike Lockwood07cd1242014-10-27 13:34:45 -0700630 case DEVICE_IN_DEFAULT:
631 default:
632 return Integer.toString(device);
633 }
634 }
Eric Laurent948d3272014-05-16 15:18:45 -0700635
Glenn Kastened0079d2011-04-04 10:50:50 -0700636 // phone state, match audio_mode???
Eric Laurenta553c252009-07-17 12:17:14 -0700637 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 Burkac0f7042016-02-24 12:19:08 -0800641 // device categories config for setForceUse, must match audio_policy_forced_cfg_t
Eric Laurenta553c252009-07-17 12:17:14 -0700642 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 Laurenteb14a782009-12-17 03:12:59 -0800648 public static final int FORCE_BT_CAR_DOCK = 6;
649 public static final int FORCE_BT_DESK_DOCK = 7;
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500650 public static final int FORCE_ANALOG_DOCK = 8;
651 public static final int FORCE_DIGITAL_DOCK = 9;
Eric Laurent78472112012-05-21 08:57:21 -0700652 public static final int FORCE_NO_BT_A2DP = 10;
Jean-Michel Trivic203ecf2012-10-11 10:13:50 -0700653 public static final int FORCE_SYSTEM_ENFORCED = 11;
Jungshik Jang12307ca2014-07-15 19:27:56 +0900654 public static final int FORCE_HDMI_SYSTEM_AUDIO_ENFORCED = 12;
Phil Burkac0f7042016-02-24 12:19:08 -0800655 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 Laurenta553c252009-07-17 12:17:14 -0700658 public static final int FORCE_DEFAULT = FORCE_NONE;
659
Phil Burkac0f7042016-02-24 12:19:08 -0800660 // usage for setForceUse, must match audio_policy_force_use_t
Eric Laurenta553c252009-07-17 12:17:14 -0700661 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 Trivi61544122009-12-07 18:40:56 -0800664 public static final int FOR_DOCK = 3;
Eric Laurentdd45d012012-10-08 09:04:34 -0700665 public static final int FOR_SYSTEM = 4;
Jungshik Jang12307ca2014-07-15 19:27:56 +0900666 public static final int FOR_HDMI_SYSTEM_AUDIO = 5;
Phil Burkac0f7042016-02-24 12:19:08 -0800667 public static final int FOR_ENCODED_SURROUND = 6;
668 private static final int NUM_FORCE_USE = 7;
Eric Laurenta553c252009-07-17 12:17:14 -0700669
Eric Laurent505e5c82012-03-29 15:19:36 -0700670 // 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 Trivi6d00e412015-08-03 17:26:01 -0700674 /**
675 * @return command completion status, one of {@link #AUDIO_STATUS_OK},
676 * {@link #AUDIO_STATUS_ERROR} or {@link #AUDIO_STATUS_SERVER_DIED}
677 */
Paul McLean10804eb2015-01-28 11:16:35 -0800678 public static native int setDeviceConnectionState(int device, int state,
679 String device_address, String device_name);
Eric Laurenta553c252009-07-17 12:17:14 -0700680 public static native int getDeviceConnectionState(int device, String device_address);
681 public static native int setPhoneState(int state);
Eric Laurenta553c252009-07-17 12:17:14 -0700682 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 Laurent9bc8358d2011-11-18 16:43:31 -0800685 public static native int setStreamVolumeIndex(int stream, int index, int device);
686 public static native int getStreamVolumeIndex(int stream, int device);
Mike Lockwoodcbdb49d2011-10-20 12:54:05 -0400687 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 Kasten8b4b97a2011-02-04 13:54:26 -0800691 public static native int getDevicesForStream(int stream);
Glenn Kastenc6c43652012-09-24 17:32:30 -0700692
Andy Hungf04b84d2015-12-18 17:33:27 -0800693 /** @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 Kastenc6c43652012-09-24 17:32:30 -0700698 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
699 public static native int getPrimaryOutputSamplingRate();
700 public static native int getPrimaryOutputFrameCount();
Oliver Woodman61dcdf32013-06-26 12:43:36 +0100701 public static native int getOutputLatency(int stream);
Glenn Kastenc6c43652012-09-24 17:32:30 -0700702
Glenn Kastenfd116ad2013-07-12 17:10:39 -0700703 public static native int setLowRamDevice(boolean isLowRamDevice);
Eric Laurentdfb881f2013-07-18 14:41:39 -0700704 public static native int checkAudioFlinger();
Eric Laurentb69681c2014-05-19 19:02:51 -0700705
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 Laurent3a241992014-05-19 19:33:26 -0700711 public static native int setAudioPortConfig(AudioPortConfig config);
Eric Laurentb634e1b2014-08-01 14:44:46 -0700712
Jean-Michel Trivi5a561092015-04-23 18:48:08 -0700713 // declare this instance as having a dynamic policy callback handler
714 private static native final void native_register_dynamic_policy_callback();
Jean-Michel Trivid3c71f02015-12-07 11:59:31 -0800715 // declare this instance as having a recording configuration update callback handler
716 private static native final void native_register_recording_callback();
Jean-Michel Trivi5a561092015-04-23 18:48:08 -0700717
Eric Laurentb634e1b2014-08-01 14:44:46 -0700718 // 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 Laurent7f5eb9f2014-12-01 19:36:30 -0800722
723 public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register);
John Spurlock61560172015-02-06 19:46:04 -0500724
Eric Laurent0867bed2015-05-20 14:49:08 -0700725 public static native int systemReady();
John Spurlock61560172015-02-06 19:46:04 -0500726
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 Laurent4bcdba82015-05-01 11:37:49 -0700813
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 Project9066cfe2009-03-03 19:31:44 -0800819}
Eric Laurentb69681c2014-05-19 19:02:51 -0700820