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.Nullable; 19 import android.content.pm.UserInfo; 20 import android.graphics.Bitmap; 21 22 /** 23 * @hide Only for use within the system server. 24 */ 25 public abstract class UserManagerInternal { 26 public static final int CAMERA_NOT_DISABLED = 0; 27 public static final int CAMERA_DISABLED_LOCALLY = 1; 28 public static final int CAMERA_DISABLED_GLOBALLY = 2; 29 30 public interface UserRestrictionsListener { 31 /** 32 * Called when a user restriction changes. 33 * 34 * @param userId target user id 35 * @param newRestrictions new user restrictions 36 * @param prevRestrictions user restrictions that were previously set 37 */ onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions)38 void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions); 39 } 40 41 /** 42 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set 43 * restrictions enforced by the user. 44 * 45 * @param userId target user id for the local restrictions. 46 * @param restrictions a bundle of user restrictions. 47 * @param isDeviceOwner whether {@code userId} corresponds to device owner user id. 48 * @param cameraRestrictionScope is camera disabled and if so what is the scope of restriction. 49 * Should be one of {@link #CAMERA_NOT_DISABLED}, {@link #CAMERA_DISABLED_LOCALLY} or 50 * {@link #CAMERA_DISABLED_GLOBALLY} 51 */ setDevicePolicyUserRestrictions(int userId, @Nullable Bundle restrictions, boolean isDeviceOwner, int cameraRestrictionScope)52 public abstract void setDevicePolicyUserRestrictions(int userId, @Nullable Bundle restrictions, 53 boolean isDeviceOwner, int cameraRestrictionScope); 54 55 /** 56 * Returns the "base" user restrictions. 57 * 58 * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading 59 * from MNC. 60 */ getBaseUserRestrictions(int userId)61 public abstract Bundle getBaseUserRestrictions(int userId); 62 63 /** 64 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading 65 * from MNC. 66 */ setBaseUserRestrictionsByDpmsForMigration(int userId, Bundle baseRestrictions)67 public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId, 68 Bundle baseRestrictions); 69 70 /** Return a user restriction. */ getUserRestriction(int userId, String key)71 public abstract boolean getUserRestriction(int userId, String key); 72 73 /** Adds a listener to user restriction changes. */ addUserRestrictionsListener(UserRestrictionsListener listener)74 public abstract void addUserRestrictionsListener(UserRestrictionsListener listener); 75 76 /** Remove a {@link UserRestrictionsListener}. */ removeUserRestrictionsListener(UserRestrictionsListener listener)77 public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener); 78 79 /** 80 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update 81 * whether the device is managed by device owner. 82 */ setDeviceManaged(boolean isManaged)83 public abstract void setDeviceManaged(boolean isManaged); 84 85 /** 86 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update 87 * whether the user is managed by profile owner. 88 */ setUserManaged(int userId, boolean isManaged)89 public abstract void setUserManaged(int userId, boolean isManaged); 90 91 /** 92 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit 93 * restriction check, because DevicePolicyManager must always be able to set user icon 94 * regardless of any restriction. 95 * Also called by {@link com.android.server.pm.UserManagerService} because the logic of setting 96 * the icon is in this method. 97 */ setUserIcon(int userId, Bitmap bitmap)98 public abstract void setUserIcon(int userId, Bitmap bitmap); 99 100 /** 101 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to inform the 102 * user manager whether all users should be created ephemeral. 103 */ setForceEphemeralUsers(boolean forceEphemeralUsers)104 public abstract void setForceEphemeralUsers(boolean forceEphemeralUsers); 105 106 /** 107 * Switches to the system user and deletes all other users. 108 * 109 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when 110 * the force-ephemeral-users policy is toggled on to make sure there are no pre-existing 111 * non-ephemeral users left. 112 */ removeAllUsers()113 public abstract void removeAllUsers(); 114 115 /** 116 * Called by the activity manager when the ephemeral user goes to background and its removal 117 * starts as a result. 118 * 119 * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered 120 * before its removal finishes. 121 * 122 * @param userId the ID of the ephemeral user. 123 */ onEphemeralUserStop(int userId)124 public abstract void onEphemeralUserStop(int userId); 125 126 /** 127 * Same as UserManager.createUser(), but bypasses the check for 128 * {@link UserManager#DISALLOW_ADD_USER} and {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE} 129 * 130 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when 131 * createAndManageUser is called by the device owner. 132 */ createUserEvenWhenDisallowed(String name, int flags)133 public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags); 134 135 /** 136 * Same as {@link UserManager#removeUser(int userHandle)}, but bypasses the check for 137 * {@link UserManager#DISALLOW_REMOVE_USER} and 138 * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the 139 * {@link android.Manifest.permission#MANAGE_USERS} permission. 140 */ removeUserEvenWhenDisallowed(int userId)141 public abstract boolean removeUserEvenWhenDisallowed(int userId); 142 143 /** 144 * Return whether the given user is running in an 145 * {@code UserState.STATE_RUNNING_UNLOCKING} or 146 * {@code UserState.STATE_RUNNING_UNLOCKED} state. 147 */ isUserUnlockingOrUnlocked(int userId)148 public abstract boolean isUserUnlockingOrUnlocked(int userId); 149 150 /** 151 * Return whether the given user is running in an 152 * {@code UserState.STATE_RUNNING_UNLOCKED} state. 153 */ isUserUnlocked(int userId)154 public abstract boolean isUserUnlocked(int userId); 155 156 /** 157 * Return whether the given user is running 158 */ isUserRunning(int userId)159 public abstract boolean isUserRunning(int userId); 160 161 /** 162 * Set user's running state 163 */ setUserState(int userId, int userState)164 public abstract void setUserState(int userId, int userState); 165 166 /** 167 * Remove user's running state 168 */ removeUserState(int userId)169 public abstract void removeUserState(int userId); 170 171 /** 172 * Returns an array of user ids. This array is cached in UserManagerService and passed as a 173 * reference, so do not modify the returned array. 174 * 175 * @return the array of user ids. 176 */ getUserIds()177 public abstract int[] getUserIds(); 178 } 179