From e05eef8449e5314c1bd0278b1484130c170a379a Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 8 Mar 2018 18:56:34 -0800 Subject: [PATCH] AudioService: prevent muting of alarm / accessibility STREAM_ACCESSIBILITY / ALARM min volume is index 1 Prevent a11y stream volume to be 0 when used separately from media. Prevent setting a volume index above min value. Bug: 72403580 Bug: 74985293 Test: verify media vol can go to 0 ; enable Talkback verify a11y volume can't be muted with vol keys or UI Change-Id: Id46506d4c407f42fe3aca463055b0973e1a7c4dc --- .../android/server/audio/AudioService.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index c8b6b5056ebbe..3e82c25836a89 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -320,13 +320,13 @@ public class AudioService extends IAudioService.Stub 0, // STREAM_SYSTEM 0, // STREAM_RING 0, // STREAM_MUSIC - 0, // STREAM_ALARM + 1, // STREAM_ALARM 0, // STREAM_NOTIFICATION 0, // STREAM_BLUETOOTH_SCO 0, // STREAM_SYSTEM_ENFORCED 0, // STREAM_DTMF 0, // STREAM_TTS - 0 // STREAM_ACCESSIBILITY + 1 // STREAM_ACCESSIBILITY }; /* mStreamVolumeAlias[] indicates for each stream if it uses the volume settings @@ -1208,6 +1208,8 @@ 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) { @@ -1389,7 +1391,15 @@ public class AudioService extends IAudioService.Stub } private int rescaleIndex(int index, int srcStream, int dstStream) { - return (index * mStreamStates[dstStream].getMaxIndex() + mStreamStates[srcStream].getMaxIndex() / 2) / mStreamStates[srcStream].getMaxIndex(); + final int rescaled = + (index * mStreamStates[dstStream].getMaxIndex() + + mStreamStates[srcStream].getMaxIndex() / 2) + / mStreamStates[srcStream].getMaxIndex(); + if (rescaled < mStreamStates[dstStream].getMinIndex()) { + return mStreamStates[dstStream].getMinIndex(); + } else { + return rescaled; + } } /////////////////////////////////////////////////////////////////////////// @@ -4602,8 +4612,8 @@ public class AudioService extends IAudioService.Stub // 4 VolumeStreamState.class public class VolumeStreamState { private final int mStreamType; - private final int mIndexMin; - private final int mIndexMax; + private int mIndexMin; + private int mIndexMax; private boolean mIsMuted; private String mVolumeIndexSettingName; @@ -4888,6 +4898,24 @@ 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