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

Commit 56246485 authored by Nikhil Kumar's avatar Nikhil Kumar
Browse files

Changed parent assumption to current context user from USER_SYSTEM

After HSUM mode profile parent is not only limited to the SYSTEM user, changed the instances where it was using the SYSTEM to get the profile parent or to get the managed profile id to use the context user.

Also removed self user id check continue statement from getManagedProfileId() method to allow it to be getting queried by manged profile user itself in that case it will return it's own user id as the managed profile.

Test: manually verfied the flow in Settings app --> Password, passkeys and autofill --> Tap on Work profile.
Bug: 347693615
Flag: EXEMPT Minor bug fix
Change-Id: I54d52faed6c233afff8e9a6336d29afdff5c8268
parent 9685f173
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -430,13 +430,21 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
        return null;
    }

    /**
     * Retrieves the user ID of a managed profile associated with a specific user.
     *
     * <p>This method iterates over the users in the profile group associated with the given user ID
     * and returns the ID of the user that is identified as a managed profile user.
     * If no managed profile is found, it returns {@link UserHandle#USER_NULL}.
     *
     * @param context The context used to obtain the {@link UserManager} system service.
     * @param userId  The ID of the user for whom to find the managed profile.
     * @return The user ID of the managed profile, or {@link UserHandle#USER_NULL} if none exists.
     */
    private static int getManagedProfileId(Context context, int userId) {
        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        List<UserInfo> userProfiles = um.getProfiles(userId);
        for (UserInfo uInfo : userProfiles) {
            if (uInfo.id == userId) {
                continue;
            }
            if (uInfo.isManagedProfile()) {
                return uInfo.id;
            }
@@ -821,11 +829,11 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
        }
        EnforcedAdmin admin =
                RestrictedLockUtils.getProfileOrDeviceOwner(
                        context, UserHandle.of(UserHandle.USER_SYSTEM));
                        context, context.getUser());
        if (admin != null) {
            return admin;
        }
        int profileId = getManagedProfileId(context, UserHandle.USER_SYSTEM);
        int profileId = getManagedProfileId(context, context.getUserId());
        return RestrictedLockUtils.getProfileOrDeviceOwner(context, UserHandle.of(profileId));
    }

@@ -848,7 +856,7 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
        if (admin != null) {
            return admin;
        }
        int profileId = getManagedProfileId(context, UserHandle.USER_SYSTEM);
        int profileId = getManagedProfileId(context, context.getUserId());
        return RestrictedLockUtils.getProfileOrDeviceOwner(context, UserHandle.of(profileId));
    }