Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84bb2740 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improved AbstractMasterSystemService to handle supported user types."

parents b636296c 987655d0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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();
}
+6 −2
Original line number Diff line number Diff line
@@ -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
@@ -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");
+7 −4
Original line number Diff line number Diff line
@@ -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);
@@ -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<UserInfo> users = um.getUsers();
        final List<UserInfo> users = getSupportedUsers();

        final boolean newDisabledValue;

+40 −5
Original line number Diff line number Diff line
@@ -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<M extends AbstractMasterSystem
    @GuardedBy("mLock")
    private SparseArray<String> mUpdatingPackageNames;

    /**
     * Lazy-loadable reference to {@link UserManagerInternal}.
     */
    @Nullable
    private UserManagerInternal mUm;

    /**
     * Default constructor.
     *
@@ -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);
@@ -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.
     *
@@ -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(": ");
+11 −0
Original line number Diff line number Diff line
@@ -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. */