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 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 737 | * Specifies if what is copied in the clipboard of this profile can |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 738 | * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be |
| 739 | * pasted in this profile. |
| 740 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 741 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 742 | * <p>Key for user restrictions. |
| 743 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 744 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 745 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 746 | * @see #getUserRestrictions() |
| 747 | */ |
| 748 | public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; |
| 749 | |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Specifies if the user is not allowed to use NFC to beam out data from apps. |
| 752 | * The default value is <code>false</code>. |
| 753 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 754 | * <p>Key for user restrictions. |
| 755 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 756 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 757 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 758 | * @see #getUserRestrictions() |
| 759 | */ |
| 760 | public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; |
| 761 | |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 762 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 763 | * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction |
| 764 | * generally means that wallpapers are not supported for the particular user. This user |
| 765 | * 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] | 766 | * @hide |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 767 | * @see #DISALLOW_SET_WALLPAPER |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 768 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 769 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 770 | * @see #getUserRestrictions() |
| 771 | */ |
| 772 | public static final String DISALLOW_WALLPAPER = "no_wallpaper"; |
| 773 | |
| 774 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 775 | * User restriction to disallow setting a wallpaper. Profile owner and device owner |
| 776 | * are able to set wallpaper regardless of this restriction. |
| 777 | * The default value is <code>false</code>. |
| 778 | * |
| 779 | * <p>Key for user restrictions. |
| 780 | * <p>Type: Boolean |
| 781 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 782 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 783 | * @see #getUserRestrictions() |
| 784 | */ |
| 785 | public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; |
| 786 | |
| 787 | /** |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 788 | * Specifies if the user is not allowed to reboot the device into safe boot mode. |
| 789 | * This can only be set by device owners and profile owners on the primary user. |
| 790 | * The default value is <code>false</code>. |
| 791 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 792 | * <p>Key for user restrictions. |
| 793 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 794 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 795 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 796 | * @see #getUserRestrictions() |
| 797 | */ |
| 798 | public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; |
| 799 | |
| 800 | /** |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 801 | * Specifies if a user is not allowed to record audio. This restriction is always enabled for |
| 802 | * background users. The default value is <code>false</code>. |
| 803 | * |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 804 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 805 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 806 | * @see #getUserRestrictions() |
| 807 | * @hide |
| 808 | */ |
| 809 | public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; |
| 810 | |
| 811 | /** |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 812 | * Specifies if a user is not allowed to run in the background and should be stopped during |
| 813 | * user switch. The default value is <code>false</code>. |
| 814 | * |
| 815 | * <p>This restriction can be set by device owners and profile owners. |
| 816 | * |
| 817 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 818 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 819 | * @see #getUserRestrictions() |
| 820 | * @hide |
| 821 | */ |
Robin Lee | 6cfb7a9 | 2017-12-18 15:14:46 +0100 | [diff] [blame] | 822 | @SystemApi |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 823 | public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; |
| 824 | |
| 825 | /** |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 826 | * Specifies if a user is not allowed to use the camera. |
| 827 | * |
| 828 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 829 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 830 | * @see #getUserRestrictions() |
| 831 | * @hide |
| 832 | */ |
| 833 | public static final String DISALLOW_CAMERA = "no_camera"; |
| 834 | |
| 835 | /** |
Tony Mak | c120511 | 2016-07-22 16:02:59 +0100 | [diff] [blame] | 836 | * Specifies if a user is not allowed to unmute the device's master volume. |
| 837 | * |
| 838 | * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean) |
| 839 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 840 | * @see #getUserRestrictions() |
| 841 | * @hide |
| 842 | */ |
Esteban Talavera | 492b472 | 2017-02-13 14:59:45 +0000 | [diff] [blame] | 843 | public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device"; |
Tony Mak | c120511 | 2016-07-22 16:02:59 +0100 | [diff] [blame] | 844 | |
| 845 | /** |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 846 | * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by |
| 847 | * device owners. The default value is <code>false</code>. |
| 848 | * |
| 849 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 850 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 851 | * @see #getUserRestrictions() |
| 852 | */ |
| 853 | public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; |
| 854 | |
| 855 | /** |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 856 | * Specifies if a user is not allowed to change their icon. Device owner and profile owner |
| 857 | * can set this restriction. When it is set by device owner, only the target user will be |
| 858 | * affected. The default value is <code>false</code>. |
| 859 | * |
| 860 | * <p>Key for user restrictions. |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 861 | * <p>Type: Boolean |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 862 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 863 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 864 | * @see #getUserRestrictions() |
| 865 | */ |
| 866 | public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; |
| 867 | |
| 868 | /** |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 869 | * 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] | 870 | * <code>false</code>. Setting this restriction has no effect if the bootloader is already |
| 871 | * unlocked. |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 872 | * |
Lenka Trochtova | 12b0496 | 2016-11-29 21:00:12 +0100 | [diff] [blame] | 873 | * <p>Not for use by third-party applications. |
| 874 | * |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 875 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 876 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 877 | * @see #getUserRestrictions() |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 878 | * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead. |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 879 | * @hide |
| 880 | */ |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 881 | @Deprecated |
Lenka Trochtova | 12b0496 | 2016-11-29 21:00:12 +0100 | [diff] [blame] | 882 | @SystemApi |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 883 | public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock"; |
| 884 | |
| 885 | /** |
Pavel Grafov | c4f87e9 | 2017-10-26 16:34:25 +0100 | [diff] [blame] | 886 | * Specifies that the managed profile is not allowed to have unified lock screen challenge with |
| 887 | * the primary user. |
| 888 | * |
| 889 | * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a |
| 890 | * separate challenge. Profile owner can ask the user to set a new password using |
| 891 | * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using |
| 892 | * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}. |
| 893 | * |
| 894 | * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed |
| 895 | * profile owner. Has no effect on non-managed profiles or users. |
| 896 | * <p>Key for user restrictions. |
| 897 | * <p>Type: Boolean |
| 898 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 899 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 900 | * @see #getUserRestrictions() |
| 901 | */ |
| 902 | public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password"; |
| 903 | |
| 904 | /** |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 905 | * Allows apps in the parent profile to handle web links from the managed profile. |
| 906 | * |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 907 | * This user restriction has an effect only in a managed profile. |
| 908 | * If set: |
| 909 | * Intent filters of activities in the parent profile with action |
| 910 | * {@link android.content.Intent#ACTION_VIEW}, |
| 911 | * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which |
| 912 | * define a host can handle intents from the managed profile. |
| 913 | * The default value is <code>false</code>. |
| 914 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 915 | * <p>Key for user restrictions. |
| 916 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 917 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 918 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 919 | * @see #getUserRestrictions() |
| 920 | */ |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 921 | public static final String ALLOW_PARENT_PROFILE_APP_LINKING |
| 922 | = "allow_parent_profile_app_linking"; |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 923 | |
| 924 | /** |
Felipe Leme | 24d5893 | 2017-03-21 14:13:58 -0700 | [diff] [blame] | 925 | * Specifies if a user is not allowed to use Autofill Services. |
| 926 | * |
| 927 | * <p>Device owner and profile owner can set this restriction. When it is set by device owner, |
| 928 | * only the target user will be affected. |
| 929 | * |
| 930 | * <p>The default value is <code>false</code>. |
| 931 | * |
| 932 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 933 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 934 | * @see #getUserRestrictions() |
| 935 | */ |
| 936 | public static final String DISALLOW_AUTOFILL = "no_autofill"; |
| 937 | |
| 938 | /** |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 939 | * Specifies if the contents of a user's screen is not allowed to be captured for artificial |
| 940 | * intelligence purposes. |
| 941 | * |
| 942 | * <p>Device owner and profile owner can set this restriction. When it is set by device owner, |
| 943 | * only the target user will be affected. |
| 944 | * |
| 945 | * <p>The default value is <code>false</code>. |
| 946 | * |
| 947 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 948 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 949 | * @see #getUserRestrictions() |
| 950 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 951 | public static final String DISALLOW_CONTENT_CAPTURE = "no_content_capture"; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 952 | |
| 953 | /** |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 954 | * Specifies if user switching is blocked on the current user. |
| 955 | * |
| 956 | * <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] | 957 | * Device owner can still switch user via |
| 958 | * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is |
| 959 | * set. |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 960 | * |
| 961 | * <p>The default value is <code>false</code>. |
| 962 | * |
| 963 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 964 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 965 | * @see #getUserRestrictions() |
| 966 | */ |
| 967 | public static final String DISALLOW_USER_SWITCH = "no_user_switch"; |
| 968 | |
| 969 | /** |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 970 | * Specifies whether the user can share file / picture / data from the primary user into the |
| 971 | * managed profile, either by sending them from the primary side, or by picking up data within |
| 972 | * an app in the managed profile. |
| 973 | * <p> |
| 974 | * When a managed profile is created, the system allows the user to send data from the primary |
| 975 | * side to the profile by setting up certain default cross profile intent filters. If |
| 976 | * this is undesired, this restriction can be set to disallow it. Note that this restriction |
| 977 | * will not block any sharing allowed by explicit |
| 978 | * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner. |
| 979 | * <p> |
| 980 | * This restriction is only meaningful when set by profile owner. When it is set by device |
| 981 | * owner, it does not have any effect. |
| 982 | * <p> |
| 983 | * The default value is <code>false</code>. |
| 984 | * |
| 985 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 986 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 987 | * @see #getUserRestrictions() |
| 988 | */ |
| 989 | 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] | 990 | |
| 991 | /** |
| 992 | * Specifies whether the user is allowed to print. |
| 993 | * |
| 994 | * This restriction can be set by device or profile owner. |
| 995 | * |
| 996 | * The default value is {@code false}. |
| 997 | * |
| 998 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 999 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1000 | * @see #getUserRestrictions() |
| 1001 | */ |
| 1002 | public static final String DISALLOW_PRINTING = "no_printing"; |
| 1003 | |
Rubin Xu | cc391c2 | 2018-01-02 20:37:35 +0000 | [diff] [blame] | 1004 | /** |
Eran Messeri | 09b122da | 2018-10-05 15:33:53 +0100 | [diff] [blame] | 1005 | * Specifies whether the user is allowed to modify private DNS settings. |
| 1006 | * |
| 1007 | * <p>The default value is <code>false</code>. |
| 1008 | * |
| 1009 | * <p>This user restriction can only be applied by the Device Owner. |
| 1010 | * <p>Key for user restrictions. |
| 1011 | * <p>Type: Boolean |
| 1012 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 1013 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 1014 | * @see #getUserRestrictions() |
| 1015 | */ |
| 1016 | public static final String DISALLOW_CONFIG_PRIVATE_DNS = |
| 1017 | "disallow_config_private_dns"; |
| 1018 | |
| 1019 | /** |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 1020 | * Application restriction key that is used to indicate the pending arrival |
| 1021 | * of real restrictions for the app. |
| 1022 | * |
| 1023 | * <p> |
| 1024 | * Applications that support restrictions should check for the presence of this key. |
| 1025 | * A <code>true</code> value indicates that restrictions may be applied in the near |
| 1026 | * future but are not available yet. It is the responsibility of any |
| 1027 | * management application that sets this flag to update it when the final |
| 1028 | * restrictions are enforced. |
| 1029 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 1030 | * <p>Key for application restrictions. |
| 1031 | * <p>Type: Boolean |
Nicolas Prevot | b14ed95 | 2015-01-13 14:23:53 +0000 | [diff] [blame] | 1032 | * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( |
| 1033 | * android.content.ComponentName, String, Bundle) |
| 1034 | * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( |
| 1035 | * android.content.ComponentName, String) |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 1036 | */ |
| 1037 | public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; |
| 1038 | |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1039 | private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; |
| 1040 | |
| 1041 | /** |
| 1042 | * Extra containing a name for the user being created. Optional parameter passed to |
| 1043 | * ACTION_CREATE_USER activity. |
| 1044 | * @hide |
| 1045 | */ |
| 1046 | public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; |
| 1047 | |
| 1048 | /** |
| 1049 | * Extra containing account name for the user being created. Optional parameter passed to |
| 1050 | * ACTION_CREATE_USER activity. |
| 1051 | * @hide |
| 1052 | */ |
| 1053 | public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; |
| 1054 | |
| 1055 | /** |
| 1056 | * Extra containing account type for the user being created. Optional parameter passed to |
| 1057 | * ACTION_CREATE_USER activity. |
| 1058 | * @hide |
| 1059 | */ |
| 1060 | public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; |
| 1061 | |
| 1062 | /** |
| 1063 | * Extra containing account-specific data for the user being created. Optional parameter passed |
| 1064 | * to ACTION_CREATE_USER activity. |
| 1065 | * @hide |
| 1066 | */ |
| 1067 | public static final String EXTRA_USER_ACCOUNT_OPTIONS |
| 1068 | = "android.os.extra.USER_ACCOUNT_OPTIONS"; |
| 1069 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1070 | /** @hide */ |
| 1071 | public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; |
| 1072 | /** @hide */ |
| 1073 | public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; |
| 1074 | /** @hide */ |
| 1075 | public static final int PIN_VERIFICATION_SUCCESS = -1; |
| 1076 | |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1077 | /** |
Makoto Onuki | e72f81b | 2017-03-16 14:08:19 -0700 | [diff] [blame] | 1078 | * Sent when user restrictions have changed. |
| 1079 | * |
| 1080 | * @hide |
| 1081 | */ |
| 1082 | @SystemApi |
| 1083 | @TestApi // To allow seeing it from CTS. |
| 1084 | public static final String ACTION_USER_RESTRICTIONS_CHANGED = |
| 1085 | "android.os.action.USER_RESTRICTIONS_CHANGED"; |
| 1086 | |
| 1087 | /** |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1088 | * Error result indicating that this user is not allowed to add other users on this device. |
| 1089 | * This is a result code returned from the activity created by the intent |
| 1090 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 1091 | */ |
| 1092 | public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; |
| 1093 | |
| 1094 | /** |
| 1095 | * Error result indicating that no more users can be created on this device. |
| 1096 | * This is a result code returned from the activity created by the intent |
| 1097 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 1098 | */ |
| 1099 | public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; |
| 1100 | |
Alex Chau | 89386ba | 2018-02-13 11:09:17 +0800 | [diff] [blame] | 1101 | /** |
| 1102 | * Indicates user operation is successful. |
| 1103 | */ |
| 1104 | public static final int USER_OPERATION_SUCCESS = 0; |
| 1105 | |
| 1106 | /** |
| 1107 | * Indicates user operation failed for unknown reason. |
| 1108 | */ |
| 1109 | public static final int USER_OPERATION_ERROR_UNKNOWN = 1; |
| 1110 | |
| 1111 | /** |
| 1112 | * Indicates user operation failed because target user is a managed profile. |
| 1113 | */ |
| 1114 | public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2; |
| 1115 | |
| 1116 | /** |
| 1117 | * Indicates user operation failed because maximum running user limit has been reached. |
| 1118 | */ |
| 1119 | public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3; |
| 1120 | |
| 1121 | /** |
| 1122 | * Indicates user operation failed because the target user is in the foreground. |
| 1123 | */ |
| 1124 | public static final int USER_OPERATION_ERROR_CURRENT_USER = 4; |
| 1125 | |
| 1126 | /** |
| 1127 | * Indicates user operation failed because device has low data storage. |
| 1128 | */ |
| 1129 | public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5; |
| 1130 | |
| 1131 | /** |
| 1132 | * Indicates user operation failed because maximum user limit has been reached. |
| 1133 | */ |
| 1134 | public static final int USER_OPERATION_ERROR_MAX_USERS = 6; |
| 1135 | |
| 1136 | /** |
| 1137 | * Result returned from various user operations. |
| 1138 | * |
| 1139 | * @hide |
| 1140 | */ |
| 1141 | @Retention(RetentionPolicy.SOURCE) |
| 1142 | @IntDef(prefix = { "USER_OPERATION_" }, value = { |
| 1143 | USER_OPERATION_SUCCESS, |
| 1144 | USER_OPERATION_ERROR_UNKNOWN, |
| 1145 | USER_OPERATION_ERROR_MANAGED_PROFILE, |
| 1146 | USER_OPERATION_ERROR_MAX_RUNNING_USERS, |
| 1147 | USER_OPERATION_ERROR_CURRENT_USER, |
| 1148 | USER_OPERATION_ERROR_LOW_STORAGE, |
| 1149 | USER_OPERATION_ERROR_MAX_USERS |
| 1150 | }) |
| 1151 | public @interface UserOperationResult {} |
| 1152 | |
| 1153 | /** |
| 1154 | * Thrown to indicate user operation failed. |
| 1155 | */ |
| 1156 | public static class UserOperationException extends RuntimeException { |
| 1157 | private final @UserOperationResult int mUserOperationResult; |
| 1158 | |
| 1159 | /** |
| 1160 | * Constructs a UserOperationException with specific result code. |
| 1161 | * |
| 1162 | * @param message the detail message |
| 1163 | * @param userOperationResult the result code |
| 1164 | * @hide |
| 1165 | */ |
| 1166 | public UserOperationException(String message, |
| 1167 | @UserOperationResult int userOperationResult) { |
| 1168 | super(message); |
| 1169 | mUserOperationResult = userOperationResult; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * Returns the operation result code. |
| 1174 | */ |
| 1175 | public @UserOperationResult int getUserOperationResult() { |
| 1176 | return mUserOperationResult; |
| 1177 | } |
| 1178 | } |
| 1179 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1180 | /** @hide */ |
Amith Yamasani | c068830 | 2015-10-30 10:40:03 -0700 | [diff] [blame] | 1181 | public static UserManager get(Context context) { |
| 1182 | return (UserManager) context.getSystemService(Context.USER_SERVICE); |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 1183 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1184 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1185 | /** @hide */ |
| 1186 | public UserManager(Context context, IUserManager service) { |
| 1187 | mService = service; |
Fyodor Kupolov | 5200e1c | 2016-10-17 18:46:16 -0700 | [diff] [blame] | 1188 | mContext = context.getApplicationContext(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1192 | * Returns whether this device supports multiple users with their own login and customizable |
| 1193 | * space. |
| 1194 | * @return whether the device supports multiple users. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1195 | */ |
Jeff Sharkey | 4673e7e | 2012-09-19 13:14:30 -0700 | [diff] [blame] | 1196 | public static boolean supportsMultipleUsers() { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 1197 | return getMaxSupportedUsers() > 1 |
| 1198 | && SystemProperties.getBoolean("fw.show_multiuserui", |
| 1199 | Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1202 | /** |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1203 | * @hide |
| 1204 | * @return Whether the device is running with split system user. It means the system user and |
| 1205 | * primary user are two separate users. Previously system user and primary user are combined as |
| 1206 | * a single owner user. see @link {android.os.UserHandle#USER_OWNER} |
| 1207 | */ |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 1208 | @TestApi |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1209 | public static boolean isSplitSystemUser() { |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1210 | return RoSystemProperties.FW_SYSTEM_USER_SPLIT; |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1214 | * @return Whether guest user is always ephemeral |
| 1215 | * @hide |
| 1216 | */ |
| 1217 | public static boolean isGuestUserEphemeral() { |
| 1218 | return Resources.getSystem() |
| 1219 | .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1223 | * Returns whether switching users is currently allowed. |
| 1224 | * <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] | 1225 | * 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] | 1226 | * @hide |
| 1227 | */ |
Varun Shah | e38c678 | 2018-12-04 16:57:49 -0800 | [diff] [blame] | 1228 | @SystemApi |
| 1229 | @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, |
| 1230 | android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1231 | public boolean canSwitchUsers() { |
| 1232 | boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( |
| 1233 | mContext.getContentResolver(), |
| 1234 | Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; |
| 1235 | boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); |
| 1236 | boolean inCall = TelephonyManager.getDefault().getCallState() |
| 1237 | != TelephonyManager.CALL_STATE_IDLE; |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 1238 | boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH); |
| 1239 | return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall |
| 1240 | && !isUserSwitchDisallowed; |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1244 | * 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] | 1245 | * |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1246 | * @return the user handle of this process. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1247 | * @hide |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1248 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1249 | public @UserIdInt int getUserHandle() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 1250 | return UserHandle.myUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
Dianne Hackborn | 8832c18 | 2012-09-17 17:20:24 -0700 | [diff] [blame] | 1254 | * Returns the user name of the user making this call. This call is only |
| 1255 | * available to applications on the system image; it requires the |
| 1256 | * MANAGE_USERS permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1257 | * @return the user name |
| 1258 | */ |
| 1259 | public String getUserName() { |
Will Harmon | d9dcfb1 | 2017-05-18 15:41:15 -0700 | [diff] [blame] | 1260 | UserInfo user = getUserInfo(getUserHandle()); |
| 1261 | return user == null ? "" : user.name; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 1264 | /** |
Fyodor Kupolov | 605b12a | 2017-05-10 15:58:09 -0700 | [diff] [blame] | 1265 | * Returns whether user name has been set. |
| 1266 | * <p>This method can be used to check that the value returned by {@link #getUserName()} was |
| 1267 | * set by the user and is not a placeholder string provided by the system. |
| 1268 | * @hide |
| 1269 | */ |
| 1270 | public boolean isUserNameSet() { |
| 1271 | try { |
| 1272 | return mService.isUserNameSet(getUserHandle()); |
| 1273 | } catch (RemoteException re) { |
| 1274 | throw re.rethrowFromSystemServer(); |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | /** |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1279 | * Used to determine whether the user making this call is subject to |
| 1280 | * teleportations. |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 1281 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1282 | * <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] | 1283 | * now automatically identify goats using advanced goat recognition technology.</p> |
| 1284 | * |
| 1285 | * @return Returns true if the user making this call is a goat. |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1286 | */ |
| 1287 | public boolean isUserAGoat() { |
Adam Powell | 988ae30 | 2014-09-17 17:58:33 -0700 | [diff] [blame] | 1288 | return mContext.getPackageManager() |
| 1289 | .isPackageAvailable("com.coffeestainstudios.goatsimulator"); |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 1290 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1291 | |
| 1292 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1293 | * Used to check if this process is running under the primary user. The primary user |
| 1294 | * is the first human user on a device. |
| 1295 | * |
| 1296 | * @return whether this process is running under the primary user. |
| 1297 | * @hide |
| 1298 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1299 | @SystemApi |
| 1300 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1301 | public boolean isPrimaryUser() { |
| 1302 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1303 | return user != null && user.isPrimary(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1307 | * Used to check if this process is running under the system user. The system user |
| 1308 | * is the initial user that is implicitly created on first boot and hosts most of the |
| 1309 | * system services. |
| 1310 | * |
| 1311 | * @return whether this process is running under the system user. |
| 1312 | */ |
| 1313 | public boolean isSystemUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1314 | return UserHandle.myUserId() == UserHandle.USER_SYSTEM; |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1315 | } |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1316 | |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 1317 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1318 | * Used to check if this process is running as an admin user. An admin user is allowed to |
| 1319 | * modify or configure certain settings that aren't available to non-admin users, |
| 1320 | * create and delete additional users, etc. There can be more than one admin users. |
| 1321 | * |
| 1322 | * @return whether this process is running under an admin user. |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1323 | * @hide |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1324 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1325 | @SystemApi |
| 1326 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1327 | public boolean isAdminUser() { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1328 | return isUserAdmin(UserHandle.myUserId()); |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * @hide |
| 1333 | * Returns whether the provided user is an admin user. There can be more than one admin |
| 1334 | * user. |
| 1335 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1336 | public boolean isUserAdmin(@UserIdInt int userId) { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1337 | UserInfo user = getUserInfo(userId); |
| 1338 | return user != null && user.isAdmin(); |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1342 | * @hide |
| 1343 | * @deprecated Use {@link #isRestrictedProfile()} |
| 1344 | */ |
| 1345 | @Deprecated |
| 1346 | public boolean isLinkedUser() { |
| 1347 | return isRestrictedProfile(); |
| 1348 | } |
| 1349 | |
| 1350 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1351 | * Used to check if this process is running under a restricted profile. Restricted profiles |
| 1352 | * may have a reduced number of available apps, app restrictions, and account restrictions. |
| 1353 | * |
| 1354 | * @return whether this process is running under a restricted profile. |
Amith Yamasani | 2555daf | 2013-04-25 13:39:27 -0700 | [diff] [blame] | 1355 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1356 | */ |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1357 | @SystemApi |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1358 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1359 | public boolean isRestrictedProfile() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1360 | try { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1361 | return mService.isRestricted(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1362 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1363 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1367 | /** |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1368 | * Checks if specified user can have restricted profile. |
| 1369 | * @hide |
| 1370 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1371 | public boolean canHaveRestrictedProfile(@UserIdInt int userId) { |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1372 | try { |
| 1373 | return mService.canHaveRestrictedProfile(userId); |
| 1374 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1375 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | /** |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1380 | * Returns whether the calling user has at least one restricted profile associated with it. |
| 1381 | * @return |
| 1382 | * @hide |
| 1383 | */ |
| 1384 | @SystemApi |
| 1385 | public boolean hasRestrictedProfiles() { |
| 1386 | try { |
| 1387 | return mService.hasRestrictedProfiles(); |
| 1388 | } catch (RemoteException re) { |
| 1389 | throw re.rethrowFromSystemServer(); |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | /** |
Evan Rosky | 13a58a9 | 2016-07-27 15:51:09 -0700 | [diff] [blame] | 1394 | * Checks if a user is a guest user. |
| 1395 | * @return whether user is a guest user. |
| 1396 | * @hide |
| 1397 | */ |
| 1398 | public boolean isGuestUser(int id) { |
| 1399 | UserInfo user = getUserInfo(id); |
| 1400 | return user != null && user.isGuest(); |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1404 | * Used to check if this process is running under a guest user. A guest user may be transient. |
| 1405 | * |
| 1406 | * @return whether this process is running under a guest user. |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1407 | * @hide |
| 1408 | */ |
Varun Shah | e142e33 | 2018-10-22 15:52:56 -0700 | [diff] [blame] | 1409 | @SystemApi |
| 1410 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1411 | public boolean isGuestUser() { |
| 1412 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1413 | return user != null && user.isGuest(); |
| 1414 | } |
| 1415 | |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 1416 | |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1417 | /** |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 1418 | * Checks if the calling app is running in a demo user. When running in a demo user, |
| 1419 | * apps can be more helpful to the user, or explain their features in more detail. |
| 1420 | * |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1421 | * @return whether the caller is a demo user. |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 1422 | */ |
| 1423 | public boolean isDemoUser() { |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 1424 | try { |
| 1425 | return mService.isDemoUser(UserHandle.myUserId()); |
| 1426 | } catch (RemoteException re) { |
| 1427 | throw re.rethrowFromSystemServer(); |
| 1428 | } |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | /** |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 1432 | * Checks if the calling app is running in a managed profile. |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 1433 | * |
| 1434 | * @return whether the caller is in a managed profile. |
| 1435 | * @hide |
| 1436 | */ |
| 1437 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1438 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 1439 | public boolean isManagedProfile() { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 1440 | // No need for synchronization. Once it becomes non-null, it'll be non-null forever. |
| 1441 | // Worst case we might end up calling the AIDL method multiple times but that's fine. |
| 1442 | if (mIsManagedProfileCached != null) { |
| 1443 | return mIsManagedProfileCached; |
| 1444 | } |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1445 | try { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 1446 | mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId()); |
| 1447 | return mIsManagedProfileCached; |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1448 | } catch (RemoteException re) { |
| 1449 | throw re.rethrowFromSystemServer(); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * Checks if the specified user is a managed profile. |
| 1455 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller |
| 1456 | * must be in the same profile group of specified user. |
| 1457 | * |
| 1458 | * @return whether the specified user is a managed profile. |
| 1459 | * @hide |
| 1460 | */ |
| 1461 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1462 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1463 | public boolean isManagedProfile(@UserIdInt int userId) { |
Makoto Onuki | d49f3fa | 2017-01-25 14:09:48 -0800 | [diff] [blame] | 1464 | if (userId == UserHandle.myUserId()) { |
| 1465 | return isManagedProfile(); |
| 1466 | } |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1467 | try { |
| 1468 | return mService.isManagedProfile(userId); |
| 1469 | } catch (RemoteException re) { |
| 1470 | throw re.rethrowFromSystemServer(); |
| 1471 | } |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | /** |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1475 | * Gets badge for a managed profile. |
| 1476 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller |
| 1477 | * must be in the same profile group of specified user. |
| 1478 | * |
| 1479 | * @return which badge to use for the managed profile badge id will be less than |
| 1480 | * UserManagerService.getMaxManagedProfiles() |
| 1481 | * @hide |
| 1482 | */ |
| 1483 | public int getManagedProfileBadge(@UserIdInt int userId) { |
| 1484 | try { |
| 1485 | return mService.getManagedProfileBadge(userId); |
| 1486 | } catch (RemoteException re) { |
| 1487 | throw re.rethrowFromSystemServer(); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | /** |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 1492 | * Checks if the calling app is running as an ephemeral user. |
| 1493 | * |
| 1494 | * @return whether the caller is an ephemeral user. |
| 1495 | * @hide |
| 1496 | */ |
| 1497 | public boolean isEphemeralUser() { |
| 1498 | return isUserEphemeral(UserHandle.myUserId()); |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * Returns whether the specified user is ephemeral. |
| 1503 | * @hide |
| 1504 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1505 | public boolean isUserEphemeral(@UserIdInt int userId) { |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 1506 | final UserInfo user = getUserInfo(userId); |
| 1507 | return user != null && user.isEphemeral(); |
| 1508 | } |
| 1509 | |
| 1510 | /** |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1511 | * Return whether the given user is actively running. This means that |
| 1512 | * the user is in the "started" state, not "stopped" -- it is currently |
| 1513 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 1514 | * etc. A started user may be either the current foreground user or a |
| 1515 | * background user; the result here does not distinguish between the two. |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 1516 | * |
| 1517 | * <p>Note prior to Android Nougat MR1 (SDK version <= 24; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 1518 | * {@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] | 1519 | * in order to check other profile's status. |
| 1520 | * Since Android Nougat MR1 (SDK version >= 25; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 1521 | * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now |
| 1522 | * 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] | 1523 | * |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1524 | * @param user The user to retrieve the running state for. |
| 1525 | */ |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 1526 | // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS. |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1527 | public boolean isUserRunning(UserHandle user) { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 1528 | return isUserRunning(user.getIdentifier()); |
| 1529 | } |
| 1530 | |
| 1531 | /** {@hide} */ |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 1532 | public boolean isUserRunning(@UserIdInt int userId) { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1533 | try { |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 1534 | return mService.isUserRunning(userId); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1535 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1536 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Return whether the given user is actively running <em>or</em> stopping. |
| 1542 | * This is like {@link #isUserRunning(UserHandle)}, but will also return |
| 1543 | * true if the user had been running but is in the process of being stopped |
| 1544 | * (but is not yet fully stopped, and still running some code). |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 1545 | * |
| 1546 | * <p>Note prior to Android Nougat MR1 (SDK version <= 24; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 1547 | * {@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] | 1548 | * in order to check other profile's status. |
| 1549 | * Since Android Nougat MR1 (SDK version >= 25; |
Andrew Solovay | 8a788f4 | 2018-12-12 14:25:47 -0800 | [diff] [blame] | 1550 | * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now |
| 1551 | * 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] | 1552 | * |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1553 | * @param user The user to retrieve the running state for. |
| 1554 | */ |
Makoto Onuki | 5eef50d | 2017-03-02 16:38:45 -0800 | [diff] [blame] | 1555 | // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS. |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1556 | public boolean isUserRunningOrStopping(UserHandle user) { |
| 1557 | try { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 1558 | // TODO: reconcile stopped vs stopping? |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1559 | return ActivityManager.getService().isUserRunning( |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 1560 | user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1561 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1562 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 1566 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1567 | * Return whether the calling user is running in an "unlocked" state. |
| 1568 | * <p> |
| 1569 | * On devices with direct boot, a user is unlocked only after they've |
| 1570 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 1571 | * without direct boot, a user is unlocked as soon as it starts. |
| 1572 | * <p> |
| 1573 | * When a user is locked, only device-protected data storage is available. |
| 1574 | * When a user is unlocked, both device-protected and credential-protected |
| 1575 | * private app data storage is available. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1576 | * |
| 1577 | * @see Intent#ACTION_USER_UNLOCKED |
| 1578 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1579 | */ |
| 1580 | public boolean isUserUnlocked() { |
| 1581 | return isUserUnlocked(Process.myUserHandle()); |
| 1582 | } |
| 1583 | |
| 1584 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1585 | * Return whether the given user is running in an "unlocked" state. |
| 1586 | * <p> |
| 1587 | * On devices with direct boot, a user is unlocked only after they've |
| 1588 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 1589 | * without direct boot, a user is unlocked as soon as it starts. |
| 1590 | * <p> |
| 1591 | * When a user is locked, only device-protected data storage is available. |
| 1592 | * When a user is unlocked, both device-protected and credential-protected |
| 1593 | * private app data storage is available. |
Fyodor Kupolov | cdb3c2f | 2017-02-10 11:48:32 -0800 | [diff] [blame] | 1594 | * <p>Requires {@code android.permission.MANAGE_USERS} or |
| 1595 | * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} |
| 1596 | * must be the calling user or a managed profile associated with it. |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1597 | * |
| 1598 | * @param user to retrieve the unlocked state for. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1599 | * @see Intent#ACTION_USER_UNLOCKED |
| 1600 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1601 | */ |
| 1602 | public boolean isUserUnlocked(UserHandle user) { |
Jeff Sharkey | 0999c0d | 2015-12-17 15:12:22 -0700 | [diff] [blame] | 1603 | return isUserUnlocked(user.getIdentifier()); |
| 1604 | } |
| 1605 | |
| 1606 | /** {@hide} */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1607 | public boolean isUserUnlocked(@UserIdInt int userId) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1608 | try { |
Fyodor Kupolov | 2e7e096 | 2016-12-01 18:09:17 -0800 | [diff] [blame] | 1609 | return mService.isUserUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1610 | } catch (RemoteException re) { |
| 1611 | throw re.rethrowFromSystemServer(); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | /** {@hide} */ |
| 1616 | public boolean isUserUnlockingOrUnlocked(UserHandle user) { |
| 1617 | return isUserUnlockingOrUnlocked(user.getIdentifier()); |
| 1618 | } |
| 1619 | |
| 1620 | /** {@hide} */ |
| 1621 | public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { |
| 1622 | try { |
Fyodor Kupolov | c413f70 | 2016-10-06 17:11:14 -0700 | [diff] [blame] | 1623 | return mService.isUserUnlockingOrUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1624 | } catch (RemoteException re) { |
| 1625 | throw re.rethrowFromSystemServer(); |
| 1626 | } |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | /** |
Makoto Onuki | 73dded2 | 2017-12-20 13:14:48 +0900 | [diff] [blame] | 1630 | * Return the time when the calling user started in elapsed milliseconds since boot, |
| 1631 | * or 0 if not started. |
| 1632 | * |
| 1633 | * @hide |
| 1634 | */ |
| 1635 | public long getUserStartRealtime() { |
| 1636 | try { |
| 1637 | return mService.getUserStartRealtime(); |
| 1638 | } catch (RemoteException re) { |
| 1639 | throw re.rethrowFromSystemServer(); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * Return the time when the calling user was unlocked elapsed milliseconds since boot, |
| 1645 | * or 0 if not unlocked. |
| 1646 | * |
| 1647 | * @hide |
| 1648 | */ |
| 1649 | public long getUserUnlockRealtime() { |
| 1650 | try { |
| 1651 | return mService.getUserUnlockRealtime(); |
| 1652 | } catch (RemoteException re) { |
| 1653 | throw re.rethrowFromSystemServer(); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1658 | * Returns the UserInfo object describing a specific user. |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1659 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1660 | * @param userHandle the user handle of the user whose information is being requested. |
| 1661 | * @return the UserInfo object for a specific user. |
| 1662 | * @hide |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1663 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1664 | public UserInfo getUserInfo(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1665 | try { |
| 1666 | return mService.getUserInfo(userHandle); |
| 1667 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1668 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1672 | /** |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1673 | * @hide |
| 1674 | * |
| 1675 | * Returns who set a user restriction on a user. |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1676 | * @param restrictionKey the string key representing the restriction |
| 1677 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1678 | * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET}, |
| 1679 | * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER} |
| 1680 | * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER} |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 1681 | * @deprecated use {@link #getUserRestrictionSources(String, int)} instead. |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1682 | */ |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 1683 | @Deprecated |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1684 | @SystemApi |
| 1685 | @UserRestrictionSource |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1686 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1687 | public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) { |
| 1688 | try { |
| 1689 | return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier()); |
| 1690 | } catch (RemoteException re) { |
| 1691 | throw re.rethrowFromSystemServer(); |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | /** |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 1696 | * @hide |
| 1697 | * |
| 1698 | * 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] | 1699 | * @param restrictionKey the string key representing the restriction |
| 1700 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1701 | * @return a list of user ids enforcing this restriction. |
| 1702 | */ |
| 1703 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1704 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 1705 | public List<EnforcingUser> getUserRestrictionSources( |
| 1706 | String restrictionKey, UserHandle userHandle) { |
| 1707 | try { |
| 1708 | return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier()); |
| 1709 | } catch (RemoteException re) { |
| 1710 | throw re.rethrowFromSystemServer(); |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1715 | * Returns the user-wide restrictions imposed on this user. |
| 1716 | * @return a Bundle containing all the restrictions. |
| 1717 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1718 | public Bundle getUserRestrictions() { |
| 1719 | return getUserRestrictions(Process.myUserHandle()); |
| 1720 | } |
| 1721 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1722 | /** |
| 1723 | * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. |
| 1724 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1725 | * @return a Bundle containing all the restrictions. |
| 1726 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1727 | public Bundle getUserRestrictions(UserHandle userHandle) { |
| 1728 | try { |
| 1729 | return mService.getUserRestrictions(userHandle.getIdentifier()); |
| 1730 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1731 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 1735 | /** |
| 1736 | * @hide |
| 1737 | * Returns whether the given user has been disallowed from performing certain actions |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 1738 | * or setting certain settings through UserManager (e.g. this type of restriction would prevent |
| 1739 | * the guest user from doing certain things, such as making calls). This method disregards |
| 1740 | * restrictions set by device policy. |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 1741 | * @param restrictionKey the string key representing the restriction |
| 1742 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1743 | */ |
| 1744 | public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { |
| 1745 | try { |
| 1746 | return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); |
| 1747 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1748 | throw re.rethrowFromSystemServer(); |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1752 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1753 | * This will no longer work. Device owners and profile owners should use |
| 1754 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
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 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1757 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1758 | public void setUserRestrictions(Bundle restrictions) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1759 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1762 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1763 | * This will no longer work. Device owners and profile owners should use |
| 1764 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
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 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1767 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1768 | public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1769 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1770 | } |
| 1771 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1772 | /** |
| 1773 | * Sets the value of a specific restriction. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1774 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1775 | * @param key the key of the restriction |
| 1776 | * @param value the value for the restriction |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1777 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1778 | * android.content.ComponentName, String)} or |
| 1779 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1780 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1781 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1782 | @Deprecated |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1783 | public void setUserRestriction(String key, boolean value) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1784 | setUserRestriction(key, value, Process.myUserHandle()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * @hide |
| 1789 | * Sets the value of a specific restriction on a specific user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1790 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1791 | * @param key the key of the restriction |
| 1792 | * @param value the value for the restriction |
| 1793 | * @param userHandle the user whose restriction is to be changed. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1794 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1795 | * android.content.ComponentName, String)} or |
| 1796 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1797 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1798 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1799 | @Deprecated |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1800 | public void setUserRestriction(String key, boolean value, UserHandle userHandle) { |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1801 | try { |
| 1802 | mService.setUserRestriction(key, value, userHandle.getIdentifier()); |
| 1803 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1804 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1805 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1806 | } |
| 1807 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1808 | /** |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1809 | * Returns whether the current user has been disallowed from performing certain actions |
| 1810 | * or setting certain settings. |
Julia Reynolds | 2b2cf72 | 2014-06-06 11:41:04 -0400 | [diff] [blame] | 1811 | * |
| 1812 | * @param restrictionKey The string key representing the restriction. |
| 1813 | * @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] | 1814 | */ |
| 1815 | public boolean hasUserRestriction(String restrictionKey) { |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 1816 | return hasUserRestriction(restrictionKey, Process.myUserHandle()); |
| 1817 | } |
| 1818 | |
| 1819 | /** |
| 1820 | * @hide |
| 1821 | * Returns whether the given user has been disallowed from performing certain actions |
| 1822 | * or setting certain settings. |
| 1823 | * @param restrictionKey the string key representing the restriction |
| 1824 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1825 | */ |
| 1826 | public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 1827 | try { |
| 1828 | return mService.hasUserRestriction(restrictionKey, |
| 1829 | userHandle.getIdentifier()); |
| 1830 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1831 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 1832 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /** |
Makoto Onuki | acc5046 | 2018-02-14 14:13:49 -0800 | [diff] [blame] | 1836 | * @hide |
| 1837 | * Returns whether any user on the device has the given user restriction set. |
| 1838 | */ |
| 1839 | public boolean hasUserRestrictionOnAnyUser(String restrictionKey) { |
| 1840 | try { |
| 1841 | return mService.hasUserRestrictionOnAnyUser(restrictionKey); |
| 1842 | } catch (RemoteException re) { |
| 1843 | throw re.rethrowFromSystemServer(); |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | /** |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1848 | * Return the serial number for a user. This is a device-unique |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1849 | * number assigned to that user; if the user is deleted and then a new |
| 1850 | * 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] | 1851 | * @param user The user whose serial number is to be retrieved. |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1852 | * @return The serial number of the given user; returns -1 if the |
| 1853 | * given UserHandle does not exist. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1854 | * @see #getUserForSerialNumber(long) |
| 1855 | */ |
| 1856 | public long getSerialNumberForUser(UserHandle user) { |
| 1857 | return getUserSerialNumber(user.getIdentifier()); |
| 1858 | } |
| 1859 | |
| 1860 | /** |
| 1861 | * Return the user associated with a serial number previously |
| 1862 | * returned by {@link #getSerialNumberForUser(UserHandle)}. |
| 1863 | * @param serialNumber The serial number of the user that is being |
| 1864 | * retrieved. |
| 1865 | * @return Return the user associated with the serial number, or null |
| 1866 | * if there is not one. |
| 1867 | * @see #getSerialNumberForUser(UserHandle) |
| 1868 | */ |
| 1869 | public UserHandle getUserForSerialNumber(long serialNumber) { |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 1870 | int ident = getUserHandle((int) serialNumber); |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1871 | return ident >= 0 ? new UserHandle(ident) : null; |
| 1872 | } |
| 1873 | |
| 1874 | /** |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1875 | * Creates a user with the specified name and options. For non-admin users, default user |
| 1876 | * restrictions are going to be applied. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1877 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1878 | * |
| 1879 | * @param name the user's name |
| 1880 | * @param flags flags that identify the type of user and other properties. |
| 1881 | * @see UserInfo |
| 1882 | * |
| 1883 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 1884 | * @hide |
| 1885 | */ |
| 1886 | public UserInfo createUser(String name, int flags) { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1887 | UserInfo user = null; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1888 | try { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1889 | user = mService.createUser(name, flags); |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 1890 | // TODO: Keep this in sync with |
| 1891 | // UserManagerService.LocalService.createUserEvenWhenDisallowed |
Christine Franks | 97a5480 | 2017-08-09 10:06:43 -0700 | [diff] [blame] | 1892 | if (user != null && !user.isAdmin() && !user.isDemo()) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1893 | mService.setUserRestriction(DISALLOW_SMS, true, user.id); |
| 1894 | mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1895 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1896 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1897 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1898 | } |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1899 | return user; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1903 | * Creates a guest user and configures it. |
| 1904 | * @param context an application context |
| 1905 | * @param name the name to set for the user |
| 1906 | * @hide |
| 1907 | */ |
| 1908 | public UserInfo createGuest(Context context, String name) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1909 | UserInfo guest = null; |
| 1910 | try { |
| 1911 | guest = mService.createUser(name, UserInfo.FLAG_GUEST); |
| 1912 | if (guest != null) { |
| 1913 | Settings.Secure.putStringForUser(context.getContentResolver(), |
| 1914 | Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1915 | } |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1916 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1917 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1918 | } |
| 1919 | return guest; |
| 1920 | } |
| 1921 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 1922 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1923 | * 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] | 1924 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1925 | * |
| 1926 | * @param name the user's name |
| 1927 | * @param flags flags that identify the type of user and other properties. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 1928 | * @param userHandle new user will be a profile of this user. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1929 | * |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 1930 | * @return the {@link UserInfo} object for the created user, or null if the user |
| 1931 | * could not be created. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1932 | * @hide |
| 1933 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1934 | public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 1935 | return createProfileForUser(name, flags, userHandle, null); |
| 1936 | } |
| 1937 | |
| 1938 | /** |
| 1939 | * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify |
| 1940 | * any packages that should not be installed in the new profile by default, these packages can |
| 1941 | * still be installed later by the user if needed. |
| 1942 | * |
| 1943 | * @param name the user's name |
| 1944 | * @param flags flags that identify the type of user and other properties. |
| 1945 | * @param userHandle new user will be a profile of this user. |
| 1946 | * @param disallowedPackages packages that will not be installed in the profile being created. |
| 1947 | * |
| 1948 | * @return the {@link UserInfo} object for the created user, or null if the user |
| 1949 | * could not be created. |
| 1950 | * @hide |
| 1951 | */ |
| 1952 | public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle, |
| 1953 | String[] disallowedPackages) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1954 | try { |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 1955 | return mService.createProfileForUser(name, flags, userHandle, disallowedPackages); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1956 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1957 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | /** |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 1962 | * Similar to {@link #createProfileForUser(String, int, int, String[])} |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1963 | * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 1964 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1965 | * |
| 1966 | * @see #createProfileForUser(String, int, int, String[]) |
| 1967 | * @hide |
| 1968 | */ |
| 1969 | public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags, |
| 1970 | @UserIdInt int userHandle, String[] disallowedPackages) { |
| 1971 | try { |
| 1972 | return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle, |
| 1973 | disallowedPackages); |
| 1974 | } catch (RemoteException re) { |
| 1975 | throw re.rethrowFromSystemServer(); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | /** |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1980 | * Creates a restricted profile with the specified name. This method also sets necessary |
| 1981 | * restrictions and adds shared accounts. |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1982 | * |
| 1983 | * @param name profile's name |
| 1984 | * @return UserInfo object for the created user, or null if the user could not be created. |
| 1985 | * @hide |
| 1986 | */ |
| 1987 | public UserInfo createRestrictedProfile(String name) { |
| 1988 | try { |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1989 | UserHandle parentUserHandle = Process.myUserHandle(); |
| 1990 | UserInfo user = mService.createRestrictedProfile(name, |
| 1991 | parentUserHandle.getIdentifier()); |
| 1992 | if (user != null) { |
| 1993 | AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, |
| 1994 | UserHandle.of(user.id)); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1995 | } |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1996 | return user; |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1997 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1998 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1999 | } |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2003 | * Returns an intent to create a user for the provided name and account name. The name |
| 2004 | * and account name will be used when the setup process for the new user is started. |
| 2005 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2006 | * The intent should be launched using startActivityForResult and the return result will |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 2007 | * indicate if the user consented to adding a new user and if the operation succeeded. Any |
| 2008 | * errors in creating the user will be returned in the result code. If the user cancels the |
| 2009 | * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the |
| 2010 | * result code will be {@link Activity#RESULT_OK}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2011 | * <p> |
| 2012 | * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation |
| 2013 | * at all. |
| 2014 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2015 | * The new user is created but not initialized. After switching into the user for the first |
| 2016 | * time, the preferred user name and account information are used by the setup process for that |
| 2017 | * user. |
| 2018 | * |
| 2019 | * @param userName Optional name to assign to the user. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2020 | * @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] | 2021 | * the user. |
| 2022 | * @param accountType Optional account type for the account to be created. This is required |
| 2023 | * if the account name is specified. |
| 2024 | * @param accountOptions Optional bundle of data to be passed in during account creation in the |
| 2025 | * new user via {@link AccountManager#addAccount(String, String, String[], |
| 2026 | * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, |
| 2027 | * Handler)}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2028 | * @return An Intent that can be launched from an Activity. |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 2029 | * @see #USER_CREATION_FAILED_NOT_PERMITTED |
| 2030 | * @see #USER_CREATION_FAILED_NO_MORE_USERS |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 2031 | * @see #supportsMultipleUsers |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2032 | */ |
| 2033 | public static Intent createUserCreationIntent(@Nullable String userName, |
| 2034 | @Nullable String accountName, |
| 2035 | @Nullable String accountType, @Nullable PersistableBundle accountOptions) { |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2036 | Intent intent = new Intent(ACTION_CREATE_USER); |
| 2037 | if (userName != null) { |
| 2038 | intent.putExtra(EXTRA_USER_NAME, userName); |
| 2039 | } |
| 2040 | if (accountName != null && accountType == null) { |
| 2041 | throw new IllegalArgumentException("accountType must be specified if accountName is " |
| 2042 | + "specified"); |
| 2043 | } |
| 2044 | if (accountName != null) { |
| 2045 | intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); |
| 2046 | } |
| 2047 | if (accountType != null) { |
| 2048 | intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); |
| 2049 | } |
| 2050 | if (accountOptions != null) { |
| 2051 | intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); |
| 2052 | } |
| 2053 | return intent; |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * @hide |
| 2058 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2059 | * Returns the preferred account name for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2060 | */ |
| 2061 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2062 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2063 | public String getSeedAccountName() { |
| 2064 | try { |
| 2065 | return mService.getSeedAccountName(); |
| 2066 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2067 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * @hide |
| 2073 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2074 | * Returns the preferred account type for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2075 | */ |
| 2076 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2077 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2078 | public String getSeedAccountType() { |
| 2079 | try { |
| 2080 | return mService.getSeedAccountType(); |
| 2081 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2082 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | /** |
| 2087 | * @hide |
| 2088 | * |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2089 | * Returns the preferred account's options bundle for user creation. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2090 | * @return Any options set by the requestor that created the user. |
| 2091 | */ |
| 2092 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2093 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2094 | public PersistableBundle getSeedAccountOptions() { |
| 2095 | try { |
| 2096 | return mService.getSeedAccountOptions(); |
| 2097 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2098 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | /** |
| 2103 | * @hide |
| 2104 | * |
| 2105 | * Called by a system activity to set the seed account information of a user created |
| 2106 | * through the user creation intent. |
| 2107 | * @param userId |
| 2108 | * @param accountName |
| 2109 | * @param accountType |
| 2110 | * @param accountOptions |
| 2111 | * @see #createUserCreationIntent(String, String, String, PersistableBundle) |
| 2112 | */ |
| 2113 | public void setSeedAccountData(int userId, String accountName, String accountType, |
| 2114 | PersistableBundle accountOptions) { |
| 2115 | try { |
| 2116 | mService.setSeedAccountData(userId, accountName, accountType, accountOptions, |
| 2117 | /* persist= */ true); |
| 2118 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2119 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | /** |
| 2124 | * @hide |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2125 | * Clears the seed information used to create this user. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2126 | */ |
| 2127 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2128 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2129 | public void clearSeedAccountData() { |
| 2130 | try { |
| 2131 | mService.clearSeedAccountData(); |
| 2132 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2133 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | /** |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2138 | * @hide |
| 2139 | * Marks the guest user for deletion to allow a new guest to be created before deleting |
| 2140 | * the current user who is a guest. |
| 2141 | * @param userHandle |
| 2142 | * @return |
| 2143 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2144 | public boolean markGuestForDeletion(@UserIdInt int userHandle) { |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2145 | try { |
| 2146 | return mService.markGuestForDeletion(userHandle); |
| 2147 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2148 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | /** |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2153 | * Sets the user as enabled, if such an user exists. |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 2154 | * |
| 2155 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2156 | * |
| 2157 | * <p>Note that the default is true, it's only that managed profiles might not be enabled. |
| 2158 | * Also ephemeral users can be disabled to indicate that their removal is in progress and they |
| 2159 | * 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] | 2160 | * |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 2161 | * @param userId the id of the profile to enable |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2162 | * @hide |
| 2163 | */ |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 2164 | public void setUserEnabled(@UserIdInt int userId) { |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2165 | try { |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 2166 | mService.setUserEnabled(userId); |
| 2167 | } catch (RemoteException re) { |
| 2168 | throw re.rethrowFromSystemServer(); |
| 2169 | } |
| 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Assigns admin privileges to the user, if such a user exists. |
| 2174 | * |
| 2175 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} and |
| 2176 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions. |
| 2177 | * |
| 2178 | * @param userHandle the id of the user to become admin |
| 2179 | * @hide |
| 2180 | */ |
| 2181 | @RequiresPermission(allOf = { |
| 2182 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 2183 | Manifest.permission.MANAGE_USERS |
| 2184 | }) |
| 2185 | public void setUserAdmin(@UserIdInt int userHandle) { |
| 2186 | try { |
| 2187 | mService.setUserAdmin(userHandle); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2188 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2189 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2194 | * Evicts the user's credential encryption key from memory by stopping and restarting the user. |
| 2195 | * |
| 2196 | * @hide |
| 2197 | */ |
| 2198 | public void evictCredentialEncryptionKey(@UserIdInt int userHandle) { |
| 2199 | try { |
| 2200 | mService.evictCredentialEncryptionKey(userHandle); |
| 2201 | } catch (RemoteException re) { |
| 2202 | throw re.rethrowFromSystemServer(); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | /** |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 2207 | * Return the number of users currently created on the device. |
| 2208 | */ |
| 2209 | public int getUserCount() { |
| 2210 | List<UserInfo> users = getUsers(); |
| 2211 | return users != null ? users.size() : 1; |
| 2212 | } |
| 2213 | |
| 2214 | /** |
Amith Yamasani | d04aaa3 | 2016-06-13 12:09:36 -0700 | [diff] [blame] | 2215 | * Returns information for all users on this device, including ones marked for deletion. |
| 2216 | * To retrieve only users that are alive, use {@link #getUsers(boolean)}. |
| 2217 | * <p> |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 2218 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 2219 | * @return the list of users that exist on the device. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2220 | * @hide |
| 2221 | */ |
| 2222 | public List<UserInfo> getUsers() { |
| 2223 | try { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 2224 | return mService.getUsers(false); |
| 2225 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2226 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | /** |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 2231 | * Returns serial numbers of all users on this device. |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 2232 | * |
| 2233 | * @param excludeDying specify if the list should exclude users being removed. |
| 2234 | * @return the list of serial numbers of users that exist on the device. |
| 2235 | * @hide |
| 2236 | */ |
| 2237 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 2238 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 2239 | public long[] getSerialNumbersOfUsers(boolean excludeDying) { |
| 2240 | try { |
| 2241 | List<UserInfo> users = mService.getUsers(excludeDying); |
| 2242 | long[] result = new long[users.size()]; |
| 2243 | for (int i = 0; i < result.length; i++) { |
| 2244 | result[i] = users.get(i).serialNumber; |
| 2245 | } |
| 2246 | return result; |
| 2247 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2248 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | /** |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 2253 | * @return the user's account name, null if not found. |
| 2254 | * @hide |
| 2255 | */ |
| 2256 | @RequiresPermission( allOf = { |
| 2257 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 2258 | Manifest.permission.MANAGE_USERS |
| 2259 | }) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2260 | public @Nullable String getUserAccount(@UserIdInt int userHandle) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 2261 | try { |
| 2262 | return mService.getUserAccount(userHandle); |
| 2263 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2264 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * Set account name for the given user. |
| 2270 | * @hide |
| 2271 | */ |
| 2272 | @RequiresPermission( allOf = { |
| 2273 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 2274 | Manifest.permission.MANAGE_USERS |
| 2275 | }) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2276 | public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 2277 | try { |
| 2278 | mService.setUserAccount(userHandle, accountName); |
| 2279 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2280 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 2285 | * Returns information for Primary user. |
| 2286 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2287 | * |
| 2288 | * @return the Primary user, null if not found. |
| 2289 | * @hide |
| 2290 | */ |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 2291 | public @Nullable UserInfo getPrimaryUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 2292 | try { |
| 2293 | return mService.getPrimaryUser(); |
| 2294 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2295 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 2300 | * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS |
| 2301 | * permission. |
| 2302 | * |
| 2303 | * @return true if more users can be added, false if limit has been reached. |
| 2304 | * @hide |
| 2305 | */ |
| 2306 | public boolean canAddMoreUsers() { |
| 2307 | final List<UserInfo> users = getUsers(true); |
| 2308 | final int totalUserCount = users.size(); |
| 2309 | int aliveUserCount = 0; |
| 2310 | for (int i = 0; i < totalUserCount; i++) { |
| 2311 | UserInfo user = users.get(i); |
| 2312 | if (!user.isGuest()) { |
| 2313 | aliveUserCount++; |
| 2314 | } |
| 2315 | } |
| 2316 | return aliveUserCount < getMaxSupportedUsers(); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 2320 | * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS |
| 2321 | * permission. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 2322 | * if allowedToRemoveOne is true and if the user already has a managed profile, then return if |
| 2323 | * 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] | 2324 | * |
| 2325 | * @return true if more managed profiles can be added, false if limit has been reached. |
| 2326 | * @hide |
| 2327 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2328 | public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 2329 | try { |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 2330 | return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 2331 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2332 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 2337 | * Returns list of the profiles of userHandle including |
| 2338 | * userHandle itself. |
Amith Yamasani | 4f7e2e3 | 2014-08-14 18:49:48 -0700 | [diff] [blame] | 2339 | * Note that this returns both enabled and not enabled profiles. See |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 2340 | * {@link #getEnabledProfiles(int)} if you need only the enabled ones. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2341 | * |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 2342 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2343 | * @param userHandle profiles of this user will be returned. |
| 2344 | * @return the list of profiles. |
| 2345 | * @hide |
| 2346 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2347 | public List<UserInfo> getProfiles(@UserIdInt int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2348 | try { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 2349 | return mService.getProfiles(userHandle, false /* enabledOnly */); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2350 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2351 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | /** |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 2356 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2357 | * @param userId one of the two user ids to check. |
| 2358 | * @param otherUserId one of the two user ids to check. |
| 2359 | * @return true if the two user ids are in the same profile group. |
| 2360 | * @hide |
| 2361 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2362 | public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 2363 | try { |
| 2364 | return mService.isSameProfileGroup(userId, otherUserId); |
| 2365 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2366 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | /** |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 2371 | * Returns list of the profiles of userHandle including |
| 2372 | * userHandle itself. |
| 2373 | * Note that this returns only enabled. |
| 2374 | * |
| 2375 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 2376 | * @param userHandle profiles of this user will be returned. |
| 2377 | * @return the list of profiles. |
| 2378 | * @hide |
| 2379 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2380 | public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 2381 | try { |
| 2382 | return mService.getProfiles(userHandle, true /* enabledOnly */); |
| 2383 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2384 | throw re.rethrowFromSystemServer(); |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 2389 | * Returns a list of UserHandles for profiles associated with the user that the calling process |
| 2390 | * is running on, including the user itself. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2391 | * |
| 2392 | * @return A non-empty list of UserHandles associated with the calling user. |
| 2393 | */ |
| 2394 | public List<UserHandle> getUserProfiles() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2395 | int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); |
| 2396 | List<UserHandle> result = new ArrayList<>(userIds.length); |
| 2397 | for (int userId : userIds) { |
| 2398 | result.add(UserHandle.of(userId)); |
| 2399 | } |
| 2400 | return result; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * Returns a list of ids for profiles associated with the specified user including the user |
| 2405 | * itself. |
| 2406 | * |
| 2407 | * @param userId id of the user to return profiles for |
| 2408 | * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles |
| 2409 | * @return A non-empty list of ids of profiles associated with the specified user. |
| 2410 | * |
| 2411 | * @hide |
| 2412 | */ |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 2413 | @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, |
| 2414 | Manifest.permission.CREATE_USERS}, conditional = true) |
Philip P. Moltmann | 4e615e6 | 2018-08-28 14:57:49 -0700 | [diff] [blame] | 2415 | public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 2416 | try { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2417 | return mService.getProfileIds(userId, enabledOnly); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 2418 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2419 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 2420 | } |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * @see #getProfileIds(int, boolean) |
| 2425 | * @hide |
| 2426 | */ |
| 2427 | public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { |
| 2428 | return getProfileIds(userId, false /* enabledOnly */); |
| 2429 | } |
| 2430 | |
| 2431 | /** |
| 2432 | * @see #getProfileIds(int, boolean) |
| 2433 | * @hide |
| 2434 | */ |
| 2435 | public int[] getEnabledProfileIds(@UserIdInt int userId) { |
| 2436 | return getProfileIds(userId, true /* enabledOnly */); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 2439 | /** |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 2440 | * Returns the device credential owner id of the profile from |
| 2441 | * which this method is called, or userHandle if called from a user that |
| 2442 | * is not a profile. |
| 2443 | * |
| 2444 | * @hide |
| 2445 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2446 | public int getCredentialOwnerProfile(@UserIdInt int userHandle) { |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 2447 | try { |
| 2448 | return mService.getCredentialOwnerProfile(userHandle); |
| 2449 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2450 | throw re.rethrowFromSystemServer(); |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 2455 | * Returns the parent of the profile which this method is called from |
| 2456 | * or null if called from a user that is not a profile. |
| 2457 | * |
| 2458 | * @hide |
| 2459 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2460 | public UserInfo getProfileParent(@UserIdInt int userHandle) { |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 2461 | try { |
| 2462 | return mService.getProfileParent(userHandle); |
| 2463 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2464 | throw re.rethrowFromSystemServer(); |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | /** |
Philip P. Moltmann | a3e358c | 2018-11-21 12:45:50 -0800 | [diff] [blame] | 2469 | * Get the parent of a user profile. |
| 2470 | * |
| 2471 | * @param user the handle of the user profile |
| 2472 | * |
| 2473 | * @return the parent of the user or {@code null} if the user is not profile |
| 2474 | * |
| 2475 | * @hide |
| 2476 | */ |
| 2477 | @SystemApi |
| 2478 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 2479 | public @Nullable UserHandle getProfileParent(@NonNull UserHandle user) { |
| 2480 | UserInfo info = getProfileParent(user.getIdentifier()); |
| 2481 | |
| 2482 | if (info == null) { |
| 2483 | return null; |
| 2484 | } |
| 2485 | |
| 2486 | return UserHandle.of(info.id); |
| 2487 | } |
| 2488 | |
| 2489 | /** |
Tony Mak | e3d1f65 | 2017-12-12 11:00:37 +0000 | [diff] [blame] | 2490 | * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a |
| 2491 | * managed profile don't run, generate notifications, or consume data or battery. |
| 2492 | * <p> |
| 2493 | * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be |
| 2494 | * shown to the user. |
| 2495 | * <p> |
| 2496 | * The change may not happen instantly, however apps can listen for |
| 2497 | * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and |
| 2498 | * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of |
| 2499 | * the change of the quiet mode. Apps can also check the current state of quiet mode by |
| 2500 | * calling {@link #isQuietModeEnabled(UserHandle)}. |
| 2501 | * <p> |
| 2502 | * The caller must either be the foreground default launcher or have one of these permissions: |
| 2503 | * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}. |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2504 | * |
Tony Mak | e3d1f65 | 2017-12-12 11:00:37 +0000 | [diff] [blame] | 2505 | * @param enableQuietMode whether quiet mode should be enabled or disabled |
| 2506 | * @param userHandle user handle of the profile |
| 2507 | * @return {@code false} if user's credential is needed in order to turn off quiet mode, |
| 2508 | * {@code true} otherwise |
| 2509 | * @throws SecurityException if the caller is invalid |
| 2510 | * @throws IllegalArgumentException if {@code userHandle} is not a managed profile |
| 2511 | * |
| 2512 | * @see #isQuietModeEnabled(UserHandle) |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2513 | */ |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 2514 | public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) { |
| 2515 | return requestQuietModeEnabled(enableQuietMode, userHandle, null); |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /** |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 2519 | * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify |
Tony Mak | d390ae9 | 2017-12-28 13:23:10 +0000 | [diff] [blame] | 2520 | * a target to start when user is unlocked. If {@code target} is specified, caller must have |
| 2521 | * the {@link android.Manifest.permission#MANAGE_USERS} permission. |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 2522 | * |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 2523 | * @see {@link #requestQuietModeEnabled(boolean, UserHandle)} |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2524 | * @hide |
| 2525 | */ |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 2526 | public boolean requestQuietModeEnabled( |
Tony Mak | b7e6fd4 | 2017-12-05 19:40:28 +0000 | [diff] [blame] | 2527 | boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) { |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2528 | try { |
Tony Mak | bece85d | 2018-01-12 12:10:17 +0000 | [diff] [blame] | 2529 | return mService.requestQuietModeEnabled( |
Tony Mak | e3d1f65 | 2017-12-12 11:00:37 +0000 | [diff] [blame] | 2530 | mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2531 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2532 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | /** |
| 2537 | * Returns whether the given profile is in quiet mode or not. |
Ricky Wai | 7881cf8 | 2016-04-15 17:20:12 +0100 | [diff] [blame] | 2538 | * Notes: Quiet mode is only supported for managed profiles. |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2539 | * |
| 2540 | * @param userHandle The user handle of the profile to be queried. |
| 2541 | * @return true if the profile is in quiet mode, false otherwise. |
| 2542 | */ |
| 2543 | public boolean isQuietModeEnabled(UserHandle userHandle) { |
| 2544 | try { |
| 2545 | return mService.isQuietModeEnabled(userHandle.getIdentifier()); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2546 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2547 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2548 | } |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | /** |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 2552 | * If the target user is a managed profile of the calling user or the caller |
| 2553 | * 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] | 2554 | * icon to be able to distinguish it from the original icon. For badging an |
| 2555 | * arbitrary drawable use {@link #getBadgedDrawableForUser( |
| 2556 | * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. |
| 2557 | * <p> |
| 2558 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 2559 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2560 | * is performed in place and the original drawable is returned. |
| 2561 | * </p> |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 2562 | * |
| 2563 | * @param icon The icon to badge. |
| 2564 | * @param user The target user. |
| 2565 | * @return A drawable that combines the original icon and a badge as |
| 2566 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2567 | * @removed |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 2568 | */ |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2569 | public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2570 | return mContext.getPackageManager().getUserBadgedIcon(icon, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2571 | } |
| 2572 | |
Kenny Guy | 701ea7c | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2573 | /** |
| 2574 | * 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] | 2575 | * is itself a managed profile, then this returns a badged copy of the given |
| 2576 | * drawable allowing the user to distinguish it from the original drawable. |
| 2577 | * The caller can specify the location in the bounds of the drawable to be |
| 2578 | * badged where the badge should be applied as well as the density of the |
| 2579 | * badge to be used. |
| 2580 | * <p> |
| 2581 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 2582 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2583 | * is performed in place and the original drawable is returned. |
| 2584 | * </p> |
| 2585 | * |
| 2586 | * @param badgedDrawable The drawable to badge. |
| 2587 | * @param user The target user. |
| 2588 | * @param badgeLocation Where in the bounds of the badged drawable to place |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 2589 | * 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] | 2590 | * drawable being badged. |
| 2591 | * @param badgeDensity The optional desired density for the badge as per |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 2592 | * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2593 | * the density of the display is used. |
| 2594 | * @return A drawable that combines the original drawable and a badge as |
| 2595 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2596 | * @removed |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2597 | */ |
| 2598 | public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, |
| 2599 | Rect badgeLocation, int badgeDensity) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2600 | return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, |
| 2601 | badgeLocation, badgeDensity); |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /** |
| 2605 | * 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] | 2606 | * is itself a managed profile, then this returns a copy of the label with |
| 2607 | * badging for accessibility services like talkback. E.g. passing in "Email" |
| 2608 | * and it might return "Work Email" for Email in the work profile. |
| 2609 | * |
| 2610 | * @param label The label to change. |
| 2611 | * @param user The target user. |
| 2612 | * @return A label that combines the original label and a badge as |
| 2613 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2614 | * @removed |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 2615 | */ |
Kenny Guy | 237aecd | 2014-07-21 14:06:09 +0100 | [diff] [blame] | 2616 | public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2617 | return mContext.getPackageManager().getUserBadgedLabel(label, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | /** |
| 2621 | * Returns information for all users on this device. Requires |
| 2622 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 2623 | * |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 2624 | * @param excludeDying specify if the list should exclude users being |
| 2625 | * removed. |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 2626 | * @return the list of users that were created. |
| 2627 | * @hide |
| 2628 | */ |
Adam Lesinski | ada8deb | 2017-05-12 13:50:42 -0700 | [diff] [blame] | 2629 | public @NonNull List<UserInfo> getUsers(boolean excludeDying) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 2630 | try { |
| 2631 | return mService.getUsers(excludeDying); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2632 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2633 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * Removes a user and all associated data. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 2639 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2640 | * @param userHandle the integer handle of the user, where 0 is the primary user. |
| 2641 | * @hide |
| 2642 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2643 | public boolean removeUser(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2644 | try { |
| 2645 | return mService.removeUser(userHandle); |
| 2646 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2647 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | /** |
Varun Shah | e38c678 | 2018-12-04 16:57:49 -0800 | [diff] [blame] | 2652 | * Removes a user and all associated data. |
| 2653 | * |
| 2654 | * @param user the user that needs to be removed. |
| 2655 | * @hide |
| 2656 | */ |
| 2657 | @SystemApi |
| 2658 | @RequiresPermission(android.Manifest.permission.MANAGE_USERS) |
| 2659 | public boolean removeUser(UserHandle user) { |
| 2660 | return removeUser(user.getIdentifier()); |
| 2661 | } |
| 2662 | |
| 2663 | |
| 2664 | /** |
Nicolas Prevot | d37c4a9 | 2017-01-23 11:56:00 +0000 | [diff] [blame] | 2665 | * Similar to {@link #removeUser(int)} except bypassing the checking of |
| 2666 | * {@link UserManager#DISALLOW_REMOVE_USER} |
| 2667 | * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}. |
| 2668 | * |
| 2669 | * @see {@link #removeUser(int)} |
| 2670 | * @hide |
| 2671 | */ |
| 2672 | public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) { |
| 2673 | try { |
| 2674 | return mService.removeUserEvenWhenDisallowed(userHandle); |
| 2675 | } catch (RemoteException re) { |
| 2676 | throw re.rethrowFromSystemServer(); |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2681 | * Updates the user's name. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 2682 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2683 | * |
| 2684 | * @param userHandle the user's integer handle |
| 2685 | * @param name the new name for the user |
| 2686 | * @hide |
| 2687 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2688 | public void setUserName(@UserIdInt int userHandle, String name) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2689 | try { |
| 2690 | mService.setUserName(userHandle, name); |
| 2691 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2692 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | /** |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 2697 | * Sets the user's photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2698 | * @param userHandle the user for whom to change the photo. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 2699 | * @param icon the bitmap to set as the photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2700 | * @hide |
| 2701 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2702 | public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2703 | try { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 2704 | mService.setUserIcon(userHandle, icon); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2705 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2706 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | /** |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2711 | * Returns a file descriptor for the user's photo. PNG data can be read from this file. |
| 2712 | * @param userHandle the user whose photo we want to read. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 2713 | * @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] | 2714 | * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2715 | * @hide |
| 2716 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2717 | public Bitmap getUserIcon(@UserIdInt int userHandle) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2718 | try { |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 2719 | ParcelFileDescriptor fd = mService.getUserIcon(userHandle); |
| 2720 | if (fd != null) { |
| 2721 | try { |
| 2722 | return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); |
| 2723 | } finally { |
| 2724 | try { |
| 2725 | fd.close(); |
| 2726 | } catch (IOException e) { |
| 2727 | } |
| 2728 | } |
| 2729 | } |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2730 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2731 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2732 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 2733 | return null; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2737 | * Returns the maximum number of users that can be created on this device. A return value |
| 2738 | * of 1 means that it is a single user device. |
| 2739 | * @hide |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 2740 | * @return a value greater than or equal to 1 |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2741 | */ |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 2742 | public static int getMaxSupportedUsers() { |
Amith Yamasani | ff54920 | 2012-10-12 12:44:49 -0700 | [diff] [blame] | 2743 | // Don't allow multiple users on certain builds |
| 2744 | if (android.os.Build.ID.startsWith("JVP")) return 1; |
Robin Lee | 83c7931 | 2018-02-09 19:27:18 +0100 | [diff] [blame] | 2745 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 2746 | // Low-ram devices are Svelte. Most of the time they don't get multi-user. |
| 2747 | if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) |
| 2748 | != Configuration.UI_MODE_TYPE_TELEVISION) { |
| 2749 | return 1; |
| 2750 | } |
| 2751 | } |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 2752 | return SystemProperties.getInt("fw.max_users", |
| 2753 | Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2754 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2755 | |
| 2756 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2757 | * Returns true if the user switcher should be shown, this will be if device supports multi-user |
| 2758 | * 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] | 2759 | * @hide |
| 2760 | * @return true if user switcher should be shown. |
| 2761 | */ |
| 2762 | public boolean isUserSwitcherEnabled() { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2763 | if (!supportsMultipleUsers()) { |
| 2764 | return false; |
| 2765 | } |
Benjamin Franz | ff66fa9 | 2017-08-10 10:39:44 +0100 | [diff] [blame] | 2766 | if (hasUserRestriction(DISALLOW_USER_SWITCH)) { |
| 2767 | return false; |
| 2768 | } |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 2769 | // If Demo Mode is on, don't show user switcher |
| 2770 | if (isDeviceInDemoMode(mContext)) { |
| 2771 | return false; |
| 2772 | } |
Fan Zhang | c69c8b6 | 2018-06-05 13:30:11 -0700 | [diff] [blame] | 2773 | // If user disabled this feature, don't show switcher |
| 2774 | final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(), |
| 2775 | Settings.Global.USER_SWITCHER_ENABLED, 1) != 0; |
| 2776 | if (!userSwitcherEnabled) { |
| 2777 | return false; |
| 2778 | } |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2779 | List<UserInfo> users = getUsers(true); |
| 2780 | if (users == null) { |
| 2781 | return false; |
| 2782 | } |
| 2783 | int switchableUserCount = 0; |
| 2784 | for (UserInfo user : users) { |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 2785 | if (user.supportsSwitchToByUser()) { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2786 | ++switchableUserCount; |
| 2787 | } |
| 2788 | } |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2789 | final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) |
| 2790 | .getGuestUserDisabled(null); |
Amith Yamasani | a596ff8 | 2014-06-12 18:12:38 -0700 | [diff] [blame] | 2791 | return switchableUserCount > 1 || guestEnabled; |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | /** |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 2795 | * @hide |
| 2796 | */ |
| 2797 | public static boolean isDeviceInDemoMode(Context context) { |
| 2798 | return Settings.Global.getInt(context.getContentResolver(), |
| 2799 | Settings.Global.DEVICE_DEMO_MODE, 0) > 0; |
| 2800 | } |
| 2801 | |
| 2802 | /** |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2803 | * Returns a serial number on this device for a given userHandle. User handles can be recycled |
| 2804 | * when deleting and creating users, but serial numbers are not reused until the device is wiped. |
| 2805 | * @param userHandle |
| 2806 | * @return a serial number associated with that user, or -1 if the userHandle is not valid. |
| 2807 | * @hide |
| 2808 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2809 | public int getUserSerialNumber(@UserIdInt int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2810 | try { |
| 2811 | return mService.getUserSerialNumber(userHandle); |
| 2812 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2813 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2814 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | /** |
| 2818 | * Returns a userHandle on this device for a given user serial number. User handles can be |
| 2819 | * recycled when deleting and creating users, but serial numbers are not reused until the device |
| 2820 | * is wiped. |
| 2821 | * @param userSerialNumber |
| 2822 | * @return the userHandle associated with that user serial number, or -1 if the serial number |
| 2823 | * is not valid. |
| 2824 | * @hide |
| 2825 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2826 | public @UserIdInt int getUserHandle(int userSerialNumber) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2827 | try { |
| 2828 | return mService.getUserHandle(userSerialNumber); |
| 2829 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2830 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2831 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2832 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 2833 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2834 | /** |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 2835 | * 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] | 2836 | * 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] | 2837 | * |
| 2838 | * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, |
| 2839 | * where the types of values may be: |
| 2840 | * <ul> |
| 2841 | * <li>{@code boolean} |
| 2842 | * <li>{@code int} |
| 2843 | * <li>{@code String} or {@code String[]} |
| 2844 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 2845 | * </ul> |
| 2846 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 2847 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 2848 | * |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2849 | * @param packageName the package name of the calling application |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 2850 | * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle} |
| 2851 | * if there are no saved restrictions. |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 2852 | * |
| 2853 | * @see #KEY_RESTRICTIONS_PENDING |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2854 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 2855 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2856 | public Bundle getApplicationRestrictions(String packageName) { |
| 2857 | try { |
| 2858 | return mService.getApplicationRestrictions(packageName); |
| 2859 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2860 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2861 | } |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2862 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2863 | |
| 2864 | /** |
| 2865 | * @hide |
| 2866 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 2867 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2868 | public Bundle getApplicationRestrictions(String packageName, UserHandle user) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2869 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2870 | return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2871 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2872 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2873 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | /** |
| 2877 | * @hide |
| 2878 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 2879 | @WorkerThread |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2880 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2881 | UserHandle user) { |
| 2882 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2883 | mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2884 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2885 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2886 | } |
| 2887 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2888 | |
| 2889 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 2890 | * Sets a new challenge PIN for restrictions. This is only for use by pre-installed |
| 2891 | * apps and requires the MANAGE_USERS permission. |
| 2892 | * @param newPin the PIN to use for challenge dialogs. |
| 2893 | * @return Returns true if the challenge PIN was set successfully. |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 2894 | * @deprecated The restrictions PIN functionality is no longer provided by the system. |
| 2895 | * This method is preserved for backwards compatibility reasons and always returns false. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2896 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 2897 | @Deprecated |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 2898 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2899 | return false; |
| 2900 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 2901 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2902 | /** |
| 2903 | * @hide |
| 2904 | * Set restrictions that should apply to any future guest user that's created. |
| 2905 | */ |
| 2906 | public void setDefaultGuestRestrictions(Bundle restrictions) { |
| 2907 | try { |
| 2908 | mService.setDefaultGuestRestrictions(restrictions); |
| 2909 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2910 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | /** |
| 2915 | * @hide |
| 2916 | * Gets the default guest restrictions. |
| 2917 | */ |
| 2918 | public Bundle getDefaultGuestRestrictions() { |
| 2919 | try { |
| 2920 | return mService.getDefaultGuestRestrictions(); |
| 2921 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2922 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2923 | } |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2924 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2925 | |
| 2926 | /** |
| 2927 | * Returns creation time of the user or of a managed profile associated with the calling user. |
| 2928 | * @param userHandle user handle of the user or a managed profile associated with the |
| 2929 | * calling user. |
| 2930 | * @return creation time in milliseconds since Epoch time. |
| 2931 | */ |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 2932 | public long getUserCreationTime(UserHandle userHandle) { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2933 | try { |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 2934 | return mService.getUserCreationTime(userHandle.getIdentifier()); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2935 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2936 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2937 | } |
| 2938 | } |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2939 | |
| 2940 | /** |
| 2941 | * @hide |
| 2942 | * Checks if any uninitialized user has the specific seed account name and type. |
| 2943 | * |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2944 | * @param accountName The account name to check for |
| 2945 | * @param accountType The account type of the account to check for |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2946 | * @return whether the seed account was found |
| 2947 | */ |
| 2948 | public boolean someUserHasSeedAccount(String accountName, String accountType) { |
| 2949 | try { |
| 2950 | return mService.someUserHasSeedAccount(accountName, accountType); |
| 2951 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2952 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2953 | } |
| 2954 | } |
Pavel Grafov | 6a40f09 | 2016-10-25 15:46:51 +0100 | [diff] [blame] | 2955 | |
| 2956 | /** |
| 2957 | * @hide |
| 2958 | * User that enforces a restriction. |
| 2959 | * |
| 2960 | * @see #getUserRestrictionSources(String, UserHandle) |
| 2961 | */ |
| 2962 | @SystemApi |
| 2963 | public static final class EnforcingUser implements Parcelable { |
| 2964 | private final @UserIdInt int userId; |
| 2965 | private final @UserRestrictionSource int userRestrictionSource; |
| 2966 | |
| 2967 | /** |
| 2968 | * @hide |
| 2969 | */ |
| 2970 | public EnforcingUser( |
| 2971 | @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) { |
| 2972 | this.userId = userId; |
| 2973 | this.userRestrictionSource = userRestrictionSource; |
| 2974 | } |
| 2975 | |
| 2976 | private EnforcingUser(Parcel in) { |
| 2977 | userId = in.readInt(); |
| 2978 | userRestrictionSource = in.readInt(); |
| 2979 | } |
| 2980 | |
| 2981 | public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() { |
| 2982 | @Override |
| 2983 | public EnforcingUser createFromParcel(Parcel in) { |
| 2984 | return new EnforcingUser(in); |
| 2985 | } |
| 2986 | |
| 2987 | @Override |
| 2988 | public EnforcingUser[] newArray(int size) { |
| 2989 | return new EnforcingUser[size]; |
| 2990 | } |
| 2991 | }; |
| 2992 | |
| 2993 | @Override |
| 2994 | public int describeContents() { |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | @Override |
| 2999 | public void writeToParcel(Parcel dest, int flags) { |
| 3000 | dest.writeInt(userId); |
| 3001 | dest.writeInt(userRestrictionSource); |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * Returns an id of the enforcing user. |
| 3006 | * |
| 3007 | * <p> Will be UserHandle.USER_NULL when restriction is set by the system. |
| 3008 | */ |
| 3009 | public UserHandle getUserHandle() { |
| 3010 | return UserHandle.of(userId); |
| 3011 | } |
| 3012 | |
| 3013 | /** |
| 3014 | * Returns the status of the enforcing user. |
| 3015 | * |
| 3016 | * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM}, |
| 3017 | * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and |
| 3018 | * {@link #RESTRICTION_SOURCE_PROFILE_OWNER} |
| 3019 | */ |
| 3020 | public @UserRestrictionSource int getUserRestrictionSource() { |
| 3021 | return userRestrictionSource; |
| 3022 | } |
| 3023 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3024 | } |