From aa407a9cca0c3b6808a9d68636f6549e46643ecd Mon Sep 17 00:00:00 2001 From: Anthony Hugh Date: Thu, 17 Oct 2019 17:02:50 -0700 Subject: [PATCH] Swap for more framework APIs Swap CarUserManagerHelper.isUserLimitReached() with !UserManager.canAddMoreUsers(). Swap CarUserManagerHelper.canForegroundUserAddUsers() with UserManager.hasUserRestriction(). Implementation is the essentially the same, but UserManager APIs are better supported across the system. Bug: 131776619 Test: atest CarSettingsRoboTests Test: Manually play with UserPicker and changing max user size Test: adb shell pm set-user-restriction --user 10 no_add_user 1 Then verify add user button does not appear in UserPicker Change-Id: I8b44ada6423f2a14c11170d890740034c8e9d34f --- .../systemui/statusbar/car/UserGridRecyclerView.java | 6 ++++-- 1 file changed, 4 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 30144524fd42c..3b482599b2a00 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.car; import static android.content.DialogInterface.BUTTON_NEGATIVE; import static android.content.DialogInterface.BUTTON_POSITIVE; +import static android.os.UserManager.DISALLOW_ADD_USER; import android.app.ActivityManager; import android.app.AlertDialog; @@ -145,7 +146,8 @@ public class UserGridRecyclerView extends RecyclerView { userRecords.add(createStartGuestUserRecord()); // Add add user record if the foreground user can add users - if (mCarUserManagerHelper.canForegroundUserAddUsers()) { + UserHandle fgUserHandle = UserHandle.of(ActivityManager.getCurrentUser()); + if (!mUserManager.hasUserRestriction(DISALLOW_ADD_USER, fgUserHandle)) { userRecords.add(createAddUserRecord()); } @@ -285,7 +287,7 @@ public class UserGridRecyclerView extends RecyclerView { } private void handleAddUserClicked() { - if (mCarUserManagerHelper.isUserLimitReached()) { + if (!mUserManager.canAddMoreUsers()) { mAddUserView.setEnabled(true); showMaxUserLimitReachedDialog(); } else {