AudioService: do not persist mic mute and master mute

Master mute and mic mute are fully managed by user restrictions so there
is no need to persist their states.

Bug: 27486437
Change-Id: I7e58d1ddf409f6c80af371c7f5a5f305ee996386
This commit is contained in:
Eric Laurent
2016-03-15 18:19:23 -07:00
parent 3c8702dd81
commit c02324864f
2 changed files with 29 additions and 79 deletions

View File

@@ -2722,24 +2722,6 @@ public final class Settings {
*/
public static final String VOLUME_MASTER = "volume_master";
/**
* Master volume mute (int 1 = mute, 0 = not muted).
*
* @hide
*/
public static final String VOLUME_MASTER_MUTE = "volume_master_mute";
private static final Validator VOLUME_MASTER_MUTE_VALIDATOR = sBooleanValidator;
/**
* Microphone mute (int 1 = mute, 0 = not muted).
*
* @hide
*/
public static final String MICROPHONE_MUTE = "microphone_mute";
private static final Validator MICROPHONE_MUTE_VALIDATOR = sBooleanValidator;
/**
* Master mono (int 1 = mono, 0 = normal).
*
@@ -3530,8 +3512,6 @@ public final class Settings {
PRIVATE_SETTINGS.add(SCREEN_AUTO_BRIGHTNESS_ADJ);
PRIVATE_SETTINGS.add(VIBRATE_INPUT_DEVICES);
PRIVATE_SETTINGS.add(VOLUME_MASTER);
PRIVATE_SETTINGS.add(VOLUME_MASTER_MUTE);
PRIVATE_SETTINGS.add(MICROPHONE_MUTE);
PRIVATE_SETTINGS.add(MASTER_MONO);
PRIVATE_SETTINGS.add(NOTIFICATIONS_USE_RING_VOLUME);
PRIVATE_SETTINGS.add(VIBRATE_IN_SILENT);
@@ -3609,8 +3589,6 @@ public final class Settings {
VALIDATORS.put(ADVANCED_SETTINGS, ADVANCED_SETTINGS_VALIDATOR);
VALIDATORS.put(SCREEN_AUTO_BRIGHTNESS_ADJ, SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR);
VALIDATORS.put(VIBRATE_INPUT_DEVICES, VIBRATE_INPUT_DEVICES_VALIDATOR);
VALIDATORS.put(VOLUME_MASTER_MUTE, VOLUME_MASTER_MUTE_VALIDATOR);
VALIDATORS.put(MICROPHONE_MUTE, MICROPHONE_MUTE_VALIDATOR);
VALIDATORS.put(MASTER_MONO, MASTER_MONO_VALIDATOR);
VALIDATORS.put(NOTIFICATIONS_USE_RING_VOLUME, NOTIFICATIONS_USE_RING_VOLUME_VALIDATOR);
VALIDATORS.put(VIBRATE_IN_SILENT, VIBRATE_IN_SILENT_VALIDATOR);

View File

@@ -206,7 +206,6 @@ public class AudioService extends IAudioService.Stub {
private static final int MSG_SET_FORCE_USE = 8;
private static final int MSG_BT_HEADSET_CNCT_FAILED = 9;
private static final int MSG_SET_ALL_VOLUMES = 10;
private static final int MSG_PERSIST_MASTER_VOLUME_MUTE = 11;
private static final int MSG_REPORT_NEW_ROUTES = 12;
private static final int MSG_SET_FORCE_BT_A2DP_USE = 13;
private static final int MSG_CHECK_MUSIC_ACTIVE = 14;
@@ -218,7 +217,6 @@ public class AudioService extends IAudioService.Stub {
private static final int MSG_UNLOAD_SOUND_EFFECTS = 20;
private static final int MSG_SYSTEM_READY = 21;
private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = 22;
private static final int MSG_PERSIST_MICROPHONE_MUTE = 23;
private static final int MSG_UNMUTE_STREAM = 24;
private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25;
private static final int MSG_INDICATE_SYSTEM_READY = 26;
@@ -665,6 +663,7 @@ public class AudioService extends IAudioService.Stub {
// array initialized by updateStreamVolumeAlias()
updateStreamVolumeAlias(false /*updateVolumes*/, TAG);
readPersistedSettings();
readUserRestrictions();
mSettingsObserver = new SettingsObserver();
createStreamStates();
@@ -1109,35 +1108,6 @@ public class AudioService extends IAudioService.Stub {
System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED,
UserHandle.USER_CURRENT);
final int currentUser = getCurrentUserId();
// In addition to checking the system setting, also check the current user restriction.
// Because of the delay before persisting VOLUME_MASTER_MUTE, there's a window where
// DISALLOW_ADJUST_VOLUME will be ignored when it's set right before switching users.
boolean masterMute = (System.getIntForUser(cr, System.VOLUME_MASTER_MUTE,
0, UserHandle.USER_CURRENT) == 1)
|| mUserManagerInternal.getUserRestriction(
currentUser, UserManager.DISALLOW_ADJUST_VOLUME);
if (mUseFixedVolume) {
masterMute = false;
AudioSystem.setMasterVolume(1.0f);
}
if (DEBUG_VOL) {
Log.d(TAG, String.format("Master mute %s, user=%d", masterMute, currentUser));
}
setSystemAudioMute(masterMute);
AudioSystem.setMasterMute(masterMute);
broadcastMasterMuteStatus(masterMute);
boolean microphoneMute =
(System.getIntForUser(cr, System.MICROPHONE_MUTE, 0, UserHandle.USER_CURRENT) == 1)
|| mUserManagerInternal.getUserRestriction(
currentUser, UserManager.DISALLOW_UNMUTE_MICROPHONE);
if (DEBUG_VOL) {
Log.d(TAG, String.format("Mic mute %s, user=%d", microphoneMute, currentUser));
}
AudioSystem.muteMicrophone(microphoneMute);
updateMasterMono(cr);
// Each stream will read its own persisted settings
@@ -1154,6 +1124,31 @@ public class AudioService extends IAudioService.Stub {
mVolumeController.loadSettings(cr);
}
private void readUserRestrictions() {
final int currentUser = getCurrentUserId();
// Check the current user restriction.
boolean masterMute = mUserManagerInternal.getUserRestriction(
currentUser, UserManager.DISALLOW_ADJUST_VOLUME);
if (mUseFixedVolume) {
masterMute = false;
AudioSystem.setMasterVolume(1.0f);
}
if (DEBUG_VOL) {
Log.d(TAG, String.format("Master mute %s, user=%d", masterMute, currentUser));
}
setSystemAudioMute(masterMute);
AudioSystem.setMasterMute(masterMute);
broadcastMasterMuteStatus(masterMute);
boolean microphoneMute = mUserManagerInternal.getUserRestriction(
currentUser, UserManager.DISALLOW_UNMUTE_MICROPHONE);
if (DEBUG_VOL) {
Log.d(TAG, String.format("Mic mute %s, user=%d", microphoneMute, currentUser));
}
AudioSystem.muteMicrophone(microphoneMute);
}
private int rescaleIndex(int index, int srcStream, int dstStream) {
return (index * mStreamStates[dstStream].getMaxIndex() + mStreamStates[srcStream].getMaxIndex() / 2) / mStreamStates[srcStream].getMaxIndex();
}
@@ -1869,20 +1864,12 @@ public class AudioService extends IAudioService.Stub {
if (mute != AudioSystem.getMasterMute()) {
setSystemAudioMute(mute);
AudioSystem.setMasterMute(mute);
// Post a persist master volume msg
sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, mute ? 1
: 0, userId, null, PERSIST_DELAY);
sendMasterMuteUpdate(mute, flags);
Intent intent = new Intent(AudioManager.MASTER_MUTE_CHANGED_ACTION);
intent.putExtra(AudioManager.EXTRA_MASTER_VOLUME_MUTED, mute);
sendBroadcastToAll(intent);
}
} else {
// If not the current user just persist the setting which will be loaded
// on user switch.
sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, mute ? 1
: 0, userId, null, PERSIST_DELAY);
}
}
@@ -1975,8 +1962,6 @@ public class AudioService extends IAudioService.Stub {
AudioSystem.muteMicrophone(on);
}
// Post a persist microphone msg.
sendMsg(mAudioHandler, MSG_PERSIST_MICROPHONE_MUTE, SENDMSG_REPLACE, on ? 1
: 0, userId, null, PERSIST_DELAY);
}
@Override
@@ -2560,6 +2545,7 @@ public class AudioService extends IAudioService.Stub {
private void readAudioSettings(boolean userSwitch) {
// restore ringer mode, ringer mode affected streams, mute affected streams and vibrate settings
readPersistedSettings();
readUserRestrictions();
// restore volume settings
int numStreamTypes = AudioSystem.getNumStreamTypes();
@@ -4492,16 +4478,6 @@ public class AudioService extends IAudioService.Stub {
persistVolume((VolumeStreamState) msg.obj, msg.arg1);
break;
case MSG_PERSIST_MASTER_VOLUME_MUTE:
if (mUseFixedVolume) {
return;
}
Settings.System.putIntForUser(mContentResolver,
Settings.System.VOLUME_MASTER_MUTE,
msg.arg1,
msg.arg2);
break;
case MSG_PERSIST_RINGER_MODE:
// note that the value persisted is the current ringer mode, not the
// value of ringer mode as of the time the request was made to persist
@@ -4624,15 +4600,11 @@ public class AudioService extends IAudioService.Stub {
Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs,
UserHandle.USER_CURRENT);
break;
case MSG_PERSIST_MICROPHONE_MUTE:
Settings.System.putIntForUser(mContentResolver,
Settings.System.MICROPHONE_MUTE,
msg.arg1,
msg.arg2);
break;
case MSG_UNMUTE_STREAM:
onUnmuteStream(msg.arg1, msg.arg2);
break;
case MSG_DYN_POLICY_MIX_STATE_UPDATE:
onDynPolicyMixStateUpdate((String) msg.obj, msg.arg1);
break;