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