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