Loading services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +7 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF; import static com.android.server.notification.ZenLog.traceApplyDeviceEffect; import static com.android.server.notification.ZenLog.traceScheduleApplyDeviceEffect; import android.app.KeyguardManager; import android.app.UiModeManager; import android.app.WallpaperManager; import android.content.BroadcastReceiver; Loading Loading @@ -53,6 +54,7 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { private final Context mContext; private final ColorDisplayManager mColorDisplayManager; private final KeyguardManager mKeyguardManager; private final PowerManager mPowerManager; private final UiModeManager mUiModeManager; private final WallpaperManager mWallpaperManager; Loading @@ -67,6 +69,7 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { DefaultDeviceEffectsApplier(Context context) { mContext = context; mColorDisplayManager = context.getSystemService(ColorDisplayManager.class); mKeyguardManager = context.getSystemService(KeyguardManager.class); mPowerManager = context.getSystemService(PowerManager.class); mUiModeManager = context.getSystemService(UiModeManager.class); WallpaperManager wallpaperManager = context.getSystemService(WallpaperManager.class); Loading Loading @@ -133,12 +136,14 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { // Changing the theme can be disruptive for the user (Activities are likely recreated, may // lose some state). Therefore we only apply the change immediately if the rule was // activated manually, or we are initializing, or the screen is currently off/dreaming. // activated manually, or we are initializing, or the screen is currently off/dreaming, // or if the device is locked. if (origin == ZenModeConfig.ORIGIN_INIT || origin == ZenModeConfig.ORIGIN_INIT_USER || origin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI || origin == ZenModeConfig.ORIGIN_USER_IN_APP || !mPowerManager.isInteractive()) { || !mPowerManager.isInteractive() || (android.app.Flags.modesUi() && mKeyguardManager.isKeyguardLocked())) { unregisterScreenOffReceiver(); updateNightModeImmediately(useNightMode); } else { Loading services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import android.app.KeyguardManager; import android.app.UiModeManager; import android.app.WallpaperManager; import android.content.BroadcastReceiver; Loading Loading @@ -78,6 +79,7 @@ public class DefaultDeviceEffectsApplierTest { private DefaultDeviceEffectsApplier mApplier; @Mock PowerManager mPowerManager; @Mock ColorDisplayManager mColorDisplayManager; @Mock KeyguardManager mKeyguardManager; @Mock UiModeManager mUiModeManager; @Mock WallpaperManager mWallpaperManager; Loading @@ -87,6 +89,7 @@ public class DefaultDeviceEffectsApplierTest { mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); mContext.addMockSystemService(PowerManager.class, mPowerManager); mContext.addMockSystemService(ColorDisplayManager.class, mColorDisplayManager); mContext.addMockSystemService(KeyguardManager.class, mKeyguardManager); mContext.addMockSystemService(UiModeManager.class, mUiModeManager); mContext.addMockSystemService(WallpaperManager.class, mWallpaperManager); when(mWallpaperManager.isWallpaperSupported()).thenReturn(true); Loading Loading @@ -310,6 +313,22 @@ public class DefaultDeviceEffectsApplierTest { verify(mContext, never()).registerReceiver(any(), any(), anyInt()); } @Test @EnableFlags({android.app.Flags.FLAG_MODES_API, android.app.Flags.FLAG_MODES_UI}) public void apply_nightModeWithScreenOnAndKeyguardShowing_appliedImmediately( @TestParameter ZenChangeOrigin origin) { when(mPowerManager.isInteractive()).thenReturn(true); when(mKeyguardManager.isKeyguardLocked()).thenReturn(true); mApplier.apply(new ZenDeviceEffects.Builder().setShouldUseNightMode(true).build(), origin.value()); // Effect was applied, and no broadcast receiver was registered. verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT)); verify(mContext, never()).registerReceiver(any(), any(), anyInt()); } @Test @TestParameters({"{origin: ORIGIN_USER_IN_SYSTEMUI}", "{origin: ORIGIN_USER_IN_APP}", "{origin: ORIGIN_INIT}", "{origin: ORIGIN_INIT_USER}"}) Loading Loading
services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +7 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF; import static com.android.server.notification.ZenLog.traceApplyDeviceEffect; import static com.android.server.notification.ZenLog.traceScheduleApplyDeviceEffect; import android.app.KeyguardManager; import android.app.UiModeManager; import android.app.WallpaperManager; import android.content.BroadcastReceiver; Loading Loading @@ -53,6 +54,7 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { private final Context mContext; private final ColorDisplayManager mColorDisplayManager; private final KeyguardManager mKeyguardManager; private final PowerManager mPowerManager; private final UiModeManager mUiModeManager; private final WallpaperManager mWallpaperManager; Loading @@ -67,6 +69,7 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { DefaultDeviceEffectsApplier(Context context) { mContext = context; mColorDisplayManager = context.getSystemService(ColorDisplayManager.class); mKeyguardManager = context.getSystemService(KeyguardManager.class); mPowerManager = context.getSystemService(PowerManager.class); mUiModeManager = context.getSystemService(UiModeManager.class); WallpaperManager wallpaperManager = context.getSystemService(WallpaperManager.class); Loading Loading @@ -133,12 +136,14 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { // Changing the theme can be disruptive for the user (Activities are likely recreated, may // lose some state). Therefore we only apply the change immediately if the rule was // activated manually, or we are initializing, or the screen is currently off/dreaming. // activated manually, or we are initializing, or the screen is currently off/dreaming, // or if the device is locked. if (origin == ZenModeConfig.ORIGIN_INIT || origin == ZenModeConfig.ORIGIN_INIT_USER || origin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI || origin == ZenModeConfig.ORIGIN_USER_IN_APP || !mPowerManager.isInteractive()) { || !mPowerManager.isInteractive() || (android.app.Flags.modesUi() && mKeyguardManager.isKeyguardLocked())) { unregisterScreenOffReceiver(); updateNightModeImmediately(useNightMode); } else { Loading
services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import android.app.KeyguardManager; import android.app.UiModeManager; import android.app.WallpaperManager; import android.content.BroadcastReceiver; Loading Loading @@ -78,6 +79,7 @@ public class DefaultDeviceEffectsApplierTest { private DefaultDeviceEffectsApplier mApplier; @Mock PowerManager mPowerManager; @Mock ColorDisplayManager mColorDisplayManager; @Mock KeyguardManager mKeyguardManager; @Mock UiModeManager mUiModeManager; @Mock WallpaperManager mWallpaperManager; Loading @@ -87,6 +89,7 @@ public class DefaultDeviceEffectsApplierTest { mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); mContext.addMockSystemService(PowerManager.class, mPowerManager); mContext.addMockSystemService(ColorDisplayManager.class, mColorDisplayManager); mContext.addMockSystemService(KeyguardManager.class, mKeyguardManager); mContext.addMockSystemService(UiModeManager.class, mUiModeManager); mContext.addMockSystemService(WallpaperManager.class, mWallpaperManager); when(mWallpaperManager.isWallpaperSupported()).thenReturn(true); Loading Loading @@ -310,6 +313,22 @@ public class DefaultDeviceEffectsApplierTest { verify(mContext, never()).registerReceiver(any(), any(), anyInt()); } @Test @EnableFlags({android.app.Flags.FLAG_MODES_API, android.app.Flags.FLAG_MODES_UI}) public void apply_nightModeWithScreenOnAndKeyguardShowing_appliedImmediately( @TestParameter ZenChangeOrigin origin) { when(mPowerManager.isInteractive()).thenReturn(true); when(mKeyguardManager.isKeyguardLocked()).thenReturn(true); mApplier.apply(new ZenDeviceEffects.Builder().setShouldUseNightMode(true).build(), origin.value()); // Effect was applied, and no broadcast receiver was registered. verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT)); verify(mContext, never()).registerReceiver(any(), any(), anyInt()); } @Test @TestParameters({"{origin: ORIGIN_USER_IN_SYSTEMUI}", "{origin: ORIGIN_USER_IN_APP}", "{origin: ORIGIN_INIT}", "{origin: ORIGIN_INIT_USER}"}) Loading