Loading media/java/android/media/AudioManager.java +20 −20 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class AudioManager { private final boolean mUseFixedVolume; private final boolean mUseFixedVolume; private final Binder mToken = new Binder(); private final Binder mToken = new Binder(); private static String TAG = "AudioManager"; 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 * 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); com.android.internal.R.bool.config_useMasterVolume); mUseVolumeKeySounds = mContext.getResources().getBoolean( mUseVolumeKeySounds = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useVolumeKeySounds); com.android.internal.R.bool.config_useVolumeKeySounds); mAudioPortEventHandler = new AudioPortEventHandler(this); mUseFixedVolume = mContext.getResources().getBoolean( mUseFixedVolume = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useFixedVolume); com.android.internal.R.bool.config_useFixedVolume); sAudioPortEventHandler.init(); } } private static IAudioService getService() private static IAudioService getService() Loading Loading @@ -3607,7 +3607,7 @@ public class AudioManager { * @hide * @hide */ */ public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.registerListener(l); sAudioPortEventHandler.registerListener(l); } } /** /** Loading @@ -3615,7 +3615,7 @@ public class AudioManager { * @hide * @hide */ */ public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { 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; static final int AUDIOPORT_GENERATION_INIT = 0; Integer mAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); static Integer sAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); ArrayList<AudioPort> mAudioPortsCached = new ArrayList<AudioPort>(); static ArrayList<AudioPort> sAudioPortsCached = new ArrayList<AudioPort>(); ArrayList<AudioPatch> mAudioPatchesCached = new ArrayList<AudioPatch>(); static ArrayList<AudioPatch> sAudioPatchesCached = new ArrayList<AudioPatch>(); int resetAudioPortGeneration() { static int resetAudioPortGeneration() { int generation; int generation; synchronized (mAudioPortGeneration) { synchronized (sAudioPortGeneration) { generation = mAudioPortGeneration; generation = sAudioPortGeneration; mAudioPortGeneration = AUDIOPORT_GENERATION_INIT; sAudioPortGeneration = AUDIOPORT_GENERATION_INIT; } } return generation; return generation; } } int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { synchronized (mAudioPortGeneration) { synchronized (sAudioPortGeneration) { if (mAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { int[] patchGeneration = new int[1]; int[] patchGeneration = new int[1]; int[] portGeneration = new int[1]; int[] portGeneration = new int[1]; int status; int status; Loading Loading @@ -3678,23 +3678,23 @@ public class AudioManager { } } } } mAudioPortsCached = newPorts; sAudioPortsCached = newPorts; mAudioPatchesCached = newPatches; sAudioPatchesCached = newPatches; mAudioPortGeneration = portGeneration[0]; sAudioPortGeneration = portGeneration[0]; } } if (ports != null) { if (ports != null) { ports.clear(); ports.clear(); ports.addAll(mAudioPortsCached); ports.addAll(sAudioPortsCached); } } if (patches != null) { if (patches != null) { patches.clear(); patches.clear(); patches.addAll(mAudioPatchesCached); patches.addAll(sAudioPatchesCached); } } } } return SUCCESS; return SUCCESS; } } AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) { static AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) { AudioPort port = portCfg.port(); AudioPort port = portCfg.port(); int k; int k; for (k = 0; k < ports.size(); k++) { for (k = 0; k < ports.size(); k++) { Loading media/java/android/media/AudioPortEventHandler.java +71 −69 Original line number Original line Diff line number Diff line Loading @@ -31,21 +31,22 @@ import java.lang.ref.WeakReference; */ */ class AudioPortEventHandler { class AudioPortEventHandler { private final Handler mHandler; private Handler mHandler; private ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners; private final ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners = private AudioManager mAudioManager; 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_PORT_LIST_UPDATED = 1; private static final int AUDIOPORT_EVENT_PATCH_LIST_UPDATED = 2; 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_SERVICE_DIED = 3; private static final int AUDIOPORT_EVENT_NEW_LISTENER = 4; private static final int AUDIOPORT_EVENT_NEW_LISTENER = 4; AudioPortEventHandler(AudioManager audioManager) { void init() { mAudioManager = audioManager; synchronized (this) { mListeners = new ArrayList<AudioManager.OnAudioPortUpdateListener>(); if (mHandler != null) { return; } // find the looper for our new event handler // find the looper for our new event handler Looper looper = Looper.getMainLooper(); Looper looper = Looper.getMainLooper(); Loading @@ -72,12 +73,12 @@ class AudioPortEventHandler { if (msg.what == AUDIOPORT_EVENT_PORT_LIST_UPDATED || if (msg.what == AUDIOPORT_EVENT_PORT_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_PATCH_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_PATCH_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_SERVICE_DIED) { msg.what == AUDIOPORT_EVENT_SERVICE_DIED) { mAudioManager.resetAudioPortGeneration(); AudioManager.resetAudioPortGeneration(); } } ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>(); ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>(); if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) { if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) { int status = mAudioManager.updateAudioPortCache(ports, patches); int status = AudioManager.updateAudioPortCache(ports, patches); if (status != AudioManager.SUCCESS) { if (status != AudioManager.SUCCESS) { return; return; } } Loading Loading @@ -113,12 +114,13 @@ class AudioPortEventHandler { } } } } }; }; native_setup(new WeakReference<AudioPortEventHandler>(this)); } else { } else { mHandler = null; mHandler = null; } } native_setup(new WeakReference<AudioPortEventHandler>(this)); } } } private native void native_setup(Object module_this); private native void native_setup(Object module_this); @Override @Override Loading Loading
media/java/android/media/AudioManager.java +20 −20 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class AudioManager { private final boolean mUseFixedVolume; private final boolean mUseFixedVolume; private final Binder mToken = new Binder(); private final Binder mToken = new Binder(); private static String TAG = "AudioManager"; 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 * 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); com.android.internal.R.bool.config_useMasterVolume); mUseVolumeKeySounds = mContext.getResources().getBoolean( mUseVolumeKeySounds = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useVolumeKeySounds); com.android.internal.R.bool.config_useVolumeKeySounds); mAudioPortEventHandler = new AudioPortEventHandler(this); mUseFixedVolume = mContext.getResources().getBoolean( mUseFixedVolume = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useFixedVolume); com.android.internal.R.bool.config_useFixedVolume); sAudioPortEventHandler.init(); } } private static IAudioService getService() private static IAudioService getService() Loading Loading @@ -3607,7 +3607,7 @@ public class AudioManager { * @hide * @hide */ */ public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { mAudioPortEventHandler.registerListener(l); sAudioPortEventHandler.registerListener(l); } } /** /** Loading @@ -3615,7 +3615,7 @@ public class AudioManager { * @hide * @hide */ */ public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { 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; static final int AUDIOPORT_GENERATION_INIT = 0; Integer mAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); static Integer sAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); ArrayList<AudioPort> mAudioPortsCached = new ArrayList<AudioPort>(); static ArrayList<AudioPort> sAudioPortsCached = new ArrayList<AudioPort>(); ArrayList<AudioPatch> mAudioPatchesCached = new ArrayList<AudioPatch>(); static ArrayList<AudioPatch> sAudioPatchesCached = new ArrayList<AudioPatch>(); int resetAudioPortGeneration() { static int resetAudioPortGeneration() { int generation; int generation; synchronized (mAudioPortGeneration) { synchronized (sAudioPortGeneration) { generation = mAudioPortGeneration; generation = sAudioPortGeneration; mAudioPortGeneration = AUDIOPORT_GENERATION_INIT; sAudioPortGeneration = AUDIOPORT_GENERATION_INIT; } } return generation; return generation; } } int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { static int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { synchronized (mAudioPortGeneration) { synchronized (sAudioPortGeneration) { if (mAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { if (sAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { int[] patchGeneration = new int[1]; int[] patchGeneration = new int[1]; int[] portGeneration = new int[1]; int[] portGeneration = new int[1]; int status; int status; Loading Loading @@ -3678,23 +3678,23 @@ public class AudioManager { } } } } mAudioPortsCached = newPorts; sAudioPortsCached = newPorts; mAudioPatchesCached = newPatches; sAudioPatchesCached = newPatches; mAudioPortGeneration = portGeneration[0]; sAudioPortGeneration = portGeneration[0]; } } if (ports != null) { if (ports != null) { ports.clear(); ports.clear(); ports.addAll(mAudioPortsCached); ports.addAll(sAudioPortsCached); } } if (patches != null) { if (patches != null) { patches.clear(); patches.clear(); patches.addAll(mAudioPatchesCached); patches.addAll(sAudioPatchesCached); } } } } return SUCCESS; return SUCCESS; } } AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) { static AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) { AudioPort port = portCfg.port(); AudioPort port = portCfg.port(); int k; int k; for (k = 0; k < ports.size(); k++) { for (k = 0; k < ports.size(); k++) { Loading
media/java/android/media/AudioPortEventHandler.java +71 −69 Original line number Original line Diff line number Diff line Loading @@ -31,21 +31,22 @@ import java.lang.ref.WeakReference; */ */ class AudioPortEventHandler { class AudioPortEventHandler { private final Handler mHandler; private Handler mHandler; private ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners; private final ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners = private AudioManager mAudioManager; 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_PORT_LIST_UPDATED = 1; private static final int AUDIOPORT_EVENT_PATCH_LIST_UPDATED = 2; 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_SERVICE_DIED = 3; private static final int AUDIOPORT_EVENT_NEW_LISTENER = 4; private static final int AUDIOPORT_EVENT_NEW_LISTENER = 4; AudioPortEventHandler(AudioManager audioManager) { void init() { mAudioManager = audioManager; synchronized (this) { mListeners = new ArrayList<AudioManager.OnAudioPortUpdateListener>(); if (mHandler != null) { return; } // find the looper for our new event handler // find the looper for our new event handler Looper looper = Looper.getMainLooper(); Looper looper = Looper.getMainLooper(); Loading @@ -72,12 +73,12 @@ class AudioPortEventHandler { if (msg.what == AUDIOPORT_EVENT_PORT_LIST_UPDATED || if (msg.what == AUDIOPORT_EVENT_PORT_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_PATCH_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_PATCH_LIST_UPDATED || msg.what == AUDIOPORT_EVENT_SERVICE_DIED) { msg.what == AUDIOPORT_EVENT_SERVICE_DIED) { mAudioManager.resetAudioPortGeneration(); AudioManager.resetAudioPortGeneration(); } } ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>(); ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>(); if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) { if (msg.what != AUDIOPORT_EVENT_SERVICE_DIED) { int status = mAudioManager.updateAudioPortCache(ports, patches); int status = AudioManager.updateAudioPortCache(ports, patches); if (status != AudioManager.SUCCESS) { if (status != AudioManager.SUCCESS) { return; return; } } Loading Loading @@ -113,12 +114,13 @@ class AudioPortEventHandler { } } } } }; }; native_setup(new WeakReference<AudioPortEventHandler>(this)); } else { } else { mHandler = null; mHandler = null; } } native_setup(new WeakReference<AudioPortEventHandler>(this)); } } } private native void native_setup(Object module_this); private native void native_setup(Object module_this); @Override @Override Loading