int userHandle -> int userId

Throughout the codebase, sometimes an integer user ID is called
userId, and sometimes it is called userHandle. Here, we rename the
occurences of "int userHandle" to "int userId" in select files.
Additionally, we add the @UserIdInt annotation in many more places.

This certainly does not cover all uses of userHandle, which is used
widely throughout Android; doing so would be more dangerous and cause
merge conflicts. But at least the core User code can have a consistent
nomenclature.

Bug: 138384792
Test: compiles. presubmit passes.

Change-Id: I9a2684e9bfac637e0476c4b68027008ebb8a160b
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 1fd7e52..92aabb5 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -18,6 +18,7 @@
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.UserIdInt;
 import android.content.ComponentName;
 import android.content.IIntentReceiver;
 import android.content.IIntentSender;
@@ -30,7 +31,6 @@
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.TransactionTooLargeException;
-import android.view.RemoteAnimationAdapter;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -51,12 +51,12 @@
     /**
      * Verify that calling app has access to the given provider.
      */
-    public abstract String checkContentProviderAccess(String authority, int userId);
+    public abstract String checkContentProviderAccess(String authority, @UserIdInt int userId);
 
     /**
      * Verify that calling UID has access to the given provider.
      */
-    public abstract int checkContentProviderUriPermission(Uri uri, int userId,
+    public abstract int checkContentProviderUriPermission(Uri uri, @UserIdInt int userId,
             int callingUid, int modeFlags);
 
     // Called by the power manager.
@@ -71,7 +71,7 @@
     /**
      * Kill foreground apps from the specified user.
      */
-    public abstract void killForegroundAppsForUser(int userHandle);
+    public abstract void killForegroundAppsForUser(@UserIdInt int userId);
 
     /**
      *  Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions
@@ -174,7 +174,7 @@
      * 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, int userId,
+    public abstract int handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId,
             boolean allowAll, int allowMode, String name, String callerPackage);
 
     /** Checks if the calling binder pid as the permission. */
@@ -184,7 +184,7 @@
     public abstract int getCurrentUserId();
 
     /** Returns true if the user is running. */
-    public abstract boolean isUserRunning(int userId, int flags);
+    public abstract boolean isUserRunning(@UserIdInt int userId, int flags);
 
     /** Trims memory usage in the system by removing/stopping unused application processes. */
     public abstract void trimApplications();
@@ -211,7 +211,7 @@
      * @param started
      */
     public abstract void updateBatteryStats(
-            ComponentName activity, int uid, int userId, boolean resumed);
+            ComponentName activity, int uid, @UserIdInt int userId, boolean resumed);
 
     /**
      * Update UsageStats of the activity.
@@ -222,23 +222,23 @@
      * @param taskRoot TaskRecord's root
      */
     public abstract void updateActivityUsageStats(
-            ComponentName activity, int userId, int event, IBinder appToken,
+            ComponentName activity, @UserIdInt int userId, int event, IBinder appToken,
             ComponentName taskRoot);
     public abstract void updateForegroundTimeIfOnBattery(
             String packageName, int uid, long cpuTimeDiff);
-    public abstract void sendForegroundProfileChanged(int userId);
+    public abstract void sendForegroundProfileChanged(@UserIdInt int userId);
 
     /**
      * Returns whether the given user requires credential entry at this time. This is used to
      * intercept activity launches for work apps when the Work Challenge is present.
      */
-    public abstract boolean shouldConfirmCredentials(int userId);
+    public abstract boolean shouldConfirmCredentials(@UserIdInt int userId);
 
     public abstract int[] getCurrentProfileIds();
     public abstract UserInfo getCurrentUser();
-    public abstract void ensureNotSpecialUser(int userId);
-    public abstract boolean isCurrentProfile(int userId);
-    public abstract boolean hasStartedUserState(int userId);
+    public abstract void ensureNotSpecialUser(@UserIdInt int userId);
+    public abstract boolean isCurrentProfile(@UserIdInt int userId);
+    public abstract boolean hasStartedUserState(@UserIdInt int userId);
     public abstract void finishUserSwitch(Object uss);
 
     /** Schedule the execution of all pending app GCs. */
@@ -261,15 +261,16 @@
     public abstract int broadcastIntentInPackage(String packageName, int uid, int realCallingUid,
             int realCallingPid, Intent intent, String resolvedType, IIntentReceiver resultTo,
             int resultCode, String resultData, Bundle resultExtras, String requiredPermission,
-            Bundle bOptions, boolean serialized, boolean sticky, int userId,
+            Bundle bOptions, boolean serialized, boolean sticky, @UserIdInt int userId,
             boolean allowBackgroundActivityStarts);
     public abstract ComponentName startServiceInPackage(int uid, Intent service,
-            String resolvedType, boolean fgRequired, String callingPackage, int userId,
+            String resolvedType, boolean fgRequired, String callingPackage, @UserIdInt int userId,
             boolean allowBackgroundActivityStarts) throws TransactionTooLargeException;
 
     public abstract void disconnectActivityFromServices(Object connectionHolder, Object conns);
