summaryrefslogtreecommitdiffstats
path: root/media/java/android
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2015-06-26 17:43:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-26 17:43:03 +0000
commit5da8ed16239c81c535afd01d91d68b6c2d96eff6 (patch)
tree7a44054d039e99df1bcff88aa78f77a749f009fd /media/java/android
parent29f37e15975dec1fbb519398e5e80b16d61a5d0c (diff)
parentc573bc5d3da12b52b0c45416f884d8d21b0ef500 (diff)
downloadframeworks_base-5da8ed16239c81c535afd01d91d68b6c2d96eff6.zip
frameworks_base-5da8ed16239c81c535afd01d91d68b6c2d96eff6.tar.gz
frameworks_base-5da8ed16239c81c535afd01d91d68b6c2d96eff6.tar.bz2
Merge "AudioManager: optimize audio port listener registration" into mnc-dev
Diffstat (limited to 'media/java/android')
-rw-r--r--media/java/android/media/AudioManager.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index a806440..b3b2b97 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -619,10 +619,6 @@ public class AudioManager {
com.android.internal.R.bool.config_useVolumeKeySounds);
mUseFixedVolume = getContext().getResources().getBoolean(
com.android.internal.R.bool.config_useFixedVolume);
- sAudioPortEventHandler.init();
-
- mPortListener = new OnAmPortUpdateListener();
- registerAudioPortUpdateListener(mPortListener);
}
private Context getContext() {
@@ -3554,6 +3550,7 @@ public class AudioManager {
* @hide
*/
public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) {
+ sAudioPortEventHandler.init();
sAudioPortEventHandler.registerListener(l);
}
@@ -3586,6 +3583,7 @@ public class AudioManager {
static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches,
ArrayList<AudioPort> previousPorts) {
+ sAudioPortEventHandler.init();
synchronized (sAudioPortGeneration) {
if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) {
@@ -3849,6 +3847,12 @@ public class AudioManager {
android.os.Handler handler) {
if (callback != null && !mDeviceCallbacks.containsKey(callback)) {
synchronized (mDeviceCallbacks) {
+ if (mDeviceCallbacks.size() == 0) {
+ if (mPortListener == null) {
+ mPortListener = new OnAmPortUpdateListener();
+ }
+ registerAudioPortUpdateListener(mPortListener);
+ }
NativeEventHandlerDelegate delegate =
new NativeEventHandlerDelegate(callback, handler);
mDeviceCallbacks.put(callback, delegate);
@@ -3867,6 +3871,9 @@ public class AudioManager {
synchronized (mDeviceCallbacks) {
if (mDeviceCallbacks.containsKey(callback)) {
mDeviceCallbacks.remove(callback);
+ if (mDeviceCallbacks.size() == 0) {
+ unregisterAudioPortUpdateListener(mPortListener);
+ }
}
}
}