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

Commit 7bec4b30 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Introduce config for auto-created guest users"

parents 7c7cb9be 7f7ffe21
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3529,6 +3529,12 @@
    <!-- If true, all guest users created on the device will be ephemeral. -->
    <bool name="config_guestUserEphemeral">false</bool>

    <!-- Whether device should always have a guest user available. If true, guest user will be
         created on boot, and a new guest user will be created in the background anytime the current
         guest user is removed. Instead of showing "Add guest" and "Remove guest", the UI will show
         "Guest" and "Reset guest". -->
    <bool name="config_guestUserAutoCreated">false</bool>

    <!-- Enforce strong auth on boot. Setting this to false represents a security risk and should
         not be ordinarily done. The only case in which this might be permissible is in a car head
         unit where there are hardware mechanisms to protect the device (physical keys) and not
+1 −0
Original line number Diff line number Diff line
@@ -402,6 +402,7 @@
  <java-symbol type="bool" name="config_supportsSystemDecorsOnSecondaryDisplays" />
  <java-symbol type="bool" name="config_supportsInsecureLockScreen" />
  <java-symbol type="bool" name="config_guestUserEphemeral" />
  <java-symbol type="bool" name="config_guestUserAutoCreated" />
  <java-symbol type="bool" name="config_localDisplaysMirrorContent" />
  <java-symbol type="array" name="config_localPrivateDisplayPorts" />
  <java-symbol type="integer" name="config_defaultDisplayDefaultColorMode" />
+2 −0
Original line number Diff line number Diff line
@@ -1422,6 +1422,8 @@
    <string name="guest_new_guest">Add guest</string>
    <!-- Label for exiting and removing the guest session in the user switcher [CHAR LIMIT=35] -->
    <string name="guest_exit_guest">Remove guest</string>
    <!-- Label for resetting guest session in the user switcher, which will remove all data from the current guest session [CHAR LIMIT=35] -->
    <string name="guest_reset_guest">Reset guest</string>
    <!-- Name for the guest user [CHAR LIMIT=35] -->
    <string name="guest_nickname">Guest</string>

+6 −0
Original line number Diff line number Diff line
@@ -1148,12 +1148,18 @@
    <!-- Title of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] -->
    <string name="guest_exit_guest_dialog_title">Remove guest?</string>

    <!-- Title of the confirmation dialog when resetting guest session [CHAR LIMIT=NONE] -->
    <string name="guest_reset_guest_dialog_title">Reset guest?</string>

    <!-- Message of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] -->
    <string name="guest_exit_guest_dialog_message">All apps and data in this session will be deleted.</string>

    <!-- Label for button in confirmation dialog when exiting guest session [CHAR LIMIT=35] -->
    <string name="guest_exit_guest_dialog_remove">Remove</string>

    <!-- Label for button in confirmation dialog when resetting guest session [CHAR LIMIT=35] -->
    <string name="guest_reset_guest_dialog_remove">Reset</string>

    <!-- Title of the notification when resuming an existing guest session [CHAR LIMIT=NONE] -->
    <string name="guest_wipe_session_title">Welcome back, guest!</string>

+14 −53
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui;

import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -24,11 +23,8 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.view.WindowManagerGlobal;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
@@ -36,6 +32,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.qs.QSUserSwitcherEvent;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import com.android.systemui.util.settings.SecureSettings;

