Merge "AudioService: fix mismatch in device volume index for alias streams" into nyc-mr2-dev

This commit is contained in:
Eric Laurent
2016-12-07 21:12:38 +00:00
committed by Android (Google) Code Review

View File

@@ -4035,25 +4035,27 @@ public class AudioService extends IAudioService.Stub {
mIndexMap.put(device, index); mIndexMap.put(device, index);
changed = oldIndex != index; changed = oldIndex != index;
if (changed) { // Apply change to all streams using this one as alias if:
// Apply change to all streams using this one as alias // - the index actually changed OR
// if changing volume of current device, also change volume of current // - there is no volume index stored for this device on alias stream.
// If changing volume of current device, also change volume of current
// device on aliased stream // device on aliased stream
boolean currentDevice = (device == getDeviceForStream(mStreamType)); final boolean currentDevice = (device == getDeviceForStream(mStreamType));
int numStreamTypes = AudioSystem.getNumStreamTypes(); final int numStreamTypes = AudioSystem.getNumStreamTypes();
for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
final VolumeStreamState aliasStreamState = mStreamStates[streamType];
if (streamType != mStreamType && if (streamType != mStreamType &&
mStreamVolumeAlias[streamType] == mStreamType) { mStreamVolumeAlias[streamType] == mStreamType &&
int scaledIndex = rescaleIndex(index, mStreamType, streamType); (changed || !aliasStreamState.hasIndexForDevice(device))) {
mStreamStates[streamType].setIndex(scaledIndex, device, caller); final int scaledIndex = rescaleIndex(index, mStreamType, streamType);
aliasStreamState.setIndex(scaledIndex, device, caller);
if (currentDevice) { if (currentDevice) {
mStreamStates[streamType].setIndex(scaledIndex, aliasStreamState.setIndex(scaledIndex,
getDeviceForStream(streamType), caller); getDeviceForStream(streamType), caller);
} }
} }
} }
} }
}
if (changed) { if (changed) {
oldIndex = (oldIndex + 5) / 10; oldIndex = (oldIndex + 5) / 10;
index = (index + 5) / 10; index = (index + 5) / 10;
@@ -4086,6 +4088,12 @@ public class AudioService extends IAudioService.Stub {
} }
} }
public boolean hasIndexForDevice(int device) {
synchronized (VolumeStreamState.class) {
return (mIndexMap.get(device, -1) != -1);
}
}
public int getMaxIndex() { public int getMaxIndex() {
return mIndexMax; return mIndexMax;
} }