Merge "AudioService: default volume group is not restored"
This commit is contained in:
@@ -1230,10 +1230,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
private void updateDefaultVolumes() {
|
private void updateDefaultVolumes() {
|
||||||
for (int stream = 0; stream < mStreamStates.length; stream++) {
|
for (int stream = 0; stream < mStreamStates.length; stream++) {
|
||||||
if (stream != mStreamVolumeAlias[stream]) {
|
if (stream != mStreamVolumeAlias[stream]) {
|
||||||
AudioSystem.DEFAULT_STREAM_VOLUME[stream] = rescaleIndex(
|
AudioSystem.DEFAULT_STREAM_VOLUME[stream] = (rescaleIndex(
|
||||||
AudioSystem.DEFAULT_STREAM_VOLUME[mStreamVolumeAlias[stream]],
|
AudioSystem.DEFAULT_STREAM_VOLUME[mStreamVolumeAlias[stream]] * 10,
|
||||||
mStreamVolumeAlias[stream],
|
mStreamVolumeAlias[stream],
|
||||||
stream);
|
stream) + 5) / 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4481,7 +4481,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Volume Groups without attributes are not controllable through set/get volume
|
// Volume Groups without attributes are not controllable through set/get volume
|
||||||
// using attributes. Do not append them.
|
// using attributes. Do not append them.
|
||||||
Log.d(TAG, "volume group " + avg.name() + " for internal policy needs");
|
if (DEBUG_VOL) {
|
||||||
|
Log.v(TAG, "volume group " + avg.name() + " for internal policy needs");
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sVolumeGroupStates.append(avg.getId(), new VolumeGroupState(avg));
|
sVolumeGroupStates.append(avg.getId(), new VolumeGroupState(avg));
|
||||||
@@ -4502,7 +4504,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void readVolumeGroupsSettings() {
|
private void readVolumeGroupsSettings() {
|
||||||
Log.v(TAG, "readVolumeGroupsSettings");
|
if (DEBUG_VOL) {
|
||||||
|
Log.v(TAG, "readVolumeGroupsSettings.");
|
||||||
|
}
|
||||||
for (int i = 0; i < sVolumeGroupStates.size(); i++) {
|
for (int i = 0; i < sVolumeGroupStates.size(); i++) {
|
||||||
final VolumeGroupState vgs = sVolumeGroupStates.valueAt(i);
|
final VolumeGroupState vgs = sVolumeGroupStates.valueAt(i);
|
||||||
vgs.readSettings();
|
vgs.readSettings();
|
||||||
@@ -4512,7 +4516,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
// Called upon crash of AudioServer
|
// Called upon crash of AudioServer
|
||||||
private void restoreVolumeGroups() {
|
private void restoreVolumeGroups() {
|
||||||
Log.v(TAG, "restoreVolumeGroups");
|
if (DEBUG_VOL) {
|
||||||
|
Log.v(TAG, "restoreVolumeGroups");
|
||||||
|
}
|
||||||
for (int i = 0; i < sVolumeGroupStates.size(); i++) {
|
for (int i = 0; i < sVolumeGroupStates.size(); i++) {
|
||||||
final VolumeGroupState vgs = sVolumeGroupStates.valueAt(i);
|
final VolumeGroupState vgs = sVolumeGroupStates.valueAt(i);
|
||||||
vgs.applyAllVolumes();
|
vgs.applyAllVolumes();
|
||||||
@@ -4548,7 +4554,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
private VolumeGroupState(AudioVolumeGroup avg) {
|
private VolumeGroupState(AudioVolumeGroup avg) {
|
||||||
mAudioVolumeGroup = avg;
|
mAudioVolumeGroup = avg;
|
||||||
Log.v(TAG, "VolumeGroupState for " + avg.toString());
|
if (DEBUG_VOL) {
|
||||||
|
Log.v(TAG, "VolumeGroupState for " + avg.toString());
|
||||||
|
}
|
||||||
for (final AudioAttributes aa : avg.getAudioAttributes()) {
|
for (final AudioAttributes aa : avg.getAudioAttributes()) {
|
||||||
if (!aa.equals(AudioProductStrategy.sDefaultAttributes)) {
|
if (!aa.equals(AudioProductStrategy.sDefaultAttributes)) {
|
||||||
mAudioAttributes = aa;
|
mAudioAttributes = aa;
|
||||||
@@ -4643,11 +4651,19 @@ public class AudioService extends IAudioService.Stub
|
|||||||
return mIndexMin;
|
return mIndexMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidLegacyStreamType() {
|
||||||
|
return (mLegacyStreamType != AudioSystem.STREAM_DEFAULT)
|
||||||
|
&& (mLegacyStreamType < mStreamStates.length);
|
||||||
|
}
|
||||||
|
|
||||||
public void applyAllVolumes() {
|
public void applyAllVolumes() {
|
||||||
synchronized (VolumeGroupState.class) {
|
synchronized (VolumeGroupState.class) {
|
||||||
if (mLegacyStreamType != AudioSystem.STREAM_DEFAULT) {
|
int deviceForStream = AudioSystem.DEVICE_NONE;
|
||||||
// No-op to avoid regression with stream based volume management
|
int volumeIndexForStream = 0;
|
||||||
return;
|
if (isValidLegacyStreamType()) {
|
||||||
|
// Prevent to apply settings twice when group is associated to public stream
|
||||||
|
deviceForStream = getDeviceForStream(mLegacyStreamType);
|
||||||
|
volumeIndexForStream = getStreamVolume(mLegacyStreamType);
|
||||||
}
|
}
|
||||||
// apply device specific volumes first
|
// apply device specific volumes first
|
||||||
int index;
|
int index;
|
||||||
@@ -4655,16 +4671,30 @@ public class AudioService extends IAudioService.Stub
|
|||||||
final int device = mIndexMap.keyAt(i);
|
final int device = mIndexMap.keyAt(i);
|
||||||
if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
|
if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
|
||||||
index = mIndexMap.valueAt(i);
|
index = mIndexMap.valueAt(i);
|
||||||
Log.v(TAG, "applyAllVolumes: restore index " + index + " for group "
|
if (device == deviceForStream && volumeIndexForStream == index) {
|
||||||
+ mAudioVolumeGroup.name() + " and device "
|
continue;
|
||||||
+ AudioSystem.getOutputDeviceName(device));
|
}
|
||||||
|
if (DEBUG_VOL) {
|
||||||
|
Log.v(TAG, "applyAllVolumes: restore index " + index + " for group "
|
||||||
|
+ mAudioVolumeGroup.name() + " and device "
|
||||||
|
+ AudioSystem.getOutputDeviceName(device));
|
||||||
|
}
|
||||||
setVolumeIndexInt(index, device, 0 /*flags*/);
|
setVolumeIndexInt(index, device, 0 /*flags*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// apply default volume last: by convention , default device volume will be used
|
// apply default volume last: by convention , default device volume will be used
|
||||||
index = getIndex(AudioSystem.DEVICE_OUT_DEFAULT);
|
index = getIndex(AudioSystem.DEVICE_OUT_DEFAULT);
|
||||||
Log.v(TAG, "applyAllVolumes: restore default device index " + index + " for group "
|
if (DEBUG_VOL) {
|
||||||
+ mAudioVolumeGroup.name());
|
Log.v(TAG, "applyAllVolumes: restore default device index " + index
|
||||||
|
+ " for group " + mAudioVolumeGroup.name());
|
||||||
|
}
|
||||||
|
if (isValidLegacyStreamType()) {
|
||||||
|
int defaultStreamIndex = (mStreamStates[mLegacyStreamType]
|
||||||
|
.getIndex(AudioSystem.DEVICE_OUT_DEFAULT) + 5) / 10;
|
||||||
|
if (defaultStreamIndex == index) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
setVolumeIndexInt(index, AudioSystem.DEVICE_OUT_DEFAULT, 0 /*flags*/);
|
setVolumeIndexInt(index, AudioSystem.DEVICE_OUT_DEFAULT, 0 /*flags*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4673,9 +4703,12 @@ public class AudioService extends IAudioService.Stub
|
|||||||
if (mUseFixedVolume) {
|
if (mUseFixedVolume) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.v(TAG, "persistVolumeGroup: storing index " + getIndex(device) + " for group "
|
if (DEBUG_VOL) {
|
||||||
+ mAudioVolumeGroup.name() + " and device "
|
Log.v(TAG, "persistVolumeGroup: storing index " + getIndex(device) + " for group "
|
||||||
+ AudioSystem.getOutputDeviceName(device));
|
+ mAudioVolumeGroup.name()
|
||||||
|
+ ", device " + AudioSystem.getOutputDeviceName(device)
|
||||||
|
+ " and User=" + ActivityManager.getCurrentUser());
|
||||||
|
}
|
||||||
boolean success = Settings.System.putIntForUser(mContentResolver,
|
boolean success = Settings.System.putIntForUser(mContentResolver,
|
||||||
getSettingNameForDevice(device),
|
getSettingNameForDevice(device),
|
||||||
getIndex(device),
|
getIndex(device),
|
||||||
@@ -4705,12 +4738,18 @@ public class AudioService extends IAudioService.Stub
|
|||||||
index = Settings.System.getIntForUser(
|
index = Settings.System.getIntForUser(
|
||||||
mContentResolver, name, defaultIndex, UserHandle.USER_CURRENT);
|
mContentResolver, name, defaultIndex, UserHandle.USER_CURRENT);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
Log.e(TAG, "readSettings: No index stored for group "
|
if (DEBUG_VOL) {
|
||||||
+ mAudioVolumeGroup.name() + ", device " + name);
|
Log.e(TAG, "readSettings: No index stored for group "
|
||||||
|
+ mAudioVolumeGroup.name() + ", device " + name
|
||||||
|
+ ", User=" + ActivityManager.getCurrentUser());
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.v(TAG, "readSettings: found stored index " + getValidIndex(index)
|
if (DEBUG_VOL) {
|
||||||
+ " for group " + mAudioVolumeGroup.name() + ", device: " + name);
|
Log.v(TAG, "readSettings: found stored index " + getValidIndex(index)
|
||||||
|
+ " for group " + mAudioVolumeGroup.name() + ", device: " + name
|
||||||
|
+ ", User=" + ActivityManager.getCurrentUser());
|
||||||
|
}
|
||||||
mIndexMap.put(device, getValidIndex(index));
|
mIndexMap.put(device, getValidIndex(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user