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

Commit 62a0e332 authored by Ayush Sharma's avatar Ayush Sharma Committed by Automerger Merge Worker
Browse files

Add check package belong to caller am: 1963f31a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15843709

Change-Id: I94bfbefc7eaabead9d0b82603f56d7ad4ee7e399
parents 40ac891e 1963f31a
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -3062,12 +3062,35 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        }
    }

    private boolean packageBelongsToUid(String packageName, int uid) {
        int userId = UserHandle.getUserId(uid);
        int packageUid;
        try {
            packageUid = mContext.getPackageManager().getPackageUidAsUser(
                    packageName, userId);
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
        return packageUid == uid;
    }

    private void enforcePackageBelongsToUid(String packageName, int uid) {
        if (!packageBelongsToUid(packageName, uid)) {
            throw new IllegalArgumentException(
                    "Invalid package or package does not belong to uid:"
                            + uid);
        }
    }

    /**
     * Certain user types do not support wallpapers (e.g. managed profiles). The check is
     * implemented through through the OP_WRITE_WALLPAPER AppOp.
     */
    public boolean isWallpaperSupported(String callingPackage) {
        return mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_WRITE_WALLPAPER, Binder.getCallingUid(),
        final int callingUid = Binder.getCallingUid();
        enforcePackageBelongsToUid(callingPackage, callingUid);

        return mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_WRITE_WALLPAPER, callingUid,
                callingPackage) == AppOpsManager.MODE_ALLOWED;
    }