Merge "Refactor getAllUsers"
This commit is contained in:
committed by
Android (Google) Code Review
commit
ade89d37a1
@@ -34,6 +34,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -52,6 +53,8 @@ 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.
|
||||
@@ -61,6 +64,7 @@ public class UserGridRecyclerView extends RecyclerView {
|
||||
private UserSelectionListener mUserSelectionListener;
|
||||
private UserAdapter mAdapter;
|
||||
private CarUserManagerHelper mCarUserManagerHelper;
|
||||
private UserManager mUserManager;
|
||||
private Context mContext;
|
||||
|
||||
private final BroadcastReceiver mUserUpdateReceiver = new BroadcastReceiver() {
|
||||
@@ -74,6 +78,7 @@ public class UserGridRecyclerView extends RecyclerView {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
mCarUserManagerHelper = new CarUserManagerHelper(mContext);
|
||||
mUserManager = UserManager.get(mContext);
|
||||
|
||||
addItemDecoration(new ItemSpacingDecoration(context.getResources().getDimensionPixelSize(
|
||||
R.dimen.car_user_switcher_vertical_spacing_between_users)));
|
||||
@@ -103,12 +108,23 @@ public class UserGridRecyclerView extends RecyclerView {
|
||||
* @return the adapter
|
||||
*/
|
||||
public void buildAdapter() {
|
||||
List<UserRecord> userRecords = createUserRecords(mCarUserManagerHelper
|
||||
.getAllUsers());
|
||||
List<UserRecord> userRecords = createUserRecords(getAllUsers());
|
||||
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<UserRecord> createUserRecords(List<UserInfo> userInfoList) {
|
||||
List<UserRecord> userRecords = new ArrayList<>();
|
||||
|
||||
@@ -173,7 +189,7 @@ public class UserGridRecyclerView extends RecyclerView {
|
||||
|
||||
private void onUsersUpdate() {
|
||||
mAdapter.clearUsers();
|
||||
mAdapter.updateUsers(createUserRecords(mCarUserManagerHelper.getAllUsers()));
|
||||
mAdapter.updateUsers(createUserRecords(getAllUsers()));
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user