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