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

Commit f4710f6f authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixed DPMS.listForegroundAffiliatedUsers().

It was not properly clearing the caller's identity, so it would
fail "in real life" when the DPC doesn't have INTERACT_ACROSS_USERS
(but it was passing on CTS because the test app had it).

Test: atest com.android.cts.devicepolicy.DeviceOwnerTest#testListForegroundAffiliatedUsers_onlyForegroundUserCalledByDeviceOwner # on automotive
Fixes: 186455856

Change-Id: I2924f5cdf90e767c4f2ae534788baa5c448126c5
parent 8479536f
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -8883,17 +8883,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    @Override
    public ComponentName getProfileOwnerAsUser(int userHandle) {
    public ComponentName getProfileOwnerAsUser(int userId) {
        if (!mHasFeature) {
            return null;
        }
        Preconditions.checkArgumentNonnegative(userHandle, "Invalid userId");
        Preconditions.checkArgumentNonnegative(userId, "Invalid userId");
        final CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userHandle));
        CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userId));
        synchronized (getLockObject()) {
            return mOwners.getProfileOwnerComponent(userHandle);
            return mOwners.getProfileOwnerComponent(userId);
        }
    }
@@ -9345,8 +9345,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    public List<UserHandle> listForegroundAffiliatedUsers() {
        checkIsDeviceOwner(getCallerIdentity());
        int userId = mInjector.binderWithCleanCallingIdentity(() -> getCurrentForegroundUserId());
        return mInjector.binderWithCleanCallingIdentity(() -> {
            int userId = getCurrentForegroundUserId();
            boolean isAffiliated;
            synchronized (getLockObject()) {
                isAffiliated = isUserAffiliatedWithDeviceLocked(userId);
@@ -9358,6 +9358,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            users.add(UserHandle.of(userId));
            return users;
        });
    }
    protected int getProfileParentId(int userHandle) {
@@ -14111,7 +14112,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private boolean isUserAffiliatedWithDeviceLocked(int userId) {
    private boolean isUserAffiliatedWithDeviceLocked(@UserIdInt int userId) {
        if (!mOwners.hasDeviceOwner()) {
            return false;
        }