am ba64d298: Merge "AudioService: fix cross deadlock in VolumeStreamState"

* commit 'ba64d298bee228b8e27ea17fb31fbff4b4188304':
  AudioService: fix cross deadlock in VolumeStreamState
This commit is contained in:
Eric Laurent
2014-05-23 21:37:54 +00:00
committed by Android Git Automerger

View File

@@ -2863,7 +2863,8 @@ public class AudioService extends IAudioService.Stub {
return name + "_" + suffix; return name + "_" + suffix;
} }
public synchronized void readSettings() { public void readSettings() {
synchronized (VolumeStreamState.class) {
// force maximum volume on all streams if fixed volume property is set // force maximum volume on all streams if fixed volume property is set
if (mUseFixedVolume) { if (mUseFixedVolume) {
mIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, mIndexMax); mIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, mIndexMax);
@@ -2914,6 +2915,7 @@ public class AudioService extends IAudioService.Stub {
} }
} }
} }
}
public void applyDeviceVolume(int device) { public void applyDeviceVolume(int device) {
int index; int index;
@@ -2928,7 +2930,8 @@ public class AudioService extends IAudioService.Stub {
AudioSystem.setStreamVolumeIndex(mStreamType, index, device); AudioSystem.setStreamVolumeIndex(mStreamType, index, device);
} }
public synchronized void applyAllVolumes() { public void applyAllVolumes() {
synchronized (VolumeStreamState.class) {
// apply default volume first: by convention this will reset all // apply default volume first: by convention this will reset all
// devices volumes in audio policy manager to the supplied value // devices volumes in audio policy manager to the supplied value
int index; int index;
@@ -2957,13 +2960,15 @@ public class AudioService extends IAudioService.Stub {
} }
} }
} }
}
public boolean adjustIndex(int deltaIndex, int device) { public boolean adjustIndex(int deltaIndex, int device) {
return setIndex(getIndex(device) + deltaIndex, return setIndex(getIndex(device) + deltaIndex,
device); device);
} }
public synchronized boolean setIndex(int index, int device) { public boolean setIndex(int index, int device) {
synchronized (VolumeStreamState.class) {
int oldIndex = getIndex(device); int oldIndex = getIndex(device);
index = getValidIndex(index); index = getValidIndex(index);
synchronized (mCameraSoundForced) { synchronized (mCameraSoundForced) {
@@ -2996,8 +3001,10 @@ public class AudioService extends IAudioService.Stub {
return false; return false;
} }
} }
}
public synchronized int getIndex(int device) { public int getIndex(int device) {
synchronized (VolumeStreamState.class) {
Integer index = mIndex.get(device); Integer index = mIndex.get(device);
if (index == null) { if (index == null) {
// there is always an entry for AudioSystem.DEVICE_OUT_DEFAULT // there is always an entry for AudioSystem.DEVICE_OUT_DEFAULT
@@ -3005,12 +3012,14 @@ public class AudioService extends IAudioService.Stub {
} }
return index.intValue(); return index.intValue();
} }
}
public int getMaxIndex() { public int getMaxIndex() {
return mIndexMax; return mIndexMax;
} }
public synchronized void setAllIndexes(VolumeStreamState srcStream) { public void setAllIndexes(VolumeStreamState srcStream) {
synchronized (VolumeStreamState.class) {
int srcStreamType = srcStream.getStreamType(); int srcStreamType = srcStream.getStreamType();
// apply default device volume from source stream to all devices first in case // apply default device volume from source stream to all devices first in case
// some devices are present in this stream state but not in source stream state // some devices are present in this stream state but not in source stream state
@@ -3034,8 +3043,10 @@ public class AudioService extends IAudioService.Stub {
setIndex(index, device); setIndex(index, device);
} }
} }
}
public synchronized void setAllIndexesToMax() { public void setAllIndexesToMax() {
synchronized (VolumeStreamState.class) {
Set set = mIndex.entrySet(); Set set = mIndex.entrySet();
Iterator i = set.iterator(); Iterator i = set.iterator();
while (i.hasNext()) { while (i.hasNext()) {
@@ -3043,8 +3054,10 @@ public class AudioService extends IAudioService.Stub {
entry.setValue(mIndexMax); entry.setValue(mIndexMax);
} }
} }
}
public synchronized void mute(IBinder cb, boolean state) { public void mute(IBinder cb, boolean state) {
synchronized (VolumeStreamState.class) {
VolumeDeathHandler handler = getDeathHandler(cb, state); VolumeDeathHandler handler = getDeathHandler(cb, state);
if (handler == null) { if (handler == null) {
Log.e(TAG, "Could not get client death handler for stream: "+mStreamType); Log.e(TAG, "Could not get client death handler for stream: "+mStreamType);
@@ -3052,6 +3065,7 @@ public class AudioService extends IAudioService.Stub {
} }
handler.mute(state); handler.mute(state);
} }
}
public int getStreamType() { public int getStreamType() {
return mStreamType; return mStreamType;