Add check package belong to caller am: 1963f31a52

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

Change-Id: I005808e6464d64b1e846e2e6855604ba78ab3a8d
This commit is contained in:
Ayush Sharma
2021-12-22 17:00:38 +00:00
committed by Automerger Merge Worker

View File

@@ -3007,12 +3007,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 * Certain user types do not support wallpapers (e.g. managed profiles). The check is
* implemented through through the OP_WRITE_WALLPAPER AppOp. * implemented through through the OP_WRITE_WALLPAPER AppOp.
*/ */
public boolean isWallpaperSupported(String callingPackage) { 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; callingPackage) == AppOpsManager.MODE_ALLOWED;
} }