blob: fa9569bbe0efee2e6682954cfa8b524d3112919e [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;
Bookatz029832a2019-10-04 16:50:22 -070021import android.annotation.ColorInt;
22import android.annotation.DrawableRes;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010023import android.annotation.IntDef;
Adam Lesinskiada8deb2017-05-12 13:50:42 -070024import android.annotation.NonNull;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -070025import android.annotation.Nullable;
Xiaohui Chenb3b92582015-12-07 11:22:13 -080026import android.annotation.RequiresPermission;
Roshan Pius3eac0b92019-12-05 09:35:36 -080027import android.annotation.StringDef;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070028import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060029import android.annotation.SystemService;
Makoto Onukie72f81b2017-03-16 14:08:19 -070030import android.annotation.TestApi;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070031import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070032import android.annotation.WorkerThread;
Amith Yamasani37ed8d12016-01-27 14:40:16 -080033import android.app.Activity;
Dianne Hackborn409297d2014-07-10 17:39:20 -070034import android.app.ActivityManager;
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -070035import android.app.admin.DevicePolicyManager;
Artur Satayevafdb23a2019-12-10 17:47:53 +000036import android.compat.annotation.UnsupportedAppUsage;
Makoto Onuki068c54a2015-10-13 14:34:03 -070037import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070038import android.content.Context;
Amith Yamasani12747872015-12-07 14:19:49 -080039import android.content.Intent;
Esteban Talavera8bd7c522017-02-13 12:35:04 +000040import android.content.IntentFilter;
Benjamin Franzf02420c2016-04-04 18:52:21 +010041import android.content.IntentSender;
Amith Yamasani258848d2012-08-10 17:06:33 -070042import android.content.pm.UserInfo;
Felipe Lemec1ca4412019-09-11 09:23:26 -070043import android.content.pm.UserInfo.UserInfoFlag;
Robin Lee83c79312018-02-09 19:27:18 +010044import android.content.res.Configuration;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070045import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050046import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010047import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080048import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080049import android.graphics.drawable.Drawable;
Soonil Nagarkardc08e3a2019-12-02 12:31:45 -080050import android.location.LocationManager;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070051import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080052import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040053import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070054
Maggie Benthall67944582013-02-22 14:58:27 -050055import com.android.internal.R;
John Reckaa67f682016-09-20 14:24:21 -070056import com.android.internal.os.RoSystemProperties;
Maggie Benthall67944582013-02-22 14:58:27 -050057
Adrian Roos1bdff912015-02-17 15:51:35 +010058import java.io.IOException;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010059import java.lang.annotation.Retention;
60import java.lang.annotation.RetentionPolicy;
Amith Yamasani4f582632014-02-19 14:31:52 -080061import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070062import java.util.List;
63
64/**
Amith Yamasani06964342016-04-15 13:55:01 -070065 * Manages users and user details on a multi-user system. There are two major categories of
66 * users: fully customizable users with their own login, and managed profiles that share a workspace
67 * with a related user.
68 * <p>
69 * Users are different from accounts, which are managed by
70 * {@link AccountManager}. Each user can have their own set of accounts.
71 * <p>
72 * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
Amith Yamasani258848d2012-08-10 17:06:33 -070073 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060074@SystemService(Context.USER_SERVICE)
Amith Yamasani258848d2012-08-10 17:06:33 -070075public class UserManager {
76
Pavel Grafov4f4f6f82017-03-28 13:44:04 +010077 private static final String TAG = "UserManager";
Andrei Onea24ec3212019-03-15 17:35:05 +000078 @UnsupportedAppUsage
Amith Yamasani258848d2012-08-10 17:06:33 -070079 private final IUserManager mService;
80 private final Context mContext;
81
Makoto Onukid49f3fa2017-01-25 14:09:48 -080082 private Boolean mIsManagedProfileCached;
Bookatz029832a2019-10-04 16:50:22 -070083 private Boolean mIsProfileCached;
84
85 /**
86 * User type representing a {@link UserHandle#USER_SYSTEM system} user that is a human user.
87 * This type of user cannot be created; it can only pre-exist on first boot.
88 * @hide
89 */
90 public static final String USER_TYPE_FULL_SYSTEM = "android.os.usertype.full.SYSTEM";
91
92 /**
93 * User type representing a regular non-profile non-{@link UserHandle#USER_SYSTEM system} human
94 * user.
95 * This is sometimes called an ordinary 'secondary user'.
96 * @hide
97 */
98 public static final String USER_TYPE_FULL_SECONDARY = "android.os.usertype.full.SECONDARY";
99
100 /**
101 * User type representing a guest user that may be transient.
102 * @hide
103 */
104 public static final String USER_TYPE_FULL_GUEST = "android.os.usertype.full.GUEST";
105
106 /**
107 * User type representing a user for demo purposes only, which can be removed at any time.
108 * @hide
109 */
110 public static final String USER_TYPE_FULL_DEMO = "android.os.usertype.full.DEMO";
111
112 /**
113 * User type representing a "restricted profile" user, which is a full user that is subject to
114 * certain restrictions from a parent user. Note, however, that it is NOT technically a profile.
115 * @hide
116 */
117 public static final String USER_TYPE_FULL_RESTRICTED = "android.os.usertype.full.RESTRICTED";
118
119 /**
120 * User type representing a managed profile, which is a profile that is to be managed by a
121 * device policy controller (DPC).
122 * The intended purpose is for work profiles, which are managed by a corporate entity.
123 * @hide
124 */
125 public static final String USER_TYPE_PROFILE_MANAGED = "android.os.usertype.profile.MANAGED";
126
127 /**
128 * User type representing a {@link UserHandle#USER_SYSTEM system} user that is <b>not</b> a
129 * human user.
130 * This type of user cannot be created; it can only pre-exist on first boot.
131 * @hide
132 */
133 public static final String USER_TYPE_SYSTEM_HEADLESS = "android.os.usertype.system.HEADLESS";
Makoto Onukid49f3fa2017-01-25 14:09:48 -0800134
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800135 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +0100136 * @hide
137 * No user restriction.
138 */
139 @SystemApi
140 public static final int RESTRICTION_NOT_SET = 0x0;
141
142 /**
143 * @hide
144 * User restriction set by system/user.
145 */
146 @SystemApi
147 public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
148
149 /**
150 * @hide
151 * User restriction set by a device owner.
152 */
153 @SystemApi
154 public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
155
156 /**
157 * @hide
158 * User restriction set by a profile owner.
159 */
160 @SystemApi
161 public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
162
163 /** @hide */
164 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700165 @IntDef(flag = true, prefix = { "RESTRICTION_" }, value = {
166 RESTRICTION_NOT_SET,
167 RESTRICTION_SOURCE_SYSTEM,
168 RESTRICTION_SOURCE_DEVICE_OWNER,
169 RESTRICTION_SOURCE_PROFILE_OWNER
170 })
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +0100171 @SystemApi
172 public @interface UserRestrictionSource {}
173
174 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -0700175 * Specifies if a user is disallowed from adding and removing accounts, unless they are
176 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
177 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700178 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700179 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +0000180 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
181 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
182 * management is disallowed.
183 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800184 * <p>Key for user restrictions.
185 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700186 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
187 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800188 * @see #getUserRestrictions()
189 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700190 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800191
192 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700193 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -0400194 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800195 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700196 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800197 * <p>Key for user restrictions.
198 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700199 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
200 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800201 * @see #getUserRestrictions()
202 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700203 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800204
205 /**
Christine Franks1bade5d2017-10-10 15:41:50 -0700206 * Specifies if a user is disallowed from changing the device
207 * language. The default value is <code>false</code>.
208 *
209 * <p>Key for user restrictions.
210 * <p>Type: Boolean
211 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
212 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
213 * @see #getUserRestrictions()
214 */
215 public static final String DISALLOW_CONFIG_LOCALE = "no_config_locale";
216
217 /**
Benjamin Millerf1c3ed12018-05-03 10:56:28 +0000218 * Specifies if a user is disallowed from installing applications. This user restriction also
219 * prevents device owners and profile owners installing apps. The default value is
220 * {@code false}.
Amith Yamasani26af8292014-09-09 09:57:27 -0700221 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800222 * <p>Key for user restrictions.
223 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700224 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
225 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800226 * @see #getUserRestrictions()
227 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700228 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800229
230 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700231 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700232 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700233 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800234 * <p>Key for user restrictions.
235 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700236 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
237 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800238 * @see #getUserRestrictions()
239 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700240 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800241
Amith Yamasani71e6c692013-03-24 17:39:28 -0700242 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800243 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700244 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800245 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800246 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700247 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800248 * <p>Key for user restrictions.
249 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700250 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
251 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500252 * @see #getUserRestrictions()
253 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700254 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500255
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400256 /**
yuemingw5fe75dc2017-11-29 15:52:56 +0000257 * Specifies if airplane mode is disallowed on the device.
258 *
259 * <p> This restriction can only be set by the device owner and the profile owner on the
260 * primary user and it applies globally - i.e. it disables airplane mode on the entire device.
261 * <p>The default value is <code>false</code>.
262 *
263 * <p>Key for user restrictions.
264 * <p>Type: Boolean
265 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
266 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
267 * @see #getUserRestrictions()
268 */
269 public static final String DISALLOW_AIRPLANE_MODE = "no_airplane_mode";
270
271 /**
yuemingwc6ac29d2018-01-10 16:54:08 +0000272 * Specifies if a user is disallowed from configuring brightness. When device owner sets it,
273 * it'll only be applied on the target(system) user.
274 *
275 * <p>The default value is <code>false</code>.
276 *
277 * <p>This user restriction has no effect on managed profiles.
278 * <p>Key for user restrictions.
279 * <p>Type: Boolean
280 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
281 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
282 * @see #getUserRestrictions()
283 */
284 public static final String DISALLOW_CONFIG_BRIGHTNESS = "no_config_brightness";
285
286 /**
yuemingwa1781442018-01-10 18:59:43 +0000287 * Specifies if ambient display is disallowed for the user.
288 *
289 * <p>The default value is <code>false</code>.
290 *
291 * <p>This user restriction has no effect on managed profiles.
292 * <p>Key for user restrictions.
293 * <p>Type: Boolean
294 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
295 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
296 * @see #getUserRestrictions()
297 */
298 public static final String DISALLOW_AMBIENT_DISPLAY = "no_ambient_display";
299
300 /**
yuemingw5cda3ae2018-01-15 10:26:19 +0000301 * Specifies if a user is disallowed from changing screen off timeout.
302 *
303 * <p>The default value is <code>false</code>.
304 *
305 * <p>This user restriction has no effect on managed profiles.
306 * <p>Key for user restrictions.
307 * <p>Type: Boolean
308 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
309 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
310 * @see #getUserRestrictions()
311 */
312 public static final String DISALLOW_CONFIG_SCREEN_TIMEOUT = "no_config_screen_timeout";
313
314 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700315 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400316 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100317 * Unknown sources exclude adb and special apps such as trusted app stores.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400318 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700319 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800320 * <p>Key for user restrictions.
321 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700322 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
323 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400324 * @see #getUserRestrictions()
325 */
326 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
327
328 /**
Tor Norbye33ca9122018-10-03 09:28:21 +0200329 * This restriction is a device-wide version of {@link #DISALLOW_INSTALL_UNKNOWN_SOURCES}.
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100330 *
331 * Specifies if all users on the device are disallowed from enabling the
332 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
Irina Dumitrescu0501eee2018-10-19 23:50:18 +0100333 *
334 * This restriction can be enabled by the profile owner, in which case all accounts and
335 * profiles will be affected.
336 *
Irina Dumitrescu4638edd2018-09-05 14:08:33 +0100337 * The default value is <code>false</code>.
338 *
339 * <p>Key for user restrictions.
340 * <p>Type: Boolean
341 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
342 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
343 * @see #getUserRestrictions()
344 */
345 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY =
346 "no_install_unknown_sources_globally";
347
348 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700349 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000350 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400351 * The default value is <code>false</code>.
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100352 * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
353 * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800354 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700355 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800356 * <p>Key for user restrictions.
357 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700358 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
359 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400360 * @see #getUserRestrictions()
361 */
362 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
363
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400364 /**
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100365 * Specifies if bluetooth is disallowed on the device.
366 *
367 * <p> This restriction can only be set by the device owner and the profile owner on the
368 * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
369 * <p>The default value is <code>false</code>.
370 * <p>Key for user restrictions.
371 * <p>Type: Boolean
372 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
373 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
374 * @see #getUserRestrictions()
375 */
376 public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
377
378 /**
Pavel Grafov4f4f6f82017-03-28 13:44:04 +0100379 * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
380 * owner can set this restriction. When it is set by device owner, all users on this device will
381 * be affected.
382 *
383 * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
384 * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
385 * managed profiles.
386 *
387 * <p>Key for user restrictions.
388 * <p>Type: Boolean
389 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
390 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
391 * @see #getUserRestrictions()
392 */
393 public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
394
395 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700396 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700397 * USB. This can only be set by device owners and profile owners on the primary user.
398 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700399 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800400 * <p>Key for user restrictions.
401 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700402 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
403 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400404 * @see #getUserRestrictions()
405 */
406 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
407
Emily Bernierb223f732013-04-11 15:46:36 -0400408 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700409 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400410 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700411 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800412 * <p>Key for user restrictions.
413 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700414 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
415 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400416 * @see #getUserRestrictions()
417 */
418 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
419
420 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800421 * When set on the primary user this specifies if the user can remove other users.
422 * When set on a secondary user, this specifies if the user can remove itself.
423 * This restriction has no effect on managed profiles.
424 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700425 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800426 * <p>Key for user restrictions.
427 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700428 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
429 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400430 * @see #getUserRestrictions()
431 */
432 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
433
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400434 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000435 * Specifies if managed profiles of this user can be removed, other than by its profile owner.
436 * The default value is <code>false</code>.
437 * <p>
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000438 * This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000439 *
440 * <p>Key for user restrictions.
441 * <p>Type: Boolean
442 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
443 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
444 * @see #getUserRestrictions()
Eran Messerice273df2019-12-17 13:14:45 +0000445 * @deprecated As the ability to have a managed profile on a fully-managed device has been
446 * removed from the platform, this restriction will be silently ignored when applied by the
447 * device owner.
448 * When the device is provisioned with a managed profile on an organization-owned device,
449 * the managed profile could not be removed anyway.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000450 */
Eran Messerice273df2019-12-17 13:14:45 +0000451 @Deprecated
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000452 public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
453
454 /**
Pavel Grafov9fb706c2018-02-27 14:07:52 +0000455 * Specifies if a user is disallowed from enabling or accessing debugging features. When set on
456 * the primary user, disables debugging features altogether, including USB debugging. When set
457 * on a managed profile or a secondary user, blocks debugging for that user only, including
458 * starting activities, making service calls, accessing content providers, sending broadcasts,
459 * installing/uninstalling packages, clearing user data, etc.
460 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700461 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800462 * <p>Key for user restrictions.
463 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700464 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
465 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400466 * @see #getUserRestrictions()
467 */
468 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
469
470 /**
Benjamin Miller05fef7e2017-07-24 10:11:39 +0200471 * Specifies if a user is disallowed from configuring a VPN. The default value is
472 * <code>false</code>. This restriction has an effect when set by device owners and, in Android
473 * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners.
474 * <p>This restriction also prevents VPNs from starting. However, in Android 7.0
475 * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does
476 * start always-on VPNs created by the device or profile owner.
Amith Yamasani26af8292014-09-09 09:57:27 -0700477 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800478 * <p>Key for user restrictions.
479 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700480 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
481 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400482 * @see #getUserRestrictions()
483 */
484 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
485
486 /**
yuemingw7810b8b2018-02-01 17:32:25 +0000487 * Specifies if a user is disallowed from enabling or disabling location providers. As a
488 * result, user is disallowed from turning on or off location. Device owner and profile owners
489 * can set this restriction and it only applies on the managed user.
yuemingw7cc2c4c2017-11-28 17:20:01 +0000490 *
491 * <p>In a managed profile, location sharing is forced off when it's off on primary user, so
492 * user can still turn off location sharing on managed profile when the restriction is set by
493 * profile owner on managed profile.
494 *
495 * <p>This user restriction is different from {@link #DISALLOW_SHARE_LOCATION},
496 * as the device owner or profile owner can still enable or disable location mode via
Soonil Nagarkardc08e3a2019-12-02 12:31:45 -0800497 * {@link DevicePolicyManager#setLocationEnabled} when this restriction is on.
yuemingw7cc2c4c2017-11-28 17:20:01 +0000498 *
499 * <p>The default value is <code>false</code>.
500 *
501 * <p>Key for user restrictions.
502 * <p>Type: Boolean
Soonil Nagarkardc08e3a2019-12-02 12:31:45 -0800503 * @see LocationManager#isLocationEnabled()
yuemingw7cc2c4c2017-11-28 17:20:01 +0000504 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
505 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
506 * @see #getUserRestrictions()
507 */
yuemingw7810b8b2018-02-01 17:32:25 +0000508 public static final String DISALLOW_CONFIG_LOCATION = "no_config_location";
yuemingw7cc2c4c2017-11-28 17:20:01 +0000509
510 /**
yuemingwa9772f362017-10-23 18:34:35 +0100511 * Specifies if date, time and timezone configuring is disallowed.
512 *
513 * <p>When restriction is set by device owners, it applies globally - i.e., it disables date,
514 * time and timezone setting on the entire device and all users will be affected. When it's set
515 * by profile owners, it's only applied to the managed user.
516 * <p>The default value is <code>false</code>.
517 *
518 * <p>This user restriction has no effect on managed profiles.
519 * <p>Key for user restrictions.
520 * <p>Type: Boolean
521 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
522 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
523 * @see #getUserRestrictions()
524 */
525 public static final String DISALLOW_CONFIG_DATE_TIME = "no_config_date_time";
526
527 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700528 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700529 * & portable hotspots. This can only be set by device owners and profile owners on the
530 * primary user. The default value is <code>false</code>.
Rubin Xu1faf1442017-08-23 15:48:12 +0100531 * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set,
532 * tethering will be automatically turned off.
Amith Yamasani26af8292014-09-09 09:57:27 -0700533 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800534 * <p>Key for user restrictions.
535 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700536 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
537 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400538 * @see #getUserRestrictions()
539 */
540 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
541
542 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700543 * Specifies if a user is disallowed from resetting network settings
544 * from Settings. This can only be set by device owners and profile owners on the primary user.
545 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800546 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700547 * primary user can reset the network settings of the device.
548 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800549 * <p>Key for user restrictions.
550 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700551 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
552 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700553 * @see #getUserRestrictions()
554 */
555 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
556
557 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700558 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700559 * from Settings. This can only be set by device owners and profile owners on the primary user.
560 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800561 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800562 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700563 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800564 * <p>Key for user restrictions.
565 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700566 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
567 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400568 * @see #getUserRestrictions()
569 */
570 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
571
572 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000573 * Specifies if a user is disallowed from adding new users. This can only be set by device
574 * owners and profile owners on the primary user.
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700575 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800576 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800577 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700578 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800579 * <p>Key for user restrictions.
580 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700581 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
582 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400583 * @see #getUserRestrictions()
584 */
585 public static final String DISALLOW_ADD_USER = "no_add_user";
586
587 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000588 * Specifies if a user is disallowed from adding managed profiles.
589 * <p>The default value for an unmanaged user is <code>false</code>.
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000590 * For users with a device owner set, the default is <code>true</code>.
591 * <p>This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000592 *
593 * <p>Key for user restrictions.
594 * <p>Type: Boolean
595 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
596 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
597 * @see #getUserRestrictions()
Eran Messerice273df2019-12-17 13:14:45 +0000598 * @deprecated As the ability to have a managed profile on a fully-managed device has been
599 * removed from the platform, this restriction will be silently ignored when applied by the
600 * device owner.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000601 */
Eran Messerice273df2019-12-17 13:14:45 +0000602 @Deprecated
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000603 public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
604
605 /**
Benjamin Millerd41a9fc2017-07-17 17:24:44 +0200606 * Specifies if a user is disallowed from disabling application verification. The default
607 * value is <code>false</code>.
608 *
609 * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher,
610 * this is a global user restriction. If a device owner or profile owner sets this restriction,
611 * the system enforces app verification across all users on the device. Running in earlier
612 * Android versions, this restriction affects only the profile that sets it.
Amith Yamasani26af8292014-09-09 09:57:27 -0700613 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800614 * <p>Key for user restrictions.
615 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700616 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
617 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400618 * @see #getUserRestrictions()
619 */
620 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
621
622 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700623 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700624 * broadcasts. This can only be set by device owners and profile owners on the primary user.
625 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800626 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800627 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700628 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800629 * <p>Key for user restrictions.
630 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700631 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
632 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400633 * @see #getUserRestrictions()
634 */
635 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
636
637 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700638 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700639 * networks. This can only be set by device owners and profile owners on the primary user.
640 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800641 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800642 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700643 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800644 * <p>Key for user restrictions.
645 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700646 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
647 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400648 * @see #getUserRestrictions()
649 */
650 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
651
652 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700653 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400654 * applications in Settings or launchers. The following actions will not be allowed when this
655 * restriction is enabled:
656 * <li>uninstalling apps</li>
657 * <li>disabling apps</li>
658 * <li>clearing app caches</li>
659 * <li>clearing app data</li>
660 * <li>force stopping apps</li>
661 * <li>clearing app defaults</li>
662 * <p>
663 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700664 *
Esteban Talavera8bd7c522017-02-13 12:35:04 +0000665 * <p><strong>Note:</strong> The user will still be able to perform those actions via other
666 * means (such as adb). Third party apps will also be able to uninstall apps via the
667 * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
668 * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
669 * used to prevent the user from uninstalling apps completely, and
670 * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
671 * to add a default intent handler for a given intent filter.
672 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800673 * <p>Key for user restrictions.
674 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700675 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
676 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400677 * @see #getUserRestrictions()
678 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400679 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400680
Emily Bernier394a6cd2014-05-07 12:49:20 -0400681 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700682 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700683 * physical external media. This can only be set by device owners and profile owners on the
684 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700685 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800686 * <p>Key for user restrictions.
687 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700688 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
689 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400690 * @see #getUserRestrictions()
691 */
692 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
693
694 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100695 * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
696 * will be muted. This can be set by device owners and profile owners. The default value is
697 * <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700698 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100699 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800700 * <p>Key for user restrictions.
701 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700702 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
703 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400704 * @see #getUserRestrictions()
705 */
706 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
707
708 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100709 * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
Wen ZHANG61ed0dc2017-08-23 14:27:02 +0100710 * will be muted. This can be set by device owners from API 21 and profile owners from API 24.
711 * The default value is <code>false</code>.
712 *
713 * <p>When the restriction is set by profile owners, then it only applies to relevant
714 * profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700715 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100716 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800717 * <p>Key for user restrictions.
718 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700719 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
720 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400721 * @see #getUserRestrictions()
722 */
723 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
724
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700725 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700726 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700727 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700728 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000729 * <p>This restriction has no effect on managed profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700730 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800731 * <p>Key for user restrictions.
732 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700733 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
734 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700735 * @see #getUserRestrictions()
736 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700737 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
738
739 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700740 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700741 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700742 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800743 * <p>Key for user restrictions.
744 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700745 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
746 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700747 * @see #getUserRestrictions()
748 */
749 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700750
Jason Monk1c7c3192014-06-26 12:52:18 -0400751 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700752 * Specifies if the user is not allowed to have fun. In some cases, the
753 * device owner may wish to prevent the user from experiencing amusement or
754 * joy while using the device. The default value is <code>false</code>.
755 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800756 * <p>Key for user restrictions.
757 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700758 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
759 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700760 * @see #getUserRestrictions()
761 */
762 public static final String DISALLOW_FUN = "no_fun";
763
764 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700765 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400766 * created. This will block the creation of the following types of windows.
767 * <li>{@link LayoutParams#TYPE_TOAST}</li>
768 * <li>{@link LayoutParams#TYPE_PHONE}</li>
769 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
770 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
771 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
772 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800773 * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
Jason Monk1c7c3192014-06-26 12:52:18 -0400774 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700775 * <p>This can only be set by device owners and profile owners on the primary user.
776 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700777 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800778 * <p>Key for user restrictions.
779 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700780 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
781 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400782 * @see #getUserRestrictions()
783 */
784 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
785
Nicolas Prevotf1939902014-06-25 09:29:02 +0100786 /**
Charles He22ff6f9d2017-10-05 21:28:55 +0100787 * Specifies that system error dialogs for crashed or unresponsive apps should not be shown.
788 * 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 +0000789 * option on the UI. A feedback report isn't collected as there is no way for the user to
790 * provide explicit consent. The default value is <code>false</code>.
Charles He22ff6f9d2017-10-05 21:28:55 +0100791 *
Benjamin Franz0c86fe12018-02-28 09:49:17 +0000792 * <p>When this user restriction is set by device owners, it's applied to all users. When set by
793 * the profile owner of the primary user or a secondary user, the restriction affects only the
794 * calling user. This user restriction has no effect on managed profiles.
Charles He22ff6f9d2017-10-05 21:28:55 +0100795 *
Charles He22ff6f9d2017-10-05 21:28:55 +0100796 * <p>Key for user restrictions.
797 * <p>Type: Boolean
798 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
799 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
800 * @see #getUserRestrictions()
801 */
802 public static final String DISALLOW_SYSTEM_ERROR_DIALOGS = "no_system_error_dialogs";
803
804 /**
Benjamin Miller8cc730d2019-01-18 19:03:40 +0000805 * Specifies if the clipboard contents can be exported by pasting the data into other users or
806 * profiles. This restriction doesn't prevent import, such as someone pasting clipboard data
807 * from other profiles or users. The default value is {@code false}.
808 *
809 * <p><strong>Note</strong>: Because it's possible to extract data from screenshots using
810 * optical character recognition (OCR), we strongly recommend combining this user restriction
811 * with {@link DevicePolicyManager#setScreenCaptureDisabled(ComponentName, boolean)}.
Amith Yamasani26af8292014-09-09 09:57:27 -0700812 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800813 * <p>Key for user restrictions.
814 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700815 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
816 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100817 * @see #getUserRestrictions()
818 */
819 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
820
Amith Yamasani26af8292014-09-09 09:57:27 -0700821 /**
822 * Specifies if the user is not allowed to use NFC to beam out data from apps.
823 * The default value is <code>false</code>.
824 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800825 * <p>Key for user restrictions.
826 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700827 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
828 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani26af8292014-09-09 09:57:27 -0700829 * @see #getUserRestrictions()
830 */
831 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
832
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000833 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100834 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
835 * generally means that wallpapers are not supported for the particular user. This user
836 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000837 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100838 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700839 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
840 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000841 * @see #getUserRestrictions()
842 */
843 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
844
845 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100846 * User restriction to disallow setting a wallpaper. Profile owner and device owner
847 * are able to set wallpaper regardless of this restriction.
848 * The default value is <code>false</code>.
849 *
850 * <p>Key for user restrictions.
851 * <p>Type: Boolean
852 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
853 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
854 * @see #getUserRestrictions()
855 */
856 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
857
858 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000859 * Specifies if the user is not allowed to reboot the device into safe boot mode.
860 * This can only be set by device owners and profile owners on the primary user.
861 * The default value is <code>false</code>.
862 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800863 * <p>Key for user restrictions.
864 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700865 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
866 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000867 * @see #getUserRestrictions()
868 */
869 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
870
871 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700872 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
873 * background users. The default value is <code>false</code>.
874 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700875 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
876 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700877 * @see #getUserRestrictions()
878 * @hide
879 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000880 @UnsupportedAppUsage
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700881 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
882
883 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700884 * Specifies if a user is not allowed to run in the background and should be stopped during
885 * user switch. The default value is <code>false</code>.
886 *
887 * <p>This restriction can be set by device owners and profile owners.
888 *
889 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
890 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
891 * @see #getUserRestrictions()
892 * @hide
893 */
Robin Lee6cfb7a92017-12-18 15:14:46 +0100894 @SystemApi
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700895 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
896
897 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700898 * Specifies if a user is not allowed to use the camera.
899 *
900 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
901 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
902 * @see #getUserRestrictions()
903 * @hide
904 */
905 public static final String DISALLOW_CAMERA = "no_camera";
906
907 /**
Tony Makc1205112016-07-22 16:02:59 +0100908 * Specifies if a user is not allowed to unmute the device's master volume.
909 *
910 * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
911 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
912 * @see #getUserRestrictions()
913 * @hide
914 */
Esteban Talavera492b4722017-02-13 14:59:45 +0000915 public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
Tony Makc1205112016-07-22 16:02:59 +0100916
917 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000918 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
919 * device owners. The default value is <code>false</code>.
920 *
921 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
922 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
923 * @see #getUserRestrictions()
924 */
925 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
926
927 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100928 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
929 * can set this restriction. When it is set by device owner, only the target user will be
930 * affected. The default value is <code>false</code>.
931 *
932 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100933 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100934 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
935 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
936 * @see #getUserRestrictions()
937 */
938 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
939
940 /**
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100941 * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100942 * <code>false</code>. Setting this restriction has no effect if the bootloader is already
943 * unlocked.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100944 *
Lenka Trochtova12b04962016-11-29 21:00:12 +0100945 * <p>Not for use by third-party applications.
946 *
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100947 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
948 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
949 * @see #getUserRestrictions()
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000950 * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100951 * @hide
952 */
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000953 @Deprecated
Lenka Trochtova12b04962016-11-29 21:00:12 +0100954 @SystemApi
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100955 public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
956
957 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +0100958 * Specifies that the managed profile is not allowed to have unified lock screen challenge with
959 * the primary user.
960 *
961 * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a
962 * separate challenge. Profile owner can ask the user to set a new password using
963 * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using
964 * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}.
965 *
966 * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed
967 * profile owner. Has no effect on non-managed profiles or users.
968 * <p>Key for user restrictions.
969 * <p>Type: Boolean
970 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
971 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
972 * @see #getUserRestrictions()
973 */
974 public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password";
975
976 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700977 * Allows apps in the parent profile to handle web links from the managed profile.
978 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700979 * This user restriction has an effect only in a managed profile.
980 * If set:
981 * Intent filters of activities in the parent profile with action
982 * {@link android.content.Intent#ACTION_VIEW},
983 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
984 * define a host can handle intents from the managed profile.
985 * The default value is <code>false</code>.
986 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800987 * <p>Key for user restrictions.
988 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700989 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
990 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700991 * @see #getUserRestrictions()
992 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700993 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
994 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700995
996 /**
Felipe Leme24d58932017-03-21 14:13:58 -0700997 * Specifies if a user is not allowed to use Autofill Services.
998 *
999 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
1000 * only the target user will be affected.
1001 *
1002 * <p>The default value is <code>false</code>.
1003 *
1004 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1005 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1006 * @see #getUserRestrictions()
1007 */
1008 public static final String DISALLOW_AUTOFILL = "no_autofill";
1009
1010 /**
Felipe Leme1dfa9a02018-10-17 17:24:37 -07001011 * Specifies if the contents of a user's screen is not allowed to be captured for artificial
1012 * intelligence purposes.
1013 *
1014 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
1015 * only the target user will be affected.
1016 *
1017 * <p>The default value is <code>false</code>.
1018 *
1019 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1020 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1021 * @see #getUserRestrictions()
1022 */
Felipe Leme749b8892018-12-03 16:30:30 -08001023 public static final String DISALLOW_CONTENT_CAPTURE = "no_content_capture";
Felipe Leme1dfa9a02018-10-17 17:24:37 -07001024
1025 /**
Zak Cohen3e12ac72019-03-05 16:50:39 -08001026 * Specifies if the current user is able to receive content suggestions for selections based on
1027 * the contents of their screen.
1028 *
1029 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
1030 * only the target user will be affected.
1031 *
1032 * <p>The default value is <code>false</code>.
1033 *
1034 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1035 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1036 * @see #getUserRestrictions()
1037 */
1038 public static final String DISALLOW_CONTENT_SUGGESTIONS = "no_content_suggestions";
1039
1040 /**
Benjamin Franzff66fa92017-08-10 10:39:44 +01001041 * Specifies if user switching is blocked on the current user.
1042 *
1043 * <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 +08001044 * Device owner can still switch user via
1045 * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is
1046 * set.
Benjamin Franzff66fa92017-08-10 10:39:44 +01001047 *
1048 * <p>The default value is <code>false</code>.
1049 *
1050 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1051 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1052 * @see #getUserRestrictions()
1053 */
1054 public static final String DISALLOW_USER_SWITCH = "no_user_switch";
1055
1056 /**
Rubin Xucc391c22018-01-02 20:37:35 +00001057 * Specifies whether the user can share file / picture / data from the primary user into the
1058 * managed profile, either by sending them from the primary side, or by picking up data within
1059 * an app in the managed profile.
1060 * <p>
1061 * When a managed profile is created, the system allows the user to send data from the primary
1062 * side to the profile by setting up certain default cross profile intent filters. If
1063 * this is undesired, this restriction can be set to disallow it. Note that this restriction
1064 * will not block any sharing allowed by explicit
1065 * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner.
1066 * <p>
1067 * This restriction is only meaningful when set by profile owner. When it is set by device
1068 * owner, it does not have any effect.
1069 * <p>
1070 * The default value is <code>false</code>.
1071 *
1072 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1073 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1074 * @see #getUserRestrictions()
1075 */
1076 public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile";
Vladislav Kuzkokov622b9f92018-01-25 16:33:05 +01001077
1078 /**
1079 * Specifies whether the user is allowed to print.
1080 *
1081 * This restriction can be set by device or profile owner.
1082 *
1083 * The default value is {@code false}.
1084 *
1085 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1086 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1087 * @see #getUserRestrictions()
1088 */
1089 public static final String DISALLOW_PRINTING = "no_printing";
1090
Rubin Xucc391c22018-01-02 20:37:35 +00001091 /**
Eran Messeri09b122da2018-10-05 15:33:53 +01001092 * Specifies whether the user is allowed to modify private DNS settings.
1093 *
1094 * <p>The default value is <code>false</code>.
1095 *
1096 * <p>This user restriction can only be applied by the Device Owner.
1097 * <p>Key for user restrictions.
1098 * <p>Type: Boolean
1099 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
1100 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1101 * @see #getUserRestrictions()
1102 */
1103 public static final String DISALLOW_CONFIG_PRIVATE_DNS =
1104 "disallow_config_private_dns";
1105
1106 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00001107 * Application restriction key that is used to indicate the pending arrival
1108 * of real restrictions for the app.
1109 *
1110 * <p>
1111 * Applications that support restrictions should check for the presence of this key.
1112 * A <code>true</code> value indicates that restrictions may be applied in the near
1113 * future but are not available yet. It is the responsibility of any
1114 * management application that sets this flag to update it when the final
1115 * restrictions are enforced.
1116 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -08001117 * <p>Key for application restrictions.
1118 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +00001119 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
1120 * android.content.ComponentName, String, Bundle)
1121 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
1122 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00001123 */
1124 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
1125
Roshan Pius3eac0b92019-12-05 09:35:36 -08001126 /**
1127 * List of key values that can be passed into the various user restriction related methods
1128 * in {@link UserManager} & {@link DevicePolicyManager}.
1129 * Note: This is slightly different from the real set of user restrictions listed in {@link
1130 * com.android.server.pm.UserRestrictionsUtils#USER_RESTRICTIONS}. For example
1131 * {@link #KEY_RESTRICTIONS_PENDING} is not a real user restriction, but is a a legitimate
1132 * value that can be passed into {@link #hasUserRestriction(String)}.
1133 * @hide
1134 */
1135 @StringDef(value = {
1136 DISALLOW_MODIFY_ACCOUNTS,
1137 DISALLOW_CONFIG_WIFI,
1138 DISALLOW_CONFIG_LOCALE,
1139 DISALLOW_INSTALL_APPS,
1140 DISALLOW_UNINSTALL_APPS,
1141 DISALLOW_SHARE_LOCATION,
1142 DISALLOW_AIRPLANE_MODE,
1143 DISALLOW_CONFIG_BRIGHTNESS,
1144 DISALLOW_AMBIENT_DISPLAY,
1145 DISALLOW_CONFIG_SCREEN_TIMEOUT,
1146 DISALLOW_INSTALL_UNKNOWN_SOURCES,
1147 DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY,
1148 DISALLOW_CONFIG_BLUETOOTH,
1149 DISALLOW_BLUETOOTH,
1150 DISALLOW_BLUETOOTH_SHARING,
1151 DISALLOW_USB_FILE_TRANSFER,
1152 DISALLOW_CONFIG_CREDENTIALS,
1153 DISALLOW_REMOVE_USER,
1154 DISALLOW_REMOVE_MANAGED_PROFILE,
1155 DISALLOW_DEBUGGING_FEATURES,
1156 DISALLOW_CONFIG_VPN,
1157 DISALLOW_CONFIG_LOCATION,
1158 DISALLOW_CONFIG_DATE_TIME,
1159 DISALLOW_CONFIG_TETHERING,
1160 DISALLOW_NETWORK_RESET,
1161 DISALLOW_FACTORY_RESET,
1162 DISALLOW_ADD_USER,
1163 DISALLOW_ADD_MANAGED_PROFILE,
1164 ENSURE_VERIFY_APPS,
1165 DISALLOW_CONFIG_CELL_BROADCASTS,
1166 DISALLOW_CONFIG_MOBILE_NETWORKS,
1167 DISALLOW_APPS_CONTROL,
1168 DISALLOW_MOUNT_PHYSICAL_MEDIA,
1169 DISALLOW_UNMUTE_MICROPHONE,
1170 DISALLOW_ADJUST_VOLUME,
1171 DISALLOW_OUTGOING_CALLS,
1172 DISALLOW_SMS,
1173 DISALLOW_FUN,
1174 DISALLOW_CREATE_WINDOWS,
1175 DISALLOW_SYSTEM_ERROR_DIALOGS,
1176 DISALLOW_CROSS_PROFILE_COPY_PASTE,
1177 DISALLOW_OUTGOING_BEAM,
1178 DISALLOW_WALLPAPER,
1179 DISALLOW_SET_WALLPAPER,
1180 DISALLOW_SAFE_BOOT,
1181 DISALLOW_RECORD_AUDIO,
1182 DISALLOW_RUN_IN_BACKGROUND,
1183 DISALLOW_CAMERA,
1184 DISALLOW_UNMUTE_DEVICE,
1185 DISALLOW_DATA_ROAMING,
1186 DISALLOW_SET_USER_ICON,
1187 DISALLOW_OEM_UNLOCK,
1188 DISALLOW_UNIFIED_PASSWORD,
1189 ALLOW_PARENT_PROFILE_APP_LINKING,
1190 DISALLOW_AUTOFILL,
1191 DISALLOW_CONTENT_CAPTURE,
1192 DISALLOW_CONTENT_SUGGESTIONS,
1193 DISALLOW_USER_SWITCH,
1194 DISALLOW_SHARE_INTO_MANAGED_PROFILE,
1195 DISALLOW_PRINTING,
1196 DISALLOW_CONFIG_PRIVATE_DNS,
1197 KEY_RESTRICTIONS_PENDING,
1198 })
1199 @Retention(RetentionPolicy.SOURCE)
1200 public @interface UserRestrictionKey {}
1201
Amith Yamasani12747872015-12-07 14:19:49 -08001202 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
1203
1204 /**
1205 * Extra containing a name for the user being created. Optional parameter passed to
1206 * ACTION_CREATE_USER activity.
1207 * @hide
1208 */
1209 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
1210
1211 /**
1212 * Extra containing account name for the user being created. Optional parameter passed to
1213 * ACTION_CREATE_USER activity.
1214 * @hide
1215 */
1216 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
1217
1218 /**
1219 * Extra containing account type for the user being created. Optional parameter passed to
1220 * ACTION_CREATE_USER activity.
1221 * @hide
1222 */
1223 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
1224
1225 /**
1226 * Extra containing account-specific data for the user being created. Optional parameter passed
1227 * to ACTION_CREATE_USER activity.
1228 * @hide
1229 */
1230 public static final String EXTRA_USER_ACCOUNT_OPTIONS
1231 = "android.os.extra.USER_ACCOUNT_OPTIONS";
1232
Amith Yamasani655d0e22013-06-12 14:19:10 -07001233 /** @hide */
1234 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
1235 /** @hide */
1236 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
1237 /** @hide */
1238 public static final int PIN_VERIFICATION_SUCCESS = -1;
1239
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001240 /**
Makoto Onukie72f81b2017-03-16 14:08:19 -07001241 * Sent when user restrictions have changed.
1242 *
1243 * @hide
1244 */
1245 @SystemApi
1246 @TestApi // To allow seeing it from CTS.
1247 public static final String ACTION_USER_RESTRICTIONS_CHANGED =
1248 "android.os.action.USER_RESTRICTIONS_CHANGED";
1249
1250 /**
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001251 * Error result indicating that this user is not allowed to add other users on this device.
1252 * This is a result code returned from the activity created by the intent
1253 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1254 */
1255 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
1256
1257 /**
1258 * Error result indicating that no more users can be created on this device.
1259 * This is a result code returned from the activity created by the intent
1260 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1261 */
1262 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
1263
Alex Chau89386ba2018-02-13 11:09:17 +08001264 /**
Varun Shah50ef2002019-03-04 16:41:12 -08001265 * Indicates that users are switchable.
1266 * @hide
1267 */
1268 @SystemApi
1269 public static final int SWITCHABILITY_STATUS_OK = 0;
1270
1271 /**
1272 * Indicated that the user is in a phone call.
1273 * @hide
1274 */
1275 @SystemApi
1276 public static final int SWITCHABILITY_STATUS_USER_IN_CALL = 1 << 0;
1277
1278 /**
1279 * Indicates that user switching is disallowed ({@link #DISALLOW_USER_SWITCH} is set).
1280 * @hide
1281 */
1282 @SystemApi
1283 public static final int SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED = 1 << 1;
1284
1285 /**
1286 * Indicates that the system user is locked and user switching is not allowed.
1287 * @hide
1288 */
1289 @SystemApi
1290 public static final int SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED = 1 << 2;
1291
1292 /**
1293 * Result returned in {@link #getUserSwitchability()} indicating user swichability.
1294 * @hide
1295 */
1296 @Retention(RetentionPolicy.SOURCE)
1297 @IntDef(flag = true, prefix = { "SWITCHABILITY_STATUS_" }, value = {
1298 SWITCHABILITY_STATUS_OK,
1299 SWITCHABILITY_STATUS_USER_IN_CALL,
1300 SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED,
1301 SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED
1302 })
1303 public @interface UserSwitchabilityResult {}
1304
1305 /**
Alex Chau89386ba2018-02-13 11:09:17 +08001306 * Indicates user operation is successful.
1307 */
1308 public static final int USER_OPERATION_SUCCESS = 0;
1309
1310 /**
1311 * Indicates user operation failed for unknown reason.
1312 */
1313 public static final int USER_OPERATION_ERROR_UNKNOWN = 1;
1314
1315 /**
1316 * Indicates user operation failed because target user is a managed profile.
1317 */
1318 public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2;
1319
1320 /**
1321 * Indicates user operation failed because maximum running user limit has been reached.
1322 */
1323 public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3;
1324
1325 /**
1326 * Indicates user operation failed because the target user is in the foreground.
1327 */
1328 public static final int USER_OPERATION_ERROR_CURRENT_USER = 4;
1329
1330 /**
1331 * Indicates user operation failed because device has low data storage.
1332 */
1333 public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5;
1334
1335 /**
1336 * Indicates user operation failed because maximum user limit has been reached.
1337 */
1338 public static final int USER_OPERATION_ERROR_MAX_USERS = 6;
1339
1340 /**
1341 * Result returned from various user operations.
1342 *
1343 * @hide
1344 */
1345 @Retention(RetentionPolicy.SOURCE)
1346 @IntDef(prefix = { "USER_OPERATION_" }, value = {
1347 USER_OPERATION_SUCCESS,
1348 USER_OPERATION_ERROR_UNKNOWN,
1349 USER_OPERATION_ERROR_MANAGED_PROFILE,
1350 USER_OPERATION_ERROR_MAX_RUNNING_USERS,
1351 USER_OPERATION_ERROR_CURRENT_USER,
1352 USER_OPERATION_ERROR_LOW_STORAGE,
1353 USER_OPERATION_ERROR_MAX_USERS
1354 })
1355 public @interface UserOperationResult {}
1356
1357 /**
1358 * Thrown to indicate user operation failed.
1359 */
1360 public static class UserOperationException extends RuntimeException {
1361 private final @UserOperationResult int mUserOperationResult;
1362
1363 /**
1364 * Constructs a UserOperationException with specific result code.
1365 *
1366 * @param message the detail message
1367 * @param userOperationResult the result code
1368 * @hide
1369 */
1370 public UserOperationException(String message,
1371 @UserOperationResult int userOperationResult) {
1372 super(message);
1373 mUserOperationResult = userOperationResult;
1374 }
1375
1376 /**
1377 * Returns the operation result code.
1378 */
1379 public @UserOperationResult int getUserOperationResult() {
1380 return mUserOperationResult;
1381 }
1382 }
1383
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001384 /** @hide */
Andrei Onea24ec3212019-03-15 17:35:05 +00001385 @UnsupportedAppUsage
Amith Yamasanic0688302015-10-30 10:40:03 -07001386 public static UserManager get(Context context) {
1387 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -07001388 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001389
Amith Yamasani258848d2012-08-10 17:06:33 -07001390 /** @hide */
1391 public UserManager(Context context, IUserManager service) {
1392 mService = service;
Fyodor Kupolov5200e1c2016-10-17 18:46:16 -07001393 mContext = context.getApplicationContext();
Amith Yamasani258848d2012-08-10 17:06:33 -07001394 }
1395
1396 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001397 * Returns whether this device supports multiple users with their own login and customizable
1398 * space.
1399 * @return whether the device supports multiple users.
Amith Yamasani258848d2012-08-10 17:06:33 -07001400 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -07001401 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +00001402 return getMaxSupportedUsers() > 1
1403 && SystemProperties.getBoolean("fw.show_multiuserui",
1404 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -07001405 }
1406
Maggie Benthall67944582013-02-22 14:58:27 -05001407 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001408 * @hide
1409 * @return Whether the device is running with split system user. It means the system user and
1410 * primary user are two separate users. Previously system user and primary user are combined as
1411 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
1412 */
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001413 @TestApi
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001414 public static boolean isSplitSystemUser() {
John Reckaa67f682016-09-20 14:24:21 -07001415 return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001416 }
1417
1418 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001419 * @return Whether guest user is always ephemeral
1420 * @hide
1421 */
1422 public static boolean isGuestUserEphemeral() {
1423 return Resources.getSystem()
1424 .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
1425 }
1426
1427 /**
Eric Jeonge7ead1b2019-07-18 09:37:08 -07001428 * @hide
1429 * @return Whether the device is running in a headless system user mode. It means the headless
1430 * user (system user) runs system services and system UI, but is not associated with any real
1431 * person. Secondary users can be created to be associated with real person.
1432 */
1433 public static boolean isHeadlessSystemUserMode() {
1434 return RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER;
1435 }
1436
1437 /**
Varun Shah50ef2002019-03-04 16:41:12 -08001438 * @deprecated use {@link #getUserSwitchability()} instead.
1439 *
1440 * @removed
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001441 * @hide
1442 */
Varun Shah50ef2002019-03-04 16:41:12 -08001443 @Deprecated
1444 @UnsupportedAppUsage
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001445 public boolean canSwitchUsers() {
1446 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
1447 mContext.getContentResolver(),
1448 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
1449 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
Jayachandran C16dce222019-11-15 15:42:01 -08001450 boolean inCall = false;
1451 TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
1452 if (telephonyManager != null) {
1453 inCall = telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE;
1454 }
Benjamin Franzff66fa92017-08-10 10:39:44 +01001455 boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
1456 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
1457 && !isUserSwitchDisallowed;
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001458 }
1459
1460 /**
Anthony Hugh6acda5e2019-10-24 14:49:52 -07001461 * Returns whether switching users is currently allowed for the user this process is running
1462 * under.
Varun Shah50ef2002019-03-04 16:41:12 -08001463 * <p>
1464 * Switching users is not allowed in the following cases:
1465 * <li>the user is in a phone call</li>
1466 * <li>{@link #DISALLOW_USER_SWITCH} is set</li>
1467 * <li>system user hasn't been unlocked yet</li>
1468 *
1469 * @return A {@link UserSwitchabilityResult} flag indicating if the user is switchable.
1470 * @hide
1471 */
1472 @SystemApi
1473 @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE,
1474 android.Manifest.permission.MANAGE_USERS,
1475 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
1476 public @UserSwitchabilityResult int getUserSwitchability() {
Anthony Hugh6acda5e2019-10-24 14:49:52 -07001477 return getUserSwitchability(Process.myUserHandle());
1478 }
1479
1480 /**
1481 * Returns whether switching users is currently allowed for the provided user.
1482 * <p>
1483 * Switching users is not allowed in the following cases:
1484 * <li>the user is in a phone call</li>
1485 * <li>{@link #DISALLOW_USER_SWITCH} is set</li>
1486 * <li>system user hasn't been unlocked yet</li>
1487 *
1488 * @return A {@link UserSwitchabilityResult} flag indicating if the user is switchable.
1489 * @hide
1490 */
1491 @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE,
1492 android.Manifest.permission.MANAGE_USERS,
1493 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
1494 public @UserSwitchabilityResult int getUserSwitchability(UserHandle userHandle) {
Varun Shah50ef2002019-03-04 16:41:12 -08001495 final TelephonyManager tm =
1496 (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
1497
1498 int flags = SWITCHABILITY_STATUS_OK;
1499 if (tm.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
1500 flags |= SWITCHABILITY_STATUS_USER_IN_CALL;
1501 }
Anthony Hugh6acda5e2019-10-24 14:49:52 -07001502 if (hasUserRestriction(DISALLOW_USER_SWITCH, userHandle)) {
Varun Shah50ef2002019-03-04 16:41:12 -08001503 flags |= SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED;
1504 }
Anthony Hugh6acda5e2019-10-24 14:49:52 -07001505
1506 // System User is always unlocked in Headless System User Mode, so ignore this flag
1507 if (!isHeadlessSystemUserMode()) {
1508 final boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
1509 mContext.getContentResolver(),
1510 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
1511 final boolean systemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
1512
1513 if (!allowUserSwitchingWhenSystemUserLocked && !systemUserUnlocked) {
1514 flags |= SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED;
1515 }
Varun Shah50ef2002019-03-04 16:41:12 -08001516 }
Anthony Hugh6acda5e2019-10-24 14:49:52 -07001517
Varun Shah50ef2002019-03-04 16:41:12 -08001518 return flags;
1519 }
1520
1521 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001522 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +01001523 *
Amith Yamasani5760e172015-04-17 18:42:41 -07001524 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -07001525 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -05001526 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001527 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001528 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001529 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -07001530 }
1531
1532 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001533 * Returns the user name of the user making this call. This call is only
1534 * available to applications on the system image; it requires the
Bookatzcde3d922019-03-08 14:30:00 -08001535 * {@code android.permission.MANAGE_USERS} or {@code android.permission.GET_ACCOUNTS_PRIVILEGED}
1536 * permissions.
Amith Yamasani258848d2012-08-10 17:06:33 -07001537 * @return the user name
1538 */
1539 public String getUserName() {
Bookatzcde3d922019-03-08 14:30:00 -08001540 try {
1541 return mService.getUserName();
1542 } catch (RemoteException re) {
1543 throw re.rethrowFromSystemServer();
1544 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001545 }
1546
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001547 /**
Fyodor Kupolov605b12a2017-05-10 15:58:09 -07001548 * Returns whether user name has been set.
1549 * <p>This method can be used to check that the value returned by {@link #getUserName()} was
1550 * set by the user and is not a placeholder string provided by the system.
1551 * @hide
1552 */
Bookatzfe4eb2b2019-08-22 18:26:49 -07001553 @SystemApi
1554 @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS,
1555 Manifest.permission.GET_ACCOUNTS_PRIVILEGED})
Fyodor Kupolov605b12a2017-05-10 15:58:09 -07001556 public boolean isUserNameSet() {
1557 try {
1558 return mService.isUserNameSet(getUserHandle());
1559 } catch (RemoteException re) {
1560 throw re.rethrowFromSystemServer();
1561 }
1562 }
1563
1564 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -07001565 * Used to determine whether the user making this call is subject to
1566 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001567 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001568 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001569 * now automatically identify goats using advanced goat recognition technology.</p>
1570 *
1571 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -07001572 */
1573 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -07001574 return mContext.getPackageManager()
1575 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -07001576 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001577
1578 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001579 * Used to check if this process is running under the primary user. The primary user
Ying Zheng215116f2019-09-11 12:50:09 -07001580 * is the first human user on a device. This is not supported in headless system user mode.
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001581 *
1582 * @return whether this process is running under the primary user.
1583 * @hide
1584 */
Varun Shahe142e332018-10-22 15:52:56 -07001585 @SystemApi
1586 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001587 public boolean isPrimaryUser() {
1588 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001589 return user != null && user.isPrimary();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001590 }
1591
1592 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001593 * Used to check if this process is running under the system user. The system user
1594 * is the initial user that is implicitly created on first boot and hosts most of the
1595 * system services.
1596 *
1597 * @return whether this process is running under the system user.
1598 */
1599 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001600 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -07001601 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001602
Amith Yamasani5760e172015-04-17 18:42:41 -07001603 /**
Varun Shahe142e332018-10-22 15:52:56 -07001604 * Used to check if this process is running as an admin user. An admin user is allowed to
1605 * modify or configure certain settings that aren't available to non-admin users,
1606 * create and delete additional users, etc. There can be more than one admin users.
1607 *
1608 * @return whether this process is running under an admin user.
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001609 * @hide
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001610 */
Varun Shahe142e332018-10-22 15:52:56 -07001611 @SystemApi
1612 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001613 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001614 return isUserAdmin(UserHandle.myUserId());
1615 }
1616
1617 /**
1618 * @hide
1619 * Returns whether the provided user is an admin user. There can be more than one admin
1620 * user.
1621 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001622 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001623 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001624 UserInfo user = getUserInfo(userId);
1625 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001626 }
1627
1628 /**
Bookatz029832a2019-10-04 16:50:22 -07001629 * Returns the calling user's user type.
1630 *
1631 * // TODO(b/142482943): Decide on the appropriate permission requirements.
1632 *
1633 * @return the name of the user type, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
1634 * @hide
1635 */
1636 public @NonNull String getUserType() {
1637 try {
1638 return mService.getUserTypeForUser(UserHandle.myUserId());
1639 } catch (RemoteException re) {
1640 throw re.rethrowFromSystemServer();
1641 }
1642 }
1643
1644 /**
1645 * Returns the given user's user type.
1646 *
1647 * // TODO(b/142482943): Decide on the appropriate permission requirements.
1648 * Requires {@link android.Manifest.permission#MANAGE_USERS} or
1649 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller
1650 * must be in the same profile group of specified user.
1651 *
1652 * @param userHandle the user handle of the user whose type is being requested.
1653 * @return the name of the user's user type, e.g. {@link UserManager#USER_TYPE_PROFILE_MANAGED},
1654 * or {@code null} if there is no such user.
1655 * @hide
1656 */
1657 @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
1658 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
1659 public @Nullable String getUserTypeForUser(@NonNull UserHandle userHandle) {
1660 try {
1661 return mService.getUserTypeForUser(userHandle.getIdentifier());
1662 } catch (RemoteException re) {
1663 throw re.rethrowFromSystemServer();
1664 }
1665 }
1666
1667 /**
1668 * Returns whether the user type is a
1669 * {@link UserManager#USER_TYPE_PROFILE_MANAGED managed profile}.
1670 * @hide
1671 */
1672 public static boolean isUserTypeManagedProfile(String userType) {
1673 return USER_TYPE_PROFILE_MANAGED.equals(userType);
1674 }
1675
1676 /**
1677 * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_GUEST guest user}.
1678 * @hide
1679 */
1680 public static boolean isUserTypeGuest(String userType) {
1681 return USER_TYPE_FULL_GUEST.equals(userType);
1682 }
1683
1684 /**
1685 * Returns whether the user type is a
1686 * {@link UserManager#USER_TYPE_FULL_RESTRICTED restricted user}.
1687 * @hide
1688 */
1689 public static boolean isUserTypeRestricted(String userType) {
1690 return USER_TYPE_FULL_RESTRICTED.equals(userType);
1691 }
1692
1693 /**
1694 * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_DEMO demo user}.
1695 * @hide
1696 */
1697 public static boolean isUserTypeDemo(String userType) {
1698 return USER_TYPE_FULL_DEMO.equals(userType);
1699 }
1700
1701 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001702 * @hide
1703 * @deprecated Use {@link #isRestrictedProfile()}
1704 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001705 @UnsupportedAppUsage
Fyodor Kupolovca177562017-11-09 17:43:01 -08001706 @Deprecated
1707 public boolean isLinkedUser() {
1708 return isRestrictedProfile();
1709 }
1710
1711 /**
Varun Shahe142e332018-10-22 15:52:56 -07001712 * Used to check if this process is running under a restricted profile. Restricted profiles
1713 * may have a reduced number of available apps, app restrictions, and account restrictions.
1714 *
1715 * @return whether this process is running under a restricted profile.
Amith Yamasani2555daf2013-04-25 13:39:27 -07001716 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001717 */
Fyodor Kupolovca177562017-11-09 17:43:01 -08001718 @SystemApi
Varun Shahe142e332018-10-22 15:52:56 -07001719 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolovca177562017-11-09 17:43:01 -08001720 public boolean isRestrictedProfile() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001721 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001722 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001723 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001724 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001725 }
1726 }
1727
Amith Yamasani258848d2012-08-10 17:06:33 -07001728 /**
Hai Zhang7c064ca2019-03-18 18:21:38 -07001729 * Check if a user is a restricted profile. Restricted profiles may have a reduced number of
1730 * available apps, app restrictions, and account restrictions.
1731 *
1732 * @param user the user to check
1733 * @return whether the user is a restricted profile.
1734 * @hide
1735 */
1736 @SystemApi
1737 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
1738 public boolean isRestrictedProfile(@NonNull UserHandle user) {
1739 try {
1740 return mService.getUserInfo(user.getIdentifier()).isRestricted();
1741 } catch (RemoteException re) {
1742 throw re.rethrowFromSystemServer();
1743 }
1744 }
1745
1746 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001747 * Checks if specified user can have restricted profile.
1748 * @hide
1749 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001750 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001751 try {
1752 return mService.canHaveRestrictedProfile(userId);
1753 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001754 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001755 }
1756 }
1757
1758 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001759 * Returns whether the calling user has at least one restricted profile associated with it.
1760 * @return
1761 * @hide
1762 */
1763 @SystemApi
1764 public boolean hasRestrictedProfiles() {
1765 try {
1766 return mService.hasRestrictedProfiles();
1767 } catch (RemoteException re) {
1768 throw re.rethrowFromSystemServer();
1769 }
1770 }
1771
1772 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001773 * Checks if a user is a guest user.
1774 * @return whether user is a guest user.
1775 * @hide
1776 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001777 @UnsupportedAppUsage
Bookatz07758e32019-11-19 17:16:08 -08001778 public boolean isGuestUser(@UserIdInt int userId) {
1779 UserInfo user = getUserInfo(userId);
Evan Rosky13a58a92016-07-27 15:51:09 -07001780 return user != null && user.isGuest();
1781 }
1782
1783 /**
Varun Shahe142e332018-10-22 15:52:56 -07001784 * Used to check if this process is running under a guest user. A guest user may be transient.
1785 *
1786 * @return whether this process is running under a guest user.
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001787 * @hide
1788 */
Varun Shahe142e332018-10-22 15:52:56 -07001789 @SystemApi
1790 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001791 public boolean isGuestUser() {
1792 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001793 return user != null && user.isGuest();
1794 }
1795
Fyodor Kupolovca177562017-11-09 17:43:01 -08001796
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001797 /**
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001798 * Checks if the calling app is running in a demo user. When running in a demo user,
1799 * apps can be more helpful to the user, or explain their features in more detail.
1800 *
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001801 * @return whether the caller is a demo user.
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001802 */
1803 public boolean isDemoUser() {
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001804 try {
1805 return mService.isDemoUser(UserHandle.myUserId());
1806 } catch (RemoteException re) {
1807 throw re.rethrowFromSystemServer();
1808 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001809 }
1810
1811 /**
Bookatz029832a2019-10-04 16:50:22 -07001812 * Checks if the calling app is running in a profile.
1813 *
1814 * @return whether the caller is in a profile.
1815 * @hide
1816 */
1817 public boolean isProfile() {
1818 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1819 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1820 if (mIsProfileCached != null) {
1821 return mIsProfileCached;
1822 }
1823 try {
1824 mIsProfileCached = mService.isProfile(UserHandle.myUserId());
1825 return mIsProfileCached;
1826 } catch (RemoteException re) {
1827 throw re.rethrowFromSystemServer();
1828 }
1829 }
1830
1831 /**
1832 * Checks if the specified user is a profile.
1833 *
1834 * Requires {@link android.Manifest.permission#MANAGE_USERS} or
1835 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller
1836 * must be in the same profile group of specified user.
1837 *
1838 * @return whether the specified user is a profile.
1839 * @hide
1840 */
1841 @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
1842 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
1843 public boolean isProfile(@UserIdInt int userId) {
1844 if (userId == UserHandle.myUserId()) {
1845 return isProfile();
1846 }
1847 try {
1848 return mService.isProfile(userId);
1849 } catch (RemoteException re) {
1850 throw re.rethrowFromSystemServer();
1851 }
1852 }
1853 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001854 * Checks if the calling app is running in a managed profile.
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001855 *
1856 * @return whether the caller is in a managed profile.
1857 * @hide
1858 */
1859 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001860 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001861 public boolean isManagedProfile() {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001862 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1863 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1864 if (mIsManagedProfileCached != null) {
1865 return mIsManagedProfileCached;
1866 }
Tony Mak8673b282016-03-21 21:10:59 +00001867 try {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001868 mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1869 return mIsManagedProfileCached;
Tony Mak8673b282016-03-21 21:10:59 +00001870 } catch (RemoteException re) {
1871 throw re.rethrowFromSystemServer();
1872 }
1873 }
1874
1875 /**
1876 * Checks if the specified user is a managed profile.
Bookatz029832a2019-10-04 16:50:22 -07001877 * Requires {@link android.Manifest.permission#MANAGE_USERS} or
1878 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller
Tony Mak8673b282016-03-21 21:10:59 +00001879 * must be in the same profile group of specified user.
1880 *
1881 * @return whether the specified user is a managed profile.
1882 * @hide
1883 */
1884 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001885 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Tony Mak8673b282016-03-21 21:10:59 +00001886 public boolean isManagedProfile(@UserIdInt int userId) {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001887 if (userId == UserHandle.myUserId()) {
1888 return isManagedProfile();
1889 }
Tony Mak8673b282016-03-21 21:10:59 +00001890 try {
1891 return mService.isManagedProfile(userId);
1892 } catch (RemoteException re) {
1893 throw re.rethrowFromSystemServer();
1894 }
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001895 }
1896
1897 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001898 * Checks if the calling app is running as an ephemeral user.
1899 *
1900 * @return whether the caller is an ephemeral user.
1901 * @hide
1902 */
1903 public boolean isEphemeralUser() {
1904 return isUserEphemeral(UserHandle.myUserId());
1905 }
1906
1907 /**
1908 * Returns whether the specified user is ephemeral.
1909 * @hide
1910 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001911 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001912 final UserInfo user = getUserInfo(userId);
1913 return user != null && user.isEphemeral();
1914 }
1915
1916 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001917 * Return whether the given user is actively running. This means that
1918 * the user is in the "started" state, not "stopped" -- it is currently
1919 * allowed to run code through scheduled alarms, receiving broadcasts,
1920 * etc. A started user may be either the current foreground user or a
1921 * background user; the result here does not distinguish between the two.
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001922 *
1923 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
Andrew Solovay8a788f42018-12-12 14:25:47 -08001924 * {@link android.os.Build.VERSION_CODES#N}, this API required a system permission
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001925 * in order to check other profile's status.
1926 * Since Android Nougat MR1 (SDK version >= 25;
Andrew Solovay8a788f42018-12-12 14:25:47 -08001927 * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now
1928 * it'll accept any {@link android.os.UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001929 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001930 * @param user The user to retrieve the running state for.
1931 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001932 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001933 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -07001934 return isUserRunning(user.getIdentifier());
1935 }
1936
1937 /** {@hide} */
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001938 public boolean isUserRunning(@UserIdInt int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001939 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001940 return mService.isUserRunning(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001941 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001942 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001943 }
1944 }
1945
1946 /**
1947 * Return whether the given user is actively running <em>or</em> stopping.
1948 * This is like {@link #isUserRunning(UserHandle)}, but will also return
1949 * true if the user had been running but is in the process of being stopped
1950 * (but is not yet fully stopped, and still running some code).
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001951 *
1952 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
Andrew Solovay8a788f42018-12-12 14:25:47 -08001953 * {@link android.os.Build.VERSION_CODES#N}, this API required a system permission
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001954 * in order to check other profile's status.
1955 * Since Android Nougat MR1 (SDK version >= 25;
Andrew Solovay8a788f42018-12-12 14:25:47 -08001956 * {@link android.os.Build.VERSION_CODES#N_MR1}), the restriction has been relaxed, and now
1957 * it'll accept any {@link android.os.UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001958 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001959 * @param user The user to retrieve the running state for.
1960 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001961 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001962 public boolean isUserRunningOrStopping(UserHandle user) {
1963 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001964 // TODO: reconcile stopped vs stopping?
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001965 return ActivityManager.getService().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001966 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001967 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001968 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001969 }
1970 }
1971
Jeff Sharkey0825ab22015-12-02 13:04:49 -07001972 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001973 * Return whether the calling user is running in an "unlocked" state.
1974 * <p>
1975 * On devices with direct boot, a user is unlocked only after they've
1976 * entered their credentials (such as a lock pattern or PIN). On devices
1977 * without direct boot, a user is unlocked as soon as it starts.
1978 * <p>
1979 * When a user is locked, only device-protected data storage is available.
1980 * When a user is unlocked, both device-protected and credential-protected
1981 * private app data storage is available.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001982 *
1983 * @see Intent#ACTION_USER_UNLOCKED
1984 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001985 */
1986 public boolean isUserUnlocked() {
1987 return isUserUnlocked(Process.myUserHandle());
1988 }
1989
1990 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001991 * Return whether the given user is running in an "unlocked" state.
1992 * <p>
1993 * On devices with direct boot, a user is unlocked only after they've
1994 * entered their credentials (such as a lock pattern or PIN). On devices
1995 * without direct boot, a user is unlocked as soon as it starts.
1996 * <p>
1997 * When a user is locked, only device-protected data storage is available.
1998 * When a user is unlocked, both device-protected and credential-protected
1999 * private app data storage is available.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08002000 * <p>Requires {@code android.permission.MANAGE_USERS} or
2001 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
2002 * must be the calling user or a managed profile associated with it.
Jeff Sharkeyb6423872015-12-11 11:11:58 -07002003 *
2004 * @param user to retrieve the unlocked state for.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06002005 * @see Intent#ACTION_USER_UNLOCKED
2006 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07002007 */
2008 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -07002009 return isUserUnlocked(user.getIdentifier());
2010 }
2011
2012 /** {@hide} */
Andrei Onea24ec3212019-03-15 17:35:05 +00002013 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002014 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06002015 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08002016 return mService.isUserUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06002017 } catch (RemoteException re) {
2018 throw re.rethrowFromSystemServer();
2019 }
2020 }
2021
Roshan Piusf6c8cd32019-10-17 13:03:18 -07002022 /**
2023 * Return whether the provided user is already running in an
2024 * "unlocked" state or in the process of unlocking.
2025 * <p>
2026 * On devices with direct boot, a user is unlocked only after they've
2027 * entered their credentials (such as a lock pattern or PIN). On devices
2028 * without direct boot, a user is unlocked as soon as it starts.
2029 * <p>
2030 * When a user is locked, only device-protected data storage is available.
2031 * When a user is unlocked, both device-protected and credential-protected
2032 * private app data storage is available.
2033 *
2034 * <p>Requires {@code android.permission.MANAGE_USERS} or
2035 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
2036 * must be the calling user or a profile associated with it.
2037 *
2038 * @hide
2039 */
2040 @SystemApi
2041 @RequiresPermission(anyOf = {
2042 Manifest.permission.MANAGE_USERS,
2043 Manifest.permission.INTERACT_ACROSS_USERS
2044 })
2045 public boolean isUserUnlockingOrUnlocked(@NonNull UserHandle user) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06002046 return isUserUnlockingOrUnlocked(user.getIdentifier());
2047 }
2048
2049 /** {@hide} */
2050 public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
2051 try {
Fyodor Kupolovc413f702016-10-06 17:11:14 -07002052 return mService.isUserUnlockingOrUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06002053 } catch (RemoteException re) {
2054 throw re.rethrowFromSystemServer();
2055 }
Jeff Sharkeyb6423872015-12-11 11:11:58 -07002056 }
2057
2058 /**
Makoto Onuki73dded22017-12-20 13:14:48 +09002059 * Return the time when the calling user started in elapsed milliseconds since boot,
2060 * or 0 if not started.
2061 *
2062 * @hide
2063 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002064 @UnsupportedAppUsage
Makoto Onuki73dded22017-12-20 13:14:48 +09002065 public long getUserStartRealtime() {
2066 try {
2067 return mService.getUserStartRealtime();
2068 } catch (RemoteException re) {
2069 throw re.rethrowFromSystemServer();
2070 }
2071 }
2072
2073 /**
2074 * Return the time when the calling user was unlocked elapsed milliseconds since boot,
2075 * or 0 if not unlocked.
2076 *
2077 * @hide
2078 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002079 @UnsupportedAppUsage
Makoto Onuki73dded22017-12-20 13:14:48 +09002080 public long getUserUnlockRealtime() {
2081 try {
2082 return mService.getUserUnlockRealtime();
2083 } catch (RemoteException re) {
2084 throw re.rethrowFromSystemServer();
2085 }
2086 }
2087
2088 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002089 * Returns the UserInfo object describing a specific user.
Tony Mak8673b282016-03-21 21:10:59 +00002090 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Bookatzf56f2582019-09-04 16:06:41 -07002091 * @param userId the user handle of the user whose information is being requested.
Amith Yamasani258848d2012-08-10 17:06:33 -07002092 * @return the UserInfo object for a specific user.
2093 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002094 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002095 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07002096 public UserInfo getUserInfo(@UserIdInt int userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002097 try {
Bookatzf56f2582019-09-04 16:06:41 -07002098 return mService.getUserInfo(userId);
Amith Yamasani258848d2012-08-10 17:06:33 -07002099 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002100 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002101 }
2102 }
2103
Amith Yamasani71e6c692013-03-24 17:39:28 -07002104 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01002105 * @hide
2106 *
2107 * Returns who set a user restriction on a user.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01002108 * @param restrictionKey the string key representing the restriction
2109 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2110 * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
2111 * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
2112 * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
Pavel Grafov6a40f092016-10-25 15:46:51 +01002113 * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01002114 */
Pavel Grafov6a40f092016-10-25 15:46:51 +01002115 @Deprecated
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01002116 @SystemApi
2117 @UserRestrictionSource
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002118 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Roshan Pius3eac0b92019-12-05 09:35:36 -08002119 public int getUserRestrictionSource(@UserRestrictionKey String restrictionKey,
2120 UserHandle userHandle) {
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01002121 try {
2122 return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
2123 } catch (RemoteException re) {
2124 throw re.rethrowFromSystemServer();
2125 }
2126 }
2127
2128 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +01002129 * @hide
2130 *
2131 * Returns a list of users who set a user restriction on a given user.
Pavel Grafov6a40f092016-10-25 15:46:51 +01002132 * @param restrictionKey the string key representing the restriction
2133 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2134 * @return a list of user ids enforcing this restriction.
2135 */
2136 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002137 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Pavel Grafov6a40f092016-10-25 15:46:51 +01002138 public List<EnforcingUser> getUserRestrictionSources(
Roshan Pius3eac0b92019-12-05 09:35:36 -08002139 @UserRestrictionKey String restrictionKey, UserHandle userHandle) {
Pavel Grafov6a40f092016-10-25 15:46:51 +01002140 try {
2141 return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
2142 } catch (RemoteException re) {
2143 throw re.rethrowFromSystemServer();
2144 }
2145 }
2146
2147 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07002148 * Returns the user-wide restrictions imposed on this user.
2149 * @return a Bundle containing all the restrictions.
2150 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002151 public Bundle getUserRestrictions() {
2152 return getUserRestrictions(Process.myUserHandle());
2153 }
2154
Amith Yamasani71e6c692013-03-24 17:39:28 -07002155 /**
2156 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
2157 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2158 * @return a Bundle containing all the restrictions.
Roshan Pius7969c802019-10-21 19:58:57 -07002159 *
2160 * <p>Requires {@code android.permission.MANAGE_USERS} or
2161 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
2162 * must be the calling user or a managed profile associated with it.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002163 */
Roshan Pius7969c802019-10-21 19:58:57 -07002164 @RequiresPermission(anyOf = {
2165 android.Manifest.permission.MANAGE_USERS,
2166 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002167 public Bundle getUserRestrictions(UserHandle userHandle) {
2168 try {
2169 return mService.getUserRestrictions(userHandle.getIdentifier());
2170 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002171 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002172 }
2173 }
2174
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00002175 /**
2176 * @hide
2177 * Returns whether the given user has been disallowed from performing certain actions
Irina Dumitrescu4638edd2018-09-05 14:08:33 +01002178 * or setting certain settings through UserManager (e.g. this type of restriction would prevent
2179 * the guest user from doing certain things, such as making calls). This method disregards
2180 * restrictions set by device policy.
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00002181 * @param restrictionKey the string key representing the restriction
2182 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2183 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002184 @UnsupportedAppUsage
Roshan Pius3eac0b92019-12-05 09:35:36 -08002185 public boolean hasBaseUserRestriction(@UserRestrictionKey String restrictionKey,
2186 UserHandle userHandle) {
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00002187 try {
2188 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
2189 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002190 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00002191 }
2192 }
2193
Amith Yamasani71e6c692013-03-24 17:39:28 -07002194 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07002195 * This will no longer work. Device owners and profile owners should use
2196 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002197 */
Makoto Onukia3c12502015-10-28 10:18:32 -07002198 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002199 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002200 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07002201 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002202 }
2203
Amith Yamasani71e6c692013-03-24 17:39:28 -07002204 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07002205 * This will no longer work. Device owners and profile owners should use
2206 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002207 */
Makoto Onukia3c12502015-10-28 10:18:32 -07002208 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002209 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002210 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07002211 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08002212 }
2213
Amith Yamasani71e6c692013-03-24 17:39:28 -07002214 /**
2215 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07002216 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002217 * @param key the key of the restriction
2218 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002219 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
2220 * android.content.ComponentName, String)} or
2221 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
2222 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002223 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002224 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07002225 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07002226 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002227 }
2228
2229 /**
2230 * @hide
2231 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07002232 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002233 * @param key the key of the restriction
2234 * @param value the value for the restriction
2235 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002236 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
2237 * android.content.ComponentName, String)} or
2238 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
2239 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002240 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04002241 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05002242 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07002243 try {
2244 mService.setUserRestriction(key, value, userHandle.getIdentifier());
2245 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002246 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07002247 }
Maggie Benthall67944582013-02-22 14:58:27 -05002248 }
2249
Amith Yamasani258848d2012-08-10 17:06:33 -07002250 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002251 * Returns whether the current user has been disallowed from performing certain actions
2252 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04002253 *
2254 * @param restrictionKey The string key representing the restriction.
2255 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002256 */
Roshan Pius3eac0b92019-12-05 09:35:36 -08002257 public boolean hasUserRestriction(@UserRestrictionKey String restrictionKey) {
Roshan Pius7969c802019-10-21 19:58:57 -07002258 return hasUserRestrictionForUser(restrictionKey, Process.myUserHandle());
David Christieb12ba932013-09-03 17:15:28 -07002259 }
2260
2261 /**
2262 * @hide
2263 * Returns whether the given user has been disallowed from performing certain actions
2264 * or setting certain settings.
2265 * @param restrictionKey the string key representing the restriction
2266 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2267 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002268 @UnsupportedAppUsage
Roshan Pius3eac0b92019-12-05 09:35:36 -08002269 public boolean hasUserRestriction(@UserRestrictionKey String restrictionKey,
2270 UserHandle userHandle) {
Roshan Pius7969c802019-10-21 19:58:57 -07002271 return hasUserRestrictionForUser(restrictionKey, userHandle);
2272 }
2273
2274 /**
2275 * Returns whether the given user has been disallowed from performing certain actions
2276 * or setting certain settings.
2277 * @param restrictionKey the string key representing the restriction
2278 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
2279 *
2280 * <p>Requires {@code android.permission.MANAGE_USERS} or
2281 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
2282 * must be the calling user or a managed profile associated with it.
2283 *
2284 * @hide
2285 */
2286 @SystemApi
2287 @RequiresPermission(anyOf = {
2288 android.Manifest.permission.MANAGE_USERS,
2289 android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
Roshan Pius3eac0b92019-12-05 09:35:36 -08002290 public boolean hasUserRestrictionForUser(@NonNull @UserRestrictionKey String restrictionKey,
Roshan Pius7969c802019-10-21 19:58:57 -07002291 @NonNull UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07002292 try {
Roshan Pius7969c802019-10-21 19:58:57 -07002293 return mService.hasUserRestriction(restrictionKey, userHandle.getIdentifier());
Amith Yamasani8cd28b52014-06-08 17:54:27 -07002294 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002295 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07002296 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002297 }
2298
2299 /**
Makoto Onukiacc50462018-02-14 14:13:49 -08002300 * @hide
2301 * Returns whether any user on the device has the given user restriction set.
2302 */
Roshan Pius3eac0b92019-12-05 09:35:36 -08002303 public boolean hasUserRestrictionOnAnyUser(@UserRestrictionKey String restrictionKey) {
Makoto Onukiacc50462018-02-14 14:13:49 -08002304 try {
2305 return mService.hasUserRestrictionOnAnyUser(restrictionKey);
2306 } catch (RemoteException re) {
2307 throw re.rethrowFromSystemServer();
2308 }
2309 }
2310
2311 /**
Christopher Tate65fb2e42019-10-11 17:00:23 -07002312 * @hide
2313 *
2314 * Checks whether changing the given setting to the given value is prohibited
2315 * by the corresponding user restriction in the given user.
2316 *
2317 * May only be called by the OS itself.
2318 *
2319 * @return {@code true} if the change is prohibited, {@code false} if the change is allowed.
2320 */
2321 public boolean isSettingRestrictedForUser(String setting, @UserIdInt int userId,
2322 String value, int callingUid) {
2323 try {
2324 return mService.isSettingRestrictedForUser(setting, userId, value, callingUid);
2325 } catch (RemoteException re) {
2326 throw re.rethrowFromSystemServer();
2327 }
2328 }
2329
2330 /**
2331 * @hide
2332 * Register a binder callback for user restrictions changes.
2333 * May only be called by the OS itself.
2334 */
2335 public void addUserRestrictionsListener(final IUserRestrictionsListener listener) {
2336 try {
2337 mService.addUserRestrictionsListener(listener);
2338 } catch (RemoteException re) {
2339 throw re.rethrowFromSystemServer();
2340 }
2341 }
2342
2343 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07002344 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002345 * number assigned to that user; if the user is deleted and then a new
2346 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07002347 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002348 * @return The serial number of the given user; returns -1 if the
2349 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07002350 * @see #getUserForSerialNumber(long)
2351 */
2352 public long getSerialNumberForUser(UserHandle user) {
2353 return getUserSerialNumber(user.getIdentifier());
2354 }
2355
2356 /**
2357 * Return the user associated with a serial number previously
2358 * returned by {@link #getSerialNumberForUser(UserHandle)}.
2359 * @param serialNumber The serial number of the user that is being
2360 * retrieved.
2361 * @return Return the user associated with the serial number, or null
2362 * if there is not one.
2363 * @see #getSerialNumberForUser(UserHandle)
2364 */
2365 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07002366 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07002367 return ident >= 0 ? new UserHandle(ident) : null;
2368 }
2369
2370 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07002371 * Creates a user with the specified name and options. For non-admin users, default user
Bookatz029832a2019-10-04 16:50:22 -07002372 * restrictions are going to be applied.
2373 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2374 *
2375 * @param name the user's name
2376 * @param flags UserInfo flags that identify the type of user and other properties.
2377 * @see UserInfo
2378 *
2379 * @return the UserInfo object for the created user, or null if the user could not be created.
2380 * @throws IllegalArgumentException if flags do not correspond to a valid user type.
2381 * @deprecated Use {@link #createUser(String, String, int)} instead.
2382 * @hide
2383 */
2384 @UnsupportedAppUsage
2385 @Deprecated
2386 public @Nullable UserInfo createUser(@Nullable String name, @UserInfoFlag int flags) {
2387 return createUser(name, UserInfo.getDefaultUserType(flags), flags);
2388 }
2389
2390 /**
2391 * Creates a user with the specified name and options. For non-admin users, default user
Felipe Lemec1ca4412019-09-11 09:23:26 -07002392 * restrictions will be applied.
2393 *
2394 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002395 *
2396 * @param name the user's name
Bookatz029832a2019-10-04 16:50:22 -07002397 * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_GUEST}.
2398 * @param flags UserInfo flags that specify user properties.
Amith Yamasani258848d2012-08-10 17:06:33 -07002399 * @see UserInfo
2400 *
Felipe Lemec1ca4412019-09-11 09:23:26 -07002401 * @return the UserInfo object for the created user, or {@code null} if the user could not be
2402 * created.
Amith Yamasani258848d2012-08-10 17:06:33 -07002403 * @hide
2404 */
Bookatz029832a2019-10-04 16:50:22 -07002405 public @Nullable UserInfo createUser(@Nullable String name, @NonNull String userType,
2406 @UserInfoFlag int flags) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002407 try {
Bookatzd15b2f72019-11-26 16:58:57 -08002408 return mService.createUser(name, userType, flags);
Amith Yamasani258848d2012-08-10 17:06:33 -07002409 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002410 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002411 }
2412 }
2413
2414 /**
Bookatz029832a2019-10-04 16:50:22 -07002415 * Pre-creates a user of the specified type. For non-admin users, default user
Felipe Lemec1ca4412019-09-11 09:23:26 -07002416 * restrictions will be applied.
2417 *
2418 * <p>This method can be used by OEMs to "warm" up the user creation by pre-creating some users
2419 * at the first boot, so they when the "real" user is created (for example,
Bookatz029832a2019-10-04 16:50:22 -07002420 * by {@link #createUser(String, String, int)} or {@link #createGuest(Context, String)}), it
2421 * takes less time.
Felipe Lemec1ca4412019-09-11 09:23:26 -07002422 *
2423 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2424 *
Bookatz029832a2019-10-04 16:50:22 -07002425 * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_GUEST}.
Felipe Lemec1ca4412019-09-11 09:23:26 -07002426 * @return the UserInfo object for the created user, or {@code null} if the user could not be
2427 * created.
2428 *
2429 * @throw {@link IllegalArgumentException} if {@code flags} contains
2430 * {@link UserInfo#FLAG_MANAGED_PROFILE}.
2431 *
2432 * @hide
2433 */
Bookatz029832a2019-10-04 16:50:22 -07002434 public @Nullable UserInfo preCreateUser(@NonNull String userType) {
Felipe Lemec1ca4412019-09-11 09:23:26 -07002435 try {
Bookatz029832a2019-10-04 16:50:22 -07002436 return mService.preCreateUser(userType);
Felipe Lemec1ca4412019-09-11 09:23:26 -07002437 } catch (RemoteException re) {
2438 throw re.rethrowFromSystemServer();
2439 }
2440 }
2441
2442 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07002443 * Creates a guest user and configures it.
2444 * @param context an application context
2445 * @param name the name to set for the user
2446 * @hide
2447 */
2448 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07002449 UserInfo guest = null;
2450 try {
Bookatz029832a2019-10-04 16:50:22 -07002451 guest = mService.createUser(name, USER_TYPE_FULL_GUEST, 0);
Makoto Onuki068c54a2015-10-13 14:34:03 -07002452 if (guest != null) {
2453 Settings.Secure.putStringForUser(context.getContentResolver(),
2454 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002455 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07002456 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002457 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07002458 }
2459 return guest;
2460 }
2461
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07002462 /**
Anthony Hugh5d7f9052019-11-13 16:48:28 -08002463 * Gets the existing guest user if it exists. This does not include guest users that are dying.
2464 * @return The existing guest user if it exists. Null otherwise.
2465 * @hide
2466 */
2467 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
2468 public UserInfo findCurrentGuestUser() {
2469 try {
2470 return mService.findCurrentGuestUser();
2471 } catch (RemoteException re) {
2472 throw re.rethrowFromSystemServer();
2473 }
2474 }
2475
2476 /**
Kenny Guy2a764942014-04-02 13:29:20 +01002477 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00002478 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Bookatz029832a2019-10-04 16:50:22 -07002479 * The type of profile must be specified using the given flags.
Kenny Guya52dc3e2014-02-11 15:33:14 +00002480 *
2481 * @param name the user's name
2482 * @param flags flags that identify the type of user and other properties.
Bookatzf56f2582019-09-04 16:06:41 -07002483 * @param userId new user will be a profile of this user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00002484 *
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07002485 * @return the {@link UserInfo} object for the created user, or null if the user
2486 * could not be created.
Bookatz029832a2019-10-04 16:50:22 -07002487 * @throws IllegalArgumentException if flags do not correspond to a valid user type.
2488 * @deprecated Use {@link #createProfileForUser(String, String, int, int)} instead.
Kenny Guya52dc3e2014-02-11 15:33:14 +00002489 * @hide
2490 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002491 @UnsupportedAppUsage
Bookatz029832a2019-10-04 16:50:22 -07002492 @Deprecated
2493 public UserInfo createProfileForUser(String name, @UserInfoFlag int flags,
2494 @UserIdInt int userId) {
2495 return createProfileForUser(name, UserInfo.getDefaultUserType(flags), flags,
2496 userId, null);
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07002497 }
2498
2499 /**
Bookatz029832a2019-10-04 16:50:22 -07002500 * Creates a user with the specified name and options as a profile of another user.
2501 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2502 *
2503 * @param name the user's name
2504 * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
2505 * @param flags UserInfo flags that specify user properties.
2506 * @param userId new user will be a profile of this user.
2507 *
2508 * @return the {@link UserInfo} object for the created user, or null if the user
2509 * could not be created.
2510 * @hide
2511 */
2512 public UserInfo createProfileForUser(String name, @NonNull String userType,
2513 @UserInfoFlag int flags, @UserIdInt int userId) {
2514 return createProfileForUser(name, userType, flags, userId, null);
2515 }
2516
2517 /**
2518 * Version of {@link #createProfileForUser(String, String, int, int)} that allows you to specify
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07002519 * any packages that should not be installed in the new profile by default, these packages can
2520 * still be installed later by the user if needed.
2521 *
2522 * @param name the user's name
Bookatz029832a2019-10-04 16:50:22 -07002523 * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
2524 * @param flags UserInfo flags that specify user properties.
Bookatzf56f2582019-09-04 16:06:41 -07002525 * @param userId new user will be a profile of this user.
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07002526 * @param disallowedPackages packages that will not be installed in the profile being created.
2527 *
2528 * @return the {@link UserInfo} object for the created user, or null if the user
2529 * could not be created.
2530 * @hide
2531 */
Bookatz029832a2019-10-04 16:50:22 -07002532 public UserInfo createProfileForUser(String name, @NonNull String userType,
2533 @UserInfoFlag int flags, @UserIdInt int userId, String[] disallowedPackages) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00002534 try {
Bookatz029832a2019-10-04 16:50:22 -07002535 return mService.createProfileForUser(name, userType, flags, userId, disallowedPackages);
Kenny Guya52dc3e2014-02-11 15:33:14 +00002536 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002537 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00002538 }
2539 }
2540
2541 /**
Bookatz029832a2019-10-04 16:50:22 -07002542 * Similar to {@link #createProfileForUser(String, String, int, int, String[])}
Esteban Talavera6c9116a2016-11-24 16:12:44 +00002543 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
Tony Mak6dc428f2016-10-10 15:48:27 +01002544 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2545 *
Bookatz029832a2019-10-04 16:50:22 -07002546 * @see #createProfileForUser(String, String, int, int, String[])
Tony Mak6dc428f2016-10-10 15:48:27 +01002547 * @hide
2548 */
Bookatz029832a2019-10-04 16:50:22 -07002549 public UserInfo createProfileForUserEvenWhenDisallowed(String name,
2550 @NonNull String userType, @UserInfoFlag int flags, @UserIdInt int userId,
2551 String[] disallowedPackages) {
Tony Mak6dc428f2016-10-10 15:48:27 +01002552 try {
Bookatz029832a2019-10-04 16:50:22 -07002553 return mService.createProfileForUserEvenWhenDisallowed(name, userType, flags,
2554 userId, disallowedPackages);
Tony Mak6dc428f2016-10-10 15:48:27 +01002555 } catch (RemoteException re) {
2556 throw re.rethrowFromSystemServer();
2557 }
2558 }
2559
2560 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07002561 * Creates a restricted profile with the specified name. This method also sets necessary
2562 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07002563 *
2564 * @param name profile's name
2565 * @return UserInfo object for the created user, or null if the user could not be created.
2566 * @hide
2567 */
2568 public UserInfo createRestrictedProfile(String name) {
2569 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07002570 UserHandle parentUserHandle = Process.myUserHandle();
2571 UserInfo user = mService.createRestrictedProfile(name,
2572 parentUserHandle.getIdentifier());
2573 if (user != null) {
2574 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
2575 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07002576 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07002577 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002578 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002579 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07002580 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07002581 }
2582
2583 /**
Amith Yamasani06964342016-04-15 13:55:01 -07002584 * Returns an intent to create a user for the provided name and account name. The name
2585 * and account name will be used when the setup process for the new user is started.
2586 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08002587 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08002588 * indicate if the user consented to adding a new user and if the operation succeeded. Any
2589 * errors in creating the user will be returned in the result code. If the user cancels the
2590 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
2591 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani06964342016-04-15 13:55:01 -07002592 * <p>
2593 * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
2594 * at all.
2595 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08002596 * The new user is created but not initialized. After switching into the user for the first
2597 * time, the preferred user name and account information are used by the setup process for that
2598 * user.
2599 *
2600 * @param userName Optional name to assign to the user.
Amith Yamasani06964342016-04-15 13:55:01 -07002601 * @param accountName Optional account name that will be used by the setup wizard to initialize
Amith Yamasani12747872015-12-07 14:19:49 -08002602 * the user.
2603 * @param accountType Optional account type for the account to be created. This is required
2604 * if the account name is specified.
2605 * @param accountOptions Optional bundle of data to be passed in during account creation in the
2606 * new user via {@link AccountManager#addAccount(String, String, String[],
2607 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
2608 * Handler)}.
Amith Yamasani06964342016-04-15 13:55:01 -07002609 * @return An Intent that can be launched from an Activity.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08002610 * @see #USER_CREATION_FAILED_NOT_PERMITTED
2611 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani06964342016-04-15 13:55:01 -07002612 * @see #supportsMultipleUsers
Amith Yamasani12747872015-12-07 14:19:49 -08002613 */
2614 public static Intent createUserCreationIntent(@Nullable String userName,
2615 @Nullable String accountName,
2616 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
Amith Yamasani12747872015-12-07 14:19:49 -08002617 Intent intent = new Intent(ACTION_CREATE_USER);
2618 if (userName != null) {
2619 intent.putExtra(EXTRA_USER_NAME, userName);
2620 }
2621 if (accountName != null && accountType == null) {
2622 throw new IllegalArgumentException("accountType must be specified if accountName is "
2623 + "specified");
2624 }
2625 if (accountName != null) {
2626 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
2627 }
2628 if (accountType != null) {
2629 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
2630 }
2631 if (accountOptions != null) {
2632 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
2633 }
2634 return intent;
2635 }
2636
2637 /**
2638 * @hide
2639 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002640 * Returns the preferred account name for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002641 */
2642 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002643 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002644 public String getSeedAccountName() {
2645 try {
2646 return mService.getSeedAccountName();
2647 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002648 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002649 }
2650 }
2651
2652 /**
2653 * @hide
2654 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002655 * Returns the preferred account type for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002656 */
2657 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002658 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002659 public String getSeedAccountType() {
2660 try {
2661 return mService.getSeedAccountType();
2662 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002663 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002664 }
2665 }
2666
2667 /**
2668 * @hide
2669 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002670 * Returns the preferred account's options bundle for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002671 * @return Any options set by the requestor that created the user.
2672 */
2673 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002674 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002675 public PersistableBundle getSeedAccountOptions() {
2676 try {
2677 return mService.getSeedAccountOptions();
2678 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002679 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002680 }
2681 }
2682
2683 /**
2684 * @hide
2685 *
2686 * Called by a system activity to set the seed account information of a user created
2687 * through the user creation intent.
2688 * @param userId
2689 * @param accountName
2690 * @param accountType
2691 * @param accountOptions
2692 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
2693 */
2694 public void setSeedAccountData(int userId, String accountName, String accountType,
2695 PersistableBundle accountOptions) {
2696 try {
2697 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
2698 /* persist= */ true);
2699 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002700 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002701 }
2702 }
2703
2704 /**
2705 * @hide
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002706 * Clears the seed information used to create this user.
Amith Yamasani12747872015-12-07 14:19:49 -08002707 */
2708 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002709 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002710 public void clearSeedAccountData() {
2711 try {
2712 mService.clearSeedAccountData();
2713 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002714 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002715 }
2716 }
2717
2718 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07002719 * @hide
2720 * Marks the guest user for deletion to allow a new guest to be created before deleting
2721 * the current user who is a guest.
Bookatzf56f2582019-09-04 16:06:41 -07002722 * @param userId
Amith Yamasani1df14732014-08-29 21:37:27 -07002723 * @return
2724 */
Bookatzf56f2582019-09-04 16:06:41 -07002725 public boolean markGuestForDeletion(@UserIdInt int userId) {
Amith Yamasani1df14732014-08-29 21:37:27 -07002726 try {
Bookatzf56f2582019-09-04 16:06:41 -07002727 return mService.markGuestForDeletion(userId);
Amith Yamasani1df14732014-08-29 21:37:27 -07002728 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002729 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07002730 }
2731 }
2732
2733 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002734 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01002735 *
2736 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2737 *
2738 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
2739 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
2740 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002741 *
jovanakf24ad492018-05-18 12:15:59 -07002742 * @param userId the id of the profile to enable
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002743 * @hide
2744 */
jovanakf24ad492018-05-18 12:15:59 -07002745 public void setUserEnabled(@UserIdInt int userId) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002746 try {
jovanakf24ad492018-05-18 12:15:59 -07002747 mService.setUserEnabled(userId);
2748 } catch (RemoteException re) {
2749 throw re.rethrowFromSystemServer();
2750 }
2751 }
2752
2753 /**
2754 * Assigns admin privileges to the user, if such a user exists.
2755 *
Bookatzd15b2f72019-11-26 16:58:57 -08002756 * <p>Note that this does not alter the user's pre-existing user restrictions.
jovanakf24ad492018-05-18 12:15:59 -07002757 *
Bookatzf56f2582019-09-04 16:06:41 -07002758 * @param userId the id of the user to become admin
jovanakf24ad492018-05-18 12:15:59 -07002759 * @hide
2760 */
2761 @RequiresPermission(allOf = {
2762 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2763 Manifest.permission.MANAGE_USERS
2764 })
Bookatzf56f2582019-09-04 16:06:41 -07002765 public void setUserAdmin(@UserIdInt int userId) {
jovanakf24ad492018-05-18 12:15:59 -07002766 try {
Bookatzf56f2582019-09-04 16:06:41 -07002767 mService.setUserAdmin(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002768 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002769 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002770 }
2771 }
2772
2773 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002774 * Evicts the user's credential encryption key from memory by stopping and restarting the user.
2775 *
2776 * @hide
2777 */
Bookatzf56f2582019-09-04 16:06:41 -07002778 public void evictCredentialEncryptionKey(@UserIdInt int userId) {
Andrew Scull85a63bc2016-10-24 13:47:47 +01002779 try {
Bookatzf56f2582019-09-04 16:06:41 -07002780 mService.evictCredentialEncryptionKey(userId);
Andrew Scull85a63bc2016-10-24 13:47:47 +01002781 } catch (RemoteException re) {
2782 throw re.rethrowFromSystemServer();
2783 }
2784 }
2785
2786 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002787 * Return the number of users currently created on the device.
Kevin Hufnagle5813a8c2019-09-30 16:25:02 +00002788 * <p>This API is not for use by third-party apps. It requires the {@code MANAGE_USERS}
2789 * permission.</p>
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002790 */
2791 public int getUserCount() {
2792 List<UserInfo> users = getUsers();
2793 return users != null ? users.size() : 1;
2794 }
2795
2796 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07002797 * Returns information for all users on this device, including ones marked for deletion.
2798 * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002799 *
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002800 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07002801 * @hide
2802 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002803 @UnsupportedAppUsage
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002804 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani258848d2012-08-10 17:06:33 -07002805 public List<UserInfo> getUsers() {
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002806 return getUsers(/* excludeDying= */ false);
2807 }
2808
2809 /**
Jeffrey Huang91027f82019-11-26 10:34:28 -08002810 * Returns information for all users on this device. Requires
2811 * {@link android.Manifest.permission#MANAGE_USERS} permission.
2812 *
2813 * @param excludeDying specify if the list should exclude users being
2814 * removed.
2815 * @return the list of users that were created.
2816 * @hide
2817 */
2818 @UnsupportedAppUsage
2819 public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
2820 return getUsers(/*excludePartial= */ true, excludeDying,
2821 /* excludePreCreated= */ true);
2822 }
2823
2824 /**
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002825 * Returns information for all users on this device, based on the filtering parameters.
2826 *
2827 * @hide
2828 */
2829 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
2830 public List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
2831 boolean excludePreCreated) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002832 try {
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002833 return mService.getUsers(excludePartial, excludeDying, excludePreCreated);
Amith Yamasani920ace02012-09-20 22:15:37 -07002834 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002835 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07002836 }
2837 }
2838
2839 /**
Jeffrey Huang91027f82019-11-26 10:34:28 -08002840 * Returns the user handles for all users on this device, based on the filtering parameters.
2841 *
2842 * @param excludeDying specify if the list should exclude users being removed.
2843 * @return the list of user handles.
2844 * @hide
2845 */
2846 @SystemApi
2847 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
2848 public @NonNull List<UserHandle> getUserHandles(boolean excludeDying) {
2849 List<UserInfo> users = getUsers(excludeDying);
2850 List<UserHandle> result = new ArrayList<>(users.size());
2851 for (UserInfo user : users) {
2852 result.add(user.getUserHandle());
2853 }
2854 return result;
2855 }
2856
2857 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002858 * Returns serial numbers of all users on this device.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002859 *
2860 * @param excludeDying specify if the list should exclude users being removed.
2861 * @return the list of serial numbers of users that exist on the device.
2862 * @hide
2863 */
2864 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002865 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002866 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002867 List<UserInfo> users = getUsers(excludeDying);
2868 long[] result = new long[users.size()];
2869 for (int i = 0; i < result.length; i++) {
2870 result[i] = users.get(i).serialNumber;
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002871 }
Felipe Leme09a7f2d2019-10-02 16:27:46 -07002872 return result;
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002873 }
2874
2875 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002876 * @return the user's account name, null if not found.
2877 * @hide
2878 */
2879 @RequiresPermission( allOf = {
2880 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2881 Manifest.permission.MANAGE_USERS
2882 })
Bookatzf56f2582019-09-04 16:06:41 -07002883 public @Nullable String getUserAccount(@UserIdInt int userId) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002884 try {
Bookatzf56f2582019-09-04 16:06:41 -07002885 return mService.getUserAccount(userId);
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002886 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002887 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002888 }
2889 }
2890
2891 /**
2892 * Set account name for the given user.
2893 * @hide
2894 */
2895 @RequiresPermission( allOf = {
2896 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2897 Manifest.permission.MANAGE_USERS
2898 })
Bookatzf56f2582019-09-04 16:06:41 -07002899 public void setUserAccount(@UserIdInt int userId, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002900 try {
Bookatzf56f2582019-09-04 16:06:41 -07002901 mService.setUserAccount(userId, accountName);
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002902 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002903 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002904 }
2905 }
2906
2907 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002908 * Returns information for Primary user.
2909 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2910 *
2911 * @return the Primary user, null if not found.
2912 * @hide
2913 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002914 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002915 try {
2916 return mService.getPrimaryUser();
2917 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002918 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002919 }
2920 }
2921
2922 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07002923 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
2924 * permission.
2925 *
2926 * @return true if more users can be added, false if limit has been reached.
2927 * @hide
2928 */
2929 public boolean canAddMoreUsers() {
Bookatz029832a2019-10-04 16:50:22 -07002930 // TODO(b/142482943): UMS has different logic, excluding Demo and Profile from counting. Why
2931 // not here? The logic is inconsistent. See UMS.canAddMoreManagedProfiles
Amith Yamasani95ab7842014-08-11 17:09:26 -07002932 final List<UserInfo> users = getUsers(true);
2933 final int totalUserCount = users.size();
2934 int aliveUserCount = 0;
2935 for (int i = 0; i < totalUserCount; i++) {
2936 UserInfo user = users.get(i);
2937 if (!user.isGuest()) {
2938 aliveUserCount++;
2939 }
2940 }
2941 return aliveUserCount < getMaxSupportedUsers();
2942 }
2943
2944 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07002945 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
2946 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002947 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
2948 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07002949 *
2950 * @return true if more managed profiles can be added, false if limit has been reached.
2951 * @hide
2952 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002953 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07002954 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002955 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07002956 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002957 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07002958 }
2959 }
2960
2961 /**
Bookatz029832a2019-10-04 16:50:22 -07002962 * Checks whether it's possible to add more profiles of the given type to the given user.
2963 *
2964 * @param userType the type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}.
2965 * @return true if more profiles can be added, false if limit has been reached.
2966 * @hide
2967 */
2968 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
2969 public boolean canAddMoreProfilesToUser(@NonNull String userType, @UserIdInt int userId) {
2970 try {
2971 return mService.canAddMoreProfilesToUser(userType, userId, false);
2972 } catch (RemoteException re) {
2973 throw re.rethrowFromSystemServer();
2974 }
2975 }
2976
2977 /**
Bookatzf56f2582019-09-04 16:06:41 -07002978 * Returns list of the profiles of userId including userId itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07002979 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07002980 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08002981 *
Kenny Guy2a764942014-04-02 13:29:20 +01002982 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Bookatzf56f2582019-09-04 16:06:41 -07002983 * @param userId profiles of this user will be returned.
Kenny Guy2a764942014-04-02 13:29:20 +01002984 * @return the list of profiles.
2985 * @hide
2986 */
Andrei Onea24ec3212019-03-15 17:35:05 +00002987 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07002988 public List<UserInfo> getProfiles(@UserIdInt int userId) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00002989 try {
Bookatzf56f2582019-09-04 16:06:41 -07002990 return mService.getProfiles(userId, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00002991 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002992 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00002993 }
2994 }
2995
2996 /**
Roshan Piusf6c8cd32019-10-17 13:03:18 -07002997 * Checks if the 2 provided user handles belong to the same profile group.
2998 *
2999 * @param user one of the two user handles to check.
3000 * @param otherUser one of the two user handles to check.
3001 * @return true if the two users are in the same profile group.
3002 *
3003 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
3004 * @hide
3005 */
3006 @SystemApi
3007 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
3008 public boolean isSameProfileGroup(@NonNull UserHandle user, @NonNull UserHandle otherUser) {
3009 return isSameProfileGroup(user.getIdentifier(), otherUser.getIdentifier());
3010 }
3011
3012 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07003013 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
3014 * @param userId one of the two user ids to check.
3015 * @param otherUserId one of the two user ids to check.
3016 * @return true if the two user ids are in the same profile group.
3017 * @hide
3018 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07003019 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07003020 try {
3021 return mService.isSameProfileGroup(userId, otherUserId);
3022 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003023 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07003024 }
3025 }
3026
3027 /**
Bookatzf56f2582019-09-04 16:06:41 -07003028 * Returns list of the profiles of userId including userId itself.
Ruben Brunk7f75da22015-04-30 17:46:30 -07003029 * Note that this returns only enabled.
3030 *
3031 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Bookatzf56f2582019-09-04 16:06:41 -07003032 * @param userId profiles of this user will be returned.
Ruben Brunk7f75da22015-04-30 17:46:30 -07003033 * @return the list of profiles.
3034 * @hide
3035 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003036 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07003037 public List<UserInfo> getEnabledProfiles(@UserIdInt int userId) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07003038 try {
Bookatzf56f2582019-09-04 16:06:41 -07003039 return mService.getProfiles(userId, true /* enabledOnly */);
Ruben Brunk7f75da22015-04-30 17:46:30 -07003040 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003041 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07003042 }
3043 }
3044
3045 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01003046 * Returns a list of UserHandles for profiles associated with the user that the calling process
3047 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08003048 *
3049 * @return A non-empty list of UserHandles associated with the calling user.
3050 */
3051 public List<UserHandle> getUserProfiles() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07003052 int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
3053 List<UserHandle> result = new ArrayList<>(userIds.length);
3054 for (int userId : userIds) {
3055 result.add(UserHandle.of(userId));
3056 }
3057 return result;
3058 }
3059
3060 /**
3061 * Returns a list of ids for profiles associated with the specified user including the user
3062 * itself.
3063 *
3064 * @param userId id of the user to return profiles for
3065 * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
3066 * @return A non-empty list of ids of profiles associated with the specified user.
3067 *
3068 * @hide
3069 */
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07003070 @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS,
3071 Manifest.permission.CREATE_USERS}, conditional = true)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07003072 public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01003073 try {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07003074 return mService.getProfileIds(userId, enabledOnly);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01003075 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003076 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01003077 }
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07003078 }
3079
3080 /**
3081 * @see #getProfileIds(int, boolean)
3082 * @hide
3083 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003084 @UnsupportedAppUsage
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07003085 public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
3086 return getProfileIds(userId, false /* enabledOnly */);
3087 }
3088
3089 /**
3090 * @see #getProfileIds(int, boolean)
3091 * @hide
3092 */
3093 public int[] getEnabledProfileIds(@UserIdInt int userId) {
3094 return getProfileIds(userId, true /* enabledOnly */);
Amith Yamasani4f582632014-02-19 14:31:52 -08003095 }
3096
Amith Yamasani7dda2652014-04-11 14:57:12 -07003097 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07003098 * Returns the device credential owner id of the profile from
Bookatzf56f2582019-09-04 16:06:41 -07003099 * which this method is called, or userId if called from a user that
Andres Moralesc5548c02015-08-05 10:23:12 -07003100 * is not a profile.
3101 *
3102 * @hide
3103 */
Bookatzf56f2582019-09-04 16:06:41 -07003104 public int getCredentialOwnerProfile(@UserIdInt int userId) {
Andres Moralesc5548c02015-08-05 10:23:12 -07003105 try {
Bookatzf56f2582019-09-04 16:06:41 -07003106 return mService.getCredentialOwnerProfile(userId);
Andres Moralesc5548c02015-08-05 10:23:12 -07003107 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003108 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07003109 }
3110 }
3111
3112 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01003113 * Returns the parent of the profile which this method is called from
3114 * or null if called from a user that is not a profile.
3115 *
3116 * @hide
3117 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003118 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07003119 public UserInfo getProfileParent(@UserIdInt int userId) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01003120 try {
Bookatzf56f2582019-09-04 16:06:41 -07003121 return mService.getProfileParent(userId);
Jessica Hummelbe81c802014-04-22 15:49:22 +01003122 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003123 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01003124 }
3125 }
3126
3127 /**
Philip P. Moltmanna3e358c2018-11-21 12:45:50 -08003128 * Get the parent of a user profile.
3129 *
3130 * @param user the handle of the user profile
3131 *
3132 * @return the parent of the user or {@code null} if the user is not profile
3133 *
3134 * @hide
3135 */
3136 @SystemApi
3137 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
3138 public @Nullable UserHandle getProfileParent(@NonNull UserHandle user) {
3139 UserInfo info = getProfileParent(user.getIdentifier());
3140
3141 if (info == null) {
3142 return null;
3143 }
3144
3145 return UserHandle.of(info.id);
3146 }
3147
3148 /**
Tony Make3d1f652017-12-12 11:00:37 +00003149 * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a
3150 * managed profile don't run, generate notifications, or consume data or battery.
3151 * <p>
3152 * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be
3153 * shown to the user.
3154 * <p>
3155 * The change may not happen instantly, however apps can listen for
3156 * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and
3157 * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of
3158 * the change of the quiet mode. Apps can also check the current state of quiet mode by
3159 * calling {@link #isQuietModeEnabled(UserHandle)}.
3160 * <p>
3161 * The caller must either be the foreground default launcher or have one of these permissions:
3162 * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003163 *
Tony Make3d1f652017-12-12 11:00:37 +00003164 * @param enableQuietMode whether quiet mode should be enabled or disabled
3165 * @param userHandle user handle of the profile
3166 * @return {@code false} if user's credential is needed in order to turn off quiet mode,
3167 * {@code true} otherwise
3168 * @throws SecurityException if the caller is invalid
3169 * @throws IllegalArgumentException if {@code userHandle} is not a managed profile
3170 *
3171 * @see #isQuietModeEnabled(UserHandle)
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003172 */
Tony Makbece85d2018-01-12 12:10:17 +00003173 public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) {
3174 return requestQuietModeEnabled(enableQuietMode, userHandle, null);
Tony Makb7e6fd42017-12-05 19:40:28 +00003175 }
3176
3177 /**
Tony Makbece85d2018-01-12 12:10:17 +00003178 * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify
Tony Makd390ae92017-12-28 13:23:10 +00003179 * a target to start when user is unlocked. If {@code target} is specified, caller must have
3180 * the {@link android.Manifest.permission#MANAGE_USERS} permission.
Tony Makb7e6fd42017-12-05 19:40:28 +00003181 *
Tony Makbece85d2018-01-12 12:10:17 +00003182 * @see {@link #requestQuietModeEnabled(boolean, UserHandle)}
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003183 * @hide
3184 */
Tony Makbece85d2018-01-12 12:10:17 +00003185 public boolean requestQuietModeEnabled(
Tony Makb7e6fd42017-12-05 19:40:28 +00003186 boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003187 try {
Tony Makbece85d2018-01-12 12:10:17 +00003188 return mService.requestQuietModeEnabled(
Tony Make3d1f652017-12-12 11:00:37 +00003189 mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07003190 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003191 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003192 }
3193 }
3194
3195 /**
3196 * Returns whether the given profile is in quiet mode or not.
Ricky Wai7881cf82016-04-15 17:20:12 +01003197 * Notes: Quiet mode is only supported for managed profiles.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003198 *
3199 * @param userHandle The user handle of the profile to be queried.
3200 * @return true if the profile is in quiet mode, false otherwise.
3201 */
3202 public boolean isQuietModeEnabled(UserHandle userHandle) {
3203 try {
3204 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07003205 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003206 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003207 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00003208 }
3209
3210 /**
Bookatz029832a2019-10-04 16:50:22 -07003211 * Returns whether the given user has a badge (generally to put on profiles' icons).
3212 *
3213 * @param userId userId of the user in question
3214 * @return true if the user's icons should display a badge; false otherwise.
3215 *
3216 * @see #getBadgedIconForUser more information about badging in general
3217 * @hide
3218 */
3219 public boolean hasBadge(@UserIdInt int userId) {
3220 if (!isProfile(userId)) {
3221 // Since currently only profiles actually have badges, we can do this optimization.
3222 return false;
3223 }
3224 try {
3225 return mService.hasBadge(userId);
3226 } catch (RemoteException re) {
3227 throw re.rethrowFromSystemServer();
3228 }
3229 }
3230
3231 /**
3232 * Returns whether the calling app's user has a badge (generally to put on profiles' icons).
3233 *
3234 * @return true if the user's icons should display a badge; false otherwise.
3235 *
3236 * @see #getBadgedIconForUser more information about badging in general
3237 * @hide
3238 */
3239 public boolean hasBadge() {
3240 return hasBadge(UserHandle.myUserId());
3241 }
3242
3243 /**
3244 * Returns the badge color for the given user (generally to color a profile's icon's badge).
3245 *
3246 * <p>To check whether a badge color is expected for the user, first call {@link #hasBadge}.
3247 *
3248 * @return the color (not the resource ID) to be used for the user's badge
3249 * @throws Resources.NotFoundException if no valid badge color exists for this user
3250 *
3251 * @see #getBadgedIconForUser more information about badging in general
3252 * @hide
3253 */
3254 public @ColorInt int getUserBadgeColor(@UserIdInt int userId) {
3255 try {
3256 final int resourceId = mService.getUserBadgeColorResId(userId);
3257 return Resources.getSystem().getColor(resourceId, null);
3258 } catch (RemoteException re) {
3259 throw re.rethrowFromSystemServer();
3260 }
3261 }
3262
3263 /**
3264 * Returns the Resource ID of the user's icon badge.
3265 *
3266 * @return the Resource ID of the user's icon badge if it has one; otherwise
3267 * {@link Resources#ID_NULL}.
3268 *
3269 * @see #getBadgedIconForUser more information about badging in general
3270 * @hide
3271 */
3272 public @DrawableRes int getUserIconBadgeResId(@UserIdInt int userId) {
3273 try {
3274 return mService.getUserIconBadgeResId(userId);
3275 } catch (RemoteException re) {
3276 throw re.rethrowFromSystemServer();
3277 }
3278 }
3279
3280 /**
3281 * Returns the Resource ID of the user's badge.
3282 *
3283 * @return the Resource ID of the user's badge if it has one; otherwise
3284 * {@link Resources#ID_NULL}.
3285 *
3286 * @see #getBadgedIconForUser more information about badging in general
3287 * @hide
3288 */
3289 public @DrawableRes int getUserBadgeResId(@UserIdInt int userId) {
3290 try {
3291 return mService.getUserBadgeResId(userId);
3292 } catch (RemoteException re) {
3293 throw re.rethrowFromSystemServer();
3294 }
3295 }
3296
3297 /**
3298 * Returns the Resource ID of the user's badge without a background.
3299 *
3300 * @return the Resource ID of the user's no-background badge if it has one; otherwise
3301 * {@link Resources#ID_NULL}.
3302 *
3303 * @see #getBadgedIconForUser more information about badging in general
3304 * @hide
3305 */
3306 public @DrawableRes int getUserBadgeNoBackgroundResId(@UserIdInt int userId) {
3307 try {
3308 return mService.getUserBadgeNoBackgroundResId(userId);
3309 } catch (RemoteException re) {
3310 throw re.rethrowFromSystemServer();
3311 }
3312 }
3313
3314 /**
3315 * If the target user is a profile of the calling user or the caller
3316 * is itself a profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07003317 * icon to be able to distinguish it from the original icon. For badging an
3318 * arbitrary drawable use {@link #getBadgedDrawableForUser(
3319 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
3320 * <p>
3321 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08003322 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07003323 * is performed in place and the original drawable is returned.
3324 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07003325 *
3326 * @param icon The icon to badge.
3327 * @param user The target user.
3328 * @return A drawable that combines the original icon and a badge as
3329 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07003330 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07003331 */
Svetoslavc71c42f2014-08-05 18:57:05 -07003332 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07003333 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08003334 }
3335
Kenny Guy701ea7c2014-05-08 23:34:12 +01003336 /**
Bookatz029832a2019-10-04 16:50:22 -07003337 * If the target user is a profile of the calling user or the caller
3338 * is itself a profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07003339 * drawable allowing the user to distinguish it from the original drawable.
3340 * The caller can specify the location in the bounds of the drawable to be
3341 * badged where the badge should be applied as well as the density of the
3342 * badge to be used.
3343 * <p>
3344 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08003345 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07003346 * is performed in place and the original drawable is returned.
3347 * </p>
3348 *
3349 * @param badgedDrawable The drawable to badge.
3350 * @param user The target user.
3351 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08003352 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07003353 * drawable being badged.
3354 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08003355 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07003356 * the density of the display is used.
3357 * @return A drawable that combines the original drawable and a badge as
3358 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07003359 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07003360 */
3361 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
3362 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07003363 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
3364 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07003365 }
3366
3367 /**
Bookatz029832a2019-10-04 16:50:22 -07003368 * If the target user is a profile of the calling user or the caller
3369 * is itself a profile, then this returns a copy of the label with
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01003370 * badging for accessibility services like talkback. E.g. passing in "Email"
3371 * and it might return "Work Email" for Email in the work profile.
3372 *
Bookatz029832a2019-10-04 16:50:22 -07003373 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} or
3374 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission, otherwise the caller
3375 * must be in the same profile group of specified user.
3376 *
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01003377 * @param label The label to change.
3378 * @param user The target user.
3379 * @return A label that combines the original label and a badge as
3380 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07003381 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01003382 */
Kenny Guy237aecd2014-07-21 14:06:09 +01003383 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Bookatz029832a2019-10-04 16:50:22 -07003384 final int userId = user.getIdentifier();
3385 if (!hasBadge(userId)) {
3386 return label;
3387 }
3388 try {
3389 final int resourceId = mService.getUserBadgeLabelResId(userId);
3390 return Resources.getSystem().getString(resourceId, label);
3391 } catch (RemoteException re) {
3392 throw re.rethrowFromSystemServer();
3393 }
Amith Yamasani4f582632014-02-19 14:31:52 -08003394 }
3395
3396 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07003397 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07003398 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Bookatzf56f2582019-09-04 16:06:41 -07003399 * @param userId the integer handle of the user.
Amith Yamasani258848d2012-08-10 17:06:33 -07003400 * @hide
3401 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003402 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07003403 public boolean removeUser(@UserIdInt int userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07003404 try {
Bookatzf56f2582019-09-04 16:06:41 -07003405 return mService.removeUser(userId);
Amith Yamasani258848d2012-08-10 17:06:33 -07003406 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003407 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07003408 }
3409 }
3410
3411 /**
Varun Shahe38c6782018-12-04 16:57:49 -08003412 * Removes a user and all associated data.
3413 *
3414 * @param user the user that needs to be removed.
Varun Shah9533e622019-02-27 15:26:56 -08003415 * @return {@code true} if the user was successfully removed, {@code false} otherwise.
3416 * @throws IllegalArgumentException if {@code user} is {@code null}
Varun Shahe38c6782018-12-04 16:57:49 -08003417 * @hide
3418 */
3419 @SystemApi
3420 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Varun Shah9533e622019-02-27 15:26:56 -08003421 public boolean removeUser(@NonNull UserHandle user) {
3422 if (user == null) {
3423 throw new IllegalArgumentException("user cannot be null");
3424 }
Varun Shahe38c6782018-12-04 16:57:49 -08003425 return removeUser(user.getIdentifier());
3426 }
3427
3428
3429 /**
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00003430 * Similar to {@link #removeUser(int)} except bypassing the checking of
3431 * {@link UserManager#DISALLOW_REMOVE_USER}
3432 * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
3433 *
3434 * @see {@link #removeUser(int)}
3435 * @hide
3436 */
Bookatzf56f2582019-09-04 16:06:41 -07003437 public boolean removeUserEvenWhenDisallowed(@UserIdInt int userId) {
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00003438 try {
Bookatzf56f2582019-09-04 16:06:41 -07003439 return mService.removeUserEvenWhenDisallowed(userId);
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00003440 } catch (RemoteException re) {
3441 throw re.rethrowFromSystemServer();
3442 }
3443 }
3444
3445 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07003446 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07003447 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07003448 *
Bookatzf56f2582019-09-04 16:06:41 -07003449 * @param userId the user's integer id
Amith Yamasani258848d2012-08-10 17:06:33 -07003450 * @param name the new name for the user
3451 * @hide
3452 */
Bookatzf56f2582019-09-04 16:06:41 -07003453 public void setUserName(@UserIdInt int userId, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07003454 try {
Bookatzf56f2582019-09-04 16:06:41 -07003455 mService.setUserName(userId, name);
Amith Yamasani258848d2012-08-10 17:06:33 -07003456 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003457 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07003458 }
3459 }
3460
3461 /**
Leo Hsuab28fff2019-01-30 15:40:56 +08003462 * Updates the calling user's name.
3463 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
3464 *
3465 * @param name the new name for the user
3466 * @hide
3467 */
3468 @SystemApi
3469 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Leo Hsu51839332019-03-05 16:59:04 +08003470 public void setUserName(@Nullable String name) {
Leo Hsuab28fff2019-01-30 15:40:56 +08003471 setUserName(getUserHandle(), name);
3472 }
3473
3474 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07003475 * Sets the user's photo.
Bookatzf56f2582019-09-04 16:06:41 -07003476 * @param userId the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07003477 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07003478 * @hide
3479 */
Bookatzf56f2582019-09-04 16:06:41 -07003480 public void setUserIcon(@UserIdInt int userId, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07003481 try {
Bookatzf56f2582019-09-04 16:06:41 -07003482 mService.setUserIcon(userId, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07003483 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003484 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07003485 }
3486 }
3487
3488 /**
Leo Hsuab28fff2019-01-30 15:40:56 +08003489 * Sets the calling user's photo.
3490 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
3491 *
3492 * @param icon the bitmap to set as the photo.
3493 * @hide
3494 */
3495 @SystemApi
3496 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Leo Hsu51839332019-03-05 16:59:04 +08003497 public void setUserIcon(@NonNull Bitmap icon) {
Leo Hsuab28fff2019-01-30 15:40:56 +08003498 setUserIcon(getUserHandle(), icon);
3499 }
3500
3501 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07003502 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
Bookatzf56f2582019-09-04 16:06:41 -07003503 * @param userId the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07003504 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01003505 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07003506 * @hide
3507 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003508 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07003509 public Bitmap getUserIcon(@UserIdInt int userId) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07003510 try {
Bookatzf56f2582019-09-04 16:06:41 -07003511 ParcelFileDescriptor fd = mService.getUserIcon(userId);
Adrian Roos1bdff912015-02-17 15:51:35 +01003512 if (fd != null) {
3513 try {
3514 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
3515 } finally {
3516 try {
3517 fd.close();
3518 } catch (IOException e) {
3519 }
3520 }
3521 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07003522 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003523 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07003524 }
Adrian Roos1bdff912015-02-17 15:51:35 +01003525 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07003526 }
3527
3528 /**
Leo Hsuab28fff2019-01-30 15:40:56 +08003529 * Returns a Bitmap for the calling user's photo.
Bookatzcde3d922019-03-08 14:30:00 -08003530 * Requires {@link android.Manifest.permission#MANAGE_USERS}
3531 * or {@link android.Manifest.permission#GET_ACCOUNTS_PRIVILEGED} permissions.
Leo Hsuab28fff2019-01-30 15:40:56 +08003532 *
3533 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
3534 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
3535 * @hide
3536 */
3537 @SystemApi
Bookatzcde3d922019-03-08 14:30:00 -08003538 @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
3539 android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED})
Leo Hsu51839332019-03-05 16:59:04 +08003540 public @Nullable Bitmap getUserIcon() {
Leo Hsuab28fff2019-01-30 15:40:56 +08003541 return getUserIcon(getUserHandle());
3542 }
3543
3544 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07003545 * Returns the maximum number of users that can be created on this device. A return value
3546 * of 1 means that it is a single user device.
3547 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04003548 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07003549 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003550 @UnsupportedAppUsage
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07003551 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07003552 // Don't allow multiple users on certain builds
3553 if (android.os.Build.ID.startsWith("JVP")) return 1;
Robin Lee83c79312018-02-09 19:27:18 +01003554 if (ActivityManager.isLowRamDeviceStatic()) {
3555 // Low-ram devices are Svelte. Most of the time they don't get multi-user.
3556 if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
3557 != Configuration.UI_MODE_TYPE_TELEVISION) {
3558 return 1;
3559 }
3560 }
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07003561 return SystemProperties.getInt("fw.max_users",
3562 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07003563 }
Amith Yamasani2a003292012-08-14 18:25:45 -07003564
3565 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003566 * Returns true if the user switcher should be shown, this will be if device supports multi-user
3567 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00003568 * @hide
3569 * @return true if user switcher should be shown.
3570 */
3571 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003572 if (!supportsMultipleUsers()) {
3573 return false;
3574 }
Benjamin Franzff66fa92017-08-10 10:39:44 +01003575 if (hasUserRestriction(DISALLOW_USER_SWITCH)) {
3576 return false;
3577 }
Amith Yamasanieb437d42016-04-29 09:31:25 -07003578 // If Demo Mode is on, don't show user switcher
3579 if (isDeviceInDemoMode(mContext)) {
3580 return false;
3581 }
Fan Zhangc69c8b62018-06-05 13:30:11 -07003582 // If user disabled this feature, don't show switcher
3583 final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(),
3584 Settings.Global.USER_SWITCHER_ENABLED, 1) != 0;
3585 if (!userSwitcherEnabled) {
3586 return false;
3587 }
Kenny Guy1a447532014-02-20 21:55:32 +00003588 List<UserInfo> users = getUsers(true);
3589 if (users == null) {
3590 return false;
3591 }
3592 int switchableUserCount = 0;
3593 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07003594 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00003595 ++switchableUserCount;
3596 }
3597 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003598 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
3599 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07003600 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00003601 }
3602
3603 /**
Amith Yamasanieb437d42016-04-29 09:31:25 -07003604 * @hide
3605 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003606 @UnsupportedAppUsage
Amith Yamasanieb437d42016-04-29 09:31:25 -07003607 public static boolean isDeviceInDemoMode(Context context) {
3608 return Settings.Global.getInt(context.getContentResolver(),
3609 Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
3610 }
3611
3612 /**
Bookatzf56f2582019-09-04 16:06:41 -07003613 * Returns a serial number on this device for a given userId. User handles can be recycled
Amith Yamasani2a003292012-08-14 18:25:45 -07003614 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
Bookatzf56f2582019-09-04 16:06:41 -07003615 * @param userId
3616 * @return a serial number associated with that user, or -1 if the userId is not valid.
Amith Yamasani2a003292012-08-14 18:25:45 -07003617 * @hide
3618 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003619 @UnsupportedAppUsage
Bookatzf56f2582019-09-04 16:06:41 -07003620 public int getUserSerialNumber(@UserIdInt int userId) {
Amith Yamasani2a003292012-08-14 18:25:45 -07003621 try {
Bookatzf56f2582019-09-04 16:06:41 -07003622 return mService.getUserSerialNumber(userId);
Amith Yamasani2a003292012-08-14 18:25:45 -07003623 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003624 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07003625 }
Amith Yamasani2a003292012-08-14 18:25:45 -07003626 }
3627
3628 /**
Bookatzf56f2582019-09-04 16:06:41 -07003629 * Returns a userId on this device for a given user serial number. User handles can be
Amith Yamasani2a003292012-08-14 18:25:45 -07003630 * recycled when deleting and creating users, but serial numbers are not reused until the device
3631 * is wiped.
3632 * @param userSerialNumber
Bookatzf56f2582019-09-04 16:06:41 -07003633 * @return the userId associated with that user serial number, or -1 if the serial number
Amith Yamasani2a003292012-08-14 18:25:45 -07003634 * is not valid.
3635 * @hide
3636 */
Andrei Onea24ec3212019-03-15 17:35:05 +00003637 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07003638 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07003639 try {
3640 return mService.getUserHandle(userSerialNumber);
3641 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003642 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07003643 }
Amith Yamasani2a003292012-08-14 18:25:45 -07003644 }
Maggie Benthall67944582013-02-22 14:58:27 -05003645
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003646 /**
Esteban Talavera953fe482016-06-07 15:25:20 +01003647 * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003648 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00003649 *
3650 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
3651 * where the types of values may be:
3652 * <ul>
3653 * <li>{@code boolean}
3654 * <li>{@code int}
3655 * <li>{@code String} or {@code String[]}
3656 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3657 * </ul>
3658 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07003659 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
3660 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003661 * @param packageName the package name of the calling application
Esteban Talavera953fe482016-06-07 15:25:20 +01003662 * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
3663 * if there are no saved restrictions.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00003664 *
3665 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003666 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07003667 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003668 public Bundle getApplicationRestrictions(String packageName) {
3669 try {
3670 return mService.getApplicationRestrictions(packageName);
3671 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003672 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003673 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003674 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003675
3676 /**
3677 * @hide
3678 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07003679 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003680 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003681 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003682 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003683 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003684 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003685 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003686 }
3687
3688 /**
3689 * @hide
3690 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07003691 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003692 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003693 UserHandle user) {
3694 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07003695 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003696 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003697 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003698 }
3699 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003700
3701 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07003702 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
3703 * apps and requires the MANAGE_USERS permission.
3704 * @param newPin the PIN to use for challenge dialogs.
3705 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07003706 * @deprecated The restrictions PIN functionality is no longer provided by the system.
3707 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07003708 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003709 @Deprecated
Amith Yamasanid304af62013-09-05 09:30:23 -07003710 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07003711 return false;
3712 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07003713
Amith Yamasanie4afaa32014-06-30 14:55:07 +05303714 /**
3715 * @hide
3716 * Set restrictions that should apply to any future guest user that's created.
3717 */
3718 public void setDefaultGuestRestrictions(Bundle restrictions) {
3719 try {
3720 mService.setDefaultGuestRestrictions(restrictions);
3721 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003722 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05303723 }
3724 }
3725
3726 /**
3727 * @hide
3728 * Gets the default guest restrictions.
3729 */
3730 public Bundle getDefaultGuestRestrictions() {
3731 try {
3732 return mService.getDefaultGuestRestrictions();
3733 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003734 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05303735 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05303736 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07003737
3738 /**
3739 * Returns creation time of the user or of a managed profile associated with the calling user.
3740 * @param userHandle user handle of the user or a managed profile associated with the
3741 * calling user.
3742 * @return creation time in milliseconds since Epoch time.
3743 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07003744 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07003745 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07003746 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07003747 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003748 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07003749 }
3750 }
Amith Yamasani12747872015-12-07 14:19:49 -08003751
3752 /**
3753 * @hide
3754 * Checks if any uninitialized user has the specific seed account name and type.
3755 *
Pavel Grafov6a40f092016-10-25 15:46:51 +01003756 * @param accountName The account name to check for
3757 * @param accountType The account type of the account to check for
Amith Yamasani12747872015-12-07 14:19:49 -08003758 * @return whether the seed account was found
3759 */
3760 public boolean someUserHasSeedAccount(String accountName, String accountType) {
3761 try {
3762 return mService.someUserHasSeedAccount(accountName, accountType);
3763 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003764 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08003765 }
3766 }
Pavel Grafov6a40f092016-10-25 15:46:51 +01003767
3768 /**
3769 * @hide
3770 * User that enforces a restriction.
3771 *
3772 * @see #getUserRestrictionSources(String, UserHandle)
3773 */
3774 @SystemApi
3775 public static final class EnforcingUser implements Parcelable {
3776 private final @UserIdInt int userId;
3777 private final @UserRestrictionSource int userRestrictionSource;
3778
3779 /**
3780 * @hide
3781 */
3782 public EnforcingUser(
3783 @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
3784 this.userId = userId;
3785 this.userRestrictionSource = userRestrictionSource;
3786 }
3787
3788 private EnforcingUser(Parcel in) {
3789 userId = in.readInt();
3790 userRestrictionSource = in.readInt();
3791 }
3792
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07003793 public static final @android.annotation.NonNull Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
Pavel Grafov6a40f092016-10-25 15:46:51 +01003794 @Override
3795 public EnforcingUser createFromParcel(Parcel in) {
3796 return new EnforcingUser(in);
3797 }
3798
3799 @Override
3800 public EnforcingUser[] newArray(int size) {
3801 return new EnforcingUser[size];
3802 }
3803 };
3804
3805 @Override
3806 public int describeContents() {
3807 return 0;
3808 }
3809
3810 @Override
3811 public void writeToParcel(Parcel dest, int flags) {
3812 dest.writeInt(userId);
3813 dest.writeInt(userRestrictionSource);
3814 }
3815
3816 /**
3817 * Returns an id of the enforcing user.
3818 *
3819 * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
3820 */
3821 public UserHandle getUserHandle() {
3822 return UserHandle.of(userId);
3823 }
3824
3825 /**
3826 * Returns the status of the enforcing user.
3827 *
3828 * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
3829 * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
3830 * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
3831 */
3832 public @UserRestrictionSource int getUserRestrictionSource() {
3833 return userRestrictionSource;
3834 }
3835 }
Amith Yamasani258848d2012-08-10 17:06:33 -07003836}