blob: abfcfaacde218fe16e082e79ef773d9336dd49b4 [file] [log] [blame]
Amith Yamasani258848d2012-08-10 17:06:33 -07001/*
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 Sharkey8a372a02016-03-16 16:25:45 -060016
Amith Yamasani258848d2012-08-10 17:06:33 -070017package android.os;
18
Xiaohui Chenb3b92582015-12-07 11:22:13 -080019import android.Manifest;
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -070020import android.accounts.AccountManager;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010021import android.annotation.IntDef;
Adam Lesinskiada8deb2017-05-12 13:50:42 -070022import android.annotation.NonNull;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -070023import android.annotation.Nullable;
Xiaohui Chenb3b92582015-12-07 11:22:13 -080024import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070025import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SystemService;
Makoto Onukie72f81b2017-03-16 14:08:19 -070027import android.annotation.TestApi;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070028import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070029import android.annotation.WorkerThread;
Amith Yamasani37ed8d12016-01-27 14:40:16 -080030import android.app.Activity;
Dianne Hackborn409297d2014-07-10 17:39:20 -070031import android.app.ActivityManager;
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -070032import android.app.admin.DevicePolicyManager;
Makoto Onuki068c54a2015-10-13 14:34:03 -070033import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070034import android.content.Context;
Amith Yamasani12747872015-12-07 14:19:49 -080035import android.content.Intent;
Esteban Talavera8bd7c522017-02-13 12:35:04 +000036import android.content.IntentFilter;
Benjamin Franzf02420c2016-04-04 18:52:21 +010037import android.content.IntentSender;
Amith Yamasani258848d2012-08-10 17:06:33 -070038import android.content.pm.UserInfo;
Robin Lee83c79312018-02-09 19:27:18 +010039import android.content.res.Configuration;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070040import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050041import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010042import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080043import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080044import android.graphics.drawable.Drawable;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070045import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080046import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040047import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070048
Maggie Benthall67944582013-02-22 14:58:27 -050049import com.android.internal.R;
John Reckaa67f682016-09-20 14:24:21 -070050import com.android.internal.os.RoSystemProperties;
Maggie Benthall67944582013-02-22 14:58:27 -050051
Adrian Roos1bdff912015-02-17 15:51:35 +010052import java.io.IOException;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010053import java.lang.annotation.Retention;
54import java.lang.annotation.RetentionPolicy;
Amith Yamasani4f582632014-02-19 14:31:52 -080055import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070056import java.util.List;
57
58/**
Amith Yamasani06964342016-04-15 13:55:01 -070059 * Manages users and user details on a multi-user system. There are two major categories of
60 * users: fully customizable users with their own login, and managed profiles that share a workspace
61 * with a related user.
62 * <p>
63 * Users are different from accounts, which are managed by
64 * {@link AccountManager}. Each user can have their own set of accounts.
65 * <p>
66 * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
Amith Yamasani258848d2012-08-10 17:06:33 -070067 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060068@SystemService(Context.USER_SERVICE)
Amith Yamasani258848d2012-08-10 17:06:33 -070069public class UserManager {
70
Pavel Grafov4f4f6f82017-03-28 13:44:04 +010071 private static final String TAG = "UserManager";
Amith Yamasani258848d2012-08-10 17:06:33 -070072 private final IUserManager mService;
73 private final Context mContext;
74
Makoto Onukid49f3fa2017-01-25 14:09:48 -080075 private Boolean mIsManagedProfileCached;
76
Amith Yamasanie4cf7342012-12-17 11:12:09 -080077 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010078 * @hide
79 * No user restriction.
80 */
81 @SystemApi
82 public static final int RESTRICTION_NOT_SET = 0x0;
83
84 /**
85 * @hide
86 * User restriction set by system/user.
87 */
88 @SystemApi
89 public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
90
91 /**
92 * @hide
93 * User restriction set by a device owner.
94 */
95 @SystemApi
96 public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
97
98 /**
99 * @hide
100 * User restriction set by a profile owner.
101 */
102 @SystemApi
103 public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
104
105 /** @hide */
106 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700107 @IntDef(flag = true, prefix = { "RESTRICTION_" }, value = {
108 RESTRICTION_NOT_SET,
109 RESTRICTION_SOURCE_SYSTEM,
110 RESTRICTION_SOURCE_DEVICE_OWNER,
111 RESTRICTION_SOURCE_PROFILE_OWNER
112 })
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +0100113 @SystemApi
114 public @interface UserRestrictionSource {}
115
116 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -0700117 * Specifies if a user is disallowed from adding and removing accounts, unless they are
118 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
119 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700120 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700121 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +0000122 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
123 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
124 * management is disallowed.
125 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800126 * <p>Key for user restrictions.
127 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700128 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
129 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800130 * @see #getUserRestrictions()
131 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700132 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800133
134 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700135 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -0400136 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800137 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700138 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800139 * <p>Key for user restrictions.
140 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700141 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
142 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800143 * @see #getUserRestrictions()
144 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700145 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800146
147 /**
Christine Franks1bade5d2017-10-10 15:41:50 -0700148 * Specifies if a user is disallowed from changing the device
149 * language. The default value is <code>false</code>.
150 *
151 * <p>Key for user restrictions.
152 * <p>Type: Boolean
153 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
154 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
155 * @see #getUserRestrictions()
156 */
157 public static final String DISALLOW_CONFIG_LOCALE = "no_config_locale";
158
159 /**
Benjamin Millerf1c3ed12018-05-03 10:56:28 +0000160 * Specifies if a user is disallowed from installing applications. This user restriction also
161 * prevents device owners and profile owners installing apps. The default value is
162 * {@code false}.
Amith Yamasani26af8292014-09-09 09:57:27 -0700163 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800164 * <p>Key for user restrictions.
165 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700166 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
167 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800168 * @see #getUserRestrictions()
169 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700170 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800171
172 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700173 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700174 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700175 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800176 * <p>Key for user restrictions.
177 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700178 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
179 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800180 * @see #getUserRestrictions()
181 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700182 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800183
Amith Yamasani71e6c692013-03-24 17:39:28 -0700184 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800185 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700186 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800187 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800188 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700189 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800190 * <p>Key for user restrictions.
191 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700192 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
193 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500194 * @see #getUserRestrictions()
195 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700196 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500197
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400198 /**
yuemingw5fe75dc2017-11-29 15:52:56 +0000199 * Specifies if airplane mode is disallowed on the device.
200 *
201 * <p> This restriction can only be set by the device owner and the profile owner on the
202 * primary user and it applies globally - i.e. it disables airplane mode on the entire device.
203 * <p>The default value is <code>false</code>.
204 *
205 * <p>Key for user restrictions.
206 * <p>Type: Boolean
207 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
208 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
209 * @see #getUserRestrictions()
210 */
211 public static final String DISALLOW_AIRPLANE_MODE = "no_airplane_mode";
212
213 /**
yuemingwc6ac29d2018-01-10 16:54:08 +0000214 * Specifies if a user is disallowed from configuring brightness. When device owner sets it,
215 * it'll only be applied on the target(system) user.
216 *
217 * <p>The default value is <code>false</code>.
218 *
219 * <p>This user restriction has no effect on managed profiles.
220 * <p>Key for user restrictions.
221 * <p>Type: Boolean
222 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
223 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
224 * @see #getUserRestrictions()
225 */
226 public static final String DISALLOW_CONFIG_BRIGHTNESS = "no_config_brightness";
227
228 /**
yuemingwa1781442018-01-10 18:59:43 +0000229 * Specifies if ambient display is disallowed for the user.
230 *
231 * <p>The default value is <code>false</code>.
232 *
233 * <p>This user restriction has no effect on managed profiles.
234 * <p>Key for user restrictions.
235 * <p>Type: Boolean
236 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
237 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
238 * @see #getUserRestrictions()
239 */
240 public static final String DISALLOW_AMBIENT_DISPLAY = "no_ambient_display";
241
242 /**
yuemingw5cda3ae2018-01-15 10:26:19 +0000243 * Specifies if a user is disallowed from changing screen off timeout.
244 *
245 * <p>The default value is <code>false</code>.
246 *
247 * <p>This user restriction has no effect on managed profiles.
248 * <p>Key for user restrictions.
249 * <p>Type: Boolean
250 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
251 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
252 * @see #getUserRestrictions()
253 */
254 public static final String DISALLOW_CONFIG_SCREEN_TIMEOUT = "no_config_screen_timeout";
255
256 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700257 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400258 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100259 * Unknown sources exclude adb and special apps such as trusted app stores.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400260 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700261 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800262 * <p>Key for user restrictions.
263 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700264 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
265 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400266 * @see #getUserRestrictions()
267 */
268 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
269
270 /**
Tor Norbye33ca9122018-10-03 09:28:21 +0200271 * This restriction is a device-wide version of {@link #DISALLOW_INSTALL_UNKNOWN_SOURCES}.
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100272 *
273 * Specifies if all users on the device are disallowed from enabling the
274 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
Irina Dumitrescu0501eee2018-10-19 23:50:18 +0100275 *
276 * This restriction can be enabled by the profile owner, in which case all accounts and
277 * profiles will be affected.
278 *
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100279 * The default value is <code>false</code>.
280 *
281 * <p>Key for user restrictions.
282 * <p>Type: Boolean
283 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
284 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
285 * @see #getUserRestrictions()
286 */
287 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY =
288 "no_install_unknown_sources_globally";
289
290 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700291 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000292 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400293 * The default value is <code>false</code>.
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100294 * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
295 * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800296 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700297 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800298 * <p>Key for user restrictions.
299 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700300 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
301 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400302 * @see #getUserRestrictions()
303 */
304 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
305
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400306 /**
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100307 * Specifies if bluetooth is disallowed on the device.
308 *
309 * <p> This restriction can only be set by the device owner and the profile owner on the
310 * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
311 * <p>The default value is <code>false</code>.
312 * <p>Key for user restrictions.
313 * <p>Type: Boolean
314 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
315 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
316 * @see #getUserRestrictions()
317 */
318 public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
319
320 /**
Pavel Grafov4f4f6f82017-03-28 13:44:04 +0100321 * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
322 * owner can set this restriction. When it is set by device owner, all users on this device will
323 * be affected.
324 *
325 * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
326 * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
327 * managed profiles.
328 *
329 * <p>Key for user restrictions.
330 * <p>Type: Boolean
331 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
332 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
333 * @see #getUserRestrictions()
334 */
335 public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
336
337 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700338 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700339 * USB. This can only be set by device owners and profile owners on the primary user.
340 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700341 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800342 * <p>Key for user restrictions.
343 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700344 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
345 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400346 * @see #getUserRestrictions()
347 */
348 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
349
Emily Bernierb223f732013-04-11 15:46:36 -0400350 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700351 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400352 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700353 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800354 * <p>Key for user restrictions.
355 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700356 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
357 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400358 * @see #getUserRestrictions()
359 */
360 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
361
362 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800363 * When set on the primary user this specifies if the user can remove other users.
364 * When set on a secondary user, this specifies if the user can remove itself.
365 * This restriction has no effect on managed profiles.
366 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700367 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800368 * <p>Key for user restrictions.
369 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700370 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
371 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400372 * @see #getUserRestrictions()
373 */
374 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
375
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400376 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000377 * Specifies if managed profiles of this user can be removed, other than by its profile owner.
378 * The default value is <code>false</code>.
379 * <p>
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000380 * This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000381 *
382 * <p>Key for user restrictions.
383 * <p>Type: Boolean
384 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
385 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
386 * @see #getUserRestrictions()
387 */
388 public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
389
390 /**
Pavel Grafov9fb706c2018-02-27 14:07:52 +0000391 * Specifies if a user is disallowed from enabling or accessing debugging features. When set on
392 * the primary user, disables debugging features altogether, including USB debugging. When set
393 * on a managed profile or a secondary user, blocks debugging for that user only, including
394 * starting activities, making service calls, accessing content providers, sending broadcasts,
395 * installing/uninstalling packages, clearing user data, etc.
396 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700397 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800398 * <p>Key for user restrictions.
399 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700400 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
401 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400402 * @see #getUserRestrictions()
403 */
404 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
405
406 /**
Benjamin Miller05fef7e2017-07-24 10:11:39 +0200407 * Specifies if a user is disallowed from configuring a VPN. The default value is
408 * <code>false</code>. This restriction has an effect when set by device owners and, in Android
409 * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners.
410 * <p>This restriction also prevents VPNs from starting. However, in Android 7.0
411 * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does
412 * start always-on VPNs created by the device or profile owner.
Amith Yamasani26af8292014-09-09 09:57:27 -0700413 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800414 * <p>Key for user restrictions.
415 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700416 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
417 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400418 * @see #getUserRestrictions()
419 */
420 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
421
422 /**
yuemingw7810b8b2018-02-01 17:32:25 +0000423 * Specifies if a user is disallowed from enabling or disabling location providers. As a
424 * result, user is disallowed from turning on or off location. Device owner and profile owners
425 * can set this restriction and it only applies on the managed user.
yuemingw7cc2c4c2017-11-28 17:20:01 +0000426 *
427 * <p>In a managed profile, location sharing is forced off when it's off on primary user, so
428 * user can still turn off location sharing on managed profile when the restriction is set by
429 * profile owner on managed profile.
430 *
431 * <p>This user restriction is different from {@link #DISALLOW_SHARE_LOCATION},
432 * as the device owner or profile owner can still enable or disable location mode via
433 * {@link DevicePolicyManager#setSecureSetting} when this restriction is on.
434 *
435 * <p>The default value is <code>false</code>.
436 *
437 * <p>Key for user restrictions.
438 * <p>Type: Boolean
yuemingw7810b8b2018-02-01 17:32:25 +0000439 * @see android.location.LocationManager#isProviderEnabled(String)
yuemingw7cc2c4c2017-11-28 17:20:01 +0000440 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
441 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
442 * @see #getUserRestrictions()
443 */
yuemingw7810b8b2018-02-01 17:32:25 +0000444 public static final String DISALLOW_CONFIG_LOCATION = "no_config_location";
yuemingw7cc2c4c2017-11-28 17:20:01 +0000445
446 /**
yuemingwa9772f362017-10-23 18:34:35 +0100447 * Specifies if date, time and timezone configuring is disallowed.
448 *
449 * <p>When restriction is set by device owners, it applies globally - i.e., it disables date,
450 * time and timezone setting on the entire device and all users will be affected. When it's set
451 * by profile owners, it's only applied to the managed user.
452 * <p>The default value is <code>false</code>.
453 *
454 * <p>This user restriction has no effect on managed profiles.
455 * <p>Key for user restrictions.
456 * <p>Type: Boolean
457 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
458 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
459 * @see #getUserRestrictions()
460 */
461 public static final String DISALLOW_CONFIG_DATE_TIME = "no_config_date_time";
462
463 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700464 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700465 * & portable hotspots. This can only be set by device owners and profile owners on the
466 * primary user. The default value is <code>false</code>.
Rubin Xu1faf1442017-08-23 15:48:12 +0100467 * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set,
468 * tethering will be automatically turned off.
Amith Yamasani26af8292014-09-09 09:57:27 -0700469 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800470 * <p>Key for user restrictions.
471 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700472 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
473 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400474 * @see #getUserRestrictions()
475 */
476 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
477
478 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700479 * Specifies if a user is disallowed from resetting network settings
480 * from Settings. This can only be set by device owners and profile owners on the primary user.
481 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800482 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700483 * primary user can reset the network settings of the device.
484 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800485 * <p>Key for user restrictions.
486 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700487 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
488 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700489 * @see #getUserRestrictions()
490 */
491 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
492
493 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700494 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700495 * from Settings. This can only be set by device owners and profile owners on the primary user.
496 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800497 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800498 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700499 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800500 * <p>Key for user restrictions.
501 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700502 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
503 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400504 * @see #getUserRestrictions()
505 */
506 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
507
508 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000509 * Specifies if a user is disallowed from adding new users. This can only be set by device
510 * owners and profile owners on the primary user.
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700511 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800512 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800513 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700514 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800515 * <p>Key for user restrictions.
516 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700517 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
518 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400519 * @see #getUserRestrictions()
520 */
521 public static final String DISALLOW_ADD_USER = "no_add_user";
522
523 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000524 * Specifies if a user is disallowed from adding managed profiles.
525 * <p>The default value for an unmanaged user is <code>false</code>.
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000526 * For users with a device owner set, the default is <code>true</code>.
527 * <p>This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000528 *
529 * <p>Key for user restrictions.
530 * <p>Type: Boolean
531 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
532 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
533 * @see #getUserRestrictions()
534 */
535 public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
536
537 /**
Benjamin Millerd41a9fc2017-07-17 17:24:44 +0200538 * Specifies if a user is disallowed from disabling application verification. The default
539 * value is <code>false</code>.
540 *
541 * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher,
542 * this is a global user restriction. If a device owner or profile owner sets this restriction,
543 * the system enforces app verification across all users on the device. Running in earlier
544 * Android versions, this restriction affects only the profile that sets it.
Amith Yamasani26af8292014-09-09 09:57:27 -0700545 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800546 * <p>Key for user restrictions.
547 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700548 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
549 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400550 * @see #getUserRestrictions()
551 */
552 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
553
554 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700555 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700556 * broadcasts. This can only be set by device owners and profile owners on the primary user.
557 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800558 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800559 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700560 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800561 * <p>Key for user restrictions.
562 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700563 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
564 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400565 * @see #getUserRestrictions()
566 */
567 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
568
569 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700570 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700571 * networks. This can only be set by device owners and profile owners on the primary user.
572 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800573 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800574 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700575 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800576 * <p>Key for user restrictions.
577 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700578 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
579 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400580 * @see #getUserRestrictions()
581 */
582 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
583
584 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700585 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400586 * applications in Settings or launchers. The following actions will not be allowed when this
587 * restriction is enabled:
588 * <li>uninstalling apps</li>
589 * <li>disabling apps</li>
590 * <li>clearing app caches</li>
591 * <li>clearing app data</li>
592 * <li>force stopping apps</li>
593 * <li>clearing app defaults</li>
594 * <p>
595 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700596 *
Esteban Talavera8bd7c522017-02-13 12:35:04 +0000597 * <p><strong>Note:</strong> The user will still be able to perform those actions via other
598 * means (such as adb). Third party apps will also be able to uninstall apps via the
599 * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
600 * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
601 * used to prevent the user from uninstalling apps completely, and
602 * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
603 * to add a default intent handler for a given intent filter.
604 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800605 * <p>Key for user restrictions.
606 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700607 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
608 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400609 * @see #getUserRestrictions()
610 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400611 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400612
Emily Bernier394a6cd2014-05-07 12:49:20 -0400613 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700614 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700615 * physical external media. This can only be set by device owners and profile owners on the
616 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700617 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800618 * <p>Key for user restrictions.
619 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700620 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
621 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400622 * @see #getUserRestrictions()
623 */
624 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
625
626 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100627 * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
628 * will be muted. This can be set by device owners and profile owners. The default value is
629 * <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700630 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100631 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800632 * <p>Key for user restrictions.
633 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700634 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
635 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400636 * @see #getUserRestrictions()
637 */
638 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
639
640 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100641 * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
Wen ZHANG61ed0dc2017-08-23 14:27:02 +0100642 * will be muted. This can be set by device owners from API 21 and profile owners from API 24.
643 * The default value is <code>false</code>.
644 *
645 * <p>When the restriction is set by profile owners, then it only applies to relevant
646 * profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700647 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100648 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800649 * <p>Key for user restrictions.
650 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700651 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
652 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400653 * @see #getUserRestrictions()
654 */
655 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
656
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700657 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700658 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700659 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700660 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000661 * <p>This restriction has no effect on managed profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700662 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800663 * <p>Key for user restrictions.
664 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700665 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
666 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700667 * @see #getUserRestrictions()
668 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700669 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
670
671 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700672 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700673 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700674 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800675 * <p>Key for user restrictions.
676 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700677 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
678 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700679 * @see #getUserRestrictions()
680 */
681 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700682
Jason Monk1c7c3192014-06-26 12:52:18 -0400683 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700684 * Specifies if the user is not allowed to have fun. In some cases, the
685 * device owner may wish to prevent the user from experiencing amusement or
686 * joy while using the device. The default value is <code>false</code>.
687 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800688 * <p>Key for user restrictions.
689 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700690 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
691 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700692 * @see #getUserRestrictions()
693 */
694 public static final String DISALLOW_FUN = "no_fun";
695
696 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700697 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400698 * created. This will block the creation of the following types of windows.
699 * <li>{@link LayoutParams#TYPE_TOAST}</li>
700 * <li>{@link LayoutParams#TYPE_PHONE}</li>
701 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
702 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
703 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
704 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800705 * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
Jason Monk1c7c3192014-06-26 12:52:18 -0400706 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700707 * <p>This can only be set by device owners and profile owners on the primary user.
708 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700709 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800710 * <p>Key for user restrictions.
711 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700712 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
713 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400714 * @see #getUserRestrictions()
715 */
716 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
717
Nicolas Prevotf1939902014-06-25 09:29:02 +0100718 /**
Charles He22ff6f9d2017-10-05 21:28:55 +0100719 * Specifies that system error dialogs for crashed or unresponsive apps should not be shown.
720 * In this case, the system will force-stop the app as if the user chooses the "close app"
Benjamin Franz0c86fe12018-02-28 09:49:17 +0000721 * option on the UI. A feedback report isn't collected as there is no way for the user to
722 * provide explicit consent. The default value is <code>false</code>.
Charles He22ff6f9d2017-10-05 21:28:55 +0100723 *
Benjamin Franz0c86fe12018-02-28 09:49:17 +0000724 * <p>When this user restriction is set by device owners, it's applied to all users. When set by
725 * the profile owner of the primary user or a secondary user, the restriction affects only the
726 * calling user. This user restriction has no effect on managed profiles.
Charles He22ff6f9d2017-10-05 21:28:55 +0100727 *
Charles He22ff6f9d2017-10-05 21:28:55 +0100728 * <p>Key for user restrictions.
729 * <p>Type: Boolean
730 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
731 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
732 * @see #getUserRestrictions()
733 */
734 public static final String DISALLOW_SYSTEM_ERROR_DIALOGS = "no_system_error_dialogs";
735
736 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700737 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100738 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
739 * pasted in this profile.
740 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700741 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800742 * <p>Key for user restrictions.
743 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700744 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
745 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100746 * @see #getUserRestrictions()
747 */
748 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
749
Amith Yamasani26af8292014-09-09 09:57:27 -0700750 /**
751 * Specifies if the user is not allowed to use NFC to beam out data from apps.
752 * The default value is <code>false</code>.
753 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800754 * <p>Key for user restrictions.
755 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700756 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
757 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani26af8292014-09-09 09:57:27 -0700758 * @see #getUserRestrictions()
759 */
760 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
761
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000762 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100763 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
764 * generally means that wallpapers are not supported for the particular user. This user
765 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000766 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100767 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700768 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
769 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000770 * @see #getUserRestrictions()
771 */
772 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
773
774 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100775 * User restriction to disallow setting a wallpaper. Profile owner and device owner
776 * are able to set wallpaper regardless of this restriction.
777 * The default value is <code>false</code>.
778 *
779 * <p>Key for user restrictions.
780 * <p>Type: Boolean
781 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
782 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
783 * @see #getUserRestrictions()
784 */
785 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
786
787 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000788 * Specifies if the user is not allowed to reboot the device into safe boot mode.
789 * This can only be set by device owners and profile owners on the primary user.
790 * The default value is <code>false</code>.
791 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800792 * <p>Key for user restrictions.
793 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700794 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
795 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000796 * @see #getUserRestrictions()
797 */
798 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
799
800 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700801 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
802 * background users. The default value is <code>false</code>.
803 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700804 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
805 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700806 * @see #getUserRestrictions()
807 * @hide
808 */
809 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
810
811 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700812 * Specifies if a user is not allowed to run in the background and should be stopped during
813 * user switch. The default value is <code>false</code>.
814 *
815 * <p>This restriction can be set by device owners and profile owners.
816 *
817 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
818 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
819 * @see #getUserRestrictions()
820 * @hide
821 */
Robin Lee6cfb7a92017-12-18 15:14:46 +0100822 @SystemApi
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700823 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
824
825 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700826 * Specifies if a user is not allowed to use the camera.
827 *
828 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
829 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
830 * @see #getUserRestrictions()
831 * @hide
832 */
833 public static final String DISALLOW_CAMERA = "no_camera";
834
835 /**
Tony Makc1205112016-07-22 16:02:59 +0100836 * Specifies if a user is not allowed to unmute the device's master volume.
837 *
838 * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
839 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
840 * @see #getUserRestrictions()
841 * @hide
842 */
Esteban Talavera492b4722017-02-13 14:59:45 +0000843 public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
Tony Makc1205112016-07-22 16:02:59 +0100844
845 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000846 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
847 * device owners. The default value is <code>false</code>.
848 *
849 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
850 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
851 * @see #getUserRestrictions()
852 */
853 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
854
855 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100856 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
857 * can set this restriction. When it is set by device owner, only the target user will be
858 * affected. The default value is <code>false</code>.
859 *
860 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100861 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100862 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
863 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
864 * @see #getUserRestrictions()
865 */
866 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
867
868 /**
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100869 * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100870 * <code>false</code>. Setting this restriction has no effect if the bootloader is already
871 * unlocked.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100872 *
Lenka Trochtova12b04962016-11-29 21:00:12 +0100873 * <p>Not for use by third-party applications.
874 *
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100875 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
876 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
877 * @see #getUserRestrictions()
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000878 * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100879 * @hide
880 */
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000881 @Deprecated
Lenka Trochtova12b04962016-11-29 21:00:12 +0100882 @SystemApi
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100883 public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
884
885 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +0100886 * Specifies that the managed profile is not allowed to have unified lock screen challenge with
887 * the primary user.
888 *
889 * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a
890 * separate challenge. Profile owner can ask the user to set a new password using
891 * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using
892 * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}.
893 *
894 * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed
895 * profile owner. Has no effect on non-managed profiles or users.
896 * <p>Key for user restrictions.
897 * <p>Type: Boolean
898 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
899 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
900 * @see #getUserRestrictions()
901 */
902 public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password";
903
904 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700905 * Allows apps in the parent profile to handle web links from the managed profile.
906 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700907 * This user restriction has an effect only in a managed profile.
908 * If set:
909 * Intent filters of activities in the parent profile with action
910 * {@link android.content.Intent#ACTION_VIEW},
911 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
912 * define a host can handle intents from the managed profile.
913 * The default value is <code>false</code>.
914 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800915 * <p>Key for user restrictions.
916 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700917 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
918 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700919 * @see #getUserRestrictions()
920 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700921 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
922 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700923
924 /**
Felipe Leme24d58932017-03-21 14:13:58 -0700925 * Specifies if a user is not allowed to use Autofill Services.
926 *
927 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
928 * only the target user will be affected.
929 *
930 * <p>The default value is <code>false</code>.
931 *
932 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
933 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
934 * @see #getUserRestrictions()
935 */
936 public static final String DISALLOW_AUTOFILL = "no_autofill";
937
938 /**
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700939 * Specifies if the contents of a user's screen is not allowed to be captured for artificial
940 * intelligence purposes.
941 *
942 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
943 * only the target user will be affected.
944 *
945 * <p>The default value is <code>false</code>.
946 *
947 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
948 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
949 * @see #getUserRestrictions()
950 */
951 public static final String DISALLOW_INTELLIGENCE_CAPTURE = "no_intelligence_capture";
952
953 /**
Benjamin Franzff66fa92017-08-10 10:39:44 +0100954 * Specifies if user switching is blocked on the current user.
955 *
956 * <p> This restriction can only be set by the device owner, it will be applied to all users.
Alex Chau71ada442018-02-22 12:56:59 +0800957 * Device owner can still switch user via
958 * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is
959 * set.
Benjamin Franzff66fa92017-08-10 10:39:44 +0100960 *
961 * <p>The default value is <code>false</code>.
962 *
963 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
964 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
965 * @see #getUserRestrictions()
966 */
967 public static final String DISALLOW_USER_SWITCH = "no_user_switch";
968
969 /**
Rubin Xucc391c22018-01-02 20:37:35 +0000970 * Specifies whether the user can share file / picture / data from the primary user into the
971 * managed profile, either by sending them from the primary side, or by picking up data within
972 * an app in the managed profile.
973 * <p>
974 * When a managed profile is created, the system allows the user to send data from the primary
975 * side to the profile by setting up certain default cross profile intent filters. If
976 * this is undesired, this restriction can be set to disallow it. Note that this restriction
977 * will not block any sharing allowed by explicit
978 * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner.
979 * <p>
980 * This restriction is only meaningful when set by profile owner. When it is set by device
981 * owner, it does not have any effect.
982 * <p>
983 * The default value is <code>false</code>.
984 *
985 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
986 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
987 * @see #getUserRestrictions()
988 */
989 public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile";
Vladislav Kuzkokov622b9f92018-01-25 16:33:05 +0100990
991 /**
992 * Specifies whether the user is allowed to print.
993 *
994 * This restriction can be set by device or profile owner.
995 *
996 * The default value is {@code false}.
997 *
998 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
999 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1000 * @see #getUserRestrictions()
1001 */
1002 public static final String DISALLOW_PRINTING = "no_printing";
1003
Rubin Xucc391c22018-01-02 20:37:35 +00001004 /**
Eran Messeri09b122da2018-10-05 15:33:53 +01001005 * Specifies whether the user is allowed to modify private DNS settings.
1006 *
1007 * <p>The default value is <code>false</code>.
1008 *
1009 * <p>This user restriction can only be applied by the Device Owner.
1010 * <p>Key for user restrictions.
1011 * <p>Type: Boolean
1012 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1013 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1014 * @see #getUserRestrictions()
1015 */
1016 public static final String DISALLOW_CONFIG_PRIVATE_DNS =
1017 "disallow_config_private_dns";
1018
1019 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00001020 * Application restriction key that is used to indicate the pending arrival
1021 * of real restrictions for the app.
1022 *
1023 * <p>
1024 * Applications that support restrictions should check for the presence of this key.
1025 * A <code>true</code> value indicates that restrictions may be applied in the near
1026 * future but are not available yet. It is the responsibility of any
1027 * management application that sets this flag to update it when the final
1028 * restrictions are enforced.
1029 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -08001030 * <p>Key for application restrictions.
1031 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +00001032 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
1033 * android.content.ComponentName, String, Bundle)
1034 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
1035 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00001036 */
1037 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
1038
Amith Yamasani12747872015-12-07 14:19:49 -08001039 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
1040
1041 /**
1042 * Extra containing a name for the user being created. Optional parameter passed to
1043 * ACTION_CREATE_USER activity.
1044 * @hide
1045 */
1046 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
1047
1048 /**
1049 * Extra containing account name for the user being created. Optional parameter passed to
1050 * ACTION_CREATE_USER activity.
1051 * @hide
1052 */
1053 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
1054
1055 /**
1056 * Extra containing account type for the user being created. Optional parameter passed to
1057 * ACTION_CREATE_USER activity.
1058 * @hide
1059 */
1060 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
1061
1062 /**
1063 * Extra containing account-specific data for the user being created. Optional parameter passed
1064 * to ACTION_CREATE_USER activity.
1065 * @hide
1066 */
1067 public static final String EXTRA_USER_ACCOUNT_OPTIONS
1068 = "android.os.extra.USER_ACCOUNT_OPTIONS";
1069
Amith Yamasani655d0e22013-06-12 14:19:10 -07001070 /** @hide */
1071 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
1072 /** @hide */
1073 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
1074 /** @hide */
1075 public static final int PIN_VERIFICATION_SUCCESS = -1;
1076
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001077 /**
Makoto Onukie72f81b2017-03-16 14:08:19 -07001078 * Sent when user restrictions have changed.
1079 *
1080 * @hide
1081 */
1082 @SystemApi
1083 @TestApi // To allow seeing it from CTS.
1084 public static final String ACTION_USER_RESTRICTIONS_CHANGED =
1085 "android.os.action.USER_RESTRICTIONS_CHANGED";
1086
1087 /**
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001088 * Error result indicating that this user is not allowed to add other users on this device.
1089 * This is a result code returned from the activity created by the intent
1090 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1091 */
1092 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
1093
1094 /**
1095 * Error result indicating that no more users can be created on this device.
1096 * This is a result code returned from the activity created by the intent
1097 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1098 */
1099 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
1100
Alex Chau89386ba2018-02-13 11:09:17 +08001101 /**
1102 * Indicates user operation is successful.
1103 */
1104 public static final int USER_OPERATION_SUCCESS = 0;
1105
1106 /**
1107 * Indicates user operation failed for unknown reason.
1108 */
1109 public static final int USER_OPERATION_ERROR_UNKNOWN = 1;
1110
1111 /**
1112 * Indicates user operation failed because target user is a managed profile.
1113 */
1114 public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2;
1115
1116 /**
1117 * Indicates user operation failed because maximum running user limit has been reached.
1118 */
1119 public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3;
1120
1121 /**
1122 * Indicates user operation failed because the target user is in the foreground.
1123 */
1124 public static final int USER_OPERATION_ERROR_CURRENT_USER = 4;
1125
1126 /**
1127 * Indicates user operation failed because device has low data storage.
1128 */
1129 public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5;
1130
1131 /**
1132 * Indicates user operation failed because maximum user limit has been reached.
1133 */
1134 public static final int USER_OPERATION_ERROR_MAX_USERS = 6;
1135
1136 /**
1137 * Result returned from various user operations.
1138 *
1139 * @hide
1140 */
1141 @Retention(RetentionPolicy.SOURCE)
1142 @IntDef(prefix = { "USER_OPERATION_" }, value = {
1143 USER_OPERATION_SUCCESS,
1144 USER_OPERATION_ERROR_UNKNOWN,
1145 USER_OPERATION_ERROR_MANAGED_PROFILE,
1146 USER_OPERATION_ERROR_MAX_RUNNING_USERS,
1147 USER_OPERATION_ERROR_CURRENT_USER,
1148 USER_OPERATION_ERROR_LOW_STORAGE,
1149 USER_OPERATION_ERROR_MAX_USERS
1150 })
1151 public @interface UserOperationResult {}
1152
1153 /**
1154 * Thrown to indicate user operation failed.
1155 */
1156 public static class UserOperationException extends RuntimeException {
1157 private final @UserOperationResult int mUserOperationResult;
1158
1159 /**
1160 * Constructs a UserOperationException with specific result code.
1161 *
1162 * @param message the detail message
1163 * @param userOperationResult the result code
1164 * @hide
1165 */
1166 public UserOperationException(String message,
1167 @UserOperationResult int userOperationResult) {
1168 super(message);
1169 mUserOperationResult = userOperationResult;
1170 }
1171
1172 /**
1173 * Returns the operation result code.
1174 */
1175 public @UserOperationResult int getUserOperationResult() {
1176 return mUserOperationResult;
1177 }
1178 }
1179
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001180 /** @hide */
Amith Yamasanic0688302015-10-30 10:40:03 -07001181 public static UserManager get(Context context) {
1182 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -07001183 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001184
Amith Yamasani258848d2012-08-10 17:06:33 -07001185 /** @hide */
1186 public UserManager(Context context, IUserManager service) {
1187 mService = service;
Fyodor Kupolov5200e1c2016-10-17 18:46:16 -07001188 mContext = context.getApplicationContext();
Amith Yamasani258848d2012-08-10 17:06:33 -07001189 }
1190
1191 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001192 * Returns whether this device supports multiple users with their own login and customizable
1193 * space.
1194 * @return whether the device supports multiple users.
Amith Yamasani258848d2012-08-10 17:06:33 -07001195 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -07001196 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +00001197 return getMaxSupportedUsers() > 1
1198 && SystemProperties.getBoolean("fw.show_multiuserui",
1199 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -07001200 }
1201
Maggie Benthall67944582013-02-22 14:58:27 -05001202 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001203 * @hide
1204 * @return Whether the device is running with split system user. It means the system user and
1205 * primary user are two separate users. Previously system user and primary user are combined as
1206 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
1207 */
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001208 @TestApi
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001209 public static boolean isSplitSystemUser() {
John Reckaa67f682016-09-20 14:24:21 -07001210 return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001211 }
1212
1213 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001214 * @return Whether guest user is always ephemeral
1215 * @hide
1216 */
1217 public static boolean isGuestUserEphemeral() {
1218 return Resources.getSystem()
1219 .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
1220 }
1221
1222 /**
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001223 * Returns whether switching users is currently allowed.
1224 * <p>For instance switching users is not allowed if the current user is in a phone call,
Benjamin Franzff66fa92017-08-10 10:39:44 +01001225 * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set.
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001226 * @hide
1227 */
1228 public boolean canSwitchUsers() {
1229 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
1230 mContext.getContentResolver(),
1231 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
1232 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
1233 boolean inCall = TelephonyManager.getDefault().getCallState()
1234 != TelephonyManager.CALL_STATE_IDLE;
Benjamin Franzff66fa92017-08-10 10:39:44 +01001235 boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
1236 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
1237 && !isUserSwitchDisallowed;
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001238 }
1239
1240 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001241 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +01001242 *
Amith Yamasani5760e172015-04-17 18:42:41 -07001243 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -07001244 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -05001245 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001246 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001247 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -07001248 }
1249
1250 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001251 * Returns the user name of the user making this call. This call is only
1252 * available to applications on the system image; it requires the
1253 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001254 * @return the user name
1255 */
1256 public String getUserName() {
Will Harmond9dcfb12017-05-18 15:41:15 -07001257 UserInfo user = getUserInfo(getUserHandle());
1258 return user == null ? "" : user.name;
Amith Yamasani258848d2012-08-10 17:06:33 -07001259 }
1260
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001261 /**
Fyodor Kupolov605b12a2017-05-10 15:58:09 -07001262 * Returns whether user name has been set.
1263 * <p>This method can be used to check that the value returned by {@link #getUserName()} was
1264 * set by the user and is not a placeholder string provided by the system.
1265 * @hide
1266 */
1267 public boolean isUserNameSet() {
1268 try {
1269 return mService.isUserNameSet(getUserHandle());
1270 } catch (RemoteException re) {
1271 throw re.rethrowFromSystemServer();
1272 }
1273 }
1274
1275 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -07001276 * Used to determine whether the user making this call is subject to
1277 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001278 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001279 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001280 * now automatically identify goats using advanced goat recognition technology.</p>
1281 *
1282 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -07001283 */
1284 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -07001285 return mContext.getPackageManager()
1286 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -07001287 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001288
1289 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001290 * Used to check if this process is running under the primary user. The primary user
1291 * is the first human user on a device.
1292 *
1293 * @return whether this process is running under the primary user.
1294 * @hide
1295 */
Varun Shahe142e332018-10-22 15:52:56 -07001296 @SystemApi
1297 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001298 public boolean isPrimaryUser() {
1299 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001300 return user != null && user.isPrimary();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001301 }
1302
1303 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001304 * Used to check if this process is running under the system user. The system user
1305 * is the initial user that is implicitly created on first boot and hosts most of the
1306 * system services.
1307 *
1308 * @return whether this process is running under the system user.
1309 */
1310 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001311 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -07001312 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001313
Amith Yamasani5760e172015-04-17 18:42:41 -07001314 /**
Varun Shahe142e332018-10-22 15:52:56 -07001315 * Used to check if this process is running as an admin user. An admin user is allowed to
1316 * modify or configure certain settings that aren't available to non-admin users,
1317 * create and delete additional users, etc. There can be more than one admin users.
1318 *
1319 * @return whether this process is running under an admin user.
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001320 * @hide
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001321 */
Varun Shahe142e332018-10-22 15:52:56 -07001322 @SystemApi
1323 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001324 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001325 return isUserAdmin(UserHandle.myUserId());
1326 }
1327
1328 /**
1329 * @hide
1330 * Returns whether the provided user is an admin user. There can be more than one admin
1331 * user.
1332 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001333 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001334 UserInfo user = getUserInfo(userId);
1335 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001336 }
1337
1338 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001339 * @hide
1340 * @deprecated Use {@link #isRestrictedProfile()}
1341 */
1342 @Deprecated
1343 public boolean isLinkedUser() {
1344 return isRestrictedProfile();
1345 }
1346
1347 /**
Varun Shahe142e332018-10-22 15:52:56 -07001348 * Used to check if this process is running under a restricted profile. Restricted profiles
1349 * may have a reduced number of available apps, app restrictions, and account restrictions.
1350 *
1351 * @return whether this process is running under a restricted profile.
Amith Yamasani2555daf2013-04-25 13:39:27 -07001352 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001353 */
Fyodor Kupolovca177562017-11-09 17:43:01 -08001354 @SystemApi
Varun Shahe142e332018-10-22 15:52:56 -07001355 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolovca177562017-11-09 17:43:01 -08001356 public boolean isRestrictedProfile() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001357 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001358 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001359 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001360 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001361 }
1362 }
1363
Amith Yamasani258848d2012-08-10 17:06:33 -07001364 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001365 * Checks if specified user can have restricted profile.
1366 * @hide
1367 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001368 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001369 try {
1370 return mService.canHaveRestrictedProfile(userId);
1371 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001372 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001373 }
1374 }
1375
1376 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001377 * Returns whether the calling user has at least one restricted profile associated with it.
1378 * @return
1379 * @hide
1380 */
1381 @SystemApi
1382 public boolean hasRestrictedProfiles() {
1383 try {
1384 return mService.hasRestrictedProfiles();
1385 } catch (RemoteException re) {
1386 throw re.rethrowFromSystemServer();
1387 }
1388 }
1389
1390 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001391 * Checks if a user is a guest user.
1392 * @return whether user is a guest user.
1393 * @hide
1394 */
1395 public boolean isGuestUser(int id) {
1396 UserInfo user = getUserInfo(id);
1397 return user != null && user.isGuest();
1398 }
1399
1400 /**
Varun Shahe142e332018-10-22 15:52:56 -07001401 * Used to check if this process is running under a guest user. A guest user may be transient.
1402 *
1403 * @return whether this process is running under a guest user.
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001404 * @hide
1405 */
Varun Shahe142e332018-10-22 15:52:56 -07001406 @SystemApi
1407 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001408 public boolean isGuestUser() {
1409 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001410 return user != null && user.isGuest();
1411 }
1412
Fyodor Kupolovca177562017-11-09 17:43:01 -08001413
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001414 /**
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001415 * Checks if the calling app is running in a demo user. When running in a demo user,
1416 * apps can be more helpful to the user, or explain their features in more detail.
1417 *
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001418 * @return whether the caller is a demo user.
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001419 */
1420 public boolean isDemoUser() {
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001421 try {
1422 return mService.isDemoUser(UserHandle.myUserId());
1423 } catch (RemoteException re) {
1424 throw re.rethrowFromSystemServer();
1425 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001426 }
1427
1428 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001429 * Checks if the calling app is running in a managed profile.
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001430 *
1431 * @return whether the caller is in a managed profile.
1432 * @hide
1433 */
1434 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001435 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001436 public boolean isManagedProfile() {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001437 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1438 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1439 if (mIsManagedProfileCached != null) {
1440 return mIsManagedProfileCached;
1441 }
Tony Mak8673b282016-03-21 21:10:59 +00001442 try {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001443 mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1444 return mIsManagedProfileCached;
Tony Mak8673b282016-03-21 21:10:59 +00001445 } catch (RemoteException re) {
1446 throw re.rethrowFromSystemServer();
1447 }
1448 }
1449
1450 /**
1451 * Checks if the specified user is a managed profile.
1452 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1453 * must be in the same profile group of specified user.
1454 *
1455 * @return whether the specified user is a managed profile.
1456 * @hide
1457 */
1458 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001459 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Tony Mak8673b282016-03-21 21:10:59 +00001460 public boolean isManagedProfile(@UserIdInt int userId) {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001461 if (userId == UserHandle.myUserId()) {
1462 return isManagedProfile();
1463 }
Tony Mak8673b282016-03-21 21:10:59 +00001464 try {
1465 return mService.isManagedProfile(userId);
1466 } catch (RemoteException re) {
1467 throw re.rethrowFromSystemServer();
1468 }
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001469 }
1470
1471 /**
Kenny Guy02c89902016-11-15 19:36:38 +00001472 * Gets badge for a managed profile.
1473 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1474 * must be in the same profile group of specified user.
1475 *
1476 * @return which badge to use for the managed profile badge id will be less than
1477 * UserManagerService.getMaxManagedProfiles()
1478 * @hide
1479 */
1480 public int getManagedProfileBadge(@UserIdInt int userId) {
1481 try {
1482 return mService.getManagedProfileBadge(userId);
1483 } catch (RemoteException re) {
1484 throw re.rethrowFromSystemServer();
1485 }
1486 }
1487
1488 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001489 * Checks if the calling app is running as an ephemeral user.
1490 *
1491 * @return whether the caller is an ephemeral user.
1492 * @hide
1493 */
1494 public boolean isEphemeralUser() {
1495 return isUserEphemeral(UserHandle.myUserId());
1496 }
1497
1498 /**
1499 * Returns whether the specified user is ephemeral.
1500 * @hide
1501 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001502 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001503 final UserInfo user = getUserInfo(userId);
1504 return user != null && user.isEphemeral();
1505 }
1506
1507 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001508 * Return whether the given user is actively running. This means that
1509 * the user is in the "started" state, not "stopped" -- it is currently
1510 * allowed to run code through scheduled alarms, receiving broadcasts,
1511 * etc. A started user may be either the current foreground user or a
1512 * background user; the result here does not distinguish between the two.
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001513 *
1514 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1515 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1516 * in order to check other profile's status.
1517 * Since Android Nougat MR1 (SDK version >= 25;
1518 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1519 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001520 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001521 * @param user The user to retrieve the running state for.
1522 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001523 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001524 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -07001525 return isUserRunning(user.getIdentifier());
1526 }
1527
1528 /** {@hide} */
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001529 public boolean isUserRunning(@UserIdInt int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001530 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001531 return mService.isUserRunning(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001532 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001533 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001534 }
1535 }
1536
1537 /**
1538 * Return whether the given user is actively running <em>or</em> stopping.
1539 * This is like {@link #isUserRunning(UserHandle)}, but will also return
1540 * true if the user had been running but is in the process of being stopped
1541 * (but is not yet fully stopped, and still running some code).
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001542 *
1543 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1544 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1545 * in order to check other profile's status.
1546 * Since Android Nougat MR1 (SDK version >= 25;
1547 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1548 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001549 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001550 * @param user The user to retrieve the running state for.
1551 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001552 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001553 public boolean isUserRunningOrStopping(UserHandle user) {
1554 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001555 // TODO: reconcile stopped vs stopping?
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001556 return ActivityManager.getService().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001557 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001558 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001559 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001560 }
1561 }
1562
Jeff Sharkey0825ab22015-12-02 13:04:49 -07001563 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001564 * Return whether the calling user is running in an "unlocked" state.
1565 * <p>
1566 * On devices with direct boot, a user is unlocked only after they've
1567 * entered their credentials (such as a lock pattern or PIN). On devices
1568 * without direct boot, a user is unlocked as soon as it starts.
1569 * <p>
1570 * When a user is locked, only device-protected data storage is available.
1571 * When a user is unlocked, both device-protected and credential-protected
1572 * private app data storage is available.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001573 *
1574 * @see Intent#ACTION_USER_UNLOCKED
1575 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001576 */
1577 public boolean isUserUnlocked() {
1578 return isUserUnlocked(Process.myUserHandle());
1579 }
1580
1581 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001582 * Return whether the given user is running in an "unlocked" state.
1583 * <p>
1584 * On devices with direct boot, a user is unlocked only after they've
1585 * entered their credentials (such as a lock pattern or PIN). On devices
1586 * without direct boot, a user is unlocked as soon as it starts.
1587 * <p>
1588 * When a user is locked, only device-protected data storage is available.
1589 * When a user is unlocked, both device-protected and credential-protected
1590 * private app data storage is available.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001591 * <p>Requires {@code android.permission.MANAGE_USERS} or
1592 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1593 * must be the calling user or a managed profile associated with it.
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001594 *
1595 * @param user to retrieve the unlocked state for.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001596 * @see Intent#ACTION_USER_UNLOCKED
1597 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001598 */
1599 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -07001600 return isUserUnlocked(user.getIdentifier());
1601 }
1602
1603 /** {@hide} */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001604 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001605 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001606 return mService.isUserUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001607 } catch (RemoteException re) {
1608 throw re.rethrowFromSystemServer();
1609 }
1610 }
1611
1612 /** {@hide} */
1613 public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1614 return isUserUnlockingOrUnlocked(user.getIdentifier());
1615 }
1616
1617 /** {@hide} */
1618 public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1619 try {
Fyodor Kupolovc413f702016-10-06 17:11:14 -07001620 return mService.isUserUnlockingOrUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001621 } catch (RemoteException re) {
1622 throw re.rethrowFromSystemServer();
1623 }
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001624 }
1625
1626 /**
Makoto Onuki73dded22017-12-20 13:14:48 +09001627 * Return the time when the calling user started in elapsed milliseconds since boot,
1628 * or 0 if not started.
1629 *
1630 * @hide
1631 */
1632 public long getUserStartRealtime() {
1633 try {
1634 return mService.getUserStartRealtime();
1635 } catch (RemoteException re) {
1636 throw re.rethrowFromSystemServer();
1637 }
1638 }
1639
1640 /**
1641 * Return the time when the calling user was unlocked elapsed milliseconds since boot,
1642 * or 0 if not unlocked.
1643 *
1644 * @hide
1645 */
1646 public long getUserUnlockRealtime() {
1647 try {
1648 return mService.getUserUnlockRealtime();
1649 } catch (RemoteException re) {
1650 throw re.rethrowFromSystemServer();
1651 }
1652 }
1653
1654 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001655 * Returns the UserInfo object describing a specific user.
Tony Mak8673b282016-03-21 21:10:59 +00001656 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001657 * @param userHandle the user handle of the user whose information is being requested.
1658 * @return the UserInfo object for a specific user.
1659 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001660 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001661 public UserInfo getUserInfo(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001662 try {
1663 return mService.getUserInfo(userHandle);
1664 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001665 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001666 }
1667 }
1668
Amith Yamasani71e6c692013-03-24 17:39:28 -07001669 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001670 * @hide
1671 *
1672 * Returns who set a user restriction on a user.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001673 * @param restrictionKey the string key representing the restriction
1674 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1675 * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1676 * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1677 * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
Pavel Grafov6a40f092016-10-25 15:46:51 +01001678 * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001679 */
Pavel Grafov6a40f092016-10-25 15:46:51 +01001680 @Deprecated
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001681 @SystemApi
1682 @UserRestrictionSource
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001683 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001684 public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1685 try {
1686 return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1687 } catch (RemoteException re) {
1688 throw re.rethrowFromSystemServer();
1689 }
1690 }
1691
1692 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +01001693 * @hide
1694 *
1695 * Returns a list of users who set a user restriction on a given user.
Pavel Grafov6a40f092016-10-25 15:46:51 +01001696 * @param restrictionKey the string key representing the restriction
1697 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1698 * @return a list of user ids enforcing this restriction.
1699 */
1700 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001701 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Pavel Grafov6a40f092016-10-25 15:46:51 +01001702 public List<EnforcingUser> getUserRestrictionSources(
1703 String restrictionKey, UserHandle userHandle) {
1704 try {
1705 return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
1706 } catch (RemoteException re) {
1707 throw re.rethrowFromSystemServer();
1708 }
1709 }
1710
1711 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07001712 * Returns the user-wide restrictions imposed on this user.
1713 * @return a Bundle containing all the restrictions.
1714 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001715 public Bundle getUserRestrictions() {
1716 return getUserRestrictions(Process.myUserHandle());
1717 }
1718
Amith Yamasani71e6c692013-03-24 17:39:28 -07001719 /**
1720 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
1721 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1722 * @return a Bundle containing all the restrictions.
1723 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001724 public Bundle getUserRestrictions(UserHandle userHandle) {
1725 try {
1726 return mService.getUserRestrictions(userHandle.getIdentifier());
1727 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001728 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001729 }
1730 }
1731
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001732 /**
1733 * @hide
1734 * Returns whether the given user has been disallowed from performing certain actions
Irina Dumitrescu4638edd2018-09-05 14:08:33 +01001735 * or setting certain settings through UserManager (e.g. this type of restriction would prevent
1736 * the guest user from doing certain things, such as making calls). This method disregards
1737 * restrictions set by device policy.
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001738 * @param restrictionKey the string key representing the restriction
1739 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1740 */
1741 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
1742 try {
1743 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
1744 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001745 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001746 }
1747 }
1748
Amith Yamasani71e6c692013-03-24 17:39:28 -07001749 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001750 * This will no longer work. Device owners and profile owners should use
1751 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001752 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001753 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001754 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001755 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001756 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001757 }
1758
Amith Yamasani71e6c692013-03-24 17:39:28 -07001759 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001760 * This will no longer work. Device owners and profile owners should use
1761 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001762 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001763 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001764 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001765 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001766 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001767 }
1768
Amith Yamasani71e6c692013-03-24 17:39:28 -07001769 /**
1770 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07001771 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001772 * @param key the key of the restriction
1773 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001774 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1775 * android.content.ComponentName, String)} or
1776 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1777 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001778 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001779 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07001780 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001781 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07001782 }
1783
1784 /**
1785 * @hide
1786 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07001787 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001788 * @param key the key of the restriction
1789 * @param value the value for the restriction
1790 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001791 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1792 * android.content.ComponentName, String)} or
1793 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1794 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001795 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001796 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05001797 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001798 try {
1799 mService.setUserRestriction(key, value, userHandle.getIdentifier());
1800 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001802 }
Maggie Benthall67944582013-02-22 14:58:27 -05001803 }
1804
Amith Yamasani258848d2012-08-10 17:06:33 -07001805 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001806 * Returns whether the current user has been disallowed from performing certain actions
1807 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04001808 *
1809 * @param restrictionKey The string key representing the restriction.
1810 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001811 */
1812 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -07001813 return hasUserRestriction(restrictionKey, Process.myUserHandle());
1814 }
1815
1816 /**
1817 * @hide
1818 * Returns whether the given user has been disallowed from performing certain actions
1819 * or setting certain settings.
1820 * @param restrictionKey the string key representing the restriction
1821 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1822 */
1823 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001824 try {
1825 return mService.hasUserRestriction(restrictionKey,
1826 userHandle.getIdentifier());
1827 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001828 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001829 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001830 }
1831
1832 /**
Makoto Onukiacc50462018-02-14 14:13:49 -08001833 * @hide
1834 * Returns whether any user on the device has the given user restriction set.
1835 */
1836 public boolean hasUserRestrictionOnAnyUser(String restrictionKey) {
1837 try {
1838 return mService.hasUserRestrictionOnAnyUser(restrictionKey);
1839 } catch (RemoteException re) {
1840 throw re.rethrowFromSystemServer();
1841 }
1842 }
1843
1844 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001845 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001846 * number assigned to that user; if the user is deleted and then a new
1847 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001848 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001849 * @return The serial number of the given user; returns -1 if the
1850 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001851 * @see #getUserForSerialNumber(long)
1852 */
1853 public long getSerialNumberForUser(UserHandle user) {
1854 return getUserSerialNumber(user.getIdentifier());
1855 }
1856
1857 /**
1858 * Return the user associated with a serial number previously
1859 * returned by {@link #getSerialNumberForUser(UserHandle)}.
1860 * @param serialNumber The serial number of the user that is being
1861 * retrieved.
1862 * @return Return the user associated with the serial number, or null
1863 * if there is not one.
1864 * @see #getSerialNumberForUser(UserHandle)
1865 */
1866 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07001867 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001868 return ident >= 0 ? new UserHandle(ident) : null;
1869 }
1870
1871 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001872 * Creates a user with the specified name and options. For non-admin users, default user
1873 * restrictions are going to be applied.
Amith Yamasani195263742012-08-21 15:40:12 -07001874 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001875 *
1876 * @param name the user's name
1877 * @param flags flags that identify the type of user and other properties.
1878 * @see UserInfo
1879 *
1880 * @return the UserInfo object for the created user, or null if the user could not be created.
1881 * @hide
1882 */
1883 public UserInfo createUser(String name, int flags) {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001884 UserInfo user = null;
Amith Yamasani258848d2012-08-10 17:06:33 -07001885 try {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001886 user = mService.createUser(name, flags);
phweisse9c44062016-02-10 12:57:38 +01001887 // TODO: Keep this in sync with
1888 // UserManagerService.LocalService.createUserEvenWhenDisallowed
Christine Franks97a54802017-08-09 10:06:43 -07001889 if (user != null && !user.isAdmin() && !user.isDemo()) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001890 mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1891 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001892 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001893 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001894 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001895 }
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001896 return user;
Amith Yamasani258848d2012-08-10 17:06:33 -07001897 }
1898
1899 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001900 * Creates a guest user and configures it.
1901 * @param context an application context
1902 * @param name the name to set for the user
1903 * @hide
1904 */
1905 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001906 UserInfo guest = null;
1907 try {
1908 guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1909 if (guest != null) {
1910 Settings.Secure.putStringForUser(context.getContentResolver(),
1911 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001912 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07001913 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001914 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001915 }
1916 return guest;
1917 }
1918
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07001919 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001920 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001921 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1922 *
1923 * @param name the user's name
1924 * @param flags flags that identify the type of user and other properties.
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001925 * @param userHandle new user will be a profile of this user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001926 *
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001927 * @return the {@link UserInfo} object for the created user, or null if the user
1928 * could not be created.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001929 * @hide
1930 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001931 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001932 return createProfileForUser(name, flags, userHandle, null);
1933 }
1934
1935 /**
1936 * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
1937 * any packages that should not be installed in the new profile by default, these packages can
1938 * still be installed later by the user if needed.
1939 *
1940 * @param name the user's name
1941 * @param flags flags that identify the type of user and other properties.
1942 * @param userHandle new user will be a profile of this user.
1943 * @param disallowedPackages packages that will not be installed in the profile being created.
1944 *
1945 * @return the {@link UserInfo} object for the created user, or null if the user
1946 * could not be created.
1947 * @hide
1948 */
1949 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
1950 String[] disallowedPackages) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001951 try {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001952 return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001953 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001954 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001955 }
1956 }
1957
1958 /**
Tony Mak6dc428f2016-10-10 15:48:27 +01001959 * Similar to {@link #createProfileForUser(String, int, int, String[])}
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001960 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
Tony Mak6dc428f2016-10-10 15:48:27 +01001961 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1962 *
1963 * @see #createProfileForUser(String, int, int, String[])
1964 * @hide
1965 */
1966 public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
1967 @UserIdInt int userHandle, String[] disallowedPackages) {
1968 try {
1969 return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
1970 disallowedPackages);
1971 } catch (RemoteException re) {
1972 throw re.rethrowFromSystemServer();
1973 }
1974 }
1975
1976 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001977 * Creates a restricted profile with the specified name. This method also sets necessary
1978 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001979 *
1980 * @param name profile's name
1981 * @return UserInfo object for the created user, or null if the user could not be created.
1982 * @hide
1983 */
1984 public UserInfo createRestrictedProfile(String name) {
1985 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001986 UserHandle parentUserHandle = Process.myUserHandle();
1987 UserInfo user = mService.createRestrictedProfile(name,
1988 parentUserHandle.getIdentifier());
1989 if (user != null) {
1990 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
1991 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001992 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001993 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001994 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001995 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001996 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001997 }
1998
1999 /**
Amith Yamasani06964342016-04-15 13:55:01 -07002000 * Returns an intent to create a user for the provided name and account name. The name
2001 * and account name will be used when the setup process for the new user is started.
2002 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08002003 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08002004 * indicate if the user consented to adding a new user and if the operation succeeded. Any
2005 * errors in creating the user will be returned in the result code. If the user cancels the
2006 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
2007 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani06964342016-04-15 13:55:01 -07002008 * <p>
2009 * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
2010 * at all.
2011 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08002012 * The new user is created but not initialized. After switching into the user for the first
2013 * time, the preferred user name and account information are used by the setup process for that
2014 * user.
2015 *
2016 * @param userName Optional name to assign to the user.
Amith Yamasani06964342016-04-15 13:55:01 -07002017 * @param accountName Optional account name that will be used by the setup wizard to initialize
Amith Yamasani12747872015-12-07 14:19:49 -08002018 * the user.
2019 * @param accountType Optional account type for the account to be created. This is required
2020 * if the account name is specified.
2021 * @param accountOptions Optional bundle of data to be passed in during account creation in the
2022 * new user via {@link AccountManager#addAccount(String, String, String[],
2023 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
2024 * Handler)}.
Amith Yamasani06964342016-04-15 13:55:01 -07002025 * @return An Intent that can be launched from an Activity.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08002026 * @see #USER_CREATION_FAILED_NOT_PERMITTED
2027 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani06964342016-04-15 13:55:01 -07002028 * @see #supportsMultipleUsers
Amith Yamasani12747872015-12-07 14:19:49 -08002029 */
2030 public static Intent createUserCreationIntent(@Nullable String userName,
2031 @Nullable String accountName,
2032 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
Amith Yamasani12747872015-12-07 14:19:49 -08002033 Intent intent = new Intent(ACTION_CREATE_USER);
2034 if (userName != null) {
2035 intent.putExtra(EXTRA_USER_NAME, userName);
2036 }
2037 if (accountName != null && accountType == null) {
2038 throw new IllegalArgumentException("accountType must be specified if accountName is "
2039 + "specified");
2040 }
2041 if (accountName != null) {
2042 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
2043 }
2044 if (accountType != null) {
2045 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
2046 }
2047 if (accountOptions != null) {
2048 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
2049 }
2050 return intent;
2051 }
2052
2053 /**
2054 * @hide
2055 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002056 * Returns the preferred account name for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002057 */
2058 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002059 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002060 public String getSeedAccountName() {
2061 try {
2062 return mService.getSeedAccountName();
2063 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002064 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002065 }
2066 }
2067
2068 /**
2069 * @hide
2070 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002071 * Returns the preferred account type for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002072 */
2073 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002074 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002075 public String getSeedAccountType() {
2076 try {
2077 return mService.getSeedAccountType();
2078 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002079 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002080 }
2081 }
2082
2083 /**
2084 * @hide
2085 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002086 * Returns the preferred account's options bundle for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002087 * @return Any options set by the requestor that created the user.
2088 */
2089 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002090 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002091 public PersistableBundle getSeedAccountOptions() {
2092 try {
2093 return mService.getSeedAccountOptions();
2094 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002095 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002096 }
2097 }
2098
2099 /**
2100 * @hide
2101 *
2102 * Called by a system activity to set the seed account information of a user created
2103 * through the user creation intent.
2104 * @param userId
2105 * @param accountName
2106 * @param accountType
2107 * @param accountOptions
2108 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
2109 */
2110 public void setSeedAccountData(int userId, String accountName, String accountType,
2111 PersistableBundle accountOptions) {
2112 try {
2113 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
2114 /* persist= */ true);
2115 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002116 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002117 }
2118 }
2119
2120 /**
2121 * @hide
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002122 * Clears the seed information used to create this user.
Amith Yamasani12747872015-12-07 14:19:49 -08002123 */
2124 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002125 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002126 public void clearSeedAccountData() {
2127 try {
2128 mService.clearSeedAccountData();
2129 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002130 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002131 }
2132 }
2133
2134 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07002135 * @hide
2136 * Marks the guest user for deletion to allow a new guest to be created before deleting
2137 * the current user who is a guest.
2138 * @param userHandle
2139 * @return
2140 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002141 public boolean markGuestForDeletion(@UserIdInt int userHandle) {
Amith Yamasani1df14732014-08-29 21:37:27 -07002142 try {
2143 return mService.markGuestForDeletion(userHandle);
2144 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002145 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07002146 }
2147 }
2148
2149 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002150 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01002151 *
2152 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2153 *
2154 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
2155 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
2156 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002157 *
jovanakf24ad492018-05-18 12:15:59 -07002158 * @param userId the id of the profile to enable
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002159 * @hide
2160 */
jovanakf24ad492018-05-18 12:15:59 -07002161 public void setUserEnabled(@UserIdInt int userId) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002162 try {
jovanakf24ad492018-05-18 12:15:59 -07002163 mService.setUserEnabled(userId);
2164 } catch (RemoteException re) {
2165 throw re.rethrowFromSystemServer();
2166 }
2167 }
2168
2169 /**
2170 * Assigns admin privileges to the user, if such a user exists.
2171 *
2172 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} and
2173 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions.
2174 *
2175 * @param userHandle the id of the user to become admin
2176 * @hide
2177 */
2178 @RequiresPermission(allOf = {
2179 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2180 Manifest.permission.MANAGE_USERS
2181 })
2182 public void setUserAdmin(@UserIdInt int userHandle) {
2183 try {
2184 mService.setUserAdmin(userHandle);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002185 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002186 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002187 }
2188 }
2189
2190 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002191 * Evicts the user's credential encryption key from memory by stopping and restarting the user.
2192 *
2193 * @hide
2194 */
2195 public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
2196 try {
2197 mService.evictCredentialEncryptionKey(userHandle);
2198 } catch (RemoteException re) {
2199 throw re.rethrowFromSystemServer();
2200 }
2201 }
2202
2203 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002204 * Return the number of users currently created on the device.
2205 */
2206 public int getUserCount() {
2207 List<UserInfo> users = getUsers();
2208 return users != null ? users.size() : 1;
2209 }
2210
2211 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07002212 * Returns information for all users on this device, including ones marked for deletion.
2213 * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
2214 * <p>
Amith Yamasani195263742012-08-21 15:40:12 -07002215 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002216 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07002217 * @hide
2218 */
2219 public List<UserInfo> getUsers() {
2220 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07002221 return mService.getUsers(false);
2222 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002223 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07002224 }
2225 }
2226
2227 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002228 * Returns serial numbers of all users on this device.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002229 *
2230 * @param excludeDying specify if the list should exclude users being removed.
2231 * @return the list of serial numbers of users that exist on the device.
2232 * @hide
2233 */
2234 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002235 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002236 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
2237 try {
2238 List<UserInfo> users = mService.getUsers(excludeDying);
2239 long[] result = new long[users.size()];
2240 for (int i = 0; i < result.length; i++) {
2241 result[i] = users.get(i).serialNumber;
2242 }
2243 return result;
2244 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002245 throw re.rethrowFromSystemServer();
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002246 }
2247 }
2248
2249 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002250 * @return the user's account name, null if not found.
2251 * @hide
2252 */
2253 @RequiresPermission( allOf = {
2254 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2255 Manifest.permission.MANAGE_USERS
2256 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002257 public @Nullable String getUserAccount(@UserIdInt int userHandle) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002258 try {
2259 return mService.getUserAccount(userHandle);
2260 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002261 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002262 }
2263 }
2264
2265 /**
2266 * Set account name for the given user.
2267 * @hide
2268 */
2269 @RequiresPermission( allOf = {
2270 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2271 Manifest.permission.MANAGE_USERS
2272 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002273 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002274 try {
2275 mService.setUserAccount(userHandle, accountName);
2276 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002277 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002278 }
2279 }
2280
2281 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002282 * Returns information for Primary user.
2283 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2284 *
2285 * @return the Primary user, null if not found.
2286 * @hide
2287 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002288 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002289 try {
2290 return mService.getPrimaryUser();
2291 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002292 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002293 }
2294 }
2295
2296 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07002297 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
2298 * permission.
2299 *
2300 * @return true if more users can be added, false if limit has been reached.
2301 * @hide
2302 */
2303 public boolean canAddMoreUsers() {
2304 final List<UserInfo> users = getUsers(true);
2305 final int totalUserCount = users.size();
2306 int aliveUserCount = 0;
2307 for (int i = 0; i < totalUserCount; i++) {
2308 UserInfo user = users.get(i);
2309 if (!user.isGuest()) {
2310 aliveUserCount++;
2311 }
2312 }
2313 return aliveUserCount < getMaxSupportedUsers();
2314 }
2315
2316 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07002317 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
2318 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002319 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
2320 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07002321 *
2322 * @return true if more managed profiles can be added, false if limit has been reached.
2323 * @hide
2324 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002325 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07002326 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002327 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07002328 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002329 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07002330 }
2331 }
2332
2333 /**
Kenny Guy2a764942014-04-02 13:29:20 +01002334 * Returns list of the profiles of userHandle including
2335 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07002336 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07002337 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08002338 *
Kenny Guy2a764942014-04-02 13:29:20 +01002339 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2340 * @param userHandle profiles of this user will be returned.
2341 * @return the list of profiles.
2342 * @hide
2343 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002344 public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00002345 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002346 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00002347 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002348 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00002349 }
2350 }
2351
2352 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002353 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2354 * @param userId one of the two user ids to check.
2355 * @param otherUserId one of the two user ids to check.
2356 * @return true if the two user ids are in the same profile group.
2357 * @hide
2358 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002359 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002360 try {
2361 return mService.isSameProfileGroup(userId, otherUserId);
2362 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002363 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002364 }
2365 }
2366
2367 /**
Ruben Brunk7f75da22015-04-30 17:46:30 -07002368 * Returns list of the profiles of userHandle including
2369 * userHandle itself.
2370 * Note that this returns only enabled.
2371 *
2372 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2373 * @param userHandle profiles of this user will be returned.
2374 * @return the list of profiles.
2375 * @hide
2376 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002377 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07002378 try {
2379 return mService.getProfiles(userHandle, true /* enabledOnly */);
2380 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002381 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07002382 }
2383 }
2384
2385 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002386 * Returns a list of UserHandles for profiles associated with the user that the calling process
2387 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08002388 *
2389 * @return A non-empty list of UserHandles associated with the calling user.
2390 */
2391 public List<UserHandle> getUserProfiles() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002392 int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
2393 List<UserHandle> result = new ArrayList<>(userIds.length);
2394 for (int userId : userIds) {
2395 result.add(UserHandle.of(userId));
2396 }
2397 return result;
2398 }
2399
2400 /**
2401 * Returns a list of ids for profiles associated with the specified user including the user
2402 * itself.
2403 *
2404 * @param userId id of the user to return profiles for
2405 * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
2406 * @return A non-empty list of ids of profiles associated with the specified user.
2407 *
2408 * @hide
2409 */
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07002410 @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS,
2411 Manifest.permission.CREATE_USERS}, conditional = true)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07002412 public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002413 try {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002414 return mService.getProfileIds(userId, enabledOnly);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002415 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002416 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002417 }
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002418 }
2419
2420 /**
2421 * @see #getProfileIds(int, boolean)
2422 * @hide
2423 */
2424 public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
2425 return getProfileIds(userId, false /* enabledOnly */);
2426 }
2427
2428 /**
2429 * @see #getProfileIds(int, boolean)
2430 * @hide
2431 */
2432 public int[] getEnabledProfileIds(@UserIdInt int userId) {
2433 return getProfileIds(userId, true /* enabledOnly */);
Amith Yamasani4f582632014-02-19 14:31:52 -08002434 }
2435
Amith Yamasani7dda2652014-04-11 14:57:12 -07002436 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07002437 * Returns the device credential owner id of the profile from
2438 * which this method is called, or userHandle if called from a user that
2439 * is not a profile.
2440 *
2441 * @hide
2442 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002443 public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
Andres Moralesc5548c02015-08-05 10:23:12 -07002444 try {
2445 return mService.getCredentialOwnerProfile(userHandle);
2446 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002447 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07002448 }
2449 }
2450
2451 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002452 * Returns the parent of the profile which this method is called from
2453 * or null if called from a user that is not a profile.
2454 *
2455 * @hide
2456 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002457 public UserInfo getProfileParent(@UserIdInt int userHandle) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01002458 try {
2459 return mService.getProfileParent(userHandle);
2460 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002461 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01002462 }
2463 }
2464
2465 /**
Philip P. Moltmanna3e358c2018-11-21 12:45:50 -08002466 * Get the parent of a user profile.
2467 *
2468 * @param user the handle of the user profile
2469 *
2470 * @return the parent of the user or {@code null} if the user is not profile
2471 *
2472 * @hide
2473 */
2474 @SystemApi
2475 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
2476 public @Nullable UserHandle getProfileParent(@NonNull UserHandle user) {
2477 UserInfo info = getProfileParent(user.getIdentifier());
2478
2479 if (info == null) {
2480 return null;
2481 }
2482
2483 return UserHandle.of(info.id);
2484 }
2485
2486 /**
Tony Make3d1f652017-12-12 11:00:37 +00002487 * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a
2488 * managed profile don't run, generate notifications, or consume data or battery.
2489 * <p>
2490 * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be
2491 * shown to the user.
2492 * <p>
2493 * The change may not happen instantly, however apps can listen for
2494 * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and
2495 * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of
2496 * the change of the quiet mode. Apps can also check the current state of quiet mode by
2497 * calling {@link #isQuietModeEnabled(UserHandle)}.
2498 * <p>
2499 * The caller must either be the foreground default launcher or have one of these permissions:
2500 * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002501 *
Tony Make3d1f652017-12-12 11:00:37 +00002502 * @param enableQuietMode whether quiet mode should be enabled or disabled
2503 * @param userHandle user handle of the profile
2504 * @return {@code false} if user's credential is needed in order to turn off quiet mode,
2505 * {@code true} otherwise
2506 * @throws SecurityException if the caller is invalid
2507 * @throws IllegalArgumentException if {@code userHandle} is not a managed profile
2508 *
2509 * @see #isQuietModeEnabled(UserHandle)
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002510 */
Tony Makbece85d2018-01-12 12:10:17 +00002511 public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) {
2512 return requestQuietModeEnabled(enableQuietMode, userHandle, null);
Tony Makb7e6fd42017-12-05 19:40:28 +00002513 }
2514
2515 /**
Tony Makbece85d2018-01-12 12:10:17 +00002516 * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify
Tony Makd390ae92017-12-28 13:23:10 +00002517 * a target to start when user is unlocked. If {@code target} is specified, caller must have
2518 * the {@link android.Manifest.permission#MANAGE_USERS} permission.
Tony Makb7e6fd42017-12-05 19:40:28 +00002519 *
Tony Makbece85d2018-01-12 12:10:17 +00002520 * @see {@link #requestQuietModeEnabled(boolean, UserHandle)}
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002521 * @hide
2522 */
Tony Makbece85d2018-01-12 12:10:17 +00002523 public boolean requestQuietModeEnabled(
Tony Makb7e6fd42017-12-05 19:40:28 +00002524 boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002525 try {
Tony Makbece85d2018-01-12 12:10:17 +00002526 return mService.requestQuietModeEnabled(
Tony Make3d1f652017-12-12 11:00:37 +00002527 mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002528 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002529 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002530 }
2531 }
2532
2533 /**
2534 * Returns whether the given profile is in quiet mode or not.
Ricky Wai7881cf82016-04-15 17:20:12 +01002535 * Notes: Quiet mode is only supported for managed profiles.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002536 *
2537 * @param userHandle The user handle of the profile to be queried.
2538 * @return true if the profile is in quiet mode, false otherwise.
2539 */
2540 public boolean isQuietModeEnabled(UserHandle userHandle) {
2541 try {
2542 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002543 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002544 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002545 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002546 }
2547
2548 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -07002549 * If the target user is a managed profile of the calling user or the caller
2550 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07002551 * icon to be able to distinguish it from the original icon. For badging an
2552 * arbitrary drawable use {@link #getBadgedDrawableForUser(
2553 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2554 * <p>
2555 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002556 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002557 * is performed in place and the original drawable is returned.
2558 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07002559 *
2560 * @param icon The icon to badge.
2561 * @param user The target user.
2562 * @return A drawable that combines the original icon and a badge as
2563 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002564 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07002565 */
Svetoslavc71c42f2014-08-05 18:57:05 -07002566 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002567 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002568 }
2569
Kenny Guy701ea7c2014-05-08 23:34:12 +01002570 /**
2571 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -07002572 * is itself a managed profile, then this returns a badged copy of the given
2573 * drawable allowing the user to distinguish it from the original drawable.
2574 * The caller can specify the location in the bounds of the drawable to be
2575 * badged where the badge should be applied as well as the density of the
2576 * badge to be used.
2577 * <p>
2578 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002579 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002580 * is performed in place and the original drawable is returned.
2581 * </p>
2582 *
2583 * @param badgedDrawable The drawable to badge.
2584 * @param user The target user.
2585 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002586 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07002587 * drawable being badged.
2588 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002589 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07002590 * the density of the display is used.
2591 * @return A drawable that combines the original drawable and a badge as
2592 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002593 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07002594 */
2595 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2596 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002597 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2598 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07002599 }
2600
2601 /**
2602 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002603 * is itself a managed profile, then this returns a copy of the label with
2604 * badging for accessibility services like talkback. E.g. passing in "Email"
2605 * and it might return "Work Email" for Email in the work profile.
2606 *
2607 * @param label The label to change.
2608 * @param user The target user.
2609 * @return A label that combines the original label and a badge as
2610 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002611 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002612 */
Kenny Guy237aecd2014-07-21 14:06:09 +01002613 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002614 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002615 }
2616
2617 /**
2618 * Returns information for all users on this device. Requires
2619 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04002620 *
Amith Yamasani4f582632014-02-19 14:31:52 -08002621 * @param excludeDying specify if the list should exclude users being
2622 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07002623 * @return the list of users that were created.
2624 * @hide
2625 */
Adam Lesinskiada8deb2017-05-12 13:50:42 -07002626 public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
Amith Yamasani920ace02012-09-20 22:15:37 -07002627 try {
2628 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07002629 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002630 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002631 }
2632 }
2633
2634 /**
2635 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07002636 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002637 * @param userHandle the integer handle of the user, where 0 is the primary user.
2638 * @hide
2639 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002640 public boolean removeUser(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002641 try {
2642 return mService.removeUser(userHandle);
2643 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002644 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002645 }
2646 }
2647
2648 /**
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00002649 * Similar to {@link #removeUser(int)} except bypassing the checking of
2650 * {@link UserManager#DISALLOW_REMOVE_USER}
2651 * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2652 *
2653 * @see {@link #removeUser(int)}
2654 * @hide
2655 */
2656 public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2657 try {
2658 return mService.removeUserEvenWhenDisallowed(userHandle);
2659 } catch (RemoteException re) {
2660 throw re.rethrowFromSystemServer();
2661 }
2662 }
2663
2664 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002665 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07002666 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002667 *
2668 * @param userHandle the user's integer handle
2669 * @param name the new name for the user
2670 * @hide
2671 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002672 public void setUserName(@UserIdInt int userHandle, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002673 try {
2674 mService.setUserName(userHandle, name);
2675 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002676 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002677 }
2678 }
2679
2680 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002681 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002682 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002683 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002684 * @hide
2685 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002686 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002687 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002688 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07002689 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002690 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002691 }
2692 }
2693
2694 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07002695 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
2696 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002697 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002698 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07002699 * @hide
2700 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002701 public Bitmap getUserIcon(@UserIdInt int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07002702 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01002703 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
2704 if (fd != null) {
2705 try {
2706 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
2707 } finally {
2708 try {
2709 fd.close();
2710 } catch (IOException e) {
2711 }
2712 }
2713 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07002714 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002715 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07002716 }
Adrian Roos1bdff912015-02-17 15:51:35 +01002717 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07002718 }
2719
2720 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002721 * Returns the maximum number of users that can be created on this device. A return value
2722 * of 1 means that it is a single user device.
2723 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002724 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07002725 */
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002726 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07002727 // Don't allow multiple users on certain builds
2728 if (android.os.Build.ID.startsWith("JVP")) return 1;
Robin Lee83c79312018-02-09 19:27:18 +01002729 if (ActivityManager.isLowRamDeviceStatic()) {
2730 // Low-ram devices are Svelte. Most of the time they don't get multi-user.
2731 if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
2732 != Configuration.UI_MODE_TYPE_TELEVISION) {
2733 return 1;
2734 }
2735 }
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002736 return SystemProperties.getInt("fw.max_users",
2737 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07002738 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002739
2740 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002741 * Returns true if the user switcher should be shown, this will be if device supports multi-user
2742 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00002743 * @hide
2744 * @return true if user switcher should be shown.
2745 */
2746 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002747 if (!supportsMultipleUsers()) {
2748 return false;
2749 }
Benjamin Franzff66fa92017-08-10 10:39:44 +01002750 if (hasUserRestriction(DISALLOW_USER_SWITCH)) {
2751 return false;
2752 }
Amith Yamasanieb437d42016-04-29 09:31:25 -07002753 // If Demo Mode is on, don't show user switcher
2754 if (isDeviceInDemoMode(mContext)) {
2755 return false;
2756 }
Fan Zhangc69c8b62018-06-05 13:30:11 -07002757 // If user disabled this feature, don't show switcher
2758 final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(),
2759 Settings.Global.USER_SWITCHER_ENABLED, 1) != 0;
2760 if (!userSwitcherEnabled) {
2761 return false;
2762 }
Kenny Guy1a447532014-02-20 21:55:32 +00002763 List<UserInfo> users = getUsers(true);
2764 if (users == null) {
2765 return false;
2766 }
2767 int switchableUserCount = 0;
2768 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002769 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00002770 ++switchableUserCount;
2771 }
2772 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002773 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2774 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07002775 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00002776 }
2777
2778 /**
Amith Yamasanieb437d42016-04-29 09:31:25 -07002779 * @hide
2780 */
2781 public static boolean isDeviceInDemoMode(Context context) {
2782 return Settings.Global.getInt(context.getContentResolver(),
2783 Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2784 }
2785
2786 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07002787 * Returns a serial number on this device for a given userHandle. User handles can be recycled
2788 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
2789 * @param userHandle
2790 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
2791 * @hide
2792 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002793 public int getUserSerialNumber(@UserIdInt int userHandle) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002794 try {
2795 return mService.getUserSerialNumber(userHandle);
2796 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002797 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002798 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002799 }
2800
2801 /**
2802 * Returns a userHandle on this device for a given user serial number. User handles can be
2803 * recycled when deleting and creating users, but serial numbers are not reused until the device
2804 * is wiped.
2805 * @param userSerialNumber
2806 * @return the userHandle associated with that user serial number, or -1 if the serial number
2807 * is not valid.
2808 * @hide
2809 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002810 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002811 try {
2812 return mService.getUserHandle(userSerialNumber);
2813 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002814 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002815 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002816 }
Maggie Benthall67944582013-02-22 14:58:27 -05002817
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002818 /**
Esteban Talavera953fe482016-06-07 15:25:20 +01002819 * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002820 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002821 *
2822 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
2823 * where the types of values may be:
2824 * <ul>
2825 * <li>{@code boolean}
2826 * <li>{@code int}
2827 * <li>{@code String} or {@code String[]}
2828 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
2829 * </ul>
2830 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002831 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
2832 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002833 * @param packageName the package name of the calling application
Esteban Talavera953fe482016-06-07 15:25:20 +01002834 * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2835 * if there are no saved restrictions.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002836 *
2837 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002838 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002839 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002840 public Bundle getApplicationRestrictions(String packageName) {
2841 try {
2842 return mService.getApplicationRestrictions(packageName);
2843 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002844 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002845 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002846 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002847
2848 /**
2849 * @hide
2850 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002851 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002852 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002853 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002854 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002855 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002856 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002857 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002858 }
2859
2860 /**
2861 * @hide
2862 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002863 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002864 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002865 UserHandle user) {
2866 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002867 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002868 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002869 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002870 }
2871 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002872
2873 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07002874 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2875 * apps and requires the MANAGE_USERS permission.
2876 * @param newPin the PIN to use for challenge dialogs.
2877 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07002878 * @deprecated The restrictions PIN functionality is no longer provided by the system.
2879 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07002880 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07002881 @Deprecated
Amith Yamasanid304af62013-09-05 09:30:23 -07002882 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002883 return false;
2884 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07002885
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302886 /**
2887 * @hide
2888 * Set restrictions that should apply to any future guest user that's created.
2889 */
2890 public void setDefaultGuestRestrictions(Bundle restrictions) {
2891 try {
2892 mService.setDefaultGuestRestrictions(restrictions);
2893 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002894 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302895 }
2896 }
2897
2898 /**
2899 * @hide
2900 * Gets the default guest restrictions.
2901 */
2902 public Bundle getDefaultGuestRestrictions() {
2903 try {
2904 return mService.getDefaultGuestRestrictions();
2905 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002906 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302907 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302908 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002909
2910 /**
2911 * Returns creation time of the user or of a managed profile associated with the calling user.
2912 * @param userHandle user handle of the user or a managed profile associated with the
2913 * calling user.
2914 * @return creation time in milliseconds since Epoch time.
2915 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07002916 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002917 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07002918 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002919 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002920 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002921 }
2922 }
Amith Yamasani12747872015-12-07 14:19:49 -08002923
2924 /**
2925 * @hide
2926 * Checks if any uninitialized user has the specific seed account name and type.
2927 *
Pavel Grafov6a40f092016-10-25 15:46:51 +01002928 * @param accountName The account name to check for
2929 * @param accountType The account type of the account to check for
Amith Yamasani12747872015-12-07 14:19:49 -08002930 * @return whether the seed account was found
2931 */
2932 public boolean someUserHasSeedAccount(String accountName, String accountType) {
2933 try {
2934 return mService.someUserHasSeedAccount(accountName, accountType);
2935 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002936 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002937 }
2938 }
Pavel Grafov6a40f092016-10-25 15:46:51 +01002939
2940 /**
2941 * @hide
2942 * User that enforces a restriction.
2943 *
2944 * @see #getUserRestrictionSources(String, UserHandle)
2945 */
2946 @SystemApi
2947 public static final class EnforcingUser implements Parcelable {
2948 private final @UserIdInt int userId;
2949 private final @UserRestrictionSource int userRestrictionSource;
2950
2951 /**
2952 * @hide
2953 */
2954 public EnforcingUser(
2955 @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
2956 this.userId = userId;
2957 this.userRestrictionSource = userRestrictionSource;
2958 }
2959
2960 private EnforcingUser(Parcel in) {
2961 userId = in.readInt();
2962 userRestrictionSource = in.readInt();
2963 }
2964
2965 public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
2966 @Override
2967 public EnforcingUser createFromParcel(Parcel in) {
2968 return new EnforcingUser(in);
2969 }
2970
2971 @Override
2972 public EnforcingUser[] newArray(int size) {
2973 return new EnforcingUser[size];
2974 }
2975 };
2976
2977 @Override
2978 public int describeContents() {
2979 return 0;
2980 }
2981
2982 @Override
2983 public void writeToParcel(Parcel dest, int flags) {
2984 dest.writeInt(userId);
2985 dest.writeInt(userRestrictionSource);
2986 }
2987
2988 /**
2989 * Returns an id of the enforcing user.
2990 *
2991 * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
2992 */
2993 public UserHandle getUserHandle() {
2994 return UserHandle.of(userId);
2995 }
2996
2997 /**
2998 * Returns the status of the enforcing user.
2999 *
3000 * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
3001 * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
3002 * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
3003 */
3004 public @UserRestrictionSource int getUserRestrictionSource() {
3005 return userRestrictionSource;
3006 }
3007 }
Amith Yamasani258848d2012-08-10 17:06:33 -07003008}