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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23586063

Change-Id: I543acd5fab3a7867b68abad538db1409e811ca40
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Lucas Dupin
2023-06-07 22:43:07 +00:00
committed by Automerger Merge Worker
2 changed files with 30 additions and 13 deletions

View File

@@ -133,16 +133,14 @@ class WallpaperData {
*/ */
final Rect cropHint = new Rect(0, 0, 0, 0); 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) { WallpaperData(int userId, @SetWallpaperFlags int wallpaperType) {
this(userId, getWallpaperDir(userId), this.userId = userId;
(wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_ORIG : WALLPAPER, this.mWhich = wallpaperType;
(wallpaperType == FLAG_LOCK) ? WALLPAPER_LOCK_CROP : WALLPAPER_CROP); 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);
} }
/** /**

View File

@@ -17,8 +17,10 @@
package com.android.server.wallpaper; package com.android.server.wallpaper;
import static android.app.WallpaperManager.COMMAND_REAPPLY; import static android.app.WallpaperManager.COMMAND_REAPPLY;
import static android.app.WallpaperManager.FLAG_LOCK;
import static android.app.WallpaperManager.FLAG_SYSTEM; import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.os.FileObserver.CLOSE_WRITE; 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.os.UserHandle.USER_SYSTEM;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
@@ -106,6 +108,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List;
/** /**
* Tests for the {@link WallpaperManagerService} class. * 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. * 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"); fail("exception occurred while writing system wallpaper attributes");
} }
WallpaperData shouldMatchSystem = new WallpaperData(systemWallpaperData.userId, WallpaperData shouldMatchSystem = new WallpaperData(0, FLAG_SYSTEM);
systemWallpaperData.wallpaperFile.getParentFile(),
systemWallpaperData.wallpaperFile.getAbsolutePath(),
systemWallpaperData.cropFile.getAbsolutePath());
try { try {
TypedXmlPullParser parser = Xml.newBinaryPullParser(); TypedXmlPullParser parser = Xml.newBinaryPullParser();
mService.mWallpaperDataParser.parseWallpaperAttributes(parser, shouldMatchSystem, true); mService.mWallpaperDataParser.parseWallpaperAttributes(parser, shouldMatchSystem, true);