diff options
| author | 2022-10-05 17:49:54 -0700 | |
|---|---|---|
| committer | 2022-10-05 17:49:54 -0700 | |
| commit | f04121f0aa3c988799d6efc92f1697e00a84f76a (patch) | |
| tree | fac3c5d2e7d2aa58d801c136016d20e11847496a | |
| parent | fc48388a5bd359bff444799b2013f6f069183a27 (diff) | |
Add UserManagerInternal#getProfileIds()
The public API
int[] UserManager#getProfileIds(int userId, boolean enabledOnly)
looks to be used enough in system_server process. Let's have it in
UserManagerInternal as well.
Bug: 234882948
Test: atest CtsInputMethodServiceHostTestCases:MultiUserTest
Change-Id: Ie1e6bab0f9a5d2801ad57c89c23f0798276d8aa2
3 files changed, 24 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index ab05e034562b..28a62f53f356 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1926,7 +1926,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub void updateCurrentProfileIds() { mSettings.setCurrentProfileIds( - mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); + mUserManagerInternal.getProfileIds(mSettings.getCurrentUserId(), + false /* enabledOnly */)); } @Override @@ -3669,7 +3670,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub scheduleSwitchUserTaskLocked(userId, cs.mClient); return InputBindResult.USER_SWITCHING; } - for (int profileId : mUserManager.getProfileIdsWithDisabled(nextUserId)) { + final int[] profileIdsWithDisabled = mUserManagerInternal.getProfileIds( + mSettings.getCurrentUserId(), false /* enabledOnly */); + for (int profileId : profileIdsWithDisabled) { if (profileId == userId) { scheduleSwitchUserTaskLocked(userId, cs.mClient); return InputBindResult.USER_SWITCHING; diff --git a/services/core/java/com/android/server/pm/UserManagerInternal.java b/services/core/java/com/android/server/pm/UserManagerInternal.java index b9770254fb46..56ec8e46291d 100644 --- a/services/core/java/com/android/server/pm/UserManagerInternal.java +++ b/services/core/java/com/android/server/pm/UserManagerInternal.java @@ -248,6 +248,18 @@ public abstract class UserManagerInternal { boolean excludePreCreated); /** + * Returns an array of ids for profiles associated with the specified user including the user + * itself. + * <p>Note that this includes all profile types (not including Restricted profiles). + * + * @param userId id of the user to return profiles for + * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles + * @return A non-empty array of ids of profiles associated with the specified user if the user + * exists. Otherwise, an empty array. + */ + public abstract @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly); + + /** * Checks if the {@code callingUserId} and {@code targetUserId} are same or in same group * and that the {@code callingUserId} is not a profile and {@code targetUserId} is enabled. * diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 0a89d131eda2..0a4669c0aace 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -6700,6 +6700,13 @@ public class UserManagerService extends IUserManager.Stub { } @Override + public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { + synchronized (mUsersLock) { + return getProfileIdsLU(userId, null /* userType */, enabledOnly).toArray(); + } + } + + @Override public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { int state; synchronized (mUserStates) { |