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

Commit 1ddda479 authored by Lenka Trochtova's avatar Lenka Trochtova
Browse files

Prevent ephemeral user from being re-entered after stop.

Once the ephemeral user stops, the user's deletion is scheduled.
It takes a while before the user actually disappears and it is not
desirable for the user to be re-entered in the meantime.
Mark the user as disabled on stop and check this flag
in the activity manager to prevent the user from being switched
to again. Also hide the user from user-switching UI.

BUG: 26795729
BUG: 26780152

Change-Id: I83a61674958954b5a210114b88ffa5ae55922c1f
parent 1bf6ed9f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ public class UserInfo implements Parcelable {

    /**
     * Indicates that this user is disabled.
     *
     * <p>Note: If an ephemeral user is disabled, it shouldn't be later re-enabled. Ephemeral users
     * are disabled as their removal is in progress to indicate that they shouldn't be re-entered.
     */
    public static final int FLAG_DISABLED = 0x00000040;

@@ -171,6 +174,10 @@ public class UserInfo implements Parcelable {
     * @return true if this user can be switched to.
     **/
    public boolean supportsSwitchTo() {
        if (isEphemeral() && !isEnabled()) {
            // Don't support switching to an ephemeral user with removal in progress.
            return false;
        }
        // TODO remove fw.show_hidden_users when we have finished developing managed profiles.
        return !isManagedProfile() || SystemProperties.getBoolean("fw.show_hidden_users", false);
    }
+6 −2
Original line number Diff line number Diff line
@@ -1371,8 +1371,12 @@ public class UserManager {

    /**
     * Sets the user as enabled, if such an user exists.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * Note that the default is true, it's only that managed profiles might not be enabled.
     *
     * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     *
     * <p>Note that the default is true, it's only that managed profiles might not be enabled.
     * Also ephemeral users can be disabled to indicate that their removal is in progress and they
     * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
     *
     * @param userHandle the id of the profile to enable
     * @hide
+11 −0
Original line number Diff line number Diff line
@@ -108,6 +108,17 @@ public abstract class UserManagerInternal {
     */
    public abstract void removeAllUsers();

    /**
     * Called by the activity manager when the ephemeral user goes to background and its removal
     * starts as a result.
     *
     * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered
     * before its removal finishes.
     *
     * @param userId the ID of the ephemeral user.
     */
    public abstract void onEphemeralUserStop(int userId);

    /**
     * Same as UserManager.createUser(), but bypasses the check for DISALLOW_ADD_USER.
     *
+18 −16
Original line number Diff line number Diff line
@@ -199,11 +199,12 @@ public class UserSwitcherController {
                        currentUserInfo = info;
                    }
                    boolean switchToEnabled = allowUserSwitching || isCurrent;
                    if (info.isEnabled()) {
                        if (info.isGuest()) {
                            guestRecord = new UserRecord(info, null /* picture */,
                                    true /* isGuest */, isCurrent, false /* isAddUser */,
                                    false /* isRestricted */, switchToEnabled);
                    } else if (info.isEnabled() && info.supportsSwitchToByUser()) {
                        } else if (info.supportsSwitchToByUser()) {
                            Bitmap picture = bitmaps.get(info.id);
                            if (picture == null) {
                                picture = mUserManager.getUserIcon(info.id);
@@ -219,6 +220,7 @@ public class UserSwitcherController {
                                    switchToEnabled));
                        }
                    }
                }

                boolean systemCanCreateUsers = !mUserManager.hasBaseUserRestriction(
                                UserManager.DISALLOW_ADD_USER, UserHandle.SYSTEM);
+4 −0
Original line number Diff line number Diff line
@@ -20511,6 +20511,10 @@ public final class ActivityManagerService extends ActivityManagerNative
                Slog.w(TAG, "No user info for user #" + targetUserId);
                return false;
            }
            if (!targetUserInfo.supportsSwitchTo()) {
                Slog.w(TAG, "Cannot switch to User #" + targetUserId + ": not supported");
                return false;
            }
            if (targetUserInfo.isManagedProfile()) {
                Slog.w(TAG, "Cannot switch to User #" + targetUserId + ": not a full user");
                return false;
Loading