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

Commit b460022e authored by Rubin Xu's avatar Rubin Xu
Browse files

Fix DPMS.findAdmin() after app enumeration restrictions

Clear binder identity before calling into PackageManager APIs.

Bug: 149932907
Test: atest com.android.cts.devicepolicy.MixedProfileOwnerHostSideTransferTest
Change-Id: I6376a79d7cac6a296adfa267cb07f719400f9c59
parent 547ef077
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -3297,22 +3297,24 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle,
    public DeviceAdminInfo findAdmin(final ComponentName adminName, final int userHandle,
            boolean throwForMissingPermission) {
        if (!mHasFeature) {
            return null;
        }
        enforceFullCrossUsersPermission(userHandle);
        ActivityInfo ai = null;
        final ActivityInfo ai = mInjector.binderWithCleanCallingIdentity(() -> {
            try {
            ai = mIPackageManager.getReceiverInfo(adminName,
                    PackageManager.GET_META_DATA |
                    PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
                    PackageManager.MATCH_DIRECT_BOOT_AWARE |
                    PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle);
                return mIPackageManager.getReceiverInfo(adminName,
                        PackageManager.GET_META_DATA
                        | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
                        | PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle);
            } catch (RemoteException e) {
                // shouldn't happen.
                return null;
            }
        });
        if (ai == null) {
            throw new IllegalArgumentException("Unknown admin: " + adminName);
        }