Skip to content
Snippets Groups Projects
Commit 0985eea3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix a lock issue in AudioPortEventHandler"

parents 45402914 6dbaaf2d
No related branches found
No related tags found
No related merge requests found
......@@ -19,10 +19,12 @@ package android.media;
import android.annotation.UnsupportedAppUsage;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import java.util.ArrayList;
import com.android.internal.annotations.GuardedBy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
/**
* The AudioPortEventHandler handles AudioManager.OnAudioPortUpdateListener callbacks
......@@ -33,6 +35,9 @@ import java.lang.ref.WeakReference;
class AudioPortEventHandler {
private Handler mHandler;
private HandlerThread mHandlerThread;
private final Object mLock = new Object();
@GuardedBy("mLock")
private final ArrayList<AudioManager.OnAudioPortUpdateListener> mListeners =
new ArrayList<AudioManager.OnAudioPortUpdateListener>();
......@@ -53,7 +58,7 @@ class AudioPortEventHandler {
private long mJniCallback;
void init() {
synchronized (this) {
synchronized (mLock) {
if (mHandler != null) {
return;
}
......@@ -66,7 +71,7 @@ class AudioPortEventHandler {
@Override
public void handleMessage(Message msg) {
ArrayList<AudioManager.OnAudioPortUpdateListener> listeners;
synchronized (this) {
synchronized (mLock) {
if (msg.what == AUDIOPORT_EVENT_NEW_LISTENER) {
listeners = new ArrayList<AudioManager.OnAudioPortUpdateListener>();
if (mListeners.contains(msg.obj)) {
......@@ -152,7 +157,7 @@ class AudioPortEventHandler {
private native void native_finalize();
void registerListener(AudioManager.OnAudioPortUpdateListener l) {
synchronized (this) {
synchronized (mLock) {
mListeners.add(l);
}
if (mHandler != null) {
......@@ -162,7 +167,7 @@ class AudioPortEventHandler {
}
void unregisterListener(AudioManager.OnAudioPortUpdateListener l) {
synchronized (this) {
synchronized (mLock) {
mListeners.remove(l);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment