From f018e12b68f652ab43b95b8c40cafeff523cf3c3 Mon Sep 17 00:00:00 2001 From: Anthony Hugh Date: Tue, 26 Nov 2019 13:22:02 -0800 Subject: [PATCH] Move getMaxSupportedRealUsers() to App layer Moves API to app layer as it is just for a display string. Fixes: 145228444 Test: atest CarUserManagerHelperTest Test: atest CarSettingsRoboTests Change-Id: I440e4a4d3c21b97c3d5c77110d43e6b9c98210c6 --- .../statusbar/car/UserGridRecyclerView.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java index fb1870a6ea42e..7500bcd9b8f75 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java @@ -296,14 +296,42 @@ public class UserGridRecyclerView extends RecyclerView { } } + /** + * Get the maximum number of real (non-guest, non-managed profile) users that can be created + * on the device. This is a dynamic value and it decreases with the increase of the number + * of managed profiles on the device. + * + *

It excludes system user in headless system user model. + * + * @return Maximum number of real users that can be created. + */ + private int getMaxSupportedRealUsers() { + int maxSupportedUsers = UserManager.getMaxSupportedUsers(); + if (UserManager.isHeadlessSystemUserMode()) { + maxSupportedUsers -= 1; + } + + List users = mUserManager.getUsers(/* excludeDying= */ true); + + // Count all users that are managed profiles of another user. + int managedProfilesCount = 0; + for (UserInfo user : users) { + if (user.isManagedProfile()) { + managedProfilesCount++; + } + } + + return maxSupportedUsers - managedProfilesCount; + } + private void showMaxUserLimitReachedDialog() { AlertDialog maxUsersDialog = new Builder(mContext, com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert) .setTitle(R.string.user_limit_reached_title) .setMessage(getResources().getQuantityString( R.plurals.user_limit_reached_message, - mCarUserManagerHelper.getMaxSupportedRealUsers(), - mCarUserManagerHelper.getMaxSupportedRealUsers())) + getMaxSupportedRealUsers(), + getMaxSupportedRealUsers())) .setPositiveButton(android.R.string.ok, null) .create(); // Sets window flags for the SysUI dialog