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

Commit 6b0064a4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SpecialUserHandle annotation: handleIncomingUser" into main

parents c032c46c 07a2387d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.SpecialUsers.CanBeCURRENT;
import android.annotation.SpecialUsers.CanBeCURRENT_OR_SELF;
import android.annotation.SpecialUsers.CannotBeSpecialUser;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
@@ -5269,7 +5270,8 @@ public class ActivityManager {
     * user number, unless <var>allowAll</var> is true in which case it could also be
     * USER_ALL.
     */
    public static int handleIncomingUser(int callingPid, int callingUid, int userId,
    public static @CanBeALL @UserIdInt int handleIncomingUser(int callingPid, int callingUid,
            @CanBeALL @CanBeCURRENT @CanBeCURRENT_OR_SELF @UserIdInt int userId,
            boolean allowAll, boolean requireFull, String name, String callerPackage) {
        if (UserHandle.getUserId(callingUid) == userId) {
            return userId;
+4 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.PermissionMethod;
import android.annotation.PermissionName;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.SpecialUsers.CanBeCURRENT;
import android.annotation.SpecialUsers.CanBeCURRENT_OR_SELF;
import android.annotation.UserIdInt;
import android.app.ActivityManager.ProcessCapability;
import android.app.ActivityManager.RestrictionLevel;
@@ -333,7 +334,8 @@ public abstract class ActivityManagerInternal {
     * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as
     * needed.
     */
    public abstract int handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId,
    public abstract @CanBeALL @UserIdInt int handleIncomingUser(int callingPid, int callingUid,
            @CanBeALL @CanBeCURRENT @CanBeCURRENT_OR_SELF @UserIdInt int userId,
            boolean allowAll, int allowMode, String name, String callerPackage);

    /** Checks if the calling binder pid/uid has the given permission. */
@@ -1339,7 +1341,7 @@ public abstract class ActivityManagerInternal {
     * @hide
     */
    public abstract boolean clearApplicationUserData(String packageName, boolean keepState,
            boolean isRestore, IPackageDataObserver observer, int userId);
            boolean isRestore, IPackageDataObserver observer, @CanBeCURRENT @UserIdInt int userId);


    /**
+5 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.os;
import android.annotation.AppIdInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SpecialUsers.CanBeUsers;
import android.annotation.SpecialUsers.SpecialUser;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
@@ -324,7 +326,9 @@ public final class UserHandle implements Parcelable {

    /** @hide */
    @SystemApi
    public static UserHandle of(@UserIdInt int userId) {
    public static @CanBeUsers(SpecialUser.ALLOW_EVERY) UserHandle of(
            @CanBeUsers(SpecialUser.ALLOW_EVERY) @UserIdInt int userId) {

        if (userId == USER_SYSTEM) {
            return SYSTEM; // Most common.
        }
+2 −2
Original line number Diff line number Diff line
@@ -6971,8 +6971,8 @@ public class UserManager {
        /**
         * @hide
         */
        public EnforcingUser(
                @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
        public EnforcingUser(@CanBeALL @CanBeNULL @UserIdInt int userId,
                @UserRestrictionSource int userRestrictionSource) {
            this.userId = userId;
            this.userRestrictionSource = userRestrictionSource;
        }
+28 −17
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ import android.annotation.PermissionName;
import android.annotation.RequiresPermission;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.SpecialUsers.CanBeCURRENT;
import android.annotation.SpecialUsers.CanBeCURRENT_OR_SELF;
import android.annotation.SpecialUsers.CannotBeSpecialUser;
import android.annotation.UserIdInt;
import android.app.Activity;
@@ -3522,13 +3523,14 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public boolean clearApplicationUserData(final String packageName, boolean keepState,
            final IPackageDataObserver observer, int userId) {
            final IPackageDataObserver observer, @CanBeCURRENT @UserIdInt int userId) {
        return clearApplicationUserData(packageName, keepState, /*isRestore=*/ false, observer,
                userId);
    }
    private boolean clearApplicationUserData(final String packageName, boolean keepState,
            boolean isRestore, final IPackageDataObserver observer, int userId) {
            boolean isRestore, final IPackageDataObserver observer,
            @CanBeCURRENT @UserIdInt int userId) {
        enforceNotIsolatedCaller("clearApplicationUserData");
        int uid = Binder.getCallingUid();
        int pid = Binder.getCallingPid();
@@ -3667,7 +3669,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public void killBackgroundProcesses(final String packageName, int userId) {
    public void killBackgroundProcesses(
            final String packageName, @CanBeALL @CanBeCURRENT @UserIdInt int userId) {
        if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES)
                != PackageManager.PERMISSION_GRANTED &&
                checkCallingPermission(android.Manifest.permission.RESTART_PACKAGES)
@@ -3835,8 +3838,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        forceStopPackage(packageName, userId, ActivityManager.FLAG_OR_STOPPED, null);
    }
    void forceStopPackage(final String packageName, int userId, int userRunningFlags,
            String reason) {
    void forceStopPackage(final String packageName, @CanBeALL @CanBeCURRENT @UserIdInt int userId,
            int userRunningFlags, String reason) {
        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
                != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: forceStopPackage() from pid="
@@ -10156,7 +10159,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public ParceledListSlice<ApplicationStartInfo> getHistoricalProcessStartReasons(
            String packageName, int maxNum, int userId) {
            String packageName, int maxNum, @CannotBeSpecialUser @UserIdInt int userId) {
        enforceNotIsolatedCaller("getHistoricalProcessStartReasons");
        // For the simplification, we don't support USER_ALL nor USER_CURRENT here.
        if (userId == UserHandle.USER_ALL || userId == UserHandle.USER_CURRENT) {
@@ -10187,7 +10190,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public void addApplicationStartInfoCompleteListener(
            IApplicationStartInfoCompleteListener listener, int userId) {
            IApplicationStartInfoCompleteListener listener,
            @CannotBeSpecialUser @UserIdInt int userId) {
        enforceNotIsolatedCaller("setApplicationStartInfoCompleteListener");
        // For the simplification, we don't support USER_ALL nor USER_CURRENT here.
@@ -10206,7 +10210,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public void removeApplicationStartInfoCompleteListener(
            IApplicationStartInfoCompleteListener listener, int userId) {
            IApplicationStartInfoCompleteListener listener,
            @CannotBeSpecialUser @UserIdInt int userId) {
        enforceNotIsolatedCaller("clearApplicationStartInfoCompleteListener");
        // For the simplification, we don't support USER_ALL nor USER_CURRENT here.
@@ -10223,7 +10228,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public void addStartInfoTimestamp(int key, long timestampNs, int userId) {
    public void addStartInfoTimestamp(
            int key, long timestampNs, @CannotBeSpecialUser @UserIdInt int userId) {
        enforceNotIsolatedCaller("addStartInfoTimestamp");
        // For the simplification, we don't support USER_ALL nor USER_CURRENT here.
@@ -10261,7 +10267,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public ParceledListSlice<ApplicationExitInfo> getHistoricalProcessExitReasons(
            String packageName, int pid, int maxNum, int userId) {
            String packageName, int pid, int maxNum, @CannotBeSpecialUser @UserIdInt int userId) {
        enforceNotIsolatedCaller("getHistoricalProcessExitReasons");
        // For the simplification, we don't support USER_ALL nor USER_CURRENT here.
@@ -13920,7 +13926,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
    public @CanBeALL @UserIdInt int handleIncomingUser(int callingPid, int callingUid,
            @CanBeALL @CanBeCURRENT @CanBeCURRENT_OR_SELF @UserIdInt int userId, boolean allowAll,
            boolean requireFull, String name, String callerPackage) {
        return mUserController.handleIncomingUser(callingPid, callingUid, userId, allowAll,
                requireFull ? ALLOW_FULL_ONLY : ALLOW_NON_FULL, name, callerPackage);
@@ -14299,7 +14306,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    // A backup agent has just come up
    @Override
    public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
    public void backupAgentCreated(
            String agentPackageName, IBinder agent, @CanBeCURRENT @UserIdInt int userId) {
        final int callingUid = Binder.getCallingUid();
        enforceCallingPackage(agentPackageName, callingUid);
@@ -14511,7 +14519,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    public boolean startInstrumentation(ComponentName className,
            String profileFile, int flags, Bundle arguments,
            IInstrumentationWatcher watcher, IUiAutomationConnection uiAutomationConnection,
            int userId, String abiOverride) {
            @CanBeCURRENT @UserIdInt int userId, String abiOverride) {
        enforceNotIsolatedCaller("startInstrumentation");
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();
@@ -15608,7 +15616,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public void makePackageIdle(String packageName, int userId) {
    public void makePackageIdle(String packageName, @CanBeALL @CanBeCURRENT @UserIdInt int userId) {
        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
                != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: makePackageIdle() from pid="
@@ -17104,7 +17112,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public int handleIncomingUser(int callingPid, int callingUid, int userId,
        public @CanBeALL @UserIdInt int handleIncomingUser(int callingPid, int callingUid,
                @CanBeALL @CanBeCURRENT @CanBeCURRENT_OR_SELF @UserIdInt int userId,
                boolean allowAll, int allowMode, String name, String callerPackage) {
            return mUserController.handleIncomingUser(callingPid, callingUid, userId, allowAll,
                    allowMode, name, callerPackage);
@@ -18217,7 +18226,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public boolean clearApplicationUserData(final String packageName, boolean keepState,
                boolean isRestore, final IPackageDataObserver observer, int userId) {
                boolean isRestore, final IPackageDataObserver observer,
                @CanBeCURRENT @UserIdInt int userId) {
            return ActivityManagerService.this.clearApplicationUserData(packageName, keepState,
                    isRestore, observer, userId);
        }
@@ -18699,7 +18709,8 @@ public class ActivityManagerService extends IActivityManager.Stub
     * Kill processes for the user with id userId and that depend on the package named packageName
     */
    @Override
    public void killPackageDependents(String packageName, int userId) {
    public void killPackageDependents(
            String packageName, @CanBeALL @CanBeCURRENT @UserIdInt int userId) {
        enforceCallingPermission(android.Manifest.permission.KILL_UID, "killPackageDependents()");
        if (packageName == null) {
            throw new NullPointerException(
Loading