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