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,21 +4035,23 @@ 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.
// device on aliased stream // If changing volume of current device, also change volume of current
boolean currentDevice = (device == getDeviceForStream(mStreamType)); // device on aliased stream
int numStreamTypes = AudioSystem.getNumStreamTypes(); final boolean currentDevice = (device == getDeviceForStream(mStreamType));
for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { final int numStreamTypes = AudioSystem.getNumStreamTypes();
if (streamType != mStreamType && for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
mStreamVolumeAlias[streamType] == mStreamType) { final VolumeStreamState aliasStreamState = mStreamStates[streamType];
int scaledIndex = rescaleIndex(index, mStreamType, streamType); if (streamType != mStreamType &&
mStreamStates[streamType].setIndex(scaledIndex, device, caller); mStreamVolumeAlias[streamType] == mStreamType &&
if (currentDevice) { (changed || !aliasStreamState.hasIndexForDevice(device))) {
mStreamStates[streamType].setIndex(scaledIndex, final int scaledIndex = rescaleIndex(index, mStreamType, streamType);
getDeviceForStream(streamType), caller); aliasStreamState.setIndex(scaledIndex, device, caller);
} if (currentDevice) {
aliasStreamState.setIndex(scaledIndex,
getDeviceForStream(streamType), caller);
} }
} }
} }
@@ -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;
} }