am 16cfa8dd: Merge "AudioManager: make AudioPortEventHandler static" into lmp-mr1-dev

* commit '16cfa8ddfd6c18577f5d38e545597a63889d9779':
  AudioManager: make AudioPortEventHandler static
This commit is contained in:
Eric Laurent
2015-01-15 22:16:28 +00:00
committed by Android Git Automerger
2 changed files with 92 additions and 90 deletions

View File

@ -65,7 +65,7 @@ public class AudioManager {
private final boolean mUseFixedVolume;
private final Binder mToken = new Binder();
private static String TAG = "AudioManager";
AudioPortEventHandler mAudioPortEventHandler;
private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
/**
* Broadcast intent, a hint for applications that audio is about to become
@ -646,9 +646,9 @@ public class AudioManager {
com.android.internal.R.bool.config_useMasterVolume);
mUseVolumeKeySounds = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useVolumeKeySounds);
mAudioPortEventHandler = new AudioPortEventHandler(this);
mUseFixedVolume = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useFixedVolume);
sAudioPortEventHandler.init();
}
private static IAudioService getService()
@ -3607,7 +3607,7 @@ public class AudioManager {
* @hide
*/
public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) {
mAudioPortEventHandler.registerListener(l);
sAudioPortEventHandler.registerListener(l);
}
/**
@ -3615,7 +3615,7 @@ public class AudioManager {
* @hide
*/
public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) {
mAudioPortEventHandler.unregisterListener(l);
sAudioPortEventHandler.unregisterListener(l);
}
//
@ -3623,23 +3623,23 @@ public class AudioManager {
//
static final int AUDIOPORT_GENERATION_INIT = 0;
Integer mAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT);
ArrayList<AudioPort> mAudioPortsCached = new ArrayList<AudioPort>();
ArrayList<AudioPatch> mAudioPatchesCached = new ArrayList<AudioPatch>();
static Integer sAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT);
static ArrayList<AudioPort> sAudioPortsCached = new ArrayList<AudioPort>();
static ArrayList<AudioPatch> sAudioPatchesCached = new ArrayList<AudioPatch>();
int resetAudioPortGeneration() {
static int resetAudioPortGeneration() {
int generation;
synchronized (mAudioPortGeneration) {
generation = mAudioPortGeneration;
mAudioPortGeneration = AUDIOPORT_GENERATION_INIT;
synchronized (sAudioPortGeneration) {
generation = sAudioPortGeneration;
sAudioPortGeneration = AUDIOPORT_GENERATION_INIT;
}
return generation;
}
int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) {
synchronized (mAudioPortGeneration) {
static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) {
synchronized (sAudioPortGeneration) {
if (mAudioPortGeneration == AUDIOPORT_GENERATION_INIT) {
if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) {
int[] patchGeneration = new int[1];
int[] portGeneration = new int[1];
int status;
@ -3678,23 +3678,23 @@ public class AudioManager {
}
}
mAudioPortsCached = newPorts;
mAudioPatchesCached = newPatches;
mAudioPortGeneration = portGeneration[0];
sAudioPortsCached = newPorts;
sAudioPatchesCached = newPatches;
sAudioPortGeneration = portGeneration[0];
}
if (ports != null) {
ports.clear();
ports.addAll(mAudioPortsCached);
ports.addAll(sAudioPortsCached);
}
if (patches != null) {
patches.clear();
patches.addAll(mAudioPatchesCached);
patches.addAll(sAudioPatchesCached);
}
}
return SUCCESS;
}
AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) {
static AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) {
AudioPort port = portCfg.port();
int k;
for (k = 0; k < ports.size(); k++) {

View File

@ -31,21 +31,22 @@ import java.lang.ref.WeakReference;
*/
class AudioPortEventHandler {
private final Handler mHandler;
private ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners;
private AudioManager mAudioManager;
private Handler mHandler;
private final ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners =
new ArrayList<AudioManager.OnAudioPortUpdateListener>();
private static String TAG = "AudioPortEventHandler";
private static final String TAG = "AudioPortEventHandler";
private static final int AUDIOPORT_EVENT_PORT_LIST_UPDATED = 1;
private static final int AUDIOPORT_EVENT_PATCH_LIST_UPDATED = 2;
private static final int AUDIOPORT_EVENT_SERVICE_DIED = 3;
private static final int AUDIOPORT_EVENT_NEW_LISTENER = 4;
AudioPortEventHandler(AudioManager audioManager) {
mAudioManager = audioManager;
mListeners = new ArrayList<AudioManager.OnAudioPortUpdateListener>();
void init() {
synchronized (this) {
if (mHandler != null) {
return;
}
// find the looper for our new event handler
Looper looper = Looper.getMainLooper();
@ -72,12 +73,12 @@ class AudioPortEventHandler {
if (msg.what == AUDIOPORT_EVENT_PORT_LIST_UPDATED ||
msg.what == AUDIOPORT_EVENT_PATCH_LIST_UPDATED ||
msg.what == AUDIOPORT_EVENT_SERVICE_DIED) {
mAudioManager.resetAudioPortGeneration();
AudioManager.resetAudioPortGeneration();
}
ArrayList<AudioPort> ports = new ArrayList<AudioPort>();
ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>();
if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) {
int status = mAudioManager.updateAudioPortCache(ports, patches);
int status = AudioManager.updateAudioPortCache(ports, patches);
if (status != AudioManager.SUCCESS) {
return;
}
@ -113,12 +114,13 @@ class AudioPortEventHandler {
}
}
};
native_setup(new WeakReference<AudioPortEventHandler>(this));
} else {
mHandler = null;
}
native_setup(new WeakReference<AudioPortEventHandler>(this));
}
}
private native void native_setup(Object module_this);
@Override