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

Commit 5a3ed74f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove leftover wallpaper dim on reboot" into main

parents cdad3b5d 09ed5693
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -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);
                });

@@ -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);
            }
        }
    }
@@ -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);
            }
        });
    }
+27 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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());
    }
}