summaryrefslogtreecommitdiff
path: root/core/java/android/os/UserManager.java
diff options
context:
space:
mode:
authorKedar Chitnis <kedarc@google.com>2022-03-25 05:12:34 +0000
committerKedar Chitnis <kedarc@google.com>2022-04-14 09:47:35 +0000
commitc60e7c411994172c7f55ae65f413b13e0646a879 (patch)
treeef497b4114fea0f2b070d7f9f3d9423b84ae0c7d /core/java/android/os/UserManager.java
parent8f60ed56c4fc687108743ba08e557e160758b804 (diff)
Guest mode updates to resolve privacy concerns in guest mode
- Add API in IUserManager to allow setting ephemeral user flag - Implement and export this API in UserManagerService and UserManager - Set guest as ephermal by default when createGuest in UserManager is called - Handle guest user switching in UserSwitcherController for the case of dynamic change of ephemeral state - Add persistant notification when in guest mode to indicate - if guest session is new or previously used. - if guest session will be cleared on exit or not - Add buttons in persistant notification to reset or exit guest - Add flags to enable/disable this feature Bug: 214031645 Screenshots: go/ephemeral-guest-b-214031645-ux Test: Manual test using sunfish, atest SystemUITests, atest SettingsRoboTests Relands ag/16545010 after resolving post submit issues Revert "Revert "Guest mode updates to resolve privacy concerns in guest mode"" This reverts commit dd5c440802078291a88e9f939e8a25348ec81315. Change-Id: I46b8ab527bab8fe665114ed0fffbb06a59d49a77 Merged-In: I46b8ab527bab8fe665114ed0fffbb06a59d49a77
Diffstat (limited to 'core/java/android/os/UserManager.java')
-rw-r--r--core/java/android/os/UserManager.java52
1 files changed, 50 insertions, 2 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index a64e63eacd56..570d533ccf1e 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1997,13 +1997,22 @@ public class UserManager {
* @return Whether guest user is always ephemeral
* @hide
*/
- @TestApi
- public static boolean isGuestUserEphemeral() {
+ public static boolean isGuestUserAlwaysEphemeral() {
return Resources.getSystem()
.getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
}
/**
+ * @return true, when we want to enable user manager API and UX to allow
+ * guest user ephemeral state change based on user input
+ * @hide
+ */
+ public static boolean isGuestUserAllowEphemeralStateChange() {
+ return Resources.getSystem()
+ .getBoolean(com.android.internal.R.bool.config_guestUserAllowEphemeralStateChange);
+ }
+
+ /**
* Checks whether the device is running in a headless system user mode.
*
* <p>Headless system user mode means the {@link #isSystemUser() system user} runs system
@@ -3424,6 +3433,20 @@ public class UserManager {
if (guest != null) {
Settings.Secure.putStringForUser(context.getContentResolver(),
Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
+
+ if (UserManager.isGuestUserAllowEphemeralStateChange()) {
+ // Mark guest as (changeably) ephemeral if REMOVE_GUEST_ON_EXIT is 1
+ // This is done so that a user via a UI controller can choose to
+ // make a guest as ephemeral or not.
+ // Settings.Global.REMOVE_GUEST_ON_EXIT holds the choice on what the guest state
+ // should be, with default being ephemeral.
+ boolean resetGuestOnExit = Settings.Global.getInt(context.getContentResolver(),
+ Settings.Global.REMOVE_GUEST_ON_EXIT, 1) == 1;
+
+ if (resetGuestOnExit && !guest.isEphemeral()) {
+ setUserEphemeral(guest.id, true);
+ }
+ }
}
return guest;
} catch (ServiceSpecificException e) {
@@ -4941,6 +4964,31 @@ public class UserManager {
}
/**
+ * Set the user as ephemeral or non-ephemeral.
+ *
+ * If the user was initially created as ephemeral then this
+ * method has no effect and false is returned.
+ *
+ * @param userId the user's integer id
+ * @param enableEphemeral true: change user state to ephemeral,
+ * false: change user state to non-ephemeral
+ * @return true: user now has the desired ephemeral state,
+ * false: desired user ephemeral state could not be set
+ *
+ * @hide
+ */
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.MANAGE_USERS,
+ android.Manifest.permission.CREATE_USERS})
+ public boolean setUserEphemeral(@UserIdInt int userId, boolean enableEphemeral) {
+ try {
+ return mService.setUserEphemeral(userId, enableEphemeral);
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Updates the context user's name.
*
* @param name the new name for the user