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; |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 25 | import android.annotation.UserIdInt; |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 26 | import android.app.Activity; |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 27 | import android.app.ActivityManager; |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 28 | import android.app.ActivityManagerNative; |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 32 | import android.content.Intent; |
Benjamin Franz | f02420c | 2016-04-04 18:52:21 +0100 | [diff] [blame] | 33 | import android.content.IntentSender; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 34 | import android.content.pm.UserInfo; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 35 | import android.content.res.Resources; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 37 | import android.graphics.BitmapFactory; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 38 | import android.graphics.Rect; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 41 | import android.telephony.TelephonyManager; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 42 | import android.view.WindowManager.LayoutParams; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 43 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 44 | import com.android.internal.R; |
| 45 | |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 46 | import java.io.IOException; |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 47 | import java.lang.annotation.Retention; |
| 48 | import java.lang.annotation.RetentionPolicy; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 49 | import java.util.ArrayList; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 50 | import java.util.List; |
| 51 | |
| 52 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 53 | * Manages users and user details on a multi-user system. There are two major categories of |
| 54 | * users: fully customizable users with their own login, and managed profiles that share a workspace |
| 55 | * with a related user. |
| 56 | * <p> |
| 57 | * Users are different from accounts, which are managed by |
| 58 | * {@link AccountManager}. Each user can have their own set of accounts. |
| 59 | * <p> |
| 60 | * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 61 | */ |
| 62 | public class UserManager { |
| 63 | |
| 64 | private static String TAG = "UserManager"; |
| 65 | private final IUserManager mService; |
| 66 | private final Context mContext; |
| 67 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 68 | /** |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 69 | * @hide |
| 70 | * No user restriction. |
| 71 | */ |
| 72 | @SystemApi |
| 73 | public static final int RESTRICTION_NOT_SET = 0x0; |
| 74 | |
| 75 | /** |
| 76 | * @hide |
| 77 | * User restriction set by system/user. |
| 78 | */ |
| 79 | @SystemApi |
| 80 | public static final int RESTRICTION_SOURCE_SYSTEM = 0x1; |
| 81 | |
| 82 | /** |
| 83 | * @hide |
| 84 | * User restriction set by a device owner. |
| 85 | */ |
| 86 | @SystemApi |
| 87 | public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2; |
| 88 | |
| 89 | /** |
| 90 | * @hide |
| 91 | * User restriction set by a profile owner. |
| 92 | */ |
| 93 | @SystemApi |
| 94 | public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4; |
| 95 | |
| 96 | /** @hide */ |
| 97 | @Retention(RetentionPolicy.SOURCE) |
| 98 | @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM, |
| 99 | RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER}) |
| 100 | @SystemApi |
| 101 | public @interface UserRestrictionSource {} |
| 102 | |
| 103 | /** |
Fyodor Kupolov | 5301928 | 2015-07-21 11:48:18 -0700 | [diff] [blame] | 104 | * Specifies if a user is disallowed from adding and removing accounts, unless they are |
| 105 | * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by |
| 106 | * Authenticator. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 107 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 108 | * |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 109 | * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still |
| 110 | * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 111 | * management is disallowed. |
| 112 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 113 | * <p>Key for user restrictions. |
| 114 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 115 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 116 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 117 | * @see #getUserRestrictions() |
| 118 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 119 | public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 122 | * Specifies if a user is disallowed from changing Wi-Fi |
Julia Reynolds | 2cb384f | 2014-08-13 15:15:55 -0400 | [diff] [blame] | 123 | * access points. The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 124 | * <p>This restriction has no effect in a managed profile. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 125 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 126 | * <p>Key for user restrictions. |
| 127 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 128 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 129 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 130 | * @see #getUserRestrictions() |
| 131 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 132 | public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 133 | |
| 134 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 135 | * Specifies if a user is disallowed from installing applications. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 136 | * The default value is <code>false</code>. |
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_INSTALL_APPS = "no_install_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 147 | * Specifies if a user is disallowed from uninstalling applications. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 148 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 149 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 150 | * <p>Key for user restrictions. |
| 151 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 152 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 153 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 154 | * @see #getUserRestrictions() |
| 155 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 156 | public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 157 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 158 | /** |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 159 | * Specifies if a user is disallowed from turning on location sharing. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 160 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 161 | * <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] | 162 | * 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] | 163 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 164 | * <p>Key for user restrictions. |
| 165 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 166 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 167 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 168 | * @see #getUserRestrictions() |
| 169 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 170 | public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 171 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 172 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 173 | * Specifies if a user is disallowed from enabling the |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 174 | * "Unknown Sources" setting, that allows installation of apps from unknown sources. |
| 175 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 176 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 177 | * <p>Key for user restrictions. |
| 178 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 179 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 180 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 181 | * @see #getUserRestrictions() |
| 182 | */ |
| 183 | public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; |
| 184 | |
| 185 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 186 | * Specifies if a user is disallowed from configuring bluetooth. |
Nicolas Prevot | 1c4c442 | 2015-02-16 11:32:21 +0000 | [diff] [blame] | 187 | * 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] | 188 | * The default value is <code>false</code>. |
Lenka Trochtova | 13a0519 | 2016-12-02 12:19:39 +0100 | [diff] [blame] | 189 | * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of |
| 190 | * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 191 | * <p>This restriction has no effect in a managed profile. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 192 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 193 | * <p>Key for user restrictions. |
| 194 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 195 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 196 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 197 | * @see #getUserRestrictions() |
| 198 | */ |
| 199 | public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; |
| 200 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 201 | /** |
Lenka Trochtova | 13a0519 | 2016-12-02 12:19:39 +0100 | [diff] [blame] | 202 | * Specifies if bluetooth is disallowed on the device. |
| 203 | * |
| 204 | * <p> This restriction can only be set by the device owner and the profile owner on the |
| 205 | * primary user and it applies globally - i.e. it disables bluetooth on the entire device. |
| 206 | * <p>The default value is <code>false</code>. |
| 207 | * <p>Key for user restrictions. |
| 208 | * <p>Type: Boolean |
| 209 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 210 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 211 | * @see #getUserRestrictions() |
| 212 | */ |
| 213 | public static final String DISALLOW_BLUETOOTH = "no_bluetooth"; |
| 214 | |
| 215 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 216 | * Specifies if a user is disallowed from transferring files over |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 217 | * USB. This can only be set by device owners and profile owners on the primary user. |
| 218 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 219 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 220 | * <p>Key for user restrictions. |
| 221 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 222 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 223 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 224 | * @see #getUserRestrictions() |
| 225 | */ |
| 226 | public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; |
| 227 | |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 228 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 229 | * Specifies if a user is disallowed from configuring user |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 230 | * credentials. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 231 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 232 | * <p>Key for user restrictions. |
| 233 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 234 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 235 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 236 | * @see #getUserRestrictions() |
| 237 | */ |
| 238 | public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; |
| 239 | |
| 240 | /** |
Amith Yamasani | 150514b | 2015-01-07 16:05:05 -0800 | [diff] [blame] | 241 | * When set on the primary user this specifies if the user can remove other users. |
| 242 | * When set on a secondary user, this specifies if the user can remove itself. |
| 243 | * This restriction has no effect on managed profiles. |
| 244 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 245 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 246 | * <p>Key for user restrictions. |
| 247 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 248 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 249 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 250 | * @see #getUserRestrictions() |
| 251 | */ |
| 252 | public static final String DISALLOW_REMOVE_USER = "no_remove_user"; |
| 253 | |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 254 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 255 | * Specifies if a user is disallowed from enabling or |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 256 | * accessing debugging features. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 257 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 258 | * <p>Key for user restrictions. |
| 259 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 260 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 261 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 262 | * @see #getUserRestrictions() |
| 263 | */ |
| 264 | public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; |
| 265 | |
| 266 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 267 | * Specifies if a user is disallowed from configuring VPN. |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 268 | * The default value is <code>false</code>. |
Nicolas Prevot | 298f98f | 2015-05-22 16:43:03 -0700 | [diff] [blame] | 269 | * This restriction has an effect in a managed profile only from |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 270 | * {@link android.os.Build.VERSION_CODES#M} |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 271 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 272 | * <p>Key for user restrictions. |
| 273 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 274 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 275 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 276 | * @see #getUserRestrictions() |
| 277 | */ |
| 278 | public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; |
| 279 | |
| 280 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 281 | * Specifies if a user is disallowed from configuring Tethering |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 282 | * & portable hotspots. This can only be set by device owners and profile owners on the |
| 283 | * primary user. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 284 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 285 | * <p>Key for user restrictions. |
| 286 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 287 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 288 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 289 | * @see #getUserRestrictions() |
| 290 | */ |
| 291 | public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; |
| 292 | |
| 293 | /** |
Stuart Scott | e3e314d | 2015-04-20 14:07:45 -0700 | [diff] [blame] | 294 | * Specifies if a user is disallowed from resetting network settings |
| 295 | * from Settings. This can only be set by device owners and profile owners on the primary user. |
| 296 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 297 | * <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] | 298 | * primary user can reset the network settings of the device. |
| 299 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 300 | * <p>Key for user restrictions. |
| 301 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 302 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 303 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Stuart Scott | e3e314d | 2015-04-20 14:07:45 -0700 | [diff] [blame] | 304 | * @see #getUserRestrictions() |
| 305 | */ |
| 306 | public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; |
| 307 | |
| 308 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 309 | * Specifies if a user is disallowed from factory resetting |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 310 | * from Settings. This can only be set by device owners and profile owners on the primary user. |
| 311 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 312 | * <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] | 313 | * primary user can factory reset the device. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 314 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 315 | * <p>Key for user restrictions. |
| 316 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 317 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 318 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 319 | * @see #getUserRestrictions() |
| 320 | */ |
| 321 | public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; |
| 322 | |
| 323 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 324 | * Specifies if a user is disallowed from adding new users and |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 325 | * profiles. This can only be set by device owners and profile owners on the primary user. |
| 326 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 327 | * <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] | 328 | * primary user can add other users. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 329 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 330 | * <p>Key for user restrictions. |
| 331 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 332 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 333 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 334 | * @see #getUserRestrictions() |
| 335 | */ |
| 336 | public static final String DISALLOW_ADD_USER = "no_add_user"; |
| 337 | |
| 338 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 339 | * Specifies if a user is disallowed from disabling application |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 340 | * verification. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 341 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 342 | * <p>Key for user restrictions. |
| 343 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 344 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 345 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 346 | * @see #getUserRestrictions() |
| 347 | */ |
| 348 | public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; |
| 349 | |
| 350 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 351 | * Specifies if a user is disallowed from configuring cell |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 352 | * broadcasts. This can only be set by device owners and profile owners on the primary user. |
| 353 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 354 | * <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] | 355 | * primary user can configure cell broadcasts. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 356 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 357 | * <p>Key for user restrictions. |
| 358 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 359 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 360 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 361 | * @see #getUserRestrictions() |
| 362 | */ |
| 363 | public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; |
| 364 | |
| 365 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 366 | * Specifies if a user is disallowed from configuring mobile |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 367 | * networks. This can only be set by device owners and profile owners on the primary user. |
| 368 | * The default value is <code>false</code>. |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 369 | * <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] | 370 | * primary user can configure mobile networks. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 371 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 372 | * <p>Key for user restrictions. |
| 373 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 374 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 375 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 376 | * @see #getUserRestrictions() |
| 377 | */ |
| 378 | public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; |
| 379 | |
| 380 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 381 | * Specifies if a user is disallowed from modifying |
Julia Reynolds | c617f81 | 2014-07-25 16:32:27 -0400 | [diff] [blame] | 382 | * applications in Settings or launchers. The following actions will not be allowed when this |
| 383 | * restriction is enabled: |
| 384 | * <li>uninstalling apps</li> |
| 385 | * <li>disabling apps</li> |
| 386 | * <li>clearing app caches</li> |
| 387 | * <li>clearing app data</li> |
| 388 | * <li>force stopping apps</li> |
| 389 | * <li>clearing app defaults</li> |
| 390 | * <p> |
| 391 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 392 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 393 | * <p>Key for user restrictions. |
| 394 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 395 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 396 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 397 | * @see #getUserRestrictions() |
| 398 | */ |
Julia Reynolds | 36fbc8d | 2014-06-18 09:26:30 -0400 | [diff] [blame] | 399 | public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 400 | |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 401 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 402 | * Specifies if a user is disallowed from mounting |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 403 | * physical external media. This can only be set by device owners and profile owners on the |
| 404 | * primary user. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 405 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 406 | * <p>Key for user restrictions. |
| 407 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 408 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 409 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 410 | * @see #getUserRestrictions() |
| 411 | */ |
| 412 | public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; |
| 413 | |
| 414 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 415 | * Specifies if a user is disallowed from adjusting microphone |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 416 | * volume. If set, the microphone will be muted. This can only be set by device owners |
| 417 | * and profile owners on the primary user. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 418 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 419 | * <p>Key for user restrictions. |
| 420 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 421 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 422 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 423 | * @see #getUserRestrictions() |
| 424 | */ |
| 425 | public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; |
| 426 | |
| 427 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 428 | * Specifies if a user is disallowed from adjusting the master |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 429 | * volume. If set, the master volume will be muted. This can only be set by device owners |
| 430 | * and profile owners on the primary user. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 431 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 432 | * <p>Key for user restrictions. |
| 433 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 434 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 435 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 436 | * @see #getUserRestrictions() |
| 437 | */ |
| 438 | public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; |
| 439 | |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 440 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 441 | * Specifies that the user is not allowed to make outgoing |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 442 | * phone calls. Emergency calls are still permitted. |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 443 | * The default value is <code>false</code>. |
Tony Mak | eb83ab5 | 2016-02-22 18:36:08 +0000 | [diff] [blame] | 444 | * <p>This restriction has no effect on managed profiles. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 445 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 446 | * <p>Key for user restrictions. |
| 447 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 448 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 449 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 450 | * @see #getUserRestrictions() |
| 451 | */ |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 452 | public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; |
| 453 | |
| 454 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 455 | * Specifies that the user is not allowed to send or receive |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 456 | * SMS messages. The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 457 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 458 | * <p>Key for user restrictions. |
| 459 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 460 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 461 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 462 | * @see #getUserRestrictions() |
| 463 | */ |
| 464 | public static final String DISALLOW_SMS = "no_sms"; |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 465 | |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 466 | /** |
Jeff Sharkey | 2cc03e5 | 2015-03-20 11:24:04 -0700 | [diff] [blame] | 467 | * Specifies if the user is not allowed to have fun. In some cases, the |
| 468 | * device owner may wish to prevent the user from experiencing amusement or |
| 469 | * joy while using the device. The default value is <code>false</code>. |
| 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) |
Jeff Sharkey | 2cc03e5 | 2015-03-20 11:24:04 -0700 | [diff] [blame] | 475 | * @see #getUserRestrictions() |
| 476 | */ |
| 477 | public static final String DISALLOW_FUN = "no_fun"; |
| 478 | |
| 479 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 480 | * Specifies that windows besides app windows should not be |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 481 | * created. This will block the creation of the following types of windows. |
| 482 | * <li>{@link LayoutParams#TYPE_TOAST}</li> |
| 483 | * <li>{@link LayoutParams#TYPE_PHONE}</li> |
| 484 | * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> |
| 485 | * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> |
| 486 | * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> |
| 487 | * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> |
| 488 | * |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 489 | * <p>This can only be set by device owners and profile owners on the primary user. |
| 490 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 491 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 492 | * <p>Key for user restrictions. |
| 493 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 494 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 495 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 496 | * @see #getUserRestrictions() |
| 497 | */ |
| 498 | public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; |
| 499 | |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 500 | /** |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 501 | * Specifies if what is copied in the clipboard of this profile can |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 502 | * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be |
| 503 | * pasted in this profile. |
| 504 | * The default value is <code>false</code>. |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 505 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 506 | * <p>Key for user restrictions. |
| 507 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 508 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 509 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | f193990 | 2014-06-25 09:29:02 +0100 | [diff] [blame] | 510 | * @see #getUserRestrictions() |
| 511 | */ |
| 512 | public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; |
| 513 | |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 514 | /** |
| 515 | * Specifies if the user is not allowed to use NFC to beam out data from apps. |
| 516 | * The default value is <code>false</code>. |
| 517 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 518 | * <p>Key for user restrictions. |
| 519 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 520 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 521 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 522 | * @see #getUserRestrictions() |
| 523 | */ |
| 524 | public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; |
| 525 | |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 526 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 527 | * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction |
| 528 | * generally means that wallpapers are not supported for the particular user. This user |
| 529 | * 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] | 530 | * @hide |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 531 | * @see #DISALLOW_SET_WALLPAPER |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 532 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 533 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 534 | * @see #getUserRestrictions() |
| 535 | */ |
| 536 | public static final String DISALLOW_WALLPAPER = "no_wallpaper"; |
| 537 | |
| 538 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 539 | * User restriction to disallow setting a wallpaper. Profile owner and device owner |
| 540 | * are able to set wallpaper regardless of this restriction. |
| 541 | * The default value is <code>false</code>. |
| 542 | * |
| 543 | * <p>Key for user restrictions. |
| 544 | * <p>Type: Boolean |
| 545 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 546 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 547 | * @see #getUserRestrictions() |
| 548 | */ |
| 549 | public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper"; |
| 550 | |
| 551 | /** |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 552 | * Specifies if the user is not allowed to reboot the device into safe boot mode. |
| 553 | * This can only be set by device owners and profile owners on the primary user. |
| 554 | * The default value is <code>false</code>. |
| 555 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 556 | * <p>Key for user restrictions. |
| 557 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 558 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 559 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 560 | * @see #getUserRestrictions() |
| 561 | */ |
| 562 | public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; |
| 563 | |
| 564 | /** |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 565 | * Specifies if a user is not allowed to record audio. This restriction is always enabled for |
| 566 | * background users. The default value is <code>false</code>. |
| 567 | * |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 568 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 569 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 570 | * @see #getUserRestrictions() |
| 571 | * @hide |
| 572 | */ |
| 573 | public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; |
| 574 | |
| 575 | /** |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 576 | * Specifies if a user is not allowed to run in the background and should be stopped during |
| 577 | * user switch. The default value is <code>false</code>. |
| 578 | * |
| 579 | * <p>This restriction can be set by device owners and profile owners. |
| 580 | * |
| 581 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 582 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 583 | * @see #getUserRestrictions() |
| 584 | * @hide |
| 585 | */ |
| 586 | public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background"; |
| 587 | |
| 588 | /** |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 589 | * Specifies if a user is not allowed to use the camera. |
| 590 | * |
| 591 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 592 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 593 | * @see #getUserRestrictions() |
| 594 | * @hide |
| 595 | */ |
| 596 | public static final String DISALLOW_CAMERA = "no_camera"; |
| 597 | |
| 598 | /** |
Tony Mak | c120511 | 2016-07-22 16:02:59 +0100 | [diff] [blame] | 599 | * Specifies if a user is not allowed to unmute the device's master volume. |
| 600 | * |
| 601 | * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean) |
| 602 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 603 | * @see #getUserRestrictions() |
| 604 | * @hide |
| 605 | */ |
| 606 | public static final String DISALLLOW_UNMUTE_DEVICE = "disallow_unmute_device"; |
| 607 | |
| 608 | /** |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 609 | * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by |
| 610 | * device owners. The default value is <code>false</code>. |
| 611 | * |
| 612 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 613 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 614 | * @see #getUserRestrictions() |
| 615 | */ |
| 616 | public static final String DISALLOW_DATA_ROAMING = "no_data_roaming"; |
| 617 | |
| 618 | /** |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 619 | * Specifies if a user is not allowed to change their icon. Device owner and profile owner |
| 620 | * can set this restriction. When it is set by device owner, only the target user will be |
| 621 | * affected. The default value is <code>false</code>. |
| 622 | * |
| 623 | * <p>Key for user restrictions. |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 624 | * <p>Type: Boolean |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 625 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 626 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 627 | * @see #getUserRestrictions() |
| 628 | */ |
| 629 | public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon"; |
| 630 | |
| 631 | /** |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 632 | * 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] | 633 | * <code>false</code>. Setting this restriction has no effect if the bootloader is already |
| 634 | * unlocked. |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 635 | * |
| 636 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 637 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
| 638 | * @see #getUserRestrictions() |
| 639 | * @hide |
| 640 | */ |
| 641 | public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock"; |
| 642 | |
| 643 | /** |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 644 | * Allows apps in the parent profile to handle web links from the managed profile. |
| 645 | * |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 646 | * This user restriction has an effect only in a managed profile. |
| 647 | * If set: |
| 648 | * Intent filters of activities in the parent profile with action |
| 649 | * {@link android.content.Intent#ACTION_VIEW}, |
| 650 | * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which |
| 651 | * define a host can handle intents from the managed profile. |
| 652 | * The default value is <code>false</code>. |
| 653 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 654 | * <p>Key for user restrictions. |
| 655 | * <p>Type: Boolean |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 656 | * @see DevicePolicyManager#addUserRestriction(ComponentName, String) |
| 657 | * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 658 | * @see #getUserRestrictions() |
| 659 | */ |
Nicolas Prevot | f0029c1 | 2015-06-25 14:25:41 -0700 | [diff] [blame] | 660 | public static final String ALLOW_PARENT_PROFILE_APP_LINKING |
| 661 | = "allow_parent_profile_app_linking"; |
Nicolas Prevot | 9edbda1 | 2015-06-17 11:09:48 -0700 | [diff] [blame] | 662 | |
| 663 | /** |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 664 | * Application restriction key that is used to indicate the pending arrival |
| 665 | * of real restrictions for the app. |
| 666 | * |
| 667 | * <p> |
| 668 | * Applications that support restrictions should check for the presence of this key. |
| 669 | * A <code>true</code> value indicates that restrictions may be applied in the near |
| 670 | * future but are not available yet. It is the responsibility of any |
| 671 | * management application that sets this flag to update it when the final |
| 672 | * restrictions are enforced. |
| 673 | * |
Fyodor Kupolov | 0ffbfea | 2016-01-19 10:07:54 -0800 | [diff] [blame] | 674 | * <p>Key for application restrictions. |
| 675 | * <p>Type: Boolean |
Nicolas Prevot | b14ed95 | 2015-01-13 14:23:53 +0000 | [diff] [blame] | 676 | * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( |
| 677 | * android.content.ComponentName, String, Bundle) |
| 678 | * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( |
| 679 | * android.content.ComponentName, String) |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 680 | */ |
| 681 | public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; |
| 682 | |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 683 | private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; |
| 684 | |
| 685 | /** |
| 686 | * Extra containing a name for the user being created. Optional parameter passed to |
| 687 | * ACTION_CREATE_USER activity. |
| 688 | * @hide |
| 689 | */ |
| 690 | public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME"; |
| 691 | |
| 692 | /** |
| 693 | * Extra containing account name for the user being created. Optional parameter passed to |
| 694 | * ACTION_CREATE_USER activity. |
| 695 | * @hide |
| 696 | */ |
| 697 | public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME"; |
| 698 | |
| 699 | /** |
| 700 | * Extra containing account type for the user being created. Optional parameter passed to |
| 701 | * ACTION_CREATE_USER activity. |
| 702 | * @hide |
| 703 | */ |
| 704 | public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE"; |
| 705 | |
| 706 | /** |
| 707 | * Extra containing account-specific data for the user being created. Optional parameter passed |
| 708 | * to ACTION_CREATE_USER activity. |
| 709 | * @hide |
| 710 | */ |
| 711 | public static final String EXTRA_USER_ACCOUNT_OPTIONS |
| 712 | = "android.os.extra.USER_ACCOUNT_OPTIONS"; |
| 713 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 714 | /** @hide */ |
| 715 | public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; |
| 716 | /** @hide */ |
| 717 | public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; |
| 718 | /** @hide */ |
| 719 | public static final int PIN_VERIFICATION_SUCCESS = -1; |
| 720 | |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 721 | /** |
| 722 | * Error result indicating that this user is not allowed to add other users on this device. |
| 723 | * This is a result code returned from the activity created by the intent |
| 724 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 725 | */ |
| 726 | public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER; |
| 727 | |
| 728 | /** |
| 729 | * Error result indicating that no more users can be created on this device. |
| 730 | * This is a result code returned from the activity created by the intent |
| 731 | * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}. |
| 732 | */ |
| 733 | public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1; |
| 734 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 735 | /** @hide */ |
Amith Yamasani | c068830 | 2015-10-30 10:40:03 -0700 | [diff] [blame] | 736 | public static UserManager get(Context context) { |
| 737 | return (UserManager) context.getSystemService(Context.USER_SERVICE); |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 738 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 739 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 740 | /** @hide */ |
| 741 | public UserManager(Context context, IUserManager service) { |
| 742 | mService = service; |
| 743 | mContext = context; |
| 744 | } |
| 745 | |
| 746 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 747 | * Returns whether this device supports multiple users with their own login and customizable |
| 748 | * space. |
| 749 | * @return whether the device supports multiple users. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 750 | */ |
Jeff Sharkey | 4673e7e | 2012-09-19 13:14:30 -0700 | [diff] [blame] | 751 | public static boolean supportsMultipleUsers() { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 752 | return getMaxSupportedUsers() > 1 |
| 753 | && SystemProperties.getBoolean("fw.show_multiuserui", |
| 754 | Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 757 | /** |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 758 | * @hide |
| 759 | * @return Whether the device is running with split system user. It means the system user and |
| 760 | * primary user are two separate users. Previously system user and primary user are combined as |
| 761 | * a single owner user. see @link {android.os.UserHandle#USER_OWNER} |
| 762 | */ |
| 763 | public static boolean isSplitSystemUser() { |
| 764 | return SystemProperties.getBoolean("ro.fw.system_user_split", false); |
| 765 | } |
| 766 | |
| 767 | /** |
Fyodor Kupolov | 523c404 | 2016-02-24 15:03:13 -0800 | [diff] [blame] | 768 | * Returns whether switching users is currently allowed. |
| 769 | * <p>For instance switching users is not allowed if the current user is in a phone call, |
| 770 | * or system user hasn't been unlocked yet |
| 771 | * @hide |
| 772 | */ |
| 773 | public boolean canSwitchUsers() { |
| 774 | boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt( |
| 775 | mContext.getContentResolver(), |
| 776 | Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; |
| 777 | boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); |
| 778 | boolean inCall = TelephonyManager.getDefault().getCallState() |
| 779 | != TelephonyManager.CALL_STATE_IDLE; |
| 780 | return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall; |
| 781 | } |
| 782 | |
| 783 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 784 | * 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] | 785 | * |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 786 | * @return the user handle of this process. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 787 | * @hide |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 788 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 789 | public @UserIdInt int getUserHandle() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 790 | return UserHandle.myUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /** |
Dianne Hackborn | 8832c18 | 2012-09-17 17:20:24 -0700 | [diff] [blame] | 794 | * Returns the user name of the user making this call. This call is only |
| 795 | * available to applications on the system image; it requires the |
| 796 | * MANAGE_USERS permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 797 | * @return the user name |
| 798 | */ |
| 799 | public String getUserName() { |
| 800 | try { |
| 801 | return mService.getUserInfo(getUserHandle()).name; |
| 802 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 803 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 807 | /** |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 808 | * Used to determine whether the user making this call is subject to |
| 809 | * teleportations. |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 810 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 811 | * <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] | 812 | * now automatically identify goats using advanced goat recognition technology.</p> |
| 813 | * |
| 814 | * @return Returns true if the user making this call is a goat. |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 815 | */ |
| 816 | public boolean isUserAGoat() { |
Adam Powell | 988ae30 | 2014-09-17 17:58:33 -0700 | [diff] [blame] | 817 | return mContext.getPackageManager() |
| 818 | .isPackageAvailable("com.coffeestainstudios.goatsimulator"); |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 819 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 820 | |
| 821 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 822 | * Used to check if this process is running under the primary user. The primary user |
| 823 | * is the first human user on a device. |
| 824 | * |
| 825 | * @return whether this process is running under the primary user. |
| 826 | * @hide |
| 827 | */ |
| 828 | public boolean isPrimaryUser() { |
| 829 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 830 | return user != null && user.isPrimary(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 834 | * Used to check if this process is running under the system user. The system user |
| 835 | * is the initial user that is implicitly created on first boot and hosts most of the |
| 836 | * system services. |
| 837 | * |
| 838 | * @return whether this process is running under the system user. |
| 839 | */ |
| 840 | public boolean isSystemUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 841 | return UserHandle.myUserId() == UserHandle.USER_SYSTEM; |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 842 | } |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 843 | |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 844 | /** |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 845 | * @hide |
| 846 | * Returns whether the caller is running as an admin user. There can be more than one admin |
| 847 | * user. |
| 848 | */ |
| 849 | public boolean isAdminUser() { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 850 | return isUserAdmin(UserHandle.myUserId()); |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * @hide |
| 855 | * Returns whether the provided user is an admin user. There can be more than one admin |
| 856 | * user. |
| 857 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 858 | public boolean isUserAdmin(@UserIdInt int userId) { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 859 | UserInfo user = getUserInfo(userId); |
| 860 | return user != null && user.isAdmin(); |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | /** |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 864 | * Used to check if the user making this call is linked to another user. Linked users may have |
Amith Yamasani | 46bc4eb | 2013-04-12 13:26:50 -0700 | [diff] [blame] | 865 | * a reduced number of available apps, app restrictions and account restrictions. |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 866 | * @return whether the user making this call is a linked user |
Amith Yamasani | 2555daf | 2013-04-25 13:39:27 -0700 | [diff] [blame] | 867 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 868 | */ |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 869 | public boolean isLinkedUser() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 870 | try { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 871 | return mService.isRestricted(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 872 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 873 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 877 | /** |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 878 | * Checks if specified user can have restricted profile. |
| 879 | * @hide |
| 880 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 881 | public boolean canHaveRestrictedProfile(@UserIdInt int userId) { |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 882 | try { |
| 883 | return mService.canHaveRestrictedProfile(userId); |
| 884 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 885 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
| 889 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 890 | * Checks if the calling app is running as a guest user. |
| 891 | * @return whether the caller is a guest user. |
| 892 | * @hide |
| 893 | */ |
| 894 | public boolean isGuestUser() { |
| 895 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 896 | return user != null && user.isGuest(); |
| 897 | } |
| 898 | |
| 899 | /** |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 900 | * Checks if the calling app is running in a demo user. When running in a demo user, |
| 901 | * apps can be more helpful to the user, or explain their features in more detail. |
| 902 | * |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 903 | * @return whether the caller is a demo user. |
Amith Yamasani | d35a89c | 2016-05-26 16:58:43 -0700 | [diff] [blame] | 904 | */ |
| 905 | public boolean isDemoUser() { |
Amith Yamasani | 1c41dc8 | 2016-06-28 16:13:15 -0700 | [diff] [blame] | 906 | try { |
| 907 | return mService.isDemoUser(UserHandle.myUserId()); |
| 908 | } catch (RemoteException re) { |
| 909 | throw re.rethrowFromSystemServer(); |
| 910 | } |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /** |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 914 | * Checks if the calling app is running in a managed profile. |
| 915 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 916 | * |
| 917 | * @return whether the caller is in a managed profile. |
| 918 | * @hide |
| 919 | */ |
| 920 | @SystemApi |
| 921 | public boolean isManagedProfile() { |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 922 | try { |
| 923 | return mService.isManagedProfile(UserHandle.myUserId()); |
| 924 | } catch (RemoteException re) { |
| 925 | throw re.rethrowFromSystemServer(); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Checks if the specified user is a managed profile. |
| 931 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller |
| 932 | * must be in the same profile group of specified user. |
| 933 | * |
| 934 | * @return whether the specified user is a managed profile. |
| 935 | * @hide |
| 936 | */ |
| 937 | @SystemApi |
| 938 | public boolean isManagedProfile(@UserIdInt int userId) { |
| 939 | try { |
| 940 | return mService.isManagedProfile(userId); |
| 941 | } catch (RemoteException re) { |
| 942 | throw re.rethrowFromSystemServer(); |
| 943 | } |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | /** |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 947 | * Checks if the calling app is running as an ephemeral user. |
| 948 | * |
| 949 | * @return whether the caller is an ephemeral user. |
| 950 | * @hide |
| 951 | */ |
| 952 | public boolean isEphemeralUser() { |
| 953 | return isUserEphemeral(UserHandle.myUserId()); |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Returns whether the specified user is ephemeral. |
| 958 | * @hide |
| 959 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 960 | public boolean isUserEphemeral(@UserIdInt int userId) { |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 961 | final UserInfo user = getUserInfo(userId); |
| 962 | return user != null && user.isEphemeral(); |
| 963 | } |
| 964 | |
| 965 | /** |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 966 | * Return whether the given user is actively running. This means that |
| 967 | * the user is in the "started" state, not "stopped" -- it is currently |
| 968 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 969 | * etc. A started user may be either the current foreground user or a |
| 970 | * background user; the result here does not distinguish between the two. |
| 971 | * @param user The user to retrieve the running state for. |
| 972 | */ |
| 973 | public boolean isUserRunning(UserHandle user) { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 974 | return isUserRunning(user.getIdentifier()); |
| 975 | } |
| 976 | |
| 977 | /** {@hide} */ |
| 978 | public boolean isUserRunning(int userId) { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 979 | try { |
Fyodor Kupolov | 7a1e682 | 2016-12-05 13:23:28 -0800 | [diff] [blame] | 980 | return mService.isUserRunning(userId); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 981 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 982 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Return whether the given user is actively running <em>or</em> stopping. |
| 988 | * This is like {@link #isUserRunning(UserHandle)}, but will also return |
| 989 | * true if the user had been running but is in the process of being stopped |
| 990 | * (but is not yet fully stopped, and still running some code). |
| 991 | * @param user The user to retrieve the running state for. |
| 992 | */ |
| 993 | public boolean isUserRunningOrStopping(UserHandle user) { |
| 994 | try { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 995 | // TODO: reconcile stopped vs stopping? |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 996 | return ActivityManagerNative.getDefault().isUserRunning( |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 997 | user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 998 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 999 | throw re.rethrowFromSystemServer(); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1003 | /** @removed */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1004 | @Deprecated |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 1005 | public boolean isUserRunningAndLocked() { |
| 1006 | return isUserRunningAndLocked(Process.myUserHandle()); |
| 1007 | } |
| 1008 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1009 | /** @removed */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1010 | @Deprecated |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 1011 | public boolean isUserRunningAndLocked(UserHandle user) { |
| 1012 | try { |
| 1013 | return ActivityManagerNative.getDefault().isUserRunning( |
| 1014 | user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1015 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1016 | throw re.rethrowFromSystemServer(); |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1020 | /** @removed */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1021 | @Deprecated |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 1022 | public boolean isUserRunningAndUnlocked() { |
| 1023 | return isUserRunningAndUnlocked(Process.myUserHandle()); |
| 1024 | } |
| 1025 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1026 | /** @removed */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1027 | @Deprecated |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 1028 | public boolean isUserRunningAndUnlocked(UserHandle user) { |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 1029 | try { |
| 1030 | return ActivityManagerNative.getDefault().isUserRunning( |
| 1031 | user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1032 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1033 | throw re.rethrowFromSystemServer(); |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1038 | * Return whether the calling user is running in an "unlocked" state. |
| 1039 | * <p> |
| 1040 | * On devices with direct boot, a user is unlocked only after they've |
| 1041 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 1042 | * without direct boot, a user is unlocked as soon as it starts. |
| 1043 | * <p> |
| 1044 | * When a user is locked, only device-protected data storage is available. |
| 1045 | * When a user is unlocked, both device-protected and credential-protected |
| 1046 | * private app data storage is available. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1047 | * |
| 1048 | * @see Intent#ACTION_USER_UNLOCKED |
| 1049 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1050 | */ |
| 1051 | public boolean isUserUnlocked() { |
| 1052 | return isUserUnlocked(Process.myUserHandle()); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1056 | * Return whether the given user is running in an "unlocked" state. |
| 1057 | * <p> |
| 1058 | * On devices with direct boot, a user is unlocked only after they've |
| 1059 | * entered their credentials (such as a lock pattern or PIN). On devices |
| 1060 | * without direct boot, a user is unlocked as soon as it starts. |
| 1061 | * <p> |
| 1062 | * When a user is locked, only device-protected data storage is available. |
| 1063 | * When a user is unlocked, both device-protected and credential-protected |
| 1064 | * private app data storage is available. |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1065 | * |
| 1066 | * @param user to retrieve the unlocked state for. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1067 | * @see Intent#ACTION_USER_UNLOCKED |
| 1068 | * @see Context#createDeviceProtectedStorageContext() |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1069 | */ |
| 1070 | public boolean isUserUnlocked(UserHandle user) { |
Jeff Sharkey | 0999c0d | 2015-12-17 15:12:22 -0700 | [diff] [blame] | 1071 | return isUserUnlocked(user.getIdentifier()); |
| 1072 | } |
| 1073 | |
| 1074 | /** {@hide} */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1075 | public boolean isUserUnlocked(@UserIdInt int userId) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1076 | try { |
Fyodor Kupolov | 7a1e682 | 2016-12-05 13:23:28 -0800 | [diff] [blame] | 1077 | return mService.isUserUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1078 | } catch (RemoteException re) { |
| 1079 | throw re.rethrowFromSystemServer(); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | /** {@hide} */ |
| 1084 | public boolean isUserUnlockingOrUnlocked(UserHandle user) { |
| 1085 | return isUserUnlockingOrUnlocked(user.getIdentifier()); |
| 1086 | } |
| 1087 | |
| 1088 | /** {@hide} */ |
| 1089 | public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { |
| 1090 | try { |
Fyodor Kupolov | 7a1e682 | 2016-12-05 13:23:28 -0800 | [diff] [blame] | 1091 | return mService.isUserUnlockingOrUnlocked(userId); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1092 | } catch (RemoteException re) { |
| 1093 | throw re.rethrowFromSystemServer(); |
| 1094 | } |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1098 | * Returns the UserInfo object describing a specific user. |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1099 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1100 | * @param userHandle the user handle of the user whose information is being requested. |
| 1101 | * @return the UserInfo object for a specific user. |
| 1102 | * @hide |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1103 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1104 | public UserInfo getUserInfo(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1105 | try { |
| 1106 | return mService.getUserInfo(userHandle); |
| 1107 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1108 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1112 | /** |
Zoltan Szatmary-Ban | e783460 | 2016-04-08 18:41:11 +0100 | [diff] [blame] | 1113 | * @hide |
| 1114 | * |
| 1115 | * Returns who set a user restriction on a user. |
| 1116 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1117 | * @param restrictionKey the string key representing the restriction |
| 1118 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1119 | * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET}, |
| 1120 | * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER} |
| 1121 | * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER} |
| 1122 | */ |
| 1123 | @SystemApi |
| 1124 | @UserRestrictionSource |
| 1125 | public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) { |
| 1126 | try { |
| 1127 | return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier()); |
| 1128 | } catch (RemoteException re) { |
| 1129 | throw re.rethrowFromSystemServer(); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1134 | * Returns the user-wide restrictions imposed on this user. |
| 1135 | * @return a Bundle containing all the restrictions. |
| 1136 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1137 | public Bundle getUserRestrictions() { |
| 1138 | return getUserRestrictions(Process.myUserHandle()); |
| 1139 | } |
| 1140 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1141 | /** |
| 1142 | * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. |
| 1143 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1144 | * @return a Bundle containing all the restrictions. |
| 1145 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1146 | public Bundle getUserRestrictions(UserHandle userHandle) { |
| 1147 | try { |
| 1148 | return mService.getUserRestrictions(userHandle.getIdentifier()); |
| 1149 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1150 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 1154 | /** |
| 1155 | * @hide |
| 1156 | * Returns whether the given user has been disallowed from performing certain actions |
| 1157 | * or setting certain settings through UserManager. This method disregards restrictions |
| 1158 | * set by device policy. |
| 1159 | * @param restrictionKey the string key representing the restriction |
| 1160 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1161 | */ |
| 1162 | public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { |
| 1163 | try { |
| 1164 | return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); |
| 1165 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1166 | throw re.rethrowFromSystemServer(); |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1170 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1171 | * This will no longer work. Device owners and profile owners should use |
| 1172 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1173 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1174 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1175 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1176 | public void setUserRestrictions(Bundle restrictions) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1177 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1180 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1181 | * This will no longer work. Device owners and profile owners should use |
| 1182 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1183 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1184 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1185 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1186 | public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1187 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1190 | /** |
| 1191 | * Sets the value of a specific restriction. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1192 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1193 | * @param key the key of the restriction |
| 1194 | * @param value the value for the restriction |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1195 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1196 | * android.content.ComponentName, String)} or |
| 1197 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1198 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1199 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1200 | @Deprecated |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1201 | public void setUserRestriction(String key, boolean value) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1202 | setUserRestriction(key, value, Process.myUserHandle()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /** |
| 1206 | * @hide |
| 1207 | * Sets the value of a specific restriction on a specific user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1208 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1209 | * @param key the key of the restriction |
| 1210 | * @param value the value for the restriction |
| 1211 | * @param userHandle the user whose restriction is to be changed. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1212 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1213 | * android.content.ComponentName, String)} or |
| 1214 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1215 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1216 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1217 | @Deprecated |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1218 | public void setUserRestriction(String key, boolean value, UserHandle userHandle) { |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1219 | try { |
| 1220 | mService.setUserRestriction(key, value, userHandle.getIdentifier()); |
| 1221 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1222 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1223 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1224 | } |
| 1225 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1226 | /** |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1227 | * Returns whether the current user has been disallowed from performing certain actions |
| 1228 | * or setting certain settings. |
Julia Reynolds | 2b2cf72 | 2014-06-06 11:41:04 -0400 | [diff] [blame] | 1229 | * |
| 1230 | * @param restrictionKey The string key representing the restriction. |
| 1231 | * @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] | 1232 | */ |
| 1233 | public boolean hasUserRestriction(String restrictionKey) { |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 1234 | return hasUserRestriction(restrictionKey, Process.myUserHandle()); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * @hide |
| 1239 | * Returns whether the given user has been disallowed from performing certain actions |
| 1240 | * or setting certain settings. |
| 1241 | * @param restrictionKey the string key representing the restriction |
| 1242 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1243 | */ |
| 1244 | public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 1245 | try { |
| 1246 | return mService.hasUserRestriction(restrictionKey, |
| 1247 | userHandle.getIdentifier()); |
| 1248 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1249 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 1250 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1254 | * Return the serial number for a user. This is a device-unique |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1255 | * number assigned to that user; if the user is deleted and then a new |
| 1256 | * 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] | 1257 | * @param user The user whose serial number is to be retrieved. |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1258 | * @return The serial number of the given user; returns -1 if the |
| 1259 | * given UserHandle does not exist. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1260 | * @see #getUserForSerialNumber(long) |
| 1261 | */ |
| 1262 | public long getSerialNumberForUser(UserHandle user) { |
| 1263 | return getUserSerialNumber(user.getIdentifier()); |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * Return the user associated with a serial number previously |
| 1268 | * returned by {@link #getSerialNumberForUser(UserHandle)}. |
| 1269 | * @param serialNumber The serial number of the user that is being |
| 1270 | * retrieved. |
| 1271 | * @return Return the user associated with the serial number, or null |
| 1272 | * if there is not one. |
| 1273 | * @see #getSerialNumberForUser(UserHandle) |
| 1274 | */ |
| 1275 | public UserHandle getUserForSerialNumber(long serialNumber) { |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 1276 | int ident = getUserHandle((int) serialNumber); |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1277 | return ident >= 0 ? new UserHandle(ident) : null; |
| 1278 | } |
| 1279 | |
| 1280 | /** |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1281 | * Creates a user with the specified name and options. For non-admin users, default user |
| 1282 | * restrictions are going to be applied. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1283 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1284 | * |
| 1285 | * @param name the user's name |
| 1286 | * @param flags flags that identify the type of user and other properties. |
| 1287 | * @see UserInfo |
| 1288 | * |
| 1289 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 1290 | * @hide |
| 1291 | */ |
| 1292 | public UserInfo createUser(String name, int flags) { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1293 | UserInfo user = null; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1294 | try { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1295 | user = mService.createUser(name, flags); |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 1296 | // TODO: Keep this in sync with |
| 1297 | // UserManagerService.LocalService.createUserEvenWhenDisallowed |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1298 | if (user != null && !user.isAdmin()) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1299 | mService.setUserRestriction(DISALLOW_SMS, true, user.id); |
| 1300 | mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1301 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1302 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1303 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1304 | } |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1305 | return user; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1309 | * Creates a guest user and configures it. |
| 1310 | * @param context an application context |
| 1311 | * @param name the name to set for the user |
| 1312 | * @hide |
| 1313 | */ |
| 1314 | public UserInfo createGuest(Context context, String name) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1315 | UserInfo guest = null; |
| 1316 | try { |
| 1317 | guest = mService.createUser(name, UserInfo.FLAG_GUEST); |
| 1318 | if (guest != null) { |
| 1319 | Settings.Secure.putStringForUser(context.getContentResolver(), |
| 1320 | Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1321 | } |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1322 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1323 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1324 | } |
| 1325 | return guest; |
| 1326 | } |
| 1327 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 1328 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1329 | * 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] | 1330 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1331 | * |
| 1332 | * @param name the user's name |
| 1333 | * @param flags flags that identify the type of user and other properties. |
| 1334 | * @see UserInfo |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1335 | * @param userHandle new user will be a profile of this use. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1336 | * |
| 1337 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 1338 | * @hide |
| 1339 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1340 | public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1341 | try { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1342 | return mService.createProfileForUser(name, flags, userHandle); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1343 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1344 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | /** |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1349 | * Creates a restricted profile with the specified name. This method also sets necessary |
| 1350 | * restrictions and adds shared accounts. |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1351 | * |
| 1352 | * @param name profile's name |
| 1353 | * @return UserInfo object for the created user, or null if the user could not be created. |
| 1354 | * @hide |
| 1355 | */ |
| 1356 | public UserInfo createRestrictedProfile(String name) { |
| 1357 | try { |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1358 | UserHandle parentUserHandle = Process.myUserHandle(); |
| 1359 | UserInfo user = mService.createRestrictedProfile(name, |
| 1360 | parentUserHandle.getIdentifier()); |
| 1361 | if (user != null) { |
| 1362 | AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, |
| 1363 | UserHandle.of(user.id)); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1364 | } |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1365 | return user; |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1366 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1367 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1368 | } |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /** |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1372 | * Returns an intent to create a user for the provided name and account name. The name |
| 1373 | * and account name will be used when the setup process for the new user is started. |
| 1374 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1375 | * The intent should be launched using startActivityForResult and the return result will |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1376 | * indicate if the user consented to adding a new user and if the operation succeeded. Any |
| 1377 | * errors in creating the user will be returned in the result code. If the user cancels the |
| 1378 | * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the |
| 1379 | * result code will be {@link Activity#RESULT_OK}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1380 | * <p> |
| 1381 | * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation |
| 1382 | * at all. |
| 1383 | * <p> |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1384 | * The new user is created but not initialized. After switching into the user for the first |
| 1385 | * time, the preferred user name and account information are used by the setup process for that |
| 1386 | * user. |
| 1387 | * |
| 1388 | * @param userName Optional name to assign to the user. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1389 | * @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] | 1390 | * the user. |
| 1391 | * @param accountType Optional account type for the account to be created. This is required |
| 1392 | * if the account name is specified. |
| 1393 | * @param accountOptions Optional bundle of data to be passed in during account creation in the |
| 1394 | * new user via {@link AccountManager#addAccount(String, String, String[], |
| 1395 | * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, |
| 1396 | * Handler)}. |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1397 | * @return An Intent that can be launched from an Activity. |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1398 | * @see #USER_CREATION_FAILED_NOT_PERMITTED |
| 1399 | * @see #USER_CREATION_FAILED_NO_MORE_USERS |
Amith Yamasani | 0696434 | 2016-04-15 13:55:01 -0700 | [diff] [blame] | 1400 | * @see #supportsMultipleUsers |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1401 | */ |
| 1402 | public static Intent createUserCreationIntent(@Nullable String userName, |
| 1403 | @Nullable String accountName, |
| 1404 | @Nullable String accountType, @Nullable PersistableBundle accountOptions) { |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1405 | Intent intent = new Intent(ACTION_CREATE_USER); |
| 1406 | if (userName != null) { |
| 1407 | intent.putExtra(EXTRA_USER_NAME, userName); |
| 1408 | } |
| 1409 | if (accountName != null && accountType == null) { |
| 1410 | throw new IllegalArgumentException("accountType must be specified if accountName is " |
| 1411 | + "specified"); |
| 1412 | } |
| 1413 | if (accountName != null) { |
| 1414 | intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); |
| 1415 | } |
| 1416 | if (accountType != null) { |
| 1417 | intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); |
| 1418 | } |
| 1419 | if (accountOptions != null) { |
| 1420 | intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); |
| 1421 | } |
| 1422 | return intent; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * @hide |
| 1427 | * |
| 1428 | * Returns the preferred account name for user creation. Requires MANAGE_USERS permission. |
| 1429 | */ |
| 1430 | @SystemApi |
| 1431 | public String getSeedAccountName() { |
| 1432 | try { |
| 1433 | return mService.getSeedAccountName(); |
| 1434 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1435 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * @hide |
| 1441 | * |
| 1442 | * Returns the preferred account type for user creation. Requires MANAGE_USERS permission. |
| 1443 | */ |
| 1444 | @SystemApi |
| 1445 | public String getSeedAccountType() { |
| 1446 | try { |
| 1447 | return mService.getSeedAccountType(); |
| 1448 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1449 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * @hide |
| 1455 | * |
| 1456 | * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS |
| 1457 | * permission. |
| 1458 | * @return Any options set by the requestor that created the user. |
| 1459 | */ |
| 1460 | @SystemApi |
| 1461 | public PersistableBundle getSeedAccountOptions() { |
| 1462 | try { |
| 1463 | return mService.getSeedAccountOptions(); |
| 1464 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1465 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * @hide |
| 1471 | * |
| 1472 | * Called by a system activity to set the seed account information of a user created |
| 1473 | * through the user creation intent. |
| 1474 | * @param userId |
| 1475 | * @param accountName |
| 1476 | * @param accountType |
| 1477 | * @param accountOptions |
| 1478 | * @see #createUserCreationIntent(String, String, String, PersistableBundle) |
| 1479 | */ |
| 1480 | public void setSeedAccountData(int userId, String accountName, String accountType, |
| 1481 | PersistableBundle accountOptions) { |
| 1482 | try { |
| 1483 | mService.setSeedAccountData(userId, accountName, accountType, accountOptions, |
| 1484 | /* persist= */ true); |
| 1485 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1486 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /** |
| 1491 | * @hide |
| 1492 | * Clears the seed information used to create this user. Requires MANAGE_USERS permission. |
| 1493 | */ |
| 1494 | @SystemApi |
| 1495 | public void clearSeedAccountData() { |
| 1496 | try { |
| 1497 | mService.clearSeedAccountData(); |
| 1498 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1499 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | /** |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1504 | * @hide |
| 1505 | * Marks the guest user for deletion to allow a new guest to be created before deleting |
| 1506 | * the current user who is a guest. |
| 1507 | * @param userHandle |
| 1508 | * @return |
| 1509 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1510 | public boolean markGuestForDeletion(@UserIdInt int userHandle) { |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1511 | try { |
| 1512 | return mService.markGuestForDeletion(userHandle); |
| 1513 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1514 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /** |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 1519 | * Sets the user as enabled, if such an user exists. |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 1520 | * |
| 1521 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1522 | * |
| 1523 | * <p>Note that the default is true, it's only that managed profiles might not be enabled. |
| 1524 | * Also ephemeral users can be disabled to indicate that their removal is in progress and they |
| 1525 | * 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] | 1526 | * |
| 1527 | * @param userHandle the id of the profile to enable |
| 1528 | * @hide |
| 1529 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1530 | public void setUserEnabled(@UserIdInt int userHandle) { |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 1531 | try { |
| 1532 | mService.setUserEnabled(userHandle); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1533 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1534 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /** |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1539 | * Return the number of users currently created on the device. |
| 1540 | */ |
| 1541 | public int getUserCount() { |
| 1542 | List<UserInfo> users = getUsers(); |
| 1543 | return users != null ? users.size() : 1; |
| 1544 | } |
| 1545 | |
| 1546 | /** |
Amith Yamasani | d04aaa3 | 2016-06-13 12:09:36 -0700 | [diff] [blame] | 1547 | * Returns information for all users on this device, including ones marked for deletion. |
| 1548 | * To retrieve only users that are alive, use {@link #getUsers(boolean)}. |
| 1549 | * <p> |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1550 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 1551 | * @return the list of users that exist on the device. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1552 | * @hide |
| 1553 | */ |
| 1554 | public List<UserInfo> getUsers() { |
| 1555 | try { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1556 | return mService.getUsers(false); |
| 1557 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1558 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 1563 | * Returns serial numbers of all users on this device. |
| 1564 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1565 | * |
| 1566 | * @param excludeDying specify if the list should exclude users being removed. |
| 1567 | * @return the list of serial numbers of users that exist on the device. |
| 1568 | * @hide |
| 1569 | */ |
| 1570 | @SystemApi |
| 1571 | public long[] getSerialNumbersOfUsers(boolean excludeDying) { |
| 1572 | try { |
| 1573 | List<UserInfo> users = mService.getUsers(excludeDying); |
| 1574 | long[] result = new long[users.size()]; |
| 1575 | for (int i = 0; i < result.length; i++) { |
| 1576 | result[i] = users.get(i).serialNumber; |
| 1577 | } |
| 1578 | return result; |
| 1579 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1580 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | /** |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1585 | * @return the user's account name, null if not found. |
| 1586 | * @hide |
| 1587 | */ |
| 1588 | @RequiresPermission( allOf = { |
| 1589 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 1590 | Manifest.permission.MANAGE_USERS |
| 1591 | }) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1592 | public @Nullable String getUserAccount(@UserIdInt int userHandle) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1593 | try { |
| 1594 | return mService.getUserAccount(userHandle); |
| 1595 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1596 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Set account name for the given user. |
| 1602 | * @hide |
| 1603 | */ |
| 1604 | @RequiresPermission( allOf = { |
| 1605 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 1606 | Manifest.permission.MANAGE_USERS |
| 1607 | }) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1608 | public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1609 | try { |
| 1610 | mService.setUserAccount(userHandle, accountName); |
| 1611 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1612 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1617 | * Returns information for Primary user. |
| 1618 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1619 | * |
| 1620 | * @return the Primary user, null if not found. |
| 1621 | * @hide |
| 1622 | */ |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1623 | public @Nullable UserInfo getPrimaryUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1624 | try { |
| 1625 | return mService.getPrimaryUser(); |
| 1626 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1627 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | /** |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1632 | * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS |
| 1633 | * permission. |
| 1634 | * |
| 1635 | * @return true if more users can be added, false if limit has been reached. |
| 1636 | * @hide |
| 1637 | */ |
| 1638 | public boolean canAddMoreUsers() { |
| 1639 | final List<UserInfo> users = getUsers(true); |
| 1640 | final int totalUserCount = users.size(); |
| 1641 | int aliveUserCount = 0; |
| 1642 | for (int i = 0; i < totalUserCount; i++) { |
| 1643 | UserInfo user = users.get(i); |
| 1644 | if (!user.isGuest()) { |
| 1645 | aliveUserCount++; |
| 1646 | } |
| 1647 | } |
| 1648 | return aliveUserCount < getMaxSupportedUsers(); |
| 1649 | } |
| 1650 | |
| 1651 | /** |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1652 | * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS |
| 1653 | * permission. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 1654 | * if allowedToRemoveOne is true and if the user already has a managed profile, then return if |
| 1655 | * 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] | 1656 | * |
| 1657 | * @return true if more managed profiles can be added, false if limit has been reached. |
| 1658 | * @hide |
| 1659 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1660 | public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1661 | try { |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 1662 | return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1663 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1664 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1669 | * Returns list of the profiles of userHandle including |
| 1670 | * userHandle itself. |
Amith Yamasani | 4f7e2e3 | 2014-08-14 18:49:48 -0700 | [diff] [blame] | 1671 | * Note that this returns both enabled and not enabled profiles. See |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1672 | * {@link #getEnabledProfiles(int)} if you need only the enabled ones. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1673 | * |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1674 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1675 | * @param userHandle profiles of this user will be returned. |
| 1676 | * @return the list of profiles. |
| 1677 | * @hide |
| 1678 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1679 | public List<UserInfo> getProfiles(@UserIdInt int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1680 | try { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1681 | return mService.getProfiles(userHandle, false /* enabledOnly */); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1682 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1683 | throw re.rethrowFromSystemServer(); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | /** |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 1688 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1689 | * @param userId one of the two user ids to check. |
| 1690 | * @param otherUserId one of the two user ids to check. |
| 1691 | * @return true if the two user ids are in the same profile group. |
| 1692 | * @hide |
| 1693 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1694 | public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 1695 | try { |
| 1696 | return mService.isSameProfileGroup(userId, otherUserId); |
| 1697 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1698 | throw re.rethrowFromSystemServer(); |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | /** |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1703 | * Returns list of the profiles of userHandle including |
| 1704 | * userHandle itself. |
| 1705 | * Note that this returns only enabled. |
| 1706 | * |
| 1707 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1708 | * @param userHandle profiles of this user will be returned. |
| 1709 | * @return the list of profiles. |
| 1710 | * @hide |
| 1711 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1712 | public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1713 | try { |
| 1714 | return mService.getProfiles(userHandle, true /* enabledOnly */); |
| 1715 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1716 | throw re.rethrowFromSystemServer(); |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1721 | * Returns a list of UserHandles for profiles associated with the user that the calling process |
| 1722 | * is running on, including the user itself. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1723 | * |
| 1724 | * @return A non-empty list of UserHandles associated with the calling user. |
| 1725 | */ |
| 1726 | public List<UserHandle> getUserProfiles() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1727 | int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); |
| 1728 | List<UserHandle> result = new ArrayList<>(userIds.length); |
| 1729 | for (int userId : userIds) { |
| 1730 | result.add(UserHandle.of(userId)); |
| 1731 | } |
| 1732 | return result; |
| 1733 | } |
| 1734 | |
| 1735 | /** |
| 1736 | * Returns a list of ids for profiles associated with the specified user including the user |
| 1737 | * itself. |
| 1738 | * |
| 1739 | * @param userId id of the user to return profiles for |
| 1740 | * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles |
| 1741 | * @return A non-empty list of ids of profiles associated with the specified user. |
| 1742 | * |
| 1743 | * @hide |
| 1744 | */ |
| 1745 | public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1746 | try { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1747 | return mService.getProfileIds(userId, enabledOnly); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1748 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1749 | throw re.rethrowFromSystemServer(); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1750 | } |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * @see #getProfileIds(int, boolean) |
| 1755 | * @hide |
| 1756 | */ |
| 1757 | public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { |
| 1758 | return getProfileIds(userId, false /* enabledOnly */); |
| 1759 | } |
| 1760 | |
| 1761 | /** |
| 1762 | * @see #getProfileIds(int, boolean) |
| 1763 | * @hide |
| 1764 | */ |
| 1765 | public int[] getEnabledProfileIds(@UserIdInt int userId) { |
| 1766 | return getProfileIds(userId, true /* enabledOnly */); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1767 | } |
| 1768 | |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1769 | /** |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 1770 | * Returns the device credential owner id of the profile from |
| 1771 | * which this method is called, or userHandle if called from a user that |
| 1772 | * is not a profile. |
| 1773 | * |
| 1774 | * @hide |
| 1775 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1776 | public int getCredentialOwnerProfile(@UserIdInt int userHandle) { |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 1777 | try { |
| 1778 | return mService.getCredentialOwnerProfile(userHandle); |
| 1779 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1780 | throw re.rethrowFromSystemServer(); |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1785 | * Returns the parent of the profile which this method is called from |
| 1786 | * or null if called from a user that is not a profile. |
| 1787 | * |
| 1788 | * @hide |
| 1789 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1790 | public UserInfo getProfileParent(@UserIdInt int userHandle) { |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1791 | try { |
| 1792 | return mService.getProfileParent(userHandle); |
| 1793 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1794 | throw re.rethrowFromSystemServer(); |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | /** |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1799 | * Set quiet mode of a managed profile. |
| 1800 | * |
| 1801 | * @param userHandle The user handle of the profile. |
| 1802 | * @param enableQuietMode Whether quiet mode should be enabled or disabled. |
| 1803 | * @hide |
| 1804 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1805 | public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1806 | try { |
| 1807 | mService.setQuietModeEnabled(userHandle, enableQuietMode); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1808 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1809 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * Returns whether the given profile is in quiet mode or not. |
Ricky Wai | 7881cf8 | 2016-04-15 17:20:12 +0100 | [diff] [blame] | 1815 | * Notes: Quiet mode is only supported for managed profiles. |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1816 | * |
| 1817 | * @param userHandle The user handle of the profile to be queried. |
| 1818 | * @return true if the profile is in quiet mode, false otherwise. |
| 1819 | */ |
| 1820 | public boolean isQuietModeEnabled(UserHandle userHandle) { |
| 1821 | try { |
| 1822 | return mService.isQuietModeEnabled(userHandle.getIdentifier()); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1823 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1824 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1825 | } |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /** |
Benjamin Franz | f02420c | 2016-04-04 18:52:21 +0100 | [diff] [blame] | 1829 | * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user |
| 1830 | * first by showing the confirm credentials screen and disable quiet mode upon successful |
| 1831 | * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled} |
| 1832 | * directly. |
| 1833 | * |
| 1834 | * @return true if the quiet mode was disabled immediately |
| 1835 | * @hide |
| 1836 | */ |
| 1837 | public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) { |
| 1838 | try { |
| 1839 | return mService.trySetQuietModeDisabled(userHandle, target); |
| 1840 | } catch (RemoteException re) { |
| 1841 | throw re.rethrowFromSystemServer(); |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | /** |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1846 | * If the target user is a managed profile of the calling user or the caller |
| 1847 | * 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] | 1848 | * icon to be able to distinguish it from the original icon. For badging an |
| 1849 | * arbitrary drawable use {@link #getBadgedDrawableForUser( |
| 1850 | * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. |
| 1851 | * <p> |
| 1852 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1853 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1854 | * is performed in place and the original drawable is returned. |
| 1855 | * </p> |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1856 | * |
| 1857 | * @param icon The icon to badge. |
| 1858 | * @param user The target user. |
| 1859 | * @return A drawable that combines the original icon and a badge as |
| 1860 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1861 | * @removed |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1862 | */ |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1863 | public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1864 | return mContext.getPackageManager().getUserBadgedIcon(icon, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Kenny Guy | 701ea7c | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 1867 | /** |
| 1868 | * 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] | 1869 | * is itself a managed profile, then this returns a badged copy of the given |
| 1870 | * drawable allowing the user to distinguish it from the original drawable. |
| 1871 | * The caller can specify the location in the bounds of the drawable to be |
| 1872 | * badged where the badge should be applied as well as the density of the |
| 1873 | * badge to be used. |
| 1874 | * <p> |
| 1875 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1876 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1877 | * is performed in place and the original drawable is returned. |
| 1878 | * </p> |
| 1879 | * |
| 1880 | * @param badgedDrawable The drawable to badge. |
| 1881 | * @param user The target user. |
| 1882 | * @param badgeLocation Where in the bounds of the badged drawable to place |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1883 | * 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] | 1884 | * drawable being badged. |
| 1885 | * @param badgeDensity The optional desired density for the badge as per |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1886 | * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive, |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1887 | * the density of the display is used. |
| 1888 | * @return A drawable that combines the original drawable and a badge as |
| 1889 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1890 | * @removed |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1891 | */ |
| 1892 | public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, |
| 1893 | Rect badgeLocation, int badgeDensity) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1894 | return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, |
| 1895 | badgeLocation, badgeDensity); |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * 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] | 1900 | * is itself a managed profile, then this returns a copy of the label with |
| 1901 | * badging for accessibility services like talkback. E.g. passing in "Email" |
| 1902 | * and it might return "Work Email" for Email in the work profile. |
| 1903 | * |
| 1904 | * @param label The label to change. |
| 1905 | * @param user The target user. |
| 1906 | * @return A label that combines the original label and a badge as |
| 1907 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1908 | * @removed |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 1909 | */ |
Kenny Guy | 237aecd | 2014-07-21 14:06:09 +0100 | [diff] [blame] | 1910 | public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1911 | return mContext.getPackageManager().getUserBadgedLabel(label, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Returns information for all users on this device. Requires |
| 1916 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 1917 | * |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1918 | * @param excludeDying specify if the list should exclude users being |
| 1919 | * removed. |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1920 | * @return the list of users that were created. |
| 1921 | * @hide |
| 1922 | */ |
| 1923 | public List<UserInfo> getUsers(boolean excludeDying) { |
| 1924 | try { |
| 1925 | return mService.getUsers(excludeDying); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1926 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1927 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * Removes a user and all associated data. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1933 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1934 | * @param userHandle the integer handle of the user, where 0 is the primary user. |
| 1935 | * @hide |
| 1936 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1937 | public boolean removeUser(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1938 | try { |
| 1939 | return mService.removeUser(userHandle); |
| 1940 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1941 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Updates the user's name. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1947 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1948 | * |
| 1949 | * @param userHandle the user's integer handle |
| 1950 | * @param name the new name for the user |
| 1951 | * @hide |
| 1952 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1953 | public void setUserName(@UserIdInt int userHandle, String name) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1954 | try { |
| 1955 | mService.setUserName(userHandle, name); |
| 1956 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1957 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | /** |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1962 | * Sets the user's photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1963 | * @param userHandle the user for whom to change the photo. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1964 | * @param icon the bitmap to set as the photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1965 | * @hide |
| 1966 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1967 | public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1968 | try { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1969 | mService.setUserIcon(userHandle, icon); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1970 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1971 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | /** |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1976 | * Returns a file descriptor for the user's photo. PNG data can be read from this file. |
| 1977 | * @param userHandle the user whose photo we want to read. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1978 | * @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] | 1979 | * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1980 | * @hide |
| 1981 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1982 | public Bitmap getUserIcon(@UserIdInt int userHandle) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1983 | try { |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 1984 | ParcelFileDescriptor fd = mService.getUserIcon(userHandle); |
| 1985 | if (fd != null) { |
| 1986 | try { |
| 1987 | return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); |
| 1988 | } finally { |
| 1989 | try { |
| 1990 | fd.close(); |
| 1991 | } catch (IOException e) { |
| 1992 | } |
| 1993 | } |
| 1994 | } |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1995 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1996 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1997 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 1998 | return null; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2002 | * Returns the maximum number of users that can be created on this device. A return value |
| 2003 | * of 1 means that it is a single user device. |
| 2004 | * @hide |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 2005 | * @return a value greater than or equal to 1 |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2006 | */ |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 2007 | public static int getMaxSupportedUsers() { |
Amith Yamasani | ff54920 | 2012-10-12 12:44:49 -0700 | [diff] [blame] | 2008 | // Don't allow multiple users on certain builds |
| 2009 | if (android.os.Build.ID.startsWith("JVP")) return 1; |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 2010 | // Svelte devices don't get multi-user. |
| 2011 | if (ActivityManager.isLowRamDeviceStatic()) return 1; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 2012 | return SystemProperties.getInt("fw.max_users", |
| 2013 | Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2014 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2015 | |
| 2016 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2017 | * Returns true if the user switcher should be shown, this will be if device supports multi-user |
| 2018 | * 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] | 2019 | * @hide |
| 2020 | * @return true if user switcher should be shown. |
| 2021 | */ |
| 2022 | public boolean isUserSwitcherEnabled() { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2023 | if (!supportsMultipleUsers()) { |
| 2024 | return false; |
| 2025 | } |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 2026 | // If Demo Mode is on, don't show user switcher |
| 2027 | if (isDeviceInDemoMode(mContext)) { |
| 2028 | return false; |
| 2029 | } |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2030 | List<UserInfo> users = getUsers(true); |
| 2031 | if (users == null) { |
| 2032 | return false; |
| 2033 | } |
| 2034 | int switchableUserCount = 0; |
| 2035 | for (UserInfo user : users) { |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 2036 | if (user.supportsSwitchToByUser()) { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2037 | ++switchableUserCount; |
| 2038 | } |
| 2039 | } |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 2040 | final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) |
| 2041 | .getGuestUserDisabled(null); |
Amith Yamasani | a596ff8 | 2014-06-12 18:12:38 -0700 | [diff] [blame] | 2042 | return switchableUserCount > 1 || guestEnabled; |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | /** |
Amith Yamasani | eb437d4 | 2016-04-29 09:31:25 -0700 | [diff] [blame] | 2046 | * @hide |
| 2047 | */ |
| 2048 | public static boolean isDeviceInDemoMode(Context context) { |
| 2049 | return Settings.Global.getInt(context.getContentResolver(), |
| 2050 | Settings.Global.DEVICE_DEMO_MODE, 0) > 0; |
| 2051 | } |
| 2052 | |
| 2053 | /** |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2054 | * Returns a serial number on this device for a given userHandle. User handles can be recycled |
| 2055 | * when deleting and creating users, but serial numbers are not reused until the device is wiped. |
| 2056 | * @param userHandle |
| 2057 | * @return a serial number associated with that user, or -1 if the userHandle is not valid. |
| 2058 | * @hide |
| 2059 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2060 | public int getUserSerialNumber(@UserIdInt int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2061 | try { |
| 2062 | return mService.getUserSerialNumber(userHandle); |
| 2063 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2064 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2065 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * Returns a userHandle on this device for a given user serial number. User handles can be |
| 2070 | * recycled when deleting and creating users, but serial numbers are not reused until the device |
| 2071 | * is wiped. |
| 2072 | * @param userSerialNumber |
| 2073 | * @return the userHandle associated with that user serial number, or -1 if the serial number |
| 2074 | * is not valid. |
| 2075 | * @hide |
| 2076 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2077 | public @UserIdInt int getUserHandle(int userSerialNumber) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2078 | try { |
| 2079 | return mService.getUserHandle(userSerialNumber); |
| 2080 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2081 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2082 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 2083 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 2084 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2085 | /** |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 2086 | * 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] | 2087 | * 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] | 2088 | * |
| 2089 | * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, |
| 2090 | * where the types of values may be: |
| 2091 | * <ul> |
| 2092 | * <li>{@code boolean} |
| 2093 | * <li>{@code int} |
| 2094 | * <li>{@code String} or {@code String[]} |
| 2095 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 2096 | * </ul> |
| 2097 | * |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2098 | * @param packageName the package name of the calling application |
Esteban Talavera | 953fe48 | 2016-06-07 15:25:20 +0100 | [diff] [blame] | 2099 | * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle} |
| 2100 | * if there are no saved restrictions. |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 2101 | * |
| 2102 | * @see #KEY_RESTRICTIONS_PENDING |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2103 | */ |
| 2104 | public Bundle getApplicationRestrictions(String packageName) { |
| 2105 | try { |
| 2106 | return mService.getApplicationRestrictions(packageName); |
| 2107 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2108 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2109 | } |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2110 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2111 | |
| 2112 | /** |
| 2113 | * @hide |
| 2114 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2115 | public Bundle getApplicationRestrictions(String packageName, UserHandle user) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2116 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2117 | return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2118 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2119 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2120 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /** |
| 2124 | * @hide |
| 2125 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2126 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2127 | UserHandle user) { |
| 2128 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 2129 | mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2130 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2131 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 2132 | } |
| 2133 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2134 | |
| 2135 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 2136 | * Sets a new challenge PIN for restrictions. This is only for use by pre-installed |
| 2137 | * apps and requires the MANAGE_USERS permission. |
| 2138 | * @param newPin the PIN to use for challenge dialogs. |
| 2139 | * @return Returns true if the challenge PIN was set successfully. |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 2140 | * @deprecated The restrictions PIN functionality is no longer provided by the system. |
| 2141 | * This method is preserved for backwards compatibility reasons and always returns false. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2142 | */ |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 2143 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2144 | return false; |
| 2145 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 2146 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2147 | /** |
| 2148 | * @hide |
| 2149 | * Set restrictions that should apply to any future guest user that's created. |
| 2150 | */ |
| 2151 | public void setDefaultGuestRestrictions(Bundle restrictions) { |
| 2152 | try { |
| 2153 | mService.setDefaultGuestRestrictions(restrictions); |
| 2154 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2155 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * @hide |
| 2161 | * Gets the default guest restrictions. |
| 2162 | */ |
| 2163 | public Bundle getDefaultGuestRestrictions() { |
| 2164 | try { |
| 2165 | return mService.getDefaultGuestRestrictions(); |
| 2166 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2167 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2168 | } |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 2169 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2170 | |
| 2171 | /** |
| 2172 | * Returns creation time of the user or of a managed profile associated with the calling user. |
| 2173 | * @param userHandle user handle of the user or a managed profile associated with the |
| 2174 | * calling user. |
| 2175 | * @return creation time in milliseconds since Epoch time. |
| 2176 | */ |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 2177 | public long getUserCreationTime(UserHandle userHandle) { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2178 | try { |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 2179 | return mService.getUserCreationTime(userHandle.getIdentifier()); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2180 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2181 | throw re.rethrowFromSystemServer(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2184 | |
| 2185 | /** |
| 2186 | * @hide |
| 2187 | * Checks if any uninitialized user has the specific seed account name and type. |
| 2188 | * |
| 2189 | * @param mAccountName The account name to check for |
| 2190 | * @param mAccountType The account type of the account to check for |
| 2191 | * @return whether the seed account was found |
| 2192 | */ |
| 2193 | public boolean someUserHasSeedAccount(String accountName, String accountType) { |
| 2194 | try { |
| 2195 | return mService.someUserHasSeedAccount(accountName, accountType); |
| 2196 | } catch (RemoteException re) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2197 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 2198 | } |
| 2199 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2200 | } |