Merge "AudioService: fix step rescaling."
am: 7516db2ec2
Change-Id: I12c88bb68269fb018c239ad267239fefbb06368d
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 055a4bd..24569a6 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -1582,12 +1582,13 @@
setMicrophoneMuteNoCallerCheck(currentUser);
}
- private int rescaleIndex(int index, int srcStream, int dstStream) {
- int srcRange =
- mStreamStates[srcStream].getMaxIndex() - mStreamStates[srcStream].getMinIndex();
- int dstRange =
- mStreamStates[dstStream].getMaxIndex() - mStreamStates[dstStream].getMinIndex();
+ private int getIndexRange(int streamType) {
+ return (mStreamStates[streamType].getMaxIndex() - mStreamStates[streamType].getMinIndex());
+ }
+ private int rescaleIndex(int index, int srcStream, int dstStream) {
+ int srcRange = getIndexRange(srcStream);
+ int dstRange = getIndexRange(dstStream);
if (srcRange == 0) {
Log.e(TAG, "rescaleIndex : index range should not be zero");
return mStreamStates[dstStream].getMinIndex();
@@ -1598,6 +1599,17 @@
/ srcRange;
}
+ private int rescaleStep(int step, int srcStream, int dstStream) {
+ int srcRange = getIndexRange(srcStream);
+ int dstRange = getIndexRange(dstStream);
+ if (srcRange == 0) {
+ Log.e(TAG, "rescaleStep : index range should not be zero");
+ return 0;
+ }
+
+ return ((step * dstRange + srcRange / 2) / srcRange);
+ }
+
///////////////////////////////////////////////////////////////////////////
// IPC methods
///////////////////////////////////////////////////////////////////////////
@@ -1774,7 +1786,7 @@
}
} else {
// convert one UI step (+/-1) into a number of internal units on the stream alias
- step = rescaleIndex(10, streamType, streamTypeAlias);
+ step = rescaleStep(10, streamType, streamTypeAlias);
}
// If either the client forces allowing ringer modes for this adjustment,