diff options
| author | Paul McLean <pmclean@google.com> | 2015-05-11 15:39:28 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-11 15:39:29 +0000 |
| commit | 1c82b221d46b4f235f4c7fd3fd8d029772f86abb (patch) | |
| tree | 58170fadcaae3f475c0e2996fddc7a3080f51ca7 /media | |
| parent | f864d925bf861d8ae19ed91deeebf30741d286c5 (diff) | |
| parent | e3383cc4539921756232ae4f3f54e99b95fb20cc (diff) | |
| download | frameworks_base-1c82b221d46b4f235f4c7fd3fd8d029772f86abb.zip frameworks_base-1c82b221d46b4f235f4c7fd3fd8d029772f86abb.tar.gz frameworks_base-1c82b221d46b4f235f4c7fd3fd8d029772f86abb.tar.bz2 | |
Merge "Changes as per API council review." into mnc-dev
Diffstat (limited to 'media')
| -rw-r--r-- | media/java/android/media/AudioDeviceInfo.java | 22 | ||||
| -rw-r--r-- | media/java/android/media/AudioDevicesManager.java | 275 | ||||
| -rw-r--r-- | media/java/android/media/AudioManager.java | 212 | ||||
| -rw-r--r-- | media/java/android/media/AudioRecord.java | 34 | ||||
| -rw-r--r-- | media/java/android/media/AudioTrack.java | 34 | ||||
| -rw-r--r-- | media/java/android/media/OnAudioDeviceConnectionListener.java | 6 | ||||
| -rw-r--r-- | media/java/android/media/OnAudioRecordRoutingListener.java | 29 | ||||
| -rw-r--r-- | media/java/android/media/OnAudioTrackRoutingListener.java | 29 |
8 files changed, 270 insertions, 371 deletions
diff --git a/media/java/android/media/AudioDeviceInfo.java b/media/java/android/media/AudioDeviceInfo.java index d58b1d1..566f8dc 100644 --- a/media/java/android/media/AudioDeviceInfo.java +++ b/media/java/android/media/AudioDeviceInfo.java @@ -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(); diff --git a/media/java/android/media/AudioDevicesManager.java b/media/java/android/media/AudioDevicesManager.java deleted file mode 100644 index 8b83c17..0000000 --- a/media/java/android/media/AudioDevicesManager.java +++ /dev/null @@ -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; - } - } -} diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 56f0400..cba83f9 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -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; + } + } + } diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index 11671d8..c720e2a 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -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; } diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index dc37700..eda14a7 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -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: diff --git a/media/java/android/media/OnAudioDeviceConnectionListener.java b/media/java/android/media/OnAudioDeviceConnectionListener.java index 71c135a..57e9e17 100644 --- a/media/java/android/media/OnAudioDeviceConnectionListener.java +++ b/media/java/android/media/OnAudioDeviceConnectionListener.java @@ -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(); diff --git a/media/java/android/media/OnAudioRecordRoutingListener.java b/media/java/android/media/OnAudioRecordRoutingListener.java deleted file mode 100644 index 8ff41c5..0000000 --- a/media/java/android/media/OnAudioRecordRoutingListener.java +++ /dev/null @@ -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); -} diff --git a/media/java/android/media/OnAudioTrackRoutingListener.java b/media/java/android/media/OnAudioTrackRoutingListener.java deleted file mode 100644 index 18c72ef..0000000 --- a/media/java/android/media/OnAudioTrackRoutingListener.java +++ /dev/null @@ -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); -} |
