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

Commit b420daef authored by Adam Bookatz's avatar Adam Bookatz
Browse files

@CanBeALL annotation for PackageManager

Add the @CanBeALL annotation to various PackageManager-related methods
that accept UserHandle.USER_ALL. A few of the places they call into are
likewise annotated. This can help clarify which methods accept pseuduser
values.

There is no guarantee that this accounts for all such usages.

Test: N/A just annotations
Bug: 373455030
Flag: EXEMPT documentation only
Change-Id: I1f81478ed6103880e812483ada24a33ff4362ec6
parent 10d770d4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.PermissionMethod;
import android.annotation.PermissionName;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.UserIdInt;
import android.app.ActivityManager.ProcessCapability;
import android.app.ActivityManager.RestrictionLevel;
@@ -1365,8 +1366,8 @@ public abstract class ActivityManagerInternal {
     * watchdog reset.
     * @hide
     */
    public abstract void killApplicationSync(String pkgName, int appId, int userId,
            String reason, int exitInfoReason);
    public abstract void killApplicationSync(String pkgName, int appId,
            @CanBeALL @UserIdInt int userId, String reason, int exitInfoReason);

    /**
     * Queries the offset data for a given method on a process.
+4 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.SpecialUsers.CanBeCURRENT;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -2709,7 +2711,7 @@ public abstract class ContentResolver implements ContentInterface {
    public final void registerContentObserverAsUser(@NonNull Uri uri,
            boolean notifyForDescendants,
            @NonNull ContentObserver observer,
            @NonNull UserHandle userHandle) {
            @NonNull @CanBeALL @CanBeCURRENT UserHandle userHandle) {
        Objects.requireNonNull(uri, "uri");
        Objects.requireNonNull(observer, "observer");
        Objects.requireNonNull(userHandle, "userHandle");
@@ -2723,7 +2725,7 @@ public abstract class ContentResolver implements ContentInterface {
    /** @hide - designated user version */
    @UnsupportedAppUsage
    public final void registerContentObserver(Uri uri, boolean notifyForDescendants,
            ContentObserver observer, @UserIdInt int userHandle) {
            ContentObserver observer, @CanBeALL @CanBeCURRENT @UserIdInt int userHandle) {
        try {
            getContentService().registerContentObserver(uri, notifyForDescendants,
                    observer.getContentObserver(), userHandle, mTargetSdkVersion);
+6 −5
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ import android.annotation.Nullable;
import android.annotation.PermissionMethod;
import android.annotation.PermissionName;
import android.annotation.RequiresPermission;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.ActivityClient;
@@ -3909,8 +3910,8 @@ public class ActivityManagerService extends IActivityManager.Stub
     * The pkg name and app id have to be specified.
     */
    @Override
    public void killApplication(String pkg, int appId, int userId, String reason,
            int exitInfoReason) {
    public void killApplication(String pkg, int appId, @CanBeALL @UserIdInt int userId,
            String reason, int exitInfoReason) {
        if (pkg == null) {
            return;
        }
@@ -4295,7 +4296,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    final boolean forceStopPackageLocked(String packageName, int appId,
            boolean callerWillRestart, boolean purgeCache, boolean doit,
            boolean evenPersistent, boolean uninstalling, boolean packageStateStopped,
            int userId, String reasonString, int reason) {
            @CanBeALL @UserIdInt int userId, String reasonString, int reason) {
        return forceStopPackageInternalLocked(packageName, appId, callerWillRestart, purgeCache,
                doit, evenPersistent, uninstalling, packageStateStopped, userId, reasonString,
                reason, ProcessList.INVALID_ADJ);
@@ -4305,7 +4306,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    private boolean forceStopPackageInternalLocked(String packageName, int appId,
            boolean callerWillRestart, boolean purgeCache, boolean doit,
            boolean evenPersistent, boolean uninstalling, boolean packageStateStopped,
            int userId, String reasonString, int reason, int minOomAdj) {
            @CanBeALL @UserIdInt int userId, String reasonString, int reason, int minOomAdj) {
        int i;
        if (userId == UserHandle.USER_ALL && packageName == null) {
@@ -18081,7 +18082,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public void killApplicationSync(String pkgName, int appId, int userId,
        public void killApplicationSync(String pkgName, int appId, @CanBeALL @UserIdInt int userId,
                String reason, int exitInfoReason) {
            if (pkgName == null) {
                return;
+10 −7
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ import static com.android.server.wm.WindowProcessController.STOPPED_STATE_FORCE_
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManager.ProcessCapability;
import android.app.ActivityThread;
@@ -2961,8 +2963,8 @@ public final class ProcessList {
    }

    @GuardedBy({"mService", "mProcLock"})
    boolean killPackageProcessesLSP(String packageName, int appId, int userId, int minOomAdj,
            int reasonCode, int subReason, String reason) {
    boolean killPackageProcessesLSP(String packageName, int appId, @CanBeALL @UserIdInt int userId,
            int minOomAdj, int reasonCode, int subReason, String reason) {
        return killPackageProcessesLSP(packageName, appId, userId, minOomAdj,
                false /* callerWillRestart */, true /* allowRestart */, true /* doit */,
                false /* evenPersistent */, false /* setRemoved */, false /* uninstalling */,
@@ -2970,7 +2972,8 @@ public final class ProcessList {
    }

    @GuardedBy("mService")
    void killAppZygotesLocked(String packageName, int appId, int userId, boolean force) {
    void killAppZygotesLocked(String packageName, int appId, @CanBeALL @UserIdInt int userId,
            boolean force) {
        // See if there are any app zygotes running for this packageName / UID combination,
        // and kill it if so.
        final ArrayList<AppZygote> zygotesToKill = new ArrayList<>();
@@ -3050,9 +3053,9 @@ public final class ProcessList {

    @GuardedBy({"mService", "mProcLock"})
    boolean killPackageProcessesLSP(String packageName, int appId,
            int userId, int minOomAdj, boolean callerWillRestart, boolean allowRestart,
            boolean doit, boolean evenPersistent, boolean setRemoved, boolean uninstalling,
            int reasonCode, int subReason, String reason) {
            @CanBeALL @UserIdInt int userId, int minOomAdj, boolean callerWillRestart,
            boolean allowRestart, boolean doit, boolean evenPersistent, boolean setRemoved,
            boolean uninstalling, int reasonCode, int subReason, String reason) {
        final PackageManagerInternal pm = mService.getPackageManagerInternal();
        final ArrayList<Pair<ProcessRecord, Boolean>> procs = new ArrayList<>();

@@ -5220,7 +5223,7 @@ public final class ProcessList {
    }

    @GuardedBy("mService")
    void sendPackageBroadcastLocked(int cmd, String[] packages, int userId) {
    void sendPackageBroadcastLocked(int cmd, String[] packages, @CanBeALL @UserIdInt int userId) {
        boolean foundProcess = false;
        for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
            ProcessRecord r = mLruProcesses.get(i);
+6 −3
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.accounts.AccountManagerInternal;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SpecialUsers.CanBeALL;
import android.annotation.SpecialUsers.CanBeCURRENT;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManager.RestrictionLevel;
@@ -361,7 +363,8 @@ public final class ContentService extends IContentService.Stub {
     */
    @Override
    public void registerContentObserver(Uri uri, boolean notifyForDescendants,
            IContentObserver observer, int userHandle, int targetSdkVersion) {
            IContentObserver observer, @CanBeALL @CanBeCURRENT @UserIdInt int userHandle,
            int targetSdkVersion) {
        if (observer == null || uri == null) {
            throw new IllegalArgumentException("You must pass a valid uri and observer");
        }
@@ -1398,8 +1401,8 @@ public final class ContentService extends IContentService.Stub {
        }
    }

    private int handleIncomingUser(Uri uri, int pid, int uid, int modeFlags, boolean allowNonFull,
            int userId) {
    private @CanBeALL @UserIdInt int handleIncomingUser(Uri uri, int pid, int uid, int modeFlags,
            boolean allowNonFull, @CanBeALL @CanBeCURRENT @UserIdInt int userId) {
        if (userId == UserHandle.USER_CURRENT) {
            userId = ActivityManager.getCurrentUser();
        }
Loading