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

Commit 05b1563d authored by Matías Hernández's avatar Matías Hernández
Browse files

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

On auto, getSystemService(WallpaperManager) returns a non-null but non-working service (DisabledWallpaperManager) that fails on each method call (this seems like a rather unusual pattern). We detect this by calling isWallpaperSupported() and, if false, we won't try to apply the effect.

Bug: 327485783
Test: atest DefaultDeviceEffectsApplierTest
Change-Id: I1be7c902f4ae63d0b6191d9fcb106691052cbc55
parent 23283573
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);