Adds an info dialog when a maximum number of users on the device is reached.

Change-Id: I559ddbcbc22f0388af22d807711533659eed8421
Fixes: 111075706
Test: Manual tests on mojave, pre-limit and post-limit reached.
(cherry picked from commit bc4d90d0c99607cf2b812345c2192814a06649aa)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java
index b376c00..da6401c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java
@@ -164,7 +164,6 @@
         private final Resources mRes;
         private final String mGuestName;
         private final String mNewUserName;
-        private AlertDialog mDialog;
         // View that holds the add user button.  Used to enable/disable the view
         private View mAddUserView;
         // User record for the add user.  Need to call notifyUserSelected only if the user
@@ -221,23 +220,9 @@
                     // Disable button so it cannot be clicked multiple times
                     mAddUserView = holder.mView;
                     mAddUserView.setEnabled(false);
-
-                    String message = mRes.getString(R.string.user_add_user_message_setup)
-                        .concat(System.getProperty("line.separator"))
-                        .concat(System.getProperty("line.separator"))
-                        .concat(mRes.getString(R.string.user_add_user_message_update));
-
                     mAddUserRecord = userRecord;
-                    mDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
-                        .setTitle(R.string.user_add_user_title)
-                        .setMessage(message)
-                        .setNegativeButton(android.R.string.cancel, this)
-                        .setPositiveButton(android.R.string.ok, this)
-                        .setOnCancelListener(this)
-                        .create();
-                    // Sets window flags for the SysUI dialog
-                    SystemUIDialog.applyFlags(mDialog);
-                    mDialog.show();
+
+                    handleAddUserClicked();
                     return;
                 }
                 // If the user doesn't want to be a guest or add a user, switch to the user selected
@@ -247,6 +232,47 @@
 
         }
 
+        private void handleAddUserClicked() {
+            if (mCarUserManagerHelper.isUserLimitReached()) {
+                mAddUserView.setEnabled(true);
+                showMaxUserLimitReachedDialog();
+            } else {
+                showConfirmAddUserDialog();
+            }
+        }
+
+        private void showMaxUserLimitReachedDialog() {
+            AlertDialog maxUsersDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
+                .setTitle(R.string.user_limit_reached_title)
+                .setMessage(getResources().getQuantityString(
+                    R.plurals.user_limit_reached_message,
+                    mCarUserManagerHelper.getMaxSupportedRealUsers(),
+                    mCarUserManagerHelper.getMaxSupportedRealUsers()))
+                .setPositiveButton(android.R.string.ok, null)
+                .create();
+            // Sets window flags for the SysUI dialog
+            SystemUIDialog.applyFlags(maxUsersDialog);
+            maxUsersDialog.show();
+        }
+
+        private void showConfirmAddUserDialog() {
+            String message = mRes.getString(R.string.user_add_user_message_setup)
+                .concat(System.getProperty("line.separator"))
+                .concat(System.getProperty("line.separator"))
+                .concat(mRes.getString(R.string.user_add_user_message_update));
+
+            AlertDialog addUserDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
+                .setTitle(R.string.user_add_user_title)
+                .setMessage(message)
+                .setNegativeButton(android.R.string.cancel, this)
+                .setPositiveButton(android.R.string.ok, this)
+                .setOnCancelListener(this)
+                .create();
+            // Sets window flags for the SysUI dialog
+            SystemUIDialog.applyFlags(addUserDialog);
+            addUserDialog.show();
+        }
+
         private void notifyUserSelected(UserRecord userRecord) {
             // Notify the listener which user was selected
             if (mUserSelectionListener != null) {