Loading services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +3 −1 Original line number Diff line number Diff line Loading @@ -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 Loading services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -186,6 +190,26 @@ public class DefaultDeviceEffectsApplierTest { // (And no crash from missing services). } @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); Loading Loading
services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java +3 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -186,6 +190,26 @@ public class DefaultDeviceEffectsApplierTest { // (And no crash from missing services). } @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); Loading