Include disabled managed profiles in Accounts page
At the moment we include disabled profiles when deciding
whether the Work section needs to be added, and then only
include enabled ones when searching for the managed profile's
user handle
Change-Id: I96b0c36aad6b9326abc2992fa3309716f5cd1e74
Fix: 62021410
Test: m RunSettingsRoboTests
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 0142ea2..7b69fe0 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -602,7 +602,8 @@
}
/**
- * Returns the managed profile of the current user or null if none found.
+ * Returns the managed profile of the current user or {@code null} if none is found or a profile
+ * exists but it is disabled.
*/
public static UserHandle getManagedProfile(UserManager userManager) {
List<UserHandle> userProfiles = userManager.getUserProfiles();
@@ -621,6 +622,29 @@
}
/**
+ * Returns the managed profile of the current user or {@code null} if none is found. Unlike
+ * {@link #getManagedProfile} this method returns enabled and disabled managed profiles.
+ */
+ public static UserHandle getManagedProfileWithDisabled(UserManager userManager) {
+ // TODO: Call getManagedProfileId from here once Robolectric supports
+ // API level 24 and UserManager.getProfileIdsWithDisabled can be Mocked (to avoid having
+ // yet another implementation that loops over user profiles in this method). In the meantime
+ // we need to use UserManager.getProfiles that is available on API 23 (the one currently
+ // used for Settings Robolectric tests).
+ final int myUserId = UserHandle.myUserId();
+ List<UserInfo> profiles = userManager.getProfiles(myUserId);
+ final int count = profiles.size();
+ for (int i = 0; i < count; i++) {
+ final UserInfo profile = profiles.get(i);
+ if (profile.isManagedProfile()
+ && profile.getUserHandle().getIdentifier() != myUserId) {
+ return profile.getUserHandle();
+ }
+ }
+ return null;
+ }
+
+ /**
* Retrieves the id for the given user's managed profile.
*
* @return the managed profile id or UserHandle.USER_NULL if there is none.