summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aurélien Pomini <pomini@google.com> 2024-11-11 15:57:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-11 15:57:19 +0000
commitba766939f95e718c28df8d39fcdd94d6ea0d9a57 (patch)
treefdd0afa05634becc0394ea55979ad3218fabae28
parentc5eb0ab4bd107031a4b7882a75dad38f7ea9c956 (diff)
parent17bcaa18034fc629c0f565123bc9b319f1f9464d (diff)
Merge changes from topic "wallpaper-crop-systemapi" into main
* changes: New getBitmapCrops API, move some @hide to SystemAPIs Make new WallpaperManager helpers @TestApi
-rw-r--r--core/api/system-current.txt8
-rw-r--r--core/api/test-current.txt4
-rw-r--r--core/java/android/app/DisabledWallpaperManager.java12
-rw-r--r--core/java/android/app/IWallpaperManager.aidl10
-rw-r--r--core/java/android/app/WallpaperManager.java99
-rw-r--r--core/java/android/app/wallpaper.aconfig8
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java21
7 files changed, 146 insertions, 16 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 8954f8e70157..70fbad01cae6 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -1270,13 +1270,21 @@ package android.app {
public class WallpaperManager {
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public void clearWallpaper(int, int);
+ method @FlaggedApi("android.app.customization_packs_apis") @NonNull @RequiresPermission(android.Manifest.permission.READ_WALLPAPER_INTERNAL) public android.util.SparseArray<android.graphics.Rect> getBitmapCrops(int);
+ method @FlaggedApi("android.app.customization_packs_apis") public static int getOrientation(@NonNull android.graphics.Point);
method @FloatRange(from=0.0f, to=1.0f) @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) public float getWallpaperDimAmount();
+ method @FlaggedApi("android.app.customization_packs_apis") @Nullable public android.os.ParcelFileDescriptor getWallpaperFile(int, boolean);
method @FlaggedApi("android.app.live_wallpaper_content_handling") @Nullable @RequiresPermission(android.Manifest.permission.READ_WALLPAPER_INTERNAL) public android.app.wallpaper.WallpaperInstance getWallpaperInstance(int);
method public void setDisplayOffset(android.os.IBinder, int, int);
+ method @FlaggedApi("com.android.window.flags.multi_crop") @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public int setStreamWithCrops(@NonNull java.io.InputStream, @NonNull android.util.SparseArray<android.graphics.Rect>, boolean, int) throws java.io.IOException;
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) public boolean setWallpaperComponent(android.content.ComponentName);
method @FlaggedApi("android.app.live_wallpaper_content_handling") @RequiresPermission(allOf={android.Manifest.permission.SET_WALLPAPER_COMPONENT, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}, conditional=true) public boolean setWallpaperComponentWithDescription(@NonNull android.app.wallpaper.WallpaperDescription, int);
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) public boolean setWallpaperComponentWithFlags(@NonNull android.content.ComponentName, int);
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) public void setWallpaperDimAmount(@FloatRange(from=0.0f, to=1.0f) float);
+ field @FlaggedApi("android.app.customization_packs_apis") public static final int ORIENTATION_LANDSCAPE = 1; // 0x1
+ field @FlaggedApi("android.app.customization_packs_apis") public static final int ORIENTATION_PORTRAIT = 0; // 0x0
+ field @FlaggedApi("android.app.customization_packs_apis") public static final int ORIENTATION_SQUARE_LANDSCAPE = 3; // 0x3
+ field @FlaggedApi("android.app.customization_packs_apis") public static final int ORIENTATION_SQUARE_PORTRAIT = 2; // 0x2
}
}
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 3ca55b932e19..c8ecfa94ec87 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -535,9 +535,13 @@ package android.app {
public class WallpaperManager {
method @Nullable public android.graphics.Bitmap getBitmap();
method @Nullable public android.graphics.Bitmap getBitmapAsUser(int, boolean, int);
+ method @FlaggedApi("com.android.window.flags.multi_crop") @NonNull @RequiresPermission(android.Manifest.permission.READ_WALLPAPER_INTERNAL) public java.util.List<android.graphics.Rect> getBitmapCrops(@NonNull java.util.List<android.graphics.Point>, int, boolean);
+ method @FlaggedApi("com.android.window.flags.multi_crop") @NonNull public java.util.List<android.graphics.Rect> getBitmapCrops(@NonNull android.graphics.Point, @NonNull java.util.List<android.graphics.Point>, @Nullable java.util.Map<android.graphics.Point,android.graphics.Rect>);
method public boolean isLockscreenLiveWallpaperEnabled();
method @Nullable public android.graphics.Rect peekBitmapDimensions();
method @Nullable public android.graphics.Rect peekBitmapDimensions(int);
+ method @FlaggedApi("com.android.window.flags.multi_crop") @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public int setBitmapWithCrops(@Nullable android.graphics.Bitmap, @NonNull java.util.Map<android.graphics.Point,android.graphics.Rect>, boolean, int) throws java.io.IOException;
+ method @FlaggedApi("com.android.window.flags.multi_crop") @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public int setStreamWithCrops(@NonNull java.io.InputStream, @NonNull java.util.Map<android.graphics.Point,android.graphics.Rect>, boolean, int) throws java.io.IOException;
method public void setWallpaperZoomOut(@NonNull android.os.IBinder, float);
method public boolean shouldEnableWideColorGamut();
method public boolean wallpaperSupportsWcg(int);
diff --git a/core/java/android/app/DisabledWallpaperManager.java b/core/java/android/app/DisabledWallpaperManager.java
index b06fb9e2f284..233dc75b810f 100644
--- a/core/java/android/app/DisabledWallpaperManager.java
+++ b/core/java/android/app/DisabledWallpaperManager.java
@@ -177,6 +177,13 @@ final class DisabledWallpaperManager extends WallpaperManager {
}
@Override
+ @NonNull
+ public SparseArray<Rect> getBitmapCrops(int which) {
+ unsupported();
+ return new SparseArray<>();
+ }
+
+ @Override
public List<Rect> getBitmapCrops(@NonNull Point bitmapSize, @NonNull List<Point> displaySizes,
@Nullable Map<Point, Rect> cropHints) {
return unsupported();
@@ -358,8 +365,9 @@ final class DisabledWallpaperManager extends WallpaperManager {
@Override
- public int setStreamWithCrops(InputStream bitmapData, @NonNull SparseArray<Rect> cropHints,
- boolean allowBackup, @SetWallpaperFlags int which) throws IOException {
+ public int setStreamWithCrops(@NonNull InputStream bitmapData,
+ @NonNull SparseArray<Rect> cropHints, boolean allowBackup, @SetWallpaperFlags int which
+ ) throws IOException {
return unsupportedInt();
}
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl
index f693e9ba11ec..6449ea1742a1 100644
--- a/core/java/android/app/IWallpaperManager.aidl
+++ b/core/java/android/app/IWallpaperManager.aidl
@@ -97,6 +97,16 @@ interface IWallpaperManager {
List getBitmapCrops(in List<Point> displaySizes, int which, boolean originalBitmap, int userId);
/**
+ * For a given user, if the wallpaper of the specified which is an ImageWallpaper, return
+ * a bundle which is a Map<Integer, Rect> containing the custom cropHints that were sent to
+ * setBitmapWithCrops or setStreamWithCrops. These crops are relative to the original bitmap.
+ * If the wallpaper isn't an ImageWallpaper, return null.
+ */
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.READ_WALLPAPER_INTERNAL)")
+ @SuppressWarnings(value={"untyped-collection"})
+ Bundle getCurrentBitmapCrops(int which, int userId);
+
+ /**
* Return how a bitmap of a given size would be cropped for a given list of display sizes when
* set with the given suggested crops.
* @hide
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 479f3df9affb..abb2dd465576 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -19,9 +19,10 @@ package android.app;
import static android.Manifest.permission.MANAGE_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_WALLPAPER_INTERNAL;
import static android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT;
+import static android.app.Flags.FLAG_CUSTOMIZATION_PACKS_APIS;
+import static android.app.Flags.FLAG_LIVE_WALLPAPER_CONTENT_HANDLING;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
-import static android.app.Flags.FLAG_LIVE_WALLPAPER_CONTENT_HANDLING;
import static com.android.window.flags.Flags.FLAG_MULTI_CROP;
import static com.android.window.flags.Flags.multiCrop;
@@ -342,24 +343,32 @@ public class WallpaperManager {
* Portrait orientation of most screens
* @hide
*/
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
public static final int ORIENTATION_PORTRAIT = 0;
/**
* Landscape orientation of most screens
* @hide
*/
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
public static final int ORIENTATION_LANDSCAPE = 1;
/**
* Portrait orientation with similar width and height (e.g. the inner screen of a foldable)
* @hide
*/
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
public static final int ORIENTATION_SQUARE_PORTRAIT = 2;
/**
* Landscape orientation with similar width and height (e.g. the inner screen of a foldable)
* @hide
*/
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
public static final int ORIENTATION_SQUARE_LANDSCAPE = 3;
/**
@@ -368,7 +377,9 @@ public class WallpaperManager {
* @return the corresponding {@link ScreenOrientation}.
* @hide
*/
- public static @ScreenOrientation int getOrientation(Point screenSize) {
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
+ public static @ScreenOrientation int getOrientation(@NonNull Point screenSize) {
float ratio = ((float) screenSize.x) / screenSize.y;
// ratios between 3/4 and 4/3 are considered square
return ratio >= 4 / 3f ? ORIENTATION_LANDSCAPE
@@ -1623,14 +1634,15 @@ public class WallpaperManager {
* If false, return areas relative to the cropped bitmap.
* @return A List of Rect where the Rect is within the cropped/original bitmap, and corresponds
* to what is displayed. The Rect may have a larger width/height ratio than the screen
- * due to parallax. Return {@code null} if the wallpaper is not an ImageWallpaper.
- * Also return {@code null} when called with which={@link #FLAG_LOCK} if there is a
+ * due to parallax. Return an empty list if the wallpaper is not an ImageWallpaper.
+ * Also return an empty list when called with which={@link #FLAG_LOCK} if there is a
* shared home + lock wallpaper.
* @hide
*/
@FlaggedApi(FLAG_MULTI_CROP)
+ @TestApi
@RequiresPermission(READ_WALLPAPER_INTERNAL)
- @Nullable
+ @NonNull
public List<Rect> getBitmapCrops(@NonNull List<Point> displaySizes,
@SetWallpaperFlags int which, boolean originalBitmap) {
checkExactlyOneWallpaperFlagSet(which);
@@ -1653,6 +1665,52 @@ public class WallpaperManager {
}
/**
+ * For the current user, if the wallpaper of the specified destination is an ImageWallpaper,
+ * return the custom crops of the wallpaper, that have been provided for example via
+ * {@link #setStreamWithCrops}. These crops are relative to the original bitmap.
+ * <p>
+ * This method helps apps that change wallpapers provide an undo option. Calling
+ * {@link #setStreamWithCrops(InputStream, SparseArray, boolean, int)} with this SparseArray and
+ * the current original bitmap file, that can be obtained with {@link #getWallpaperFile(int,
+ * boolean)} with {@code getCropped=false}, will exactly lead to the current wallpaper state.
+ *
+ * @param which wallpaper type. Must be either {@link #FLAG_SYSTEM} or {@link #FLAG_LOCK}.
+ * @return A map from {{@link #ORIENTATION_PORTRAIT}, {@link #ORIENTATION_LANDSCAPE},
+ * {@link #ORIENTATION_SQUARE_PORTRAIT}, {{@link #ORIENTATION_SQUARE_LANDSCAPE}}} to
+ * Rect, representing the custom cropHints. The map can be empty and will only contains
+ * entries for screen orientations for which a custom crop was provided. If no custom
+ * crop is provided for an orientation, the system will infer the crop based on the
+ * custom crops of the other orientations; or center-align the full image if no custom
+ * crops are provided at all.
+ * <p>
+ * Return an empty map if the wallpaper is not an ImageWallpaper. Also return
+ * an empty map when called with which={@link #FLAG_LOCK} if there is a shared
+ * home + lock wallpaper.
+ *
+ * @hide
+ */
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
+ @RequiresPermission(READ_WALLPAPER_INTERNAL)
+ @NonNull
+ public SparseArray<Rect> getBitmapCrops(@SetWallpaperFlags int which) {
+ checkExactlyOneWallpaperFlagSet(which);
+ try {
+ Bundle bundle = sGlobals.mService.getCurrentBitmapCrops(which, mContext.getUserId());
+ SparseArray<Rect> result = new SparseArray<>();
+ if (bundle == null) return result;
+ for (String key : bundle.keySet()) {
+ int intKey = Integer.parseInt(key);
+ Rect rect = bundle.getParcelable(key, Rect.class);
+ result.put(intKey, rect);
+ }
+ return result;
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* For preview purposes.
* Return how a bitmap of a given size would be cropped for a given list of display sizes, if
* it was set as wallpaper via {@link #setBitmapWithCrops(Bitmap, Map, boolean, int)} or
@@ -1664,7 +1722,8 @@ public class WallpaperManager {
* @hide
*/
@FlaggedApi(FLAG_MULTI_CROP)
- @Nullable
+ @TestApi
+ @NonNull
public List<Rect> getBitmapCrops(@NonNull Point bitmapSize, @NonNull List<Point> displaySizes,
@Nullable Map<Point, Rect> cropHints) {
try {
@@ -1890,9 +1949,14 @@ public class WallpaperManager {
* defined kind of wallpaper, either {@link #FLAG_SYSTEM} or {@link #FLAG_LOCK}.
* @param getCropped If true the cropped file will be retrieved, if false the original will
* be retrieved.
- *
+ * @return A ParcelFileDescriptor for the wallpaper bitmap of the given destination, if it's an
+ * ImageWallpaper wallpaper. Return {@code null} if the wallpaper is not an
+ * ImageWallpaper. Also return {@code null} when called with
+ * which={@link #FLAG_LOCK} if there is a shared home + lock wallpaper.
* @hide
*/
+ @FlaggedApi(FLAG_CUSTOMIZATION_PACKS_APIS)
+ @SystemApi
@Nullable
public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, boolean getCropped) {
return getWallpaperFile(which, mContext.getUserId(), getCropped);
@@ -2371,7 +2435,6 @@ public class WallpaperManager {
/**
* Version of setBitmap that defines how the wallpaper will be positioned for different
* display sizes.
- * Requires permission {@link android.Manifest.permission#SET_WALLPAPER}.
* @param cropHints map from screen dimensions to a sub-region of the image to display for those
* dimensions. The {@code Rect} sub-region may have a larger width/height ratio
* than the screen dimensions to apply a horizontal parallax effect. If the
@@ -2380,6 +2443,7 @@ public class WallpaperManager {
* @hide
*/
@FlaggedApi(FLAG_MULTI_CROP)
+ @TestApi
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
public int setBitmapWithCrops(@Nullable Bitmap fullImage, @NonNull Map<Point, Rect> cropHints,
boolean allowBackup, @SetWallpaperFlags int which) throws IOException {
@@ -2562,7 +2626,6 @@ public class WallpaperManager {
/**
* Version of setStream that defines how the wallpaper will be positioned for different
* display sizes.
- * Requires permission {@link android.Manifest.permission#SET_WALLPAPER}.
* @param cropHints map from screen dimensions to a sub-region of the image to display for those
* dimensions. The {@code Rect} sub-region may have a larger width/height ratio
* than the screen dimensions to apply a horizontal parallax effect. If the
@@ -2571,9 +2634,11 @@ public class WallpaperManager {
* @hide
*/
@FlaggedApi(FLAG_MULTI_CROP)
+ @TestApi
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
- public int setStreamWithCrops(InputStream bitmapData, @NonNull Map<Point, Rect> cropHints,
- boolean allowBackup, @SetWallpaperFlags int which) throws IOException {
+ public int setStreamWithCrops(@NonNull InputStream bitmapData,
+ @NonNull Map<Point, Rect> cropHints, boolean allowBackup, @SetWallpaperFlags int which)
+ throws IOException {
SparseArray<Rect> crops = new SparseArray<>();
cropHints.forEach((k, v) -> crops.put(getOrientation(k), v));
return setStreamWithCrops(bitmapData, crops, allowBackup, which);
@@ -2583,15 +2648,21 @@ public class WallpaperManager {
* Similar to {@link #setStreamWithCrops(InputStream, Map, boolean, int)}, but using
* {@link ScreenOrientation} as keys of the cropHints map. Used for backup & restore, since
* WallpaperBackupAgent stores orientations rather than the exact display size.
- * Requires permission {@link android.Manifest.permission#SET_WALLPAPER}.
+ * @param bitmapData A stream containing the raw data to install as a wallpaper. This
+ * data can be in any format handled by {@link BitmapRegionDecoder}.
* @param cropHints map from {@link ScreenOrientation} to a sub-region of the image to display
* for that screen orientation.
+ * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper
+ * image for restore to a future device; {@code false} otherwise.
+ * @param which Flags indicating which wallpaper(s) to configure with the new imagery.
* @hide
*/
@FlaggedApi(FLAG_MULTI_CROP)
+ @SystemApi
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
- public int setStreamWithCrops(InputStream bitmapData, @NonNull SparseArray<Rect> cropHints,
- boolean allowBackup, @SetWallpaperFlags int which) throws IOException {
+ public int setStreamWithCrops(@NonNull InputStream bitmapData,
+ @NonNull SparseArray<Rect> cropHints, boolean allowBackup, @SetWallpaperFlags int which)
+ throws IOException {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
throw new RuntimeException(new DeadSystemException());
diff --git a/core/java/android/app/wallpaper.aconfig b/core/java/android/app/wallpaper.aconfig
index 4b880d030413..32334d893d75 100644
--- a/core/java/android/app/wallpaper.aconfig
+++ b/core/java/android/app/wallpaper.aconfig
@@ -22,3 +22,11 @@ flag {
bug: "347235611"
is_exported: true
}
+
+flag {
+ name: "customization_packs_apis"
+ is_exported: true
+ namespace: "systemui"
+ description: "Move APIs related to bitmap and crops to @SystemApi."
+ bug: "372344184"
+}
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 10f096c9031b..e29f05336760 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -2410,6 +2410,27 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
@Override
+ public Bundle getCurrentBitmapCrops(int which, int userId) {
+ userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
+ Binder.getCallingUid(), userId, false, true, "getBitmapCrop", null);
+ synchronized (mLock) {
+ checkPermission(READ_WALLPAPER_INTERNAL);
+ WallpaperData wallpaper = (which == FLAG_LOCK) ? mLockWallpaperMap.get(userId)
+ : mWallpaperMap.get(userId);
+ if (wallpaper == null || !mImageWallpaper.equals(wallpaper.getComponent())) {
+ return null;
+ }
+ Bundle bundle = new Bundle();
+ for (int i = 0; i < wallpaper.mCropHints.size(); i++) {
+ String key = String.valueOf(wallpaper.mCropHints.keyAt(i));
+ Rect rect = wallpaper.mCropHints.valueAt(i);
+ bundle.putParcelable(key, rect);
+ }
+ return bundle;
+ }
+ }
+
+ @Override
public List<Rect> getFutureBitmapCrops(Point bitmapSize, List<Point> displaySizes,
int[] screenOrientations, List<Rect> crops) {
SparseArray<Rect> cropMap = getCropMap(screenOrientations, crops);