am 7238cdc3: am 1c82b221: Merge "Changes as per API council review." into mnc-dev

* commit '7238cdc314678eb9c9165a12b52bc3594f268720':
  Changes as per API council review.
This commit is contained in:
Paul McLean
2015-05-11 16:02:04 +00:00
committed by Android Git Automerger
12 changed files with 321 additions and 448 deletions

View File

@@ -7763,7 +7763,6 @@ package android.content {
field public static final java.lang.String ALARM_SERVICE = "alarm";
field public static final java.lang.String APPWIDGET_SERVICE = "appwidget";
field public static final java.lang.String APP_OPS_SERVICE = "appops";
field public static final java.lang.String AUDIO_DEVICES_SERVICE = "audio_devices_manager";
field public static final java.lang.String AUDIO_SERVICE = "audio";
field public static final java.lang.String BATTERY_SERVICE = "batterymanager";
field public static final int BIND_ABOVE_CLIENT = 8; // 0x8
@@ -14728,12 +14727,12 @@ package android.media {
method public android.media.AudioAttributes.Builder setUsage(int);
}
public class AudioDeviceInfo {
method public java.lang.String getAddress();
public final class AudioDeviceInfo {
method public int[] getChannelCounts();
method public int[] getChannelMasks();
method public int[] getFormats();
method public java.lang.String getName();
method public int getId();
method public java.lang.CharSequence getName();
method public int[] getSampleRates();
method public int getType();
method public boolean isSink();
@@ -14760,15 +14759,6 @@ package android.media {
field public static final int TYPE_WIRED_HEADSET = 3; // 0x3
}
public class AudioDevicesManager {
method public void addOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener, android.os.Handler);
method public android.media.AudioDeviceInfo[] listDevices(int);
method public void removeOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener);
field public static final int LIST_DEVICES_ALL = 3; // 0x3
field public static final int LIST_DEVICES_INPUTS = 1; // 0x1
field public static final int LIST_DEVICES_OUTPUTS = 2; // 0x2
}
public class AudioFormat {
method public int getChannelCount();
method public int getChannelIndexMask();
@@ -14839,11 +14829,13 @@ package android.media {
public class AudioManager {
method public int abandonAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener);
method public void addOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener, android.os.Handler);
method public void adjustStreamVolume(int, int, int);
method public void adjustSuggestedStreamVolume(int, int, int);
method public void adjustVolume(int, int);
method public void dispatchMediaKeyEvent(android.view.KeyEvent);
method public int generateAudioSessionId();
method public android.media.AudioDeviceInfo[] getDevices(int);
method public int getMode();
method public java.lang.String getParameters(java.lang.String);
method public java.lang.String getProperty(java.lang.String);
@@ -14868,6 +14860,7 @@ package android.media {
method public deprecated void registerMediaButtonEventReceiver(android.app.PendingIntent);
method public deprecated void registerRemoteControlClient(android.media.RemoteControlClient);
method public deprecated boolean registerRemoteController(android.media.RemoteController);
method public void removeOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener);
method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int);
method public deprecated void setBluetoothA2dpOn(boolean);
method public void setBluetoothScoOn(boolean);
@@ -14936,6 +14929,9 @@ package android.media {
field public static final int FX_KEYPRESS_SPACEBAR = 6; // 0x6
field public static final int FX_KEYPRESS_STANDARD = 5; // 0x5
field public static final int FX_KEY_CLICK = 0; // 0x0
field public static final int GET_DEVICES_ALL = 3; // 0x3
field public static final int GET_DEVICES_INPUTS = 1; // 0x1
field public static final int GET_DEVICES_OUTPUTS = 2; // 0x2
field public static final int MODE_CURRENT = -1; // 0xffffffff
field public static final int MODE_INVALID = -2; // 0xfffffffe
field public static final int MODE_IN_CALL = 2; // 0x2
@@ -14984,7 +14980,7 @@ package android.media {
public class AudioRecord {
ctor public AudioRecord(int, int, int, int, int) throws java.lang.IllegalArgumentException;
method public void addOnAudioRecordRoutingListener(android.media.OnAudioRecordRoutingListener, android.os.Handler);
method public void addOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener, android.os.Handler);
method public int getAudioFormat();
method public int getAudioSessionId();
method public int getAudioSource();
@@ -14995,7 +14991,7 @@ package android.media {
method public int getNativeFrameCount() throws java.lang.IllegalStateException;
method public int getNotificationMarkerPosition();
method public int getPositionNotificationPeriod();
method public android.media.AudioDeviceInfo getPreferredInputDevice();
method public android.media.AudioDeviceInfo getPreferredDevice();
method public int getRecordingState();
method public android.media.AudioDeviceInfo getRoutedDevice();
method public int getSampleRate();
@@ -15008,10 +15004,10 @@ package android.media {
method public int read(java.nio.ByteBuffer, int);
method public int read(java.nio.ByteBuffer, int, int);
method public void release();
method public void removeOnAudioRecordRoutingListener(android.media.OnAudioRecordRoutingListener);
method public void removeOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener);
method public int setNotificationMarkerPosition(int);
method public int setPositionNotificationPeriod(int);
method public boolean setPreferredInputDevice(android.media.AudioDeviceInfo);
method public boolean setPreferredDevice(android.media.AudioDeviceInfo);
method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener);
method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener, android.os.Handler);
method public void startRecording() throws java.lang.IllegalStateException;
@@ -15042,6 +15038,10 @@ package android.media {
method public abstract void onPeriodicNotification(android.media.AudioRecord);
}
public static abstract interface AudioRecord.OnRoutingChangedListener {
method public abstract void onRoutingChanged(android.media.AudioRecord);
}
public final class AudioTimestamp {
ctor public AudioTimestamp();
field public long framePosition;
@@ -15052,7 +15052,7 @@ package android.media {
ctor public AudioTrack(int, int, int, int, int, int) throws java.lang.IllegalArgumentException;
ctor public AudioTrack(int, int, int, int, int, int, int) throws java.lang.IllegalArgumentException;
ctor public AudioTrack(android.media.AudioAttributes, android.media.AudioFormat, int, int, int) throws java.lang.IllegalArgumentException;
method public void addOnAudioTrackRoutingListener(android.media.OnAudioTrackRoutingListener, android.os.Handler);
method public void addOnRoutingChangedListener(android.media.AudioTrack.OnRoutingChangedListener, android.os.Handler);
method public int attachAuxEffect(int);
method public void flush();
method public int getAudioFormat();
@@ -15071,7 +15071,7 @@ package android.media {
method public android.media.PlaybackParams getPlaybackParams();
method public int getPlaybackRate();
method public int getPositionNotificationPeriod();
method public android.media.AudioDeviceInfo getPreferredOutputDevice();
method public android.media.AudioDeviceInfo getPreferredDevice();
method public android.media.AudioDeviceInfo getRoutedDevice();
method public int getSampleRate();
method public int getState();
@@ -15081,7 +15081,7 @@ package android.media {
method public void play() throws java.lang.IllegalStateException;
method public void release();
method public int reloadStaticData();
method public void removeOnAudioTrackRoutingListener(android.media.OnAudioTrackRoutingListener);
method public void removeOnRoutingChangedListener(android.media.AudioTrack.OnRoutingChangedListener);
method public int setAuxEffectSendLevel(float);
method public int setLoopPoints(int, int, int);
method public int setNotificationMarkerPosition(int);
@@ -15091,7 +15091,7 @@ package android.media {
method public void setPlaybackPositionUpdateListener(android.media.AudioTrack.OnPlaybackPositionUpdateListener, android.os.Handler);
method public int setPlaybackRate(int);
method public int setPositionNotificationPeriod(int);
method public boolean setPreferredOutputDevice(android.media.AudioDeviceInfo);
method public boolean setPreferredDevice(android.media.AudioDeviceInfo);
method protected deprecated void setState(int);
method public deprecated int setStereoVolume(float, float);
method public int setVolume(float);
@@ -15134,6 +15134,10 @@ package android.media {
method public abstract void onPeriodicNotification(android.media.AudioTrack);
}
public static abstract interface AudioTrack.OnRoutingChangedListener {
method public abstract void onRoutingChanged(android.media.AudioTrack);
}
public class CamcorderProfile {
method public static android.media.CamcorderProfile get(int);
method public static android.media.CamcorderProfile get(int, int);
@@ -16501,14 +16505,6 @@ package android.media {
method public abstract void onAudioDeviceConnection();
}
public abstract interface OnAudioRecordRoutingListener {
method public abstract void onAudioRecordRouting(android.media.AudioRecord);
}
public abstract interface OnAudioTrackRoutingListener {
method public abstract void onAudioTrackRouting(android.media.AudioTrack);
}
public final class PlaybackParams {
ctor public PlaybackParams();
method public android.media.PlaybackParams allowDefaults();

View File

@@ -7978,7 +7978,6 @@ package android.content {
field public static final java.lang.String ALARM_SERVICE = "alarm";
field public static final java.lang.String APPWIDGET_SERVICE = "appwidget";
field public static final java.lang.String APP_OPS_SERVICE = "appops";
field public static final java.lang.String AUDIO_DEVICES_SERVICE = "audio_devices_manager";
field public static final java.lang.String AUDIO_SERVICE = "audio";
field public static final java.lang.String BACKUP_SERVICE = "backup";
field public static final java.lang.String BATTERY_SERVICE = "batterymanager";
@@ -15926,12 +15925,12 @@ package android.media {
method public android.media.AudioAttributes.Builder setUsage(int);
}
public class AudioDeviceInfo {
method public java.lang.String getAddress();
public final class AudioDeviceInfo {
method public int[] getChannelCounts();
method public int[] getChannelMasks();
method public int[] getFormats();
method public java.lang.String getName();
method public int getId();
method public java.lang.CharSequence getName();
method public int[] getSampleRates();
method public int getType();
method public boolean isSink();
@@ -15958,15 +15957,6 @@ package android.media {
field public static final int TYPE_WIRED_HEADSET = 3; // 0x3
}
public class AudioDevicesManager {
method public void addOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener, android.os.Handler);
method public android.media.AudioDeviceInfo[] listDevices(int);
method public void removeOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener);
field public static final int LIST_DEVICES_ALL = 3; // 0x3
field public static final int LIST_DEVICES_INPUTS = 1; // 0x1
field public static final int LIST_DEVICES_OUTPUTS = 2; // 0x2
}
public final class AudioFocusInfo implements android.os.Parcelable {
method public int describeContents();
method public android.media.AudioAttributes getAttributes();
@@ -16050,11 +16040,13 @@ package android.media {
public class AudioManager {
method public int abandonAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener);
method public int abandonAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, android.media.AudioAttributes);
method public void addOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener, android.os.Handler);
method public void adjustStreamVolume(int, int, int);
method public void adjustSuggestedStreamVolume(int, int, int);
method public void adjustVolume(int, int);
method public void dispatchMediaKeyEvent(android.view.KeyEvent);
method public int generateAudioSessionId();
method public android.media.AudioDeviceInfo[] getDevices(int);
method public int getMode();
method public java.lang.String getParameters(java.lang.String);
method public java.lang.String getProperty(java.lang.String);
@@ -16081,6 +16073,7 @@ package android.media {
method public deprecated void registerMediaButtonEventReceiver(android.app.PendingIntent);
method public deprecated void registerRemoteControlClient(android.media.RemoteControlClient);
method public deprecated boolean registerRemoteController(android.media.RemoteController);
method public void removeOnAudioDeviceConnectionListener(android.media.OnAudioDeviceConnectionListener);
method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int);
method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, android.media.AudioAttributes, int, int) throws java.lang.IllegalArgumentException;
method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, android.media.AudioAttributes, int, int, android.media.audiopolicy.AudioPolicy) throws java.lang.IllegalArgumentException;
@@ -16155,6 +16148,9 @@ package android.media {
field public static final int FX_KEYPRESS_SPACEBAR = 6; // 0x6
field public static final int FX_KEYPRESS_STANDARD = 5; // 0x5
field public static final int FX_KEY_CLICK = 0; // 0x0
field public static final int GET_DEVICES_ALL = 3; // 0x3
field public static final int GET_DEVICES_INPUTS = 1; // 0x1
field public static final int GET_DEVICES_OUTPUTS = 2; // 0x2
field public static final int MODE_CURRENT = -1; // 0xffffffff
field public static final int MODE_INVALID = -2; // 0xfffffffe
field public static final int MODE_IN_CALL = 2; // 0x2
@@ -16204,7 +16200,7 @@ package android.media {
public class AudioRecord {
ctor public AudioRecord(int, int, int, int, int) throws java.lang.IllegalArgumentException;
ctor public AudioRecord(android.media.AudioAttributes, android.media.AudioFormat, int, int) throws java.lang.IllegalArgumentException;
method public void addOnAudioRecordRoutingListener(android.media.OnAudioRecordRoutingListener, android.os.Handler);
method public void addOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener, android.os.Handler);
method public int getAudioFormat();
method public int getAudioSessionId();
method public int getAudioSource();
@@ -16215,7 +16211,7 @@ package android.media {
method public int getNativeFrameCount() throws java.lang.IllegalStateException;
method public int getNotificationMarkerPosition();
method public int getPositionNotificationPeriod();
method public android.media.AudioDeviceInfo getPreferredInputDevice();
method public android.media.AudioDeviceInfo getPreferredDevice();
method public int getRecordingState();
method public android.media.AudioDeviceInfo getRoutedDevice();
method public int getSampleRate();
@@ -16228,10 +16224,10 @@ package android.media {
method public int read(java.nio.ByteBuffer, int);
method public int read(java.nio.ByteBuffer, int, int);
method public void release();
method public void removeOnAudioRecordRoutingListener(android.media.OnAudioRecordRoutingListener);
method public void removeOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener);
method public int setNotificationMarkerPosition(int);
method public int setPositionNotificationPeriod(int);
method public boolean setPreferredInputDevice(android.media.AudioDeviceInfo);
method public boolean setPreferredDevice(android.media.AudioDeviceInfo);
method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener);
method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener, android.os.Handler);
method public void startRecording() throws java.lang.IllegalStateException;
@@ -16264,6 +16260,10 @@ package android.media {
method public abstract void onPeriodicNotification(android.media.AudioRecord);
}
public static abstract interface AudioRecord.OnRoutingChangedListener {
method public abstract void onRoutingChanged(android.media.AudioRecord);
}
public final class AudioTimestamp {
ctor public AudioTimestamp();
field public long framePosition;
@@ -16274,7 +16274,7 @@ package android.media {
ctor public AudioTrack(int, int, int, int, int, int) throws java.lang.IllegalArgumentException;
ctor public AudioTrack(int, int, int, int, int, int, int) throws java.lang.IllegalArgumentException;
ctor public AudioTrack(android.media.AudioAttributes, android.media.AudioFormat, int, int, int) throws java.lang.IllegalArgumentException;
method public void addOnAudioTrackRoutingListener(android.media.OnAudioTrackRoutingListener, android.os.Handler);
method public void addOnRoutingChangedListener(android.media.AudioTrack.OnRoutingChangedListener, android.os.Handler);
method public int attachAuxEffect(int);
method public void flush();
method public int getAudioFormat();
@@ -16293,7 +16293,7 @@ package android.media {
method public android.media.PlaybackParams getPlaybackParams();
method public int getPlaybackRate();
method public int getPositionNotificationPeriod();
method public android.media.AudioDeviceInfo getPreferredOutputDevice();
method public android.media.AudioDeviceInfo getPreferredDevice();
method public android.media.AudioDeviceInfo getRoutedDevice();
method public int getSampleRate();
method public int getState();
@@ -16303,7 +16303,7 @@ package android.media {
method public void play() throws java.lang.IllegalStateException;
method public void release();
method public int reloadStaticData();
method public void removeOnAudioTrackRoutingListener(android.media.OnAudioTrackRoutingListener);
method public void removeOnRoutingChangedListener(android.media.AudioTrack.OnRoutingChangedListener);
method public int setAuxEffectSendLevel(float);
method public int setLoopPoints(int, int, int);
method public int setNotificationMarkerPosition(int);
@@ -16313,7 +16313,7 @@ package android.media {
method public void setPlaybackPositionUpdateListener(android.media.AudioTrack.OnPlaybackPositionUpdateListener, android.os.Handler);
method public int setPlaybackRate(int);
method public int setPositionNotificationPeriod(int);
method public boolean setPreferredOutputDevice(android.media.AudioDeviceInfo);
method public boolean setPreferredDevice(android.media.AudioDeviceInfo);
method protected deprecated void setState(int);
method public deprecated int setStereoVolume(float, float);
method public int setVolume(float);
@@ -16356,6 +16356,10 @@ package android.media {
method public abstract void onPeriodicNotification(android.media.AudioTrack);
}
public static abstract interface AudioTrack.OnRoutingChangedListener {
method public abstract void onRoutingChanged(android.media.AudioTrack);
}
public class CamcorderProfile {
method public static android.media.CamcorderProfile get(int);
method public static android.media.CamcorderProfile get(int, int);
@@ -17726,14 +17730,6 @@ package android.media {
method public abstract void onAudioDeviceConnection();
}
public abstract interface OnAudioRecordRoutingListener {
method public abstract void onAudioRecordRouting(android.media.AudioRecord);
}
public abstract interface OnAudioTrackRoutingListener {
method public abstract void onAudioTrackRouting(android.media.AudioTrack);
}
public final class PlaybackParams {
ctor public PlaybackParams();
method public android.media.PlaybackParams allowDefaults();

View File

@@ -55,7 +55,6 @@ import android.location.CountryDetector;
import android.location.ICountryDetector;
import android.location.ILocationManager;
import android.location.LocationManager;
import android.media.AudioDevicesManager;
import android.media.AudioManager;
import android.media.MediaRouter;
import android.media.midi.IMidiManager;
@@ -701,13 +700,6 @@ final class SystemServiceRegistry {
public RadioManager createService(ContextImpl ctx) {
return new RadioManager(ctx);
}});
registerService(Context.AUDIO_DEVICES_SERVICE, AudioDevicesManager.class,
new CachedServiceFetcher<AudioDevicesManager>() {
@Override
public AudioDevicesManager createService(ContextImpl ctx) {
return new AudioDevicesManager(ctx);
}});
}
/**
@@ -726,7 +718,7 @@ final class SystemServiceRegistry {
}
/**
* Gets the name of the system-level service that is represented by the specified class.
* Gets the name of the system-level service that is represented by the specified class.
*/
public static String getSystemServiceName(Class<?> serviceClass) {
return SYSTEM_SERVICE_NAMES.get(serviceClass);

View File

@@ -3132,16 +3132,6 @@ public abstract class Context {
*/
public static final String RADIO_SERVICE = "radio";
/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.AudioDevicesManager} for handling device enumeration & notification.
*
* @see #getSystemService
* @see android.media.AudioDevicesManager
*/
public static final String AUDIO_DEVICES_SERVICE = "audio_devices_manager";
/**
* Determine whether the given permission is allowed for a particular
* process and user ID running in the system.

View File

@@ -21,7 +21,7 @@ import android.util.SparseIntArray;
/**
* Class to provide information about the audio devices.
*/
public class AudioDeviceInfo {
public final class AudioDeviceInfo {
/**
* A device type associated with an unknown or uninitialized device.
@@ -112,7 +112,6 @@ public class AudioDeviceInfo {
}
/**
* @hide
* @return The internal device ID.
*/
public int getId() {
@@ -122,15 +121,15 @@ public class AudioDeviceInfo {
/**
* @return The human-readable name of the audio device.
*/
public String getName() {
public CharSequence getName() {
return mPort.name();
}
/**
* @hide
* @return The "address" string of the device. This generally contains device-specific
* parameters.
*/
// TODO Is there a compelling reason to expose this?
public String getAddress() {
return mPort.address();
}
@@ -157,15 +156,18 @@ public class AudioDeviceInfo {
}
/**
* @return An array of channel masks supported by the audio device (defined in
* AudioFormat.java).
* @return An array of channel masks ({@link AudioFormat#CHANNEL_IN_STEREO},
* {@link AudioFormat#CHANNEL_OUT_7POINT1) for which this audio device can be configured.
*
* @see AudioFormat
*/
public int[] getChannelMasks() {
return mPort.channelMasks();
}
/**
* @return An array of channel counts supported by the audio device.
* @return An array of channel counts (1, 2, 4....) for which this audio device
* can be configured.
*/
public int[] getChannelCounts() {
int[] masks = getChannelMasks();
@@ -179,8 +181,10 @@ public class AudioDeviceInfo {
}
/**
* @return An array of audio format IDs supported by the audio device (defined in
* AudioFormat.java)
* @return An array of audio format IDs (@link AudioFormat#ENCODING_PCM_16BIT,
* {@link AudioFormat#ENCODING_PCM_FLOAT}...) supported by the audio device.
*
* @see AudioFormat
*/
public int[] getFormats() {
return mPort.formats();

View File

@@ -1,275 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.ArrayMap;
import android.util.Pair;
import android.util.Slog;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.HashMap;
import java.util.Iterator;
/**
* AudioDevicesManager implements the Android Media Audio device enumeration and notification
* functionality. This functionality is in two comlementary parts.
* <ol>
* <li>{@link AudioDevicesManager#listDevices(int)} gets the list of current audio devices
* </li>
* <li>{@link AudioDevicesManager#addOnAudioDeviceConnectionListener(OnAudioDeviceConnectionListener, android.os.Handler)}
* provides a mechanism for applications to be informed of audio device connect/disconnect events.
* </li>
* </ol>
*/
public class AudioDevicesManager {
private static String TAG = "AudioDevicesManager";
private static boolean DEBUG = false;
private AudioManager mAudioManager = null;
private OnAmPortUpdateListener mPortListener = null;
/**
* The message sent to apps when the contents of the device list changes if they provide
* a {#link Handler} object to addOnAudioDeviceConnectionListener().
*/
private final static int MSG_DEVICES_LIST_CHANGE = 0;
private ArrayMap<OnAudioDeviceConnectionListener, NativeEventHandlerDelegate>
mDeviceConnectionListeners =
new ArrayMap<OnAudioDeviceConnectionListener, NativeEventHandlerDelegate>();
/**
* @hide
* The AudioDevicesManager class is used to enumerate the physical audio devices connected
* to the system. See also {@link AudioDeviceInfo}.
*/
public AudioDevicesManager(Context context) {
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mPortListener = new OnAmPortUpdateListener();
mAudioManager.registerAudioPortUpdateListener(mPortListener);
}
/**
* Specifies to the {@link AudioDevicesManager#listDevices(int)} method to include
* source (i.e. input) audio devices.
*/
public static final int LIST_DEVICES_INPUTS = 0x0001;
/**
* Specifies to the {@link AudioDevicesManager#listDevices(int)} method to include
* sink (i.e. output) audio devices.
*/
public static final int LIST_DEVICES_OUTPUTS = 0x0002;
/**
* Specifies to the {@link AudioDevicesManager#listDevices(int)} method to include both
* source and sink devices.
*/
public static final int LIST_DEVICES_ALL = LIST_DEVICES_OUTPUTS | LIST_DEVICES_INPUTS;
/**
* Determines if a given AudioDevicePort meets the specified filter criteria.
* @param port The port to test.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link LIST_DEVICES_OUTPUTS} and {@link LIST_DEVICES_INPUTS}
**/
private static boolean checkFlags(AudioDevicePort port, int flags) {
return port.role() == AudioPort.ROLE_SINK && (flags & LIST_DEVICES_OUTPUTS) != 0 ||
port.role() == AudioPort.ROLE_SOURCE && (flags & LIST_DEVICES_INPUTS) != 0;
}
/**
* Generates a list of AudioDeviceInfo objects corresponding to the audio devices currently
* connected to the system and meeting the criteria specified in the <code>flags</code>
* parameter.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link LIST_DEVICES_OUTPUTS}, {@link LIST_DEVICES_INPUTS} and {@link LIST_DEVICES_ALL}.
* @return A (possibly zero-length) array of AudioDeviceInfo objects.
*/
public AudioDeviceInfo[] listDevices(int flags) {
return listDevicesStatic(flags);
}
/**
* Generates a list of AudioDeviceInfo objects corresponding to the audio devices currently
* connected to the system and meeting the criteria specified in the <code>flags</code>
* parameter.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link LIST_DEVICES_OUTPUTS}, {@link LIST_DEVICES_INPUTS} and {@link LIST_DEVICES_ALL}.
* @return A (possibly zero-length) array of AudioDeviceInfo objects.
* @hide
*/
public static AudioDeviceInfo[] listDevicesStatic(int flags) {
ArrayList<AudioDevicePort> ports = new ArrayList<AudioDevicePort>();
int status = AudioManager.listAudioDevicePorts(ports);
if (status != AudioManager.SUCCESS) {
// fail and bail!
return new AudioDeviceInfo[0];
}
// figure out how many AudioDeviceInfo we need space for
int numRecs = 0;
for (AudioDevicePort port : ports) {
if (checkFlags(port, flags)) {
numRecs++;
}
}
// Now load them up
AudioDeviceInfo[] deviceList = new AudioDeviceInfo[numRecs];
int slot = 0;
for (AudioDevicePort port : ports) {
if (checkFlags(port, flags)) {
deviceList[slot++] = new AudioDeviceInfo(port);
}
}
return deviceList;
}
/**
* Adds an {@link OnAudioDeviceConnectionListener} to receive notifications of changes
* to the set of connected audio devices.
*/
public void addOnAudioDeviceConnectionListener(OnAudioDeviceConnectionListener listener,
android.os.Handler handler) {
if (listener != null && !mDeviceConnectionListeners.containsKey(listener)) {
synchronized (mDeviceConnectionListeners) {
mDeviceConnectionListeners.put(
listener, new NativeEventHandlerDelegate(listener, handler));
}
}
}
/**
* Removes an {@link OnAudioDeviceConnectionListener} which has been previously registered
* to receive notifications of changes to the set of connected audio devices.
*/
public void removeOnAudioDeviceConnectionListener(OnAudioDeviceConnectionListener listener) {
synchronized (mDeviceConnectionListeners) {
if (mDeviceConnectionListeners.containsKey(listener)) {
mDeviceConnectionListeners.remove(listener);
}
}
}
/**
* Sends device list change notification to all listeners.
*/
private void broadcastDeviceListChange() {
Collection<NativeEventHandlerDelegate> values;
synchronized (mDeviceConnectionListeners) {
values = mDeviceConnectionListeners.values();
}
for(NativeEventHandlerDelegate delegate : values) {
Handler handler = delegate.getHandler();
if (handler != null) {
handler.sendEmptyMessage(MSG_DEVICES_LIST_CHANGE);
}
}
}
/**
* Handles Port list update notifications from the AudioManager
*/
private class OnAmPortUpdateListener implements AudioManager.OnAudioPortUpdateListener {
static final String TAG = "OnAmPortUpdateListener";
public void onAudioPortListUpdate(AudioPort[] portList) {
broadcastDeviceListChange();
}
/**
* Callback method called upon audio patch list update.
* @param patchList the updated list of audio patches
*/
public void onAudioPatchListUpdate(AudioPatch[] patchList) {
if (DEBUG) {
Slog.d(TAG, "onAudioPatchListUpdate() " + patchList.length + " patches.");
}
}
/**
* Callback method called when the mediaserver dies
*/
public void onServiceDied() {
if (DEBUG) {
Slog.i(TAG, "onServiceDied()");
}
broadcastDeviceListChange();
}
}
//---------------------------------------------------------
// Inner classes
//--------------------
/**
* Helper class to handle the forwarding of native events to the appropriate listener
* (potentially) handled in a different thread.
*/
private class NativeEventHandlerDelegate {
private final Handler mHandler;
NativeEventHandlerDelegate(final OnAudioDeviceConnectionListener listener,
Handler handler) {
// find the looper for our new event handler
Looper looper;
if (handler != null) {
looper = handler.getLooper();
} else {
// no given handler, use the looper the addListener call was called in
looper = Looper.getMainLooper();
}
// construct the event handler with this looper
if (looper != null) {
// implement the event handler delegate
mHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_DEVICES_LIST_CHANGE:
// call the OnAudioDeviceConnectionListener
if (listener != null) {
listener.onAudioDeviceConnection();
}
break;
default:
Slog.e(TAG, "Unknown native event type: " + msg.what);
break;
}
}
};
} else {
mHandler = null;
}
}
Handler getHandler() {
return mHandler;
}
}
}

View File

@@ -42,10 +42,13 @@ import android.os.SystemProperties;
import android.os.SystemClock;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -628,6 +631,9 @@ public class AudioManager {
mUseFixedVolume = getContext().getResources().getBoolean(
com.android.internal.R.bool.config_useFixedVolume);
sAudioPortEventHandler.init();
mPortListener = new OnAmPortUpdateListener();
registerAudioPortUpdateListener(mPortListener);
}
private Context getContext() {
@@ -3697,4 +3703,210 @@ public class AudioManager {
portCfg.format(),
gainCfg);
}
private OnAmPortUpdateListener mPortListener = null;
/**
* The message sent to apps when the contents of the device list changes if they provide
* a {#link Handler} object to addOnAudioDeviceConnectionListener().
*/
private final static int MSG_DEVICES_LIST_CHANGE = 0;
private ArrayMap<OnAudioDeviceConnectionListener, NativeEventHandlerDelegate>
mDeviceConnectionListeners =
new ArrayMap<OnAudioDeviceConnectionListener, NativeEventHandlerDelegate>();
/**
* Specifies to the {@link AudioManager#getDevices(int)} method to include
* source (i.e. input) audio devices.
*/
public static final int GET_DEVICES_INPUTS = 0x0001;
/**
* Specifies to the {@link AudioManager#getDevices(int)} method to include
* sink (i.e. output) audio devices.
*/
public static final int GET_DEVICES_OUTPUTS = 0x0002;
/**
* Specifies to the {@link AudioManager#getDevices(int)} method to include both
* source and sink devices.
*/
public static final int GET_DEVICES_ALL = GET_DEVICES_OUTPUTS | GET_DEVICES_INPUTS;
/**
* Determines if a given AudioDevicePort meets the specified filter criteria.
* @param port The port to test.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link GET_DEVICES_OUTPUTS} and {@link GET_DEVICES_INPUTS}
**/
private static boolean checkFlags(AudioDevicePort port, int flags) {
return port.role() == AudioPort.ROLE_SINK && (flags & GET_DEVICES_OUTPUTS) != 0 ||
port.role() == AudioPort.ROLE_SOURCE && (flags & GET_DEVICES_INPUTS) != 0;
}
/**
* Generates a list of AudioDeviceInfo objects corresponding to the audio devices currently
* connected to the system and meeting the criteria specified in the <code>flags</code>
* parameter.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link GET_DEVICES_OUTPUTS}, {@link GET_DEVICES_INPUTS} and {@lGET_DEVICES_CES_ALL}.
* @return A (possibly zero-length) array of AudioDeviceInfo objects.
*/
public AudioDeviceInfo[] getDevices(int flags) {
return getDevicesStatic(flags);
}
/**
* Generates a list of AudioDeviceInfo objects corresponding to the audio devices currently
* connected to the system and meeting the criteria specified in the <code>flags</code>
* parameter.
* @param flags A set of bitflags specifying the criteria to test.
* @see {@link GET_DEVICES_OUTPUTS}, {@link GET_DEVICES_INPUTS} and {@link GET_DEVICES_ALL}.
* @return A (possibly zero-length) array of AudioDeviceInfo objects.
* @hide
*/
public static AudioDeviceInfo[] getDevicesStatic(int flags) {
ArrayList<AudioDevicePort> ports = new ArrayList<AudioDevicePort>();
int status = AudioManager.listAudioDevicePorts(ports);
if (status != AudioManager.SUCCESS) {
// fail and bail!
return new AudioDeviceInfo[0];
}
// figure out how many AudioDeviceInfo we need space for
int numRecs = 0;
for (AudioDevicePort port : ports) {
if (checkFlags(port, flags)) {
numRecs++;
}
}
// Now load them up
AudioDeviceInfo[] deviceList = new AudioDeviceInfo[numRecs];
int slot = 0;
for (AudioDevicePort port : ports) {
if (checkFlags(port, flags)) {
deviceList[slot++] = new AudioDeviceInfo(port);
}
}
return deviceList;
}
/**
* Adds an {@link OnAudioDeviceConnectionListener} to receive notifications of changes
* to the set of connected audio devices.
*/
public void addOnAudioDeviceConnectionListener(OnAudioDeviceConnectionListener listener,
android.os.Handler handler) {
if (listener != null && !mDeviceConnectionListeners.containsKey(listener)) {
synchronized (mDeviceConnectionListeners) {
mDeviceConnectionListeners.put(
listener, new NativeEventHandlerDelegate(listener, handler));
}
}
}
/**
* Removes an {@link OnAudioDeviceConnectionListener} which has been previously registered
* to receive notifications of changes to the set of connected audio devices.
*/
public void removeOnAudioDeviceConnectionListener(OnAudioDeviceConnectionListener listener) {
synchronized (mDeviceConnectionListeners) {
if (mDeviceConnectionListeners.containsKey(listener)) {
mDeviceConnectionListeners.remove(listener);
}
}
}
/**
* Sends device list change notification to all listeners.
*/
private void broadcastDeviceListChange() {
Collection<NativeEventHandlerDelegate> values;
synchronized (mDeviceConnectionListeners) {
values = mDeviceConnectionListeners.values();
}
for (NativeEventHandlerDelegate delegate : values) {
Handler handler = delegate.getHandler();
if (handler != null) {
handler.sendEmptyMessage(MSG_DEVICES_LIST_CHANGE);
}
}
}
/**
* Handles Port list update notifications from the AudioManager
*/
private class OnAmPortUpdateListener implements AudioManager.OnAudioPortUpdateListener {
static final String TAG = "OnAmPortUpdateListener";
public void onAudioPortListUpdate(AudioPort[] portList) {
broadcastDeviceListChange();
}
/**
* Callback method called upon audio patch list update.
* @param patchList the updated list of audio patches
*/
public void onAudioPatchListUpdate(AudioPatch[] patchList) {}
/**
* Callback method called when the mediaserver dies
*/
public void onServiceDied() {
broadcastDeviceListChange();
}
}
//---------------------------------------------------------
// Inner classes
//--------------------
/**
* Helper class to handle the forwarding of native events to the appropriate listener
* (potentially) handled in a different thread.
*/
private class NativeEventHandlerDelegate {
private final Handler mHandler;
NativeEventHandlerDelegate(final OnAudioDeviceConnectionListener listener,
Handler handler) {
// find the looper for our new event handler
Looper looper;
if (handler != null) {
looper = handler.getLooper();
} else {
// no given handler, use the looper the addListener call was called in
looper = Looper.getMainLooper();
}
// construct the event handler with this looper
if (looper != null) {
// implement the event handler delegate
mHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_DEVICES_LIST_CHANGE:
// call the OnAudioDeviceConnectionListener
if (listener != null) {
listener.onAudioDeviceConnection();
}
break;
default:
Log.e(TAG, "Unknown native event type: " + msg.what);
break;
}
}
};
} else {
mHandler = null;
}
}
Handler getHandler() {
return mHandler;
}
}
}

View File

@@ -1202,6 +1202,14 @@ public class AudioRecord
//--------------------------------------------------------------------------
// (Re)Routing Info
//--------------------
public interface OnRoutingChangedListener {
/**
* Called when the routing of an AudioRecord changes from either and explicit or
* policy rerouting.
*/
public void onRoutingChanged(AudioRecord audioRecord);
}
/**
* Returns an {@link AudioDeviceInfo} identifying the current routing of this AudioRecord.
*/
@@ -1211,7 +1219,7 @@ public class AudioRecord
return null;
}
AudioDeviceInfo[] devices =
AudioDevicesManager.listDevicesStatic(AudioDevicesManager.LIST_DEVICES_INPUTS);
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_INPUTS);
for (int i = 0; i < devices.length; i++) {
if (devices[i].getId() == deviceId) {
return devices[i];
@@ -1222,17 +1230,17 @@ public class AudioRecord
/**
* The message sent to apps when the routing of this AudioRecord changes if they provide
* a {#link Handler} object to addOnAudioRecordRoutingListener().
* a {#link Handler} object to addOnRoutingChangeListener().
*/
private ArrayMap<OnAudioRecordRoutingListener, NativeRoutingEventHandlerDelegate>
private ArrayMap<OnRoutingChangedListener, NativeRoutingEventHandlerDelegate>
mRoutingChangeListeners =
new ArrayMap<OnAudioRecordRoutingListener, NativeRoutingEventHandlerDelegate>();
new ArrayMap<OnRoutingChangedListener, NativeRoutingEventHandlerDelegate>();
/**
* Adds an {@link OnAudioRecordRoutingListener} to receive notifications of routing changes
* Adds an {@link OnRoutingChangedListener} to receive notifications of routing changes
* on this AudioRecord.
*/
public void addOnAudioRecordRoutingListener(OnAudioRecordRoutingListener listener,
public void addOnRoutingChangedListener(OnRoutingChangedListener listener,
android.os.Handler handler) {
if (listener != null && !mRoutingChangeListeners.containsKey(listener)) {
synchronized (mRoutingChangeListeners) {
@@ -1246,10 +1254,10 @@ public class AudioRecord
}
/**
* Removes an {@link OnAudioRecordRoutingListener} which has been previously added
* Removes an {@link OnRoutingChangedListener} which has been previously added
* to receive notifications of changes to the set of connected audio devices.
*/
public void removeOnAudioRecordRoutingListener(OnAudioRecordRoutingListener listener) {
public void removeOnRoutingChangedListener(OnRoutingChangedListener listener) {
synchronized (mRoutingChangeListeners) {
if (mRoutingChangeListeners.containsKey(listener)) {
mRoutingChangeListeners.remove(listener);
@@ -1268,7 +1276,7 @@ public class AudioRecord
private final Handler mHandler;
NativeRoutingEventHandlerDelegate(final AudioRecord record,
final OnAudioRecordRoutingListener listener,
final OnRoutingChangedListener listener,
Handler handler) {
// find the looper for our new event handler
Looper looper;
@@ -1291,7 +1299,7 @@ public class AudioRecord
switch(msg.what) {
case AudioSystem.NATIVE_EVENT_ROUTING_CHANGE:
if (listener != null) {
listener.onAudioRecordRouting(record);
listener.onRoutingChanged(record);
}
break;
default:
@@ -1354,7 +1362,7 @@ public class AudioRecord
* @return true if successful, false if the specified {@link AudioDeviceInfo} is non-null and
* does not correspond to a valid audio input device.
*/
public boolean setPreferredInputDevice(AudioDeviceInfo deviceInfo) {
public boolean setPreferredDevice(AudioDeviceInfo deviceInfo) {
// Do some validation....
if (deviceInfo != null && !deviceInfo.isSource()) {
return false;
@@ -1371,10 +1379,10 @@ public class AudioRecord
}
/**
* Returns the selected input specified by {@link #setPreferredInputDevice}. Note that this
* Returns the selected input specified by {@link #setPreferredDevice}. Note that this
* is not guarenteed to correspond to the actual device being used for recording.
*/
public AudioDeviceInfo getPreferredInputDevice() {
public AudioDeviceInfo getPreferredDevice() {
synchronized (this) {
return mPreferredDevice;
}

View File

@@ -2046,7 +2046,7 @@ public class AudioTrack
* @return true if succesful, false if the specified {@link AudioDeviceInfo} is non-null and
* does not correspond to a valid audio output device.
*/
public boolean setPreferredOutputDevice(AudioDeviceInfo deviceInfo) {
public boolean setPreferredDevice(AudioDeviceInfo deviceInfo) {
// Do some validation....
if (deviceInfo != null && !deviceInfo.isSink()) {
return false;
@@ -2062,10 +2062,10 @@ public class AudioTrack
}
/**
* Returns the selected output specified by {@link #setPreferredOutputDevice}. Note that this
* Returns the selected output specified by {@link #setPreferredDevice}. Note that this
* is not guaranteed to correspond to the actual device being used for playback.
*/
public AudioDeviceInfo getPreferredOutputDevice() {
public AudioDeviceInfo getPreferredDevice() {
synchronized (this) {
return mPreferredDevice;
}
@@ -2074,6 +2074,14 @@ public class AudioTrack
//--------------------------------------------------------------------------
// (Re)Routing Info
//--------------------
public interface OnRoutingChangedListener {
/**
* Called when the routing of an AudioTrack changes from either and explicit or
* policy rerouting.
*/
public void onRoutingChanged(AudioTrack audioTrack);
}
/**
* Returns an {@link AudioDeviceInfo} identifying the current routing of this AudioTrack.
*/
@@ -2083,7 +2091,7 @@ public class AudioTrack
return null;
}
AudioDeviceInfo[] devices =
AudioDevicesManager.listDevicesStatic(AudioDevicesManager.LIST_DEVICES_OUTPUTS);
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_OUTPUTS);
for (int i = 0; i < devices.length; i++) {
if (devices[i].getId() == deviceId) {
return devices[i];
@@ -2094,17 +2102,17 @@ public class AudioTrack
/**
* The message sent to apps when the routing of this AudioTrack changes if they provide
* a {#link Handler} object to addOnAudioTrackRoutingListener().
* a {#link Handler} object to addOnRoutingChangedListener().
*/
private ArrayMap<OnAudioTrackRoutingListener, NativeRoutingEventHandlerDelegate>
private ArrayMap<OnRoutingChangedListener, NativeRoutingEventHandlerDelegate>
mRoutingChangeListeners =
new ArrayMap<OnAudioTrackRoutingListener, NativeRoutingEventHandlerDelegate>();
new ArrayMap<OnRoutingChangedListener, NativeRoutingEventHandlerDelegate>();
/**
* Adds an {@link OnAudioTrackRoutingListener} to receive notifications of routing changes
* Adds an {@link OnRoutingChangedListener} to receive notifications of routing changes
* on this AudioTrack.
*/
public void addOnAudioTrackRoutingListener(OnAudioTrackRoutingListener listener,
public void addOnRoutingChangedListener(OnRoutingChangedListener listener,
android.os.Handler handler) {
if (listener != null && !mRoutingChangeListeners.containsKey(listener)) {
synchronized (mRoutingChangeListeners) {
@@ -2118,10 +2126,10 @@ public class AudioTrack
}
/**
* Removes an {@link OnAudioTrackRoutingListener} which has been previously added
* Removes an {@link OnRoutingChangedListener} which has been previously added
* to receive notifications of changes to the set of connected audio devices.
*/
public void removeOnAudioTrackRoutingListener(OnAudioTrackRoutingListener listener) {
public void removeOnRoutingChangedListener(OnRoutingChangedListener listener) {
synchronized (mRoutingChangeListeners) {
if (mRoutingChangeListeners.containsKey(listener)) {
mRoutingChangeListeners.remove(listener);
@@ -2236,7 +2244,7 @@ public class AudioTrack
private final Handler mHandler;
NativeRoutingEventHandlerDelegate(final AudioTrack track,
final OnAudioTrackRoutingListener listener,
final OnRoutingChangedListener listener,
Handler handler) {
// find the looper for our new event handler
Looper looper;
@@ -2259,7 +2267,7 @@ public class AudioTrack
switch(msg.what) {
case AudioSystem.NATIVE_EVENT_ROUTING_CHANGE:
if (listener != null) {
listener.onAudioTrackRouting(track);
listener.onRoutingChanged(track);
}
break;
default:

View File

@@ -18,13 +18,13 @@ package android.media;
/**
* OnAudioDeviceConnectionListener defines the interface for notification listeners in the
* {@link AudioDevicesManager}
* {@link AudioManager}
*/
public interface OnAudioDeviceConnectionListener {
/**
* Called by the {@link AudioDevicesManager} to indicate that an audio device has been
* Called by the {@link AudioManager} to indicate that an audio device has been
* connected or disconnected. A listener will probably call the
* {@link AudioDevicesManager#listDevices} method to retrieve the current list of audio
* {@link AudioManager#getDevices} method to retrieve the current list of audio
* devices.
*/
public void onAudioDeviceConnection();

View File

@@ -1,29 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
/**
* OnAudioDeviceConnectionListener defines the interface for notification listeners in the
* {@link AudioDevicesManager}
*/
public interface OnAudioRecordRoutingListener {
/**
* Called when the routing of an AudioRecord changes from either and explicit or
* policy rerouting.
*/
public void onAudioRecordRouting(AudioRecord audioRecord);
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
/**
* OnAudioDeviceConnectionListener defines the interface for notification listeners in the
* {@link AudioDevicesManager}
*/
public interface OnAudioTrackRoutingListener {
/**
* Called when the routing of an AudioTrack changes from either and explicit or
* policy rerouting.
*/
public void onAudioTrackRouting(AudioTrack audioTrack);
}