Loading media/java/android/media/AudioManager.java +20 −20 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading Loading @@ -3607,7 +3607,7 @@ public class AudioManager { * @hide */ public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.registerListener(l); sAudioPortEventHandler.registerListener(l); } /** Loading @@ -3615,7 +3615,7 @@ public class AudioManager { * @hide */ public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.unregisterListener(l); sAudioPortEventHandler.unregisterListener(l); } // Loading @@ -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; Loading Loading @@ -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++) { Loading media/java/android/media/AudioPortEventHandler.java +71 −69 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; } Loading Loading @@ -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 Loading Loading
media/java/android/media/AudioManager.java +20 −20 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading Loading @@ -3607,7 +3607,7 @@ public class AudioManager { * @hide */ public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.registerListener(l); sAudioPortEventHandler.registerListener(l); } /** Loading @@ -3615,7 +3615,7 @@ public class AudioManager { * @hide */ public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.unregisterListener(l); sAudioPortEventHandler.unregisterListener(l); } // Loading @@ -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; Loading Loading @@ -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++) { Loading
media/java/android/media/AudioPortEventHandler.java +71 −69 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; } Loading Loading @@ -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 Loading