-    public abstract void cleanUpServices(int userId, ComponentName component, Intent baseIntent);
-    public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId);
+    public abstract void cleanUpServices(@UserIdInt int userId, ComponentName component,
+            Intent baseIntent);
+    public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId);
     public abstract void ensureBootCompleted();
     public abstract void updateOomLevelsForDisplay(int displayId);
     public abstract boolean isActivityStartsLoggingEnabled();
@@ -328,7 +329,7 @@
     public abstract boolean isAppBad(ApplicationInfo info);
 
     /** Remove pending backup for the given userId. */
-    public abstract void clearPendingBackup(int userId);
+    public abstract void clearPendingBackup(@UserIdInt int userId);
 
     /**
      * When power button is very long pressed, call this interface to do some pre-shutdown work
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 2a17800..3418b7b 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -5413,8 +5413,8 @@
             "android.intent.extra.ALLOW_MULTIPLE";
 
     /**
-     * The integer userHandle carried with broadcast intents related to addition, removal and
-     * switching of users and managed profiles - {@link #ACTION_USER_ADDED},
+     * The integer userHandle (i.e. userId) carried with broadcast intents related to addition,
+     * removal and switching of users and managed profiles - {@link #ACTION_USER_ADDED},
      * {@link #ACTION_USER_REMOVED} and {@link #ACTION_USER_SWITCHED}.
      *
      * @hide
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 4e17f7e..0754dc7 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -128,8 +128,9 @@
     @UnsupportedAppUsage
     public static final int AID_CACHE_GID_START = android.os.Process.FIRST_APPLICATION_CACHE_GID;
 
+    /** The userId represented by this UserHandle. */
     @UnsupportedAppUsage
-    final int mHandle;
+    final @UserIdInt int mHandle;
 
     /**
      * Checks to see if the user id is the same for the two uids, i.e., they belong to the same
@@ -270,7 +271,7 @@
     }
 
     /** @hide */
