Skip to content

Commit 33902db

Browse files
author
Eric Laurent
committed
AudioService: fix settings for fixed volume device
Force max volume for devices with fixed volume policy (HDMI, dock...) when reading the settings from DB. Otherwise, these devices would get the default volume which is not what we want. Also fix a problem related to ringer mode management when reloading the volume settings upon user switch that would cause a muted stream to be unmuted. Bug 7301563; Change-Id: I81cdb97125b845da584ed680181b93c7c1e5903f
1 parent 7711260 commit 33902db

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

media/java/android/media/AudioService.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,16 +1750,17 @@ private void readAudioSettings(boolean userSwitch) {
17501750
}
17511751
}
17521752

1753+
// apply new ringer mode before checking volume for alias streams so that streams
1754+
// muted by ringer mode have the correct volume
1755+
setRingerModeInt(getRingerMode(), false);
1756+
17531757
checkAllAliasStreamVolumes();
17541758

17551759
synchronized (mSafeMediaVolumeState) {
17561760
if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) {
17571761
enforceSafeMediaVolume();
17581762
}
17591763
}
1760-
1761-
// apply new ringer mode
1762-
setRingerModeInt(getRingerMode(), false);
17631764
}
17641765

17651766
/** @see AudioManager#setSpeakerphoneOn() */
@@ -2575,9 +2576,10 @@ private VolumeStreamState(String settingName, int streamType) {
25752576
AudioSystem.initStreamVolume(streamType, 0, mIndexMax);
25762577
mIndexMax *= 10;
25772578

2578-
readSettings();
2579-
2579+
// mDeathHandlers must be created before calling readSettings()
25802580
mDeathHandlers = new ArrayList<VolumeDeathHandler>();
2581+
2582+
readSettings();
25812583
}
25822584

25832585
public String getSettingNameForDevice(boolean lastAudible, int device) {
@@ -2597,7 +2599,9 @@ public synchronized void readSettings() {
25972599
// do not read system stream volume from settings: this stream is always aliased
25982600
// to another stream type and its volume is never persisted. Values in settings can
25992601
// only be stale values
2600-
if ((mStreamType == AudioSystem.STREAM_SYSTEM) ||
2602+
// on first call to readSettings() at init time, muteCount() is always 0 so we will
2603+
// always create entries for default device
2604+
if ((muteCount() == 0) && (mStreamType == AudioSystem.STREAM_SYSTEM) ||
26012605
(mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED)) {
26022606
mLastAudibleIndex.put(AudioSystem.DEVICE_OUT_DEFAULT,
26032607
10 * AudioManager.DEFAULT_STREAM_VOLUME[mStreamType]);
@@ -2613,6 +2617,14 @@ public synchronized void readSettings() {
26132617
}
26142618
remainingDevices &= ~device;
26152619

2620+
// ignore settings for fixed volume devices: volume should always be at max
2621+
if ((muteCount() == 0) &&
2622+
(mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC) &&
2623+
((device & mFixedVolumeDevices) != 0)) {
2624+
mIndex.put(device, mIndexMax);
2625+
mLastAudibleIndex.put(device, mIndexMax);
2626+
continue;
2627+
}
26162628
// retrieve current volume for device
26172629
String name = getSettingNameForDevice(false /* lastAudible */, device);
26182630
// if no volume stored for current stream and device, use default volume if default
@@ -2798,7 +2810,12 @@ public synchronized void setAllIndexes(VolumeStreamState srcStream, boolean last
27982810
int device = ((Integer)entry.getKey()).intValue();
27992811
int index = ((Integer)entry.getValue()).intValue();
28002812
index = rescaleIndex(index, srcStream.getStreamType(), mStreamType);
2801-
setIndex(index, device, lastAudible);
2813+
2814+
if (lastAudible) {
2815+
setLastAudibleIndex(index, device);
2816+
} else {
2817+
setIndex(index, device, false /* lastAudible */);
2818+
}
28022819
}
28032820
}
28042821

0 commit comments

Comments
 (0)