From 987655d0498078643cf8b5aec9fb4403bf71aef3 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 26 Aug 2019 10:45:24 -0700 Subject: [PATCH] Improved AbstractMasterSystemService to handle supported user types. Also changed AutofillManagerService and ContentCaptureManagerService to take advantage of these methods. Test: manual verification Test: atest CtsAutoFillServiceTestCases CtsContentCaptureServiceTestCases # on phone and Automotive Bug: 133242016 Change-Id: I3e7f9d65a6ef1e8e6ec886a41b35733e463a6389 --- core/java/android/os/UserManagerInternal.java | 6 +++ .../autofill/AutofillManagerService.java | 8 +++- .../ContentCaptureManagerService.java | 11 +++-- .../infra/AbstractMasterSystemService.java | 45 ++++++++++++++++--- .../android/server/pm/UserManagerService.java | 11 +++++ 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/core/java/android/os/UserManagerInternal.java b/core/java/android/os/UserManagerInternal.java index f302263f23ce8..ddd949d64a1f3 100644 --- a/core/java/android/os/UserManagerInternal.java +++ b/core/java/android/os/UserManagerInternal.java @@ -15,6 +15,7 @@ */ package android.os; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.content.Context; @@ -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(); } diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 6b7c3e69e54ed..c689ed1c64c7c 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -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 users = um.getUsers(); + final List 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 @@ -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"); diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java index 5c6258ffe4cb7..c8dbb363bc36c 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java @@ -147,8 +147,7 @@ public final class ContentCaptureManagerService extends mRequestsHistory = null; } - final UserManager um = getContext().getSystemService(UserManager.class); - final List users = um.getUsers(); + final List users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = !isEnabledBySettings(userId); @@ -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, @@ -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 users = um.getUsers(); + final List users = getSupportedUsers(); final boolean newDisabledValue; diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java index 9782f30d30743..a9c4d088f203c 100644 --- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java +++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java @@ -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; /** @@ -166,6 +167,12 @@ public abstract class AbstractMasterSystemService mUpdatingPackageNames; + /** + * Lazy-loadable reference to {@link UserManagerInternal}. + */ + @Nullable + private UserManagerInternal mUm; + /** * Default constructor. * @@ -222,9 +229,8 @@ public abstract class AbstractMasterSystemService users = um.getUsers(); + final UserManagerInternal umi = getUserManagerInternal(); + final List users = getSupportedUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean disabled = umi.getUserRestriction(userId, disallowProperty); @@ -648,6 +654,36 @@ public abstract class AbstractMasterSystemService getSupportedUsers() { + final UserInfo[] allUsers = getUserManagerInternal().getUserInfos(); + final int size = allUsers.length; + final List 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. * @@ -684,8 +720,7 @@ public abstract class AbstractMasterSystemService users = um.getUsers(); + final List 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(": "); diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 1fe551222a063..65fb35d34c011 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -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. */