-    public static int getSharedAppGid(int userId, int appId) {
+    public static int getSharedAppGid(@UserIdInt int userId, @AppIdInt int appId) {
         if (appId >= AID_APP_START && appId <= AID_APP_END) {
             return (appId - AID_APP_START) + AID_SHARED_GID_START;
         } else if (appId >= AID_ROOT && appId <= AID_APP_START) {
@@ -300,7 +301,7 @@
     }
 
     /** @hide */
-    public static int getCacheAppGid(int userId, int appId) {
+    public static int getCacheAppGid(@UserIdInt int userId, @AppIdInt int appId) {
         if (appId >= AID_APP_START && appId <= AID_APP_END) {
             return getUid(userId, (appId - AID_APP_START) + AID_CACHE_GID_START);
         } else {
@@ -432,8 +433,8 @@
 
     /** @hide */
     @UnsupportedAppUsage
-    public UserHandle(int h) {
-        mHandle = h;
+    public UserHandle(@UserIdInt int userId) {
+        mHandle = userId;
     }
 
     /**
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index a7fa96b..baf748f 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1794,14 +1794,14 @@
     /**
      * Returns the UserInfo object describing a specific user.
      * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
-     * @param userHandle the user handle of the user whose information is being requested.
+     * @param userId the user handle of the user whose information is being requested.
      * @return the UserInfo object for a specific user.
      * @hide
      */
     @UnsupportedAppUsage
-    public UserInfo getUserInfo(@UserIdInt int userHandle) {
+    public UserInfo getUserInfo(@UserIdInt int userId) {
         try {
-            return mService.getUserInfo(userHandle);
+            return mService.getUserInfo(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2066,15 +2066,15 @@
      *
      * @param name the user's name
      * @param flags flags that identify the type of user and other properties.
-     * @param userHandle new user will be a profile of this user.
+     * @param userId new user will be a profile of this user.
      *
      * @return the {@link UserInfo} object for the created user, or null if the user
      *         could not be created.
      * @hide
      */
     @UnsupportedAppUsage
-    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
-        return createProfileForUser(name, flags, userHandle, null);
+    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userId) {
+        return createProfileForUser(name, flags, userId, null);
     }
 
     /**
@@ -2084,17 +2084,17 @@
      *
      * @param name the user's name
      * @param flags flags that identify the type of user and other properties.
-     * @param userHandle new user will be a profile of this user.
+     * @param userId new user will be a profile of this user.
      * @param disallowedPackages packages that will not be installed in the profile being created.
      *
      * @return the {@link UserInfo} object for the created user, or null if the user
      *         could not be created.
      * @hide
      */
-    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
+    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userId,
             String[] disallowedPackages) {
         try {
-            return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
+            return mService.createProfileForUser(name, flags, userId, disallowedPackages);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2109,9 +2109,9 @@
      * @hide
      */
     public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
-            @UserIdInt int userHandle, String[] disallowedPackages) {
+            @UserIdInt int userId, String[] disallowedPackages) {
         try {
-            return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
+            return mService.createProfileForUserEvenWhenDisallowed(name, flags, userId,
                     disallowedPackages);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
@@ -2280,12 +2280,12 @@
      * @hide
      * Marks the guest user for deletion to allow a new guest to be created before deleting
      * the current user who is a guest.
-     * @param userHandle
+     * @param userId
      * @return
      */
-    public boolean markGuestForDeletion(@UserIdInt int userHandle) {
+    public boolean markGuestForDeletion(@UserIdInt int userId) {
         try {
-            return mService.markGuestForDeletion(userHandle);
+            return mService.markGuestForDeletion(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2317,16 +2317,16 @@
      * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} and
      * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions.
      *
-     * @param userHandle the id of the user to become admin
+     * @param userId the id of the user to become admin
      * @hide
      */
     @RequiresPermission(allOf = {
             Manifest.permission.INTERACT_ACROSS_USERS_FULL,
             Manifest.permission.MANAGE_USERS
     })
-    public void setUserAdmin(@UserIdInt int userHandle) {
+    public void setUserAdmin(@UserIdInt int userId) {
         try {
-            mService.setUserAdmin(userHandle);
+            mService.setUserAdmin(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2337,9 +2337,9 @@
      *
      * @hide
      */
-    public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
+    public void evictCredentialEncryptionKey(@UserIdInt int userId) {
         try {
-            mService.evictCredentialEncryptionKey(userHandle);
+            mService.evictCredentialEncryptionKey(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2400,9 +2400,9 @@
             Manifest.permission.INTERACT_ACROSS_USERS_FULL,
             Manifest.permission.MANAGE_USERS
     })
-    public @Nullable String getUserAccount(@UserIdInt int userHandle) {
+    public @Nullable String getUserAccount(@UserIdInt int userId) {
         try {
-            return mService.getUserAccount(userHandle);
+            return mService.getUserAccount(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2416,9 +2416,9 @@
             Manifest.permission.INTERACT_ACROSS_USERS_FULL,
             Manifest.permission.MANAGE_USERS
     })
-    public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
+    public void setUserAccount(@UserIdInt int userId, @Nullable String accountName) {
         try {
-            mService.setUserAccount(userHandle, accountName);
+            mService.setUserAccount(userId, accountName);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2477,20 +2477,19 @@
     }
 
     /**
-     * Returns list of the profiles of userHandle including
-     * userHandle itself.
+     * Returns list of the profiles of userId including userId itself.
      * Note that this returns both enabled and not enabled profiles. See
      * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
      *
      * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
-     * @param userHandle profiles of this user will be returned.
+     * @param userId profiles of this user will be returned.
      * @return the list of profiles.
      * @hide
      */
     @UnsupportedAppUsage
-    public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
+    public List<UserInfo> getProfiles(@UserIdInt int userId) {
         try {
-            return mService.getProfiles(userHandle, false /* enabledOnly */);
+            return mService.getProfiles(userId, false /* enabledOnly */);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2512,19 +2511,18 @@
     }
 
     /**
-     * Returns list of the profiles of userHandle including
-     * userHandle itself.
+     * Returns list of the profiles of userId including userId itself.
      * Note that this returns only enabled.
      *
      * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
-     * @param userHandle profiles of this user will be returned.
+     * @param userId profiles of this user will be returned.
      * @return the list of profiles.
      * @hide
      */
     @UnsupportedAppUsage
-    public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
+    public List<UserInfo> getEnabledProfiles(@UserIdInt int userId) {
         try {
-            return mService.getProfiles(userHandle, true /* enabledOnly */);
+            return mService.getProfiles(userId, true /* enabledOnly */);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2584,14 +2582,14 @@
 
     /**
      * Returns the device credential owner id of the profile from
-     * which this method is called, or userHandle if called from a user that
+     * which this method is called, or userId if called from a user that
      * is not a profile.
      *
      * @hide
      */
-    public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
+    public int getCredentialOwnerProfile(@UserIdInt int userId) {
         try {
-            return mService.getCredentialOwnerProfile(userHandle);
+            return mService.getCredentialOwnerProfile(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2604,9 +2602,9 @@
      * @hide
      */
     @UnsupportedAppUsage
-    public UserInfo getProfileParent(@UserIdInt int userHandle) {
+    public UserInfo getProfileParent(@UserIdInt int userId) {
         try {
-            return mService.getProfileParent(userHandle);
+            return mService.getProfileParent(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2785,13 +2783,13 @@
     /**
      * Removes a user and all associated data.
      * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
-     * @param userHandle the integer handle of the user, where 0 is the primary user.
+     * @param userId the integer handle of the user.
      * @hide
      */
     @UnsupportedAppUsage
-    public boolean removeUser(@UserIdInt int userHandle) {
+    public boolean removeUser(@UserIdInt int userId) {
         try {
-            return mService.removeUser(userHandle);
+            return mService.removeUser(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2823,9 +2821,9 @@
      * @see {@link #removeUser(int)}
      * @hide
      */
-    public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
+    public boolean removeUserEvenWhenDisallowed(@UserIdInt int userId) {
         try {
-            return mService.removeUserEvenWhenDisallowed(userHandle);
+            return mService.removeUserEvenWhenDisallowed(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2835,13 +2833,13 @@
      * Updates the user's name.
      * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
      *
-     * @param userHandle the user's integer handle
+     * @param userId the user's integer id
      * @param name the new name for the user
      * @hide
      */
-    public void setUserName(@UserIdInt int userHandle, String name) {
+    public void setUserName(@UserIdInt int userId, String name) {
         try {
-            mService.setUserName(userHandle, name);
+            mService.setUserName(userId, name);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2862,13 +2860,13 @@
 
     /**
      * Sets the user's photo.
-     * @param userHandle the user for whom to change the photo.
+     * @param userId the user for whom to change the photo.
      * @param icon the bitmap to set as the photo.
      * @hide
      */
-    public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
+    public void setUserIcon(@UserIdInt int userId, Bitmap icon) {
         try {
-            mService.setUserIcon(userHandle, icon);
+            mService.setUserIcon(userId, icon);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -2889,15 +2887,15 @@
 
     /**
      * Returns a file descriptor for the user's photo. PNG data can be read from this file.
-     * @param userHandle the user whose photo we want to read.
+     * @param userId the user whose photo we want to read.
      * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
      * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
      * @hide
      */
     @UnsupportedAppUsage
-    public Bitmap getUserIcon(@UserIdInt int userHandle) {
+    public Bitmap getUserIcon(@UserIdInt int userId) {
         try {
-            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
+            ParcelFileDescriptor fd = mService.getUserIcon(userId);
             if (fd != null) {
                 try {
                     return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
@@ -2999,27 +2997,27 @@
     }
 
     /**
-     * Returns a serial number on this device for a given userHandle. User handles can be recycled
+     * Returns a serial number on this device for a given userId. User handles can be recycled
      * when deleting and creating users, but serial numbers are not reused until the device is wiped.
-     * @param userHandle
-     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
+     * @param userId
+     * @return a serial number associated with that user, or -1 if the userId is not valid.
      * @hide
      */
     @UnsupportedAppUsage
-    public int getUserSerialNumber(@UserIdInt int userHandle) {
+    public int getUserSerialNumber(@UserIdInt int userId) {
         try {
-            return mService.getUserSerialNumber(userHandle);
+            return mService.getUserSerialNumber(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
     }
 
     /**
-     * Returns a userHandle on this device for a given user serial number. User handles can be
+     * Returns a userId on this device for a given user serial number. User handles can be
      * recycled when deleting and creating users, but serial numbers are not reused until the device
      * is wiped.
      * @param userSerialNumber
-     * @return the userHandle associated with that user serial number, or -1 if the serial number
+     * @return the userId associated with that user serial number, or -1 if the serial number
      * is not valid.
      * @hide
      */
diff --git a/core/java/android/os/UserManagerInternal.java b/core/java/android/os/UserManagerInternal.java
index f302263..b6540d2 100644
--- a/core/java/android/os/UserManagerInternal.java
+++ b/core/java/android/os/UserManagerInternal.java
@@ -136,7 +136,7 @@
             String[] disallowedPackages);
 
     /**
-     * Same as {@link UserManager#removeUser(int userHandle)}, but bypasses the check for
+     * Same as {@link UserManager#removeUser(int userId)}, but bypasses the check for
      * {@link UserManager#DISALLOW_REMOVE_USER} and
      * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the
      * {@link android.Manifest.permission#MANAGE_USERS} permission.