AudioService: fix system stream muted by restore
Releases prior ICS (included) would persist the stream volumes in the database when muted by silent mode. If the DB was backed up while in silent mode, stream volume was backed up at 0. When restored on a new device, the volume was restored at 0 which was a problem for SYSTEM stream because it would never be corrected as this stream volume is fixed. Added a check on valid volume values when reading settings from the DB and correct the DB if this happens. Change-Id: Ie3b98eb74e10413c22aab7568b83ac3ace5bfc07
This commit is contained in:
@@ -2035,20 +2035,11 @@ public class AudioService extends IAudioService.Stub {
|
||||
}
|
||||
|
||||
public void readSettings() {
|
||||
int index = Settings.System.getInt(mContentResolver,
|
||||
mVolumeIndexSettingName,
|
||||
AudioManager.DEFAULT_STREAM_VOLUME[mStreamType]);
|
||||
|
||||
mIndex.clear();
|
||||
mIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, index);
|
||||
|
||||
index = Settings.System.getInt(mContentResolver,
|
||||
mLastAudibleVolumeIndexSettingName,
|
||||
(index > 0) ? index : AudioManager.DEFAULT_STREAM_VOLUME[mStreamType]);
|
||||
mLastAudibleIndex.clear();
|
||||
mLastAudibleIndex.put(AudioSystem.DEVICE_OUT_DEFAULT, index);
|
||||
boolean checkSilentVolume = (mRingerMode == AudioManager.RINGER_MODE_NORMAL) &&
|
||||
isStreamAffectedByRingerMode(mStreamType);
|
||||
|
||||
int remainingDevices = AudioSystem.DEVICE_OUT_ALL;
|
||||
|
||||
for (int i = 0; remainingDevices != 0; i++) {
|
||||
int device = (1 << i);
|
||||
if ((device & remainingDevices) == 0) {
|
||||
@@ -2057,17 +2048,58 @@ public class AudioService extends IAudioService.Stub {
|
||||
remainingDevices &= ~device;
|
||||
|
||||
// retrieve current volume for device
|
||||
String name = getSettingNameForDevice(false, device);
|
||||
index = Settings.System.getInt(mContentResolver, name, -1);
|
||||
String name = getSettingNameForDevice(false /* lastAudible */, device);
|
||||
// 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;
|
||||
int index = Settings.System.getInt(mContentResolver, name, defaultIndex);
|
||||
if (index == -1) {
|
||||
continue;
|
||||
}
|
||||
mIndex.put(device, getValidIndex(10 * index));
|
||||
|
||||
// retrieve last audible volume for device
|
||||
name = getSettingNameForDevice(true, device);
|
||||
index = Settings.System.getInt(mContentResolver, name, -1);
|
||||
mLastAudibleIndex.put(device, getValidIndex(10 * index));
|
||||
name = getSettingNameForDevice(true /* lastAudible */, device);
|
||||
// use stored last audible index if present, otherwise use current index if not 0
|
||||
// or default index
|
||||
defaultIndex = (index > 0) ?
|
||||
index : AudioManager.DEFAULT_STREAM_VOLUME[mStreamType];
|
||||
int lastAudibleIndex = Settings.System.getInt(mContentResolver, name, defaultIndex);
|
||||
|
||||
// a last audible index of 0 is never stored, except on non-voice capable devices
|
||||
// (e.g. tablets) for the music stream type, where the music stream volume can reach
|
||||
// 0 without the device being in silent mode
|
||||
if ((lastAudibleIndex == 0) &&
|
||||
(mVoiceCapable ||
|
||||
(STREAM_VOLUME_ALIAS[mStreamType] != AudioSystem.STREAM_MUSIC))) {
|
||||
lastAudibleIndex = AudioManager.DEFAULT_STREAM_VOLUME[mStreamType];
|
||||
// Correct the data base
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_PERSIST_VOLUME,
|
||||
SENDMSG_QUEUE,
|
||||
PERSIST_LAST_AUDIBLE,
|
||||
device,
|
||||
this,
|
||||
PERSIST_DELAY);
|
||||
}
|
||||
mLastAudibleIndex.put(device, getValidIndex(10 * lastAudibleIndex));
|
||||
// the initial index should never be 0 for a stream affected by ringer mode if not
|
||||
// in silent or vibrate mode.
|
||||
// this is permitted on tablets for music stream type.
|
||||
if (checkSilentVolume && (index == 0) &&
|
||||
(mVoiceCapable ||
|
||||
(STREAM_VOLUME_ALIAS[mStreamType] != AudioSystem.STREAM_MUSIC))) {
|
||||
index = lastAudibleIndex;
|
||||
// Correct the data base
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_PERSIST_VOLUME,
|
||||
SENDMSG_QUEUE,
|
||||
PERSIST_CURRENT,
|
||||
device,
|
||||
this,
|
||||
PERSIST_DELAY);
|
||||
}
|
||||
mIndex.put(device, getValidIndex(10 * index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -279,6 +279,7 @@ public class AudioSystem
|
||||
return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME;
|
||||
case DEVICE_OUT_DGTL_DOCK_HEADSET:
|
||||
return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME;
|
||||
case DEVICE_IN_DEFAULT:
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user