Unfocus wallpaper updated with permission
This commit is a refractoring of ag/20338859. The change gives apps
with android.permission.ALWAYS_UPDATE_WALLPAPER to update the wallpaper
even if the wallpaper is out of focus.
The permission is given to home role owners, and is intended to be used
by wear targets only.
Bug: 271132915
Test: run cts -m CtsWallpaperTestCases
Change-Id: I4471a7e13ce8f3c52e1f5e6288a5e0f2b290955b
diff --git a/core/api/current.txt b/core/api/current.txt
index 5a16910..fe3b4b3 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -7599,7 +7599,7 @@
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_EXTERNAL_STORAGE, "android.permission.READ_WALLPAPER_INTERNAL"}) public android.graphics.drawable.Drawable peekFastDrawable();
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_EXTERNAL_STORAGE, "android.permission.READ_WALLPAPER_INTERNAL"}) public android.graphics.drawable.Drawable peekFastDrawable(int);
method public void removeOnColorsChangedListener(@NonNull android.app.WallpaperManager.OnColorsChangedListener);
- method public void sendWallpaperCommand(android.os.IBinder, String, int, int, int, android.os.Bundle);
+ method @RequiresPermission(value="android.permission.ALWAYS_UPDATE_WALLPAPER", conditional=true) public void sendWallpaperCommand(android.os.IBinder, String, int, int, int, android.os.Bundle);
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public void setBitmap(android.graphics.Bitmap) throws java.io.IOException;
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean, int) throws java.io.IOException;
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 431b48b..92b422d 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -36,6 +36,7 @@
field public static final String ALLOW_ANY_CODEC_FOR_PLAYBACK = "android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK";
field public static final String ALLOW_PLACE_IN_MULTI_PANE_SETTINGS = "android.permission.ALLOW_PLACE_IN_MULTI_PANE_SETTINGS";
field public static final String ALLOW_SLIPPERY_TOUCHES = "android.permission.ALLOW_SLIPPERY_TOUCHES";
+ field public static final String ALWAYS_UPDATE_WALLPAPER = "android.permission.ALWAYS_UPDATE_WALLPAPER";
field public static final String AMBIENT_WALLPAPER = "android.permission.AMBIENT_WALLPAPER";
field public static final String APPROVE_INCIDENT_REPORTS = "android.permission.APPROVE_INCIDENT_REPORTS";
field public static final String ASSOCIATE_COMPANION_DEVICES = "android.permission.ASSOCIATE_COMPANION_DEVICES";
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 201189e..c74ce2e 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -2615,6 +2615,8 @@
* @param z Arbitrary integer argument based on command.
* @param extras Optional additional information for the command, or null.
*/
+ @RequiresPermission(value = android.Manifest.permission.ALWAYS_UPDATE_WALLPAPER,
+ conditional = true)
public void sendWallpaperCommand(IBinder windowToken, String action,
int x, int y, int z, Bundle extras) {
try {
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 7911933..a04faa4 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -4029,6 +4029,13 @@
<permission android:name="android.permission.READ_WALLPAPER_INTERNAL"
android:protectionLevel="signature|privileged" />
+ <!-- Allow apps to always update wallpaper by sending data.
+ @SystemApi
+ @hide
+ -->
+ <permission android:name="android.permission.ALWAYS_UPDATE_WALLPAPER"
+ android:protectionLevel="internal|role" />
+
<!-- ===================================================== -->
<!-- Permissions for changing the system clock / time zone -->
<!-- ===================================================== -->
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index 1515798..ffe73d3 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -843,11 +843,15 @@
<!-- Permission required for GTS test - GtsCredentialsTestCases -->
<uses-permission android:name="android.permission.LAUNCH_CREDENTIAL_SELECTOR" />
+ <!-- Permission required for CTS test - CtsWallpaperTestCases -->
+ <uses-permission android:name="android.permission.ALWAYS_UPDATE_WALLPAPER" />
+
<application
android:label="@string/app_label"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
android:defaultToDeviceProtectedStorage="true"
android:directBootAware="true">
+
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.android.shell"
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
index 7b10c63..7eea42f 100644
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.Manifest.permission.ALWAYS_UPDATE_WALLPAPER;
import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
@@ -112,6 +113,7 @@
final boolean mCanCreateSystemApplicationOverlay;
final boolean mCanHideNonSystemOverlayWindows;
final boolean mCanSetUnrestrictedGestureExclusion;
+ final boolean mCanAlwaysUpdateWallpaper;
private AlertWindowNotification mAlertWindowNotification;
private boolean mShowingAlertWindowNotificationAllowed;
private boolean mClientDead = false;
@@ -144,6 +146,9 @@
mCanSetUnrestrictedGestureExclusion =
service.mContext.checkCallingOrSelfPermission(SET_UNRESTRICTED_GESTURE_EXCLUSION)
== PERMISSION_GRANTED;
+ mCanAlwaysUpdateWallpaper =
+ service.mContext.checkCallingOrSelfPermission(ALWAYS_UPDATE_WALLPAPER)
+ == PERMISSION_GRANTED;
mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
mDragDropController = mService.mDragDropController;
StringBuilder sb = new StringBuilder();
@@ -621,8 +626,15 @@
final long ident = Binder.clearCallingIdentity();
try {
final WindowState windowState = mService.windowForClientLocked(this, window, true);
- return windowState.getDisplayContent().mWallpaperController
- .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
+ WallpaperController wallpaperController =
+ windowState.getDisplayContent().mWallpaperController;
+ if (mCanAlwaysUpdateWallpaper
+ || windowState == wallpaperController.getWallpaperTarget()
+ || windowState == wallpaperController.getPrevWallpaperTarget()) {
+ return wallpaperController.sendWindowWallpaperCommandUnchecked(
+ windowState, action, x, y, z, extras, sync);
+ }
+ return null;
} finally {
Binder.restoreCallingIdentity(ident);
}
diff --git a/services/core/java/com/android/server/wm/WallpaperController.java b/services/core/java/com/android/server/wm/WallpaperController.java
index edafe06..799dc02 100644
--- a/services/core/java/com/android/server/wm/WallpaperController.java
+++ b/services/core/java/com/android/server/wm/WallpaperController.java
@@ -291,6 +291,10 @@
return mWallpaperTarget;
}
+ WindowState getPrevWallpaperTarget() {
+ return mPrevWallpaperTarget;
+ }
+
boolean isWallpaperTarget(WindowState win) {
return win == mWallpaperTarget;
}
@@ -589,12 +593,10 @@
}
}
- Bundle sendWindowWallpaperCommand(
- WindowState window, String action, int x, int y, int z, Bundle extras, boolean sync) {
- if (window == mWallpaperTarget || window == mPrevWallpaperTarget) {
- sendWindowWallpaperCommand(action, x, y, z, extras, sync);
- }
-
+ Bundle sendWindowWallpaperCommandUnchecked(
+ WindowState window, String action, int x, int y, int z,
+ Bundle extras, boolean sync) {
+ sendWindowWallpaperCommand(action, x, y, z, extras, sync);
return null;
}