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

Commit f07f1e54 authored by Brahim Chikhaoui's avatar Brahim Chikhaoui
Browse files

Prevent switching to non-full users with supportsSwitchToByUser

On Android Desktop with Headless System User Mode (HSUM), regular users
should not be able to switch to the system user via the UI.
The `config_canSwitchToHeadlessSystemUser` allowed this at the
framework level,via supportsSwitchTo but the UI should prevent such switches.

This change un-deprecates `supportsSwitchToByUser` and modifies it
to ensure that only full users (`UserInfo::isFull`) are considered
switchable through this method. This explicitly prevents switching
to the headless system user from the UI, as such operations are
intended to be framework-level and should rely on `supportsSwitchTo`.

The updated `supportsSwitchToByUser` method now returns true if
`supportsSwitchTo()` is true AND the target user is a full user.
This ensures that the headless system user, which is not a full user,
is not presented as a switchable option to end users in Settings.

Bug: 393051605
Test: manually build and deploy in DUT
Flag: EXEMPT desktop only
Change-Id: I8a07d32eb7eb88bb28987cb8dabf8a244150acde
parent 49dbd164
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1211,7 +1211,7 @@ package android.content.pm {
    method public boolean isRestricted();
    method @FlaggedApi("android.multiuser.allow_supervising_profile") public boolean isSupervisingProfile();
    method public boolean supportsSwitchTo();
    method @Deprecated public boolean supportsSwitchToByUser();
    method public boolean supportsSwitchToByUser();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.UserInfo> CREATOR;
    field public static final int FLAG_ADMIN = 2; // 0x2
+6 −4
Original line number Diff line number Diff line
@@ -482,13 +482,15 @@ public class UserInfo implements Parcelable {
    }

    /**
     * @return true if this user can be switched to by end user through UI.
     * @deprecated Use {@link UserInfo#supportsSwitchTo} instead.
     * @return true if this user can be switched to by an end user through the UI.
     * This method checks if supportsSwitchTo() is true AND the user is a full user.
     * It specifically excludes the headless system user, as switching to that user
     * is typically a framework-level operation and not available to regular users
     * via the UI.
     */
    @Deprecated
    @android.ravenwood.annotation.RavenwoodThrow
    public boolean supportsSwitchToByUser() {
        return supportsSwitchTo();
        return supportsSwitchTo() && isFull();
    }

    /**