Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1 | /* |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016 The Android Open Source Project |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 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 |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 14 | * limitations under the License |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 15 | */ |
| 16 | package android.os; |
| 17 | |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 18 | import android.annotation.Nullable; |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 19 | import android.content.pm.UserInfo; |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 21 | |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 22 | /** |
| 23 | * @hide Only for use within the system server. |
| 24 | */ |
| 25 | public abstract class UserManagerInternal { |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 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 | |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 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 | */ |
| 38 | void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions); |
| 39 | } |
| 40 | |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 41 | /** |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 42 | * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set |
| 43 | * restrictions enforced by the user. |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 44 | * |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 45 | * @param userId target user id for the local restrictions. |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 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} |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 51 | */ |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 52 | public abstract void setDevicePolicyUserRestrictions(int userId, @Nullable Bundle restrictions, |
| 53 | boolean isDeviceOwner, int cameraRestrictionScope); |
| 54 | |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Returns the "base" user restrictions. |
| 57 | * |
| 58 | * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading |
| 59 | * from MNC. |
| 60 | */ |
| 61 | public abstract Bundle getBaseUserRestrictions(int userId); |
| 62 | |
| 63 | /** |
| 64 | * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading |
| 65 | * from MNC. |
| 66 | */ |
| 67 | public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId, |
| 68 | Bundle baseRestrictions); |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 69 | |
| 70 | /** Return a user restriction. */ |
| 71 | public abstract boolean getUserRestriction(int userId, String key); |
| 72 | |
| 73 | /** Adds a listener to user restriction changes. */ |
| 74 | public abstract void addUserRestrictionsListener(UserRestrictionsListener listener); |
| 75 | |
| 76 | /** Remove a {@link UserRestrictionsListener}. */ |
| 77 | public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener); |
Makoto Onuki | e7927da | 2015-11-25 10:05:17 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update |
| 81 | * whether the device is managed by device owner. |
| 82 | */ |
| 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 | */ |
| 89 | public abstract void setUserManaged(int userId, boolean isManaged); |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 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 | */ |
| 98 | public abstract void setUserIcon(int userId, Bitmap bitmap); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 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 | */ |
| 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 | */ |
| 113 | public abstract void removeAllUsers(); |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 114 | |
| 115 | /** |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 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 | */ |
| 124 | public abstract void onEphemeralUserStop(int userId); |
| 125 | |
| 126 | /** |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 127 | * Same as UserManager.createUser(), but bypasses the check for |
| 128 | * {@link UserManager#DISALLOW_ADD_USER} and {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE} |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 129 | * |
| 130 | * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when |
| 131 | * createAndManageUser is called by the device owner. |
| 132 | */ |
| 133 | public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags); |
Fyodor Kupolov | 6c915ea | 2016-05-09 19:10:53 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
Nicolas Prevot | df1b87d | 2016-10-25 13:57:08 +0100 | [diff] [blame] | 136 | * Same as {@link UserManager#removeUser(int userHandle)}, but bypasses the check for |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 137 | * {@link UserManager#DISALLOW_REMOVE_USER} and |
| 138 | * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the |
Nicolas Prevot | df1b87d | 2016-10-25 13:57:08 +0100 | [diff] [blame] | 139 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 140 | */ |
| 141 | public abstract boolean removeUserEvenWhenDisallowed(int userId); |
| 142 | |
| 143 | /** |
Fyodor Kupolov | 6c915ea | 2016-05-09 19:10:53 -0700 | [diff] [blame] | 144 | * Return whether the given user is running in an |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 145 | * {@code UserState.STATE_RUNNING_UNLOCKING} or |
| 146 | * {@code UserState.STATE_RUNNING_UNLOCKED} state. |
Fyodor Kupolov | 6c915ea | 2016-05-09 19:10:53 -0700 | [diff] [blame] | 147 | */ |
| 148 | public abstract boolean isUserUnlockingOrUnlocked(int userId); |
| 149 | |
| 150 | /** |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 151 | * Return whether the given user is running in an |
| 152 | * {@code UserState.STATE_RUNNING_UNLOCKED} state. |
| 153 | */ |
| 154 | public abstract boolean isUserUnlocked(int userId); |
| 155 | |
| 156 | /** |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 157 | * Return whether the given user is running |
Fyodor Kupolov | 6c915ea | 2016-05-09 19:10:53 -0700 | [diff] [blame] | 158 | */ |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 159 | public abstract boolean isUserRunning(int userId); |
| 160 | |
| 161 | /** |
| 162 | * Set user's running state |
| 163 | */ |
| 164 | public abstract void setUserState(int userId, int userState); |
| 165 | |
| 166 | /** |
| 167 | * Remove user's running state |
| 168 | */ |
| 169 | public abstract void removeUserState(int userId); |
Michael Wachenschwanz | 3f2b655 | 2017-05-15 13:53:09 -0700 | [diff] [blame] | 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 | */ |
| 177 | public abstract int[] getUserIds(); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 178 | } |