Loading services/core/java/com/android/server/notification/ZenModeHelper.java +17 −6 Original line number Diff line number Diff line Loading @@ -874,7 +874,14 @@ public class ZenModeHelper { } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_MEDIA) { applyRestrictions(muteMedia || muteEverything, usage); } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_SYSTEM) { if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { // normally DND will only restrict touch sounds, not haptic feedback/vibrations applyRestrictions(muteSystem || muteEverything, usage, AppOpsManager.OP_PLAY_AUDIO); applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE); } else { applyRestrictions(muteSystem || muteEverything, usage); } } else { applyRestrictions(muteEverything, usage); } Loading @@ -883,17 +890,21 @@ public class ZenModeHelper { @VisibleForTesting protected void applyRestrictions(boolean mute, int usage) { protected void applyRestrictions(boolean mute, int usage, int code) { final String[] exceptionPackages = null; // none (for now) mAppOps.setRestriction(AppOpsManager.OP_VIBRATE, usage, mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, exceptionPackages); mAppOps.setRestriction(AppOpsManager.OP_PLAY_AUDIO, usage, mAppOps.setRestriction(code, usage, mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, exceptionPackages); } @VisibleForTesting protected void applyRestrictions(boolean mute, int usage) { applyRestrictions(mute, usage, AppOpsManager.OP_VIBRATE); applyRestrictions(mute, usage, AppOpsManager.OP_PLAY_AUDIO); } @VisibleForTesting protected void applyZenToRingerMode() { if (mAudioManager == null) return; Loading services/core/java/com/android/server/power/Notifier.java +4 −1 Original line number Diff line number Diff line Loading @@ -720,9 +720,12 @@ final class Notifier { private void playChargingStartedSound() { final boolean enabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.CHARGING_SOUNDS_ENABLED, 1) != 0; final boolean dndOff = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) == Settings.Global.ZEN_MODE_OFF; final String soundPath = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.CHARGING_STARTED_SOUND); if (enabled && soundPath != null) { if (enabled && dndOff && soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +35 −5 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.AppOpsManager; import android.app.NotificationManager; import android.content.ComponentName; import android.content.ContentResolver; Loading Loading @@ -159,6 +160,26 @@ public class ZenModeHelperTest extends UiServiceTestCase { AudioAttributes.USAGE_GAME); } @Test public void testTotalSilence() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_NO_INTERRUPTIONS; mZenModeHelperSpy.applyRestrictions(); // Total silence will silence alarms, media and system noises (but not vibrations) verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ALARM); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_MEDIA); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_GAME); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_VIBRATE); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_UNKNOWN); } @Test public void testAlarmsOnly_alarmMediaMuteNotApplied() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_ALARMS; Loading @@ -179,9 +200,9 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, AudioAttributes.USAGE_GAME); // Alarms only will silence system noises // Alarms only will silence system noises (but not vibrations) verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION); AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_UNKNOWN); } Loading Loading @@ -228,6 +249,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { @Test public void testZenAllCannotBypass() { // Only audio attributes with SUPPRESIBLE_NEVER can bypass // with special case USAGE_ASSISTANCE_SONIFICATION mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; mZenModeHelperSpy.mConfig.allowAlarms = false; mZenModeHelperSpy.mConfig.allowMedia = false; Loading @@ -247,11 +269,19 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelperSpy.applyRestrictions(); for (int usage : AudioAttributes.SDK_USAGES) { if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { // only mute audio, not vibrations verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, usage, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE); } else { boolean shouldMute = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage) != AudioAttributes.SUPPRESSIBLE_NEVER; verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(shouldMute, usage); } } } @Test public void testZenUpgradeNotification() { Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +17 −6 Original line number Diff line number Diff line Loading @@ -874,7 +874,14 @@ public class ZenModeHelper { } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_MEDIA) { applyRestrictions(muteMedia || muteEverything, usage); } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_SYSTEM) { if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { // normally DND will only restrict touch sounds, not haptic feedback/vibrations applyRestrictions(muteSystem || muteEverything, usage, AppOpsManager.OP_PLAY_AUDIO); applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE); } else { applyRestrictions(muteSystem || muteEverything, usage); } } else { applyRestrictions(muteEverything, usage); } Loading @@ -883,17 +890,21 @@ public class ZenModeHelper { @VisibleForTesting protected void applyRestrictions(boolean mute, int usage) { protected void applyRestrictions(boolean mute, int usage, int code) { final String[] exceptionPackages = null; // none (for now) mAppOps.setRestriction(AppOpsManager.OP_VIBRATE, usage, mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, exceptionPackages); mAppOps.setRestriction(AppOpsManager.OP_PLAY_AUDIO, usage, mAppOps.setRestriction(code, usage, mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, exceptionPackages); } @VisibleForTesting protected void applyRestrictions(boolean mute, int usage) { applyRestrictions(mute, usage, AppOpsManager.OP_VIBRATE); applyRestrictions(mute, usage, AppOpsManager.OP_PLAY_AUDIO); } @VisibleForTesting protected void applyZenToRingerMode() { if (mAudioManager == null) return; Loading
services/core/java/com/android/server/power/Notifier.java +4 −1 Original line number Diff line number Diff line Loading @@ -720,9 +720,12 @@ final class Notifier { private void playChargingStartedSound() { final boolean enabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.CHARGING_SOUNDS_ENABLED, 1) != 0; final boolean dndOff = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) == Settings.Global.ZEN_MODE_OFF; final String soundPath = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.CHARGING_STARTED_SOUND); if (enabled && soundPath != null) { if (enabled && dndOff && soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +35 −5 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.AppOpsManager; import android.app.NotificationManager; import android.content.ComponentName; import android.content.ContentResolver; Loading Loading @@ -159,6 +160,26 @@ public class ZenModeHelperTest extends UiServiceTestCase { AudioAttributes.USAGE_GAME); } @Test public void testTotalSilence() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_NO_INTERRUPTIONS; mZenModeHelperSpy.applyRestrictions(); // Total silence will silence alarms, media and system noises (but not vibrations) verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ALARM); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_MEDIA); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_GAME); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_VIBRATE); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_UNKNOWN); } @Test public void testAlarmsOnly_alarmMediaMuteNotApplied() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_ALARMS; Loading @@ -179,9 +200,9 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, AudioAttributes.USAGE_GAME); // Alarms only will silence system noises // Alarms only will silence system noises (but not vibrations) verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_ASSISTANCE_SONIFICATION); AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, AudioAttributes.USAGE_UNKNOWN); } Loading Loading @@ -228,6 +249,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { @Test public void testZenAllCannotBypass() { // Only audio attributes with SUPPRESIBLE_NEVER can bypass // with special case USAGE_ASSISTANCE_SONIFICATION mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; mZenModeHelperSpy.mConfig.allowAlarms = false; mZenModeHelperSpy.mConfig.allowMedia = false; Loading @@ -247,11 +269,19 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelperSpy.applyRestrictions(); for (int usage : AudioAttributes.SDK_USAGES) { if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { // only mute audio, not vibrations verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(true, usage, AppOpsManager.OP_PLAY_AUDIO); verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE); } else { boolean shouldMute = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage) != AudioAttributes.SUPPRESSIBLE_NEVER; verify(mZenModeHelperSpy, atLeastOnce()).applyRestrictions(shouldMute, usage); } } } @Test public void testZenUpgradeNotification() { Loading