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