audioservice: fix default stream volume
When the max stream volume is configurable by
a system property, the default stream volume should
be set accordingly.
Bug: 17507571.
Change-Id: I9d9378292fc7b9c9e32acc55a275cc0ae5b203d4
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 69c1142..faac6bfa 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -353,21 +353,6 @@
*/
@Deprecated public static final int NUM_STREAMS = AudioSystem.NUM_STREAMS;
-
- /** @hide Default volume index values for audio streams */
- public static final int[] DEFAULT_STREAM_VOLUME = new int[] {
- 4, // STREAM_VOICE_CALL
- 7, // STREAM_SYSTEM
- 5, // STREAM_RING
- 11, // STREAM_MUSIC
- 6, // STREAM_ALARM
- 5, // STREAM_NOTIFICATION
- 7, // STREAM_BLUETOOTH_SCO
- 7, // STREAM_SYSTEM_ENFORCED
- 11, // STREAM_DTMF
- 11 // STREAM_TTS
- };
-
/**
* Increase the ringer volume.
*
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index b0bf4a1..96df403 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -248,7 +248,7 @@
private final int[][] SOUND_EFFECT_FILES_MAP = new int[AudioManager.NUM_SOUND_EFFECTS][2];
/** @hide Maximum volume index values for audio streams */
- private static final int[] MAX_STREAM_VOLUME = new int[] {
+ private static int[] MAX_STREAM_VOLUME = new int[] {
5, // STREAM_VOICE_CALL
7, // STREAM_SYSTEM
7, // STREAM_RING
@@ -260,6 +260,20 @@
15, // STREAM_DTMF
15 // STREAM_TTS
};
+
+ private static int[] DEFAULT_STREAM_VOLUME = new int[] {
+ 4, // STREAM_VOICE_CALL
+ 7, // STREAM_SYSTEM
+ 5, // STREAM_RING
+ 11, // STREAM_MUSIC
+ 6, // STREAM_ALARM
+ 5, // STREAM_NOTIFICATION
+ 7, // STREAM_BLUETOOTH_SCO
+ 7, // STREAM_SYSTEM_ENFORCED
+ 11, // STREAM_DTMF
+ 11 // STREAM_TTS
+ };
+
/* mStreamVolumeAlias[] indicates for each stream if it uses the volume settings
* of another stream: This avoids multiplying the volume settings for hidden
* stream types that follow other stream behavior for volume settings
@@ -541,12 +555,18 @@
mHasVibrator = vibrator == null ? false : vibrator.hasVibrator();
// Intialized volume
- MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = SystemProperties.getInt(
- "ro.config.vc_call_vol_steps",
- MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]);
- MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = SystemProperties.getInt(
- "ro.config.media_vol_steps",
- MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]);
+ int maxVolume = SystemProperties.getInt("ro.config.vc_call_vol_steps",
+ MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]);
+ if (maxVolume != MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]) {
+ MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxVolume;
+ DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = (maxVolume * 3) / 4;
+ }
+ maxVolume = SystemProperties.getInt("ro.config.media_vol_steps",
+ MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]);
+ if (maxVolume != MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]) {
+ MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = maxVolume;
+ DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = (maxVolume * 3) / 4;
+ }
sSoundEffectVolumeDb = context.getResources().getInteger(
com.android.internal.R.integer.config_soundEffectVolumeDb);
@@ -1625,6 +1645,10 @@
return MAX_STREAM_VOLUME[streamType];
}
+ public static int getDefaultStreamVolume(int streamType) {
+ return DEFAULT_STREAM_VOLUME[streamType];
+ }
+
/** @see AudioManager#getStreamVolume(int) */
public int getStreamVolume(int streamType) {
ensureValidStreamType(streamType);
@@ -3351,7 +3375,7 @@
// only be stale values
if ((mStreamType == AudioSystem.STREAM_SYSTEM) ||
(mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED)) {
- int index = 10 * AudioManager.DEFAULT_STREAM_VOLUME[mStreamType];
+ int index = 10 * DEFAULT_STREAM_VOLUME[mStreamType];
synchronized (mCameraSoundForced) {
if (mCameraSoundForced) {
index = mIndexMax;
@@ -3375,7 +3399,7 @@
// if no volume stored for current stream and device, use default volume if default
// device, continue otherwise
int defaultIndex = (device == AudioSystem.DEVICE_OUT_DEFAULT) ?
- AudioManager.DEFAULT_STREAM_VOLUME[mStreamType] : -1;
+ DEFAULT_STREAM_VOLUME[mStreamType] : -1;
int index = Settings.System.getIntForUser(
mContentResolver, name, defaultIndex, UserHandle.USER_CURRENT);
if (index == -1) {
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index e56806a..eea97ea 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -568,7 +568,7 @@
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
@@ -2169,25 +2169,25 @@
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_MUSIC,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
loadSetting(stmt, Settings.System.VOLUME_RING,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_RING));
loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
loadSetting(
stmt,
Settings.System.VOLUME_VOICE,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
loadSetting(stmt, Settings.System.VOLUME_ALARM,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
loadSetting(
stmt,
Settings.System.VOLUME_NOTIFICATION,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
loadSetting(
stmt,
Settings.System.VOLUME_BLUETOOTH_SCO,
- AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
+ AudioService.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
// By default:
// - ringtones, notification, system and music streams are affected by ringer mode