Loading core/java/android/os/UserManagerInternal.java +6 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.content.Context; Loading Loading @@ -231,4 +232,9 @@ public abstract class UserManagerInternal { * found. */ public abstract @Nullable UserInfo getUserInfo(@UserIdInt int userId); /** * Gets all {@link UserInfo UserInfos}. */ public abstract @NonNull UserInfo[] getUserInfos(); } services/autofill/java/com/android/server/autofill/AutofillManagerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -212,8 +212,7 @@ public final class AutofillManagerService (u, s, t) -> onAugmentedServiceNameChanged(u, s, t)); if (mSupportedSmartSuggestionModes != AutofillManager.FLAG_SMART_SUGGESTION_OFF) { final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; // Must eager load the services so they bind to the augmented autofill service Loading Loading @@ -324,6 +323,11 @@ public final class AutofillManagerService publishLocalService(AutofillManagerInternal.class, mLocalService); } @Override // from SystemService public boolean isSupported(UserInfo userInfo) { return userInfo.isFull() || userInfo.isManagedProfile(); } @Override // from SystemService public void onSwitchUser(int userHandle) { if (sDebug) Slog.d(TAG, "Hiding UI when user switched"); Loading services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +7 −4 Original line number Diff line number Diff line Loading @@ -147,8 +147,7 @@ public final class ContentCaptureManagerService extends mRequestsHistory = null; } final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = !isEnabledBySettings(userId); Loading @@ -173,6 +172,11 @@ public final class ContentCaptureManagerService extends return new ContentCapturePerUserService(this, mLock, disabled, resolvedUserId); } @Override // from SystemService public boolean isSupported(UserInfo userInfo) { return userInfo.isFull() || userInfo.isManagedProfile(); } @Override // from SystemService public void onStart() { publishBinderService(CONTENT_CAPTURE_MANAGER_SERVICE, Loading Loading @@ -336,8 +340,7 @@ public final class ContentCaptureManagerService extends if (verbose) { Slog.v(mTag, "setDisabledByDeviceConfig(): explicitlyEnabled=" + explicitlyEnabled); } final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); final boolean newDisabledValue; Loading services/core/java/com/android/server/infra/AbstractMasterSystemService.java +40 −5 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import com.android.server.SystemService; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; /** Loading Loading @@ -166,6 +167,12 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem @GuardedBy("mLock") private SparseArray<String> mUpdatingPackageNames; /** * Lazy-loadable reference to {@link UserManagerInternal}. */ @Nullable private UserManagerInternal mUm; /** * Default constructor. * Loading Loading @@ -222,9 +229,8 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem } else { mDisabledByUserRestriction = new SparseBooleanArray(); // Hookup with UserManager to disable service when necessary. final UserManager um = context.getSystemService(UserManager.class); final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class); final List<UserInfo> users = um.getUsers(); final UserManagerInternal umi = getUserManagerInternal(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = umi.getUserRestriction(userId, disallowProperty); Loading Loading @@ -648,6 +654,36 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem mServicesCache.clear(); } /** * Gets a cached reference to {@link UserManagerInternal}. */ @NonNull protected UserManagerInternal getUserManagerInternal() { if (mUm == null) { if (verbose) Slog.v(mTag, "lazy-loading UserManagerInternal"); mUm = LocalServices.getService(UserManagerInternal.class); } return mUm; } /** * Gets a list of all supported users (i.e., those that pass the {@link #isSupported(UserInfo)} * check). */ @NonNull protected List<UserInfo> getSupportedUsers() { final UserInfo[] allUsers = getUserManagerInternal().getUserInfos(); final int size = allUsers.length; final List<UserInfo> supportedUsers = new ArrayList<>(size); for (int i = 0; i < size; i++) { final UserInfo userInfo = allUsers[i]; if (isSupported(userInfo)) { supportedUsers.add(userInfo); } } return supportedUsers; } /** * Asserts that the given package name is owned by the UID making this call. * Loading Loading @@ -684,8 +720,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem if (mServiceNameResolver != null) { pw.print(prefix); pw.print("Name resolver: "); mServiceNameResolver.dumpShort(pw); pw.println(); final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; pw.print(prefix2); pw.print(userId); pw.print(": "); Loading services/core/java/com/android/server/pm/UserManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -4180,6 +4180,17 @@ public class UserManagerService extends IUserManager.Stub { } return userData == null ? null : userData.info; } public @NonNull UserInfo[] getUserInfos() { synchronized (mUsersLock) { int userSize = mUsers.size(); UserInfo[] allInfos = new UserInfo[userSize]; for (int i = 0; i < userSize; i++) { allInfos[i] = mUsers.valueAt(i).info; } return allInfos; } } } /* Remove all the users except of the system one. */ Loading Loading
core/java/android/os/UserManagerInternal.java +6 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.content.Context; Loading Loading @@ -231,4 +232,9 @@ public abstract class UserManagerInternal { * found. */ public abstract @Nullable UserInfo getUserInfo(@UserIdInt int userId); /** * Gets all {@link UserInfo UserInfos}. */ public abstract @NonNull UserInfo[] getUserInfos(); }
services/autofill/java/com/android/server/autofill/AutofillManagerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -212,8 +212,7 @@ public final class AutofillManagerService (u, s, t) -> onAugmentedServiceNameChanged(u, s, t)); if (mSupportedSmartSuggestionModes != AutofillManager.FLAG_SMART_SUGGESTION_OFF) { final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; // Must eager load the services so they bind to the augmented autofill service Loading Loading @@ -324,6 +323,11 @@ public final class AutofillManagerService publishLocalService(AutofillManagerInternal.class, mLocalService); } @Override // from SystemService public boolean isSupported(UserInfo userInfo) { return userInfo.isFull() || userInfo.isManagedProfile(); } @Override // from SystemService public void onSwitchUser(int userHandle) { if (sDebug) Slog.d(TAG, "Hiding UI when user switched"); Loading
services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +7 −4 Original line number Diff line number Diff line Loading @@ -147,8 +147,7 @@ public final class ContentCaptureManagerService extends mRequestsHistory = null; } final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = !isEnabledBySettings(userId); Loading @@ -173,6 +172,11 @@ public final class ContentCaptureManagerService extends return new ContentCapturePerUserService(this, mLock, disabled, resolvedUserId); } @Override // from SystemService public boolean isSupported(UserInfo userInfo) { return userInfo.isFull() || userInfo.isManagedProfile(); } @Override // from SystemService public void onStart() { publishBinderService(CONTENT_CAPTURE_MANAGER_SERVICE, Loading Loading @@ -336,8 +340,7 @@ public final class ContentCaptureManagerService extends if (verbose) { Slog.v(mTag, "setDisabledByDeviceConfig(): explicitlyEnabled=" + explicitlyEnabled); } final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); final boolean newDisabledValue; Loading
services/core/java/com/android/server/infra/AbstractMasterSystemService.java +40 −5 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import com.android.server.SystemService; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; /** Loading Loading @@ -166,6 +167,12 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem @GuardedBy("mLock") private SparseArray<String> mUpdatingPackageNames; /** * Lazy-loadable reference to {@link UserManagerInternal}. */ @Nullable private UserManagerInternal mUm; /** * Default constructor. * Loading Loading @@ -222,9 +229,8 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem } else { mDisabledByUserRestriction = new SparseBooleanArray(); // Hookup with UserManager to disable service when necessary. final UserManager um = context.getSystemService(UserManager.class); final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class); final List<UserInfo> users = um.getUsers(); final UserManagerInternal umi = getUserManagerInternal(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = umi.getUserRestriction(userId, disallowProperty); Loading Loading @@ -648,6 +654,36 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem mServicesCache.clear(); } /** * Gets a cached reference to {@link UserManagerInternal}. */ @NonNull protected UserManagerInternal getUserManagerInternal() { if (mUm == null) { if (verbose) Slog.v(mTag, "lazy-loading UserManagerInternal"); mUm = LocalServices.getService(UserManagerInternal.class); } return mUm; } /** * Gets a list of all supported users (i.e., those that pass the {@link #isSupported(UserInfo)} * check). */ @NonNull protected List<UserInfo> getSupportedUsers() { final UserInfo[] allUsers = getUserManagerInternal().getUserInfos(); final int size = allUsers.length; final List<UserInfo> supportedUsers = new ArrayList<>(size); for (int i = 0; i < size; i++) { final UserInfo userInfo = allUsers[i]; if (isSupported(userInfo)) { supportedUsers.add(userInfo); } } return supportedUsers; } /** * Asserts that the given package name is owned by the UID making this call. * Loading Loading @@ -684,8 +720,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem if (mServiceNameResolver != null) { pw.print(prefix); pw.print("Name resolver: "); mServiceNameResolver.dumpShort(pw); pw.println(); final UserManager um = getContext().getSystemService(UserManager.class); final List<UserInfo> users = um.getUsers(); final List<UserInfo> users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; pw.print(prefix2); pw.print(userId); pw.print(": "); Loading
services/core/java/com/android/server/pm/UserManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -4180,6 +4180,17 @@ public class UserManagerService extends IUserManager.Stub { } return userData == null ? null : userData.info; } public @NonNull UserInfo[] getUserInfos() { synchronized (mUsersLock) { int userSize = mUsers.size(); UserInfo[] allInfos = new UserInfo[userSize]; for (int i = 0; i < userSize; i++) { allInfos[i] = mUsers.valueAt(i).info; } return allInfos; } } } /* Remove all the users except of the system one. */ Loading