Guest user first iteration
Setting for controlling if guest is enabled on the device.
Setting to hint to apps that they should skip showing first use clings.
User switcher handles creation and deletion of the guest user.
Some tweaks to the user switcher to show some feedback and make the icons
circular.
Change-Id: I187dc381d2ee7c372ec6d35e14aa9ea4dfbe5936
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl
index cd47099..e77ef95 100644
--- a/core/java/android/os/IUserManager.aidl
+++ b/core/java/android/os/IUserManager.aidl
@@ -39,9 +39,6 @@
UserInfo getProfileParent(int userHandle);
UserInfo getUserInfo(int userHandle);
boolean isRestricted();
- void setGuestEnabled(boolean enable);
- boolean isGuestEnabled();
- void wipeUser(int userHandle);
int getUserSerialNumber(int userHandle);
int getUserHandle(int userSerialNumber);
Bundle getUserRestrictions(int userHandle);
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 91fbb9d..eb3c748 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -25,6 +25,7 @@
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.provider.Settings;
import android.util.Log;
import com.android.internal.R;
@@ -361,6 +362,16 @@
}
/**
+ * Checks if the calling app is running as a guest user.
+ * @return whether the caller is a guest user.
+ * @hide
+ */
+ public boolean isGuestUser() {
+ UserInfo user = getUserInfo(UserHandle.myUserId());
+ return user != null ? user.isGuest() : false;
+ }
+
+ /**
* Return whether the given user is actively running. This means that
* the user is in the "started" state, not "stopped" -- it is currently
* allowed to run code through scheduled alarms, receiving broadcasts,
@@ -550,6 +561,21 @@
}
/**
+ * Creates a guest user and configures it.
+ * @param context an application context
+ * @param name the name to set for the user
+ * @hide
+ */
+ public UserInfo createGuest(Context context, String name) {
+ UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
+ if (guest != null) {
+ Settings.Secure.putStringForUser(context.getContentResolver(),
+ Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
+ }
+ return guest;
+ }
+
+ /**
* Creates a user with the specified name and options as a profile of another user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
@@ -827,50 +853,6 @@
}
/**
- * Enable or disable the use of a guest account. If disabled, the existing guest account
- * will be wiped.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
- * @param enable whether to enable a guest account.
- * @hide
- */
- public void setGuestEnabled(boolean enable) {
- try {
- mService.setGuestEnabled(enable);
- } catch (RemoteException re) {
- Log.w(TAG, "Could not change guest account availability to " + enable);
- }
- }
-
- /**
- * Checks if a guest user is enabled for this device.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
- * @return whether a guest user is enabled
- * @hide
- */
- public boolean isGuestEnabled() {
- try {
- return mService.isGuestEnabled();
- } catch (RemoteException re) {
- Log.w(TAG, "Could not retrieve guest enabled state");
- return false;
- }
- }
-
- /**
- * Wipes all the data for a user, but doesn't remove the user.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
- * @param userHandle
- * @hide
- */
- public void wipeUser(int userHandle) {
- try {
- mService.wipeUser(userHandle);
- } catch (RemoteException re) {
- Log.w(TAG, "Could not wipe user " + userHandle);
- }
- }
-
- /**
* Returns the maximum number of users that can be created on this device. A return value
* of 1 means that it is a single user device.
* @hide
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 1001677..3fe0fb8 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -4576,6 +4576,16 @@
public static final String DISPLAY_INTERCEPTED_NOTIFICATIONS = "display_intercepted_notifications";
/**
+ * If enabled, apps should try to skip any introductory hints on first launch. This might
+ * apply to users that are already familiar with the environment or temporary users, like
+ * guests.
+ * <p>
+ * Type : int (0 to show hints, 1 to skip showing hints)
+ * @hide
+ */
+ public static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";
+
+ /**
* This are the settings to be backed up.
*
* NOTE: Settings are backed up and restored in the order they appear
@@ -6216,6 +6226,14 @@
public static final String DEVICE_NAME = "device_name";
/**
+ * Whether it should be possible to create a guest user on the device.
+ * <p>
+ * Type: int (0 for disabled, 1 for enabled)
+ * @hide
+ */
+ public static final String GUEST_USER_ENABLED = "guest_user_enabled";
+
+ /**
* Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update.
*