diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index a2cacc5ed2c01..ff17824565967 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -1499,6 +1499,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. + * + *

+ * In order to use this, apps should declare a {@code } tag with the action + * {@code "android.service.wallpaper.WallpaperService"}. Otherwise, + * this method will return {@code null} if the caller doesn't otherwise have + * visibility of the wallpaper package. + *

*/ public WallpaperInfo getWallpaperInfo() { return getWallpaperInfoForUser(mContext.getUserId()); @@ -1520,6 +1527,13 @@ public class WallpaperManager { * wallpaper component. Otherwise, if the wallpaper is a static image or is not set, this * returns null. * + *

+ * In order to use this, apps should declare a {@code } tag with the action + * {@code "android.service.wallpaper.WallpaperService"}. Otherwise, + * this method will return {@code null} if the caller doesn't otherwise have + * visibility of the wallpaper package. + *

+ * * @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}}. diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 262b964ea720f..5fd57e3f5dafb 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -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; }