Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fdc3dcf authored by Anthony Hugh's avatar Anthony Hugh Committed by Android (Google) Code Review
Browse files

Merge "Update UserInfo.supportsSwitchToByUser to support Headless User Mode"

parents b151f194 75908bcb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ public class UserInfo implements Parcelable {
     */
    public boolean supportsSwitchToByUser() {
        // Hide the system user when it does not represent a human user.
        boolean hideSystemUser = UserManager.isSplitSystemUser();
        boolean hideSystemUser = UserManager.isHeadlessSystemUserMode();
        return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo();
    }

+7 −13
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import com.android.systemui.statusbar.phone.SystemUIDialog;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Displays a GridLayout with icons for the users in the system to allow switching between users.
@@ -109,21 +108,16 @@ public class UserGridRecyclerView extends RecyclerView {
     * @return the adapter
     */
    public void buildAdapter() {
        List<UserRecord> userRecords = createUserRecords(getAllUsers());
        List<UserRecord> userRecords = createUserRecords(getUsersForUserGrid());
        mAdapter = new UserAdapter(mContext, userRecords);
        super.setAdapter(mAdapter);
    }

    private List<UserInfo> getAllUsers() {
        Stream<UserInfo> userListStream =
                mUserManager.getUsers(/* excludeDying= */ true).stream();

        if (UserManager.isHeadlessSystemUserMode()) {
            userListStream =
                    userListStream.filter(userInfo -> userInfo.id != UserHandle.USER_SYSTEM);
        }
        userListStream = userListStream.filter(userInfo -> userInfo.supportsSwitchToByUser());
        return userListStream.collect(Collectors.toList());
    private List<UserInfo> getUsersForUserGrid() {
        return mUserManager.getUsers(/* excludeDying= */ true)
                .stream()
                .filter(UserInfo::supportsSwitchToByUser)
                .collect(Collectors.toList());
    }

    private List<UserRecord> createUserRecords(List<UserInfo> userInfoList) {
@@ -189,7 +183,7 @@ public class UserGridRecyclerView extends RecyclerView {

    private void onUsersUpdate() {
        mAdapter.clearUsers();
        mAdapter.updateUsers(createUserRecords(getAllUsers()));
        mAdapter.updateUsers(createUserRecords(getUsersForUserGrid()));
        mAdapter.notifyDataSetChanged();
    }