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 android.os; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.content.pm.UserInfo; 21 import android.graphics.Bitmap; 22 23 /** 24 * @hide Only for use within the system server. 25 */ 26 public abstract class UserManagerInternal { 27 public interface UserRestrictionsListener { 28 /** 29 * Called when a user restriction changes. 30 * 31 * @param userId target user id 32 * @param newRestrictions new user restrictions 33 * @param prevRestrictions user restrictions that were previously set 34 */ 35 void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions); 36 } 37 38 /** 39 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} 40 * to set per-user as well as global user restrictions. 41 * 42 * @param userId target user id for the local restrictions. 43 * @param localRestrictions per-user restrictions. 44 * Caller must not change it once passed to this method. 45 * @param globalRestrictions global restrictions set by DO. Must be null when PO changed user 46 * restrictions, in which case global restrictions won't change. 47 * Caller must not change it once passed to this method. 48 */ 49 public abstract void setDevicePolicyUserRestrictions(int userId, 50 @NonNull Bundle localRestrictions, @Nullable Bundle globalRestrictions); 51 /** 52 * Returns the "base" user restrictions. 53 * 54 * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading 55 * from MNC. 56 */ 57 public abstract Bundle getBaseUserRestrictions(int userId); 58 59 /** 60 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading 61 * from MNC. 62 */ 63 public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId, 64 Bundle baseRestrictions); 65 66 /** Return a user restriction. */ 67 public abstract boolean getUserRestriction(int userId, String key); 68 69 /** Adds a listener to user restriction changes. */ 70 public abstract void addUserRestrictionsListener(UserRestrictionsListener listener); 71 72 /** Remove a {@link UserRestrictionsListener}. */ 73 public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener); 74 75 /** 76 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update 77 * whether the device is managed by device owner. 78 */ 79 public abstract void setDeviceManaged(boolean isManaged); 80 81 /** 82 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update 83 * whether the user is managed by profile owner. 84 */ 85 public abstract void setUserManaged(int userId, boolean isManaged); 86 87 /** 88 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit 89 * restriction check, because DevicePolicyManager must always be able to set user icon 90 * regardless of any restriction. 91 * Also called by {@link com.android.server.pm.UserManagerService} because the logic of setting 92 * the icon is in this method. 93 */ 94 public abstract void setUserIcon(int userId, Bitmap bitmap); 95 96 /** 97 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to inform the 98 * user manager whether all users should be created ephemeral. 99 */ 100 public abstract void setForceEphemeralUsers(boolean forceEphemeralUsers); 101 102 /** 103 * Switches to the system user and deletes all other users. 104 * 105 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when 106 * the force-ephemeral-users policy is toggled on to make sure there are no pre-existing 107 * non-ephemeral users left. 108 */ 109 public abstract void removeAllUsers(); 110 111 /** 112 * Called by the activity manager when the ephemeral user goes to background and its removal 113 * starts as a result. 114 * 115 * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered 116 * before its removal finishes. 117 * 118 * @param userId the ID of the ephemeral user. 119 */ 120 public abstract void onEphemeralUserStop(int userId); 121 122 /** 123 * Same as UserManager.createUser(), but bypasses the check for DISALLOW_ADD_USER. 124 * 125 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when 126 * createAndManageUser is called by the device owner. 127 */ 128 public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags); 129 130 /** 131 * Return whether the given user is running in an 132 * {@code UserState.STATE_RUNNING_UNLOCKING} or 133 * {@code UserState.STATE_RUNNING_UNLOCKED} state. 134 */ 135 public abstract boolean isUserUnlockingOrUnlocked(int userId); 136 137 /** 138 * Return whether the given user is running 139 */ 140 public abstract boolean isUserRunning(int userId); 141 142 /** 143 * Set user's running state 144 */ 145 public abstract void setUserState(int userId, int userState); 146 147 /** 148 * Remove user's running state 149 */ 150 public abstract void removeUserState(int userId); 151 } 152