From f0fecb1967f1b258af6eded5e69277eeebad0b2f Mon Sep 17 00:00:00 2001 From: Tomoharu Kasahara Date: Thu, 6 Sep 2018 20:04:38 +0900 Subject: [PATCH] Make pre-scale for absolute volume configurable Audio gain for lower volume steps are restricted for Bluetooth Absolute Volume scenario, but it's better not to use the fixed value. This CL makes it possible to configure the value of pre-scale. Bug: 114220617 Test: manual - gain is restricted as per the configuration Change-Id: I1fd0c77476386ba9518e1819d5ea2c7b0c344a40 --- core/res/res/values/config.xml | 9 +++++ core/res/res/values/symbols.xml | 5 +++ .../android/server/audio/AudioService.java | 38 ++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 1404383bc234a..9aebf6c4597f9 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -3541,4 +3541,13 @@ + + + 50% + + + 70% + + + 85% diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 21f0dad69e2ca..9f2256a6461a2 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3470,4 +3470,9 @@ + + + + + diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 8caa70283acf3..66c7c437284b9 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -627,6 +627,13 @@ public class AudioService extends IAudioService.Stub // If absolute volume is supported in AVRCP device private boolean mAvrcpAbsVolSupported = false; + // Pre-scale for Bluetooth Absolute Volume + private float[] mPrescaleAbsoluteVolume = new float[] { + 0.5f, // Pre-scale for index 1 + 0.7f, // Pre-scale for index 2 + 0.85f, // Pre-scale for index 3 + }; + private static Long mLastDeviceConnectMsgTime = new Long(0); private NotificationManager mNm; @@ -878,6 +885,23 @@ public class AudioService extends IAudioService.Stub mUserManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener); mRecordMonitor.initMonitor(); + + final float[] preScale = new float[3]; + preScale[0] = mContext.getResources().getFraction( + com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index1, + 1, 1); + preScale[1] = mContext.getResources().getFraction( + com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index2, + 1, 1); + preScale[2] = mContext.getResources().getFraction( + com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index3, + 1, 1); + for (int i = 0; i < preScale.length; i++) { + if (0.0f <= preScale[i] && preScale[i] <= 1.0f) { + mPrescaleAbsoluteVolume[i] = preScale[i]; + } + } + } public void systemReady() { @@ -4926,18 +4950,12 @@ public class AudioService extends IAudioService.Stub if (index == 0) { // 0% for volume 0 index = 0; - } else if (index == 1) { - // 50% for volume 1 - index = (int)(mIndexMax * 0.5) /10; - } else if (index == 2) { - // 70% for volume 2 - index = (int)(mIndexMax * 0.70) /10; - } else if (index == 3) { - // 85% for volume 3 - index = (int)(mIndexMax * 0.85) /10; + } else if (index > 0 && index <= 3) { + // Pre-scale for volume steps 1 2 and 3 + index = (int) (mIndexMax * mPrescaleAbsoluteVolume[index - 1]) / 10; } else { // otherwise, full gain - index = (mIndexMax + 5)/10; + index = (mIndexMax + 5) / 10; } return index; }