diff options
author | Eric Laurent <elaurent@google.com> | 2015-05-08 11:43:05 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2015-05-08 11:43:05 -0700 |
commit | 8a1e7a881ee73b9b1e492e7014c3eaefe81cfbd7 (patch) | |
tree | a9eb32e65ba3a783603b32d1bf41f533a54f9c7a /media | |
parent | dd441795409f26f45de3ce40a1bab4121cfcefe5 (diff) | |
download | frameworks_base-8a1e7a881ee73b9b1e492e7014c3eaefe81cfbd7.zip frameworks_base-8a1e7a881ee73b9b1e492e7014c3eaefe81cfbd7.tar.gz frameworks_base-8a1e7a881ee73b9b1e492e7014c3eaefe81cfbd7.tar.bz2 |
AudioManager: add previous AudioPort list
Maintain a cache of previously attached audio ports used
to create lists of added and removed devices following
a port list update callback.
Change-Id: Iad1c95b85c8ae9bdbed79eb0cdc46aeedeafccea
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioManager.java | 62 | ||||
-rw-r--r-- | media/java/android/media/AudioPortEventHandler.java | 2 |
2 files changed, 53 insertions, 11 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 19900d0..56f0400 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -3402,7 +3402,17 @@ public class AudioManager { * @hide */ public static int listAudioPorts(ArrayList<AudioPort> ports) { - return updateAudioPortCache(ports, null); + return updateAudioPortCache(ports, null, null); + } + + /** + * Returns a list of descriptors for all audio ports managed by the audio framework as + * it was before the last update calback. + * @param ports An AudioPort ArrayList where the list will be returned. + * @hide + */ + public static int listPreviousAudioPorts(ArrayList<AudioPort> ports) { + return updateAudioPortCache(null, null, ports); } /** @@ -3411,19 +3421,44 @@ public class AudioManager { * @hide */ public static int listAudioDevicePorts(ArrayList<AudioDevicePort> devices) { + if (devices == null) { + return ERROR_BAD_VALUE; + } ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); - int status = updateAudioPortCache(ports, null); + int status = updateAudioPortCache(ports, null, null); if (status == SUCCESS) { - devices.clear(); - for (int i = 0; i < ports.size(); i++) { - if (ports.get(i) instanceof AudioDevicePort) { - devices.add((AudioDevicePort)ports.get(i)); - } - } + filterDevicePorts(ports, devices); + } + return status; + } + + /** + * Specialized version of listPreviousAudioPorts() listing only audio devices (AudioDevicePort) + * @see listPreviousAudioPorts(ArrayList<AudioPort>) + * @hide + */ + public static int listPreviousAudioDevicePorts(ArrayList<AudioDevicePort> devices) { + if (devices == null) { + return ERROR_BAD_VALUE; + } + ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); + int status = updateAudioPortCache(null, null, ports); + if (status == SUCCESS) { + filterDevicePorts(ports, devices); } return status; } + private static void filterDevicePorts(ArrayList<AudioPort> ports, + ArrayList<AudioDevicePort> devices) { + devices.clear(); + for (int i = 0; i < ports.size(); i++) { + if (ports.get(i) instanceof AudioDevicePort) { + devices.add((AudioDevicePort)ports.get(i)); + } + } + } + /** * Create a connection between two or more devices. The framework will reject the request if * device types are not compatible or the implementation does not support the requested @@ -3474,7 +3509,7 @@ public class AudioManager { * @hide */ public static int listAudioPatches(ArrayList<AudioPatch> patches) { - return updateAudioPortCache(null, patches); + return updateAudioPortCache(null, patches, null); } /** @@ -3540,6 +3575,7 @@ public class AudioManager { static final int AUDIOPORT_GENERATION_INIT = 0; static Integer sAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); static ArrayList<AudioPort> sAudioPortsCached = new ArrayList<AudioPort>(); + static ArrayList<AudioPort> sPreviousAudioPortsCached = new ArrayList<AudioPort>(); static ArrayList<AudioPatch> sAudioPatchesCached = new ArrayList<AudioPatch>(); static int resetAudioPortGeneration() { @@ -3551,7 +3587,8 @@ public class AudioManager { return generation; } - static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { + static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches, + ArrayList<AudioPort> previousPorts) { synchronized (sAudioPortGeneration) { if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { @@ -3610,6 +3647,7 @@ public class AudioManager { } } + sPreviousAudioPortsCached = sAudioPortsCached; sAudioPortsCached = newPorts; sAudioPatchesCached = newPatches; sAudioPortGeneration = portGeneration[0]; @@ -3622,6 +3660,10 @@ public class AudioManager { patches.clear(); patches.addAll(sAudioPatchesCached); } + if (previousPorts != null) { + previousPorts.clear(); + previousPorts.addAll(sPreviousAudioPortsCached); + } } return SUCCESS; } diff --git a/media/java/android/media/AudioPortEventHandler.java b/media/java/android/media/AudioPortEventHandler.java index c49e8c2..c152245 100644 --- a/media/java/android/media/AudioPortEventHandler.java +++ b/media/java/android/media/AudioPortEventHandler.java @@ -84,7 +84,7 @@ class AudioPortEventHandler { ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>(); if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) { - int status = AudioManager.updateAudioPortCache(ports, patches); + int status = AudioManager.updateAudioPortCache(ports, patches, null); if (status != AudioManager.SUCCESS) { return; } |