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; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 39 | import android.util.Log; |
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 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 684 | * 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] | 685 | * |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 686 | * @return the user handle of this process. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 687 | * @hide |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 688 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 689 | public @UserIdInt int getUserHandle() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 690 | return UserHandle.myUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /** |
Dianne Hackborn | 8832c18 | 2012-09-17 17:20:24 -0700 | [diff] [blame] | 694 | * Returns the user name of the user making this call. This call is only |
| 695 | * available to applications on the system image; it requires the |
| 696 | * MANAGE_USERS permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 697 | * @return the user name |
| 698 | */ |
| 699 | public String getUserName() { |
| 700 | try { |
| 701 | return mService.getUserInfo(getUserHandle()).name; |
| 702 | } catch (RemoteException re) { |
| 703 | Log.w(TAG, "Could not get user name", re); |
| 704 | return ""; |
| 705 | } |
| 706 | } |
| 707 | |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 708 | /** |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 709 | * Used to determine whether the user making this call is subject to |
| 710 | * teleportations. |
Dianne Hackborn | 67a101a | 2014-10-02 12:42:18 -0700 | [diff] [blame] | 711 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 712 | * <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] | 713 | * now automatically identify goats using advanced goat recognition technology.</p> |
| 714 | * |
| 715 | * @return Returns true if the user making this call is a goat. |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 716 | */ |
| 717 | public boolean isUserAGoat() { |
Adam Powell | 988ae30 | 2014-09-17 17:58:33 -0700 | [diff] [blame] | 718 | return mContext.getPackageManager() |
| 719 | .isPackageAvailable("com.coffeestainstudios.goatsimulator"); |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 720 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 721 | |
| 722 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 723 | * Used to check if this process is running under the primary user. The primary user |
| 724 | * is the first human user on a device. |
| 725 | * |
| 726 | * @return whether this process is running under the primary user. |
| 727 | * @hide |
| 728 | */ |
| 729 | public boolean isPrimaryUser() { |
| 730 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
| 731 | return user != null ? user.isPrimary() : false; |
| 732 | } |
| 733 | |
| 734 | /** |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 735 | * Used to check if this process is running under the system user. The system user |
| 736 | * is the initial user that is implicitly created on first boot and hosts most of the |
| 737 | * system services. |
| 738 | * |
| 739 | * @return whether this process is running under the system user. |
| 740 | */ |
| 741 | public boolean isSystemUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 742 | return UserHandle.myUserId() == UserHandle.USER_SYSTEM; |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 743 | } |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 744 | |
Amith Yamasani | 5760e17 | 2015-04-17 18:42:41 -0700 | [diff] [blame] | 745 | /** |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 746 | * @hide |
| 747 | * Returns whether the caller is running as an admin user. There can be more than one admin |
| 748 | * user. |
| 749 | */ |
| 750 | public boolean isAdminUser() { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 751 | return isUserAdmin(UserHandle.myUserId()); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * @hide |
| 756 | * Returns whether the provided user is an admin user. There can be more than one admin |
| 757 | * user. |
| 758 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 759 | public boolean isUserAdmin(@UserIdInt int userId) { |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 760 | UserInfo user = getUserInfo(userId); |
| 761 | return user != null && user.isAdmin(); |
Amith Yamasani | 462ac3a | 2015-06-30 14:21:01 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 765 | * 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] | 766 | * a reduced number of available apps, app restrictions and account restrictions. |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 767 | * @return whether the user making this call is a linked user |
Amith Yamasani | 2555daf | 2013-04-25 13:39:27 -0700 | [diff] [blame] | 768 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 769 | */ |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 770 | public boolean isLinkedUser() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 771 | try { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 772 | return mService.isRestricted(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 773 | } catch (RemoteException re) { |
Amith Yamasani | 46bc4eb | 2013-04-12 13:26:50 -0700 | [diff] [blame] | 774 | Log.w(TAG, "Could not check if user is limited ", re); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 775 | return false; |
| 776 | } |
| 777 | } |
| 778 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 779 | /** |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 780 | * Checks if specified user can have restricted profile. |
| 781 | * @hide |
| 782 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 783 | public boolean canHaveRestrictedProfile(@UserIdInt int userId) { |
Fyodor Kupolov | 1c36315 | 2015-09-02 13:27:21 -0700 | [diff] [blame] | 784 | try { |
| 785 | return mService.canHaveRestrictedProfile(userId); |
| 786 | } catch (RemoteException re) { |
| 787 | Log.w(TAG, "Could not check if user can have restricted profile", re); |
| 788 | return false; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 793 | * Checks if the calling app is running as a guest user. |
| 794 | * @return whether the caller is a guest user. |
| 795 | * @hide |
| 796 | */ |
| 797 | public boolean isGuestUser() { |
| 798 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
| 799 | return user != null ? user.isGuest() : false; |
| 800 | } |
| 801 | |
| 802 | /** |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 803 | * Checks if the calling app is running in a managed profile. |
| 804 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 805 | * |
| 806 | * @return whether the caller is in a managed profile. |
| 807 | * @hide |
| 808 | */ |
| 809 | @SystemApi |
| 810 | public boolean isManagedProfile() { |
| 811 | UserInfo user = getUserInfo(UserHandle.myUserId()); |
| 812 | return user != null ? user.isManagedProfile() : false; |
| 813 | } |
| 814 | |
| 815 | /** |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 816 | * Checks if the calling app is running as an ephemeral user. |
| 817 | * |
| 818 | * @return whether the caller is an ephemeral user. |
| 819 | * @hide |
| 820 | */ |
| 821 | public boolean isEphemeralUser() { |
| 822 | return isUserEphemeral(UserHandle.myUserId()); |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Returns whether the specified user is ephemeral. |
| 827 | * @hide |
| 828 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 829 | public boolean isUserEphemeral(@UserIdInt int userId) { |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 830 | final UserInfo user = getUserInfo(userId); |
| 831 | return user != null && user.isEphemeral(); |
| 832 | } |
| 833 | |
| 834 | /** |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 835 | * Return whether the given user is actively running. This means that |
| 836 | * the user is in the "started" state, not "stopped" -- it is currently |
| 837 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 838 | * etc. A started user may be either the current foreground user or a |
| 839 | * background user; the result here does not distinguish between the two. |
| 840 | * @param user The user to retrieve the running state for. |
| 841 | */ |
| 842 | public boolean isUserRunning(UserHandle user) { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 843 | return isUserRunning(user.getIdentifier()); |
| 844 | } |
| 845 | |
| 846 | /** {@hide} */ |
| 847 | public boolean isUserRunning(int userId) { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 848 | try { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 849 | return ActivityManagerNative.getDefault().isUserRunning(userId, 0); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 850 | } catch (RemoteException e) { |
| 851 | return false; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * Return whether the given user is actively running <em>or</em> stopping. |
| 857 | * This is like {@link #isUserRunning(UserHandle)}, but will also return |
| 858 | * true if the user had been running but is in the process of being stopped |
| 859 | * (but is not yet fully stopped, and still running some code). |
| 860 | * @param user The user to retrieve the running state for. |
| 861 | */ |
| 862 | public boolean isUserRunningOrStopping(UserHandle user) { |
| 863 | try { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 864 | // TODO: reconcile stopped vs stopping? |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 865 | return ActivityManagerNative.getDefault().isUserRunning( |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 866 | user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED); |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 867 | } catch (RemoteException e) { |
| 868 | return false; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /** |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 873 | * Return whether the calling user is running in a "locked" state. A user is |
| 874 | * unlocked only after they've entered their credentials (such as a lock |
| 875 | * pattern or PIN), and credential-encrypted private app data storage is |
| 876 | * available. |
| 877 | */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 878 | @Deprecated |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 879 | public boolean isUserRunningAndLocked() { |
| 880 | return isUserRunningAndLocked(Process.myUserHandle()); |
| 881 | } |
| 882 | |
| 883 | /** |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 884 | * Return whether the given user is running in a "locked" state. A user |
| 885 | * is unlocked only after they've entered their credentials (such as a lock |
| 886 | * pattern or PIN), and credential-encrypted private app data storage is |
| 887 | * available. |
| 888 | * |
| 889 | * @param user to retrieve the unlocked state for. |
| 890 | */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 891 | @Deprecated |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 892 | public boolean isUserRunningAndLocked(UserHandle user) { |
| 893 | try { |
| 894 | return ActivityManagerNative.getDefault().isUserRunning( |
| 895 | user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED); |
| 896 | } catch (RemoteException e) { |
| 897 | return false; |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /** |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 902 | * Return whether the calling user is running in an "unlocked" state. A user |
| 903 | * is unlocked only after they've entered their credentials (such as a lock |
| 904 | * pattern or PIN), and credential-encrypted private app data storage is |
| 905 | * available. |
| 906 | */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 907 | @Deprecated |
Jeff Sharkey | e13529a | 2015-12-09 14:15:27 -0700 | [diff] [blame] | 908 | public boolean isUserRunningAndUnlocked() { |
| 909 | return isUserRunningAndUnlocked(Process.myUserHandle()); |
| 910 | } |
| 911 | |
| 912 | /** |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 913 | * Return whether the given user is running in an "unlocked" state. A user |
| 914 | * is unlocked only after they've entered their credentials (such as a lock |
| 915 | * pattern or PIN), and credential-encrypted private app data storage is |
| 916 | * available. |
| 917 | * |
| 918 | * @param user to retrieve the unlocked state for. |
| 919 | */ |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 920 | @Deprecated |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 921 | public boolean isUserRunningAndUnlocked(UserHandle user) { |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 922 | try { |
| 923 | return ActivityManagerNative.getDefault().isUserRunning( |
| 924 | user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED); |
| 925 | } catch (RemoteException e) { |
| 926 | return false; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | /** |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 931 | * Return whether the calling user is running in an "unlocked" state. A user |
| 932 | * is unlocked only after they've entered their credentials (such as a lock |
| 933 | * pattern or PIN), and credential-encrypted private app data storage is |
| 934 | * available. |
| 935 | */ |
| 936 | public boolean isUserUnlocked() { |
| 937 | return isUserUnlocked(Process.myUserHandle()); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Return whether the given user is running in an "unlocked" state. A user |
| 942 | * is unlocked only after they've entered their credentials (such as a lock |
| 943 | * pattern or PIN), and credential-encrypted private app data storage is |
| 944 | * available. |
| 945 | * |
| 946 | * @param user to retrieve the unlocked state for. |
| 947 | */ |
| 948 | public boolean isUserUnlocked(UserHandle user) { |
Jeff Sharkey | 0999c0d | 2015-12-17 15:12:22 -0700 | [diff] [blame] | 949 | return isUserUnlocked(user.getIdentifier()); |
| 950 | } |
| 951 | |
| 952 | /** {@hide} */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 953 | public boolean isUserUnlocked(@UserIdInt int userId) { |
Jeff Sharkey | 5b0e520 | 2015-12-18 17:18:09 -0700 | [diff] [blame] | 954 | // TODO: eventually pivot this back to look at ActivityManager state, |
| 955 | // but there is race where we can start a non-encryption-aware launcher |
| 956 | // before that lifecycle has entered the running unlocked state. |
| 957 | return mContext.getSystemService(StorageManager.class).isUserKeyUnlocked(userId); |
Jeff Sharkey | b642387 | 2015-12-11 11:11:58 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 961 | * Returns the UserInfo object describing a specific user. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 962 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 963 | * @param userHandle the user handle of the user whose information is being requested. |
| 964 | * @return the UserInfo object for a specific user. |
| 965 | * @hide |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 966 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 967 | public UserInfo getUserInfo(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 968 | try { |
| 969 | return mService.getUserInfo(userHandle); |
| 970 | } catch (RemoteException re) { |
| 971 | Log.w(TAG, "Could not get user info", re); |
| 972 | return null; |
| 973 | } |
| 974 | } |
| 975 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Returns the user-wide restrictions imposed on this user. |
| 978 | * @return a Bundle containing all the restrictions. |
| 979 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 980 | public Bundle getUserRestrictions() { |
| 981 | return getUserRestrictions(Process.myUserHandle()); |
| 982 | } |
| 983 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 984 | /** |
| 985 | * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. |
| 986 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 987 | * @return a Bundle containing all the restrictions. |
| 988 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 989 | public Bundle getUserRestrictions(UserHandle userHandle) { |
| 990 | try { |
| 991 | return mService.getUserRestrictions(userHandle.getIdentifier()); |
| 992 | } catch (RemoteException re) { |
| 993 | Log.w(TAG, "Could not get user restrictions", re); |
| 994 | return Bundle.EMPTY; |
| 995 | } |
| 996 | } |
| 997 | |
Zoltan Szatmary-Ban | 3bbcedd | 2015-11-26 13:45:51 +0000 | [diff] [blame] | 998 | /** |
| 999 | * @hide |
| 1000 | * Returns whether the given user has been disallowed from performing certain actions |
| 1001 | * or setting certain settings through UserManager. This method disregards restrictions |
| 1002 | * set by device policy. |
| 1003 | * @param restrictionKey the string key representing the restriction |
| 1004 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1005 | */ |
| 1006 | public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) { |
| 1007 | try { |
| 1008 | return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier()); |
| 1009 | } catch (RemoteException re) { |
| 1010 | Log.w(TAG, "Could not get base user restrictions for user " + |
| 1011 | userHandle.getIdentifier(), re); |
| 1012 | return false; |
| 1013 | } |
| 1014 | } |
| 1015 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1016 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1017 | * This will no longer work. Device owners and profile owners should use |
| 1018 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1019 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1020 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1021 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1022 | public void setUserRestrictions(Bundle restrictions) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1023 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1026 | /** |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1027 | * This will no longer work. Device owners and profile owners should use |
| 1028 | * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1029 | */ |
Makoto Onuki | a3c1250 | 2015-10-28 10:18:32 -0700 | [diff] [blame] | 1030 | // System apps should use UserManager.setUserRestriction() instead. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1031 | @Deprecated |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1032 | public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1033 | throw new UnsupportedOperationException("This method is no longer supported"); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1036 | /** |
| 1037 | * Sets the value of a specific restriction. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1038 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1039 | * @param key the key of the restriction |
| 1040 | * @param value the value for the restriction |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1041 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1042 | * android.content.ComponentName, String)} or |
| 1043 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1044 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1045 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1046 | @Deprecated |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1047 | public void setUserRestriction(String key, boolean value) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1048 | setUserRestriction(key, value, Process.myUserHandle()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * @hide |
| 1053 | * Sets the value of a specific restriction on a specific user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1054 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1055 | * @param key the key of the restriction |
| 1056 | * @param value the value for the restriction |
| 1057 | * @param userHandle the user whose restriction is to be changed. |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1058 | * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( |
| 1059 | * android.content.ComponentName, String)} or |
| 1060 | * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( |
| 1061 | * android.content.ComponentName, String)} instead. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1062 | */ |
Julia Reynolds | 3d9eb78 | 2014-08-11 16:40:08 -0400 | [diff] [blame] | 1063 | @Deprecated |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1064 | public void setUserRestriction(String key, boolean value, UserHandle userHandle) { |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1065 | try { |
| 1066 | mService.setUserRestriction(key, value, userHandle.getIdentifier()); |
| 1067 | } catch (RemoteException re) { |
| 1068 | Log.w(TAG, "Could not set user restriction", re); |
| 1069 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1070 | } |
| 1071 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1072 | /** |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1073 | * Returns whether the current user has been disallowed from performing certain actions |
| 1074 | * or setting certain settings. |
Julia Reynolds | 2b2cf72 | 2014-06-06 11:41:04 -0400 | [diff] [blame] | 1075 | * |
| 1076 | * @param restrictionKey The string key representing the restriction. |
| 1077 | * @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] | 1078 | */ |
| 1079 | public boolean hasUserRestriction(String restrictionKey) { |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 1080 | return hasUserRestriction(restrictionKey, Process.myUserHandle()); |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * @hide |
| 1085 | * Returns whether the given user has been disallowed from performing certain actions |
| 1086 | * or setting certain settings. |
| 1087 | * @param restrictionKey the string key representing the restriction |
| 1088 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 1089 | */ |
| 1090 | public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 1091 | try { |
| 1092 | return mService.hasUserRestriction(restrictionKey, |
| 1093 | userHandle.getIdentifier()); |
| 1094 | } catch (RemoteException re) { |
| 1095 | Log.w(TAG, "Could not check user restrictions", re); |
| 1096 | return false; |
| 1097 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /** |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1101 | * Return the serial number for a user. This is a device-unique |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1102 | * number assigned to that user; if the user is deleted and then a new |
| 1103 | * 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] | 1104 | * @param user The user whose serial number is to be retrieved. |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1105 | * @return The serial number of the given user; returns -1 if the |
| 1106 | * given UserHandle does not exist. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1107 | * @see #getUserForSerialNumber(long) |
| 1108 | */ |
| 1109 | public long getSerialNumberForUser(UserHandle user) { |
| 1110 | return getUserSerialNumber(user.getIdentifier()); |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * Return the user associated with a serial number previously |
| 1115 | * returned by {@link #getSerialNumberForUser(UserHandle)}. |
| 1116 | * @param serialNumber The serial number of the user that is being |
| 1117 | * retrieved. |
| 1118 | * @return Return the user associated with the serial number, or null |
| 1119 | * if there is not one. |
| 1120 | * @see #getSerialNumberForUser(UserHandle) |
| 1121 | */ |
| 1122 | public UserHandle getUserForSerialNumber(long serialNumber) { |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 1123 | int ident = getUserHandle((int) serialNumber); |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1124 | return ident >= 0 ? new UserHandle(ident) : null; |
| 1125 | } |
| 1126 | |
| 1127 | /** |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1128 | * Creates a user with the specified name and options. For non-admin users, default user |
| 1129 | * restrictions are going to be applied. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1130 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1131 | * |
| 1132 | * @param name the user's name |
| 1133 | * @param flags flags that identify the type of user and other properties. |
| 1134 | * @see UserInfo |
| 1135 | * |
| 1136 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 1137 | * @hide |
| 1138 | */ |
| 1139 | public UserInfo createUser(String name, int flags) { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1140 | UserInfo user = null; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1141 | try { |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1142 | user = mService.createUser(name, flags); |
phweiss | e9c4406 | 2016-02-10 12:57:38 +0100 | [diff] [blame] | 1143 | // TODO: Keep this in sync with |
| 1144 | // UserManagerService.LocalService.createUserEvenWhenDisallowed |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1145 | if (user != null && !user.isAdmin()) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1146 | mService.setUserRestriction(DISALLOW_SMS, true, user.id); |
| 1147 | mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1148 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1149 | } catch (RemoteException re) { |
| 1150 | Log.w(TAG, "Could not create a user", re); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1151 | } |
Xiaohui Chen | cfe64c8 | 2015-07-16 14:30:50 -0700 | [diff] [blame] | 1152 | return user; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /** |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1156 | * Creates a guest user and configures it. |
| 1157 | * @param context an application context |
| 1158 | * @param name the name to set for the user |
| 1159 | * @hide |
| 1160 | */ |
| 1161 | public UserInfo createGuest(Context context, String name) { |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1162 | UserInfo guest = null; |
| 1163 | try { |
| 1164 | guest = mService.createUser(name, UserInfo.FLAG_GUEST); |
| 1165 | if (guest != null) { |
| 1166 | Settings.Secure.putStringForUser(context.getContentResolver(), |
| 1167 | Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1168 | } |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 1169 | } catch (RemoteException re) { |
| 1170 | Log.w(TAG, "Could not create a user", re); |
Amith Yamasani | 1e9c218 | 2014-06-11 17:25:51 -0700 | [diff] [blame] | 1171 | } |
| 1172 | return guest; |
| 1173 | } |
| 1174 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 1175 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1176 | * 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] | 1177 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1178 | * |
| 1179 | * @param name the user's name |
| 1180 | * @param flags flags that identify the type of user and other properties. |
| 1181 | * @see UserInfo |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1182 | * @param userHandle new user will be a profile of this use. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1183 | * |
| 1184 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 1185 | * @hide |
| 1186 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1187 | public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1188 | try { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1189 | return mService.createProfileForUser(name, flags, userHandle); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1190 | } catch (RemoteException re) { |
| 1191 | Log.w(TAG, "Could not create a user", re); |
| 1192 | return null; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | /** |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1197 | * Creates a restricted profile with the specified name. This method also sets necessary |
| 1198 | * restrictions and adds shared accounts. |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1199 | * |
| 1200 | * @param name profile's name |
| 1201 | * @return UserInfo object for the created user, or null if the user could not be created. |
| 1202 | * @hide |
| 1203 | */ |
| 1204 | public UserInfo createRestrictedProfile(String name) { |
| 1205 | try { |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1206 | UserHandle parentUserHandle = Process.myUserHandle(); |
| 1207 | UserInfo user = mService.createRestrictedProfile(name, |
| 1208 | parentUserHandle.getIdentifier()); |
| 1209 | if (user != null) { |
| 1210 | AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, |
| 1211 | UserHandle.of(user.id)); |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1212 | } |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 1213 | return user; |
Fyodor Kupolov | 06a484a | 2015-08-21 16:33:20 -0700 | [diff] [blame] | 1214 | } catch (RemoteException e) { |
| 1215 | Log.w(TAG, "Could not create a restricted profile", e); |
| 1216 | } |
| 1217 | return null; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1221 | * Returns an intent to create a user for the provided name and email address. The name |
| 1222 | * and email address will be used when the setup process for the new user is started. |
| 1223 | * If this device does not support multiple users, null is returned. |
| 1224 | * <p/> |
| 1225 | * The intent should be launched using startActivityForResult and the return result will |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1226 | * indicate if the user consented to adding a new user and if the operation succeeded. Any |
| 1227 | * errors in creating the user will be returned in the result code. If the user cancels the |
| 1228 | * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the |
| 1229 | * result code will be {@link Activity#RESULT_OK}. |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1230 | * <p/> |
| 1231 | * The new user is created but not initialized. After switching into the user for the first |
| 1232 | * time, the preferred user name and account information are used by the setup process for that |
| 1233 | * user. |
| 1234 | * |
| 1235 | * @param userName Optional name to assign to the user. |
| 1236 | * @param accountName Optional email address that will be used by the setup wizard to initialize |
| 1237 | * the user. |
| 1238 | * @param accountType Optional account type for the account to be created. This is required |
| 1239 | * if the account name is specified. |
| 1240 | * @param accountOptions Optional bundle of data to be passed in during account creation in the |
| 1241 | * new user via {@link AccountManager#addAccount(String, String, String[], |
| 1242 | * Bundle, android.app.Activity, android.accounts.AccountManagerCallback, |
| 1243 | * Handler)}. |
| 1244 | * @return An Intent that can be launched from an Activity or null if creating users is not |
| 1245 | * supported on this device. |
Amith Yamasani | 37ed8d1 | 2016-01-27 14:40:16 -0800 | [diff] [blame] | 1246 | * @see #USER_CREATION_FAILED_NOT_PERMITTED |
| 1247 | * @see #USER_CREATION_FAILED_NO_MORE_USERS |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1248 | */ |
| 1249 | public static Intent createUserCreationIntent(@Nullable String userName, |
| 1250 | @Nullable String accountName, |
| 1251 | @Nullable String accountType, @Nullable PersistableBundle accountOptions) { |
| 1252 | if (!supportsMultipleUsers() || getMaxSupportedUsers() < 2) { |
| 1253 | return null; |
| 1254 | } |
| 1255 | Intent intent = new Intent(ACTION_CREATE_USER); |
| 1256 | if (userName != null) { |
| 1257 | intent.putExtra(EXTRA_USER_NAME, userName); |
| 1258 | } |
| 1259 | if (accountName != null && accountType == null) { |
| 1260 | throw new IllegalArgumentException("accountType must be specified if accountName is " |
| 1261 | + "specified"); |
| 1262 | } |
| 1263 | if (accountName != null) { |
| 1264 | intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName); |
| 1265 | } |
| 1266 | if (accountType != null) { |
| 1267 | intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType); |
| 1268 | } |
| 1269 | if (accountOptions != null) { |
| 1270 | intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions); |
| 1271 | } |
| 1272 | return intent; |
| 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * @hide |
| 1277 | * |
| 1278 | * Returns the preferred account name for user creation. Requires MANAGE_USERS permission. |
| 1279 | */ |
| 1280 | @SystemApi |
| 1281 | public String getSeedAccountName() { |
| 1282 | try { |
| 1283 | return mService.getSeedAccountName(); |
| 1284 | } catch (RemoteException re) { |
| 1285 | Log.w(TAG, "Could not get the seed account name", re); |
| 1286 | return null; |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * @hide |
| 1292 | * |
| 1293 | * Returns the preferred account type for user creation. Requires MANAGE_USERS permission. |
| 1294 | */ |
| 1295 | @SystemApi |
| 1296 | public String getSeedAccountType() { |
| 1297 | try { |
| 1298 | return mService.getSeedAccountType(); |
| 1299 | } catch (RemoteException re) { |
| 1300 | Log.w(TAG, "Could not get the seed account type", re); |
| 1301 | return null; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | /** |
| 1306 | * @hide |
| 1307 | * |
| 1308 | * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS |
| 1309 | * permission. |
| 1310 | * @return Any options set by the requestor that created the user. |
| 1311 | */ |
| 1312 | @SystemApi |
| 1313 | public PersistableBundle getSeedAccountOptions() { |
| 1314 | try { |
| 1315 | return mService.getSeedAccountOptions(); |
| 1316 | } catch (RemoteException re) { |
| 1317 | Log.w(TAG, "Could not get the seed account options", re); |
| 1318 | return null; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * @hide |
| 1324 | * |
| 1325 | * Called by a system activity to set the seed account information of a user created |
| 1326 | * through the user creation intent. |
| 1327 | * @param userId |
| 1328 | * @param accountName |
| 1329 | * @param accountType |
| 1330 | * @param accountOptions |
| 1331 | * @see #createUserCreationIntent(String, String, String, PersistableBundle) |
| 1332 | */ |
| 1333 | public void setSeedAccountData(int userId, String accountName, String accountType, |
| 1334 | PersistableBundle accountOptions) { |
| 1335 | try { |
| 1336 | mService.setSeedAccountData(userId, accountName, accountType, accountOptions, |
| 1337 | /* persist= */ true); |
| 1338 | } catch (RemoteException re) { |
| 1339 | Log.w(TAG, "Could not set the seed account data", re); |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * @hide |
| 1345 | * Clears the seed information used to create this user. Requires MANAGE_USERS permission. |
| 1346 | */ |
| 1347 | @SystemApi |
| 1348 | public void clearSeedAccountData() { |
| 1349 | try { |
| 1350 | mService.clearSeedAccountData(); |
| 1351 | } catch (RemoteException re) { |
| 1352 | Log.w(TAG, "Could not clear the seed account data", re); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /** |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1357 | * @hide |
| 1358 | * Marks the guest user for deletion to allow a new guest to be created before deleting |
| 1359 | * the current user who is a guest. |
| 1360 | * @param userHandle |
| 1361 | * @return |
| 1362 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1363 | public boolean markGuestForDeletion(@UserIdInt int userHandle) { |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1364 | try { |
| 1365 | return mService.markGuestForDeletion(userHandle); |
| 1366 | } catch (RemoteException re) { |
| 1367 | Log.w(TAG, "Could not mark guest for deletion", re); |
| 1368 | return false; |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | /** |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 1373 | * Sets the user as enabled, if such an user exists. |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 1374 | * |
| 1375 | * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1376 | * |
| 1377 | * <p>Note that the default is true, it's only that managed profiles might not be enabled. |
| 1378 | * Also ephemeral users can be disabled to indicate that their removal is in progress and they |
| 1379 | * 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] | 1380 | * |
| 1381 | * @param userHandle the id of the profile to enable |
| 1382 | * @hide |
| 1383 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1384 | public void setUserEnabled(@UserIdInt int userHandle) { |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 1385 | try { |
| 1386 | mService.setUserEnabled(userHandle); |
| 1387 | } catch (RemoteException e) { |
| 1388 | Log.w(TAG, "Could not enable the profile", e); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /** |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 1393 | * Return the number of users currently created on the device. |
| 1394 | */ |
| 1395 | public int getUserCount() { |
| 1396 | List<UserInfo> users = getUsers(); |
| 1397 | return users != null ? users.size() : 1; |
| 1398 | } |
| 1399 | |
| 1400 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1401 | * Returns information for all users on this device. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1402 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 1403 | * @return the list of users that exist on the device. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1404 | * @hide |
| 1405 | */ |
| 1406 | public List<UserInfo> getUsers() { |
| 1407 | try { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1408 | return mService.getUsers(false); |
| 1409 | } catch (RemoteException re) { |
| 1410 | Log.w(TAG, "Could not get user list", re); |
| 1411 | return null; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | /** |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 1416 | * Returns serial numbers of all users on this device. |
| 1417 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1418 | * |
| 1419 | * @param excludeDying specify if the list should exclude users being removed. |
| 1420 | * @return the list of serial numbers of users that exist on the device. |
| 1421 | * @hide |
| 1422 | */ |
| 1423 | @SystemApi |
| 1424 | public long[] getSerialNumbersOfUsers(boolean excludeDying) { |
| 1425 | try { |
| 1426 | List<UserInfo> users = mService.getUsers(excludeDying); |
| 1427 | long[] result = new long[users.size()]; |
| 1428 | for (int i = 0; i < result.length; i++) { |
| 1429 | result[i] = users.get(i).serialNumber; |
| 1430 | } |
| 1431 | return result; |
| 1432 | } catch (RemoteException re) { |
| 1433 | Log.w(TAG, "Could not get users list", re); |
| 1434 | return null; |
| 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) { |
| 1450 | Log.w(TAG, "Could not get user account", re); |
| 1451 | return null; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /** |
| 1456 | * Set account name for the given user. |
| 1457 | * @hide |
| 1458 | */ |
| 1459 | @RequiresPermission( allOf = { |
| 1460 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 1461 | Manifest.permission.MANAGE_USERS |
| 1462 | }) |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1463 | public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) { |
Xiaohui Chen | b3b9258 | 2015-12-07 11:22:13 -0800 | [diff] [blame] | 1464 | try { |
| 1465 | mService.setUserAccount(userHandle, accountName); |
| 1466 | } catch (RemoteException re) { |
| 1467 | Log.w(TAG, "Could not set user account", re); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | /** |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1472 | * Returns information for Primary user. |
| 1473 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1474 | * |
| 1475 | * @return the Primary user, null if not found. |
| 1476 | * @hide |
| 1477 | */ |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1478 | public @Nullable UserInfo getPrimaryUser() { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 1479 | try { |
| 1480 | return mService.getPrimaryUser(); |
| 1481 | } catch (RemoteException re) { |
| 1482 | Log.w(TAG, "Could not get Primary user", re); |
| 1483 | return null; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | /** |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1488 | * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS |
| 1489 | * permission. |
| 1490 | * |
| 1491 | * @return true if more users can be added, false if limit has been reached. |
| 1492 | * @hide |
| 1493 | */ |
| 1494 | public boolean canAddMoreUsers() { |
| 1495 | final List<UserInfo> users = getUsers(true); |
| 1496 | final int totalUserCount = users.size(); |
| 1497 | int aliveUserCount = 0; |
| 1498 | for (int i = 0; i < totalUserCount; i++) { |
| 1499 | UserInfo user = users.get(i); |
| 1500 | if (!user.isGuest()) { |
| 1501 | aliveUserCount++; |
| 1502 | } |
| 1503 | } |
| 1504 | return aliveUserCount < getMaxSupportedUsers(); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1508 | * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS |
| 1509 | * permission. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 1510 | * if allowedToRemoveOne is true and if the user already has a managed profile, then return if |
| 1511 | * 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] | 1512 | * |
| 1513 | * @return true if more managed profiles can be added, false if limit has been reached. |
| 1514 | * @hide |
| 1515 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1516 | public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) { |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1517 | try { |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 1518 | return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); |
Nicolas Prevot | 72434b7 | 2015-05-13 12:15:03 -0700 | [diff] [blame] | 1519 | } catch (RemoteException re) { |
| 1520 | Log.w(TAG, "Could not check if we can add more managed profiles", re); |
| 1521 | return false; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1526 | * Returns list of the profiles of userHandle including |
| 1527 | * userHandle itself. |
Amith Yamasani | 4f7e2e3 | 2014-08-14 18:49:48 -0700 | [diff] [blame] | 1528 | * Note that this returns both enabled and not enabled profiles. See |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1529 | * {@link #getEnabledProfiles(int)} if you need only the enabled ones. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1530 | * |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1531 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1532 | * @param userHandle profiles of this user will be returned. |
| 1533 | * @return the list of profiles. |
| 1534 | * @hide |
| 1535 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1536 | public List<UserInfo> getProfiles(@UserIdInt int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1537 | try { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1538 | return mService.getProfiles(userHandle, false /* enabledOnly */); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1539 | } catch (RemoteException re) { |
| 1540 | Log.w(TAG, "Could not get user list", re); |
| 1541 | return null; |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | /** |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 1546 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1547 | * @param userId one of the two user ids to check. |
| 1548 | * @param otherUserId one of the two user ids to check. |
| 1549 | * @return true if the two user ids are in the same profile group. |
| 1550 | * @hide |
| 1551 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1552 | public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { |
Xiaohui Chen | fd5b774 | 2015-10-14 15:47:04 -0700 | [diff] [blame] | 1553 | try { |
| 1554 | return mService.isSameProfileGroup(userId, otherUserId); |
| 1555 | } catch (RemoteException re) { |
| 1556 | Log.w(TAG, "Could not get user list", re); |
| 1557 | return false; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | /** |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1562 | * Returns list of the profiles of userHandle including |
| 1563 | * userHandle itself. |
| 1564 | * Note that this returns only enabled. |
| 1565 | * |
| 1566 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 1567 | * @param userHandle profiles of this user will be returned. |
| 1568 | * @return the list of profiles. |
| 1569 | * @hide |
| 1570 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1571 | public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) { |
Ruben Brunk | 7f75da2 | 2015-04-30 17:46:30 -0700 | [diff] [blame] | 1572 | try { |
| 1573 | return mService.getProfiles(userHandle, true /* enabledOnly */); |
| 1574 | } catch (RemoteException re) { |
| 1575 | Log.w(TAG, "Could not get user list", re); |
| 1576 | return null; |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1581 | * Returns a list of UserHandles for profiles associated with the user that the calling process |
| 1582 | * is running on, including the user itself. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1583 | * |
| 1584 | * @return A non-empty list of UserHandles associated with the calling user. |
| 1585 | */ |
| 1586 | public List<UserHandle> getUserProfiles() { |
| 1587 | ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); |
Xiaohui Chen | 2b45f8a | 2015-08-04 15:12:23 -0700 | [diff] [blame] | 1588 | List<UserInfo> users; |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1589 | try { |
Alexandra Gherghina | f2e7b3f | 2014-04-30 17:01:03 +0000 | [diff] [blame] | 1590 | users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 1591 | } catch (RemoteException re) { |
| 1592 | Log.w(TAG, "Could not get user list", re); |
| 1593 | return null; |
| 1594 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1595 | for (UserInfo info : users) { |
| 1596 | UserHandle userHandle = new UserHandle(info.id); |
| 1597 | profiles.add(userHandle); |
| 1598 | } |
| 1599 | return profiles; |
| 1600 | } |
| 1601 | |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1602 | /** |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 1603 | * Returns the device credential owner id of the profile from |
| 1604 | * which this method is called, or userHandle if called from a user that |
| 1605 | * is not a profile. |
| 1606 | * |
| 1607 | * @hide |
| 1608 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1609 | public int getCredentialOwnerProfile(@UserIdInt int userHandle) { |
Andres Morales | c5548c0 | 2015-08-05 10:23:12 -0700 | [diff] [blame] | 1610 | try { |
| 1611 | return mService.getCredentialOwnerProfile(userHandle); |
| 1612 | } catch (RemoteException re) { |
| 1613 | Log.w(TAG, "Could not get credential owner", re); |
| 1614 | return -1; |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1619 | * Returns the parent of the profile which this method is called from |
| 1620 | * or null if called from a user that is not a profile. |
| 1621 | * |
| 1622 | * @hide |
| 1623 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1624 | public UserInfo getProfileParent(@UserIdInt int userHandle) { |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1625 | try { |
| 1626 | return mService.getProfileParent(userHandle); |
| 1627 | } catch (RemoteException re) { |
| 1628 | Log.w(TAG, "Could not get profile parent", re); |
| 1629 | return null; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | /** |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1634 | * Set quiet mode of a managed profile. |
| 1635 | * |
| 1636 | * @param userHandle The user handle of the profile. |
| 1637 | * @param enableQuietMode Whether quiet mode should be enabled or disabled. |
| 1638 | * @hide |
| 1639 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1640 | public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) { |
Rubin Xu | 0a29ecd | 2015-11-04 15:11:48 +0000 | [diff] [blame] | 1641 | try { |
| 1642 | mService.setQuietModeEnabled(userHandle, enableQuietMode); |
| 1643 | } catch (RemoteException e) { |
| 1644 | Log.w(TAG, "Could not change the profile's quiet mode", e); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * Returns whether the given profile is in quiet mode or not. |
| 1650 | * |
| 1651 | * @param userHandle The user handle of the profile to be queried. |
| 1652 | * @return true if the profile is in quiet mode, false otherwise. |
| 1653 | */ |
| 1654 | public boolean isQuietModeEnabled(UserHandle userHandle) { |
| 1655 | try { |
| 1656 | return mService.isQuietModeEnabled(userHandle.getIdentifier()); |
| 1657 | } catch (RemoteException e) { |
| 1658 | Log.w(TAG, "Could not query the profile's quiet mode", e); |
| 1659 | } |
| 1660 | return false; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1664 | * If the target user is a managed profile of the calling user or the caller |
| 1665 | * 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] | 1666 | * icon to be able to distinguish it from the original icon. For badging an |
| 1667 | * arbitrary drawable use {@link #getBadgedDrawableForUser( |
| 1668 | * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. |
| 1669 | * <p> |
| 1670 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
| 1671 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading |
| 1672 | * is performed in place and the original drawable is returned. |
| 1673 | * </p> |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1674 | * |
| 1675 | * @param icon The icon to badge. |
| 1676 | * @param user The target user. |
| 1677 | * @return A drawable that combines the original icon and a badge as |
| 1678 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1679 | * @removed |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 1680 | */ |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1681 | public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1682 | return mContext.getPackageManager().getUserBadgedIcon(icon, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1683 | } |
| 1684 | |
Kenny Guy | 701ea7c | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 1685 | /** |
| 1686 | * 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] | 1687 | * is itself a managed profile, then this returns a badged copy of the given |
| 1688 | * drawable allowing the user to distinguish it from the original drawable. |
| 1689 | * The caller can specify the location in the bounds of the drawable to be |
| 1690 | * badged where the badge should be applied as well as the density of the |
| 1691 | * badge to be used. |
| 1692 | * <p> |
| 1693 | * If the original drawable is a BitmapDrawable and the backing bitmap is |
| 1694 | * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading |
| 1695 | * is performed in place and the original drawable is returned. |
| 1696 | * </p> |
| 1697 | * |
| 1698 | * @param badgedDrawable The drawable to badge. |
| 1699 | * @param user The target user. |
| 1700 | * @param badgeLocation Where in the bounds of the badged drawable to place |
| 1701 | * the badge. If not provided, the badge is applied on top of the entire |
| 1702 | * drawable being badged. |
| 1703 | * @param badgeDensity The optional desired density for the badge as per |
| 1704 | * {@link android.util.DisplayMetrics#densityDpi}. If not provided, |
| 1705 | * the density of the display is used. |
| 1706 | * @return A drawable that combines the original drawable and a badge as |
| 1707 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1708 | * @removed |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1709 | */ |
| 1710 | public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, |
| 1711 | Rect badgeLocation, int badgeDensity) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1712 | return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, |
| 1713 | badgeLocation, badgeDensity); |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * 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] | 1718 | * is itself a managed profile, then this returns a copy of the label with |
| 1719 | * badging for accessibility services like talkback. E.g. passing in "Email" |
| 1720 | * and it might return "Work Email" for Email in the work profile. |
| 1721 | * |
| 1722 | * @param label The label to change. |
| 1723 | * @param user The target user. |
| 1724 | * @return A label that combines the original label and a badge as |
| 1725 | * determined by the system. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1726 | * @removed |
Kenny Guy | f7ecf7c | 2014-06-18 11:32:05 +0100 | [diff] [blame] | 1727 | */ |
Kenny Guy | 237aecd | 2014-07-21 14:06:09 +0100 | [diff] [blame] | 1728 | public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1729 | return mContext.getPackageManager().getUserBadgedLabel(label, user); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | /** |
| 1733 | * Returns information for all users on this device. Requires |
| 1734 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 1735 | * |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1736 | * @param excludeDying specify if the list should exclude users being |
| 1737 | * removed. |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1738 | * @return the list of users that were created. |
| 1739 | * @hide |
| 1740 | */ |
| 1741 | public List<UserInfo> getUsers(boolean excludeDying) { |
| 1742 | try { |
| 1743 | return mService.getUsers(excludeDying); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1744 | } catch (RemoteException re) { |
| 1745 | Log.w(TAG, "Could not get user list", re); |
| 1746 | return null; |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | /** |
| 1751 | * Removes a user and all associated data. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1752 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1753 | * @param userHandle the integer handle of the user, where 0 is the primary user. |
| 1754 | * @hide |
| 1755 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1756 | public boolean removeUser(@UserIdInt int userHandle) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1757 | try { |
| 1758 | return mService.removeUser(userHandle); |
| 1759 | } catch (RemoteException re) { |
| 1760 | Log.w(TAG, "Could not remove user ", re); |
| 1761 | return false; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | /** |
| 1766 | * Updates the user's name. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1767 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1768 | * |
| 1769 | * @param userHandle the user's integer handle |
| 1770 | * @param name the new name for the user |
| 1771 | * @hide |
| 1772 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1773 | public void setUserName(@UserIdInt int userHandle, String name) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1774 | try { |
| 1775 | mService.setUserName(userHandle, name); |
| 1776 | } catch (RemoteException re) { |
| 1777 | Log.w(TAG, "Could not set the user name ", re); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1782 | * Sets the user's photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1783 | * @param userHandle the user for whom to change the photo. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1784 | * @param icon the bitmap to set as the photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1785 | * @hide |
| 1786 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1787 | public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1788 | try { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1789 | mService.setUserIcon(userHandle, icon); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1790 | } catch (RemoteException re) { |
| 1791 | Log.w(TAG, "Could not set the user icon ", re); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | /** |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1796 | * Returns a file descriptor for the user's photo. PNG data can be read from this file. |
| 1797 | * @param userHandle the user whose photo we want to read. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1798 | * @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] | 1799 | * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1800 | * @hide |
| 1801 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1802 | public Bitmap getUserIcon(@UserIdInt int userHandle) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1803 | try { |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 1804 | ParcelFileDescriptor fd = mService.getUserIcon(userHandle); |
| 1805 | if (fd != null) { |
| 1806 | try { |
| 1807 | return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); |
| 1808 | } finally { |
| 1809 | try { |
| 1810 | fd.close(); |
| 1811 | } catch (IOException e) { |
| 1812 | } |
| 1813 | } |
| 1814 | } |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1815 | } catch (RemoteException re) { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 1816 | Log.w(TAG, "Could not get the user icon ", re); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1817 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 1818 | return null; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1822 | * Returns the maximum number of users that can be created on this device. A return value |
| 1823 | * of 1 means that it is a single user device. |
| 1824 | * @hide |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 1825 | * @return a value greater than or equal to 1 |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1826 | */ |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 1827 | public static int getMaxSupportedUsers() { |
Amith Yamasani | ff54920 | 2012-10-12 12:44:49 -0700 | [diff] [blame] | 1828 | // Don't allow multiple users on certain builds |
| 1829 | if (android.os.Build.ID.startsWith("JVP")) return 1; |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 1830 | // Svelte devices don't get multi-user. |
| 1831 | if (ActivityManager.isLowRamDeviceStatic()) return 1; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 1832 | return SystemProperties.getInt("fw.max_users", |
| 1833 | Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1834 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1835 | |
| 1836 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 1837 | * Returns true if the user switcher should be shown, this will be if device supports multi-user |
| 1838 | * 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] | 1839 | * @hide |
| 1840 | * @return true if user switcher should be shown. |
| 1841 | */ |
| 1842 | public boolean isUserSwitcherEnabled() { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 1843 | if (!supportsMultipleUsers()) { |
| 1844 | return false; |
| 1845 | } |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 1846 | List<UserInfo> users = getUsers(true); |
| 1847 | if (users == null) { |
| 1848 | return false; |
| 1849 | } |
| 1850 | int switchableUserCount = 0; |
| 1851 | for (UserInfo user : users) { |
Xiaohui Chen | 7cb69df | 2015-07-13 16:01:01 -0700 | [diff] [blame] | 1852 | if (user.supportsSwitchToByUser()) { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 1853 | ++switchableUserCount; |
| 1854 | } |
| 1855 | } |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 1856 | final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) |
| 1857 | .getGuestUserDisabled(null); |
Amith Yamasani | a596ff8 | 2014-06-12 18:12:38 -0700 | [diff] [blame] | 1858 | return switchableUserCount > 1 || guestEnabled; |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /** |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1862 | * Returns a serial number on this device for a given userHandle. User handles can be recycled |
| 1863 | * when deleting and creating users, but serial numbers are not reused until the device is wiped. |
| 1864 | * @param userHandle |
| 1865 | * @return a serial number associated with that user, or -1 if the userHandle is not valid. |
| 1866 | * @hide |
| 1867 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1868 | public int getUserSerialNumber(@UserIdInt int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1869 | try { |
| 1870 | return mService.getUserSerialNumber(userHandle); |
| 1871 | } catch (RemoteException re) { |
| 1872 | Log.w(TAG, "Could not get serial number for user " + userHandle); |
| 1873 | } |
| 1874 | return -1; |
| 1875 | } |
| 1876 | |
| 1877 | /** |
| 1878 | * Returns a userHandle on this device for a given user serial number. User handles can be |
| 1879 | * recycled when deleting and creating users, but serial numbers are not reused until the device |
| 1880 | * is wiped. |
| 1881 | * @param userSerialNumber |
| 1882 | * @return the userHandle associated with that user serial number, or -1 if the serial number |
| 1883 | * is not valid. |
| 1884 | * @hide |
| 1885 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 1886 | public @UserIdInt int getUserHandle(int userSerialNumber) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1887 | try { |
| 1888 | return mService.getUserHandle(userSerialNumber); |
| 1889 | } catch (RemoteException re) { |
| 1890 | Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); |
| 1891 | } |
| 1892 | return -1; |
| 1893 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 1894 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1895 | /** |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 1896 | * 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] | 1897 | * 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] | 1898 | * |
| 1899 | * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application, |
| 1900 | * where the types of values may be: |
| 1901 | * <ul> |
| 1902 | * <li>{@code boolean} |
| 1903 | * <li>{@code int} |
| 1904 | * <li>{@code String} or {@code String[]} |
| 1905 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 1906 | * </ul> |
| 1907 | * |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1908 | * @param packageName the package name of the calling application |
Esteban Talavera | 5b9f167 | 2015-12-11 15:22:34 +0000 | [diff] [blame] | 1909 | * @return a {@code Bundle} with the restrictions for that package, or {@code null} if there |
| 1910 | * are no saved restrictions. |
| 1911 | * |
| 1912 | * @see #KEY_RESTRICTIONS_PENDING |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1913 | */ |
| 1914 | public Bundle getApplicationRestrictions(String packageName) { |
| 1915 | try { |
| 1916 | return mService.getApplicationRestrictions(packageName); |
| 1917 | } catch (RemoteException re) { |
| 1918 | Log.w(TAG, "Could not get application restrictions for package " + packageName); |
| 1919 | } |
| 1920 | return null; |
| 1921 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1922 | |
| 1923 | /** |
| 1924 | * @hide |
| 1925 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1926 | public Bundle getApplicationRestrictions(String packageName, UserHandle user) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1927 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1928 | return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1929 | } catch (RemoteException re) { |
| 1930 | Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); |
| 1931 | } |
| 1932 | return null; |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * @hide |
| 1937 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1938 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1939 | UserHandle user) { |
| 1940 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1941 | mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1942 | } catch (RemoteException re) { |
| 1943 | Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); |
| 1944 | } |
| 1945 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1946 | |
| 1947 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1948 | * Sets a new challenge PIN for restrictions. This is only for use by pre-installed |
| 1949 | * apps and requires the MANAGE_USERS permission. |
| 1950 | * @param newPin the PIN to use for challenge dialogs. |
| 1951 | * @return Returns true if the challenge PIN was set successfully. |
Fyodor Kupolov | ef24909 | 2015-05-06 13:18:46 -0700 | [diff] [blame] | 1952 | * @deprecated The restrictions PIN functionality is no longer provided by the system. |
| 1953 | * This method is preserved for backwards compatibility reasons and always returns false. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1954 | */ |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1955 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1956 | return false; |
| 1957 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1958 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 1959 | /** |
| 1960 | * @hide |
| 1961 | * Set restrictions that should apply to any future guest user that's created. |
| 1962 | */ |
| 1963 | public void setDefaultGuestRestrictions(Bundle restrictions) { |
| 1964 | try { |
| 1965 | mService.setDefaultGuestRestrictions(restrictions); |
| 1966 | } catch (RemoteException re) { |
| 1967 | Log.w(TAG, "Could not set guest restrictions"); |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * @hide |
| 1973 | * Gets the default guest restrictions. |
| 1974 | */ |
| 1975 | public Bundle getDefaultGuestRestrictions() { |
| 1976 | try { |
| 1977 | return mService.getDefaultGuestRestrictions(); |
| 1978 | } catch (RemoteException re) { |
| 1979 | Log.w(TAG, "Could not set guest restrictions"); |
| 1980 | } |
| 1981 | return new Bundle(); |
| 1982 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 1983 | |
| 1984 | /** |
| 1985 | * Returns creation time of the user or of a managed profile associated with the calling user. |
| 1986 | * @param userHandle user handle of the user or a managed profile associated with the |
| 1987 | * calling user. |
| 1988 | * @return creation time in milliseconds since Epoch time. |
| 1989 | */ |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 1990 | public long getUserCreationTime(UserHandle userHandle) { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 1991 | try { |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 1992 | return mService.getUserCreationTime(userHandle.getIdentifier()); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 1993 | } catch (RemoteException re) { |
| 1994 | Log.w(TAG, "Could not get user creation time", re); |
| 1995 | return 0; |
| 1996 | } |
| 1997 | } |
Amith Yamasani | 1274787 | 2015-12-07 14:19:49 -0800 | [diff] [blame] | 1998 | |
| 1999 | /** |
| 2000 | * @hide |
| 2001 | * Checks if any uninitialized user has the specific seed account name and type. |
| 2002 | * |
| 2003 | * @param mAccountName The account name to check for |
| 2004 | * @param mAccountType The account type of the account to check for |
| 2005 | * @return whether the seed account was found |
| 2006 | */ |
| 2007 | public boolean someUserHasSeedAccount(String accountName, String accountType) { |
| 2008 | try { |
| 2009 | return mService.someUserHasSeedAccount(accountName, accountType); |
| 2010 | } catch (RemoteException re) { |
| 2011 | Log.w(TAG, "Could not check seed accounts", re); |
| 2012 | return false; |
| 2013 | } |
| 2014 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2015 | } |