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