1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.server.pm;
17 
18 import android.annotation.IntDef;
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.content.Context;
23 import android.content.pm.LauncherUserInfo;
24 import android.content.pm.UserInfo;
25 import android.content.pm.UserProperties;
26 import android.graphics.Bitmap;
27 import android.os.Bundle;
28 import android.os.UserManager;
29 import android.util.DebugUtils;
30 
31 import com.android.internal.annotations.Keep;
32 
33 import java.lang.annotation.Retention;
34 import java.lang.annotation.RetentionPolicy;
35 import java.util.List;
36 
37 /**
38  * @hide Only for use within the system server.
39  */
40 public abstract class UserManagerInternal {
41 
42     public static final int OWNER_TYPE_DEVICE_OWNER = 0;
43     public static final int OWNER_TYPE_PROFILE_OWNER = 1;
44     public static final int OWNER_TYPE_PROFILE_OWNER_OF_ORGANIZATION_OWNED_DEVICE = 2;
45     public static final int OWNER_TYPE_NO_OWNER = 3;
46 
47     @Retention(RetentionPolicy.SOURCE)
48     @IntDef(value = {OWNER_TYPE_DEVICE_OWNER, OWNER_TYPE_PROFILE_OWNER,
49             OWNER_TYPE_PROFILE_OWNER_OF_ORGANIZATION_OWNED_DEVICE, OWNER_TYPE_NO_OWNER})
50     public @interface OwnerType {
51     }
52 
53     // TODO(b/248408342): Move keep annotation to the method referencing these fields reflectively.
54     @Keep public static final int USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE = 1;
55     @Keep public static final int USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE = 2;
56     @Keep public static final int USER_ASSIGNMENT_RESULT_SUCCESS_ALREADY_VISIBLE = 3;
57     @Keep public static final int USER_ASSIGNMENT_RESULT_FAILURE = -1;
58 
59     private static final String PREFIX_USER_ASSIGNMENT_RESULT = "USER_ASSIGNMENT_RESULT_";
60     @IntDef(flag = false, prefix = {PREFIX_USER_ASSIGNMENT_RESULT}, value = {
61             USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE,
62             USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE,
63             USER_ASSIGNMENT_RESULT_SUCCESS_ALREADY_VISIBLE,
64             USER_ASSIGNMENT_RESULT_FAILURE
65     })
66     public @interface UserAssignmentResult {}
67 
68     private static final String PREFIX_USER_START_MODE = "USER_START_MODE_";
69 
70     /**
71      * Type used to indicate how a user started.
72      */
73     @IntDef(flag = false, prefix = {PREFIX_USER_START_MODE}, value = {
74             USER_START_MODE_FOREGROUND,
75             USER_START_MODE_BACKGROUND,
76             USER_START_MODE_BACKGROUND_VISIBLE
77     })
78     public @interface UserStartMode {}
79 
80     // TODO(b/248408342): Move keep annotations below to the method referencing these fields
81     // reflectively.
82 
83     /** (Full) user started on foreground (a.k.a. "current user"). */
84     @Keep public static final int USER_START_MODE_FOREGROUND = 1;
85 
86     /**
87      * User (full or profile) started on background and is
88      * {@link UserManager#isUserVisible() invisible}.
89      *
90      * <p>This is the "traditional" way of starting a background user, and can be used to start
91      * profiles as well, although starting an invisible profile is not common from the System UI
92      * (it could be done through APIs or adb, though).
93      */
94     @Keep public static final int USER_START_MODE_BACKGROUND = 2;
95 
96     /**
97      * User (full or profile) started on background and is
98      * {@link UserManager#isUserVisible() visible}.
99      *
100      * <p>This is the "traditional" way of starting a profile (i.e., when the profile of the current
101      * user is the current foreground user), but it can also be used to start a full user associated
102      * with a display (which is the case on automotives with passenger displays).
103      */
104     @Keep public static final int USER_START_MODE_BACKGROUND_VISIBLE = 3;
105 
106     public interface UserRestrictionsListener {
107         /**
108          * Called when a user restriction changes.
109          *
110          * @param userId target user id
111          * @param newRestrictions new user restrictions
112          * @param prevRestrictions user restrictions that were previously set
113          */
onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions)114         void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions);
115     }
116 
117     /**
118      * Listener for user lifecycle events.
119      *
120      * <p><b>NOTE: </b>implementations MUST not block the current thread.
121      */
122     public interface UserLifecycleListener {
123 
124         /**
125          * Called when a new user is created.
126          *
127          * @param user new user.
128          * @param token token passed to the method that created the user.
129          */
onUserCreated(UserInfo user, @Nullable Object token)130         default void onUserCreated(UserInfo user, @Nullable Object token) {}
131 
132         /** Called when an existing user is removed. */
onUserRemoved(UserInfo user)133         default void onUserRemoved(UserInfo user) {}
134     }
135 
136     /**
137      * Listener for {@link UserManager#isUserVisible() user visibility} changes.
138      */
139     public interface UserVisibilityListener {
140 
141         /**
142          * Called when the {@link UserManager#isUserVisible() user visibility} changed.
143          *
144          * <p><b>Note:</b> this method is called independently of
145          * {@link com.android.server.SystemService} callbacks; for example, the call with
146          * {@code visible} {@code true} might be called before the
147          * {@link com.android.server.SystemService#onUserStarting(com.android.server.SystemService.TargetUser)}
148          * call.
149          */
onUserVisibilityChanged(@serIdInt int userId, boolean visible)150         void onUserVisibilityChanged(@UserIdInt int userId, boolean visible);
151     }
152 
153     /**
154      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set
155      * restrictions enforced by the user.
156      *
157      * @param originatingUserId user id of the user where the restrictions originated.
158      * @param global            a bundle of global user restrictions. Global restrictions are
159      *                          restrictions that apply device-wide: to the managed profile,
160      *                          primary profile and secondary users and any profile created in
161      *                          any secondary user.
162      * @param local             a restriction set of local user restrictions. The key is the user
163      *                          id of the user whom the restrictions are targeting.
164      * @param isDeviceOwner     whether {@code originatingUserId} corresponds to device owner
165      *                          user id.
166      */
setDevicePolicyUserRestrictions(int originatingUserId, @Nullable Bundle global, @Nullable RestrictionsSet local, boolean isDeviceOwner)167     public abstract void setDevicePolicyUserRestrictions(int originatingUserId,
168             @Nullable Bundle global, @Nullable RestrictionsSet local, boolean isDeviceOwner);
169 
170     /**
171      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set a
172      * user restriction.
173      *
174      * @param userId user id to apply the restriction to. {@link com.android.os.UserHandle.USER_ALL}
175      *               will apply the restriction to all users globally.
176      * @param key    The key of the restriction.
177      * @param value  The value of the restriction.
178      */
setUserRestriction(@serIdInt int userId, @NonNull String key, boolean value)179     public abstract void setUserRestriction(@UserIdInt int userId, @NonNull String key,
180             boolean value);
181 
182     /** Return a user restriction. */
getUserRestriction(int userId, String key)183     public abstract boolean getUserRestriction(int userId, String key);
184 
185     /** Adds a listener to user restriction changes. */
addUserRestrictionsListener(UserRestrictionsListener listener)186     public abstract void addUserRestrictionsListener(UserRestrictionsListener listener);
187 
188     /** Remove a {@link UserRestrictionsListener}. */
removeUserRestrictionsListener(UserRestrictionsListener listener)189     public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener);
190 
191     /** Adds a {@link UserLifecycleListener}. */
addUserLifecycleListener(UserLifecycleListener listener)192     public abstract void addUserLifecycleListener(UserLifecycleListener listener);
193 
194     /** Removes a {@link UserLifecycleListener}. */
removeUserLifecycleListener(UserLifecycleListener listener)195     public abstract void removeUserLifecycleListener(UserLifecycleListener listener);
196 
197     /**
198      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
199      * whether the device is managed by device owner.
200      *
201      * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
202      */
203     @Deprecated
204     // TODO(b/258213147): Remove
setDeviceManaged(boolean isManaged)205     public abstract void setDeviceManaged(boolean isManaged);
206 
207     /**
208      * Returns whether the device is managed by device owner.
209      *
210      * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
211      */
212     @Deprecated
213     // TODO(b/258213147): Remove
isDeviceManaged()214     public abstract boolean isDeviceManaged();
215 
216     /**
217      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
218      * whether the user is managed by profile owner.
219      *
220      * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
221      */
222     // TODO(b/258213147): Remove
223     @Deprecated
setUserManaged(int userId, boolean isManaged)224     public abstract void setUserManaged(int userId, boolean isManaged);
225 
226     /**
227      * Whether a profile owner manages this user.
228      *
229      * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
230      */
231     // TODO(b/258213147): Remove
232     @Deprecated
isUserManaged(int userId)233     public abstract boolean isUserManaged(int userId);
234 
235     /**
236      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit
237      * restriction check, because DevicePolicyManager must always be able to set user icon
238      * regardless of any restriction.
239      * Also called by {@link com.android.server.pm.UserManagerService} because the logic of setting
240      * the icon is in this method.
241      */
setUserIcon(int userId, Bitmap bitmap)242     public abstract void setUserIcon(int userId, Bitmap bitmap);
243 
244     /**
245      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to inform the
246      * user manager whether all users should be created ephemeral.
247      */
setForceEphemeralUsers(boolean forceEphemeralUsers)248     public abstract void setForceEphemeralUsers(boolean forceEphemeralUsers);
249 
250     /**
251      * Switches to the system user and deletes all other users.
252      *
253      * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
254      * the force-ephemeral-users policy is toggled on to make sure there are no pre-existing
255      * non-ephemeral users left.
256      */
removeAllUsers()257     public abstract void removeAllUsers();
258 
259     /**
260      * Called by the activity manager when the ephemeral user goes to background and its removal
261      * starts as a result.
262      *
263      * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered
264      * before its removal finishes.
265      *
266      * @param userId the ID of the ephemeral user.
267      */
onEphemeralUserStop(int userId)268     public abstract void onEphemeralUserStop(int userId);
269 
270     /**
271      * Same as UserManager.createUser(), but bypasses the check for
272      * {@link UserManager#DISALLOW_ADD_USER} and {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}
273      *
274      * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
275      * createAndManageUser is called by the device owner; it uses {@code token} to block until
276      * the user is created (as it will be passed back to it through
277      * {@link UserLifecycleListener#onUserCreated(UserInfo, Object)});
278      */
createUserEvenWhenDisallowed( @ullable String name, @NonNull String userType, @UserInfo.UserInfoFlag int flags, @Nullable String[] disallowedPackages, @Nullable Object token)279     public abstract @NonNull UserInfo createUserEvenWhenDisallowed(
280             @Nullable String name, @NonNull String userType, @UserInfo.UserInfoFlag int flags,
281             @Nullable String[] disallowedPackages, @Nullable Object token)
282             throws UserManager.CheckedUserOperationException;
283 
284     /**
285      * Same as {@link UserManager#removeUser(int userId)}, but bypasses the check for
286      * {@link UserManager#DISALLOW_REMOVE_USER} and
287      * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the
288      * {@link android.Manifest.permission#MANAGE_USERS} permission.
289      */
removeUserEvenWhenDisallowed(int userId)290     public abstract boolean removeUserEvenWhenDisallowed(int userId);
291 
292     /**
293      * Return whether the given user is running in an
294      * {@code UserState.STATE_RUNNING_UNLOCKING} or
295      * {@code UserState.STATE_RUNNING_UNLOCKED} state.
296      */
isUserUnlockingOrUnlocked(int userId)297     public abstract boolean isUserUnlockingOrUnlocked(int userId);
298 
299     /**
300      * Return whether the given user is running in an
301      * {@code UserState.STATE_RUNNING_UNLOCKED} state.
302      */
isUserUnlocked(int userId)303     public abstract boolean isUserUnlocked(int userId);
304 
305     /**
306      * Returns whether the given user is running
307      */
isUserRunning(int userId)308     public abstract boolean isUserRunning(int userId);
309 
310     /**
311      * Returns whether the given user is initialized
312      */
isUserInitialized(int userId)313     public abstract boolean isUserInitialized(int userId);
314 
315     /**
316      * Returns whether the given user exists
317      */
exists(int userId)318     public abstract boolean exists(int userId);
319 
320     /**
321      * Set user's running state
322      */
setUserState(int userId, int userState)323     public abstract void setUserState(int userId, int userState);
324 
325     /**
326      * Remove user's running state
327      */
removeUserState(int userId)328     public abstract void removeUserState(int userId);
329 
330     /**
331      * Returns an array of user ids. This array is cached in UserManagerService and passed as a
332      * reference, so do not modify the returned array.
333      *
334      * @return the array of user ids.
335      */
getUserIds()336     public abstract int[] getUserIds();
337 
338     /**
339      * Internal implementation of getUsers does not check permissions.
340      * This improves performance for calls from inside system server which already have permissions
341      * checked.
342      */
getUsers(boolean excludeDying)343     public abstract @NonNull List<UserInfo> getUsers(boolean excludeDying);
344 
345     /**
346      * Internal implementation of getUsers does not check permissions.
347      * This improves performance for calls from inside system server which already have permissions
348      * checked.
349      */
getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated)350     public abstract @NonNull List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
351             boolean excludePreCreated);
352 
353     /**
354      * Returns an array of ids for profiles associated with the specified user including the user
355      * itself.
356      * <p>Note that this includes all profile types (not including Restricted profiles).
357      *
358      * @param userId      id of the user to return profiles for
359      * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
360      * @return A non-empty array of ids of profiles associated with the specified user if the user
361      *         exists. Otherwise, an empty array.
362      */
getProfileIds(@serIdInt int userId, boolean enabledOnly)363     public abstract @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly);
364 
365     /**
366      * Checks if the {@code callingUserId} and {@code targetUserId} are same or in same group
367      * and that the {@code callingUserId} is not a profile and {@code targetUserId} is enabled.
368      *
369      * @return TRUE if the {@code callingUserId} can access {@code targetUserId}. FALSE
370      * otherwise
371      *
372      * @throws SecurityException if the calling user and {@code targetUser} are not in the same
373      * group and {@code throwSecurityException} is true, otherwise if will simply return false.
374      */
isProfileAccessible(int callingUserId, int targetUserId, String debugMsg, boolean throwSecurityException)375     public abstract boolean isProfileAccessible(int callingUserId, int targetUserId,
376             String debugMsg, boolean throwSecurityException);
377 
378     /**
379      * If {@code userId} is of a profile, return the parent user ID. Otherwise return itself.
380      */
getProfileParentId(int userId)381     public abstract int getProfileParentId(int userId);
382 
383     /**
384      * Checks whether changing a setting to a value is prohibited by the corresponding user
385      * restriction.
386      *
387      * <p>See also {@link com.android.server.pm.UserRestrictionsUtils#applyUserRestriction(
388      * Context, int, String, boolean)}, which should be in sync with this method.
389      *
390      * @return {@code true} if the change is prohibited, {@code false} if the change is allowed.
391      *
392      * @hide
393      */
isSettingRestrictedForUser(String setting, int userId, String value, int callingUid)394     public abstract boolean isSettingRestrictedForUser(String setting, int userId, String value,
395             int callingUid);
396 
397     /** @return a specific user restriction that's in effect currently. */
hasUserRestriction(String restriction, int userId)398     public abstract boolean hasUserRestriction(String restriction, int userId);
399 
400     /**
401      * Gets a {@link UserInfo} for the given {@code userId}, or {@code null} if not found.
402      */
getUserInfo(@serIdInt int userId)403     public abstract @Nullable UserInfo getUserInfo(@UserIdInt int userId);
404 
405     /**
406      * Gets all {@link UserInfo UserInfos}.
407      */
getUserInfos()408     public abstract @NonNull UserInfo[] getUserInfos();
409 
410     /**
411      * Gets a {@link LauncherUserInfo} for the given {@code userId}, or {@code null} if not found.
412      */
getLauncherUserInfo(@serIdInt int userId)413     public abstract @Nullable LauncherUserInfo getLauncherUserInfo(@UserIdInt int userId);
414 
415     /**
416      * Sets all default cross profile intent filters between {@code parentUserId} and
417      * {@code profileUserId}.
418      */
setDefaultCrossProfileIntentFilters( @serIdInt int parentUserId, @UserIdInt int profileUserId)419     public abstract void setDefaultCrossProfileIntentFilters(
420             @UserIdInt int parentUserId, @UserIdInt int profileUserId);
421 
422     /**
423      * Returns {@code true} if the system should ignore errors when preparing
424      * the storage directories for the user with ID {@code userId}. This will
425      * return {@code false} for all new users; it will only return {@code true}
426      * for users that already existed on-disk from an older version of Android.
427      */
shouldIgnorePrepareStorageErrors(int userId)428     public abstract boolean shouldIgnorePrepareStorageErrors(int userId);
429 
430     /**
431      * Returns the {@link UserProperties} of the given user, or {@code null} if it is not found.
432      * NB: The actual object is returned. So do NOT modify it!
433      */
getUserProperties(@serIdInt int userId)434     public abstract @Nullable UserProperties getUserProperties(@UserIdInt int userId);
435 
436     /**
437      * Assigns a user to a display when it's starting, returning whether the assignment succeeded
438      * and the user is {@link UserManager#isUserVisible() visible}.
439      *
440      * <p><b>NOTE: </b>this method is meant to be used only by {@code UserController} (when a user
441      * is started); for extra unassignments, callers should call {@link
442      * #assignUserToExtraDisplay(int, int)} instead.
443      *
444      * <p><b>NOTE: </b>this method doesn't validate if the display exists, it's up to the caller to
445      * pass a valid display id.
446      */
assignUserToDisplayOnStart(@serIdInt int userId, @UserIdInt int profileGroupId, @UserStartMode int userStartMode, int displayId)447     public abstract @UserAssignmentResult int assignUserToDisplayOnStart(@UserIdInt int userId,
448             @UserIdInt int profileGroupId, @UserStartMode int userStartMode, int displayId);
449 
450     /**
451      * Assigns an extra display to the given user, so the user is visible on that display.
452      *
453      * <p>This method is meant to be used on automotive builds where a passenger zone has more than
454      * one display (for example, the "main" display and a smaller display used for input).
455      *
456      * <p><b>NOTE: </b>this call will be ignored on devices that do not
457      * {@link UserManager#isVisibleBackgroundUsersSupported() support visible background users}.
458      *
459      * @return whether the operation succeeded, in which case the user would be visible on the
460      * display.
461      */
assignUserToExtraDisplay(@serIdInt int userId, int displayId)462     public abstract boolean assignUserToExtraDisplay(@UserIdInt int userId, int displayId);
463 
464     /**
465      * Unassigns a user from its current display when it's stopping.
466      *
467      * <p><b>NOTE: </b>this method is meant to be used only by {@code UserController} (when a user
468      * is stopped); for extra unassignments, callers should call
469      * {@link #unassignUserFromExtraDisplay(int, int)} instead.
470      */
unassignUserFromDisplayOnStop(@serIdInt int userId)471     public abstract void unassignUserFromDisplayOnStop(@UserIdInt int userId);
472 
473     /**
474      * Unassigns the extra display from the given user.
475      *
476      * <p>This method is meant to be used on automotive builds where a passenger zone has more than
477      * one display (for example, the "main" display and a smaller display used for input).
478      *
479      * <p><b>NOTE: </b>this call will be ignored on devices that do not
480      * {@link UserManager#isVisibleBackgroundUsersSupported() support visible background users}.
481      *
482      * @return whether the operation succeeded, i.e., the user was previously
483      *         {@link #assignUserToExtraDisplay(int, int) assigned to an extra display}.
484      */
unassignUserFromExtraDisplay(@serIdInt int userId, int displayId)485     public abstract boolean unassignUserFromExtraDisplay(@UserIdInt int userId, int displayId);
486 
487     /**
488      * Returns {@code true} if the user is visible (as defined by
489      * {@link UserManager#isUserVisible()}.
490      */
isUserVisible(@serIdInt int userId)491     public abstract boolean isUserVisible(@UserIdInt int userId);
492 
493     /**
494      * Returns {@code true} if the user is visible (as defined by
495      * {@link UserManager#isUserVisible()} in the given display.
496      */
isUserVisible(@serIdInt int userId, int displayId)497     public abstract boolean isUserVisible(@UserIdInt int userId, int displayId);
498 
499     /**
500      * Returns the main display id assigned to the user, or {@code Display.INVALID_DISPLAY} if the
501      * user is not assigned to any main display.
502      *
503      * <p>In the context of multi-user multi-display, there can be multiple main displays, at most
504      * one per each zone. Main displays are where UI is launched which a user interacts with.
505      *
506      * <p>The current foreground user and its running profiles are associated with the
507      * {@link android.view.Display#DEFAULT_DISPLAY default display}, while other users would only be
508      * assigned to a display if a call to {@link #assignUserToDisplay(int, int)} is made for such
509      * user / display combination (for example, if the user was started with
510      * {@code ActivityManager.startUserInBackgroundOnSecondaryDisplay()}, {@code UserController}
511      * would make such call).
512      *
513      * <p>If the user is a profile and is running, it's assigned to its parent display.
514      */
getMainDisplayAssignedToUser(@serIdInt int userId)515     public abstract int getMainDisplayAssignedToUser(@UserIdInt int userId);
516 
517     /**
518      * Returns all display ids assigned to the user including {@link
519      * #assignUserToExtraDisplay(int, int) extra displays}, or {@code null} if there is no display
520      * assigned to the specified user.
521      *
522      * <p>Note that this method is different from {@link #getMainDisplayAssignedToUser(int)}, which
523      * returns a main display only.
524      */
getDisplaysAssignedToUser(@serIdInt int userId)525     public abstract @Nullable int[] getDisplaysAssignedToUser(@UserIdInt int userId);
526 
527     /**
528      * Returns the main user (i.e., not a profile) that is assigned to the display, or the
529      * {@link android.app.ActivityManager#getCurrentUser() current foreground user} if no user is
530      * associated with the display.
531      *
532      * <p>The {@link android.view.Display#DEFAULT_DISPLAY default display} is always assigned to
533      * the current foreground user, while other displays would only be associated with users through
534      * a explicit {@link #assignUserToDisplay(int, int)} call with that user / display combination
535      * (for example, if the user was started with
536      * {@code ActivityManager.startUserInBackgroundOnSecondaryDisplay()}, {@code UserController}
537      * would make such call).
538      */
getUserAssignedToDisplay(int displayId)539     public abstract @UserIdInt int getUserAssignedToDisplay(int displayId);
540 
541     /**
542      * Gets the user-friendly representation of the {@code result} of a
543      * {@link #assignUserToDisplayOnStart(int, int, boolean, int)} call.
544      */
userAssignmentResultToString(@serAssignmentResult int result)545     public static String userAssignmentResultToString(@UserAssignmentResult int result) {
546         return DebugUtils.constantToString(UserManagerInternal.class, PREFIX_USER_ASSIGNMENT_RESULT,
547                 result);
548     }
549 
550     /**
551      * Gets the user-friendly representation of a user start {@code mode}.
552      */
userStartModeToString(@serStartMode int mode)553     public static String userStartModeToString(@UserStartMode int mode) {
554         return DebugUtils.constantToString(UserManagerInternal.class, PREFIX_USER_START_MODE, mode);
555     }
556 
557     /** Adds a {@link UserVisibilityListener}. */
addUserVisibilityListener(UserVisibilityListener listener)558     public abstract void addUserVisibilityListener(UserVisibilityListener listener);
559 
560     /** Removes a {@link UserVisibilityListener}. */
removeUserVisibilityListener(UserVisibilityListener listener)561     public abstract void removeUserVisibilityListener(UserVisibilityListener listener);
562 
563     // TODO(b/242195409): remove this method if not needed anymore
564     /** Notify {@link UserVisibilityListener listeners} that the visibility of the
565      * {@link android.os.UserHandle#USER_SYSTEM} changed. */
onSystemUserVisibilityChanged(boolean visible)566     public abstract void onSystemUserVisibilityChanged(boolean visible);
567 
568     /** Return the integer types of the given user IDs. Only used for reporting metrics to statsd.
569      */
getUserTypesForStatsd(@serIdInt int[] userIds)570     public abstract int[] getUserTypesForStatsd(@UserIdInt int[] userIds);
571 
572     /**
573      * Returns the user id of the main user, or {@link android.os.UserHandle#USER_NULL} if there is
574      * no main user.
575      *
576      * @see UserManager#isMainUser()
577      */
getMainUserId()578     public abstract @UserIdInt int getMainUserId();
579 
580     /**
581      * Returns the id of the user which should be in the foreground after boot completes.
582      *
583      * <p>If a boot user has been provided by calling {@link UserManager#setBootUser}, the
584      * returned value will be whatever was specified, as long as that user exists and can be
585      * switched to.
586      *
587      * <p>Otherwise, in {@link UserManager#isHeadlessSystemUserMode() headless system user mode},
588      * this will be the user who was last in the foreground on this device.
589      *
590      * <p>In non-headless system user mode, the return value will be
591      * {@link android.os.UserHandle#USER_SYSTEM}.
592 
593      * @throws UserManager.CheckedUserOperationException if no switchable user can be found
594      */
getBootUser(boolean waitUntilSet)595     public abstract @UserIdInt int getBootUser(boolean waitUntilSet)
596             throws UserManager.CheckedUserOperationException;
597 
598     /**
599      * Returns the user id of the communal profile, or {@link android.os.UserHandle#USER_NULL}
600      * if there is no such user.
601      */
getCommunalProfileId()602     public abstract @UserIdInt int getCommunalProfileId();
603 }
604