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