/**
@@ -51,11 +48,14 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
    @VisibleForTesting
    public AlertDialog mNewSessionDialog;
    private final UserTracker mUserTracker;
    private final UserSwitcherController mUserSwitcherController;
    private final UiEventLogger mUiEventLogger;
    private final SecureSettings mSecureSettings;

    public GuestResumeSessionReceiver(UserTracker userTracker, UiEventLogger uiEventLogger,
    public GuestResumeSessionReceiver(UserSwitcherController userSwitcherController,
            UserTracker userTracker, UiEventLogger uiEventLogger,
            SecureSettings secureSettings) {
        mUserSwitcherController = userSwitcherController;
        mUserTracker = userTracker;
        mUiEventLogger = uiEventLogger;
        mSecureSettings = secureSettings;
@@ -92,8 +92,8 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
            int notFirstLogin = mSecureSettings.getIntForUser(
                    SETTING_GUEST_HAS_LOGGED_IN, 0, userId);
            if (notFirstLogin != 0) {
                mNewSessionDialog = new ResetSessionDialog(context, mUserTracker, mUiEventLogger,
                        userId);
                mNewSessionDialog = new ResetSessionDialog(context, mUserSwitcherController,
                        mUserTracker, mUiEventLogger, userId);
                mNewSessionDialog.show();
            } else {
                mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, 1, userId);
@@ -101,48 +101,6 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
        }
    }

    /**
     * Wipes the guest session.
     *
     * The guest must be the current user and its id must be {@param userId}.
     */
    private static void wipeGuestSession(Context context, UserTracker userTracker, int userId) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        UserInfo currentUser = userTracker.getUserInfo();
        if (currentUser.id != userId) {
            Log.w(TAG, "User requesting to start a new session (" + userId + ")"
                    + " is not current user (" + currentUser.id + ")");
            return;
        }
        if (!currentUser.isGuest()) {
            Log.w(TAG, "User requesting to start a new session (" + userId + ")"
                    + " is not a guest");
            return;
        }

        boolean marked = userManager.markGuestForDeletion(currentUser.id);
        if (!marked) {
            Log.w(TAG, "Couldn't mark the guest for deletion for user " + userId);
            return;
        }
        UserInfo newGuest = userManager.createGuest(context, currentUser.name);

        try {
            if (newGuest == null) {
                Log.e(TAG, "Could not create new guest, switching back to system user");
                ActivityManager.getService().switchUser(UserHandle.USER_SYSTEM);
                userManager.removeUser(currentUser.id);
                WindowManagerGlobal.getWindowManagerService().lockNow(null /* options */);
                return;
            }
            ActivityManager.getService().switchUser(newGuest.id);
            userManager.removeUser(currentUser.id);
        } catch (RemoteException e) {
            Log.e(TAG, "Couldn't wipe session because ActivityManager or WindowManager is dead");
            return;
        }
    }

    private void cancelDialog() {
        if (mNewSessionDialog != null && mNewSessionDialog.isShowing()) {
            mNewSessionDialog.cancel();
@@ -162,11 +120,14 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
        @VisibleForTesting
        public static final int BUTTON_DONTWIPE = BUTTON_POSITIVE;

        private final UserTracker mUserTracker;
        private final UserSwitcherController mUserSwitcherController;
        private final UiEventLogger mUiEventLogger;
        private final int mUserId;

        ResetSessionDialog(Context context, UserTracker userTracker, UiEventLogger uiEventLogger,
        ResetSessionDialog(Context context,
                UserSwitcherController userSwitcherController,
                UserTracker userTracker,
                UiEventLogger uiEventLogger,
                int userId) {
            super(context);

@@ -179,7 +140,7 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
            setButton(BUTTON_DONTWIPE,
                    context.getString(R.string.guest_wipe_session_dontwipe), this);

            mUserTracker = userTracker;
            mUserSwitcherController = userSwitcherController;
            mUiEventLogger = uiEventLogger;
            mUserId = userId;
        }
@@ -188,7 +149,7 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
        public void onClick(DialogInterface dialog, int which) {
            if (which == BUTTON_WIPE) {
                mUiEventLogger.log(QSUserSwitcherEvent.QS_USER_GUEST_WIPE);
                wipeGuestSession(getContext(), mUserTracker, mUserId);
                mUserSwitcherController.removeGuestUser(mUserId, UserHandle.USER_NULL);
                dismiss();
            } else if (which == BUTTON_DONTWIPE) {
                mUiEventLogger.log(QSUserSwitcherEvent.QS_USER_GUEST_CONTINUE);
Loading