Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 529e1eb7 authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Android (Google) Code Review
Browse files

Merge "Properly check MANAGE_EXTERNAL_STORAGE for wallpaper" into main

parents 92e4b2db a196b639
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -2224,15 +2224,21 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
    public ParcelFileDescriptor getWallpaperWithFeature(String callingPkg, String callingFeatureId,
            IWallpaperManagerCallback cb, final int which, Bundle outParams, int wallpaperUserId,
            boolean getCropped) {
        final boolean hasPrivilege = hasPermission(READ_WALLPAPER_INTERNAL)
                || hasPermission(MANAGE_EXTERNAL_STORAGE);
        final int callingPid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        final boolean hasPrivilege = hasPermission(READ_WALLPAPER_INTERNAL);
        if (!hasPrivilege) {
            boolean hasManageExternalStorage = hasPermission(MANAGE_EXTERNAL_STORAGE)
                    || hasAppOpPermission(MANAGE_EXTERNAL_STORAGE, callingUid, callingPkg,
                        callingFeatureId, "getWallpaperWithFeature from package: " + callingPkg);
            if (!hasManageExternalStorage) {
                mContext.getSystemService(StorageManager.class).checkPermissionReadImages(true,
                    Binder.getCallingPid(), Binder.getCallingUid(), callingPkg, callingFeatureId);
                        callingPid, callingUid, callingPkg, callingFeatureId);
            }
        }

        wallpaperUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
                Binder.getCallingUid(), wallpaperUserId, false, true, "getWallpaper", null);
        wallpaperUserId = ActivityManager.handleIncomingUser(callingPid, callingUid,
                wallpaperUserId, false, true, "getWallpaper", null);

        if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
            throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to read");
@@ -2348,6 +2354,22 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        return mContext.checkCallingOrSelfPermission(permission) == PERMISSION_GRANTED;
    }

    private boolean hasAppOpPermission(String permission, int callingUid, String callingPackage,
            String attributionTag, String message) {
        final String op = AppOpsManager.permissionToOp(permission);
        final int opMode = mAppOpsManager.noteOpNoThrow(op, callingUid, callingPackage,
                attributionTag, message);
        switch (opMode) {
            case AppOpsManager.MODE_ALLOWED:
            case AppOpsManager.MODE_FOREGROUND:
                return true;
            case AppOpsManager.MODE_DEFAULT:
                return hasPermission(permission);
            default:
                return false;
        }
    }

    @Override
    public WallpaperInfo getWallpaperInfo(int userId) {
        return getWallpaperInfoWithFlags(FLAG_SYSTEM, userId);