Improve multi user settings screen

- Added switch and user delete functionality to details screen.
- Added robo tests.

Screenshots: http://shortn/_S6fbIMhAYO
Bug: 142798722
Test: Run robo tests with this command:
  make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.users.*SettingsTest"
Change-Id: Id51c12c5470e30e2dffe93f3bd8c22380d8bdc1f
This commit is contained in:
Andras Kloczl
2020-04-21 11:32:12 +01:00
parent 18490b2dc8
commit d19dc306dd
16 changed files with 1478 additions and 523 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.testutils.shadow;
import android.annotation.UserIdInt;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager.EnforcingUser;
@@ -43,13 +44,18 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
private static boolean sIsSupportsMultipleUsers;
private final List<String> mRestrictions = new ArrayList<>();
private final List<String> mBaseRestrictions = new ArrayList<>();
private final List<String> mUserRestrictions = new ArrayList<>();
private final List<String> mGuestRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
private final List<UserInfo> mUserProfileInfos = new ArrayList<>();
private final Set<Integer> mManagedProfiles = new HashSet<>();
private boolean mIsQuietModeEnabled = false;
private int[] profileIdsForUser = new int[0];
private boolean mUserSwitchEnabled;
private @UserManager.UserSwitchabilityResult int mSwitchabilityStatus =
UserManager.SWITCHABILITY_STATUS_OK;
private final Map<Integer, Integer> mSameProfileGroupIds = Maps.newHashMap();
public void addProfile(UserInfo userInfo) {
@@ -82,11 +88,32 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
@Implementation
protected boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
return mRestrictions.contains(restrictionKey);
return mBaseRestrictions.contains(restrictionKey);
}
public void addBaseUserRestriction(String restriction) {
mRestrictions.add(restriction);
mBaseRestrictions.add(restriction);
}
@Implementation
protected boolean hasUserRestriction(@UserManager.UserRestrictionKey String restrictionKey,
UserHandle userHandle) {
return mUserRestrictions.contains(restrictionKey);
}
public void addUserRestriction(String restriction) {
mUserRestrictions.add(restriction);
}
@Implementation
protected Bundle getDefaultGuestRestrictions() {
Bundle bundle = new Bundle();
mGuestRestrictions.forEach(restriction -> bundle.putBoolean(restriction, true));
return bundle;
}
public void addGuestUserRestriction(String restriction) {
mGuestRestrictions.add(restriction);
}
public static ShadowUserManager getShadow() {
@@ -166,4 +193,21 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
public void setSupportsMultipleUsers(boolean supports) {
sIsSupportsMultipleUsers = supports;
}
@Implementation
protected UserInfo getUserInfo(@UserIdInt int userId) {
return mUserProfileInfos.stream()
.filter(userInfo -> userInfo.id == userId)
.findFirst()
.orElse(super.getUserInfo(userId));
}
@Implementation
protected @UserManager.UserSwitchabilityResult int getUserSwitchability() {
return mSwitchabilityStatus;
}
public void setSwitchabilityStatus(@UserManager.UserSwitchabilityResult int newStatus) {
mSwitchabilityStatus = newStatus;
}
}