diff options
2 files changed, 27 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java index ab650afe68a7..27b85746fec2 100644 --- a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +++ b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java @@ -65,7 +65,9 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {          mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);          mPowerManager = context.getSystemService(PowerManager.class);          mUiModeManager = context.getSystemService(UiModeManager.class); -        mWallpaperManager = context.getSystemService(WallpaperManager.class); +        WallpaperManager wallpaperManager = context.getSystemService(WallpaperManager.class); +        mWallpaperManager = wallpaperManager != null && wallpaperManager.isWallpaperSupported() +                ? wallpaperManager : null;      }      @Override diff --git a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java index 3797dbb97213..bfbc81ccfe39 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java @@ -29,9 +29,11 @@ import static org.mockito.ArgumentMatchers.anyInt;  import static org.mockito.ArgumentMatchers.anyString;  import static org.mockito.ArgumentMatchers.argThat;  import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock;  import static org.mockito.Mockito.never;  import static org.mockito.Mockito.spy;  import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions;  import static org.mockito.Mockito.verifyZeroInteractions;  import static org.mockito.Mockito.when; @@ -103,8 +105,10 @@ public class DefaultDeviceEffectsApplierTest {          mContext.addMockSystemService(ColorDisplayManager.class, mColorDisplayManager);          mContext.addMockSystemService(UiModeManager.class, mUiModeManager);          mContext.addMockSystemService(WallpaperManager.class, mWallpaperManager); +        when(mWallpaperManager.isWallpaperSupported()).thenReturn(true);          mApplier = new DefaultDeviceEffectsApplier(mContext); +        verify(mWallpaperManager).isWallpaperSupported();      }      @Test @@ -187,6 +191,26 @@ public class DefaultDeviceEffectsApplierTest {      }      @Test +    public void apply_disabledWallpaperService_dimWallpaperNotApplied() { +        mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API); +        WallpaperManager disabledWallpaperService = mock(WallpaperManager.class); +        when(mWallpaperManager.isWallpaperSupported()).thenReturn(false); +        mContext.addMockSystemService(WallpaperManager.class, disabledWallpaperService); +        mApplier = new DefaultDeviceEffectsApplier(mContext); +        verify(mWallpaperManager).isWallpaperSupported(); + +        ZenDeviceEffects effects = new ZenDeviceEffects.Builder() +                .setShouldSuppressAmbientDisplay(true) +                .setShouldDimWallpaper(true) +                .setShouldDisplayGrayscale(true) +                .setShouldUseNightMode(true) +                .build(); +        mApplier.apply(effects, UPDATE_ORIGIN_USER); + +        verifyNoMoreInteractions(mWallpaperManager); +    } + +    @Test      public void apply_someEffects_onlyThoseEffectsApplied() {          mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);  |