Stop requiring QUERY_ALL_PACKAGES for getWallpaperInfo

Instead, we now do a check packageManagerInternal.canQueryPackage(Binder.getCallingUid(), info.getComponent().getPackageName()).

Bug: 248219671
Test: atest CtsWallpaperTestCases
Change-Id: I3b4c82ba2517fc6439b8302135c20c79d6d012b9
This commit is contained in:
Aurélien Pomini
2023-02-01 12:33:07 +00:00
parent 69e586c6ff
commit 47f2618db2
2 changed files with 32 additions and 13 deletions

View File

@@ -1496,6 +1496,13 @@ public class WallpaperManager {
/**
* Returns the information about the home screen wallpaper if its current wallpaper is a live
* wallpaper component. Otherwise, if the wallpaper is a static image, this returns null.
*
* <p>
* In order to use this, apps should declare a {@code <queries>} tag with the action
* {@code "android.service.wallpaper.WallpaperService"}. Otherwise,
* this method will return {@code null} if the caller doesn't otherwise have
* <a href="{@docRoot}training/package-visibility">visibility</a> of the wallpaper package.
* </p>
*/
public WallpaperInfo getWallpaperInfo() {
return getWallpaperInfoForUser(mContext.getUserId());
@@ -1517,6 +1524,13 @@ public class WallpaperManager {
* wallpaper component. Otherwise, if the wallpaper is a static image or is not set, this
* returns null.
*
* <p>
* In order to use this, apps should declare a {@code <queries>} tag with the action
* {@code "android.service.wallpaper.WallpaperService"}. Otherwise,
* this method will return {@code null} if the caller doesn't otherwise have
* <a href="{@docRoot}training/package-visibility">visibility</a> of the wallpaper package.
* </p>
*
* @param which Specifies wallpaper to request (home or lock).
* @throws IllegalArgumentException if {@code which} is not exactly one of
* {{@link #FLAG_SYSTEM},{@link #FLAG_LOCK}}.

View File

@@ -17,7 +17,6 @@
package com.android.server.wallpaper;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.QUERY_ALL_PACKAGES;
import static android.Manifest.permission.READ_WALLPAPER_INTERNAL;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.WallpaperManager.COMMAND_REAPPLY;
@@ -67,6 +66,7 @@ import android.content.ServiceConnection;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
@@ -759,6 +759,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
private final Context mContext;
private final WindowManagerInternal mWindowManagerInternal;
private final PackageManagerInternal mPackageManagerInternal;
private final IPackageManager mIPackageManager;
private final ActivityManager mActivityManager;
private final MyPackageMonitor mMonitor;
@@ -1604,6 +1605,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
context.getResources().getString(R.string.image_wallpaper_component));
mDefaultWallpaperComponent = WallpaperManager.getDefaultWallpaperComponent(context);
mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
mIPackageManager = AppGlobals.getPackageManager();
mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
DisplayManager dm = mContext.getSystemService(DisplayManager.class);
@@ -2283,20 +2285,23 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
@Override
public WallpaperInfo getWallpaperInfoWithFlags(@SetWallpaperFlags int which, int userId) {
final boolean allow =
hasPermission(READ_WALLPAPER_INTERNAL) || hasPermission(QUERY_ALL_PACKAGES);
if (allow) {
userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, true, "getWallpaperInfo", null);
synchronized (mLock) {
WallpaperData wallpaper = (which == FLAG_LOCK) ? mLockWallpaperMap.get(userId)
: mWallpaperMap.get(userId);
if (wallpaper != null && wallpaper.connection != null) {
return wallpaper.connection.mInfo;
}
userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, true, "getWallpaperInfo", null);
synchronized (mLock) {
WallpaperData wallpaper = (which == FLAG_LOCK) ? mLockWallpaperMap.get(userId)
: mWallpaperMap.get(userId);
if (wallpaper == null
|| wallpaper.connection == null
|| wallpaper.connection.mInfo == null) return null;
WallpaperInfo info = wallpaper.connection.mInfo;
if (hasPermission(READ_WALLPAPER_INTERNAL)
|| mPackageManagerInternal.canQueryPackage(
Binder.getCallingUid(), info.getComponent().getPackageName())) {
return info;
}
}
return null;
}