Merge "AudioManager: optimize audio port listener registration" into mnc-dev
This commit is contained in:
@@ -619,10 +619,6 @@ public class AudioManager {
|
|||||||
com.android.internal.R.bool.config_useVolumeKeySounds);
|
com.android.internal.R.bool.config_useVolumeKeySounds);
|
||||||
mUseFixedVolume = getContext().getResources().getBoolean(
|
mUseFixedVolume = getContext().getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_useFixedVolume);
|
com.android.internal.R.bool.config_useFixedVolume);
|
||||||
sAudioPortEventHandler.init();
|
|
||||||
|
|
||||||
mPortListener = new OnAmPortUpdateListener();
|
|
||||||
registerAudioPortUpdateListener(mPortListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Context getContext() {
|
private Context getContext() {
|
||||||
@@ -3554,6 +3550,7 @@ public class AudioManager {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) {
|
public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) {
|
||||||
|
sAudioPortEventHandler.init();
|
||||||
sAudioPortEventHandler.registerListener(l);
|
sAudioPortEventHandler.registerListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3586,6 +3583,7 @@ public class AudioManager {
|
|||||||
|
|
||||||
static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches,
|
static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches,
|
||||||
ArrayList<AudioPort> previousPorts) {
|
ArrayList<AudioPort> previousPorts) {
|
||||||
|
sAudioPortEventHandler.init();
|
||||||
synchronized (sAudioPortGeneration) {
|
synchronized (sAudioPortGeneration) {
|
||||||
|
|
||||||
if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) {
|
if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) {
|
||||||
@@ -3849,6 +3847,12 @@ public class AudioManager {
|
|||||||
android.os.Handler handler) {
|
android.os.Handler handler) {
|
||||||
if (callback != null && !mDeviceCallbacks.containsKey(callback)) {
|
if (callback != null && !mDeviceCallbacks.containsKey(callback)) {
|
||||||
synchronized (mDeviceCallbacks) {
|
synchronized (mDeviceCallbacks) {
|
||||||
|
if (mDeviceCallbacks.size() == 0) {
|
||||||
|
if (mPortListener == null) {
|
||||||
|
mPortListener = new OnAmPortUpdateListener();
|
||||||
|
}
|
||||||
|
registerAudioPortUpdateListener(mPortListener);
|
||||||
|
}
|
||||||
NativeEventHandlerDelegate delegate =
|
NativeEventHandlerDelegate delegate =
|
||||||
new NativeEventHandlerDelegate(callback, handler);
|
new NativeEventHandlerDelegate(callback, handler);
|
||||||
mDeviceCallbacks.put(callback, delegate);
|
mDeviceCallbacks.put(callback, delegate);
|
||||||
@@ -3867,6 +3871,9 @@ public class AudioManager {
|
|||||||
synchronized (mDeviceCallbacks) {
|
synchronized (mDeviceCallbacks) {
|
||||||
if (mDeviceCallbacks.containsKey(callback)) {
|
if (mDeviceCallbacks.containsKey(callback)) {
|
||||||
mDeviceCallbacks.remove(callback);
|
mDeviceCallbacks.remove(callback);
|
||||||
|
if (mDeviceCallbacks.size() == 0) {
|
||||||
|
unregisterAudioPortUpdateListener(mPortListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user