Merge "AudioService: do not persist mic mute and master mute" into nyc-dev

This commit is contained in:
Eric Laurent
2016-03-16 21:09:29 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 79 deletions

View File

@@ -2707,24 +2707,6 @@ public final class Settings {
*/ */
public static final String VOLUME_MASTER = "volume_master"; 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). * Master mono (int 1 = mono, 0 = normal).
* *
@@ -3515,8 +3497,6 @@ public final class Settings {
PRIVATE_SETTINGS.add(SCREEN_AUTO_BRIGHTNESS_ADJ); PRIVATE_SETTINGS.add(SCREEN_AUTO_BRIGHTNESS_ADJ);
PRIVATE_SETTINGS.add(VIBRATE_INPUT_DEVICES); PRIVATE_SETTINGS.add(VIBRATE_INPUT_DEVICES);
PRIVATE_SETTINGS.add(VOLUME_MASTER); PRIVATE_SETTINGS.add(VOLUME_MASTER);
PRIVATE_SETTINGS.add(VOLUME_MASTER_MUTE);
PRIVATE_SETTINGS.add(MICROPHONE_MUTE);
PRIVATE_SETTINGS.add(MASTER_MONO); PRIVATE_SETTINGS.add(MASTER_MONO);
PRIVATE_SETTINGS.add(NOTIFICATIONS_USE_RING_VOLUME); PRIVATE_SETTINGS.add(NOTIFICATIONS_USE_RING_VOLUME);
PRIVATE_SETTINGS.add(VIBRATE_IN_SILENT); PRIVATE_SETTINGS.add(VIBRATE_IN_SILENT);
@@ -3594,8 +3574,6 @@ public final class Settings {
VALIDATORS.put(ADVANCED_SETTINGS, ADVANCED_SETTINGS_VALIDATOR); VALIDATORS.put(ADVANCED_SETTINGS, ADVANCED_SETTINGS_VALIDATOR);
VALIDATORS.put(SCREEN_AUTO_BRIGHTNESS_ADJ, SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR); VALIDATORS.put(SCREEN_AUTO_BRIGHTNESS_ADJ, SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR);
VALIDATORS.put(VIBRATE_INPUT_DEVICES, VIBRATE_INPUT_DEVICES_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(MASTER_MONO, MASTER_MONO_VALIDATOR);
VALIDATORS.put(NOTIFICATIONS_USE_RING_VOLUME, NOTIFICATIONS_USE_RING_VOLUME_VALIDATOR); VALIDATORS.put(NOTIFICATIONS_USE_RING_VOLUME, NOTIFICATIONS_USE_RING_VOLUME_VALIDATOR);
VALIDATORS.put(VIBRATE_IN_SILENT, VIBRATE_IN_SILENT_VALIDATOR); VALIDATORS.put(VIBRATE_IN_SILENT, VIBRATE_IN_SILENT_VALIDATOR);

View File

@@ -205,7 +205,6 @@ public class AudioService extends IAudioService.Stub {
private static final int MSG_SET_FORCE_USE = 8; private static final int MSG_SET_FORCE_USE = 8;
private static final int MSG_BT_HEADSET_CNCT_FAILED = 9; private static final int MSG_BT_HEADSET_CNCT_FAILED = 9;
private static final int MSG_SET_ALL_VOLUMES = 10; 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_REPORT_NEW_ROUTES = 12;
private static final int MSG_SET_FORCE_BT_A2DP_USE = 13; private static final int MSG_SET_FORCE_BT_A2DP_USE = 13;
private static final int MSG_CHECK_MUSIC_ACTIVE = 14; private static final int MSG_CHECK_MUSIC_ACTIVE = 14;
@@ -217,7 +216,6 @@ public class AudioService extends IAudioService.Stub {
private static final int MSG_UNLOAD_SOUND_EFFECTS = 20; private static final int MSG_UNLOAD_SOUND_EFFECTS = 20;
private static final int MSG_SYSTEM_READY = 21; private static final int MSG_SYSTEM_READY = 21;
private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = 22; 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_UNMUTE_STREAM = 24;
private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25; private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25;
private static final int MSG_INDICATE_SYSTEM_READY = 26; private static final int MSG_INDICATE_SYSTEM_READY = 26;
@@ -665,6 +663,7 @@ public class AudioService extends IAudioService.Stub {
// array initialized by updateStreamVolumeAlias() // array initialized by updateStreamVolumeAlias()
updateStreamVolumeAlias(false /*updateVolumes*/, TAG); updateStreamVolumeAlias(false /*updateVolumes*/, TAG);
readPersistedSettings(); readPersistedSettings();
readUserRestrictions();
mSettingsObserver = new SettingsObserver(); mSettingsObserver = new SettingsObserver();
createStreamStates(); createStreamStates();
@@ -1111,35 +1110,6 @@ public class AudioService extends IAudioService.Stub {
System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED, System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED,
UserHandle.USER_CURRENT); 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); updateMasterMono(cr);
// Each stream will read its own persisted settings // Each stream will read its own persisted settings
@@ -1156,6 +1126,31 @@ public class AudioService extends IAudioService.Stub {
mVolumeController.loadSettings(cr); 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) { private int rescaleIndex(int index, int srcStream, int dstStream) {
return (index * mStreamStates[dstStream].getMaxIndex() + mStreamStates[srcStream].getMaxIndex() / 2) / mStreamStates[srcStream].getMaxIndex(); return (index * mStreamStates[dstStream].getMaxIndex() + mStreamStates[srcStream].getMaxIndex() / 2) / mStreamStates[srcStream].getMaxIndex();
} }
@@ -1911,20 +1906,12 @@ public class AudioService extends IAudioService.Stub {
if (mute != AudioSystem.getMasterMute()) { if (mute != AudioSystem.getMasterMute()) {
setSystemAudioMute(mute); setSystemAudioMute(mute);
AudioSystem.setMasterMute(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); sendMasterMuteUpdate(mute, flags);
Intent intent = new Intent(AudioManager.MASTER_MUTE_CHANGED_ACTION); Intent intent = new Intent(AudioManager.MASTER_MUTE_CHANGED_ACTION);
intent.putExtra(AudioManager.EXTRA_MASTER_VOLUME_MUTED, mute); intent.putExtra(AudioManager.EXTRA_MASTER_VOLUME_MUTED, mute);
sendBroadcastToAll(intent); 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);
} }
} }
@@ -2017,8 +2004,6 @@ public class AudioService extends IAudioService.Stub {
AudioSystem.muteMicrophone(on); AudioSystem.muteMicrophone(on);
} }
// Post a persist microphone msg. // Post a persist microphone msg.
sendMsg(mAudioHandler, MSG_PERSIST_MICROPHONE_MUTE, SENDMSG_REPLACE, on ? 1
: 0, userId, null, PERSIST_DELAY);
} }
@Override @Override
@@ -2607,6 +2592,7 @@ public class AudioService extends IAudioService.Stub {
private void readAudioSettings(boolean userSwitch) { private void readAudioSettings(boolean userSwitch) {
// restore ringer mode, ringer mode affected streams, mute affected streams and vibrate settings // restore ringer mode, ringer mode affected streams, mute affected streams and vibrate settings
readPersistedSettings(); readPersistedSettings();
readUserRestrictions();
// restore volume settings // restore volume settings
int numStreamTypes = AudioSystem.getNumStreamTypes(); int numStreamTypes = AudioSystem.getNumStreamTypes();
@@ -4545,16 +4531,6 @@ public class AudioService extends IAudioService.Stub {
persistVolume((VolumeStreamState) msg.obj, msg.arg1); persistVolume((VolumeStreamState) msg.obj, msg.arg1);
break; 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: case MSG_PERSIST_RINGER_MODE:
// note that the value persisted is the current ringer mode, not the // 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 // value of ringer mode as of the time the request was made to persist
@@ -4677,15 +4653,11 @@ public class AudioService extends IAudioService.Stub {
Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs, Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
break; break;
case MSG_PERSIST_MICROPHONE_MUTE:
Settings.System.putIntForUser(mContentResolver,
Settings.System.MICROPHONE_MUTE,
msg.arg1,
msg.arg2);
break;
case MSG_UNMUTE_STREAM: case MSG_UNMUTE_STREAM:
onUnmuteStream(msg.arg1, msg.arg2); onUnmuteStream(msg.arg1, msg.arg2);
break; break;
case MSG_DYN_POLICY_MIX_STATE_UPDATE: case MSG_DYN_POLICY_MIX_STATE_UPDATE:
onDynPolicyMixStateUpdate((String) msg.obj, msg.arg1); onDynPolicyMixStateUpdate((String) msg.obj, msg.arg1);
break; break;