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

Commit 676d5233 authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Android (Google) Code Review
Browse files

Merge "Use UserHandle created context to check package name." into tm-qpr-dev

parents 21e1b8d7 74621539
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -373,9 +373,12 @@ public final class Utils {
     */
     */
    public static boolean isPackageNameAccurate(Context context, String callingPackage,
    public static boolean isPackageNameAccurate(Context context, String callingPackage,
            int callingUid) {
            int callingUid) {
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);

        // Verifies the integrity of the calling package name
        // Verifies the integrity of the calling package name
        try {
        try {
            int packageUid = context.getPackageManager().getPackageUid(callingPackage, 0);
            int packageUid = context.createContextAsUser(callingUser, 0)
                    .getPackageManager().getPackageUid(callingPackage, 0);
            if (packageUid != callingUid) {
            if (packageUid != callingUid) {
                Log.e(TAG, "isPackageNameAccurate: App with package name " + callingPackage
                Log.e(TAG, "isPackageNameAccurate: App with package name " + callingPackage
                        + " is UID " + packageUid + " but caller is " + callingUid);
                        + " is UID " + packageUid + " but caller is " + callingUid);