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

Commit 5e068910 authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Set WallpaperData flag in constructor" into udc-dev am: d9bc3422

parents 17584e97 d9bc3422
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -133,16 +133,14 @@ class WallpaperData {
     */
    final Rect cropHint = new Rect(0, 0, 0, 0);

    WallpaperData(int userId, File wallpaperDir, String inputFileName, String cropFileName) {
        this.userId = userId;
        wallpaperFile = new File(wallpaperDir, inputFileName);
        cropFile = new File(wallpaperDir, cropFileName);
    }

    WallpaperData(int userId, @SetWallpaperFlags int wallpaperType) {
        this(userId, getWallpaperDir(userId),
                (wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_ORIG : WALLPAPER,
                (wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_CROP : WALLPAPER_CROP);
        this.userId = userId;
        this.mWhich = wallpaperType;
        File wallpaperDir = getWallpaperDir(userId);
        String wallpaperFileName = (wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_ORIG : WALLPAPER;
        String cropFileName = (wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_CROP : WALLPAPER_CROP;
        this.wallpaperFile = new File(wallpaperDir, wallpaperFileName);
        this.cropFile = new File(wallpaperDir, cropFileName);
    }

    /**
+23 −4
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.server.wallpaper;

import static android.app.WallpaperManager.COMMAND_REAPPLY;
import static android.app.WallpaperManager.FLAG_LOCK;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.os.FileObserver.CLOSE_WRITE;
import static android.os.UserHandle.MIN_SECONDARY_USER_ID;
import static android.os.UserHandle.USER_SYSTEM;
import static android.view.Display.DEFAULT_DISPLAY;

@@ -106,6 +108,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * Tests for the {@link WallpaperManagerService} class.
@@ -261,6 +264,25 @@ public class WallpaperManagerServiceTests {
        }
    }

    /**
     * Tests that the fundamental fields are set by the main WallpaperData constructor
     */
    @Test
    public void testWallpaperDataConstructor() {
        final int testUserId = MIN_SECONDARY_USER_ID;
        for (int which: List.of(FLAG_LOCK, FLAG_SYSTEM)) {
            WallpaperData newWallpaperData = new WallpaperData(testUserId, which);
            assertEquals(which, newWallpaperData.mWhich);
            assertEquals(testUserId, newWallpaperData.userId);

            WallpaperData wallpaperData = mService.getWallpaperSafeLocked(testUserId, which);
            assertEquals(wallpaperData.cropFile.getAbsolutePath(),
                    newWallpaperData.cropFile.getAbsolutePath());
            assertEquals(wallpaperData.wallpaperFile.getAbsolutePath(),
                    newWallpaperData.wallpaperFile.getAbsolutePath());
        }
    }

    /**
     * Tests that internal basic data should be correct after boot up.
     */
@@ -405,10 +427,7 @@ public class WallpaperManagerServiceTests {
            fail("exception occurred while writing system wallpaper attributes");
        }

        WallpaperData shouldMatchSystem = new WallpaperData(systemWallpaperData.userId,
                systemWallpaperData.wallpaperFile.getParentFile(),
                systemWallpaperData.wallpaperFile.getAbsolutePath(),
                systemWallpaperData.cropFile.getAbsolutePath());
        WallpaperData shouldMatchSystem = new WallpaperData(0, FLAG_SYSTEM);
        try {
            TypedXmlPullParser parser = Xml.newBinaryPullParser();
            mService.mWallpaperDataParser.parseWallpaperAttributes(parser, shouldMatchSystem, true);