From 4886465390bc7899d664057c0d6b6f15fdf19f62 Mon Sep 17 00:00:00 2001 From: Anthony Hugh Date: Tue, 29 Oct 2019 13:12:02 -0700 Subject: [PATCH] Update to use UserManager.getUserSwitchability() Updated framework to handle user switchability cases, so use that instead of CarUserManagerHelper. Bug: 131776619 Test: Manually play with user picker. Test: [1] Open User Picker [2] Verify can switch to a different user user [3] adb root && adb shell pm set-user-restriction --user 10 no_user_switch 1 [4] Verify can't switch to a different user [5] adb root && adb shell pm set-user-restriction --user 10 no_user_switch 0 [6] adb root && adb shell pm set-user-restriction --user 0 no_user_switch 1 [7] Verify can user switch Change-Id: Ie898723bd93a85d0ea01a9d0879af0c84e904c98 --- .../systemui/statusbar/car/UserGridRecyclerView.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 05657fff70e04..fb1870a6ea42e 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/UserGridRecyclerView.java @@ -19,6 +19,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 static android.os.UserManager.SWITCHABILITY_STATUS_OK; import android.app.ActivityManager; import android.app.AlertDialog; @@ -123,10 +124,12 @@ public class UserGridRecyclerView extends RecyclerView { } private List createUserRecords(List userInfoList) { + int fgUserId = ActivityManager.getCurrentUser(); + UserHandle fgUserHandle = UserHandle.of(fgUserId); List userRecords = new ArrayList<>(); // If the foreground user CANNOT switch to other users, only display the foreground user. - if (!mCarUserManagerHelper.canForegroundUserSwitchUsers()) { + if (mUserManager.getUserSwitchability(fgUserHandle) != SWITCHABILITY_STATUS_OK) { userRecords.add(createForegroundUserRecord()); return userRecords; } @@ -137,7 +140,7 @@ public class UserGridRecyclerView extends RecyclerView { continue; } - boolean isForeground = ActivityManager.getCurrentUser() == userInfo.id; + boolean isForeground = fgUserId == userInfo.id; UserRecord record = new UserRecord(userInfo, false /* isStartGuestSession */, false /* isAddUser */, isForeground); userRecords.add(record); @@ -147,7 +150,6 @@ public class UserGridRecyclerView extends RecyclerView { userRecords.add(createStartGuestUserRecord()); // Add add user record if the foreground user can add users - UserHandle fgUserHandle = UserHandle.of(ActivityManager.getCurrentUser()); if (!mUserManager.hasUserRestriction(DISALLOW_ADD_USER, fgUserHandle)) { userRecords.add(createAddUserRecord()); }