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