Loading services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +22 −15 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { () -> { maybeSuppressAmbientDisplay(effects.shouldSuppressAmbientDisplay()); maybeDisplayGrayscale(effects.shouldDisplayGrayscale()); maybeDimWallpaper(effects.shouldDimWallpaper()); maybeDimWallpaper(effects.shouldDimWallpaper(), origin); maybeUseNightMode(effects.shouldUseNightMode(), origin); }); Loading Loading @@ -120,28 +120,35 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { } } protected void maybeDimWallpaper(boolean shouldDimWallpaper) { if (mLastAppliedEffects.shouldDimWallpaper() != shouldDimWallpaper) { if (mWallpaperManager != null) { protected void maybeDimWallpaper(boolean shouldDimWallpaper, @ConfigOrigin int origin) { if (mWallpaperManager == null) { return; } try { // Unlike the other effects, dimWallpaper is serialized (and thus preserved on reboot). if (mLastAppliedEffects.shouldDimWallpaper() != shouldDimWallpaper) { traceApplyDeviceEffect("dimWallpaper", shouldDimWallpaper); mWallpaperManager.setWallpaperDimAmount( shouldDimWallpaper ? WALLPAPER_DIM_AMOUNT_DIMMED : WALLPAPER_DIM_AMOUNT_NORMAL); } else if (origin == ZenModeConfig.ORIGIN_INIT && !shouldDimWallpaper && mWallpaperManager.getWallpaperDimAmount() == WALLPAPER_DIM_AMOUNT_DIMMED) { traceApplyDeviceEffect("dimWallpaper (reset on boot)", false); mWallpaperManager.setWallpaperDimAmount(WALLPAPER_DIM_AMOUNT_NORMAL); } } catch (Exception e) { Slog.e(TAG, "Could not change wallpaper override", e); } } } } protected void maybeUseNightMode(boolean shouldUseNightMode, @ConfigOrigin int origin) { if (mLastAppliedEffects.shouldUseNightMode() != shouldUseNightMode) { try { updateOrScheduleNightMode(shouldUseNightMode, origin); } catch (Exception e) { Slog.e(TAG, "Could not change dark theme override", e); Slog.e(TAG, "Could not change night mode override", e); } } } Loading Loading @@ -184,7 +191,7 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { useNightMode ? MODE_ATTENTION_THEME_OVERLAY_NIGHT : MODE_ATTENTION_THEME_OVERLAY_OFF); } catch (Exception e) { Slog.e(TAG, "Could not change wallpaper override", e); Slog.e(TAG, "Could not change night mode override", e); } }); } Loading services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.notification; import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_NIGHT; import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF; import static android.service.notification.ZenModeConfig.ORIGIN_APP; import static android.service.notification.ZenModeConfig.ORIGIN_INIT; import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -81,6 +82,8 @@ public class DefaultDeviceEffectsApplierTest { @Mock UiModeManager mUiModeManager; @Mock WallpaperManager mWallpaperManager; private static final ZenDeviceEffects NO_EFFECTS = new ZenDeviceEffects.Builder().build(); @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading Loading @@ -361,4 +364,28 @@ public class DefaultDeviceEffectsApplierTest { // No crashes } @Test public void apply_onBootWithLeftoverDim_forceRemovesDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.6f); mApplier.apply(NO_EFFECTS, ORIGIN_INIT); verify(mWallpaperManager).setWallpaperDimAmount(eq(0f)); String zenLog = getZenLog(); assertThat(zenLog).contains("apply_device_effect: dimWallpaper (reset on boot) -> false"); } @Test public void apply_onBootWithUnrelatedDim_doesNotForceRemoveDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.42f); mApplier.apply(NO_EFFECTS, ORIGIN_INIT); verify(mWallpaperManager, never()).setWallpaperDimAmount(anyFloat()); } @Test public void apply_notOnBoot_doesNotForceRemoveDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.6f); mApplier.apply(NO_EFFECTS, ORIGIN_APP); verify(mWallpaperManager, never()).setWallpaperDimAmount(anyFloat()); } } Loading
services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +22 −15 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { () -> { maybeSuppressAmbientDisplay(effects.shouldSuppressAmbientDisplay()); maybeDisplayGrayscale(effects.shouldDisplayGrayscale()); maybeDimWallpaper(effects.shouldDimWallpaper()); maybeDimWallpaper(effects.shouldDimWallpaper(), origin); maybeUseNightMode(effects.shouldUseNightMode(), origin); }); Loading Loading @@ -120,28 +120,35 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { } } protected void maybeDimWallpaper(boolean shouldDimWallpaper) { if (mLastAppliedEffects.shouldDimWallpaper() != shouldDimWallpaper) { if (mWallpaperManager != null) { protected void maybeDimWallpaper(boolean shouldDimWallpaper, @ConfigOrigin int origin) { if (mWallpaperManager == null) { return; } try { // Unlike the other effects, dimWallpaper is serialized (and thus preserved on reboot). if (mLastAppliedEffects.shouldDimWallpaper() != shouldDimWallpaper) { traceApplyDeviceEffect("dimWallpaper", shouldDimWallpaper); mWallpaperManager.setWallpaperDimAmount( shouldDimWallpaper ? WALLPAPER_DIM_AMOUNT_DIMMED : WALLPAPER_DIM_AMOUNT_NORMAL); } else if (origin == ZenModeConfig.ORIGIN_INIT && !shouldDimWallpaper && mWallpaperManager.getWallpaperDimAmount() == WALLPAPER_DIM_AMOUNT_DIMMED) { traceApplyDeviceEffect("dimWallpaper (reset on boot)", false); mWallpaperManager.setWallpaperDimAmount(WALLPAPER_DIM_AMOUNT_NORMAL); } } catch (Exception e) { Slog.e(TAG, "Could not change wallpaper override", e); } } } } protected void maybeUseNightMode(boolean shouldUseNightMode, @ConfigOrigin int origin) { if (mLastAppliedEffects.shouldUseNightMode() != shouldUseNightMode) { try { updateOrScheduleNightMode(shouldUseNightMode, origin); } catch (Exception e) { Slog.e(TAG, "Could not change dark theme override", e); Slog.e(TAG, "Could not change night mode override", e); } } } Loading Loading @@ -184,7 +191,7 @@ public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier { useNightMode ? MODE_ATTENTION_THEME_OVERLAY_NIGHT : MODE_ATTENTION_THEME_OVERLAY_OFF); } catch (Exception e) { Slog.e(TAG, "Could not change wallpaper override", e); Slog.e(TAG, "Could not change night mode override", e); } }); } Loading
services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.notification; import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_NIGHT; import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF; import static android.service.notification.ZenModeConfig.ORIGIN_APP; import static android.service.notification.ZenModeConfig.ORIGIN_INIT; import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -81,6 +82,8 @@ public class DefaultDeviceEffectsApplierTest { @Mock UiModeManager mUiModeManager; @Mock WallpaperManager mWallpaperManager; private static final ZenDeviceEffects NO_EFFECTS = new ZenDeviceEffects.Builder().build(); @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading Loading @@ -361,4 +364,28 @@ public class DefaultDeviceEffectsApplierTest { // No crashes } @Test public void apply_onBootWithLeftoverDim_forceRemovesDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.6f); mApplier.apply(NO_EFFECTS, ORIGIN_INIT); verify(mWallpaperManager).setWallpaperDimAmount(eq(0f)); String zenLog = getZenLog(); assertThat(zenLog).contains("apply_device_effect: dimWallpaper (reset on boot) -> false"); } @Test public void apply_onBootWithUnrelatedDim_doesNotForceRemoveDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.42f); mApplier.apply(NO_EFFECTS, ORIGIN_INIT); verify(mWallpaperManager, never()).setWallpaperDimAmount(anyFloat()); } @Test public void apply_notOnBoot_doesNotForceRemoveDimWallpaper() { when(mWallpaperManager.getWallpaperDimAmount()).thenReturn(0.6f); mApplier.apply(NO_EFFECTS, ORIGIN_APP); verify(mWallpaperManager, never()).setWallpaperDimAmount(anyFloat()); } }