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