Skip to content

Commit 7ef9743

Browse files
Eric LaurentAndroid (Google) Code Review
authored andcommitted
Merge "AudioService: fix system stream muted by restore"
2 parents 2d5ddd1 + 9ac8d0c commit 7ef9743

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

media/java/android/media/AudioService.java

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,20 +2035,11 @@ public String getSettingNameForDevice(boolean lastAudible, int device) {
20352035
}
20362036

20372037
public void readSettings() {
2038-
int index = Settings.System.getInt(mContentResolver,
2039-
mVolumeIndexSettingName,
2040-
AudioManager.DEFAULT_STREAM_VOLUME[mStreamType]);
2041-
2042-
mIndex.clear();
2043-
mIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, index);
2044-
2045-
index = Settings.System.getInt(mContentResolver,
2046-
mLastAudibleVolumeIndexSettingName,
2047-
(index > 0) ? index : AudioManager.DEFAULT_STREAM_VOLUME[mStreamType]);
2048-
mLastAudibleIndex.clear();
2049-
mLastAudibleIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, index);
2038+
boolean checkSilentVolume = (mRingerMode == AudioManager.RINGER_MODE_NORMAL) &&
2039+
isStreamAffectedByRingerMode(mStreamType);
20502040

20512041
int remainingDevices = AudioSystem.DEVICE_OUT_ALL;
2042+
20522043
for (int i = 0; remainingDevices != 0; i++) {
20532044
int device = (1 << i);
20542045
if ((device & remainingDevices) == 0) {
@@ -2057,17 +2048,58 @@ public void readSettings() {
20572048
remainingDevices &= ~device;
20582049

20592050
// retrieve current volume for device
2060-
String name = getSettingNameForDevice(false, device);
2061-
index = Settings.System.getInt(mContentResolver, name, -1);
2051+
String name = getSettingNameForDevice(false /* lastAudible */, device);
2052+
// if no volume stored for current stream and device, use default volume if default
2053+
// device, continue otherwise
2054+
int defaultIndex = (device == AudioSystem.DEVICE_OUT_DEFAULT) ?
2055+
AudioManager.DEFAULT_STREAM_VOLUME[mStreamType] : -1;
2056+
int index = Settings.System.getInt(mContentResolver, name, defaultIndex);
20622057
if (index == -1) {
20632058
continue;
20642059
}
2065-
mIndex.put(device, getValidIndex(10 * index));
20662060

20672061
// retrieve last audible volume for device
2068-
name = getSettingNameForDevice(true, device);
2069-
index = Settings.System.getInt(mContentResolver, name, -1);
2070-
mLastAudibleIndex.put(device, getValidIndex(10 * index));
2062+
name = getSettingNameForDevice(true /* lastAudible */, device);
2063+
// use stored last audible index if present, otherwise use current index if not 0
2064+
// or default index
2065+
defaultIndex = (index > 0) ?
2066+
index : AudioManager.DEFAULT_STREAM_VOLUME[mStreamType];
2067+
int lastAudibleIndex = Settings.System.getInt(mContentResolver, name, defaultIndex);
2068+
2069+
// a last audible index of 0 is never stored, except on non-voice capable devices
2070+
// (e.g. tablets) for the music stream type, where the music stream volume can reach
2071+
// 0 without the device being in silent mode
2072+
if ((lastAudibleIndex == 0) &&
2073+
(mVoiceCapable ||
2074+
(STREAM_VOLUME_ALIAS[mStreamType] != AudioSystem.STREAM_MUSIC))) {
2075+
lastAudibleIndex = AudioManager.DEFAULT_STREAM_VOLUME[mStreamType];
2076+
// Correct the data base
2077+
sendMsg(mAudioHandler,
2078+
MSG_PERSIST_VOLUME,
2079+
SENDMSG_QUEUE,
2080+
PERSIST_LAST_AUDIBLE,
2081+
device,
2082+
this,
2083+
PERSIST_DELAY);
2084+
}
2085+
mLastAudibleIndex.put(device, getValidIndex(10 * lastAudibleIndex));
2086+
// the initial index should never be 0 for a stream affected by ringer mode if not
2087+
// in silent or vibrate mode.
2088+
// this is permitted on tablets for music stream type.
2089+
if (checkSilentVolume && (index == 0) &&
2090+
(mVoiceCapable ||
2091+
(STREAM_VOLUME_ALIAS[mStreamType] != AudioSystem.STREAM_MUSIC))) {
2092+
index = lastAudibleIndex;
2093+
// Correct the data base
2094+
sendMsg(mAudioHandler,
2095+
MSG_PERSIST_VOLUME,
2096+
SENDMSG_QUEUE,
2097+
PERSIST_CURRENT,
2098+
device,
2099+
this,
2100+
PERSIST_DELAY);
2101+
}
2102+
mIndex.put(device, getValidIndex(10 * index));
20712103
}
20722104
}
20732105

media/java/android/media/AudioSystem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public static String getDeviceName(int device)
279279
return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME;
280280
case DEVICE_OUT_DGTL_DOCK_HEADSET:
281281
return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME;
282+
case DEVICE_IN_DEFAULT:
282283
default:
283284
return "";
284285
}

0 commit comments

Comments
 (0)