Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7841e422 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Don't apply the "dim wallpaper" effect if wallpaper is not supported" into main

parents df1abf02 05b1563d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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
+24 −0
Original line number Diff line number Diff line
@@ -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
@@ -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);