From 9f9029c455484dd02d189d8cb633415dc502d081 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 30 May 2019 18:20:07 -0700 Subject: [PATCH] AudioService: fix accessibility volume range Do not change accessibility stream volume range when the alias changes and make sure index rescaling enforces destination min and max values. Bug: 134099531 Test: change volume with talkback on or off Change-Id: I6c2a702628110b45ca63417994db9ffe1e01c569 --- .../android/server/audio/AudioService.java | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 30035c8c365bf..81a30388bb6cd 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -1275,8 +1275,6 @@ public class AudioService extends IAudioService.Stub System.VOLUME_SETTINGS_INT[a11yStreamAlias]; mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].setAllIndexes( mStreamStates[a11yStreamAlias], caller); - mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].refreshRange( - mStreamVolumeAlias[AudioSystem.STREAM_ACCESSIBILITY]); } } if (sIndependentA11yVolume) { @@ -1577,20 +1575,19 @@ public class AudioService extends IAudioService.Stub } private int rescaleIndex(int index, int srcStream, int dstStream) { - int max = mStreamStates[srcStream].getMaxIndex(); - if (max == 0) { - Log.e(TAG, "rescaleIndex : Max index should not be zero"); - return mStreamStates[srcStream].getMinIndex(); - } - final int rescaled = - (index * mStreamStates[dstStream].getMaxIndex() - + mStreamStates[srcStream].getMaxIndex() / 2) - / mStreamStates[srcStream].getMaxIndex(); - if (rescaled < mStreamStates[dstStream].getMinIndex()) { + int srcRange = + mStreamStates[srcStream].getMaxIndex() - mStreamStates[srcStream].getMinIndex(); + int dstRange = + mStreamStates[dstStream].getMaxIndex() - mStreamStates[dstStream].getMinIndex(); + + if (srcRange == 0) { + Log.e(TAG, "rescaleIndex : index range should not be zero"); 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; } - /** - * 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 * them with the volume for DEVICE_OUT_DEFAULT. No-op if the source VolumeStreamState