Loading core/java/android/app/WallpaperManager.java +17 −17 Original line number Diff line number Diff line Loading @@ -319,12 +319,12 @@ public class WallpaperManager { * This is only used internally by the framework and the WallpaperBackupAgent. * @hide */ @IntDef(value = { @IntDef(prefix = { "ORIENTATION_" }, value = { ORIENTATION_UNKNOWN, PORTRAIT, LANDSCAPE, SQUARE_PORTRAIT, SQUARE_LANDSCAPE, ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE, ORIENTATION_SQUARE_PORTRAIT, ORIENTATION_SQUARE_LANDSCAPE, }) @Retention(RetentionPolicy.SOURCE) public @interface ScreenOrientation {} Loading @@ -338,25 +338,25 @@ public class WallpaperManager { * Portrait orientation of most screens * @hide */ public static final int PORTRAIT = 0; public static final int ORIENTATION_PORTRAIT = 0; /** * Landscape orientation of most screens * @hide */ public static final int LANDSCAPE = 1; public static final int ORIENTATION_LANDSCAPE = 1; /** * Portrait orientation with similar width and height (e.g. the inner screen of a foldable) * @hide */ public static final int SQUARE_PORTRAIT = 2; public static final int ORIENTATION_SQUARE_PORTRAIT = 2; /** * Landscape orientation with similar width and height (e.g. the inner screen of a foldable) * @hide */ public static final int SQUARE_LANDSCAPE = 3; public static final int ORIENTATION_SQUARE_LANDSCAPE = 3; /** * Converts a (width, height) screen size to a {@link ScreenOrientation}. Loading @@ -367,10 +367,10 @@ public class WallpaperManager { public static @ScreenOrientation int getOrientation(Point screenSize) { float ratio = ((float) screenSize.x) / screenSize.y; // ratios between 3/4 and 4/3 are considered square return ratio >= 4 / 3f ? LANDSCAPE : ratio > 1f ? SQUARE_LANDSCAPE : ratio > 3 / 4f ? SQUARE_PORTRAIT : PORTRAIT; return ratio >= 4 / 3f ? ORIENTATION_LANDSCAPE : ratio > 1f ? ORIENTATION_SQUARE_LANDSCAPE : ratio > 3 / 4f ? ORIENTATION_SQUARE_PORTRAIT : ORIENTATION_PORTRAIT; } /** Loading @@ -379,10 +379,10 @@ public class WallpaperManager { */ public static @ScreenOrientation int getRotatedOrientation(@ScreenOrientation int orientation) { switch (orientation) { case PORTRAIT: return LANDSCAPE; case LANDSCAPE: return PORTRAIT; case SQUARE_PORTRAIT: return SQUARE_LANDSCAPE; case SQUARE_LANDSCAPE: return SQUARE_PORTRAIT; case ORIENTATION_PORTRAIT: return ORIENTATION_LANDSCAPE; case ORIENTATION_LANDSCAPE: return ORIENTATION_PORTRAIT; case ORIENTATION_SQUARE_PORTRAIT: return ORIENTATION_SQUARE_LANDSCAPE; case ORIENTATION_SQUARE_LANDSCAPE: return ORIENTATION_SQUARE_PORTRAIT; default: return ORIENTATION_UNKNOWN; } } Loading packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +5 −4 Original line number Diff line number Diff line Loading @@ -945,10 +945,11 @@ public class WallpaperBackupAgent extends BackupAgent { String tag = parser.getName(); if (!sectionTag.equals(tag)) continue; for (Pair<Integer, String> pair : List.of( new Pair<>(WallpaperManager.PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.SQUARE_LANDSCAPE, "SquareLandscape"))) { new Pair<>(WallpaperManager.ORIENTATION_PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.ORIENTATION_LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, "SquareLandscape"))) { Rect cropHint = new Rect( getAttributeInt(parser, "cropLeft" + pair.second, 0), getAttributeInt(parser, "cropTop" + pair.second, 0), Loading packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java +9 −8 Original line number Diff line number Diff line Loading @@ -827,16 +827,17 @@ public class WallpaperBackupAgentTest { @Test public void testOnRestore_singleCropHint() throws Exception { Map<Integer, Rect> testMap = Map.of(WallpaperManager.PORTRAIT, new Rect(1, 2, 3, 4)); Map<Integer, Rect> testMap = Map.of( WallpaperManager.ORIENTATION_PORTRAIT, new Rect(1, 2, 3, 4)); testParseCropHints(testMap); } @Test public void testOnRestore_multipleCropHints() throws Exception { Map<Integer, Rect> testMap = Map.of( WallpaperManager.PORTRAIT, new Rect(1, 2, 3, 4), WallpaperManager.SQUARE_PORTRAIT, new Rect(5, 6, 7, 8), WallpaperManager.SQUARE_LANDSCAPE, new Rect(9, 10, 11, 12)); WallpaperManager.ORIENTATION_PORTRAIT, new Rect(1, 2, 3, 4), WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, new Rect(5, 6, 7, 8), WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, new Rect(9, 10, 11, 12)); testParseCropHints(testMap); } Loading Loading @@ -936,10 +937,10 @@ public class WallpaperBackupAgentTest { out.startTag(null, "wp"); for (Map.Entry<Integer, Rect> entry: crops.entrySet()) { String orientation = switch (entry.getKey()) { case WallpaperManager.PORTRAIT -> "Portrait"; case WallpaperManager.LANDSCAPE -> "Landscape"; case WallpaperManager.SQUARE_PORTRAIT -> "SquarePortrait"; case WallpaperManager.SQUARE_LANDSCAPE -> "SquareLandscape"; case WallpaperManager.ORIENTATION_PORTRAIT -> "Portrait"; case WallpaperManager.ORIENTATION_LANDSCAPE -> "Landscape"; case WallpaperManager.ORIENTATION_SQUARE_PORTRAIT -> "SquarePortrait"; case WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE -> "SquareLandscape"; default -> throw new IllegalArgumentException("Invalid orientation"); }; Rect rect = entry.getValue(); Loading services/core/java/com/android/server/wallpaper/WallpaperDataParser.java +4 −4 Original line number Diff line number Diff line Loading @@ -745,9 +745,9 @@ public class WallpaperDataParser { private static List<Pair<Integer, String>> screenDimensionPairs() { return List.of( new Pair<>(WallpaperManager.PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.SQUARE_LANDSCAPE, "SquareLandscape")); new Pair<>(WallpaperManager.ORIENTATION_PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.ORIENTATION_LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, "SquareLandscape")); } } services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperCropperTest.java +10 −9 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.wallpaper; import static android.app.WallpaperManager.LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_UNKNOWN; import static android.app.WallpaperManager.PORTRAIT; import static android.app.WallpaperManager.SQUARE_LANDSCAPE; import static android.app.WallpaperManager.SQUARE_PORTRAIT; import static android.app.WallpaperManager.ORIENTATION_PORTRAIT; import static android.app.WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_SQUARE_PORTRAIT; import static android.app.WallpaperManager.getOrientation; import static android.app.WallpaperManager.getRotatedOrientation; Loading Loading @@ -406,15 +406,16 @@ public class WallpaperCropperTest { setUpWithDisplays(STANDARD_DISPLAY); Point bitmapSize = new Point(800, 1000); SparseArray<Rect> suggestedCrops = new SparseArray<>(); suggestedCrops.put(PORTRAIT, new Rect(0, 0, 400, 800)); for (int otherOrientation: List.of(LANDSCAPE, SQUARE_LANDSCAPE, SQUARE_PORTRAIT)) { suggestedCrops.put(ORIENTATION_PORTRAIT, new Rect(0, 0, 400, 800)); for (int otherOrientation: List.of(ORIENTATION_LANDSCAPE, ORIENTATION_SQUARE_LANDSCAPE, ORIENTATION_SQUARE_PORTRAIT)) { suggestedCrops.put(otherOrientation, new Rect(0, 0, 10, 10)); } for (boolean rtl : List.of(false, true)) { assertThat(mWallpaperCropper.getCrop( new Point(300, 800), bitmapSize, suggestedCrops, rtl)) .isEqualTo(suggestedCrops.get(PORTRAIT)); .isEqualTo(suggestedCrops.get(ORIENTATION_PORTRAIT)); assertThat(mWallpaperCropper.getCrop( new Point(500, 800), bitmapSize, suggestedCrops, rtl)) .isEqualTo(new Rect(0, 0, 500, 800)); Loading @@ -440,8 +441,8 @@ public class WallpaperCropperTest { Point landscape = new Point(PORTRAIT_ONE.y, PORTRAIT_ONE.x); Point squarePortrait = SQUARE_PORTRAIT_ONE; Point squareLandscape = new Point(SQUARE_PORTRAIT_ONE.y, SQUARE_PORTRAIT_ONE.y); suggestedCrops.put(PORTRAIT, centerOf(bitmapRect, portrait)); suggestedCrops.put(SQUARE_LANDSCAPE, centerOf(bitmapRect, squareLandscape)); suggestedCrops.put(ORIENTATION_PORTRAIT, centerOf(bitmapRect, portrait)); suggestedCrops.put(ORIENTATION_SQUARE_LANDSCAPE, centerOf(bitmapRect, squareLandscape)); for (boolean rtl : List.of(false, true)) { assertThat(mWallpaperCropper.getCrop( landscape, bitmapSize, suggestedCrops, rtl)) Loading Loading
core/java/android/app/WallpaperManager.java +17 −17 Original line number Diff line number Diff line Loading @@ -319,12 +319,12 @@ public class WallpaperManager { * This is only used internally by the framework and the WallpaperBackupAgent. * @hide */ @IntDef(value = { @IntDef(prefix = { "ORIENTATION_" }, value = { ORIENTATION_UNKNOWN, PORTRAIT, LANDSCAPE, SQUARE_PORTRAIT, SQUARE_LANDSCAPE, ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE, ORIENTATION_SQUARE_PORTRAIT, ORIENTATION_SQUARE_LANDSCAPE, }) @Retention(RetentionPolicy.SOURCE) public @interface ScreenOrientation {} Loading @@ -338,25 +338,25 @@ public class WallpaperManager { * Portrait orientation of most screens * @hide */ public static final int PORTRAIT = 0; public static final int ORIENTATION_PORTRAIT = 0; /** * Landscape orientation of most screens * @hide */ public static final int LANDSCAPE = 1; public static final int ORIENTATION_LANDSCAPE = 1; /** * Portrait orientation with similar width and height (e.g. the inner screen of a foldable) * @hide */ public static final int SQUARE_PORTRAIT = 2; public static final int ORIENTATION_SQUARE_PORTRAIT = 2; /** * Landscape orientation with similar width and height (e.g. the inner screen of a foldable) * @hide */ public static final int SQUARE_LANDSCAPE = 3; public static final int ORIENTATION_SQUARE_LANDSCAPE = 3; /** * Converts a (width, height) screen size to a {@link ScreenOrientation}. Loading @@ -367,10 +367,10 @@ public class WallpaperManager { public static @ScreenOrientation int getOrientation(Point screenSize) { float ratio = ((float) screenSize.x) / screenSize.y; // ratios between 3/4 and 4/3 are considered square return ratio >= 4 / 3f ? LANDSCAPE : ratio > 1f ? SQUARE_LANDSCAPE : ratio > 3 / 4f ? SQUARE_PORTRAIT : PORTRAIT; return ratio >= 4 / 3f ? ORIENTATION_LANDSCAPE : ratio > 1f ? ORIENTATION_SQUARE_LANDSCAPE : ratio > 3 / 4f ? ORIENTATION_SQUARE_PORTRAIT : ORIENTATION_PORTRAIT; } /** Loading @@ -379,10 +379,10 @@ public class WallpaperManager { */ public static @ScreenOrientation int getRotatedOrientation(@ScreenOrientation int orientation) { switch (orientation) { case PORTRAIT: return LANDSCAPE; case LANDSCAPE: return PORTRAIT; case SQUARE_PORTRAIT: return SQUARE_LANDSCAPE; case SQUARE_LANDSCAPE: return SQUARE_PORTRAIT; case ORIENTATION_PORTRAIT: return ORIENTATION_LANDSCAPE; case ORIENTATION_LANDSCAPE: return ORIENTATION_PORTRAIT; case ORIENTATION_SQUARE_PORTRAIT: return ORIENTATION_SQUARE_LANDSCAPE; case ORIENTATION_SQUARE_LANDSCAPE: return ORIENTATION_SQUARE_PORTRAIT; default: return ORIENTATION_UNKNOWN; } } Loading
packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +5 −4 Original line number Diff line number Diff line Loading @@ -945,10 +945,11 @@ public class WallpaperBackupAgent extends BackupAgent { String tag = parser.getName(); if (!sectionTag.equals(tag)) continue; for (Pair<Integer, String> pair : List.of( new Pair<>(WallpaperManager.PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.SQUARE_LANDSCAPE, "SquareLandscape"))) { new Pair<>(WallpaperManager.ORIENTATION_PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.ORIENTATION_LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, "SquareLandscape"))) { Rect cropHint = new Rect( getAttributeInt(parser, "cropLeft" + pair.second, 0), getAttributeInt(parser, "cropTop" + pair.second, 0), Loading
packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java +9 −8 Original line number Diff line number Diff line Loading @@ -827,16 +827,17 @@ public class WallpaperBackupAgentTest { @Test public void testOnRestore_singleCropHint() throws Exception { Map<Integer, Rect> testMap = Map.of(WallpaperManager.PORTRAIT, new Rect(1, 2, 3, 4)); Map<Integer, Rect> testMap = Map.of( WallpaperManager.ORIENTATION_PORTRAIT, new Rect(1, 2, 3, 4)); testParseCropHints(testMap); } @Test public void testOnRestore_multipleCropHints() throws Exception { Map<Integer, Rect> testMap = Map.of( WallpaperManager.PORTRAIT, new Rect(1, 2, 3, 4), WallpaperManager.SQUARE_PORTRAIT, new Rect(5, 6, 7, 8), WallpaperManager.SQUARE_LANDSCAPE, new Rect(9, 10, 11, 12)); WallpaperManager.ORIENTATION_PORTRAIT, new Rect(1, 2, 3, 4), WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, new Rect(5, 6, 7, 8), WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, new Rect(9, 10, 11, 12)); testParseCropHints(testMap); } Loading Loading @@ -936,10 +937,10 @@ public class WallpaperBackupAgentTest { out.startTag(null, "wp"); for (Map.Entry<Integer, Rect> entry: crops.entrySet()) { String orientation = switch (entry.getKey()) { case WallpaperManager.PORTRAIT -> "Portrait"; case WallpaperManager.LANDSCAPE -> "Landscape"; case WallpaperManager.SQUARE_PORTRAIT -> "SquarePortrait"; case WallpaperManager.SQUARE_LANDSCAPE -> "SquareLandscape"; case WallpaperManager.ORIENTATION_PORTRAIT -> "Portrait"; case WallpaperManager.ORIENTATION_LANDSCAPE -> "Landscape"; case WallpaperManager.ORIENTATION_SQUARE_PORTRAIT -> "SquarePortrait"; case WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE -> "SquareLandscape"; default -> throw new IllegalArgumentException("Invalid orientation"); }; Rect rect = entry.getValue(); Loading
services/core/java/com/android/server/wallpaper/WallpaperDataParser.java +4 −4 Original line number Diff line number Diff line Loading @@ -745,9 +745,9 @@ public class WallpaperDataParser { private static List<Pair<Integer, String>> screenDimensionPairs() { return List.of( new Pair<>(WallpaperManager.PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.SQUARE_LANDSCAPE, "SquareLandscape")); new Pair<>(WallpaperManager.ORIENTATION_PORTRAIT, "Portrait"), new Pair<>(WallpaperManager.ORIENTATION_LANDSCAPE, "Landscape"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_PORTRAIT, "SquarePortrait"), new Pair<>(WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE, "SquareLandscape")); } }
services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperCropperTest.java +10 −9 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.wallpaper; import static android.app.WallpaperManager.LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_UNKNOWN; import static android.app.WallpaperManager.PORTRAIT; import static android.app.WallpaperManager.SQUARE_LANDSCAPE; import static android.app.WallpaperManager.SQUARE_PORTRAIT; import static android.app.WallpaperManager.ORIENTATION_PORTRAIT; import static android.app.WallpaperManager.ORIENTATION_SQUARE_LANDSCAPE; import static android.app.WallpaperManager.ORIENTATION_SQUARE_PORTRAIT; import static android.app.WallpaperManager.getOrientation; import static android.app.WallpaperManager.getRotatedOrientation; Loading Loading @@ -406,15 +406,16 @@ public class WallpaperCropperTest { setUpWithDisplays(STANDARD_DISPLAY); Point bitmapSize = new Point(800, 1000); SparseArray<Rect> suggestedCrops = new SparseArray<>(); suggestedCrops.put(PORTRAIT, new Rect(0, 0, 400, 800)); for (int otherOrientation: List.of(LANDSCAPE, SQUARE_LANDSCAPE, SQUARE_PORTRAIT)) { suggestedCrops.put(ORIENTATION_PORTRAIT, new Rect(0, 0, 400, 800)); for (int otherOrientation: List.of(ORIENTATION_LANDSCAPE, ORIENTATION_SQUARE_LANDSCAPE, ORIENTATION_SQUARE_PORTRAIT)) { suggestedCrops.put(otherOrientation, new Rect(0, 0, 10, 10)); } for (boolean rtl : List.of(false, true)) { assertThat(mWallpaperCropper.getCrop( new Point(300, 800), bitmapSize, suggestedCrops, rtl)) .isEqualTo(suggestedCrops.get(PORTRAIT)); .isEqualTo(suggestedCrops.get(ORIENTATION_PORTRAIT)); assertThat(mWallpaperCropper.getCrop( new Point(500, 800), bitmapSize, suggestedCrops, rtl)) .isEqualTo(new Rect(0, 0, 500, 800)); Loading @@ -440,8 +441,8 @@ public class WallpaperCropperTest { Point landscape = new Point(PORTRAIT_ONE.y, PORTRAIT_ONE.x); Point squarePortrait = SQUARE_PORTRAIT_ONE; Point squareLandscape = new Point(SQUARE_PORTRAIT_ONE.y, SQUARE_PORTRAIT_ONE.y); suggestedCrops.put(PORTRAIT, centerOf(bitmapRect, portrait)); suggestedCrops.put(SQUARE_LANDSCAPE, centerOf(bitmapRect, squareLandscape)); suggestedCrops.put(ORIENTATION_PORTRAIT, centerOf(bitmapRect, portrait)); suggestedCrops.put(ORIENTATION_SQUARE_LANDSCAPE, centerOf(bitmapRect, squareLandscape)); for (boolean rtl : List.of(false, true)) { assertThat(mWallpaperCropper.getCrop( landscape, bitmapSize, suggestedCrops, rtl)) Loading