Loading services/core/java/com/android/server/notification/ZenModeHelper.java +14 −6 Original line number Diff line number Diff line Loading @@ -2811,8 +2811,9 @@ public class ZenModeHelper { private final class H extends Handler { private static final int MSG_DISPATCH = 1; private static final int MSG_METRICS = 2; private static final int MSG_RINGER_AUDIO = 5; private static final int MSG_APPLY_EFFECTS = 6; private static final int MSG_AUDIO_APPLIED_TO_RINGER = 7; private static final int MSG_AUDIO_NOT_APPLIED_TO_RINGER = 8; private static final long METRICS_PERIOD_MS = 6 * 60 * 60 * 1000; Loading @@ -2831,8 +2832,13 @@ public class ZenModeHelper { } private void postUpdateRingerAndAudio(boolean shouldApplyToRinger) { removeMessages(MSG_RINGER_AUDIO); sendMessage(obtainMessage(MSG_RINGER_AUDIO, shouldApplyToRinger)); if (shouldApplyToRinger) { removeMessages(MSG_AUDIO_APPLIED_TO_RINGER); sendEmptyMessage(MSG_AUDIO_APPLIED_TO_RINGER); } else { removeMessages(MSG_AUDIO_NOT_APPLIED_TO_RINGER); sendEmptyMessage(MSG_AUDIO_NOT_APPLIED_TO_RINGER); } } private void postApplyDeviceEffects(@ConfigChangeOrigin int origin) { Loading @@ -2849,9 +2855,11 @@ public class ZenModeHelper { case MSG_METRICS: mMetrics.emit(); break; case MSG_RINGER_AUDIO: boolean shouldApplyToRinger = (boolean) msg.obj; updateRingerAndAudio(shouldApplyToRinger); case MSG_AUDIO_APPLIED_TO_RINGER: updateRingerAndAudio(/* shouldApplyToRinger= */ true); break; case MSG_AUDIO_NOT_APPLIED_TO_RINGER: updateRingerAndAudio(/* shouldApplyToRinger= */ false); break; case MSG_APPLY_EFFECTS: @ConfigChangeOrigin int origin = msg.arg1; Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -1044,6 +1044,8 @@ public class ZenModeHelperTest extends UiServiceTestCase { AudioManagerInternal mAudioManager = mock(AudioManagerInternal.class); mZenModeHelper.mAudioManager = mAudioManager; setupZenConfig(); mTestableLooper.processAllMessages(); reset(mAudioManager); // Turn manual zen mode on mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, Loading @@ -1062,6 +1064,44 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(mAudioManager, atLeastOnce()).getRingerModeInternal(); } @Test public void testSetConfig_updatesAudioForSequentialChangesToZenMode() { AudioManagerInternal mAudioManager = mock(AudioManagerInternal.class); mZenModeHelper.mAudioManager = mAudioManager; setupZenConfig(); mTestableLooper.processAllMessages(); reset(mAudioManager); // Turn manual zen mode on mZenModeHelper.setManualZenMode( ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, null, "test", CUSTOM_PKG_UID); mZenModeHelper.setManualZenMode( ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, null, "test", CUSTOM_PKG_UID); // audio manager shouldn't do anything until the handler processes its messages verify(mAudioManager, never()).updateRingerModeAffectedStreamsInternal(); // now process the looper's messages mTestableLooper.processAllMessages(); // Expect calls to audio manager verify(mAudioManager, times(2)).updateRingerModeAffectedStreamsInternal(); verify(mAudioManager, times(1)).setRingerModeInternal(anyInt(), anyString()); // called during applyZenToRingerMode(), which should be true since zen changed verify(mAudioManager, atLeastOnce()).getRingerModeInternal(); } @Test public void testParcelConfig() { mZenModeHelper.setNotificationPolicy(new Policy(PRIORITY_CATEGORY_EVENTS Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +14 −6 Original line number Diff line number Diff line Loading @@ -2811,8 +2811,9 @@ public class ZenModeHelper { private final class H extends Handler { private static final int MSG_DISPATCH = 1; private static final int MSG_METRICS = 2; private static final int MSG_RINGER_AUDIO = 5; private static final int MSG_APPLY_EFFECTS = 6; private static final int MSG_AUDIO_APPLIED_TO_RINGER = 7; private static final int MSG_AUDIO_NOT_APPLIED_TO_RINGER = 8; private static final long METRICS_PERIOD_MS = 6 * 60 * 60 * 1000; Loading @@ -2831,8 +2832,13 @@ public class ZenModeHelper { } private void postUpdateRingerAndAudio(boolean shouldApplyToRinger) { removeMessages(MSG_RINGER_AUDIO); sendMessage(obtainMessage(MSG_RINGER_AUDIO, shouldApplyToRinger)); if (shouldApplyToRinger) { removeMessages(MSG_AUDIO_APPLIED_TO_RINGER); sendEmptyMessage(MSG_AUDIO_APPLIED_TO_RINGER); } else { removeMessages(MSG_AUDIO_NOT_APPLIED_TO_RINGER); sendEmptyMessage(MSG_AUDIO_NOT_APPLIED_TO_RINGER); } } private void postApplyDeviceEffects(@ConfigChangeOrigin int origin) { Loading @@ -2849,9 +2855,11 @@ public class ZenModeHelper { case MSG_METRICS: mMetrics.emit(); break; case MSG_RINGER_AUDIO: boolean shouldApplyToRinger = (boolean) msg.obj; updateRingerAndAudio(shouldApplyToRinger); case MSG_AUDIO_APPLIED_TO_RINGER: updateRingerAndAudio(/* shouldApplyToRinger= */ true); break; case MSG_AUDIO_NOT_APPLIED_TO_RINGER: updateRingerAndAudio(/* shouldApplyToRinger= */ false); break; case MSG_APPLY_EFFECTS: @ConfigChangeOrigin int origin = msg.arg1; Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -1044,6 +1044,8 @@ public class ZenModeHelperTest extends UiServiceTestCase { AudioManagerInternal mAudioManager = mock(AudioManagerInternal.class); mZenModeHelper.mAudioManager = mAudioManager; setupZenConfig(); mTestableLooper.processAllMessages(); reset(mAudioManager); // Turn manual zen mode on mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, Loading @@ -1062,6 +1064,44 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(mAudioManager, atLeastOnce()).getRingerModeInternal(); } @Test public void testSetConfig_updatesAudioForSequentialChangesToZenMode() { AudioManagerInternal mAudioManager = mock(AudioManagerInternal.class); mZenModeHelper.mAudioManager = mAudioManager; setupZenConfig(); mTestableLooper.processAllMessages(); reset(mAudioManager); // Turn manual zen mode on mZenModeHelper.setManualZenMode( ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, null, "test", CUSTOM_PKG_UID); mZenModeHelper.setManualZenMode( ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP, null, "test", CUSTOM_PKG_UID); // audio manager shouldn't do anything until the handler processes its messages verify(mAudioManager, never()).updateRingerModeAffectedStreamsInternal(); // now process the looper's messages mTestableLooper.processAllMessages(); // Expect calls to audio manager verify(mAudioManager, times(2)).updateRingerModeAffectedStreamsInternal(); verify(mAudioManager, times(1)).setRingerModeInternal(anyInt(), anyString()); // called during applyZenToRingerMode(), which should be true since zen changed verify(mAudioManager, atLeastOnce()).getRingerModeInternal(); } @Test public void testParcelConfig() { mZenModeHelper.setNotificationPolicy(new Policy(PRIORITY_CATEGORY_EVENTS Loading