Merge "AudioService: fix accessibility volume range" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-05-31 19:47:25 +00:00
committed by Android (Google) Code Review

View File

@@ -1275,8 +1275,6 @@ public class AudioService extends IAudioService.Stub
System.VOLUME_SETTINGS_INT[a11yStreamAlias]; System.VOLUME_SETTINGS_INT[a11yStreamAlias];
mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].setAllIndexes( mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].setAllIndexes(
mStreamStates[a11yStreamAlias], caller); mStreamStates[a11yStreamAlias], caller);
mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].refreshRange(
mStreamVolumeAlias[AudioSystem.STREAM_ACCESSIBILITY]);
} }
} }
if (sIndependentA11yVolume) { if (sIndependentA11yVolume) {
@@ -1577,20 +1575,19 @@ public class AudioService extends IAudioService.Stub
} }
private int rescaleIndex(int index, int srcStream, int dstStream) { private int rescaleIndex(int index, int srcStream, int dstStream) {
int max = mStreamStates[srcStream].getMaxIndex(); int srcRange =
if (max == 0) { mStreamStates[srcStream].getMaxIndex() - mStreamStates[srcStream].getMinIndex();
Log.e(TAG, "rescaleIndex : Max index should not be zero"); int dstRange =
return mStreamStates[srcStream].getMinIndex(); mStreamStates[dstStream].getMaxIndex() - mStreamStates[dstStream].getMinIndex();
}
final int rescaled = if (srcRange == 0) {
(index * mStreamStates[dstStream].getMaxIndex() Log.e(TAG, "rescaleIndex : index range should not be zero");
+ mStreamStates[srcStream].getMaxIndex() / 2)
/ mStreamStates[srcStream].getMaxIndex();
if (rescaled < mStreamStates[dstStream].getMinIndex()) {
return mStreamStates[dstStream].getMinIndex(); return mStreamStates[dstStream].getMinIndex();
} else {
return rescaled;
} }
return mStreamStates[dstStream].getMinIndex()
+ ((index - mStreamStates[srcStream].getMinIndex()) * dstRange + srcRange / 2)
/ srcRange;
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@@ -4729,24 +4726,6 @@ public class AudioService extends IAudioService.Stub
return mIndexMin; return mIndexMin;
} }
/**
* Updates the min/max index values from another stream. Use this when changing the alias
* for the current stream type.
* @param sourceStreamType
*/
// must be sync'd on mSettingsLock before VolumeStreamState.class
@GuardedBy("VolumeStreamState.class")
public void refreshRange(int sourceStreamType) {
mIndexMin = MIN_STREAM_VOLUME[sourceStreamType] * 10;
mIndexMax = MAX_STREAM_VOLUME[sourceStreamType] * 10;
// verify all current volumes are within bounds
for (int i = 0 ; i < mIndexMap.size(); i++) {
final int device = mIndexMap.keyAt(i);
final int index = mIndexMap.valueAt(i);
mIndexMap.put(device, getValidIndex(index));
}
}
/** /**
* Copies all device/index pairs from the given VolumeStreamState after initializing * Copies all device/index pairs from the given VolumeStreamState after initializing
* them with the volume for DEVICE_OUT_DEFAULT. No-op if the source VolumeStreamState * them with the volume for DEVICE_OUT_DEFAULT. No-op if the source VolumeStreamState