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

Commit 74621539 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Use UserHandle created context to check package name.

In BluetoothUtils#isPackageNameAccurate method we need to
create a new context with the UserHandle to be able to
retrieve the correct package UID. When app is in work
profile, we now retrieve the correct UID.

Bug: 222125980
Tag: #feature
Test: Manual
Ignore-AOSP-First: Cherry-pick
Merged-in: I2e27f56d07dae9646c5addc5f4a42afba2afc818
Change-Id: I2e27f56d07dae9646c5addc5f4a42afba2afc818
parent 553e5bb9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -373,9 +373,12 @@ public final class Utils {
     */
    public static boolean isPackageNameAccurate(Context context, String callingPackage,
            int callingUid) {
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);

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