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

Commit 41fd188f authored by Steven Ng's avatar Steven Ng
Browse files

Set the wallpaper connection when migrating from system to lock wallpaper

Problem:
The `WPMS#updateFallbackConnection` function isn't reliably updating fallback wallpapers on all displays. This is because when a static home/lock wallpaper changes to a static lock-only wallpaper, the `mLastLockWallpaper` connection isn't properly linked during the initial update in `migrateStaticSystemToLockWallpaperLocked`, leading to an inconsistent state before the `WallpaperDestinationChangeHandler#complete` links the connection.

Solution:
Set the lock wallpaper connection in `migrateStaticSystemToLockWallpaperLocked`

Test: atest FrameworksMockingServicesTests:WallpaperManagerServiceTests
Flag: EXEMPTED small bug fix
Fix: 420579203
Change-Id: I87dd0fbd0e67301b44e0b78e3da72dc7fa075ffd
parent f59abc3d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3457,6 +3457,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        lockWP.primaryColors = sysWP.primaryColors;
        lockWP.mWallpaperDimAmount = sysWP.mWallpaperDimAmount;
        lockWP.mWhich = FLAG_LOCK;
        lockWP.connection = sysWP.connection;

        // Migrate the bitmap files outright; no need to copy
        try {
+55 −4
Original line number Diff line number Diff line
@@ -1187,11 +1187,13 @@ public class WallpaperManagerServiceTests {
        assertThat(mService.mLastLockWallpaper).isNull();
    }

    // Test setWallpaperComponent on multiple displays.
    // GIVEN 3 displays, 0, 2, 3, the new wallpaper is only compatible for display 0 and 3 but not
    // 2.
    // Test setWallpaperComponent on multiple displays:
    // GIVEN TEST_WALLPAPER_COMPONENT, a live wallpaper for lock screen that supports all displays
    // GIVEN a static wallpaper for the home screen.
    // GIVEN 3 displays, 0, 2, 3, the static wallpaper is only compatible for display 0 and 3 but
    // not 2.
    // WHEN two different wallpapers set for system and lock via setWallpaperComponent.
    // THEN there are two connections in mLastWallpaper, two connection in mLastLockWallpaper and
    // THEN there are two connections in mLastWallpaper, three connection in mLastLockWallpaper and
    // one connection in mFallbackWallpaper.
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
@@ -1239,6 +1241,55 @@ public class WallpaperManagerServiceTests {
                .isTrue();
    }

    // Test setWallpaperComponent on multiple displays: from static system + lock to static system.
    // GIVEN 3 displays, 0, 2, 3, the static wallpaper is only compatible for display 0 and 3 but
    // not 2.
    // WHEN two static wallpapers set for system and lock via setWallpaperComponent.
    // THEN there are two connections in mLastWallpaper, two connection in mLastLockWallpaper and
    // one connection in mFallbackWallpaper.
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void setWallpaperComponent_staticSystemAndLockToSystemWallpapers_multiDisplays_shouldHaveExpectedConnections() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(true).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);
        final int incompatibleDisplayId = 2;
        final int compatibleDisplayId = 3;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                incompatibleDisplayId, false,
                compatibleDisplayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(sImageWallpaperComponentName, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);
        mService.setWallpaperComponent(sImageWallpaperComponentName, sContext.getOpPackageName(),
                FLAG_SYSTEM, testUserId);

        verifyLastWallpaperData(testUserId, sImageWallpaperComponentName);
        verifyLastLockWallpaperData(testUserId, sImageWallpaperComponentName);
        verifyCurrentSystemData(testUserId);

        assertThat(mService.mLastWallpaper.connection.containsDisplay(DEFAULT_DISPLAY)).isTrue();
        assertThat(mService.mLastWallpaper.connection.containsDisplay(compatibleDisplayId))
                .isTrue();
        assertThat(mService.mLastWallpaper.connection.containsDisplay(incompatibleDisplayId))
                .isFalse();
        assertThat(mService.mLastLockWallpaper.connection.containsDisplay(DEFAULT_DISPLAY))
                .isTrue();
        assertThat(mService.mLastLockWallpaper.connection.containsDisplay(compatibleDisplayId))
                .isTrue();
        assertThat(mService.mLastLockWallpaper.connection.containsDisplay(incompatibleDisplayId))
                .isFalse();
        assertThat(mService.mFallbackWallpaper.connection.containsDisplay(DEFAULT_DISPLAY))
                .isFalse();
        assertThat(mService.mFallbackWallpaper.connection.containsDisplay(compatibleDisplayId))
                .isFalse();
        assertThat(mService.mFallbackWallpaper.connection.containsDisplay(incompatibleDisplayId))
                .isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperSupported_desktopExperienceEnabled_shouldReturnTrue() {