Loading core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ interface IUserManager { void setDefaultGuestRestrictions(in Bundle restrictions); Bundle getDefaultGuestRestrictions(); boolean markGuestForDeletion(int userId); UserInfo findCurrentGuestUser(); boolean isQuietModeEnabled(int userId); void setSeedAccountData(int userId, in String accountName, in String accountType, in PersistableBundle accountOptions, boolean persist); Loading core/java/android/os/UserManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -2374,6 +2374,20 @@ public class UserManager { return guest; } /** * Gets the existing guest user if it exists. This does not include guest users that are dying. * @return The existing guest user if it exists. Null otherwise. * @hide */ @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public UserInfo findCurrentGuestUser() { try { return mService.findCurrentGuestUser(); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Creates a user with the specified name and options as a profile of another user. * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. Loading packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java +23 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.content.DialogInterface.BUTTON_POSITIVE; import static android.os.UserManager.DISALLOW_ADD_USER; import static android.os.UserManager.SWITCHABILITY_STATUS_OK; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.AlertDialog.Builder; Loading Loading @@ -266,7 +267,10 @@ public class UserGridRecyclerView extends RecyclerView { if (userRecord.mIsStartGuestSession) { notifyUserSelected(userRecord); mCarUserManagerHelper.startGuestSession(mGuestName); UserInfo guest = createNewOrFindExistingGuest(mContext); if (guest != null) { mCarUserManagerHelper.switchToUser(guest); } return; } Loading Loading @@ -381,6 +385,24 @@ public class UserGridRecyclerView extends RecyclerView { return circleIcon; } /** * Finds the existing Guest user, or creates one if it doesn't exist. * @param context App context * @return UserInfo representing the Guest user */ @Nullable public UserInfo createNewOrFindExistingGuest(Context context) { // CreateGuest will return null if a guest already exists. UserInfo newGuest = mUserManager.createGuest(context, mGuestName); if (newGuest != null) { new UserIconProvider().assignDefaultIcon( mUserManager, context.getResources(), newGuest); return newGuest; } return mUserManager.findCurrentGuestUser(); } @Override public void onClick(DialogInterface dialog, int which) { if (which == BUTTON_POSITIVE) { Loading packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserIconProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ public class UserIconProvider { * @param userInfo User whose avatar is set to default icon. * @return Bitmap of the user icon. */ private Bitmap assignDefaultIcon( public Bitmap assignDefaultIcon( UserManager userManager, Resources resources, UserInfo userInfo) { Bitmap bitmap = userInfo.isGuest() ? getGuestUserDefaultIcon(resources) Loading services/core/java/com/android/server/pm/UserManagerService.java +6 −1 Original line number Diff line number Diff line Loading @@ -3452,8 +3452,13 @@ public class UserManagerService extends IUserManager.Stub { /** * Find the current guest user. If the Guest user is partial, * then do not include it in the results as it is about to die. * * @return The current guest user. Null if it doesn't exist. * @hide */ private UserInfo findCurrentGuestUser() { @Override public UserInfo findCurrentGuestUser() { checkManageUsersPermission("findCurrentGuestUser"); synchronized (mUsersLock) { final int size = mUsers.size(); for (int i = 0; i < size; i++) { Loading Loading
core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ interface IUserManager { void setDefaultGuestRestrictions(in Bundle restrictions); Bundle getDefaultGuestRestrictions(); boolean markGuestForDeletion(int userId); UserInfo findCurrentGuestUser(); boolean isQuietModeEnabled(int userId); void setSeedAccountData(int userId, in String accountName, in String accountType, in PersistableBundle accountOptions, boolean persist); Loading
core/java/android/os/UserManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -2374,6 +2374,20 @@ public class UserManager { return guest; } /** * Gets the existing guest user if it exists. This does not include guest users that are dying. * @return The existing guest user if it exists. Null otherwise. * @hide */ @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public UserInfo findCurrentGuestUser() { try { return mService.findCurrentGuestUser(); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Creates a user with the specified name and options as a profile of another user. * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. Loading
packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java +23 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.content.DialogInterface.BUTTON_POSITIVE; import static android.os.UserManager.DISALLOW_ADD_USER; import static android.os.UserManager.SWITCHABILITY_STATUS_OK; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.AlertDialog.Builder; Loading Loading @@ -266,7 +267,10 @@ public class UserGridRecyclerView extends RecyclerView { if (userRecord.mIsStartGuestSession) { notifyUserSelected(userRecord); mCarUserManagerHelper.startGuestSession(mGuestName); UserInfo guest = createNewOrFindExistingGuest(mContext); if (guest != null) { mCarUserManagerHelper.switchToUser(guest); } return; } Loading Loading @@ -381,6 +385,24 @@ public class UserGridRecyclerView extends RecyclerView { return circleIcon; } /** * Finds the existing Guest user, or creates one if it doesn't exist. * @param context App context * @return UserInfo representing the Guest user */ @Nullable public UserInfo createNewOrFindExistingGuest(Context context) { // CreateGuest will return null if a guest already exists. UserInfo newGuest = mUserManager.createGuest(context, mGuestName); if (newGuest != null) { new UserIconProvider().assignDefaultIcon( mUserManager, context.getResources(), newGuest); return newGuest; } return mUserManager.findCurrentGuestUser(); } @Override public void onClick(DialogInterface dialog, int which) { if (which == BUTTON_POSITIVE) { Loading
packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserIconProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ public class UserIconProvider { * @param userInfo User whose avatar is set to default icon. * @return Bitmap of the user icon. */ private Bitmap assignDefaultIcon( public Bitmap assignDefaultIcon( UserManager userManager, Resources resources, UserInfo userInfo) { Bitmap bitmap = userInfo.isGuest() ? getGuestUserDefaultIcon(resources) Loading
services/core/java/com/android/server/pm/UserManagerService.java +6 −1 Original line number Diff line number Diff line Loading @@ -3452,8 +3452,13 @@ public class UserManagerService extends IUserManager.Stub { /** * Find the current guest user. If the Guest user is partial, * then do not include it in the results as it is about to die. * * @return The current guest user. Null if it doesn't exist. * @hide */ private UserInfo findCurrentGuestUser() { @Override public UserInfo findCurrentGuestUser() { checkManageUsersPermission("findCurrentGuestUser"); synchronized (mUsersLock) { final int size = mUsers.size(); for (int i = 0; i < size; i++) { Loading