Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | */ |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 16 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 17 | package android.os; |
| 18 | |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 19 | import android.Manifest; |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 20 | import android.accounts.AccountManager; |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
| 22 | import android.annotation.DrawableRes; |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 23 | import android.annotation.IntDef; |
Adam Lesinski | ada8deb | 2017-05-12 13:50:42 -0700 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 26 | import android.annotation.RequiresPermission; |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 27 | import android.annotation.StringDef; |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 28 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 29 | import android.annotation.SystemService; |
Makoto Onuki | e72f81b | 2017-03-16 14:08:19 -0700 | [diff] [blame] | 30 | import android.annotation.TestApi; |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 31 | import android.annotation.UserHandleAware; |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 32 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 33 | import android.annotation.WorkerThread; |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 34 | import android.app.Activity; |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 36 | import android.app.admin.DevicePolicyManager; |
Artur Satayev | afdb23a | 2019-12-10 17:47:53 +0000 | [diff] [blame] | 37 | import android.compat.annotation.UnsupportedAppUsage; |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 39 | import android.content.Context; |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 40 | import android.content.Intent; |
Esteban Talavera | 8bd7c52 | 2017-02-13 12:35:04 +0000 | [diff] [blame] | 41 | import android.content.IntentFilter; |
Benjamin Franz | f02420c | 2016-04-04 18:52:21 +0100 | [diff] [blame] | 42 | import android.content.IntentSender; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 43 | import android.content.pm.UserInfo; |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 44 | import android.content.pm.UserInfo.UserInfoFlag; |
Robin Lee | 83c7931 | 2018-02-09 19:27:18 +0100 | [diff] [blame] | 45 | import android.content.res.Configuration; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 46 | import android.content.res.Resources; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 47 | import android.graphics.Bitmap; |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 48 | import android.graphics.BitmapFactory; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 49 | import android.graphics.Rect; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 50 | import android.graphics.drawable.Drawable; |
Soonil Nagarkar | dc08e3a | 2019-12-02 12:31:45 -0800 | [diff] [blame] | 51 | import android.location.LocationManager; |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 52 | import android.provider.Settings; |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 53 | import android.telephony.TelephonyManager; |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 54 | import android.util.AndroidException; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 55 | import android.view.WindowManager.LayoutParams; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 56 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 57 | import com.android.internal.R; |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 58 | import com.android.internal.os.RoSystemProperties; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 59 | |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 60 | import java.io.IOException; |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 61 | import java.lang.annotation.Retention; |
| 62 | import java.lang.annotation.RetentionPolicy; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 63 | import java.util.ArrayList; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 64 | import java.util.List; |
| 65 | |
| 66 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 67 | * Manages users and user details on a multi-user system. There are two major categories of |
| 68 | * users: fully customizable users with their own login, and managed profiles that share a workspace |
| 69 | * with a related user. |
| 70 | * <p> |
| 71 | * Users are different from accounts, which are managed by |
| 72 | * {@link AccountManager}. Each user can have their own set of accounts. |
| 73 | * <p> |
| 74 | * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 75 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 76 | @SystemService(Context.USER_SERVICE) |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 77 | public class UserManager { |
| 78 | |
Pavel Grafov | 4f4f6f8 | 2017-03-28 13:44:04 +0100 | [diff] [blame] | 79 | private static final String TAG = "UserManager"; |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 80 | @UnsupportedAppUsage |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 81 | private final IUserManager mService; |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 82 | /** Holding the Application context (not constructor param context). */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 83 | private final Context mContext; |
| 84 | |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 85 | /** The userId of the constructor param context. To be used instead of mContext.getUserId(). */ |
| 86 | private final @UserIdInt int mUserId; |
| 87 | |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 88 | private Boolean mIsManagedProfileCached; |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 89 | private Boolean mIsProfileCached; |
| 90 | |
| 91 | /** |
| 92 | * User type representing a {@link UserHandle#USER_SYSTEM system} user that is a human user. |
| 93 | * This type of user cannot be created; it can only pre-exist on first boot. |
| 94 | * @hide |
| 95 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 96 | @SystemApi |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 97 | public static final String USER_TYPE_FULL_SYSTEM = "android.os.usertype.full.SYSTEM"; |
| 98 | |
| 99 | /** |
| 100 | * User type representing a regular non-profile non-{@link UserHandle#USER_SYSTEM system} human |
| 101 | * user. |
| 102 | * This is sometimes called an ordinary 'secondary user'. |
| 103 | * @hide |
| 104 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 105 | @SystemApi |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 106 | public static final String USER_TYPE_FULL_SECONDARY = "android.os.usertype.full.SECONDARY"; |
| 107 | |
| 108 | /** |
| 109 | * User type representing a guest user that may be transient. |
| 110 | * @hide |
| 111 | */ |
| 112 | public static final String USER_TYPE_FULL_GUEST = "android.os.usertype.full.GUEST"; |
| 113 | |
| 114 | /** |
| 115 | * User type representing a user for demo purposes only, which can be removed at any time. |
| 116 | * @hide |
| 117 | */ |
| 118 | public static final String USER_TYPE_FULL_DEMO = "android.os.usertype.full.DEMO"; |
| 119 | |
| 120 | /** |
| 121 | * User type representing a "restricted profile" user, which is a full user that is subject to |
| 122 | * certain restrictions from a parent user. Note, however, that it is NOT technically a profile. |
| 123 | * @hide |
| 124 | */ |
| 125 | public static final String USER_TYPE_FULL_RESTRICTED = "android.os.usertype.full.RESTRICTED"; |
| 126 | |
| 127 | /** |
| 128 | * User type representing a managed profile, which is a profile that is to be managed by a |
| 129 | * device policy controller (DPC). |
| 130 | * The intended purpose is for work profiles, which are managed by a corporate entity. |
| 131 | * @hide |
| 132 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 133 | @SystemApi |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 134 | public static final String USER_TYPE_PROFILE_MANAGED = "android.os.usertype.profile.MANAGED"; |
| 135 | |
| 136 | /** |
| 137 | * User type representing a {@link UserHandle#USER_SYSTEM system} user that is <b>not</b> a |
| 138 | * human user. |
| 139 | * This type of user cannot be created; it can only pre-exist on first boot. |
| 140 | * @hide |
| 141 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 142 | @SystemApi |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 143 | public static final String USER_TYPE_SYSTEM_HEADLESS = "android.os.usertype.system.HEADLESS"; |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 144 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 145 | /** |
Pierre Barbier de Reuille | 17eaf74 | 2020-01-10 17:49:45 +0000 | [diff] [blame] | 146 | * Flag passed to {@link #requestQuietModeEnabled} to request disabling quiet mode only if |
| 147 | * there is no need to confirm the user credentials. If credentials are required to disable |
| 148 | * quiet mode, {@link #requestQuietModeEnabled} will do nothing and return {@code false}. |
| 149 | */ |
| 150 | public static final int QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED = 0x1; |
| 151 | |
| 152 | /** |
| 153 | * List of flags available for the {@link #requestQuietModeEnabled} method. |
| 154 | * @hide |
| 155 | */ |
| 156 | @Retention(RetentionPolicy.SOURCE) |
| 157 | @IntDef(flag = true, prefix = { "QUIET_MODE_" }, value = { |
| 158 | QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED }) |
| 159 | public @interface QuietModeFlag {} |
| 160 | |
| 161 | /** |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 162 | * @hide |
| 163 | * No user restriction. |
| 164 | */ |
| 165 | @SystemApi |
| 166 | public static final int RESTRICTION_NOT_SET = 0x0; |
| 167 | |
| 168 | /** |
| 169 | * @hide |
| 170 | * User restriction set by system/user. |
| 171 | */ |
| 172 | @SystemApi |
| 173 | public static final int RESTRICTION_SOURCE_SYSTEM = 0x1; |
| 174 | |
| 175 | /** |
| 176 | * @hide |
| 177 | * User restriction set by a device owner. |
| 178 | */ |
| 179 | @SystemApi |
| 180 | public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2; |
| 181 | |
| 182 | /** |
| 183 | * @hide |
| 184 | * User restriction set by a profile owner. |
| 185 | */ |
| 186 | @SystemApi |
| 187 | public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4; |
| 188 | |
| 189 | /** @hide */ |
| 190 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 191 | @IntDef(flag = true, prefix = { "RESTRICTION_" }, value = { |
| 192 | RESTRICTION_NOT_SET, |
| 193 | RESTRICTION_SOURCE_SYSTEM, |
| 194 | RESTRICTION_SOURCE_DEVICE_OWNER, |
| 195 | RESTRICTION_SOURCE_PROFILE_OWNER |
| 196 | }) |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 197 | @SystemApi |
| 198 | public @interface UserRestrictionSource {} |
| 199 | |
| 200 | /** |
Fyodor Kupolov | 5301928 | 2015-07-21 11:48:18 -0700 | [diff] [blame] | 201 | * Specifies if a user is disallowed from adding and removing accounts, unless they are |
| 202 | * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by |
| 203 | * Authenticator. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 204 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 205 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 206 | * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still |
| 207 | * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 208 | * management is disallowed. |
| 209 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 210 | * <p>Key for user restrictions. |
| 211 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 212 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 213 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 214 | * @see #getUserRestrictions() |
| 215 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 216 | public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 217 | |
| 218 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 219 | * Specifies if a user is disallowed from changing Wi-Fi |
Julia Reynolds | 2cb384f | 2014-08-13 15:15:55 -0400 | [diff] [blame] | 220 | * access points. The default value is <code>false</code>. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 221 | * <p> |
| 222 | * Device owner and profile owner can set this restriction, although the restriction has no |
| 223 | * effect in a managed profile. When it is set by the profile owner of an organization-owned |
| 224 | * managed profile on the parent profile, it will disallow the personal user from changing |
| 225 | * Wi-Fi access points. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 226 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 227 | * <p>Key for user restrictions. |
| 228 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 229 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 230 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 231 | * @see #getUserRestrictions() |
| 232 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 233 | public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 234 | |
| 235 | /** |
Christine Franks | 1bade5d | 2017-10-10 15:41:50 -0700 | [diff] [blame] | 236 | * Specifies if a user is disallowed from changing the device |
| 237 | * language. The default value is <code>false</code>. |
| 238 | * |
| 239 | * <p>Key for user restrictions. |
| 240 | * <p>Type: Boolean |
| 241 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 242 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 243 | * @see #getUserRestrictions() |
| 244 | */ |
| 245 | public static final String DISALLOW_CONFIG_LOCALE = "no_config_locale"; |
| 246 | |
| 247 | /** |
Benjamin Miller | f1c3ed1 | 2018-05-03 10:56:28 +0000 | [diff] [blame] | 248 | * Specifies if a user is disallowed from installing applications. This user restriction also |
| 249 | * prevents device owners and profile owners installing apps. The default value is |
| 250 | * {@code false}. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 251 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 252 | * <p>Key for user restrictions. |
| 253 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 254 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 255 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 256 | * @see #getUserRestrictions() |
| 257 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 258 | public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 259 | |
| 260 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 261 | * Specifies if a user is disallowed from uninstalling applications. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 262 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 263 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 264 | * <p>Key for user restrictions. |
| 265 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 266 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 267 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 268 | * @see #getUserRestrictions() |
| 269 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 270 | public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 271 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 272 | /** |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 273 | * Specifies if a user is disallowed from turning on location sharing. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 274 | * The default value is <code>false</code>. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 275 | * <p> |
| 276 | * In a managed profile, location sharing always reflects the primary user's setting, but |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 277 | * can be overridden and forced off by setting this restriction to true in the managed profile. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 278 | * <p> |
| 279 | * Device owner and profile owner can set this restriction. When it is set by the profile |
| 280 | * owner of an organization-owned managed profile on the parent profile, it will prevent the |
| 281 | * user from turning on location sharing in the personal profile. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 282 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 283 | * <p>Key for user restrictions. |
| 284 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 285 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 286 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 287 | * @see #getUserRestrictions() |
| 288 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 289 | public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 290 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 291 | /** |
yuemingw | 5fe75dc | 2017-11-29 15:52:56 +0000 | [diff] [blame] | 292 | * Specifies if airplane mode is disallowed on the device. |
Alex Johnston | 9722abe | 2020-01-28 16:15:55 +0000 | [diff] [blame] | 293 | * <p> |
| 294 | * This restriction can only be set by the device owner, the profile owner on the primary user |
| 295 | * or the profile owner of an organization-owned managed profile on the parent profile, and it |
| 296 | * applies globally - i.e. it disables airplane mode on the entire device. |
| 297 | * <p> |
| 298 | * The default value is <code>false</code>. |
yuemingw | 5fe75dc | 2017-11-29 15:52:56 +0000 | [diff] [blame] | 299 | * |
| 300 | * <p>Key for user restrictions. |
| 301 | * <p>Type: Boolean |
| 302 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 303 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 304 | * @see #getUserRestrictions() |
| 305 | */ |
| 306 | public static final String DISALLOW_AIRPLANE_MODE = "no_airplane_mode"; |
| 307 | |
| 308 | /** |
yuemingw | c6ac29d | 2018-01-10 16:54:08 +0000 | [diff] [blame] | 309 | * Specifies if a user is disallowed from configuring brightness. When device owner sets it, |
| 310 | * it'll only be applied on the target(system) user. |
| 311 | * |
| 312 | * <p>The default value is <code>false</code>. |
| 313 | * |
| 314 | * <p>This user restriction has no effect on managed profiles. |
| 315 | * <p>Key for user restrictions. |
| 316 | * <p>Type: Boolean |
| 317 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 318 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 319 | * @see #getUserRestrictions() |
| 320 | */ |
| 321 | public static final String DISALLOW_CONFIG_BRIGHTNESS = "no_config_brightness"; |
| 322 | |
| 323 | /** |
yuemingw | a178144 | 2018-01-10 18:59:43 +0000 | [diff] [blame] | 324 | * Specifies if ambient display is disallowed for the user. |
| 325 | * |
| 326 | * <p>The default value is <code>false</code>. |
| 327 | * |
| 328 | * <p>This user restriction has no effect on managed profiles. |
| 329 | * <p>Key for user restrictions. |
| 330 | * <p>Type: Boolean |
| 331 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 332 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 333 | * @see #getUserRestrictions() |
| 334 | */ |
| 335 | public static final String DISALLOW_AMBIENT_DISPLAY = "no_ambient_display"; |
| 336 | |
| 337 | /** |
yuemingw | 5cda3ae | 2018-01-15 10:26:19 +0000 | [diff] [blame] | 338 | * Specifies if a user is disallowed from changing screen off timeout. |
| 339 | * |
| 340 | * <p>The default value is <code>false</code>. |
| 341 | * |
| 342 | * <p>This user restriction has no effect on managed profiles. |
| 343 | * <p>Key for user restrictions. |
| 344 | * <p>Type: Boolean |
| 345 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 346 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 347 | * @see #getUserRestrictions() |
| 348 | */ |
| 349 | public static final String DISALLOW_CONFIG_SCREEN_TIMEOUT = "no_config_screen_timeout"; |
| 350 | |
| 351 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 352 | * Specifies if a user is disallowed from enabling the |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 353 | * "Unknown Sources" setting, that allows installation of apps from unknown sources. |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 354 | * Unknown sources exclude adb and special apps such as trusted app stores. |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 355 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 356 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 357 | * <p>Key for user restrictions. |
| 358 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 359 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 360 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 361 | * @see #getUserRestrictions() |
| 362 | */ |
| 363 | public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; |
| 364 | |
| 365 | /** |
Tor Norbye | 33ca912 | 2018-10-03 09:28:21 +0200 | [diff] [blame] | 366 | * This restriction is a device-wide version of {@link #DISALLOW_INSTALL_UNKNOWN_SOURCES}. |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 367 | * |
| 368 | * Specifies if all users on the device are disallowed from enabling the |
| 369 | * "Unknown Sources" setting, that allows installation of apps from unknown sources. |
Irina Dumitrescu | 0501eee | 2018-10-19 23:50:18 +0100 | [diff] [blame] | 370 | * |
| 371 | * This restriction can be enabled by the profile owner, in which case all accounts and |
| 372 | * profiles will be affected. |
| 373 | * |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 374 | * The default value is <code>false</code>. |
| 375 | * |
| 376 | * <p>Key for user restrictions. |
| 377 | * <p>Type: Boolean |
| 378 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 379 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 380 | * @see #getUserRestrictions() |
| 381 | */ |
| 382 | public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY = |
| 383 | "no_install_unknown_sources_globally"; |
| 384 | |
| 385 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 386 | * Specifies if a user is disallowed from configuring bluetooth. |
Nicolas Prevot | 1c4c442 | 2015-02-16 11:32:21 +0000 | [diff] [blame] | 387 | * This does <em>not</em> restrict the user from turning bluetooth on or off. |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 388 | * The default value is <code>false</code>. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 389 | * <p> |
| 390 | * This restriction doesn't prevent the user from using bluetooth. For disallowing usage of |
Lenka Trochtova | 63d5e4a7 | 2016-12-02 12:19:39 +0100 | [diff] [blame] | 391 | * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 392 | * <p> |
| 393 | * Device owner and profile owner can set this restriction, although the restriction has no |
| 394 | * effect in a managed profile. When it is set by the profile owner of an organization-owned |
| 395 | * managed profile on the parent profile, it will disallow the personal user from configuring |
| 396 | * bluetooth. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 397 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 398 | * <p>Key for user restrictions. |
| 399 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 400 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 401 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 402 | * @see #getUserRestrictions() |
| 403 | */ |
| 404 | public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; |
| 405 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 406 | /** |
Lenka Trochtova | 63d5e4a7 | 2016-12-02 12:19:39 +0100 | [diff] [blame] | 407 | * Specifies if bluetooth is disallowed on the device. |
| 408 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 409 | * <p> This restriction can only be set by the device owner, the profile owner on the |
| 410 | * primary user or the profile owner of an organization-owned managed profile on the |
| 411 | * parent profile and it applies globally - i.e. it disables bluetooth on the entire |
| 412 | * device. |
Lenka Trochtova | 63d5e4a7 | 2016-12-02 12:19:39 +0100 | [diff] [blame] | 413 | * <p>The default value is <code>false</code>. |
| 414 | * <p>Key for user restrictions. |
| 415 | * <p>Type: Boolean |
| 416 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 417 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 418 | * @see #getUserRestrictions() |
| 419 | */ |
| 420 | public static final String DISALLOW_BLUETOOTH = "no_bluetooth"; |
| 421 | |
| 422 | /** |
Pavel Grafov | 4f4f6f8 | 2017-03-28 13:44:04 +0100 | [diff] [blame] | 423 | * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 424 | * owner can set this restriction. When it is set by device owner or the profile owner of an |
| 425 | * organization-owned managed profile on the parent profile, all users on this device will be |
| 426 | * affected. |
Pavel Grafov | 4f4f6f8 | 2017-03-28 13:44:04 +0100 | [diff] [blame] | 427 | * |
| 428 | * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device |
| 429 | * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing |
| 430 | * managed profiles. |
| 431 | * |
| 432 | * <p>Key for user restrictions. |
| 433 | * <p>Type: Boolean |
| 434 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 435 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 436 | * @see #getUserRestrictions() |
| 437 | */ |
| 438 | public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing"; |
| 439 | |
| 440 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 441 | * Specifies if a user is disallowed from transferring files over |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 442 | * USB. This can only be set by device owners, profile owners on the primary user or |
| 443 | * profile owners of organization-owned managed profiles on the parent profile. |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 444 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 445 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 446 | * <p>Key for user restrictions. |
| 447 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 448 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 449 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 450 | * @see #getUserRestrictions() |
| 451 | */ |
| 452 | public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; |
| 453 | |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 454 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 455 | * Specifies if a user is disallowed from configuring user |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 456 | * credentials. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 457 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 458 | * <p>Key for user restrictions. |
| 459 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 460 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 461 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 462 | * @see #getUserRestrictions() |
| 463 | */ |
| 464 | public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; |
| 465 | |
| 466 | /** |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 467 | * When set on the primary user this specifies if the user can remove other users. |
| 468 | * When set on a secondary user, this specifies if the user can remove itself. |
| 469 | * This restriction has no effect on managed profiles. |
| 470 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 471 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 472 | * <p>Key for user restrictions. |
| 473 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 474 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 475 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 476 | * @see #getUserRestrictions() |
| 477 | */ |
| 478 | public static final String DISALLOW_REMOVE_USER = "no_remove_user"; |
| 479 | |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 480 | /** |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 481 | * Specifies if managed profiles of this user can be removed, other than by its profile owner. |
| 482 | * The default value is <code>false</code>. |
| 483 | * <p> |
Nicolas Prevot | 2ea46fe | 2017-01-05 10:29:34 +0000 | [diff] [blame] | 484 | * This restriction has no effect on managed profiles. |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 485 | * |
| 486 | * <p>Key for user restrictions. |
| 487 | * <p>Type: Boolean |
| 488 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 489 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 490 | * @see #getUserRestrictions() |
Eran Messeri | ce273df | 2019-12-17 13:14:45 +0000 | [diff] [blame] | 491 | * @deprecated As the ability to have a managed profile on a fully-managed device has been |
| 492 | * removed from the platform, this restriction will be silently ignored when applied by the |
| 493 | * device owner. |
| 494 | * When the device is provisioned with a managed profile on an organization-owned device, |
| 495 | * the managed profile could not be removed anyway. |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 496 | */ |
Eran Messeri | ce273df | 2019-12-17 13:14:45 +0000 | [diff] [blame] | 497 | @Deprecated |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 498 | public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile"; |
| 499 | |
| 500 | /** |
Pavel Grafov | 9fb706c | 2018-02-27 14:07:52 +0000 | [diff] [blame] | 501 | * Specifies if a user is disallowed from enabling or accessing debugging features. When set on |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 502 | * the primary user or by the profile owner of an organization-owned managed profile on the |
| 503 | * parent profile, disables debugging features altogether, including USB debugging. When set on |
| 504 | * a managed profile or a secondary user, blocks debugging for that user only, including |
Pavel Grafov | 9fb706c | 2018-02-27 14:07:52 +0000 | [diff] [blame] | 505 | * starting activities, making service calls, accessing content providers, sending broadcasts, |
| 506 | * installing/uninstalling packages, clearing user data, etc. |
| 507 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 508 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 509 | * <p>Key for user restrictions. |
| 510 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 511 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 512 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 513 | * @see #getUserRestrictions() |
| 514 | */ |
| 515 | public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; |
| 516 | |
| 517 | /** |
Benjamin Miller | 05fef7e | 2017-07-24 10:11:39 +0200 | [diff] [blame] | 518 | * Specifies if a user is disallowed from configuring a VPN. The default value is |
| 519 | * <code>false</code>. This restriction has an effect when set by device owners and, in Android |
| 520 | * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners. |
| 521 | * <p>This restriction also prevents VPNs from starting. However, in Android 7.0 |
| 522 | * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does |
| 523 | * start always-on VPNs created by the device or profile owner. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 524 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 525 | * <p>Key for user restrictions. |
| 526 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 527 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 528 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 529 | * @see #getUserRestrictions() |
| 530 | */ |
| 531 | public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; |
| 532 | |
| 533 | /** |
yuemingw | 7810b8b | 2018-02-01 17:32:25 +0000 | [diff] [blame] | 534 | * Specifies if a user is disallowed from enabling or disabling location providers. As a |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 535 | * result, user is disallowed from turning on or off location. |
yuemingw | 7cc2c4c | 2017-11-28 17:20:01 +0000 | [diff] [blame] | 536 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 537 | * <p> |
| 538 | * In a managed profile, location sharing is forced off when it is turned off on the primary |
| 539 | * user or by the profile owner of an organization-owned managed profile on the parent profile. |
| 540 | * The user can still turn off location sharing on a managed profile when the restriction is |
| 541 | * set by the profile owner on a managed profile. |
| 542 | * <p> |
| 543 | * This user restriction is different from {@link #DISALLOW_SHARE_LOCATION}, |
yuemingw | 7cc2c4c | 2017-11-28 17:20:01 +0000 | [diff] [blame] | 544 | * as the device owner or profile owner can still enable or disable location mode via |
Soonil Nagarkar | dc08e3a | 2019-12-02 12:31:45 -0800 | [diff] [blame] | 545 | * {@link DevicePolicyManager#setLocationEnabled} when this restriction is on. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 546 | * <p> |
| 547 | * The default value is <code>false</code>. |
yuemingw | 7cc2c4c | 2017-11-28 17:20:01 +0000 | [diff] [blame] | 548 | * |
| 549 | * <p>Key for user restrictions. |
| 550 | * <p>Type: Boolean |
Soonil Nagarkar | dc08e3a | 2019-12-02 12:31:45 -0800 | [diff] [blame] | 551 | * @see LocationManager#isLocationEnabled() |
yuemingw | 7cc2c4c | 2017-11-28 17:20:01 +0000 | [diff] [blame] | 552 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 553 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 554 | * @see #getUserRestrictions() |
| 555 | */ |
yuemingw | 7810b8b | 2018-02-01 17:32:25 +0000 | [diff] [blame] | 556 | public static final String DISALLOW_CONFIG_LOCATION = "no_config_location"; |
yuemingw | 7cc2c4c | 2017-11-28 17:20:01 +0000 | [diff] [blame] | 557 | |
| 558 | /** |
yuemingw | a9772f36 | 2017-10-23 18:34:35 +0100 | [diff] [blame] | 559 | * Specifies if date, time and timezone configuring is disallowed. |
| 560 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 561 | * <p>When restriction is set by device owners or profile owners of organization-owned |
| 562 | * managed profiles on the parent profile, it applies globally - i.e., it disables date, |
yuemingw | a9772f36 | 2017-10-23 18:34:35 +0100 | [diff] [blame] | 563 | * time and timezone setting on the entire device and all users will be affected. When it's set |
| 564 | * by profile owners, it's only applied to the managed user. |
| 565 | * <p>The default value is <code>false</code>. |
| 566 | * |
| 567 | * <p>This user restriction has no effect on managed profiles. |
| 568 | * <p>Key for user restrictions. |
| 569 | * <p>Type: Boolean |
| 570 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 571 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 572 | * @see #getUserRestrictions() |
| 573 | */ |
| 574 | public static final String DISALLOW_CONFIG_DATE_TIME = "no_config_date_time"; |
| 575 | |
| 576 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 577 | * Specifies if a user is disallowed from configuring Tethering |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 578 | * & portable hotspots. This can only be set by device owners, profile owners on the |
| 579 | * primary user or profile owners of organization-owned managed profiles on the parent profile. |
| 580 | * The default value is <code>false</code>. |
Rubin Xu | 1faf144 | 2017-08-23 15:48:12 +0100 | [diff] [blame] | 581 | * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set, |
| 582 | * tethering will be automatically turned off. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 583 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 584 | * <p>Key for user restrictions. |
| 585 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 586 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 587 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 588 | * @see #getUserRestrictions() |
| 589 | */ |
| 590 | public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; |
| 591 | |
| 592 | /** |
Stuart Scott | e3e314d | 2015-04-20 14:07:45 -0700 | [diff] [blame] | 593 | * Specifies if a user is disallowed from resetting network settings |
| 594 | * from Settings. This can only be set by device owners and profile owners on the primary user. |
| 595 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 596 | * <p>This restriction has no effect on secondary users and managed profiles since only the |
Stuart Scott | e3e314d | 2015-04-20 14:07:45 -0700 | [diff] [blame] | 597 | * primary user can reset the network settings of the device. |
| 598 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 599 | * <p>Key for user restrictions. |
| 600 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 601 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 602 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Stuart Scott | e3e314d | 2015-04-20 14:07:45 -0700 | [diff] [blame] | 603 | * @see #getUserRestrictions() |
| 604 | */ |
| 605 | public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; |
| 606 | |
| 607 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 608 | * Specifies if a user is disallowed from factory resetting |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 609 | * from Settings. This can only be set by device owners and profile owners on the primary user. |
| 610 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 611 | * <p>This restriction has no effect on secondary users and managed profiles since only the |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 612 | * primary user can factory reset the device. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 613 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 614 | * <p>Key for user restrictions. |
| 615 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 616 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 617 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 618 | * @see #getUserRestrictions() |
| 619 | */ |
| 620 | public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; |
| 621 | |
| 622 | /** |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 623 | * Specifies if a user is disallowed from adding new users. This can only be set by device |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 624 | * owners, profile owners on the primary user or profile owners of organization-owned managed |
| 625 | * profiles on the parent profile. The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 626 | * <p>This restriction has no effect on secondary users and managed profiles since only the |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 627 | * primary user can add other users. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 628 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 629 | * <p>Key for user restrictions. |
| 630 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 631 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 632 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 633 | * @see #getUserRestrictions() |
| 634 | */ |
| 635 | public static final String DISALLOW_ADD_USER = "no_add_user"; |
| 636 | |
| 637 | /** |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 638 | * Specifies if a user is disallowed from adding managed profiles. |
| 639 | * <p>The default value for an unmanaged user is <code>false</code>. |
Nicolas Prevot | 2ea46fe | 2017-01-05 10:29:34 +0000 | [diff] [blame] | 640 | * For users with a device owner set, the default is <code>true</code>. |
| 641 | * <p>This restriction has no effect on managed profiles. |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 642 | * |
| 643 | * <p>Key for user restrictions. |
| 644 | * <p>Type: Boolean |
| 645 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 646 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 647 | * @see #getUserRestrictions() |
Eran Messeri | ce273df | 2019-12-17 13:14:45 +0000 | [diff] [blame] | 648 | * @deprecated As the ability to have a managed profile on a fully-managed device has been |
| 649 | * removed from the platform, this restriction will be silently ignored when applied by the |
| 650 | * device owner. |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 651 | */ |
Eran Messeri | ce273df | 2019-12-17 13:14:45 +0000 | [diff] [blame] | 652 | @Deprecated |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 653 | public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile"; |
| 654 | |
| 655 | /** |
Benjamin Miller | d41a9fc | 2017-07-17 17:24:44 +0200 | [diff] [blame] | 656 | * Specifies if a user is disallowed from disabling application verification. The default |
| 657 | * value is <code>false</code>. |
| 658 | * |
| 659 | * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher, |
| 660 | * this is a global user restriction. If a device owner or profile owner sets this restriction, |
| 661 | * the system enforces app verification across all users on the device. Running in earlier |
| 662 | * Android versions, this restriction affects only the profile that sets it. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 663 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 664 | * <p>Key for user restrictions. |
| 665 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 666 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 667 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 668 | * @see #getUserRestrictions() |
| 669 | */ |
| 670 | public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; |
| 671 | |
| 672 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 673 | * Specifies if a user is disallowed from configuring cell |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 674 | * broadcasts. This can only be set by device owners, profile owners on the primary user or |
| 675 | * profile owners of organization-owned managed profiles on the parent profile. |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 676 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 677 | * <p>This restriction has no effect on secondary users and managed profiles since only the |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 678 | * primary user can configure cell broadcasts. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 679 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 680 | * <p>Key for user restrictions. |
| 681 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 682 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 683 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 684 | * @see #getUserRestrictions() |
| 685 | */ |
| 686 | public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; |
| 687 | |
| 688 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 689 | * Specifies if a user is disallowed from configuring mobile |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 690 | * networks. This can only be set by device owners, profile owners on the primary user or |
| 691 | * profile owners of organization-owned managed profiles on the parent profile. |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 692 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 693 | * <p>This restriction has no effect on secondary users and managed profiles since only the |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 694 | * primary user can configure mobile networks. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 695 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 696 | * <p>Key for user restrictions. |
| 697 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 698 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 699 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 700 | * @see #getUserRestrictions() |
| 701 | */ |
| 702 | public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; |
| 703 | |
| 704 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 705 | * Specifies if a user is disallowed from modifying |
Julia Reynolds | c617f81 | 2014-07-25 16:32:27 -0400 | [diff] [blame] | 706 | * applications in Settings or launchers. The following actions will not be allowed when this |
| 707 | * restriction is enabled: |
| 708 | * <li>uninstalling apps</li> |
| 709 | * <li>disabling apps</li> |
| 710 | * <li>clearing app caches</li> |
| 711 | * <li>clearing app data</li> |
| 712 | * <li>force stopping apps</li> |
| 713 | * <li>clearing app defaults</li> |
| 714 | * <p> |
| 715 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 716 | * |
Esteban Talavera | 8bd7c52 | 2017-02-13 12:35:04 +0000 | [diff] [blame] | 717 | * <p><strong>Note:</strong> The user will still be able to perform those actions via other |
| 718 | * means (such as adb). Third party apps will also be able to uninstall apps via the |
| 719 | * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or |
| 720 | * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be |
| 721 | * used to prevent the user from uninstalling apps completely, and |
| 722 | * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)} |
| 723 | * to add a default intent handler for a given intent filter. |
| 724 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 725 | * <p>Key for user restrictions. |
| 726 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 727 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 728 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 729 | * @see #getUserRestrictions() |
| 730 | */ |
Julia Reynolds | 36fbc8d | 2014-06-18 09:26:30 -0400 | [diff] [blame] | 731 | public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 732 | |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 733 | /** |
Alex Johnston | 9722abe | 2020-01-28 16:15:55 +0000 | [diff] [blame] | 734 | * Specifies if a user is disallowed from mounting physical external media. |
| 735 | * <p> |
| 736 | * This restriction can only be set by the device owner, the profile owner on the primary user |
| 737 | * or the profile owner of an organization-owned managed profile on the parent profile. |
| 738 | * <p> |
| 739 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 740 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 741 | * <p>Key for user restrictions. |
| 742 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 743 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 744 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 745 | * @see #getUserRestrictions() |
| 746 | */ |
| 747 | public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; |
| 748 | |
| 749 | /** |
Pavel Grafov | ce3e1a3 | 2017-04-21 14:48:21 +0100 | [diff] [blame] | 750 | * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone |
Alex Johnston | 9722abe | 2020-01-28 16:15:55 +0000 | [diff] [blame] | 751 | * will be muted. |
| 752 | * <p> |
| 753 | * The default value is <code>false</code>. |
| 754 | * <p> |
| 755 | * Device owner and profile owner can set this restriction, although the restriction has no |
| 756 | * effect in a managed profile. When it is set by the profile owner of an organization-owned |
| 757 | * managed profile on the parent profile, it will disallow the personal user from adjusting the |
| 758 | * microphone volume. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 759 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 760 | * <p>Key for user restrictions. |
| 761 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 762 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 763 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 764 | * @see #getUserRestrictions() |
| 765 | */ |
| 766 | public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; |
| 767 | |
| 768 | /** |
Pavel Grafov | ce3e1a3 | 2017-04-21 14:48:21 +0100 | [diff] [blame] | 769 | * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume |
Wen ZHANG | 61ed0dc | 2017-08-23 14:27:02 +0100 | [diff] [blame] | 770 | * will be muted. This can be set by device owners from API 21 and profile owners from API 24. |
| 771 | * The default value is <code>false</code>. |
| 772 | * |
| 773 | * <p>When the restriction is set by profile owners, then it only applies to relevant |
| 774 | * profiles. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 775 | * |
Pavel Grafov | ce3e1a3 | 2017-04-21 14:48:21 +0100 | [diff] [blame] | 776 | * <p>This restriction has no effect on managed profiles. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 777 | * <p>Key for user restrictions. |
| 778 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 779 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 780 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 781 | * @see #getUserRestrictions() |
| 782 | */ |
| 783 | public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; |
| 784 | |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 785 | /** |
Alex Johnston | 9722abe | 2020-01-28 16:15:55 +0000 | [diff] [blame] | 786 | * Specifies that the user is not allowed to make outgoing phone calls. Emergency calls are |
| 787 | * still permitted. |
| 788 | * <p> |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 789 | * The default value is <code>false</code>. |
Alex Johnston | 9722abe | 2020-01-28 16:15:55 +0000 | [diff] [blame] | 790 | * <p> |
| 791 | * Device owner and profile owner can set this restriction, although the restriction has no |
| 792 | * effect in a managed profile. When it is set by the profile owner of an organization-owned |
| 793 | * managed profile on the parent profile, it will disallow the personal user from making |
| 794 | * outgoing phone calls. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 795 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 796 | * <p>Key for user restrictions. |
| 797 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 798 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 799 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 800 | * @see #getUserRestrictions() |
| 801 | */ |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 802 | public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; |
| 803 | |
| 804 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 805 | * Specifies that the user is not allowed to send or receive |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 806 | * SMS messages. The default value is <code>false</code>. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 807 | * <p> |
| 808 | * Device owner and profile owner can set this restriction. When it is set by the |
| 809 | * profile owner of an organization-owned managed profile on the parent profile, |
| 810 | * it will disable SMS in the personal profile. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 811 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 812 | * <p>Key for user restrictions. |
| 813 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 814 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 815 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 816 | * @see #getUserRestrictions() |
| 817 | */ |
| 818 | public static final String DISALLOW_SMS = "no_sms"; |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 819 | |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 820 | /** |
Jeff Sharkey | 2cc03e5 | 2015-03-20 11:24:04 -0700 | [diff] [blame] | 821 | * Specifies if the user is not allowed to have fun. In some cases, the |
| 822 | * device owner may wish to prevent the user from experiencing amusement or |
| 823 | * joy while using the device. The default value is <code>false</code>. |
| 824 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 825 | * <p>Key for user restrictions. |
| 826 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 827 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 828 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Jeff Sharkey | 2cc03e5 | 2015-03-20 11:24:04 -0700 | [diff] [blame] | 829 | * @see #getUserRestrictions() |
| 830 | */ |
| 831 | public static final String DISALLOW_FUN = "no_fun"; |
| 832 | |
| 833 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 834 | * Specifies that windows besides app windows should not be |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 835 | * created. This will block the creation of the following types of windows. |
| 836 | * <li>{@link LayoutParams#TYPE_TOAST}</li> |
| 837 | * <li>{@link LayoutParams#TYPE_PHONE}</li> |
| 838 | * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> |
| 839 | * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> |
| 840 | * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> |
| 841 | * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 842 | * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li> |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 843 | * |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 844 | * <p>This can only be set by device owners and profile owners on the primary user. |
| 845 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 846 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 847 | * <p>Key for user restrictions. |
| 848 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 849 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 850 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 851 | * @see #getUserRestrictions() |
| 852 | */ |
| 853 | public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; |
| 854 | |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 855 | /** |
Charles He | 22ff6f9d | 2017-10-05 21:28:55 +0100 | [diff] [blame] | 856 | * Specifies that system error dialogs for crashed or unresponsive apps should not be shown. |
| 857 | * In this case, the system will force-stop the app as if the user chooses the "close app" |
Benjamin Franz | 0c86fe1 | 2018-02-28 09:49:17 +0000 | [diff] [blame] | 858 | * option on the UI. A feedback report isn't collected as there is no way for the user to |
| 859 | * provide explicit consent. The default value is <code>false</code>. |
Charles He | 22ff6f9d | 2017-10-05 21:28:55 +0100 | [diff] [blame] | 860 | * |
Benjamin Franz | 0c86fe1 | 2018-02-28 09:49:17 +0000 | [diff] [blame] | 861 | * <p>When this user restriction is set by device owners, it's applied to all users. When set by |
| 862 | * the profile owner of the primary user or a secondary user, the restriction affects only the |
| 863 | * calling user. This user restriction has no effect on managed profiles. |
Charles He | 22ff6f9d | 2017-10-05 21:28:55 +0100 | [diff] [blame] | 864 | * |
Charles He | 22ff6f9d | 2017-10-05 21:28:55 +0100 | [diff] [blame] | 865 | * <p>Key for user restrictions. |
| 866 | * <p>Type: Boolean |
| 867 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 868 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 869 | * @see #getUserRestrictions() |
| 870 | */ |
| 871 | public static final String DISALLOW_SYSTEM_ERROR_DIALOGS = "no_system_error_dialogs"; |
| 872 | |
| 873 | /** |
Benjamin Miller | 8cc730d | 2019-01-18 19:03:40 +0000 | [diff] [blame] | 874 | * Specifies if the clipboard contents can be exported by pasting the data into other users or |
| 875 | * profiles. This restriction doesn't prevent import, such as someone pasting clipboard data |
| 876 | * from other profiles or users. The default value is {@code false}. |
| 877 | * |
| 878 | * <p><strong>Note</strong>: Because it's possible to extract data from screenshots using |
| 879 | * optical character recognition (OCR), we strongly recommend combining this user restriction |
| 880 | * with {@link DevicePolicyManager#setScreenCaptureDisabled(ComponentName, boolean)}. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 881 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 882 | * <p>Key for user restrictions. |
| 883 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 884 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 885 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 886 | * @see #getUserRestrictions() |
| 887 | */ |
| 888 | public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; |
| 889 | |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 890 | /** |
| 891 | * Specifies if the user is not allowed to use NFC to beam out data from apps. |
| 892 | * The default value is <code>false</code>. |
| 893 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 894 | * <p>Key for user restrictions. |
| 895 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 896 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 897 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 898 | * @see #getUserRestrictions() |
| 899 | */ |
| 900 | public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; |
| 901 | |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 902 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 903 | * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction |
| 904 | * generally means that wallpapers are not supported for the particular user. This user |
| 905 | * restriction is always set for managed profiles, because such profiles don't have wallpapers. |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 906 | * @hide |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 907 | * @see #DISALLOW_SET_WALLPAPER |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 908 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 909 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 910 | * @see #getUserRestrictions() |
| 911 | */ |
| 912 | public static final String DISALLOW_WALLPAPER = "no_wallpaper"; |
| 913 | |
| 914 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 915 | * User restriction to disallow setting a wallpaper. Profile owner and device owner |
| 916 | * are able to set wallpaper regardless of this restriction. |
| 917 | * The default value is <code>false</code>. |
| 918 | * |
| 919 | * <p>Key for user restrictions. |
| 920 | * <p>Type: Boolean |
| 921 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 922 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 923 | * @see #getUserRestrictions() |
| 924 | */ |
| 925 | public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; |
| 926 | |
| 927 | /** |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 928 | * Specifies if the user is not allowed to reboot the device into safe boot mode. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 929 | * This can only be set by device owners, profile owners on the primary user or profile |
| 930 | * owners of organization-owned managed profiles on the parent profile. |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 931 | * The default value is <code>false</code>. |
| 932 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 933 | * <p>Key for user restrictions. |
| 934 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 935 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 936 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 937 | * @see #getUserRestrictions() |
| 938 | */ |
| 939 | public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; |
| 940 | |
| 941 | /** |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 942 | * Specifies if a user is not allowed to record audio. This restriction is always enabled for |
| 943 | * background users. The default value is <code>false</code>. |
| 944 | * |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 945 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 946 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 947 | * @see #getUserRestrictions() |
| 948 | * @hide |
| 949 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 950 | @UnsupportedAppUsage |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 951 | public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; |
| 952 | |
| 953 | /** |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 954 | * Specifies if a user is not allowed to run in the background and should be stopped during |
| 955 | * user switch. The default value is <code>false</code>. |
| 956 | * |
| 957 | * <p>This restriction can be set by device owners and profile owners. |
| 958 | * |
| 959 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 960 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 961 | * @see #getUserRestrictions() |
| 962 | * @hide |
| 963 | */ |
Robin Lee | 6cfb7a9 | 2017-12-18 15:14:46 +0100 | [diff] [blame] | 964 | @SystemApi |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 965 | public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; |
| 966 | |
| 967 | /** |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 968 | * Specifies if a user is not allowed to use the camera. |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 969 | * <p> |
| 970 | * Device owner and profile owner can set this restriction. When the restriction is set by |
| 971 | * the device owner or the profile owner of an organization-owned managed profile on the |
| 972 | * parent profile, it is applied globally. |
| 973 | * <p> |
| 974 | * The default value is <code>false</code>. |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 975 | * |
| 976 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 977 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 978 | * @see #getUserRestrictions() |
| 979 | * @hide |
| 980 | */ |
| 981 | public static final String DISALLOW_CAMERA = "no_camera"; |
| 982 | |
| 983 | /** |
Tony Mak | c120511 | 2016-07-22 16:02:59 +0100 | [diff] [blame] | 984 | * Specifies if a user is not allowed to unmute the device's master volume. |
| 985 | * |
| 986 | * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean) |
| 987 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 988 | * @see #getUserRestrictions() |
| 989 | * @hide |
| 990 | */ |
Esteban Talavera | 492b472 | 2017-02-13 14:59:45 +0000 | [diff] [blame] | 991 | public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device"; |
Tony Mak | c120511 | 2016-07-22 16:02:59 +0100 | [diff] [blame] | 992 | |
| 993 | /** |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 994 | * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 995 | * device owners or profile owners of organization-owned managed profiles on the parent profile. |
| 996 | * The default value is <code>false</code>. |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 997 | * |
| 998 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 999 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1000 | * @see #getUserRestrictions() |
| 1001 | */ |
| 1002 | public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; |
| 1003 | |
| 1004 | /** |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 1005 | * Specifies if a user is not allowed to change their icon. Device owner and profile owner |
| 1006 | * can set this restriction. When it is set by device owner, only the target user will be |
| 1007 | * affected. The default value is <code>false</code>. |
| 1008 | * |
| 1009 | * <p>Key for user restrictions. |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 1010 | * <p>Type: Boolean |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 1011 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1012 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1013 | * @see #getUserRestrictions() |
| 1014 | */ |
| 1015 | public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; |
| 1016 | |
| 1017 | /** |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 1018 | * Specifies if a user is not allowed to enable the oem unlock setting. The default value is |
Esteban Talavera | c48b20f | 2016-08-11 11:23:40 +0100 | [diff] [blame] | 1019 | * <code>false</code>. Setting this restriction has no effect if the bootloader is already |
| 1020 | * unlocked. |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 1021 | * |
Lenka Trochtova | 12b0496 | 2016-11-29 21:00:12 +0100 | [diff] [blame] | 1022 | * <p>Not for use by third-party applications. |
| 1023 | * |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 1024 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1025 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1026 | * @see #getUserRestrictions() |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 1027 | * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead. |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 1028 | * @hide |
| 1029 | */ |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 1030 | @Deprecated |
Lenka Trochtova | 12b0496 | 2016-11-29 21:00:12 +0100 | [diff] [blame] | 1031 | @SystemApi |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 1032 | public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock"; |
| 1033 | |
| 1034 | /** |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 1035 | * Specifies that the managed profile is not allowed to have unified lock screen challenge with |
| 1036 | * the primary user. |
| 1037 | * |
| 1038 | * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a |
| 1039 | * separate challenge. Profile owner can ask the user to set a new password using |
| 1040 | * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using |
| 1041 | * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}. |
| 1042 | * |
| 1043 | * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed |
| 1044 | * profile owner. Has no effect on non-managed profiles or users. |
| 1045 | * <p>Key for user restrictions. |
| 1046 | * <p>Type: Boolean |
| 1047 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1048 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1049 | * @see #getUserRestrictions() |
| 1050 | */ |
| 1051 | public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password"; |
| 1052 | |
| 1053 | /** |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 1054 | * Allows apps in the parent profile to handle web links from the managed profile. |
| 1055 | * |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 1056 | * This user restriction has an effect only in a managed profile. |
| 1057 | * If set: |
| 1058 | * Intent filters of activities in the parent profile with action |
| 1059 | * {@link android.content.Intent#ACTION_VIEW}, |
| 1060 | * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which |
| 1061 | * define a host can handle intents from the managed profile. |
| 1062 | * The default value is <code>false</code>. |
| 1063 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 1064 | * <p>Key for user restrictions. |
| 1065 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1066 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1067 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 1068 | * @see #getUserRestrictions() |
| 1069 | */ |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 1070 | public static final String ALLOW_PARENT_PROFILE_APP_LINKING |
| 1071 | = "allow_parent_profile_app_linking"; |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 1072 | |
| 1073 | /** |
Felipe Leme | 24d5893 | 2017-03-21 14:13:58 -0700 | [diff] [blame] | 1074 | * Specifies if a user is not allowed to use Autofill Services. |
| 1075 | * |
| 1076 | * <p>Device owner and profile owner can set this restriction. When it is set by device owner, |
| 1077 | * only the target user will be affected. |
| 1078 | * |
| 1079 | * <p>The default value is <code>false</code>. |
| 1080 | * |
| 1081 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1082 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1083 | * @see #getUserRestrictions() |
| 1084 | */ |
| 1085 | public static final String DISALLOW_AUTOFILL = "no_autofill"; |
| 1086 | |
| 1087 | /** |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 1088 | * Specifies if the contents of a user's screen is not allowed to be captured for artificial |
| 1089 | * intelligence purposes. |
| 1090 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 1091 | * <p>Device owner and profile owner can set this restriction. When it is set by the |
| 1092 | * device owner or the profile owner of an organization-owned managed profile on the parent |
| 1093 | * profile, only the target user will be affected. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 1094 | * |
| 1095 | * <p>The default value is <code>false</code>. |
| 1096 | * |
| 1097 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1098 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1099 | * @see #getUserRestrictions() |
| 1100 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 1101 | public static final String DISALLOW_CONTENT_CAPTURE = "no_content_capture"; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 1102 | |
| 1103 | /** |
Zak Cohen | 3e12ac7 | 2019-03-05 16:50:39 -0800 | [diff] [blame] | 1104 | * Specifies if the current user is able to receive content suggestions for selections based on |
| 1105 | * the contents of their screen. |
| 1106 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 1107 | * <p>Device owner and profile owner can set this restriction. When it is set by the |
| 1108 | * device owner or the profile owner of an organization-owned managed profile on the parent |
| 1109 | * profile, only the target user will be affected. |
Zak Cohen | 3e12ac7 | 2019-03-05 16:50:39 -0800 | [diff] [blame] | 1110 | * |
| 1111 | * <p>The default value is <code>false</code>. |
| 1112 | * |
| 1113 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1114 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1115 | * @see #getUserRestrictions() |
| 1116 | */ |
| 1117 | public static final String DISALLOW_CONTENT_SUGGESTIONS = "no_content_suggestions"; |
| 1118 | |
| 1119 | /** |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 1120 | * Specifies if user switching is blocked on the current user. |
| 1121 | * |
| 1122 | * <p> This restriction can only be set by the device owner, it will be applied to all users. |
Alex Chau | 71ada44 | 2018-02-22 12:56:59 +0800 | [diff] [blame] | 1123 | * Device owner can still switch user via |
| 1124 | * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is |
| 1125 | * set. |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 1126 | * |
| 1127 | * <p>The default value is <code>false</code>. |
| 1128 | * |
| 1129 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1130 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1131 | * @see #getUserRestrictions() |
| 1132 | */ |
| 1133 | public static final String DISALLOW_USER_SWITCH = "no_user_switch"; |
| 1134 | |
| 1135 | /** |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 1136 | * Specifies whether the user can share file / picture / data from the primary user into the |
| 1137 | * managed profile, either by sending them from the primary side, or by picking up data within |
| 1138 | * an app in the managed profile. |
| 1139 | * <p> |
| 1140 | * When a managed profile is created, the system allows the user to send data from the primary |
| 1141 | * side to the profile by setting up certain default cross profile intent filters. If |
| 1142 | * this is undesired, this restriction can be set to disallow it. Note that this restriction |
| 1143 | * will not block any sharing allowed by explicit |
| 1144 | * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner. |
| 1145 | * <p> |
| 1146 | * This restriction is only meaningful when set by profile owner. When it is set by device |
| 1147 | * owner, it does not have any effect. |
| 1148 | * <p> |
| 1149 | * The default value is <code>false</code>. |
| 1150 | * |
| 1151 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1152 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1153 | * @see #getUserRestrictions() |
| 1154 | */ |
| 1155 | public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile"; |
Vladislav Kuzkokov | 622b9f9 | 2018-01-25 16:33:05 +0100 | [diff] [blame] | 1156 | |
| 1157 | /** |
| 1158 | * Specifies whether the user is allowed to print. |
| 1159 | * |
| 1160 | * This restriction can be set by device or profile owner. |
| 1161 | * |
| 1162 | * The default value is {@code false}. |
| 1163 | * |
| 1164 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1165 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1166 | * @see #getUserRestrictions() |
| 1167 | */ |
| 1168 | public static final String DISALLOW_PRINTING = "no_printing"; |
| 1169 | |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 1170 | /** |
Eran Messeri | 09b122da | 2018-10-05 15:33:53 +0100 | [diff] [blame] | 1171 | * Specifies whether the user is allowed to modify private DNS settings. |
| 1172 | * |
| 1173 | * <p>The default value is <code>false</code>. |
| 1174 | * |
Alex Johnston | 7c3d7e2 | 2020-01-08 12:57:14 +0000 | [diff] [blame] | 1175 | * <p>This user restriction can only be applied by the device owner or the profile owner |
| 1176 | * of an organization-owned managed profile on the parent profile. |
| 1177 | * |
Eran Messeri | 09b122da | 2018-10-05 15:33:53 +0100 | [diff] [blame] | 1178 | * <p>Key for user restrictions. |
| 1179 | * <p>Type: Boolean |
| 1180 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1181 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1182 | * @see #getUserRestrictions() |
| 1183 | */ |
| 1184 | public static final String DISALLOW_CONFIG_PRIVATE_DNS = |
| 1185 | "disallow_config_private_dns"; |
| 1186 | |
| 1187 | /** |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 1188 | * Application restriction key that is used to indicate the pending arrival |
| 1189 | * of real restrictions for the app. |
| 1190 | * |
| 1191 | * <p> |
| 1192 | * Applications that support restrictions should check for the presence of this key. |
| 1193 | * A <code>true</code> value indicates that restrictions may be applied in the near |
| 1194 | * future but are not available yet. It is the responsibility of any |
| 1195 | * management application that sets this flag to update it when the final |
| 1196 | * restrictions are enforced. |
| 1197 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 1198 | * <p>Key for application restrictions. |
| 1199 | * <p>Type: Boolean |
Nicolas Prevot | b14ed95 | 2015-01-13 14:23:53 +0000 | [diff] [blame] | 1200 | * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( |
| 1201 | * android.content.ComponentName, String, Bundle) |
| 1202 | * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( |
| 1203 | * android.content.ComponentName, String) |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 1204 | */ |
| 1205 | public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; |
| 1206 | |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 1207 | /** |
| 1208 | * List of key values that can be passed into the various user restriction related methods |
| 1209 | * in {@link UserManager} & {@link DevicePolicyManager}. |
| 1210 | * Note: This is slightly different from the real set of user restrictions listed in {@link |
| 1211 | * com.android.server.pm.UserRestrictionsUtils#USER_RESTRICTIONS}. For example |
| 1212 | * {@link #KEY_RESTRICTIONS_PENDING} is not a real user restriction, but is a a legitimate |
| 1213 | * value that can be passed into {@link #hasUserRestriction(String)}. |
| 1214 | * @hide |
| 1215 | */ |
| 1216 | @StringDef(value = { |
| 1217 | DISALLOW_MODIFY_ACCOUNTS, |
| 1218 | DISALLOW_CONFIG_WIFI, |
| 1219 | DISALLOW_CONFIG_LOCALE, |
| 1220 | DISALLOW_INSTALL_APPS, |
| 1221 | DISALLOW_UNINSTALL_APPS, |
| 1222 | DISALLOW_SHARE_LOCATION, |
| 1223 | DISALLOW_AIRPLANE_MODE, |
| 1224 | DISALLOW_CONFIG_BRIGHTNESS, |
| 1225 | DISALLOW_AMBIENT_DISPLAY, |
| 1226 | DISALLOW_CONFIG_SCREEN_TIMEOUT, |
| 1227 | DISALLOW_INSTALL_UNKNOWN_SOURCES, |
| 1228 | DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, |
| 1229 | DISALLOW_CONFIG_BLUETOOTH, |
| 1230 | DISALLOW_BLUETOOTH, |
| 1231 | DISALLOW_BLUETOOTH_SHARING, |
| 1232 | DISALLOW_USB_FILE_TRANSFER, |
| 1233 | DISALLOW_CONFIG_CREDENTIALS, |
| 1234 | DISALLOW_REMOVE_USER, |
| 1235 | DISALLOW_REMOVE_MANAGED_PROFILE, |
| 1236 | DISALLOW_DEBUGGING_FEATURES, |
| 1237 | DISALLOW_CONFIG_VPN, |
| 1238 | DISALLOW_CONFIG_LOCATION, |
| 1239 | DISALLOW_CONFIG_DATE_TIME, |
| 1240 | DISALLOW_CONFIG_TETHERING, |
| 1241 | DISALLOW_NETWORK_RESET, |
| 1242 | DISALLOW_FACTORY_RESET, |
| 1243 | DISALLOW_ADD_USER, |
| 1244 | DISALLOW_ADD_MANAGED_PROFILE, |
| 1245 | ENSURE_VERIFY_APPS, |
| 1246 | DISALLOW_CONFIG_CELL_BROADCASTS, |
| 1247 | DISALLOW_CONFIG_MOBILE_NETWORKS, |
| 1248 | DISALLOW_APPS_CONTROL, |
| 1249 | DISALLOW_MOUNT_PHYSICAL_MEDIA, |
| 1250 | DISALLOW_UNMUTE_MICROPHONE, |
| 1251 | DISALLOW_ADJUST_VOLUME, |
| 1252 | DISALLOW_OUTGOING_CALLS, |
| 1253 | DISALLOW_SMS, |
| 1254 | DISALLOW_FUN, |
| 1255 | DISALLOW_CREATE_WINDOWS, |
| 1256 | DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 1257 | DISALLOW_CROSS_PROFILE_COPY_PASTE, |
| 1258 | DISALLOW_OUTGOING_BEAM, |
| 1259 | DISALLOW_WALLPAPER, |
| 1260 | DISALLOW_SET_WALLPAPER, |
| 1261 | DISALLOW_SAFE_BOOT, |
| 1262 | DISALLOW_RECORD_AUDIO, |
| 1263 | DISALLOW_RUN_IN_BACKGROUND, |
| 1264 | DISALLOW_CAMERA, |
| 1265 | DISALLOW_UNMUTE_DEVICE, |
| 1266 | DISALLOW_DATA_ROAMING, |
| 1267 | DISALLOW_SET_USER_ICON, |
| 1268 | DISALLOW_OEM_UNLOCK, |
| 1269 | DISALLOW_UNIFIED_PASSWORD, |
| 1270 | ALLOW_PARENT_PROFILE_APP_LINKING, |
| 1271 | DISALLOW_AUTOFILL, |
| 1272 | DISALLOW_CONTENT_CAPTURE, |
| 1273 | DISALLOW_CONTENT_SUGGESTIONS, |
| 1274 | DISALLOW_USER_SWITCH, |
| 1275 | DISALLOW_SHARE_INTO_MANAGED_PROFILE, |
| 1276 | DISALLOW_PRINTING, |
| 1277 | DISALLOW_CONFIG_PRIVATE_DNS, |
| 1278 | KEY_RESTRICTIONS_PENDING, |
| 1279 | }) |
| 1280 | @Retention(RetentionPolicy.SOURCE) |
| 1281 | public @interface UserRestrictionKey {} |
| 1282 | |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1283 | private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; |
| 1284 | |
| 1285 | /** |
| 1286 | * Extra containing a name for the user being created. Optional parameter passed to |
| 1287 | * ACTION_CREATE_USER activity. |
| 1288 | * @hide |
| 1289 | */ |
| 1290 | public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; |
| 1291 | |
| 1292 | /** |
| 1293 | * Extra containing account name for the user being created. Optional parameter passed to |
| 1294 | * ACTION_CREATE_USER activity. |
| 1295 | * @hide |
| 1296 | */ |
| 1297 | public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; |
| 1298 | |
| 1299 | /** |
| 1300 | * Extra containing account type for the user being created. Optional parameter passed to |
| 1301 | * ACTION_CREATE_USER activity. |
| 1302 | * @hide |
| 1303 | */ |
| 1304 | public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; |
| 1305 | |
| 1306 | /** |
| 1307 | * Extra containing account-specific data for the user being created. Optional parameter passed |
| 1308 | * to ACTION_CREATE_USER activity. |
| 1309 | * @hide |
| 1310 | */ |
| 1311 | public static final String EXTRA_USER_ACCOUNT_OPTIONS |
| 1312 | = "android.os.extra.USER_ACCOUNT_OPTIONS"; |
| 1313 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1314 | /** @hide */ |
| 1315 | public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; |
| 1316 | /** @hide */ |
| 1317 | public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; |
| 1318 | /** @hide */ |
| 1319 | public static final int PIN_VERIFICATION_SUCCESS = -1; |
| 1320 | |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1321 | /** |
Makoto Onuki | e72f81b | 2017-03-16 14:08:19 -0700 | [diff] [blame] | 1322 | * Sent when user restrictions have changed. |
| 1323 | * |
| 1324 | * @hide |
| 1325 | */ |
| 1326 | @SystemApi |
| 1327 | @TestApi // To allow seeing it from CTS. |
| 1328 | public static final String ACTION_USER_RESTRICTIONS_CHANGED = |
| 1329 | "android.os.action.USER_RESTRICTIONS_CHANGED"; |
| 1330 | |
| 1331 | /** |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1332 | * Error result indicating that this user is not allowed to add other users on this device. |
| 1333 | * This is a result code returned from the activity created by the intent |
| 1334 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 1335 | */ |
| 1336 | public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; |
| 1337 | |
| 1338 | /** |
| 1339 | * Error result indicating that no more users can be created on this device. |
| 1340 | * This is a result code returned from the activity created by the intent |
| 1341 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 1342 | */ |
| 1343 | public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; |
| 1344 | |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 1345 | /** |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1346 | * Indicates that users are switchable. |
| 1347 | * @hide |
| 1348 | */ |
| 1349 | @SystemApi |
| 1350 | public static final int SWITCHABILITY_STATUS_OK = 0; |
| 1351 | |
| 1352 | /** |
| 1353 | * Indicated that the user is in a phone call. |
| 1354 | * @hide |
| 1355 | */ |
| 1356 | @SystemApi |
| 1357 | public static final int SWITCHABILITY_STATUS_USER_IN_CALL = 1 << 0; |
| 1358 | |
| 1359 | /** |
| 1360 | * Indicates that user switching is disallowed ({@link #DISALLOW_USER_SWITCH} is set). |
| 1361 | * @hide |
| 1362 | */ |
| 1363 | @SystemApi |
| 1364 | public static final int SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED = 1 << 1; |
| 1365 | |
| 1366 | /** |
| 1367 | * Indicates that the system user is locked and user switching is not allowed. |
| 1368 | * @hide |
| 1369 | */ |
| 1370 | @SystemApi |
| 1371 | public static final int SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED = 1 << 2; |
| 1372 | |
| 1373 | /** |
| 1374 | * Result returned in {@link #getUserSwitchability()} indicating user swichability. |
| 1375 | * @hide |
| 1376 | */ |
| 1377 | @Retention(RetentionPolicy.SOURCE) |
| 1378 | @IntDef(flag = true, prefix = { "SWITCHABILITY_STATUS_" }, value = { |
| 1379 | SWITCHABILITY_STATUS_OK, |
| 1380 | SWITCHABILITY_STATUS_USER_IN_CALL, |
| 1381 | SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED, |
| 1382 | SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED |
| 1383 | }) |
| 1384 | public @interface UserSwitchabilityResult {} |
| 1385 | |
| 1386 | /** |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 1387 | * Indicates user operation is successful. |
| 1388 | */ |
| 1389 | public static final int USER_OPERATION_SUCCESS = 0; |
| 1390 | |
| 1391 | /** |
| 1392 | * Indicates user operation failed for unknown reason. |
| 1393 | */ |
| 1394 | public static final int USER_OPERATION_ERROR_UNKNOWN = 1; |
| 1395 | |
| 1396 | /** |
| 1397 | * Indicates user operation failed because target user is a managed profile. |
| 1398 | */ |
| 1399 | public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2; |
| 1400 | |
| 1401 | /** |
| 1402 | * Indicates user operation failed because maximum running user limit has been reached. |
| 1403 | */ |
| 1404 | public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3; |
| 1405 | |
| 1406 | /** |
| 1407 | * Indicates user operation failed because the target user is in the foreground. |
| 1408 | */ |
| 1409 | public static final int USER_OPERATION_ERROR_CURRENT_USER = 4; |
| 1410 | |
| 1411 | /** |
| 1412 | * Indicates user operation failed because device has low data storage. |
| 1413 | */ |
| 1414 | public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5; |
| 1415 | |
| 1416 | /** |
| 1417 | * Indicates user operation failed because maximum user limit has been reached. |
| 1418 | */ |
| 1419 | public static final int USER_OPERATION_ERROR_MAX_USERS = 6; |
| 1420 | |
| 1421 | /** |
| 1422 | * Result returned from various user operations. |
| 1423 | * |
| 1424 | * @hide |
| 1425 | */ |
| 1426 | @Retention(RetentionPolicy.SOURCE) |
| 1427 | @IntDef(prefix = { "USER_OPERATION_" }, value = { |
| 1428 | USER_OPERATION_SUCCESS, |
| 1429 | USER_OPERATION_ERROR_UNKNOWN, |
| 1430 | USER_OPERATION_ERROR_MANAGED_PROFILE, |
| 1431 | USER_OPERATION_ERROR_MAX_RUNNING_USERS, |
| 1432 | USER_OPERATION_ERROR_CURRENT_USER, |
| 1433 | USER_OPERATION_ERROR_LOW_STORAGE, |
| 1434 | USER_OPERATION_ERROR_MAX_USERS |
| 1435 | }) |
| 1436 | public @interface UserOperationResult {} |
| 1437 | |
| 1438 | /** |
| 1439 | * Thrown to indicate user operation failed. |
| 1440 | */ |
| 1441 | public static class UserOperationException extends RuntimeException { |
| 1442 | private final @UserOperationResult int mUserOperationResult; |
| 1443 | |
| 1444 | /** |
| 1445 | * Constructs a UserOperationException with specific result code. |
| 1446 | * |
| 1447 | * @param message the detail message |
| 1448 | * @param userOperationResult the result code |
| 1449 | * @hide |
| 1450 | */ |
| 1451 | public UserOperationException(String message, |
| 1452 | @UserOperationResult int userOperationResult) { |
| 1453 | super(message); |
| 1454 | mUserOperationResult = userOperationResult; |
| 1455 | } |
| 1456 | |
| 1457 | /** |
| 1458 | * Returns the operation result code. |
| 1459 | */ |
| 1460 | public @UserOperationResult int getUserOperationResult() { |
| 1461 | return mUserOperationResult; |
| 1462 | } |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1463 | |
| 1464 | /** |
| 1465 | * Returns a UserOperationException containing the same message and error code. |
| 1466 | * @hide |
| 1467 | */ |
| 1468 | public static UserOperationException from(ServiceSpecificException exception) { |
| 1469 | return new UserOperationException(exception.getMessage(), exception.errorCode); |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | /** |
| 1474 | * Converts the ServiceSpecificException into a UserOperationException or throws null; |
| 1475 | * |
| 1476 | * @param exception exception to convert. |
| 1477 | * @param throwInsteadOfNull if an exception should be thrown or null returned. |
| 1478 | * @return null if chosen not to throw exception. |
| 1479 | * @throws UserOperationException |
| 1480 | */ |
| 1481 | private <T> T returnNullOrThrowUserOperationException(ServiceSpecificException exception, |
| 1482 | boolean throwInsteadOfNull) throws UserOperationException { |
| 1483 | if (throwInsteadOfNull) { |
| 1484 | throw UserOperationException.from(exception); |
| 1485 | } else { |
| 1486 | return null; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /** |
| 1491 | * Thrown to indicate user operation failed. (Checked exception) |
| 1492 | * @hide |
| 1493 | */ |
| 1494 | public static class CheckedUserOperationException extends AndroidException { |
| 1495 | private final @UserOperationResult int mUserOperationResult; |
| 1496 | |
| 1497 | /** |
| 1498 | * Constructs a CheckedUserOperationException with specific result code. |
| 1499 | * |
| 1500 | * @param message the detail message |
| 1501 | * @param userOperationResult the result code |
| 1502 | * @hide |
| 1503 | */ |
| 1504 | public CheckedUserOperationException(String message, |
| 1505 | @UserOperationResult int userOperationResult) { |
| 1506 | super(message); |
| 1507 | mUserOperationResult = userOperationResult; |
| 1508 | } |
| 1509 | |
| 1510 | /** Returns the operation result code. */ |
| 1511 | public @UserOperationResult int getUserOperationResult() { |
| 1512 | return mUserOperationResult; |
| 1513 | } |
| 1514 | |
| 1515 | /** Return a ServiceSpecificException containing the same message and error code. */ |
| 1516 | public ServiceSpecificException toServiceSpecificException() { |
| 1517 | return new ServiceSpecificException(mUserOperationResult, getMessage()); |
| 1518 | } |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1521 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1522 | @UnsupportedAppUsage |
Amith Yamasani | c068830 | 2015-10-30 10:40:03 -0700 | [diff] [blame] | 1523 | public static UserManager get(Context context) { |
| 1524 | return (UserManager) context.getSystemService(Context.USER_SERVICE); |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 1525 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1526 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1527 | /** @hide */ |
| 1528 | public UserManager(Context context, IUserManager service) { |
| 1529 | mService = service; |
Fyodor Kupolov | 5200e1c | 2016-10-17 18:46:16 -0700 | [diff] [blame] | 1530 | mContext = context.getApplicationContext(); |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1531 | mUserId = context.getUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1535 | * Returns whether this device supports multiple users with their own login and customizable |
| 1536 | * space. |
| 1537 | * @return whether the device supports multiple users. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1538 | */ |
Jeff Sharkey | 4673e7e | 2012-09-19 13:14:30 -0700 | [diff] [blame] | 1539 | public static boolean supportsMultipleUsers() { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 1540 | return getMaxSupportedUsers() > 1 |
| 1541 | && SystemProperties.getBoolean("fw.show_multiuserui", |
| 1542 | Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1545 | /** |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1546 | * @hide |
| 1547 | * @return Whether the device is running with split system user. It means the system user and |
| 1548 | * primary user are two separate users. Previously system user and primary user are combined as |
| 1549 | * a single owner user. see @link {android.os.UserHandle#USER_OWNER} |
| 1550 | */ |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 1551 | @TestApi |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1552 | public static boolean isSplitSystemUser() { |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1553 | return RoSystemProperties.FW_SYSTEM_USER_SPLIT; |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1557 | * @return Whether guest user is always ephemeral |
| 1558 | * @hide |
| 1559 | */ |
| 1560 | public static boolean isGuestUserEphemeral() { |
| 1561 | return Resources.getSystem() |
| 1562 | .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral); |
| 1563 | } |
| 1564 | |
| 1565 | /** |
Eric Jeong | e7ead1b | 2019-07-18 09:37:08 -0700 | [diff] [blame] | 1566 | * @hide |
| 1567 | * @return Whether the device is running in a headless system user mode. It means the headless |
| 1568 | * user (system user) runs system services and system UI, but is not associated with any real |
| 1569 | * person. Secondary users can be created to be associated with real person. |
| 1570 | */ |
| 1571 | public static boolean isHeadlessSystemUserMode() { |
| 1572 | return RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER; |
| 1573 | } |
| 1574 | |
| 1575 | /** |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1576 | * @deprecated use {@link #getUserSwitchability()} instead. |
| 1577 | * |
| 1578 | * @removed |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1579 | * @hide |
| 1580 | */ |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1581 | @Deprecated |
| 1582 | @UnsupportedAppUsage |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1583 | public boolean canSwitchUsers() { |
| 1584 | boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( |
| 1585 | mContext.getContentResolver(), |
| 1586 | Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; |
| 1587 | boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); |
Jayachandran C | 16dce22 | 2019-11-15 15:42:01 -0800 | [diff] [blame] | 1588 | boolean inCall = false; |
| 1589 | TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class); |
| 1590 | if (telephonyManager != null) { |
| 1591 | inCall = telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE; |
| 1592 | } |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 1593 | boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH); |
| 1594 | return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall |
| 1595 | && !isUserSwitchDisallowed; |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | /** |
Anthony Hugh | 6acda5e | 2019-10-24 14:49:52 -0700 | [diff] [blame] | 1599 | * Returns whether switching users is currently allowed for the user this process is running |
| 1600 | * under. |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1601 | * <p> |
| 1602 | * Switching users is not allowed in the following cases: |
| 1603 | * <li>the user is in a phone call</li> |
| 1604 | * <li>{@link #DISALLOW_USER_SWITCH} is set</li> |
| 1605 | * <li>system user hasn't been unlocked yet</li> |
| 1606 | * |
| 1607 | * @return A {@link UserSwitchabilityResult} flag indicating if the user is switchable. |
| 1608 | * @hide |
| 1609 | */ |
| 1610 | @SystemApi |
| 1611 | @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE, |
| 1612 | android.Manifest.permission.MANAGE_USERS, |
| 1613 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
| 1614 | public @UserSwitchabilityResult int getUserSwitchability() { |
Anthony Hugh | 6acda5e | 2019-10-24 14:49:52 -0700 | [diff] [blame] | 1615 | return getUserSwitchability(Process.myUserHandle()); |
| 1616 | } |
| 1617 | |
| 1618 | /** |
| 1619 | * Returns whether switching users is currently allowed for the provided user. |
| 1620 | * <p> |
| 1621 | * Switching users is not allowed in the following cases: |
| 1622 | * <li>the user is in a phone call</li> |
| 1623 | * <li>{@link #DISALLOW_USER_SWITCH} is set</li> |
| 1624 | * <li>system user hasn't been unlocked yet</li> |
| 1625 | * |
| 1626 | * @return A {@link UserSwitchabilityResult} flag indicating if the user is switchable. |
| 1627 | * @hide |
| 1628 | */ |
| 1629 | @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE, |
| 1630 | android.Manifest.permission.MANAGE_USERS, |
| 1631 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
| 1632 | public @UserSwitchabilityResult int getUserSwitchability(UserHandle userHandle) { |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1633 | final TelephonyManager tm = |
| 1634 | (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); |
| 1635 | |
| 1636 | int flags = SWITCHABILITY_STATUS_OK; |
| 1637 | if (tm.getCallState() != TelephonyManager.CALL_STATE_IDLE) { |
| 1638 | flags |= SWITCHABILITY_STATUS_USER_IN_CALL; |
| 1639 | } |
Anthony Hugh | 6acda5e | 2019-10-24 14:49:52 -0700 | [diff] [blame] | 1640 | if (hasUserRestriction(DISALLOW_USER_SWITCH, userHandle)) { |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1641 | flags |= SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED; |
| 1642 | } |
Anthony Hugh | 6acda5e | 2019-10-24 14:49:52 -0700 | [diff] [blame] | 1643 | |
| 1644 | // System User is always unlocked in Headless System User Mode, so ignore this flag |
| 1645 | if (!isHeadlessSystemUserMode()) { |
| 1646 | final boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( |
| 1647 | mContext.getContentResolver(), |
| 1648 | Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; |
| 1649 | final boolean systemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); |
| 1650 | |
| 1651 | if (!allowUserSwitchingWhenSystemUserLocked && !systemUserUnlocked) { |
| 1652 | flags |= SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED; |
| 1653 | } |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1654 | } |
Anthony Hugh | 6acda5e | 2019-10-24 14:49:52 -0700 | [diff] [blame] | 1655 | |
Varun Shah | 50ef200 | 2019-03-04 16:41:12 -0800 | [diff] [blame] | 1656 | return flags; |
| 1657 | } |
| 1658 | |
| 1659 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1660 | * Returns the user handle for the user that this process is running under. |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1661 | * |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1662 | * @return the user handle of this process. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1663 | * @hide |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1664 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1665 | @UnsupportedAppUsage |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1666 | public @UserIdInt int getUserHandle() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 1667 | return UserHandle.myUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1671 | * Returns the user name of the context user. This call is only available to applications on |
| 1672 | * the system image; it requires the {@code android.permission.MANAGE_USERS} or {@code |
| 1673 | * android.permission.GET_ACCOUNTS_PRIVILEGED} permissions. |
| 1674 | * |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1675 | * @return the user name |
| 1676 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1677 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 1678 | android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}, conditional = true) |
| 1679 | @UserHandleAware |
| 1680 | public @NonNull String getUserName() { |
| 1681 | if (UserHandle.myUserId() == mUserId) { |
| 1682 | try { |
| 1683 | return mService.getUserName(); |
| 1684 | } catch (RemoteException re) { |
| 1685 | throw re.rethrowFromSystemServer(); |
| 1686 | } |
| 1687 | } else { |
| 1688 | UserInfo userInfo = getUserInfo(mUserId); |
| 1689 | return userInfo == null ? "" : userInfo.name; |
Bookatz | cde3d92 | 2019-03-08 14:30:00 -0800 | [diff] [blame] | 1690 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 1693 | /** |
Fyodor Kupolov | 605b12a | 2017-05-10 15:58:09 -0700 | [diff] [blame] | 1694 | * Returns whether user name has been set. |
| 1695 | * <p>This method can be used to check that the value returned by {@link #getUserName()} was |
| 1696 | * set by the user and is not a placeholder string provided by the system. |
| 1697 | * @hide |
| 1698 | */ |
Bookatz | fe4eb2b | 2019-08-22 18:26:49 -0700 | [diff] [blame] | 1699 | @SystemApi |
| 1700 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1701 | Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) |
Fyodor Kupolov | 605b12a | 2017-05-10 15:58:09 -0700 | [diff] [blame] | 1702 | public boolean isUserNameSet() { |
| 1703 | try { |
| 1704 | return mService.isUserNameSet(getUserHandle()); |
| 1705 | } catch (RemoteException re) { |
| 1706 | throw re.rethrowFromSystemServer(); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | /** |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1711 | * Used to determine whether the user making this call is subject to |
| 1712 | * teleportations. |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 1713 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1714 | * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 1715 | * now automatically identify goats using advanced goat recognition technology.</p> |
| 1716 | * |
| 1717 | * @return Returns true if the user making this call is a goat. |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1718 | */ |
| 1719 | public boolean isUserAGoat() { |
Adam Powell | 988ae30 | 2014-09-17 17:58:33 -0700 | [diff] [blame] | 1720 | return mContext.getPackageManager() |
| 1721 | .isPackageAvailable("com.coffeestainstudios.goatsimulator"); |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1722 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1723 | |
| 1724 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1725 | * Used to check if this process is running under the primary user. The primary user |
Ying Zheng | 215116f | 2019-09-11 12:50:09 -0700 | [diff] [blame] | 1726 | * is the first human user on a device. This is not supported in headless system user mode. |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1727 | * |
| 1728 | * @return whether this process is running under the primary user. |
| 1729 | * @hide |
| 1730 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1731 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1732 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1733 | Manifest.permission.CREATE_USERS}) |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1734 | public boolean isPrimaryUser() { |
| 1735 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1736 | return user != null && user.isPrimary(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1740 | * Used to check if this process is running under the system user. The system user |
| 1741 | * is the initial user that is implicitly created on first boot and hosts most of the |
| 1742 | * system services. |
| 1743 | * |
| 1744 | * @return whether this process is running under the system user. |
| 1745 | */ |
| 1746 | public boolean isSystemUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1747 | return UserHandle.myUserId() == UserHandle.USER_SYSTEM; |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1748 | } |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1749 | |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1750 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1751 | * Used to check if this process is running as an admin user. An admin user is allowed to |
| 1752 | * modify or configure certain settings that aren't available to non-admin users, |
| 1753 | * create and delete additional users, etc. There can be more than one admin users. |
| 1754 | * |
| 1755 | * @return whether this process is running under an admin user. |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1756 | * @hide |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1757 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1758 | @SystemApi |
| 1759 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1760 | public boolean isAdminUser() { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1761 | return isUserAdmin(UserHandle.myUserId()); |
| 1762 | } |
| 1763 | |
| 1764 | /** |
| 1765 | * @hide |
| 1766 | * Returns whether the provided user is an admin user. There can be more than one admin |
| 1767 | * user. |
| 1768 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1769 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1770 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1771 | Manifest.permission.CREATE_USERS}) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1772 | public boolean isUserAdmin(@UserIdInt int userId) { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1773 | UserInfo user = getUserInfo(userId); |
| 1774 | return user != null && user.isAdmin(); |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1778 | * Returns whether the context user's user is of the given user type, such as |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1779 | * {@link UserManager#USER_TYPE_FULL_GUEST}. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1780 | * |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1781 | * @return true if the user is of the given user type. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1782 | * @hide |
| 1783 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1784 | @SystemApi |
| 1785 | @UserHandleAware |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1786 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 1787 | public boolean isUserOfType(@NonNull String userType) { |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1788 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1789 | return mService.isUserOfType(mUserId, userType); |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1790 | } catch (RemoteException re) { |
| 1791 | throw re.rethrowFromSystemServer(); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | /** |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1796 | * Returns whether the given user is of the given user type, such as |
| 1797 | * {@link UserManager#USER_TYPE_FULL_GUEST}. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1798 | * |
| 1799 | * @param userHandle the user handle of the user whose type is being requested. |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1800 | * @param userType the name of the user's user type, e.g. |
| 1801 | * {@link UserManager#USER_TYPE_PROFILE_MANAGED}. |
| 1802 | * @return true if the userHandle user is of type userType |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1803 | * @hide |
| 1804 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1805 | @SystemApi |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1806 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 1807 | public boolean isUserOfType(@NonNull UserHandle userHandle, @NonNull String userType) { |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1808 | try { |
Adam Bookatz | 351a8fb | 2019-12-23 10:09:14 -0800 | [diff] [blame] | 1809 | return mService.isUserOfType(userHandle.getIdentifier(), userType); |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1810 | } catch (RemoteException re) { |
| 1811 | throw re.rethrowFromSystemServer(); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | /** |
| 1816 | * Returns whether the user type is a |
| 1817 | * {@link UserManager#USER_TYPE_PROFILE_MANAGED managed profile}. |
| 1818 | * @hide |
| 1819 | */ |
| 1820 | public static boolean isUserTypeManagedProfile(String userType) { |
| 1821 | return USER_TYPE_PROFILE_MANAGED.equals(userType); |
| 1822 | } |
| 1823 | |
| 1824 | /** |
| 1825 | * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_GUEST guest user}. |
| 1826 | * @hide |
| 1827 | */ |
| 1828 | public static boolean isUserTypeGuest(String userType) { |
| 1829 | return USER_TYPE_FULL_GUEST.equals(userType); |
| 1830 | } |
| 1831 | |
| 1832 | /** |
| 1833 | * Returns whether the user type is a |
| 1834 | * {@link UserManager#USER_TYPE_FULL_RESTRICTED restricted user}. |
| 1835 | * @hide |
| 1836 | */ |
| 1837 | public static boolean isUserTypeRestricted(String userType) { |
| 1838 | return USER_TYPE_FULL_RESTRICTED.equals(userType); |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_DEMO demo user}. |
| 1843 | * @hide |
| 1844 | */ |
| 1845 | public static boolean isUserTypeDemo(String userType) { |
| 1846 | return USER_TYPE_FULL_DEMO.equals(userType); |
| 1847 | } |
| 1848 | |
| 1849 | /** |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1850 | * @hide |
| 1851 | * @deprecated Use {@link #isRestrictedProfile()} |
| 1852 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1853 | @UnsupportedAppUsage |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1854 | @Deprecated |
| 1855 | public boolean isLinkedUser() { |
| 1856 | return isRestrictedProfile(); |
| 1857 | } |
| 1858 | |
| 1859 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1860 | * Used to check if this process is running under a restricted profile. Restricted profiles |
| 1861 | * may have a reduced number of available apps, app restrictions, and account restrictions. |
| 1862 | * |
| 1863 | * @return whether this process is running under a restricted profile. |
Amith Yamasani | 2555daf | 2013-04-25 13:39:27 -0700 | [diff] [blame] | 1864 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1865 | */ |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1866 | @SystemApi |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1867 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1868 | public boolean isRestrictedProfile() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1869 | try { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1870 | return mService.isRestricted(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1871 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1872 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1876 | /** |
Hai Zhang | 7c064ca | 2019-03-18 18:21:38 -0700 | [diff] [blame] | 1877 | * Check if a user is a restricted profile. Restricted profiles may have a reduced number of |
| 1878 | * available apps, app restrictions, and account restrictions. |
| 1879 | * |
| 1880 | * @param user the user to check |
| 1881 | * @return whether the user is a restricted profile. |
| 1882 | * @hide |
| 1883 | */ |
| 1884 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1885 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1886 | Manifest.permission.CREATE_USERS}) |
Hai Zhang | 7c064ca | 2019-03-18 18:21:38 -0700 | [diff] [blame] | 1887 | public boolean isRestrictedProfile(@NonNull UserHandle user) { |
| 1888 | try { |
| 1889 | return mService.getUserInfo(user.getIdentifier()).isRestricted(); |
| 1890 | } catch (RemoteException re) { |
| 1891 | throw re.rethrowFromSystemServer(); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | /** |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1896 | * Checks if specified user can have restricted profile. |
| 1897 | * @hide |
| 1898 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1899 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1900 | public boolean canHaveRestrictedProfile(@UserIdInt int userId) { |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1901 | try { |
| 1902 | return mService.canHaveRestrictedProfile(userId); |
| 1903 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1904 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | /** |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1909 | * Returns whether the calling user has at least one restricted profile associated with it. |
| 1910 | * @return |
| 1911 | * @hide |
| 1912 | */ |
| 1913 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1914 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1915 | public boolean hasRestrictedProfiles() { |
| 1916 | try { |
| 1917 | return mService.hasRestrictedProfiles(); |
| 1918 | } catch (RemoteException re) { |
| 1919 | throw re.rethrowFromSystemServer(); |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | /** |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1924 | * Checks if a user is a guest user. |
| 1925 | * @return whether user is a guest user. |
| 1926 | * @hide |
| 1927 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1928 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1929 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1930 | Manifest.permission.CREATE_USERS}) |
Bookatz | 07758e3 | 2019-11-19 17:16:08 -0800 | [diff] [blame] | 1931 | public boolean isGuestUser(@UserIdInt int userId) { |
| 1932 | UserInfo user = getUserInfo(userId); |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1933 | return user != null && user.isGuest(); |
| 1934 | } |
| 1935 | |
| 1936 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1937 | * Used to check if this process is running under a guest user. A guest user may be transient. |
| 1938 | * |
| 1939 | * @return whether this process is running under a guest user. |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1940 | * @hide |
| 1941 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1942 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1943 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 1944 | Manifest.permission.CREATE_USERS}) |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1945 | public boolean isGuestUser() { |
| 1946 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1947 | return user != null && user.isGuest(); |
| 1948 | } |
| 1949 | |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1950 | |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1951 | /** |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 1952 | * Checks if the calling app is running in a demo user. When running in a demo user, |
| 1953 | * apps can be more helpful to the user, or explain their features in more detail. |
| 1954 | * |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1955 | * @return whether the caller is a demo user. |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1956 | */ |
| 1957 | public boolean isDemoUser() { |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 1958 | try { |
| 1959 | return mService.isDemoUser(UserHandle.myUserId()); |
| 1960 | } catch (RemoteException re) { |
| 1961 | throw re.rethrowFromSystemServer(); |
| 1962 | } |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1966 | * Checks if the calling context user is running in a profile. |
| 1967 | * |
| 1968 | * Requires {@link android.Manifest.permission#MANAGE_USERS} or |
| 1969 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the |
| 1970 | * caller must be in the same profile group of specified user. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1971 | * |
| 1972 | * @return whether the caller is in a profile. |
| 1973 | * @hide |
| 1974 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1975 | @SystemApi |
| 1976 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 1977 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
| 1978 | @UserHandleAware |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 1979 | public boolean isProfile() { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 1980 | return isProfile(mUserId); |
| 1981 | } |
| 1982 | |
| 1983 | private boolean isProfile(@UserIdInt int userId) { |
| 1984 | if (userId == UserHandle.myUserId()) { |
| 1985 | // No need for synchronization. Once it becomes non-null, it'll be non-null forever. |
| 1986 | // Worst case we might end up calling the AIDL method multiple times but that's fine. |
| 1987 | if (mIsProfileCached != null) { |
| 1988 | return mIsProfileCached; |
| 1989 | } |
| 1990 | try { |
| 1991 | mIsProfileCached = mService.isProfile(userId); |
| 1992 | return mIsProfileCached; |
| 1993 | } catch (RemoteException re) { |
| 1994 | throw re.rethrowFromSystemServer(); |
| 1995 | } |
| 1996 | } else { |
| 1997 | try { |
| 1998 | return mService.isProfile(userId); |
| 1999 | } catch (RemoteException re) { |
| 2000 | throw re.rethrowFromSystemServer(); |
| 2001 | } |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | /** |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2006 | * Checks if the calling app is running in a managed profile. |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2007 | * |
| 2008 | * @return whether the caller is in a managed profile. |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2009 | */ |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2010 | public boolean isManagedProfile() { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 2011 | // No need for synchronization. Once it becomes non-null, it'll be non-null forever. |
| 2012 | // Worst case we might end up calling the AIDL method multiple times but that's fine. |
| 2013 | if (mIsManagedProfileCached != null) { |
| 2014 | return mIsManagedProfileCached; |
| 2015 | } |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2016 | try { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 2017 | mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId()); |
| 2018 | return mIsManagedProfileCached; |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2019 | } catch (RemoteException re) { |
| 2020 | throw re.rethrowFromSystemServer(); |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * Checks if the specified user is a managed profile. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2026 | * Requires {@link android.Manifest.permission#MANAGE_USERS} or |
| 2027 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2028 | * must be in the same profile group of specified user. |
| 2029 | * |
| 2030 | * @return whether the specified user is a managed profile. |
| 2031 | * @hide |
| 2032 | */ |
| 2033 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2034 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 2035 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2036 | public boolean isManagedProfile(@UserIdInt int userId) { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 2037 | if (userId == UserHandle.myUserId()) { |
| 2038 | return isManagedProfile(); |
| 2039 | } |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2040 | try { |
| 2041 | return mService.isManagedProfile(userId); |
| 2042 | } catch (RemoteException re) { |
| 2043 | throw re.rethrowFromSystemServer(); |
| 2044 | } |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | /** |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 2048 | * Checks if the calling app is running as an ephemeral user. |
| 2049 | * |
| 2050 | * @return whether the caller is an ephemeral user. |
| 2051 | * @hide |
| 2052 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2053 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2054 | Manifest.permission.CREATE_USERS}) |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 2055 | public boolean isEphemeralUser() { |
| 2056 | return isUserEphemeral(UserHandle.myUserId()); |
| 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * Returns whether the specified user is ephemeral. |
| 2061 | * @hide |
| 2062 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2063 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2064 | Manifest.permission.CREATE_USERS}) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2065 | public boolean isUserEphemeral(@UserIdInt int userId) { |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 2066 | final UserInfo user = getUserInfo(userId); |
| 2067 | return user != null && user.isEphemeral(); |
| 2068 | } |
| 2069 | |
| 2070 | /** |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2071 | * Return whether the given user is actively running. This means that |
| 2072 | * the user is in the "started" state, not "stopped" -- it is currently |
| 2073 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 2074 | * etc. A started user may be either the current foreground user or a |
| 2075 | * background user; the result here does not distinguish between the two. |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 2076 | * |
| 2077 | * <p>Note prior to Android Nougat MR1 (SDK version <= 24; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 2078 | * {@link android.os.Build.VERSION_CODES#N}, this API required a system permission |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 2079 | * in order to check other profile's status. |
| 2080 | * Since Android Nougat MR1 (SDK version >= 25; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 2081 | * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now |
| 2082 | * it'll accept any {@link android.os.UserHandle} within the same profile group as the caller. |
Fyodor Kupolov | cdb3c2f | 2017-02-10 11:48:32 -0800 | [diff] [blame] | 2083 | * |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2084 | * @param user The user to retrieve the running state for. |
| 2085 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2086 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2087 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2088 | public boolean isUserRunning(UserHandle user) { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 2089 | return isUserRunning(user.getIdentifier()); |
| 2090 | } |
| 2091 | |
| 2092 | /** {@hide} */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2093 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2094 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 2095 | public boolean isUserRunning(@UserIdInt int userId) { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2096 | try { |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 2097 | return mService.isUserRunning(userId); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2098 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2099 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | /** |
| 2104 | * Return whether the given user is actively running <em>or</em> stopping. |
| 2105 | * This is like {@link #isUserRunning(UserHandle)}, but will also return |
| 2106 | * true if the user had been running but is in the process of being stopped |
| 2107 | * (but is not yet fully stopped, and still running some code). |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 2108 | * |
| 2109 | * <p>Note prior to Android Nougat MR1 (SDK version <= 24; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 2110 | * {@link android.os.Build.VERSION_CODES#N}, this API required a system permission |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 2111 | * in order to check other profile's status. |
| 2112 | * Since Android Nougat MR1 (SDK version >= 25; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 2113 | * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now |
| 2114 | * it'll accept any {@link android.os.UserHandle} within the same profile group as the caller. |
Fyodor Kupolov | cdb3c2f | 2017-02-10 11:48:32 -0800 | [diff] [blame] | 2115 | * |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2116 | * @param user The user to retrieve the running state for. |
| 2117 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2118 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2119 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2120 | public boolean isUserRunningOrStopping(UserHandle user) { |
| 2121 | try { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2122 | // TODO: reconcile stopped vs stopping? |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2123 | return ActivityManager.getService().isUserRunning( |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2124 | user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2125 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2126 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2127 | } |
| 2128 | } |
| 2129 | |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 2130 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 2131 | * Return whether the calling user is running in an "unlocked" state. |
| 2132 | * <p> |
| 2133 | * On devices with direct boot, a user is unlocked only after they've |
| 2134 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 2135 | * without direct boot, a user is unlocked as soon as it starts. |
| 2136 | * <p> |
| 2137 | * When a user is locked, only device-protected data storage is available. |
| 2138 | * When a user is unlocked, both device-protected and credential-protected |
| 2139 | * private app data storage is available. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2140 | * |
| 2141 | * @see Intent#ACTION_USER_UNLOCKED |
| 2142 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 2143 | */ |
| 2144 | public boolean isUserUnlocked() { |
| 2145 | return isUserUnlocked(Process.myUserHandle()); |
| 2146 | } |
| 2147 | |
| 2148 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 2149 | * Return whether the given user is running in an "unlocked" state. |
| 2150 | * <p> |
| 2151 | * On devices with direct boot, a user is unlocked only after they've |
| 2152 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 2153 | * without direct boot, a user is unlocked as soon as it starts. |
| 2154 | * <p> |
| 2155 | * When a user is locked, only device-protected data storage is available. |
| 2156 | * When a user is unlocked, both device-protected and credential-protected |
| 2157 | * private app data storage is available. |
Fyodor Kupolov | cdb3c2f | 2017-02-10 11:48:32 -0800 | [diff] [blame] | 2158 | * <p>Requires {@code android.permission.MANAGE_USERS} or |
| 2159 | * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} |
| 2160 | * must be the calling user or a managed profile associated with it. |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 2161 | * |
| 2162 | * @param user to retrieve the unlocked state for. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2163 | * @see Intent#ACTION_USER_UNLOCKED |
| 2164 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 2165 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2166 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2167 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 2168 | public boolean isUserUnlocked(UserHandle user) { |
Jeff Sharkey | 0999c0d | 2015-12-17 15:12:22 -0700 | [diff] [blame] | 2169 | return isUserUnlocked(user.getIdentifier()); |
| 2170 | } |
| 2171 | |
| 2172 | /** {@hide} */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2173 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2174 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2175 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2176 | public boolean isUserUnlocked(@UserIdInt int userId) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 2177 | try { |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 2178 | return mService.isUserUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 2179 | } catch (RemoteException re) { |
| 2180 | throw re.rethrowFromSystemServer(); |
| 2181 | } |
| 2182 | } |
| 2183 | |
Roshan Pius | f6c8cd3 | 2019-10-17 13:03:18 -0700 | [diff] [blame] | 2184 | /** |
| 2185 | * Return whether the provided user is already running in an |
| 2186 | * "unlocked" state or in the process of unlocking. |
| 2187 | * <p> |
| 2188 | * On devices with direct boot, a user is unlocked only after they've |
| 2189 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 2190 | * without direct boot, a user is unlocked as soon as it starts. |
| 2191 | * <p> |
| 2192 | * When a user is locked, only device-protected data storage is available. |
| 2193 | * When a user is unlocked, both device-protected and credential-protected |
| 2194 | * private app data storage is available. |
| 2195 | * |
| 2196 | * <p>Requires {@code android.permission.MANAGE_USERS} or |
| 2197 | * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} |
| 2198 | * must be the calling user or a profile associated with it. |
| 2199 | * |
| 2200 | * @hide |
| 2201 | */ |
| 2202 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2203 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2204 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Roshan Pius | f6c8cd3 | 2019-10-17 13:03:18 -0700 | [diff] [blame] | 2205 | public boolean isUserUnlockingOrUnlocked(@NonNull UserHandle user) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 2206 | return isUserUnlockingOrUnlocked(user.getIdentifier()); |
| 2207 | } |
| 2208 | |
| 2209 | /** {@hide} */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2210 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2211 | Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 2212 | public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { |
| 2213 | try { |
Fyodor Kupolov | c413f70 | 2016-10-06 17:11:14 -0700 | [diff] [blame] | 2214 | return mService.isUserUnlockingOrUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 2215 | } catch (RemoteException re) { |
| 2216 | throw re.rethrowFromSystemServer(); |
| 2217 | } |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | /** |
Makoto Onuki | 73dded2 | 2017-12-20 13:14:48 +0900 | [diff] [blame] | 2221 | * Return the time when the calling user started in elapsed milliseconds since boot, |
| 2222 | * or 0 if not started. |
| 2223 | * |
| 2224 | * @hide |
| 2225 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2226 | @UnsupportedAppUsage |
Makoto Onuki | 73dded2 | 2017-12-20 13:14:48 +0900 | [diff] [blame] | 2227 | public long getUserStartRealtime() { |
| 2228 | try { |
| 2229 | return mService.getUserStartRealtime(); |
| 2230 | } catch (RemoteException re) { |
| 2231 | throw re.rethrowFromSystemServer(); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * Return the time when the calling user was unlocked elapsed milliseconds since boot, |
| 2237 | * or 0 if not unlocked. |
| 2238 | * |
| 2239 | * @hide |
| 2240 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2241 | @UnsupportedAppUsage |
Makoto Onuki | 73dded2 | 2017-12-20 13:14:48 +0900 | [diff] [blame] | 2242 | public long getUserUnlockRealtime() { |
| 2243 | try { |
| 2244 | return mService.getUserUnlockRealtime(); |
| 2245 | } catch (RemoteException re) { |
| 2246 | throw re.rethrowFromSystemServer(); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2251 | * Returns the UserInfo object describing a specific user. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2252 | * @param userId the user handle of the user whose information is being requested. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2253 | * @return the UserInfo object for a specific user. |
| 2254 | * @hide |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 2255 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2256 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2257 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2258 | Manifest.permission.CREATE_USERS}) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2259 | public UserInfo getUserInfo(@UserIdInt int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2260 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2261 | return mService.getUserInfo(userId); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2262 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2263 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2264 | } |
| 2265 | } |
| 2266 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2267 | /** |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 2268 | * @hide |
| 2269 | * |
| 2270 | * Returns who set a user restriction on a user. |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 2271 | * @param restrictionKey the string key representing the restriction |
| 2272 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2273 | * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET}, |
| 2274 | * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER} |
| 2275 | * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER} |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2276 | * @deprecated use {@link #getUserRestrictionSources(String, int)} instead. |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 2277 | */ |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2278 | @Deprecated |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 2279 | @SystemApi |
| 2280 | @UserRestrictionSource |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2281 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2282 | public int getUserRestrictionSource(@UserRestrictionKey String restrictionKey, |
| 2283 | UserHandle userHandle) { |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 2284 | try { |
| 2285 | return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier()); |
| 2286 | } catch (RemoteException re) { |
| 2287 | throw re.rethrowFromSystemServer(); |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | /** |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2292 | * @hide |
| 2293 | * |
| 2294 | * Returns a list of users who set a user restriction on a given user. |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2295 | * @param restrictionKey the string key representing the restriction |
| 2296 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2297 | * @return a list of user ids enforcing this restriction. |
| 2298 | */ |
| 2299 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2300 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2301 | public List<EnforcingUser> getUserRestrictionSources( |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2302 | @UserRestrictionKey String restrictionKey, UserHandle userHandle) { |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2303 | try { |
| 2304 | return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier()); |
| 2305 | } catch (RemoteException re) { |
| 2306 | throw re.rethrowFromSystemServer(); |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2311 | * Returns the user-wide restrictions imposed on this user. |
| 2312 | * @return a Bundle containing all the restrictions. |
| 2313 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2314 | public Bundle getUserRestrictions() { |
| 2315 | return getUserRestrictions(Process.myUserHandle()); |
| 2316 | } |
| 2317 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2318 | /** |
| 2319 | * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. |
| 2320 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2321 | * @return a Bundle containing all the restrictions. |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2322 | * |
| 2323 | * <p>Requires {@code android.permission.MANAGE_USERS} or |
| 2324 | * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} |
| 2325 | * must be the calling user or a managed profile associated with it. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2326 | */ |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2327 | @RequiresPermission(anyOf = { |
| 2328 | android.Manifest.permission.MANAGE_USERS, |
| 2329 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2330 | public Bundle getUserRestrictions(UserHandle userHandle) { |
| 2331 | try { |
| 2332 | return mService.getUserRestrictions(userHandle.getIdentifier()); |
| 2333 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2334 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 2338 | /** |
| 2339 | * @hide |
| 2340 | * Returns whether the given user has been disallowed from performing certain actions |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 2341 | * or setting certain settings through UserManager (e.g. this type of restriction would prevent |
| 2342 | * the guest user from doing certain things, such as making calls). This method disregards |
| 2343 | * restrictions set by device policy. |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 2344 | * @param restrictionKey the string key representing the restriction |
| 2345 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2346 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2347 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2348 | @RequiresPermission(Manifest.permission.MANAGE_USERS) |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2349 | public boolean hasBaseUserRestriction(@UserRestrictionKey String restrictionKey, |
| 2350 | UserHandle userHandle) { |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 2351 | try { |
| 2352 | return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); |
| 2353 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2354 | throw re.rethrowFromSystemServer(); |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2358 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 2359 | * This will no longer work. Device owners and profile owners should use |
| 2360 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2361 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 2362 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2363 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2364 | public void setUserRestrictions(Bundle restrictions) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2365 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2368 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 2369 | * This will no longer work. Device owners and profile owners should use |
| 2370 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2371 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 2372 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2373 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2374 | public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2375 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2376 | } |
| 2377 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2378 | /** |
| 2379 | * Sets the value of a specific restriction. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 2380 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2381 | * @param key the key of the restriction |
| 2382 | * @param value the value for the restriction |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2383 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 2384 | * android.content.ComponentName, String)} or |
| 2385 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 2386 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2387 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2388 | @Deprecated |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2389 | @RequiresPermission(Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2390 | public void setUserRestriction(String key, boolean value) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2391 | setUserRestriction(key, value, Process.myUserHandle()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | /** |
| 2395 | * @hide |
| 2396 | * Sets the value of a specific restriction on a specific user. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2397 | * @param key the key of the restriction |
| 2398 | * @param value the value for the restriction |
| 2399 | * @param userHandle the user whose restriction is to be changed. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2400 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 2401 | * android.content.ComponentName, String)} or |
| 2402 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 2403 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2404 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 2405 | @Deprecated |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2406 | @RequiresPermission(Manifest.permission.MANAGE_USERS) |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 2407 | public void setUserRestriction(String key, boolean value, UserHandle userHandle) { |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2408 | try { |
| 2409 | mService.setUserRestriction(key, value, userHandle.getIdentifier()); |
| 2410 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2411 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2412 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 2413 | } |
| 2414 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2415 | /** |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 2416 | * Returns whether the current user has been disallowed from performing certain actions |
| 2417 | * or setting certain settings. |
Julia Reynolds | 2b2cf72 | 2014-06-06 11:41:04 -0400 | [diff] [blame] | 2418 | * |
| 2419 | * @param restrictionKey The string key representing the restriction. |
| 2420 | * @return {@code true} if the current user has the given restriction, {@code false} otherwise. |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 2421 | */ |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2422 | public boolean hasUserRestriction(@UserRestrictionKey String restrictionKey) { |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2423 | return hasUserRestrictionForUser(restrictionKey, Process.myUserHandle()); |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * @hide |
| 2428 | * Returns whether the given user has been disallowed from performing certain actions |
| 2429 | * or setting certain settings. |
| 2430 | * @param restrictionKey the string key representing the restriction |
| 2431 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2432 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2433 | @UnsupportedAppUsage |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2434 | public boolean hasUserRestriction(@UserRestrictionKey String restrictionKey, |
| 2435 | UserHandle userHandle) { |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2436 | return hasUserRestrictionForUser(restrictionKey, userHandle); |
| 2437 | } |
| 2438 | |
| 2439 | /** |
| 2440 | * Returns whether the given user has been disallowed from performing certain actions |
| 2441 | * or setting certain settings. |
| 2442 | * @param restrictionKey the string key representing the restriction |
| 2443 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 2444 | * |
| 2445 | * <p>Requires {@code android.permission.MANAGE_USERS} or |
| 2446 | * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} |
| 2447 | * must be the calling user or a managed profile associated with it. |
| 2448 | * |
| 2449 | * @hide |
| 2450 | */ |
| 2451 | @SystemApi |
| 2452 | @RequiresPermission(anyOf = { |
| 2453 | android.Manifest.permission.MANAGE_USERS, |
| 2454 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2455 | public boolean hasUserRestrictionForUser(@NonNull @UserRestrictionKey String restrictionKey, |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2456 | @NonNull UserHandle userHandle) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 2457 | try { |
Roshan Pius | 7969c80 | 2019-10-21 19:58:57 -0700 | [diff] [blame] | 2458 | return mService.hasUserRestriction(restrictionKey, userHandle.getIdentifier()); |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 2459 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2460 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 2461 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | /** |
Makoto Onuki | acc5046 | 2018-02-14 14:13:49 -0800 | [diff] [blame] | 2465 | * @hide |
| 2466 | * Returns whether any user on the device has the given user restriction set. |
| 2467 | */ |
Roshan Pius | 3eac0b9 | 2019-12-05 09:35:36 -0800 | [diff] [blame] | 2468 | public boolean hasUserRestrictionOnAnyUser(@UserRestrictionKey String restrictionKey) { |
Makoto Onuki | acc5046 | 2018-02-14 14:13:49 -0800 | [diff] [blame] | 2469 | try { |
| 2470 | return mService.hasUserRestrictionOnAnyUser(restrictionKey); |
| 2471 | } catch (RemoteException re) { |
| 2472 | throw re.rethrowFromSystemServer(); |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | /** |
Christopher Tate | 65fb2e4 | 2019-10-11 17:00:23 -0700 | [diff] [blame] | 2477 | * @hide |
| 2478 | * |
| 2479 | * Checks whether changing the given setting to the given value is prohibited |
| 2480 | * by the corresponding user restriction in the given user. |
| 2481 | * |
| 2482 | * May only be called by the OS itself. |
| 2483 | * |
| 2484 | * @return {@code true} if the change is prohibited, {@code false} if the change is allowed. |
| 2485 | */ |
| 2486 | public boolean isSettingRestrictedForUser(String setting, @UserIdInt int userId, |
| 2487 | String value, int callingUid) { |
| 2488 | try { |
| 2489 | return mService.isSettingRestrictedForUser(setting, userId, value, callingUid); |
| 2490 | } catch (RemoteException re) { |
| 2491 | throw re.rethrowFromSystemServer(); |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * @hide |
| 2497 | * Register a binder callback for user restrictions changes. |
| 2498 | * May only be called by the OS itself. |
| 2499 | */ |
| 2500 | public void addUserRestrictionsListener(final IUserRestrictionsListener listener) { |
| 2501 | try { |
| 2502 | mService.addUserRestrictionsListener(listener); |
| 2503 | } catch (RemoteException re) { |
| 2504 | throw re.rethrowFromSystemServer(); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | /** |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2509 | * Return the serial number for a user. This is a device-unique |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 2510 | * number assigned to that user; if the user is deleted and then a new |
| 2511 | * user created, the new users will not be given the same serial number. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2512 | * @param user The user whose serial number is to be retrieved. |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 2513 | * @return The serial number of the given user; returns -1 if the |
| 2514 | * given UserHandle does not exist. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2515 | * @see #getUserForSerialNumber(long) |
| 2516 | */ |
| 2517 | public long getSerialNumberForUser(UserHandle user) { |
| 2518 | return getUserSerialNumber(user.getIdentifier()); |
| 2519 | } |
| 2520 | |
| 2521 | /** |
| 2522 | * Return the user associated with a serial number previously |
| 2523 | * returned by {@link #getSerialNumberForUser(UserHandle)}. |
| 2524 | * @param serialNumber The serial number of the user that is being |
| 2525 | * retrieved. |
| 2526 | * @return Return the user associated with the serial number, or null |
| 2527 | * if there is not one. |
| 2528 | * @see #getSerialNumberForUser(UserHandle) |
| 2529 | */ |
| 2530 | public UserHandle getUserForSerialNumber(long serialNumber) { |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 2531 | int ident = getUserHandle((int) serialNumber); |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2532 | return ident >= 0 ? new UserHandle(ident) : null; |
| 2533 | } |
| 2534 | |
| 2535 | /** |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 2536 | * Creates a user with the specified name and options. For non-admin users, default user |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2537 | * restrictions are going to be applied. |
| 2538 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2539 | * |
| 2540 | * @param name the user's name |
| 2541 | * @param flags UserInfo flags that identify the type of user and other properties. |
| 2542 | * @see UserInfo |
| 2543 | * |
| 2544 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 2545 | * @throws IllegalArgumentException if flags do not correspond to a valid user type. |
| 2546 | * @deprecated Use {@link #createUser(String, String, int)} instead. |
| 2547 | * @hide |
| 2548 | */ |
| 2549 | @UnsupportedAppUsage |
| 2550 | @Deprecated |
| 2551 | public @Nullable UserInfo createUser(@Nullable String name, @UserInfoFlag int flags) { |
| 2552 | return createUser(name, UserInfo.getDefaultUserType(flags), flags); |
| 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * Creates a user with the specified name and options. For non-admin users, default user |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2557 | * restrictions will be applied. |
| 2558 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2559 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS}. |
| 2560 | * {@link android.Manifest.permission#CREATE_USERS} suffices if flags are in |
| 2561 | * com.android.server.pm.UserManagerService#ALLOWED_FLAGS_FOR_CREATE_USERS_PERMISSION}. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2562 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2563 | * @param name the user's name |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2564 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_GUEST}. |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2565 | * @param flags UserInfo flags that specify user properties. |
| 2566 | * @return the {@link UserInfo} object for the created user, |
| 2567 | * or throws {@link UserOperationException} if the user could not be created |
| 2568 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2569 | * (otherwise returns {@code null}). |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2570 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2571 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2572 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2573 | * @hide |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2574 | * @see UserInfo |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2575 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2576 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2577 | Manifest.permission.CREATE_USERS}) |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2578 | public @Nullable UserInfo createUser(@Nullable String name, @NonNull String userType, |
| 2579 | @UserInfoFlag int flags) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2580 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2581 | return mService.createUserWithThrow(name, userType, flags); |
| 2582 | } catch (ServiceSpecificException e) { |
| 2583 | return returnNullOrThrowUserOperationException(e, |
| 2584 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2585 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2586 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2591 | * Pre-creates a user of the specified type. For non-admin users, default user |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2592 | * restrictions will be applied. |
| 2593 | * |
| 2594 | * <p>This method can be used by OEMs to "warm" up the user creation by pre-creating some users |
| 2595 | * at the first boot, so they when the "real" user is created (for example, |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2596 | * by {@link #createUser(String, String, int)} or {@link #createGuest(Context, String)}), it |
| 2597 | * takes less time. |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2598 | * |
jovanak | 8508f2f | 2019-10-28 09:56:29 -0700 | [diff] [blame] | 2599 | * <p>This method completes the majority of work necessary for user creation: it |
| 2600 | * creates user data, CE and DE encryption keys, app data directories, initializes the user and |
| 2601 | * grants default permissions. When pre-created users become "real" users, only then are |
| 2602 | * components notified of new user creation by firing user creation broadcasts. |
| 2603 | * |
| 2604 | * <p>All pre-created users are removed during system upgrade. |
| 2605 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2606 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS}. |
| 2607 | * {@link android.Manifest.permission#CREATE_USERS} suffices if flags are in |
| 2608 | * com.android.server.pm.UserManagerService#ALLOWED_FLAGS_FOR_CREATE_USERS_PERMISSION}. |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2609 | * |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2610 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_GUEST}. |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2611 | * @return the {@link UserInfo} object for the created user, |
| 2612 | * or throws {@link UserOperationException} if the user could not be created |
| 2613 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2614 | * (otherwise returns {@code null}). |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2615 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2616 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2617 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2618 | * |
| 2619 | * @hide |
| 2620 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2621 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2622 | Manifest.permission.CREATE_USERS}) |
| 2623 | public @Nullable UserInfo preCreateUser(@NonNull String userType) |
| 2624 | throws UserOperationException { |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2625 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2626 | return mService.preCreateUserWithThrow(userType); |
| 2627 | } catch (ServiceSpecificException e) { |
| 2628 | return returnNullOrThrowUserOperationException(e, |
| 2629 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Felipe Leme | c1ca441 | 2019-09-11 09:23:26 -0700 | [diff] [blame] | 2630 | } catch (RemoteException re) { |
| 2631 | throw re.rethrowFromSystemServer(); |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 2636 | * Creates a guest user and configures it. |
| 2637 | * @param context an application context |
| 2638 | * @param name the name to set for the user |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2639 | * @return the {@link UserInfo} object for the created user, |
| 2640 | * or throws {@link UserOperationException} if the user could not be created |
| 2641 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2642 | * (otherwise returns {@code null}). |
| 2643 | * |
| 2644 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2645 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 2646 | * @hide |
| 2647 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2648 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2649 | Manifest.permission.CREATE_USERS}) |
| 2650 | public UserInfo createGuest(Context context, String name) throws UserOperationException { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2651 | UserInfo guest = null; |
| 2652 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2653 | guest = mService.createUserWithThrow(name, USER_TYPE_FULL_GUEST, 0); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2654 | if (guest != null) { |
| 2655 | Settings.Secure.putStringForUser(context.getContentResolver(), |
| 2656 | Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2657 | } |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2658 | } catch (ServiceSpecificException e) { |
| 2659 | return returnNullOrThrowUserOperationException(e, |
| 2660 | context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 2661 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2662 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 2663 | } |
| 2664 | return guest; |
| 2665 | } |
| 2666 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 2667 | /** |
Anthony Hugh | 5d7f905 | 2019-11-13 16:48:28 -0800 | [diff] [blame] | 2668 | * Gets the existing guest user if it exists. This does not include guest users that are dying. |
| 2669 | * @return The existing guest user if it exists. Null otherwise. |
| 2670 | * @hide |
| 2671 | */ |
| 2672 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 2673 | public UserInfo findCurrentGuestUser() { |
| 2674 | try { |
| 2675 | return mService.findCurrentGuestUser(); |
| 2676 | } catch (RemoteException re) { |
| 2677 | throw re.rethrowFromSystemServer(); |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2682 | * Creates a user with the specified name and options as a profile of the context's user. |
| 2683 | * |
| 2684 | * @param name the user's name. |
| 2685 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}. |
| 2686 | * @param disallowedPackages packages to not install for this profile. |
| 2687 | * |
| 2688 | * @return the {@link android.os.UserHandle} object for the created user, |
| 2689 | * or throws {@link UserOperationException} if the user could not be created |
| 2690 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2691 | * (otherwise returns {@code null}). |
| 2692 | * |
| 2693 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2694 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
| 2695 | * |
| 2696 | * @hide |
| 2697 | */ |
| 2698 | @SystemApi |
| 2699 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2700 | Manifest.permission.CREATE_USERS}) |
| 2701 | @UserHandleAware |
| 2702 | public @Nullable UserHandle createProfile(@NonNull String name, @NonNull String userType, |
| 2703 | @Nullable String[] disallowedPackages) throws UserOperationException { |
| 2704 | try { |
| 2705 | return mService.createProfileForUserWithThrow(name, userType, 0, |
| 2706 | mUserId, disallowedPackages).getUserHandle(); |
| 2707 | } catch (ServiceSpecificException e) { |
| 2708 | return returnNullOrThrowUserOperationException(e, |
| 2709 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
| 2710 | } catch (RemoteException re) { |
| 2711 | throw re.rethrowFromSystemServer(); |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 2716 | * Creates a user with the specified name and options as a profile of another user. |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2717 | * <p>Requires MANAGE_USERS. CREATE_USERS suffices for ALLOWED_FLAGS_FOR_CREATE_USERS_PERMISSION |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2718 | * |
| 2719 | * @param name the user's name |
| 2720 | * @param flags flags that identify the type of user and other properties. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2721 | * @param userId new user will be a profile of this user. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2722 | * |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 2723 | * @return the {@link UserInfo} object for the created user, or null if the user |
| 2724 | * could not be created. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2725 | * @throws IllegalArgumentException if flags do not correspond to a valid user type. |
| 2726 | * @deprecated Use {@link #createProfileForUser(String, String, int, int)} instead. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2727 | * @hide |
| 2728 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2729 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2730 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2731 | Manifest.permission.CREATE_USERS}) |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2732 | @Deprecated |
| 2733 | public UserInfo createProfileForUser(String name, @UserInfoFlag int flags, |
| 2734 | @UserIdInt int userId) { |
| 2735 | return createProfileForUser(name, UserInfo.getDefaultUserType(flags), flags, |
| 2736 | userId, null); |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2740 | * Creates a user with the specified name and options as a profile of another user. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2741 | * |
| 2742 | * @param name the user's name |
| 2743 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}. |
| 2744 | * @param flags UserInfo flags that specify user properties. |
| 2745 | * @param userId new user will be a profile of this user. |
| 2746 | * |
| 2747 | * @return the {@link UserInfo} object for the created user, or null if the user |
| 2748 | * could not be created. |
| 2749 | * @hide |
| 2750 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2751 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2752 | Manifest.permission.CREATE_USERS}) |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2753 | public UserInfo createProfileForUser(String name, @NonNull String userType, |
| 2754 | @UserInfoFlag int flags, @UserIdInt int userId) { |
| 2755 | return createProfileForUser(name, userType, flags, userId, null); |
| 2756 | } |
| 2757 | |
| 2758 | /** |
| 2759 | * Version of {@link #createProfileForUser(String, String, int, int)} that allows you to specify |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 2760 | * any packages that should not be installed in the new profile by default, these packages can |
| 2761 | * still be installed later by the user if needed. |
| 2762 | * |
| 2763 | * @param name the user's name |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2764 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}. |
| 2765 | * @param flags UserInfo flags that specify user properties. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2766 | * @param userId new user will be a profile of this user. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 2767 | * @param disallowedPackages packages that will not be installed in the profile being created. |
| 2768 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2769 | * @return the {@link UserInfo} object for the created user, |
| 2770 | * or throws {@link UserOperationException} if the user could not be created |
| 2771 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2772 | * (otherwise returns {@code null}). |
| 2773 | * |
| 2774 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2775 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 2776 | * @hide |
| 2777 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2778 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2779 | Manifest.permission.CREATE_USERS}) |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2780 | public UserInfo createProfileForUser(String name, @NonNull String userType, |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2781 | @UserInfoFlag int flags, @UserIdInt int userId, String[] disallowedPackages) |
| 2782 | throws UserOperationException { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2783 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2784 | return mService.createProfileForUserWithThrow(name, userType, flags, userId, |
| 2785 | disallowedPackages); |
| 2786 | } catch (ServiceSpecificException e) { |
| 2787 | return returnNullOrThrowUserOperationException(e, |
| 2788 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2789 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2790 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2795 | * Similar to {@link #createProfileForUser(String, String, int, int, String[])} |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 2796 | * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 2797 | * |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2798 | * @see #createProfileForUser(String, String, int, int, String[]) |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 2799 | * @hide |
| 2800 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2801 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2802 | Manifest.permission.CREATE_USERS}) |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2803 | public UserInfo createProfileForUserEvenWhenDisallowed(String name, |
| 2804 | @NonNull String userType, @UserInfoFlag int flags, @UserIdInt int userId, |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2805 | String[] disallowedPackages) throws UserOperationException { |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 2806 | try { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2807 | return mService.createProfileForUserEvenWhenDisallowedWithThrow(name, userType, flags, |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 2808 | userId, disallowedPackages); |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2809 | } catch (ServiceSpecificException e) { |
| 2810 | return returnNullOrThrowUserOperationException(e, |
| 2811 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 2812 | } catch (RemoteException re) { |
| 2813 | throw re.rethrowFromSystemServer(); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | /** |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 2818 | * Creates a restricted profile with the specified name. This method also sets necessary |
| 2819 | * restrictions and adds shared accounts. |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2820 | * |
| 2821 | * @param name profile's name |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2822 | * @return the {@link UserInfo} object for the created user, |
| 2823 | * or throws {@link UserOperationException} if the user could not be created |
| 2824 | * and calling app is targeting {@link android.os.Build.VERSION_CODES#R} or above |
| 2825 | * (otherwise returns {@code null}). |
| 2826 | * |
| 2827 | * @throws UserOperationException if the user could not be created and the calling app is |
| 2828 | * targeting {@link android.os.Build.VERSION_CODES#R} or above. |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2829 | * @hide |
| 2830 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2831 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2832 | Manifest.permission.CREATE_USERS}) |
| 2833 | public UserInfo createRestrictedProfile(String name) throws UserOperationException { |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2834 | try { |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 2835 | UserHandle parentUserHandle = Process.myUserHandle(); |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2836 | UserInfo user = mService.createRestrictedProfileWithThrow(name, |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 2837 | parentUserHandle.getIdentifier()); |
| 2838 | if (user != null) { |
| 2839 | AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, |
| 2840 | UserHandle.of(user.id)); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2841 | } |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 2842 | return user; |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2843 | } catch (ServiceSpecificException e) { |
| 2844 | return returnNullOrThrowUserOperationException(e, |
| 2845 | mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2846 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2847 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2848 | } |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2852 | * Returns an intent to create a user for the provided name and account name. The name |
| 2853 | * and account name will be used when the setup process for the new user is started. |
| 2854 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2855 | * The intent should be launched using startActivityForResult and the return result will |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 2856 | * indicate if the user consented to adding a new user and if the operation succeeded. Any |
| 2857 | * errors in creating the user will be returned in the result code. If the user cancels the |
| 2858 | * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the |
| 2859 | * result code will be {@link Activity#RESULT_OK}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2860 | * <p> |
| 2861 | * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation |
| 2862 | * at all. |
| 2863 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2864 | * The new user is created but not initialized. After switching into the user for the first |
| 2865 | * time, the preferred user name and account information are used by the setup process for that |
| 2866 | * user. |
| 2867 | * |
| 2868 | * @param userName Optional name to assign to the user. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2869 | * @param accountName Optional account name that will be used by the setup wizard to initialize |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2870 | * the user. |
| 2871 | * @param accountType Optional account type for the account to be created. This is required |
| 2872 | * if the account name is specified. |
| 2873 | * @param accountOptions Optional bundle of data to be passed in during account creation in the |
| 2874 | * new user via {@link AccountManager#addAccount(String, String, String[], |
| 2875 | * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, |
| 2876 | * Handler)}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2877 | * @return An Intent that can be launched from an Activity. |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 2878 | * @see #USER_CREATION_FAILED_NOT_PERMITTED |
| 2879 | * @see #USER_CREATION_FAILED_NO_MORE_USERS |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2880 | * @see #supportsMultipleUsers |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2881 | */ |
| 2882 | public static Intent createUserCreationIntent(@Nullable String userName, |
| 2883 | @Nullable String accountName, |
| 2884 | @Nullable String accountType, @Nullable PersistableBundle accountOptions) { |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2885 | Intent intent = new Intent(ACTION_CREATE_USER); |
| 2886 | if (userName != null) { |
| 2887 | intent.putExtra(EXTRA_USER_NAME, userName); |
| 2888 | } |
| 2889 | if (accountName != null && accountType == null) { |
| 2890 | throw new IllegalArgumentException("accountType must be specified if accountName is " |
| 2891 | + "specified"); |
| 2892 | } |
| 2893 | if (accountName != null) { |
| 2894 | intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); |
| 2895 | } |
| 2896 | if (accountType != null) { |
| 2897 | intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); |
| 2898 | } |
| 2899 | if (accountOptions != null) { |
| 2900 | intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); |
| 2901 | } |
| 2902 | return intent; |
| 2903 | } |
| 2904 | |
| 2905 | /** |
| 2906 | * @hide |
| 2907 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2908 | * Returns the preferred account name for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2909 | */ |
| 2910 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2911 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2912 | public String getSeedAccountName() { |
| 2913 | try { |
| 2914 | return mService.getSeedAccountName(); |
| 2915 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2916 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | /** |
| 2921 | * @hide |
| 2922 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2923 | * Returns the preferred account type for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2924 | */ |
| 2925 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2926 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2927 | public String getSeedAccountType() { |
| 2928 | try { |
| 2929 | return mService.getSeedAccountType(); |
| 2930 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2931 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | /** |
| 2936 | * @hide |
| 2937 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2938 | * Returns the preferred account's options bundle for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2939 | * @return Any options set by the requestor that created the user. |
| 2940 | */ |
| 2941 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2942 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2943 | public PersistableBundle getSeedAccountOptions() { |
| 2944 | try { |
| 2945 | return mService.getSeedAccountOptions(); |
| 2946 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2947 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | /** |
| 2952 | * @hide |
| 2953 | * |
| 2954 | * Called by a system activity to set the seed account information of a user created |
| 2955 | * through the user creation intent. |
| 2956 | * @param userId |
| 2957 | * @param accountName |
| 2958 | * @param accountType |
| 2959 | * @param accountOptions |
| 2960 | * @see #createUserCreationIntent(String, String, String, PersistableBundle) |
| 2961 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2962 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2963 | public void setSeedAccountData(int userId, String accountName, String accountType, |
| 2964 | PersistableBundle accountOptions) { |
| 2965 | try { |
| 2966 | mService.setSeedAccountData(userId, accountName, accountType, accountOptions, |
| 2967 | /* persist= */ true); |
| 2968 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2969 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | /** |
| 2974 | * @hide |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2975 | * Clears the seed information used to create this user. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2976 | */ |
| 2977 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2978 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2979 | public void clearSeedAccountData() { |
| 2980 | try { |
| 2981 | mService.clearSeedAccountData(); |
| 2982 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2983 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | /** |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2988 | * @hide |
| 2989 | * Marks the guest user for deletion to allow a new guest to be created before deleting |
| 2990 | * the current user who is a guest. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2991 | * @param userId |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2992 | * @return |
| 2993 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 2994 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2995 | public boolean markGuestForDeletion(@UserIdInt int userId) { |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2996 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 2997 | return mService.markGuestForDeletion(userId); |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2998 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2999 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | /** |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3004 | * Sets the user as enabled, if such an user exists. |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 3005 | * |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 3006 | * <p>Note that the default is true, it's only that managed profiles might not be enabled. |
| 3007 | * Also ephemeral users can be disabled to indicate that their removal is in progress and they |
| 3008 | * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled. |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3009 | * |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3010 | * @param userId the id of the profile to enable |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3011 | * @hide |
| 3012 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3013 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3014 | public void setUserEnabled(@UserIdInt int userId) { |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3015 | try { |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3016 | mService.setUserEnabled(userId); |
| 3017 | } catch (RemoteException re) { |
| 3018 | throw re.rethrowFromSystemServer(); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | /** |
| 3023 | * Assigns admin privileges to the user, if such a user exists. |
| 3024 | * |
Bookatz | d15b2f7 | 2019-11-26 16:58:57 -0800 | [diff] [blame] | 3025 | * <p>Note that this does not alter the user's pre-existing user restrictions. |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3026 | * |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3027 | * @param userId the id of the user to become admin |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3028 | * @hide |
| 3029 | */ |
| 3030 | @RequiresPermission(allOf = { |
| 3031 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 3032 | Manifest.permission.MANAGE_USERS |
| 3033 | }) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3034 | public void setUserAdmin(@UserIdInt int userId) { |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 3035 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3036 | mService.setUserAdmin(userId); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 3037 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3038 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3043 | * Evicts the user's credential encryption key from memory by stopping and restarting the user. |
| 3044 | * |
| 3045 | * @hide |
| 3046 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3047 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3048 | public void evictCredentialEncryptionKey(@UserIdInt int userId) { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3049 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3050 | mService.evictCredentialEncryptionKey(userId); |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 3051 | } catch (RemoteException re) { |
| 3052 | throw re.rethrowFromSystemServer(); |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | /** |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 3057 | * Return the number of users currently created on the device. |
Kevin Hufnagle | 5813a8c | 2019-09-30 16:25:02 +0000 | [diff] [blame] | 3058 | * <p>This API is not for use by third-party apps. It requires the {@code MANAGE_USERS} |
| 3059 | * permission.</p> |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 3060 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3061 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 3062 | public int getUserCount() { |
| 3063 | List<UserInfo> users = getUsers(); |
| 3064 | return users != null ? users.size() : 1; |
| 3065 | } |
| 3066 | |
| 3067 | /** |
Amith Yamasani | d04aaa3 | 2016-06-13 12:09:36 -0700 | [diff] [blame] | 3068 | * Returns information for all users on this device, including ones marked for deletion. |
| 3069 | * To retrieve only users that are alive, use {@link #getUsers(boolean)}. |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3070 | * |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3071 | * @return the list of users that exist on the device. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3072 | * @hide |
| 3073 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3074 | @UnsupportedAppUsage |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3075 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3076 | public List<UserInfo> getUsers() { |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3077 | return getUsers(/* excludeDying= */ false); |
| 3078 | } |
| 3079 | |
| 3080 | /** |
Jeffrey Huang | 91027f8 | 2019-11-26 10:34:28 -0800 | [diff] [blame] | 3081 | * Returns information for all users on this device. Requires |
| 3082 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 3083 | * |
| 3084 | * @param excludeDying specify if the list should exclude users being |
| 3085 | * removed. |
| 3086 | * @return the list of users that were created. |
| 3087 | * @hide |
| 3088 | */ |
| 3089 | @UnsupportedAppUsage |
| 3090 | public @NonNull List<UserInfo> getUsers(boolean excludeDying) { |
| 3091 | return getUsers(/*excludePartial= */ true, excludeDying, |
| 3092 | /* excludePreCreated= */ true); |
| 3093 | } |
| 3094 | |
| 3095 | /** |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3096 | * Returns information for all users on this device, based on the filtering parameters. |
| 3097 | * |
| 3098 | * @hide |
| 3099 | */ |
| 3100 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3101 | public List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, |
| 3102 | boolean excludePreCreated) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3103 | try { |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3104 | return mService.getUsers(excludePartial, excludeDying, excludePreCreated); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 3105 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3106 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | /** |
Jeffrey Huang | 91027f8 | 2019-11-26 10:34:28 -0800 | [diff] [blame] | 3111 | * Returns the user handles for all users on this device, based on the filtering parameters. |
| 3112 | * |
| 3113 | * @param excludeDying specify if the list should exclude users being removed. |
| 3114 | * @return the list of user handles. |
| 3115 | * @hide |
| 3116 | */ |
| 3117 | @SystemApi |
| 3118 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3119 | public @NonNull List<UserHandle> getUserHandles(boolean excludeDying) { |
| 3120 | List<UserInfo> users = getUsers(excludeDying); |
| 3121 | List<UserHandle> result = new ArrayList<>(users.size()); |
| 3122 | for (UserInfo user : users) { |
| 3123 | result.add(user.getUserHandle()); |
| 3124 | } |
| 3125 | return result; |
| 3126 | } |
| 3127 | |
| 3128 | /** |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3129 | * Returns serial numbers of all users on this device. |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3130 | * |
| 3131 | * @param excludeDying specify if the list should exclude users being removed. |
| 3132 | * @return the list of serial numbers of users that exist on the device. |
| 3133 | * @hide |
| 3134 | */ |
| 3135 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 3136 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3137 | public long[] getSerialNumbersOfUsers(boolean excludeDying) { |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3138 | List<UserInfo> users = getUsers(excludeDying); |
| 3139 | long[] result = new long[users.size()]; |
| 3140 | for (int i = 0; i < result.length; i++) { |
| 3141 | result[i] = users.get(i).serialNumber; |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3142 | } |
Felipe Leme | 09a7f2d | 2019-10-02 16:27:46 -0700 | [diff] [blame] | 3143 | return result; |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | /** |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3147 | * @return the user's account name, null if not found. |
| 3148 | * @hide |
| 3149 | */ |
| 3150 | @RequiresPermission( allOf = { |
| 3151 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 3152 | Manifest.permission.MANAGE_USERS |
| 3153 | }) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3154 | public @Nullable String getUserAccount(@UserIdInt int userId) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3155 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3156 | return mService.getUserAccount(userId); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3157 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3158 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | |
| 3162 | /** |
| 3163 | * Set account name for the given user. |
| 3164 | * @hide |
| 3165 | */ |
| 3166 | @RequiresPermission( allOf = { |
| 3167 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 3168 | Manifest.permission.MANAGE_USERS |
| 3169 | }) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3170 | public void setUserAccount(@UserIdInt int userId, @Nullable String accountName) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3171 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3172 | mService.setUserAccount(userId, accountName); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3173 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3174 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 3179 | * Returns information for Primary user. |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 3180 | * |
| 3181 | * @return the Primary user, null if not found. |
| 3182 | * @hide |
| 3183 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3184 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 3185 | public @Nullable UserInfo getPrimaryUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 3186 | try { |
| 3187 | return mService.getPrimaryUser(); |
| 3188 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3189 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | /** |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 3194 | * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS |
| 3195 | * permission. |
| 3196 | * |
| 3197 | * @return true if more users can be added, false if limit has been reached. |
| 3198 | * @hide |
| 3199 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3200 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 3201 | public boolean canAddMoreUsers() { |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3202 | // TODO(b/142482943): UMS has different logic, excluding Demo and Profile from counting. Why |
| 3203 | // not here? The logic is inconsistent. See UMS.canAddMoreManagedProfiles |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 3204 | final List<UserInfo> users = getUsers(true); |
| 3205 | final int totalUserCount = users.size(); |
| 3206 | int aliveUserCount = 0; |
| 3207 | for (int i = 0; i < totalUserCount; i++) { |
| 3208 | UserInfo user = users.get(i); |
| 3209 | if (!user.isGuest()) { |
| 3210 | aliveUserCount++; |
| 3211 | } |
| 3212 | } |
| 3213 | return aliveUserCount < getMaxSupportedUsers(); |
| 3214 | } |
| 3215 | |
| 3216 | /** |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 3217 | * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS |
| 3218 | * permission. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 3219 | * if allowedToRemoveOne is true and if the user already has a managed profile, then return if |
| 3220 | * we could add a new managed profile to this user after removing the existing one. |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 3221 | * |
| 3222 | * @return true if more managed profiles can be added, false if limit has been reached. |
| 3223 | * @hide |
| 3224 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3225 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3226 | public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 3227 | try { |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 3228 | return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 3229 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3230 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3235 | * Checks whether it's possible to add more profiles of the given type to the given user. |
| 3236 | * |
| 3237 | * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}. |
| 3238 | * @return true if more profiles can be added, false if limit has been reached. |
| 3239 | * @hide |
| 3240 | */ |
| 3241 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3242 | public boolean canAddMoreProfilesToUser(@NonNull String userType, @UserIdInt int userId) { |
| 3243 | try { |
| 3244 | return mService.canAddMoreProfilesToUser(userType, userId, false); |
| 3245 | } catch (RemoteException re) { |
| 3246 | throw re.rethrowFromSystemServer(); |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | /** |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3251 | * Returns list of the profiles of userId including userId itself. |
Amith Yamasani | 4f7e2e3 | 2014-08-14 18:49:48 -0700 | [diff] [blame] | 3252 | * Note that this returns both enabled and not enabled profiles. See |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3253 | * {@link #getEnabledProfiles(int)} if you need only the enabled ones. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 3254 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3255 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS}. |
| 3256 | * {@link android.Manifest.permission#CREATE_USERS} suffices if userId is the calling user. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3257 | * @param userId profiles of this user will be returned. |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 3258 | * @return the list of profiles. |
| 3259 | * @hide |
| 3260 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3261 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3262 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3263 | Manifest.permission.CREATE_USERS}, conditional = true) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3264 | public List<UserInfo> getProfiles(@UserIdInt int userId) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 3265 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3266 | return mService.getProfiles(userId, false /* enabledOnly */); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 3267 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3268 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | /** |
Roshan Pius | f6c8cd3 | 2019-10-17 13:03:18 -0700 | [diff] [blame] | 3273 | * Checks if the 2 provided user handles belong to the same profile group. |
| 3274 | * |
| 3275 | * @param user one of the two user handles to check. |
| 3276 | * @param otherUser one of the two user handles to check. |
| 3277 | * @return true if the two users are in the same profile group. |
| 3278 | * |
Roshan Pius | f6c8cd3 | 2019-10-17 13:03:18 -0700 | [diff] [blame] | 3279 | * @hide |
| 3280 | */ |
| 3281 | @SystemApi |
| 3282 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3283 | public boolean isSameProfileGroup(@NonNull UserHandle user, @NonNull UserHandle otherUser) { |
| 3284 | return isSameProfileGroup(user.getIdentifier(), otherUser.getIdentifier()); |
| 3285 | } |
| 3286 | |
| 3287 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3288 | * Checks if the 2 provided user ids belong to the same profile group. |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 3289 | * @param userId one of the two user ids to check. |
| 3290 | * @param otherUserId one of the two user ids to check. |
| 3291 | * @return true if the two user ids are in the same profile group. |
| 3292 | * @hide |
| 3293 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3294 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3295 | public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 3296 | try { |
| 3297 | return mService.isSameProfileGroup(userId, otherUserId); |
| 3298 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3299 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | /** |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3304 | * Returns list of the profiles of userId including userId itself. |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3305 | * Note that this returns only enabled. |
| 3306 | * |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3307 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS}. |
| 3308 | * {@link android.Manifest.permission#CREATE_USERS} suffices if userId is the calling user. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3309 | * @param userId profiles of this user will be returned. |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3310 | * @return the list of profiles. |
| 3311 | * @hide |
| 3312 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3313 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3314 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3315 | Manifest.permission.CREATE_USERS}, conditional = true) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3316 | public List<UserInfo> getEnabledProfiles(@UserIdInt int userId) { |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3317 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3318 | return mService.getProfiles(userId, true /* enabledOnly */); |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3319 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3320 | throw re.rethrowFromSystemServer(); |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 3325 | * Returns a list of UserHandles for profiles associated with the user that the calling process |
| 3326 | * is running on, including the user itself. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 3327 | * |
| 3328 | * @return A non-empty list of UserHandles associated with the calling user. |
| 3329 | */ |
| 3330 | public List<UserHandle> getUserProfiles() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3331 | int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); |
| 3332 | List<UserHandle> result = new ArrayList<>(userIds.length); |
| 3333 | for (int userId : userIds) { |
| 3334 | result.add(UserHandle.of(userId)); |
| 3335 | } |
| 3336 | return result; |
| 3337 | } |
| 3338 | |
| 3339 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3340 | * Returns a list of ids for profiles associated with the context user including the user |
| 3341 | * itself. |
| 3342 | * |
| 3343 | * @param enabledOnly whether to return only {@link UserInfo#isEnabled() enabled} profiles |
| 3344 | * @return A non-empty list of UserHandles associated with the calling user. |
| 3345 | * |
| 3346 | * @hide |
| 3347 | */ |
| 3348 | @SystemApi |
| 3349 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3350 | Manifest.permission.CREATE_USERS}, conditional = true) |
| 3351 | @UserHandleAware |
| 3352 | public @NonNull List<UserHandle> getUserProfiles(boolean enabledOnly) { |
| 3353 | final int[] userIds = getProfileIds(mUserId, enabledOnly); |
| 3354 | final List<UserHandle> result = new ArrayList<>(userIds.length); |
| 3355 | for (int userId : userIds) { |
| 3356 | result.add(UserHandle.of(userId)); |
| 3357 | } |
| 3358 | return result; |
| 3359 | } |
| 3360 | |
| 3361 | /** |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3362 | * Returns a list of ids for profiles associated with the specified user including the user |
| 3363 | * itself. |
| 3364 | * |
| 3365 | * @param userId id of the user to return profiles for |
| 3366 | * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles |
| 3367 | * @return A non-empty list of ids of profiles associated with the specified user. |
| 3368 | * |
| 3369 | * @hide |
| 3370 | */ |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 3371 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3372 | Manifest.permission.CREATE_USERS}, conditional = true) |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 3373 | public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 3374 | try { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3375 | return mService.getProfileIds(userId, enabledOnly); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 3376 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3377 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 3378 | } |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | /** |
| 3382 | * @see #getProfileIds(int, boolean) |
| 3383 | * @hide |
| 3384 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3385 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3386 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3387 | Manifest.permission.CREATE_USERS}, conditional = true) |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3388 | public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { |
| 3389 | return getProfileIds(userId, false /* enabledOnly */); |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * @see #getProfileIds(int, boolean) |
| 3394 | * @hide |
| 3395 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3396 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3397 | Manifest.permission.CREATE_USERS}, conditional = true) |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3398 | public int[] getEnabledProfileIds(@UserIdInt int userId) { |
| 3399 | return getProfileIds(userId, true /* enabledOnly */); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 3402 | /** |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 3403 | * Returns the device credential owner id of the profile from |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3404 | * which this method is called, or userId if called from a user that |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 3405 | * is not a profile. |
| 3406 | * |
| 3407 | * @hide |
| 3408 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3409 | @RequiresPermission(Manifest.permission.MANAGE_USERS) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3410 | public int getCredentialOwnerProfile(@UserIdInt int userId) { |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 3411 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3412 | return mService.getCredentialOwnerProfile(userId); |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 3413 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3414 | throw re.rethrowFromSystemServer(); |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 3419 | * Returns the parent of the profile which this method is called from |
| 3420 | * or null if called from a user that is not a profile. |
| 3421 | * |
| 3422 | * @hide |
| 3423 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3424 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3425 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3426 | public UserInfo getProfileParent(@UserIdInt int userId) { |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 3427 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3428 | return mService.getProfileParent(userId); |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 3429 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3430 | throw re.rethrowFromSystemServer(); |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | /** |
Philip P. Moltmann | a3e358c | 2018-11-21 12:45:50 -0800 | [diff] [blame] | 3435 | * Get the parent of a user profile. |
| 3436 | * |
| 3437 | * @param user the handle of the user profile |
| 3438 | * |
| 3439 | * @return the parent of the user or {@code null} if the user is not profile |
| 3440 | * |
| 3441 | * @hide |
| 3442 | */ |
| 3443 | @SystemApi |
| 3444 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3445 | public @Nullable UserHandle getProfileParent(@NonNull UserHandle user) { |
| 3446 | UserInfo info = getProfileParent(user.getIdentifier()); |
| 3447 | |
| 3448 | if (info == null) { |
| 3449 | return null; |
| 3450 | } |
| 3451 | |
| 3452 | return UserHandle.of(info.id); |
| 3453 | } |
| 3454 | |
| 3455 | /** |
Tony Mak | e3d1f65 | 2017-12-12 11:00:37 +0000 | [diff] [blame] | 3456 | * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a |
| 3457 | * managed profile don't run, generate notifications, or consume data or battery. |
| 3458 | * <p> |
| 3459 | * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be |
| 3460 | * shown to the user. |
| 3461 | * <p> |
| 3462 | * The change may not happen instantly, however apps can listen for |
| 3463 | * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and |
| 3464 | * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of |
| 3465 | * the change of the quiet mode. Apps can also check the current state of quiet mode by |
| 3466 | * calling {@link #isQuietModeEnabled(UserHandle)}. |
| 3467 | * <p> |
| 3468 | * The caller must either be the foreground default launcher or have one of these permissions: |
| 3469 | * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}. |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3470 | * |
Tony Mak | e3d1f65 | 2017-12-12 11:00:37 +0000 | [diff] [blame] | 3471 | * @param enableQuietMode whether quiet mode should be enabled or disabled |
| 3472 | * @param userHandle user handle of the profile |
| 3473 | * @return {@code false} if user's credential is needed in order to turn off quiet mode, |
| 3474 | * {@code true} otherwise |
| 3475 | * @throws SecurityException if the caller is invalid |
| 3476 | * @throws IllegalArgumentException if {@code userHandle} is not a managed profile |
| 3477 | * |
| 3478 | * @see #isQuietModeEnabled(UserHandle) |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3479 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3480 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 3481 | Manifest.permission.MODIFY_QUIET_MODE}, conditional = true) |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 3482 | public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) { |
| 3483 | return requestQuietModeEnabled(enableQuietMode, userHandle, null); |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | /** |
Pierre Barbier de Reuille | 17eaf74 | 2020-01-10 17:49:45 +0000 | [diff] [blame] | 3487 | * Perform the same operation as {@link #requestQuietModeEnabled(boolean, UserHandle)}, but |
| 3488 | * with a flag to tweak the behavior of the request. |
| 3489 | * |
| 3490 | * @param enableQuietMode whether quiet mode should be enabled or disabled |
| 3491 | * @param userHandle user handle of the profile |
| 3492 | * @param flags Can be 0 or {@link #QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED}. |
| 3493 | * @return {@code false} if user's credential is needed in order to turn off quiet mode, |
| 3494 | * {@code true} otherwise |
| 3495 | * @throws SecurityException if the caller is invalid |
| 3496 | * @throws IllegalArgumentException if {@code userHandle} is not a managed profile |
| 3497 | * |
| 3498 | * @see #isQuietModeEnabled(UserHandle) |
| 3499 | */ |
| 3500 | public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle, |
| 3501 | @QuietModeFlag int flags) { |
| 3502 | return requestQuietModeEnabled(enableQuietMode, userHandle, null, flags); |
| 3503 | } |
| 3504 | |
| 3505 | /** |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 3506 | * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify |
Tony Mak | d390ae9 | 2017-12-28 13:23:10 +0000 | [diff] [blame] | 3507 | * a target to start when user is unlocked. If {@code target} is specified, caller must have |
| 3508 | * the {@link android.Manifest.permission#MANAGE_USERS} permission. |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 3509 | * |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 3510 | * @see {@link #requestQuietModeEnabled(boolean, UserHandle)} |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3511 | * @hide |
| 3512 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3513 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 3514 | public boolean requestQuietModeEnabled( |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 3515 | boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) { |
Pierre Barbier de Reuille | 17eaf74 | 2020-01-10 17:49:45 +0000 | [diff] [blame] | 3516 | return requestQuietModeEnabled(enableQuietMode, userHandle, target, 0); |
| 3517 | } |
| 3518 | /** |
| 3519 | * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify |
| 3520 | * a target to start when user is unlocked. If {@code target} is specified, caller must have |
| 3521 | * the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 3522 | * |
| 3523 | * @see {@link #requestQuietModeEnabled(boolean, UserHandle)} |
| 3524 | * @hide |
| 3525 | */ |
| 3526 | public boolean requestQuietModeEnabled( |
| 3527 | boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target, |
| 3528 | int flags) { |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3529 | try { |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 3530 | return mService.requestQuietModeEnabled( |
Pierre Barbier de Reuille | 17eaf74 | 2020-01-10 17:49:45 +0000 | [diff] [blame] | 3531 | mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target, |
| 3532 | flags); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 3533 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3534 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * Returns whether the given profile is in quiet mode or not. |
Ricky Wai | 7881cf8 | 2016-04-15 17:20:12 +0100 | [diff] [blame] | 3540 | * Notes: Quiet mode is only supported for managed profiles. |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3541 | * |
| 3542 | * @param userHandle The user handle of the profile to be queried. |
| 3543 | * @return true if the profile is in quiet mode, false otherwise. |
| 3544 | */ |
| 3545 | public boolean isQuietModeEnabled(UserHandle userHandle) { |
| 3546 | try { |
| 3547 | return mService.isQuietModeEnabled(userHandle.getIdentifier()); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 3548 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3549 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3550 | } |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3554 | * Returns whether the given user has a badge (generally to put on profiles' icons). |
| 3555 | * |
| 3556 | * @param userId userId of the user in question |
| 3557 | * @return true if the user's icons should display a badge; false otherwise. |
| 3558 | * |
| 3559 | * @see #getBadgedIconForUser more information about badging in general |
| 3560 | * @hide |
| 3561 | */ |
| 3562 | public boolean hasBadge(@UserIdInt int userId) { |
| 3563 | if (!isProfile(userId)) { |
| 3564 | // Since currently only profiles actually have badges, we can do this optimization. |
| 3565 | return false; |
| 3566 | } |
| 3567 | try { |
| 3568 | return mService.hasBadge(userId); |
| 3569 | } catch (RemoteException re) { |
| 3570 | throw re.rethrowFromSystemServer(); |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3575 | * Returns whether the user associated with the context has a badge (generally to put on |
| 3576 | * profiles' icons). |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3577 | * |
| 3578 | * @return true if the user's icons should display a badge; false otherwise. |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3579 | * @see #getBadgedIconForUser more information about badging in general |
| 3580 | * @hide |
| 3581 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3582 | @UserHandleAware |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3583 | public boolean hasBadge() { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3584 | return hasBadge(mUserId); |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * Returns the badge color for the given user (generally to color a profile's icon's badge). |
| 3589 | * |
| 3590 | * <p>To check whether a badge color is expected for the user, first call {@link #hasBadge}. |
| 3591 | * |
| 3592 | * @return the color (not the resource ID) to be used for the user's badge |
| 3593 | * @throws Resources.NotFoundException if no valid badge color exists for this user |
| 3594 | * |
| 3595 | * @see #getBadgedIconForUser more information about badging in general |
| 3596 | * @hide |
| 3597 | */ |
| 3598 | public @ColorInt int getUserBadgeColor(@UserIdInt int userId) { |
| 3599 | try { |
| 3600 | final int resourceId = mService.getUserBadgeColorResId(userId); |
| 3601 | return Resources.getSystem().getColor(resourceId, null); |
| 3602 | } catch (RemoteException re) { |
| 3603 | throw re.rethrowFromSystemServer(); |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | /** |
| 3608 | * Returns the Resource ID of the user's icon badge. |
| 3609 | * |
| 3610 | * @return the Resource ID of the user's icon badge if it has one; otherwise |
| 3611 | * {@link Resources#ID_NULL}. |
| 3612 | * |
| 3613 | * @see #getBadgedIconForUser more information about badging in general |
| 3614 | * @hide |
| 3615 | */ |
| 3616 | public @DrawableRes int getUserIconBadgeResId(@UserIdInt int userId) { |
| 3617 | try { |
| 3618 | return mService.getUserIconBadgeResId(userId); |
| 3619 | } catch (RemoteException re) { |
| 3620 | throw re.rethrowFromSystemServer(); |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * Returns the Resource ID of the user's badge. |
| 3626 | * |
| 3627 | * @return the Resource ID of the user's badge if it has one; otherwise |
| 3628 | * {@link Resources#ID_NULL}. |
| 3629 | * |
| 3630 | * @see #getBadgedIconForUser more information about badging in general |
| 3631 | * @hide |
| 3632 | */ |
| 3633 | public @DrawableRes int getUserBadgeResId(@UserIdInt int userId) { |
| 3634 | try { |
| 3635 | return mService.getUserBadgeResId(userId); |
| 3636 | } catch (RemoteException re) { |
| 3637 | throw re.rethrowFromSystemServer(); |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | /** |
| 3642 | * Returns the Resource ID of the user's badge without a background. |
| 3643 | * |
| 3644 | * @return the Resource ID of the user's no-background badge if it has one; otherwise |
| 3645 | * {@link Resources#ID_NULL}. |
| 3646 | * |
| 3647 | * @see #getBadgedIconForUser more information about badging in general |
| 3648 | * @hide |
| 3649 | */ |
| 3650 | public @DrawableRes int getUserBadgeNoBackgroundResId(@UserIdInt int userId) { |
| 3651 | try { |
| 3652 | return mService.getUserBadgeNoBackgroundResId(userId); |
| 3653 | } catch (RemoteException re) { |
| 3654 | throw re.rethrowFromSystemServer(); |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * If the target user is a profile of the calling user or the caller |
| 3660 | * is itself a profile, then this returns a badged copy of the given |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3661 | * icon to be able to distinguish it from the original icon. For badging an |
| 3662 | * arbitrary drawable use {@link #getBadgedDrawableForUser( |
| 3663 | * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. |
| 3664 | * <p> |
| 3665 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 3666 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3667 | * is performed in place and the original drawable is returned. |
| 3668 | * </p> |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 3669 | * |
| 3670 | * @param icon The icon to badge. |
| 3671 | * @param user The target user. |
| 3672 | * @return A drawable that combines the original icon and a badge as |
| 3673 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 3674 | * @removed |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 3675 | */ |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3676 | public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 3677 | return mContext.getPackageManager().getUserBadgedIcon(icon, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 3678 | } |
| 3679 | |
Kenny Guy | 701ea7c | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3680 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3681 | * If the target user is a profile of the calling user or the caller |
| 3682 | * is itself a profile, then this returns a badged copy of the given |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3683 | * drawable allowing the user to distinguish it from the original drawable. |
| 3684 | * The caller can specify the location in the bounds of the drawable to be |
| 3685 | * badged where the badge should be applied as well as the density of the |
| 3686 | * badge to be used. |
| 3687 | * <p> |
| 3688 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 3689 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3690 | * is performed in place and the original drawable is returned. |
| 3691 | * </p> |
| 3692 | * |
| 3693 | * @param badgedDrawable The drawable to badge. |
| 3694 | * @param user The target user. |
| 3695 | * @param badgeLocation Where in the bounds of the badged drawable to place |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 3696 | * the badge. If it's {@code null}, the badge is applied on top of the entire |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3697 | * drawable being badged. |
| 3698 | * @param badgeDensity The optional desired density for the badge as per |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 3699 | * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3700 | * the density of the display is used. |
| 3701 | * @return A drawable that combines the original drawable and a badge as |
| 3702 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 3703 | * @removed |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3704 | */ |
| 3705 | public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, |
| 3706 | Rect badgeLocation, int badgeDensity) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 3707 | return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, |
| 3708 | badgeLocation, badgeDensity); |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | /** |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3712 | * If the target user is a profile of the calling user or the caller |
| 3713 | * is itself a profile, then this returns a copy of the label with |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 3714 | * badging for accessibility services like talkback. E.g. passing in "Email" |
| 3715 | * and it might return "Work Email" for Email in the work profile. |
| 3716 | * |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3717 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} or |
| 3718 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller |
| 3719 | * must be in the same profile group of specified user. |
| 3720 | * |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 3721 | * @param label The label to change. |
| 3722 | * @param user The target user. |
| 3723 | * @return A label that combines the original label and a badge as |
| 3724 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 3725 | * @removed |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 3726 | */ |
Kenny Guy | 237aecd | 2014-07-21 14:06:09 +0100 | [diff] [blame] | 3727 | public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { |
Bookatz | 029832a | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 3728 | final int userId = user.getIdentifier(); |
| 3729 | if (!hasBadge(userId)) { |
| 3730 | return label; |
| 3731 | } |
| 3732 | try { |
| 3733 | final int resourceId = mService.getUserBadgeLabelResId(userId); |
| 3734 | return Resources.getSystem().getString(resourceId, label); |
| 3735 | } catch (RemoteException re) { |
| 3736 | throw re.rethrowFromSystemServer(); |
| 3737 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3741 | * Removes a user and all associated data. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3742 | * @param userId the integer handle of the user. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3743 | * @hide |
| 3744 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3745 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3746 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3747 | Manifest.permission.CREATE_USERS}) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3748 | public boolean removeUser(@UserIdInt int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3749 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3750 | return mService.removeUser(userId); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3751 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3752 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | /** |
Varun Shah | e38c678 | 2018-12-04 16:57:49 -0800 | [diff] [blame] | 3757 | * Removes a user and all associated data. |
| 3758 | * |
| 3759 | * @param user the user that needs to be removed. |
Varun Shah | 9533e62 | 2019-02-27 15:26:56 -0800 | [diff] [blame] | 3760 | * @return {@code true} if the user was successfully removed, {@code false} otherwise. |
| 3761 | * @throws IllegalArgumentException if {@code user} is {@code null} |
Varun Shah | e38c678 | 2018-12-04 16:57:49 -0800 | [diff] [blame] | 3762 | * @hide |
| 3763 | */ |
| 3764 | @SystemApi |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3765 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3766 | Manifest.permission.CREATE_USERS}) |
Varun Shah | 9533e62 | 2019-02-27 15:26:56 -0800 | [diff] [blame] | 3767 | public boolean removeUser(@NonNull UserHandle user) { |
| 3768 | if (user == null) { |
| 3769 | throw new IllegalArgumentException("user cannot be null"); |
| 3770 | } |
Varun Shah | e38c678 | 2018-12-04 16:57:49 -0800 | [diff] [blame] | 3771 | return removeUser(user.getIdentifier()); |
| 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | /** |
Nicolas Prevot | d37c4a9 | 2017-01-23 11:56:00 +0000 | [diff] [blame] | 3776 | * Similar to {@link #removeUser(int)} except bypassing the checking of |
| 3777 | * {@link UserManager#DISALLOW_REMOVE_USER} |
| 3778 | * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}. |
| 3779 | * |
| 3780 | * @see {@link #removeUser(int)} |
| 3781 | * @hide |
| 3782 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3783 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 3784 | Manifest.permission.CREATE_USERS}) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3785 | public boolean removeUserEvenWhenDisallowed(@UserIdInt int userId) { |
Nicolas Prevot | d37c4a9 | 2017-01-23 11:56:00 +0000 | [diff] [blame] | 3786 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3787 | return mService.removeUserEvenWhenDisallowed(userId); |
Nicolas Prevot | d37c4a9 | 2017-01-23 11:56:00 +0000 | [diff] [blame] | 3788 | } catch (RemoteException re) { |
| 3789 | throw re.rethrowFromSystemServer(); |
| 3790 | } |
| 3791 | } |
| 3792 | |
| 3793 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3794 | * Updates the user's name. |
| 3795 | * |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3796 | * @param userId the user's integer id |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3797 | * @param name the new name for the user |
| 3798 | * @hide |
| 3799 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3800 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3801 | public void setUserName(@UserIdInt int userId, String name) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3802 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3803 | mService.setUserName(userId, name); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3804 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3805 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3810 | * Updates the context user's name. |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3811 | * |
| 3812 | * @param name the new name for the user |
| 3813 | * @hide |
| 3814 | */ |
| 3815 | @SystemApi |
| 3816 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3817 | @UserHandleAware |
Leo Hsu | 5183933 | 2019-03-05 16:59:04 +0800 | [diff] [blame] | 3818 | public void setUserName(@Nullable String name) { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3819 | setUserName(mUserId, name); |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | /** |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 3823 | * Sets the user's photo. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3824 | * @param userId the user for whom to change the photo. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 3825 | * @param icon the bitmap to set as the photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3826 | * @hide |
| 3827 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3828 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 3829 | public void setUserIcon(@UserIdInt int userId, @NonNull Bitmap icon) |
| 3830 | throws UserOperationException { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3831 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3832 | mService.setUserIcon(userId, icon); |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3833 | } catch (ServiceSpecificException e) { |
| 3834 | throw UserOperationException.from(e); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3835 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3836 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3841 | * Sets the context user's photo. |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3842 | * |
| 3843 | * @param icon the bitmap to set as the photo. |
| 3844 | * @hide |
| 3845 | */ |
| 3846 | @SystemApi |
| 3847 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3848 | @UserHandleAware |
| 3849 | public void setUserIcon(@NonNull Bitmap icon) throws UserOperationException { |
| 3850 | setUserIcon(mUserId, icon); |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3854 | * Returns a bitmap of the user's photo |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3855 | * @param userId the user whose photo we want to read. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 3856 | * @return a {@link Bitmap} of the user's photo, or null if there's no photo. |
Alexandra Gherghina | 64d4dca | 2014-08-28 18:26:56 +0100 | [diff] [blame] | 3857 | * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 3858 | * @hide |
| 3859 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3860 | @UnsupportedAppUsage |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3861 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 3862 | android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3863 | public Bitmap getUserIcon(@UserIdInt int userId) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 3864 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3865 | ParcelFileDescriptor fd = mService.getUserIcon(userId); |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 3866 | if (fd != null) { |
| 3867 | try { |
| 3868 | return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); |
| 3869 | } finally { |
| 3870 | try { |
| 3871 | fd.close(); |
| 3872 | } catch (IOException e) { |
| 3873 | } |
| 3874 | } |
| 3875 | } |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 3876 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3877 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 3878 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 3879 | return null; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | /** |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3883 | * Returns a Bitmap for the context user's photo. |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3884 | * |
| 3885 | * @return a {@link Bitmap} of the user's photo, or null if there's no photo. |
| 3886 | * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. |
| 3887 | * @hide |
| 3888 | */ |
| 3889 | @SystemApi |
Bookatz | cde3d92 | 2019-03-08 14:30:00 -0800 | [diff] [blame] | 3890 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 3891 | android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3892 | @UserHandleAware |
Leo Hsu | 5183933 | 2019-03-05 16:59:04 +0800 | [diff] [blame] | 3893 | public @Nullable Bitmap getUserIcon() { |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 3894 | return getUserIcon(mUserId); |
Leo Hsu | ab28fff | 2019-01-30 15:40:56 +0800 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3898 | * Returns the maximum number of users that can be created on this device. A return value |
| 3899 | * of 1 means that it is a single user device. |
| 3900 | * @hide |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 3901 | * @return a value greater than or equal to 1 |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3902 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3903 | @UnsupportedAppUsage |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 3904 | public static int getMaxSupportedUsers() { |
Amith Yamasani | ff54920 | 2012-10-12 12:44:49 -0700 | [diff] [blame] | 3905 | // Don't allow multiple users on certain builds |
| 3906 | if (android.os.Build.ID.startsWith("JVP")) return 1; |
Robin Lee | 83c7931 | 2018-02-09 19:27:18 +0100 | [diff] [blame] | 3907 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 3908 | // Low-ram devices are Svelte. Most of the time they don't get multi-user. |
| 3909 | if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) |
| 3910 | != Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3911 | return 1; |
| 3912 | } |
| 3913 | } |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 3914 | return SystemProperties.getInt("fw.max_users", |
| 3915 | Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3916 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3917 | |
| 3918 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3919 | * Returns true if the user switcher should be shown, this will be if device supports multi-user |
| 3920 | * and there are at least 2 users available that are not managed profiles. |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 3921 | * @hide |
| 3922 | * @return true if user switcher should be shown. |
| 3923 | */ |
| 3924 | public boolean isUserSwitcherEnabled() { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3925 | if (!supportsMultipleUsers()) { |
| 3926 | return false; |
| 3927 | } |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 3928 | if (hasUserRestriction(DISALLOW_USER_SWITCH)) { |
| 3929 | return false; |
| 3930 | } |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 3931 | // If Demo Mode is on, don't show user switcher |
| 3932 | if (isDeviceInDemoMode(mContext)) { |
| 3933 | return false; |
| 3934 | } |
Fan Zhang | c69c8b6 | 2018-06-05 13:30:11 -0700 | [diff] [blame] | 3935 | // If user disabled this feature, don't show switcher |
| 3936 | final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(), |
| 3937 | Settings.Global.USER_SWITCHER_ENABLED, 1) != 0; |
| 3938 | if (!userSwitcherEnabled) { |
| 3939 | return false; |
| 3940 | } |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 3941 | List<UserInfo> users = getUsers(true); |
| 3942 | if (users == null) { |
| 3943 | return false; |
| 3944 | } |
| 3945 | int switchableUserCount = 0; |
| 3946 | for (UserInfo user : users) { |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 3947 | if (user.supportsSwitchToByUser()) { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 3948 | ++switchableUserCount; |
| 3949 | } |
| 3950 | } |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3951 | final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) |
| 3952 | .getGuestUserDisabled(null); |
Amith Yamasani | a596ff8 | 2014-06-12 18:12:38 -0700 | [diff] [blame] | 3953 | return switchableUserCount > 1 || guestEnabled; |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | /** |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 3957 | * @hide |
| 3958 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3959 | @UnsupportedAppUsage |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 3960 | public static boolean isDeviceInDemoMode(Context context) { |
| 3961 | return Settings.Global.getInt(context.getContentResolver(), |
| 3962 | Settings.Global.DEVICE_DEMO_MODE, 0) > 0; |
| 3963 | } |
| 3964 | |
| 3965 | /** |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3966 | * Returns a serial number on this device for a given userId. User handles can be recycled |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3967 | * when deleting and creating users, but serial numbers are not reused until the device is wiped. |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3968 | * @param userId |
| 3969 | * @return a serial number associated with that user, or -1 if the userId is not valid. |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3970 | * @hide |
| 3971 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3972 | @UnsupportedAppUsage |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3973 | public int getUserSerialNumber(@UserIdInt int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3974 | try { |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3975 | return mService.getUserSerialNumber(userId); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3976 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3977 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3978 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | /** |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3982 | * Returns a userId on this device for a given user serial number. User handles can be |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3983 | * recycled when deleting and creating users, but serial numbers are not reused until the device |
| 3984 | * is wiped. |
| 3985 | * @param userSerialNumber |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 3986 | * @return the userId associated with that user serial number, or -1 if the serial number |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3987 | * is not valid. |
| 3988 | * @hide |
| 3989 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 3990 | @UnsupportedAppUsage |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3991 | public @UserIdInt int getUserHandle(int userSerialNumber) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3992 | try { |
| 3993 | return mService.getUserHandle(userSerialNumber); |
| 3994 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3995 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3996 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 3997 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 3998 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 3999 | /** |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 4000 | * Returns a {@link Bundle} containing any saved application restrictions for this user, for the |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4001 | * given package name. Only an application with this package name can call this method. |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 4002 | * |
| 4003 | * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, |
| 4004 | * where the types of values may be: |
| 4005 | * <ul> |
| 4006 | * <li>{@code boolean} |
| 4007 | * <li>{@code int} |
| 4008 | * <li>{@code String} or {@code String[]} |
| 4009 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4010 | * </ul> |
| 4011 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4012 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4013 | * |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4014 | * @param packageName the package name of the calling application |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 4015 | * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle} |
| 4016 | * if there are no saved restrictions. |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 4017 | * |
| 4018 | * @see #KEY_RESTRICTIONS_PENDING |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4019 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4020 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4021 | public Bundle getApplicationRestrictions(String packageName) { |
| 4022 | try { |
| 4023 | return mService.getApplicationRestrictions(packageName); |
| 4024 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4025 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4026 | } |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4027 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4028 | |
| 4029 | /** |
| 4030 | * @hide |
| 4031 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4032 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4033 | public Bundle getApplicationRestrictions(String packageName, UserHandle user) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4034 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4035 | return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4036 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4037 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4038 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | /** |
| 4042 | * @hide |
| 4043 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4044 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4045 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4046 | UserHandle user) { |
| 4047 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 4048 | mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4049 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4050 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4051 | } |
| 4052 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 4053 | |
| 4054 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 4055 | * Sets a new challenge PIN for restrictions. This is only for use by pre-installed |
| 4056 | * apps and requires the MANAGE_USERS permission. |
| 4057 | * @param newPin the PIN to use for challenge dialogs. |
| 4058 | * @return Returns true if the challenge PIN was set successfully. |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 4059 | * @deprecated The restrictions PIN functionality is no longer provided by the system. |
| 4060 | * This method is preserved for backwards compatibility reasons and always returns false. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 4061 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4062 | @Deprecated |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 4063 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 4064 | return false; |
| 4065 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 4066 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4067 | /** |
| 4068 | * @hide |
| 4069 | * Set restrictions that should apply to any future guest user that's created. |
| 4070 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 4071 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4072 | public void setDefaultGuestRestrictions(Bundle restrictions) { |
| 4073 | try { |
| 4074 | mService.setDefaultGuestRestrictions(restrictions); |
| 4075 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4076 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | /** |
| 4081 | * @hide |
| 4082 | * Gets the default guest restrictions. |
| 4083 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 4084 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4085 | public Bundle getDefaultGuestRestrictions() { |
| 4086 | try { |
| 4087 | return mService.getDefaultGuestRestrictions(); |
| 4088 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4089 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4090 | } |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 4091 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 4092 | |
| 4093 | /** |
| 4094 | * Returns creation time of the user or of a managed profile associated with the calling user. |
| 4095 | * @param userHandle user handle of the user or a managed profile associated with the |
| 4096 | * calling user. |
| 4097 | * @return creation time in milliseconds since Epoch time. |
| 4098 | */ |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 4099 | public long getUserCreationTime(UserHandle userHandle) { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 4100 | try { |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 4101 | return mService.getUserCreationTime(userHandle.getIdentifier()); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 4102 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4103 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 4104 | } |
| 4105 | } |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 4106 | |
| 4107 | /** |
| 4108 | * @hide |
| 4109 | * Checks if any uninitialized user has the specific seed account name and type. |
| 4110 | * |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 4111 | * @param accountName The account name to check for |
| 4112 | * @param accountType The account type of the account to check for |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 4113 | * @return whether the seed account was found |
| 4114 | */ |
Valentin Iftime | 89df4c8 | 2019-08-23 13:02:50 +0200 | [diff] [blame] | 4115 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 4116 | public boolean someUserHasSeedAccount(String accountName, String accountType) { |
| 4117 | try { |
| 4118 | return mService.someUserHasSeedAccount(accountName, accountType); |
| 4119 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4120 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 4121 | } |
| 4122 | } |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 4123 | |
| 4124 | /** |
| 4125 | * @hide |
| 4126 | * User that enforces a restriction. |
| 4127 | * |
| 4128 | * @see #getUserRestrictionSources(String, UserHandle) |
| 4129 | */ |
| 4130 | @SystemApi |
| 4131 | public static final class EnforcingUser implements Parcelable { |
| 4132 | private final @UserIdInt int userId; |
| 4133 | private final @UserRestrictionSource int userRestrictionSource; |
| 4134 | |
| 4135 | /** |
| 4136 | * @hide |
| 4137 | */ |
| 4138 | public EnforcingUser( |
| 4139 | @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) { |
| 4140 | this.userId = userId; |
| 4141 | this.userRestrictionSource = userRestrictionSource; |
| 4142 | } |
| 4143 | |
| 4144 | private EnforcingUser(Parcel in) { |
| 4145 | userId = in.readInt(); |
| 4146 | userRestrictionSource = in.readInt(); |
| 4147 | } |
| 4148 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 4149 | public static final @android.annotation.NonNull Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() { |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 4150 | @Override |
| 4151 | public EnforcingUser createFromParcel(Parcel in) { |
| 4152 | return new EnforcingUser(in); |
| 4153 | } |
| 4154 | |
| 4155 | @Override |
| 4156 | public EnforcingUser[] newArray(int size) { |
| 4157 | return new EnforcingUser[size]; |
| 4158 | } |
| 4159 | }; |
| 4160 | |
| 4161 | @Override |
| 4162 | public int describeContents() { |
| 4163 | return 0; |
| 4164 | } |
| 4165 | |
| 4166 | @Override |
| 4167 | public void writeToParcel(Parcel dest, int flags) { |
| 4168 | dest.writeInt(userId); |
| 4169 | dest.writeInt(userRestrictionSource); |
| 4170 | } |
| 4171 | |
| 4172 | /** |
| 4173 | * Returns an id of the enforcing user. |
| 4174 | * |
| 4175 | * <p> Will be UserHandle.USER_NULL when restriction is set by the system. |
| 4176 | */ |
| 4177 | public UserHandle getUserHandle() { |
| 4178 | return UserHandle.of(userId); |
| 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * Returns the status of the enforcing user. |
| 4183 | * |
| 4184 | * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM}, |
| 4185 | * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and |
| 4186 | * {@link #RESTRICTION_SOURCE_PROFILE_OWNER} |
| 4187 | */ |
| 4188 | public @UserRestrictionSource int getUserRestrictionSource() { |
| 4189 | return userRestrictionSource; |
| 4190 | } |
| 4191 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 4192 | } |