diff options
| author | 2019-11-18 19:01:35 +0000 | |
|---|---|---|
| committer | 2019-11-18 19:01:35 +0000 | |
| commit | 82865f85c1fc2367165d390ac69e554b494583f6 (patch) | |
| tree | 0069fae232023d62d07df8a20e7d771a985ebdba | |
| parent | d2dca73dc756664c241c091b8edc24cd83f886a5 (diff) | |
| parent | 41ff0f672487cbf54a7ab5b68870bf297bb6f018 (diff) | |
Merge "Pipe featureId from app to noteOp for WallpaperMgr"
4 files changed, 80 insertions, 44 deletions
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl index 7f5350ddd4e0..4cb8d936aa9c 100644 --- a/core/java/android/app/IWallpaperManager.aidl +++ b/core/java/android/app/IWallpaperManager.aidl @@ -58,14 +58,22 @@ interface IWallpaperManager { @UnsupportedAppUsage void setWallpaperComponent(in ComponentName name); + /** - * Get the wallpaper for a given user. + * @deprecated Use {@link #getWallpaperWithFeature(String, IWallpaperManagerCallback, int, + * Bundle, int)} */ @UnsupportedAppUsage ParcelFileDescriptor getWallpaper(String callingPkg, IWallpaperManagerCallback cb, int which, out Bundle outParams, int userId); /** + * Get the wallpaper for a given user. + */ + ParcelFileDescriptor getWallpaperWithFeature(String callingPkg, String callingFeatureId, + IWallpaperManagerCallback cb, int which, out Bundle outParams, int userId); + + /** * Retrieve the given user's current wallpaper ID of the given kind. */ int getWallpaperIdForUser(int which, int userId); diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 59ecf4aa6e8a..41604ec97867 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -458,8 +458,9 @@ public class WallpaperManager { try { Bundle params = new Bundle(); - ParcelFileDescriptor fd = mService.getWallpaper(context.getOpPackageName(), - this, FLAG_SYSTEM, params, userId); + ParcelFileDescriptor fd = mService.getWallpaperWithFeature( + context.getOpPackageName(), context.getFeatureId(), this, FLAG_SYSTEM, + params, userId); if (fd != null) { try { BitmapFactory.Options options = new BitmapFactory.Options(); @@ -985,8 +986,8 @@ public class WallpaperManager { } else { try { Bundle outParams = new Bundle(); - return sGlobals.mService.getWallpaper(mContext.getOpPackageName(), null, which, - outParams, userId); + return sGlobals.mService.getWallpaperWithFeature(mContext.getOpPackageName(), + mContext.getFeatureId(), null, which, outParams, userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } catch (SecurityException e) { diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index ac7a0a8d8b5c..deeeddc5fb71 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -1645,10 +1645,10 @@ public class StorageManager { * Check that given app holds both permission and appop. * @hide */ - public static boolean checkPermissionAndAppOp(Context context, boolean enforce, - int pid, int uid, String packageName, String permission, int op) { - return checkPermissionAndAppOp(context, enforce, pid, uid, packageName, permission, op, - true); + public static boolean checkPermissionAndAppOp(Context context, boolean enforce, int pid, + int uid, String packageName, @NonNull String featureId, String permission, int op) { + return checkPermissionAndAppOp(context, enforce, pid, uid, packageName, featureId, + permission, op, true); } /** @@ -1657,16 +1657,17 @@ public class StorageManager { */ public static boolean checkPermissionAndCheckOp(Context context, boolean enforce, int pid, int uid, String packageName, String permission, int op) { - return checkPermissionAndAppOp(context, enforce, pid, uid, packageName, permission, op, - false); + return checkPermissionAndAppOp(context, enforce, pid, uid, packageName, + null /* featureId is not needed when not noting */, permission, op, false); } /** * Check that given app holds both permission and appop. * @hide */ - private static boolean checkPermissionAndAppOp(Context context, boolean enforce, - int pid, int uid, String packageName, String permission, int op, boolean note) { + private static boolean checkPermissionAndAppOp(Context context, boolean enforce, int pid, + int uid, String packageName, @Nullable String featureId, String permission, int op, + boolean note) { if (context.checkPermission(permission, pid, uid) != PERMISSION_GRANTED) { if (enforce) { throw new SecurityException( @@ -1679,7 +1680,7 @@ public class StorageManager { AppOpsManager appOps = context.getSystemService(AppOpsManager.class); final int mode; if (note) { - mode = appOps.noteOpNoThrow(op, uid, packageName); + mode = appOps.noteOpNoThrow(op, uid, packageName, featureId, null); } else { try { appOps.checkPackage(uid, packageName); @@ -1711,14 +1712,15 @@ public class StorageManager { } } - private boolean checkPermissionAndAppOp(boolean enforce, - int pid, int uid, String packageName, String permission, int op) { - return checkPermissionAndAppOp(mContext, enforce, pid, uid, packageName, permission, op); + private boolean checkPermissionAndAppOp(boolean enforce, int pid, int uid, String packageName, + @Nullable String featureId, String permission, int op) { + return checkPermissionAndAppOp(mContext, enforce, pid, uid, packageName, featureId, + permission, op); } private boolean noteAppOpAllowingLegacy(boolean enforce, - int pid, int uid, String packageName, int op) { - final int mode = mAppOps.noteOpNoThrow(op, uid, packageName); + int pid, int uid, String packageName, @Nullable String featureId, int op) { + final int mode = mAppOps.noteOpNoThrow(op, uid, packageName, featureId, null); switch (mode) { case AppOpsManager.MODE_ALLOWED: return true; @@ -1749,50 +1751,68 @@ public class StorageManager { /** {@hide} */ public boolean checkPermissionReadAudio(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_READ_MEDIA_AUDIO); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_READ_MEDIA_AUDIO); } /** {@hide} */ public boolean checkPermissionWriteAudio(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_WRITE_MEDIA_AUDIO); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_WRITE_MEDIA_AUDIO); } /** {@hide} */ public boolean checkPermissionReadVideo(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_READ_MEDIA_VIDEO); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_READ_MEDIA_VIDEO); } /** {@hide} */ public boolean checkPermissionWriteVideo(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_WRITE_MEDIA_VIDEO); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_WRITE_MEDIA_VIDEO); } /** {@hide} */ public boolean checkPermissionReadImages(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_READ_MEDIA_IMAGES); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + READ_EXTERNAL_STORAGE, OP_READ_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_READ_MEDIA_IMAGES); } /** {@hide} */ public boolean checkPermissionWriteImages(boolean enforce, - int pid, int uid, String packageName) { - if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, - WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) return false; - return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, OP_WRITE_MEDIA_IMAGES); + int pid, int uid, String packageName, @Nullable String featureId) { + if (!checkPermissionAndAppOp(enforce, pid, uid, packageName, featureId, + WRITE_EXTERNAL_STORAGE, OP_WRITE_EXTERNAL_STORAGE)) { + return false; + } + return noteAppOpAllowingLegacy(enforce, pid, uid, packageName, featureId, + OP_WRITE_MEDIA_IMAGES); } /** {@hide} */ diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index dd561e10874f..d66aa18950d0 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -2170,14 +2170,21 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } + @Deprecated @Override public ParcelFileDescriptor getWallpaper(String callingPkg, IWallpaperManagerCallback cb, final int which, Bundle outParams, int wallpaperUserId) { + return getWallpaperWithFeature(callingPkg, null, cb, which, outParams, wallpaperUserId); + } + + @Override + public ParcelFileDescriptor getWallpaperWithFeature(String callingPkg, String callingFeatureId, + IWallpaperManagerCallback cb, final int which, Bundle outParams, int wallpaperUserId) { final int hasPrivilege = mContext.checkCallingOrSelfPermission( android.Manifest.permission.READ_WALLPAPER_INTERNAL); if (hasPrivilege != PackageManager.PERMISSION_GRANTED) { mContext.getSystemService(StorageManager.class).checkPermissionReadImages(true, - Binder.getCallingPid(), Binder.getCallingUid(), callingPkg); + Binder.getCallingPid(), Binder.getCallingUid(), callingPkg, callingFeatureId); } wallpaperUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |