blob: 3edd06b3890538464e655d28d8f669599b68d709 [file] [log] [blame]
Amith Yamasani258848d2012-08-10 17:06:33 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -060016
Amith Yamasani258848d2012-08-10 17:06:33 -070017package android.os;
18
Xiaohui Chenb3b92582015-12-07 11:22:13 -080019import android.Manifest;
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -070020import android.accounts.AccountManager;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010021import android.annotation.IntDef;
Adam Lesinskiada8deb2017-05-12 13:50:42 -070022import android.annotation.NonNull;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -070023import android.annotation.Nullable;
Xiaohui Chenb3b92582015-12-07 11:22:13 -080024import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070025import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SystemService;
Makoto Onukie72f81b2017-03-16 14:08:19 -070027import android.annotation.TestApi;
Andrei Oneadcb67732019-03-18 11:37:25 +000028import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070029import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070030import android.annotation.WorkerThread;
Amith Yamasani37ed8d12016-01-27 14:40:16 -080031import android.app.Activity;
Dianne Hackborn409297d2014-07-10 17:39:20 -070032import android.app.ActivityManager;
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -070033import android.app.admin.DevicePolicyManager;
Makoto Onuki068c54a2015-10-13 14:34:03 -070034import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070035import android.content.Context;
Amith Yamasani12747872015-12-07 14:19:49 -080036import android.content.Intent;
Esteban Talavera8bd7c522017-02-13 12:35:04 +000037import android.content.IntentFilter;
Benjamin Franzf02420c2016-04-04 18:52:21 +010038import android.content.IntentSender;
Amith Yamasani258848d2012-08-10 17:06:33 -070039import android.content.pm.UserInfo;
Robin Lee83c79312018-02-09 19:27:18 +010040import android.content.res.Configuration;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070041import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050042import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010043import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080044import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080045import android.graphics.drawable.Drawable;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070046import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080047import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040048import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070049
Maggie Benthall67944582013-02-22 14:58:27 -050050import com.android.internal.R;
John Reckaa67f682016-09-20 14:24:21 -070051import com.android.internal.os.RoSystemProperties;
Maggie Benthall67944582013-02-22 14:58:27 -050052
Adrian Roos1bdff912015-02-17 15:51:35 +010053import java.io.IOException;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010054import java.lang.annotation.Retention;
55import java.lang.annotation.RetentionPolicy;
Amith Yamasani4f582632014-02-19 14:31:52 -080056import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070057import java.util.List;
58
59/**
Amith Yamasani06964342016-04-15 13:55:01 -070060 * Manages users and user details on a multi-user system. There are two major categories of
61 * users: fully customizable users with their own login, and managed profiles that share a workspace
62 * with a related user.
63 * <p>
64 * Users are different from accounts, which are managed by
65 * {@link AccountManager}. Each user can have their own set of accounts.
66 * <p>
67 * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
Amith Yamasani258848d2012-08-10 17:06:33 -070068 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060069@SystemService(Context.USER_SERVICE)
Amith Yamasani258848d2012-08-10 17:06:33 -070070public class UserManager {
71
Pavel Grafov4f4f6f82017-03-28 13:44:04 +010072 private static final String TAG = "UserManager";
Andrei Oneadcb67732019-03-18 11:37:25 +000073 @UnsupportedAppUsage
Amith Yamasani258848d2012-08-10 17:06:33 -070074 private final IUserManager mService;
75 private final Context mContext;
76
Makoto Onukid49f3fa2017-01-25 14:09:48 -080077 private Boolean mIsManagedProfileCached;
78
Amith Yamasanie4cf7342012-12-17 11:12:09 -080079 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010080 * @hide
81 * No user restriction.
82 */
83 @SystemApi
84 public static final int RESTRICTION_NOT_SET = 0x0;
85
86 /**
87 * @hide
88 * User restriction set by system/user.
89 */
90 @SystemApi
91 public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
92
93 /**
94 * @hide
95 * User restriction set by a device owner.
96 */
97 @SystemApi
98 public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
99
100 /**
101 * @hide
102 * User restriction set by a profile owner.
103 */
104 @SystemApi
105 public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
106
107 /** @hide */
108 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700109 @IntDef(flag = true, prefix = { "RESTRICTION_" }, value = {
110 RESTRICTION_NOT_SET,
111 RESTRICTION_SOURCE_SYSTEM,
112 RESTRICTION_SOURCE_DEVICE_OWNER,
113 RESTRICTION_SOURCE_PROFILE_OWNER
114 })
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +0100115 @SystemApi
116 public @interface UserRestrictionSource {}
117
118 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -0700119 * Specifies if a user is disallowed from adding and removing accounts, unless they are
120 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
121 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700122 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700123 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +0000124 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
125 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
126 * management is disallowed.
127 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800128 * <p>Key for user restrictions.
129 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700130 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
131 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800132 * @see #getUserRestrictions()
133 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700134 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800135
136 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700137 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -0400138 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800139 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700140 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800141 * <p>Key for user restrictions.
142 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700143 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
144 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800145 * @see #getUserRestrictions()
146 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700147 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800148
149 /**
Christine Franks1bade5d2017-10-10 15:41:50 -0700150 * Specifies if a user is disallowed from changing the device
151 * language. The default value is <code>false</code>.
152 *
153 * <p>Key for user restrictions.
154 * <p>Type: Boolean
155 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
156 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
157 * @see #getUserRestrictions()
158 */
159 public static final String DISALLOW_CONFIG_LOCALE = "no_config_locale";
160
161 /**
Benjamin Millerf1c3ed12018-05-03 10:56:28 +0000162 * Specifies if a user is disallowed from installing applications. This user restriction also
163 * prevents device owners and profile owners installing apps. The default value is
164 * {@code false}.
Amith Yamasani26af8292014-09-09 09:57:27 -0700165 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800166 * <p>Key for user restrictions.
167 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700168 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
169 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800170 * @see #getUserRestrictions()
171 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700172 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800173
174 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700175 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700176 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700177 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800178 * <p>Key for user restrictions.
179 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700180 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
181 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800182 * @see #getUserRestrictions()
183 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700184 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800185
Amith Yamasani71e6c692013-03-24 17:39:28 -0700186 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800187 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700188 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800189 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800190 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700191 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800192 * <p>Key for user restrictions.
193 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700194 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
195 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500196 * @see #getUserRestrictions()
197 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700198 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500199
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400200 /**
yuemingw5fe75dc2017-11-29 15:52:56 +0000201 * Specifies if airplane mode is disallowed on the device.
202 *
203 * <p> This restriction can only be set by the device owner and the profile owner on the
204 * primary user and it applies globally - i.e. it disables airplane mode on the entire device.
205 * <p>The default value is <code>false</code>.
206 *
207 * <p>Key for user restrictions.
208 * <p>Type: Boolean
209 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
210 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
211 * @see #getUserRestrictions()
212 */
213 public static final String DISALLOW_AIRPLANE_MODE = "no_airplane_mode";
214
215 /**
yuemingwc6ac29d2018-01-10 16:54:08 +0000216 * Specifies if a user is disallowed from configuring brightness. When device owner sets it,
217 * it'll only be applied on the target(system) user.
218 *
219 * <p>The default value is <code>false</code>.
220 *
221 * <p>This user restriction has no effect on managed profiles.
222 * <p>Key for user restrictions.
223 * <p>Type: Boolean
224 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
225 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
226 * @see #getUserRestrictions()
227 */
228 public static final String DISALLOW_CONFIG_BRIGHTNESS = "no_config_brightness";
229
230 /**
yuemingwa1781442018-01-10 18:59:43 +0000231 * Specifies if ambient display is disallowed for the user.
232 *
233 * <p>The default value is <code>false</code>.
234 *
235 * <p>This user restriction has no effect on managed profiles.
236 * <p>Key for user restrictions.
237 * <p>Type: Boolean
238 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
239 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
240 * @see #getUserRestrictions()
241 */
242 public static final String DISALLOW_AMBIENT_DISPLAY = "no_ambient_display";
243
244 /**
yuemingw5cda3ae2018-01-15 10:26:19 +0000245 * Specifies if a user is disallowed from changing screen off timeout.
246 *
247 * <p>The default value is <code>false</code>.
248 *
249 * <p>This user restriction has no effect on managed profiles.
250 * <p>Key for user restrictions.
251 * <p>Type: Boolean
252 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
253 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
254 * @see #getUserRestrictions()
255 */
256 public static final String DISALLOW_CONFIG_SCREEN_TIMEOUT = "no_config_screen_timeout";
257
258 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700259 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400260 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
261 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700262 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800263 * <p>Key for user restrictions.
264 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700265 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
266 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400267 * @see #getUserRestrictions()
268 */
269 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
270
271 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700272 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000273 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400274 * The default value is <code>false</code>.
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100275 * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
276 * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800277 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700278 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800279 * <p>Key for user restrictions.
280 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700281 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
282 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400283 * @see #getUserRestrictions()
284 */
285 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
286
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400287 /**
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100288 * Specifies if bluetooth is disallowed on the device.
289 *
290 * <p> This restriction can only be set by the device owner and the profile owner on the
291 * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
292 * <p>The default value is <code>false</code>.
293 * <p>Key for user restrictions.
294 * <p>Type: Boolean
295 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
296 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
297 * @see #getUserRestrictions()
298 */
299 public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
300
301 /**
Pavel Grafov4f4f6f82017-03-28 13:44:04 +0100302 * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
303 * owner can set this restriction. When it is set by device owner, all users on this device will
304 * be affected.
305 *
306 * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
307 * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
308 * managed profiles.
309 *
310 * <p>Key for user restrictions.
311 * <p>Type: Boolean
312 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
313 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
314 * @see #getUserRestrictions()
315 */
316 public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
317
318 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700319 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700320 * USB. This can only be set by device owners and profile owners on the primary user.
321 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700322 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800323 * <p>Key for user restrictions.
324 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700325 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
326 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400327 * @see #getUserRestrictions()
328 */
329 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
330
Emily Bernierb223f732013-04-11 15:46:36 -0400331 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700332 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400333 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700334 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800335 * <p>Key for user restrictions.
336 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700337 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
338 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400339 * @see #getUserRestrictions()
340 */
341 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
342
343 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800344 * When set on the primary user this specifies if the user can remove other users.
345 * When set on a secondary user, this specifies if the user can remove itself.
346 * This restriction has no effect on managed profiles.
347 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700348 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800349 * <p>Key for user restrictions.
350 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700351 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
352 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400353 * @see #getUserRestrictions()
354 */
355 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
356
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400357 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000358 * Specifies if managed profiles of this user can be removed, other than by its profile owner.
359 * The default value is <code>false</code>.
360 * <p>
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000361 * This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000362 *
363 * <p>Key for user restrictions.
364 * <p>Type: Boolean
365 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
366 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
367 * @see #getUserRestrictions()
368 */
369 public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
370
371 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700372 * Specifies if a user is disallowed from enabling or
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400373 * accessing debugging features. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700374 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800375 * <p>Key for user restrictions.
376 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700377 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
378 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400379 * @see #getUserRestrictions()
380 */
381 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
382
383 /**
Benjamin Miller05fef7e2017-07-24 10:11:39 +0200384 * Specifies if a user is disallowed from configuring a VPN. The default value is
385 * <code>false</code>. This restriction has an effect when set by device owners and, in Android
386 * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners.
387 * <p>This restriction also prevents VPNs from starting. However, in Android 7.0
388 * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does
389 * start always-on VPNs created by the device or profile owner.
Amith Yamasani26af8292014-09-09 09:57:27 -0700390 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800391 * <p>Key for user restrictions.
392 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700393 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
394 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400395 * @see #getUserRestrictions()
396 */
397 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
398
399 /**
yuemingw7810b8b2018-02-01 17:32:25 +0000400 * Specifies if a user is disallowed from enabling or disabling location providers. As a
401 * result, user is disallowed from turning on or off location. Device owner and profile owners
402 * can set this restriction and it only applies on the managed user.
yuemingw7cc2c4c2017-11-28 17:20:01 +0000403 *
404 * <p>In a managed profile, location sharing is forced off when it's off on primary user, so
405 * user can still turn off location sharing on managed profile when the restriction is set by
406 * profile owner on managed profile.
407 *
408 * <p>This user restriction is different from {@link #DISALLOW_SHARE_LOCATION},
409 * as the device owner or profile owner can still enable or disable location mode via
410 * {@link DevicePolicyManager#setSecureSetting} when this restriction is on.
411 *
412 * <p>The default value is <code>false</code>.
413 *
414 * <p>Key for user restrictions.
415 * <p>Type: Boolean
yuemingw7810b8b2018-02-01 17:32:25 +0000416 * @see android.location.LocationManager#isProviderEnabled(String)
yuemingw7cc2c4c2017-11-28 17:20:01 +0000417 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
418 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
419 * @see #getUserRestrictions()
420 */
yuemingw7810b8b2018-02-01 17:32:25 +0000421 public static final String DISALLOW_CONFIG_LOCATION = "no_config_location";
yuemingw7cc2c4c2017-11-28 17:20:01 +0000422
423 /**
yuemingwa9772f362017-10-23 18:34:35 +0100424 * Specifies if date, time and timezone configuring is disallowed.
425 *
426 * <p>When restriction is set by device owners, it applies globally - i.e., it disables date,
427 * time and timezone setting on the entire device and all users will be affected. When it's set
428 * by profile owners, it's only applied to the managed user.
429 * <p>The default value is <code>false</code>.
430 *
431 * <p>This user restriction has no effect on managed profiles.
432 * <p>Key for user restrictions.
433 * <p>Type: Boolean
434 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
435 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
436 * @see #getUserRestrictions()
437 */
438 public static final String DISALLOW_CONFIG_DATE_TIME = "no_config_date_time";
439
440 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700441 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700442 * & portable hotspots. This can only be set by device owners and profile owners on the
443 * primary user. The default value is <code>false</code>.
Rubin Xu1faf1442017-08-23 15:48:12 +0100444 * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set,
445 * tethering will be automatically turned off.
Amith Yamasani26af8292014-09-09 09:57:27 -0700446 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800447 * <p>Key for user restrictions.
448 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700449 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
450 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400451 * @see #getUserRestrictions()
452 */
453 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
454
455 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700456 * Specifies if a user is disallowed from resetting network settings
457 * from Settings. This can only be set by device owners and profile owners on the primary user.
458 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800459 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700460 * primary user can reset the network settings of the device.
461 *
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)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700466 * @see #getUserRestrictions()
467 */
468 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
469
470 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700471 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700472 * from Settings. This can only be set by device owners and profile owners on the primary user.
473 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800474 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800475 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700476 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800477 * <p>Key for user restrictions.
478 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700479 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
480 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400481 * @see #getUserRestrictions()
482 */
483 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
484
485 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000486 * Specifies if a user is disallowed from adding new users. This can only be set by device
487 * owners and profile owners on the primary user.
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700488 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800489 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800490 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700491 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800492 * <p>Key for user restrictions.
493 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700494 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
495 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400496 * @see #getUserRestrictions()
497 */
498 public static final String DISALLOW_ADD_USER = "no_add_user";
499
500 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000501 * Specifies if a user is disallowed from adding managed profiles.
502 * <p>The default value for an unmanaged user is <code>false</code>.
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000503 * For users with a device owner set, the default is <code>true</code>.
504 * <p>This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000505 *
506 * <p>Key for user restrictions.
507 * <p>Type: Boolean
508 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
509 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
510 * @see #getUserRestrictions()
511 */
512 public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
513
514 /**
Benjamin Millerd41a9fc2017-07-17 17:24:44 +0200515 * Specifies if a user is disallowed from disabling application verification. The default
516 * value is <code>false</code>.
517 *
518 * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher,
519 * this is a global user restriction. If a device owner or profile owner sets this restriction,
520 * the system enforces app verification across all users on the device. Running in earlier
521 * Android versions, this restriction affects only the profile that sets it.
Amith Yamasani26af8292014-09-09 09:57:27 -0700522 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800523 * <p>Key for user restrictions.
524 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700525 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
526 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400527 * @see #getUserRestrictions()
528 */
529 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
530
531 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700532 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700533 * broadcasts. This can only be set by device owners and profile owners on the primary user.
534 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800535 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800536 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700537 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800538 * <p>Key for user restrictions.
539 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700540 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
541 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400542 * @see #getUserRestrictions()
543 */
544 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
545
546 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700547 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700548 * networks. This can only be set by device owners and profile owners on the primary user.
549 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800550 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800551 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700552 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800553 * <p>Key for user restrictions.
554 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700555 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
556 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400557 * @see #getUserRestrictions()
558 */
559 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
560
561 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700562 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400563 * applications in Settings or launchers. The following actions will not be allowed when this
564 * restriction is enabled:
565 * <li>uninstalling apps</li>
566 * <li>disabling apps</li>
567 * <li>clearing app caches</li>
568 * <li>clearing app data</li>
569 * <li>force stopping apps</li>
570 * <li>clearing app defaults</li>
571 * <p>
572 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700573 *
Esteban Talavera8bd7c522017-02-13 12:35:04 +0000574 * <p><strong>Note:</strong> The user will still be able to perform those actions via other
575 * means (such as adb). Third party apps will also be able to uninstall apps via the
576 * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
577 * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
578 * used to prevent the user from uninstalling apps completely, and
579 * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
580 * to add a default intent handler for a given intent filter.
581 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800582 * <p>Key for user restrictions.
583 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700584 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
585 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400586 * @see #getUserRestrictions()
587 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400588 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400589
Emily Bernier394a6cd2014-05-07 12:49:20 -0400590 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700591 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700592 * physical external media. This can only be set by device owners and profile owners on the
593 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700594 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800595 * <p>Key for user restrictions.
596 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700597 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
598 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400599 * @see #getUserRestrictions()
600 */
601 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
602
603 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100604 * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
605 * will be muted. This can be set by device owners and profile owners. The default value is
606 * <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700607 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100608 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800609 * <p>Key for user restrictions.
610 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700611 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
612 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400613 * @see #getUserRestrictions()
614 */
615 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
616
617 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100618 * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
Wen ZHANG61ed0dc2017-08-23 14:27:02 +0100619 * will be muted. This can be set by device owners from API 21 and profile owners from API 24.
620 * The default value is <code>false</code>.
621 *
622 * <p>When the restriction is set by profile owners, then it only applies to relevant
623 * profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700624 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100625 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800626 * <p>Key for user restrictions.
627 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700628 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
629 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400630 * @see #getUserRestrictions()
631 */
632 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
633
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700634 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700635 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700636 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700637 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000638 * <p>This restriction has no effect on managed profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700639 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800640 * <p>Key for user restrictions.
641 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700642 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
643 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700644 * @see #getUserRestrictions()
645 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700646 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
647
648 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700649 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700650 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700651 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800652 * <p>Key for user restrictions.
653 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700654 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
655 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700656 * @see #getUserRestrictions()
657 */
658 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700659
Jason Monk1c7c3192014-06-26 12:52:18 -0400660 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700661 * Specifies if the user is not allowed to have fun. In some cases, the
662 * device owner may wish to prevent the user from experiencing amusement or
663 * joy while using the device. The default value is <code>false</code>.
664 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800665 * <p>Key for user restrictions.
666 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700667 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
668 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700669 * @see #getUserRestrictions()
670 */
671 public static final String DISALLOW_FUN = "no_fun";
672
673 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700674 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400675 * created. This will block the creation of the following types of windows.
676 * <li>{@link LayoutParams#TYPE_TOAST}</li>
677 * <li>{@link LayoutParams#TYPE_PHONE}</li>
678 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
679 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
680 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
681 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800682 * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
Jason Monk1c7c3192014-06-26 12:52:18 -0400683 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700684 * <p>This can only be set by device owners and profile owners on the primary user.
685 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700686 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800687 * <p>Key for user restrictions.
688 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700689 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
690 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400691 * @see #getUserRestrictions()
692 */
693 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
694
Nicolas Prevotf1939902014-06-25 09:29:02 +0100695 /**
Charles He22ff6f9d2017-10-05 21:28:55 +0100696 * Specifies that system error dialogs for crashed or unresponsive apps should not be shown.
697 * 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 +0000698 * option on the UI. A feedback report isn't collected as there is no way for the user to
699 * provide explicit consent. The default value is <code>false</code>.
Charles He22ff6f9d2017-10-05 21:28:55 +0100700 *
Benjamin Franz0c86fe12018-02-28 09:49:17 +0000701 * <p>When this user restriction is set by device owners, it's applied to all users. When set by
702 * the profile owner of the primary user or a secondary user, the restriction affects only the
703 * calling user. This user restriction has no effect on managed profiles.
Charles He22ff6f9d2017-10-05 21:28:55 +0100704 *
Charles He22ff6f9d2017-10-05 21:28:55 +0100705 * <p>Key for user restrictions.
706 * <p>Type: Boolean
707 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
708 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
709 * @see #getUserRestrictions()
710 */
711 public static final String DISALLOW_SYSTEM_ERROR_DIALOGS = "no_system_error_dialogs";
712
713 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700714 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100715 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
716 * pasted in this profile.
717 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700718 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800719 * <p>Key for user restrictions.
720 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700721 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
722 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100723 * @see #getUserRestrictions()
724 */
725 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
726
Amith Yamasani26af8292014-09-09 09:57:27 -0700727 /**
728 * Specifies if the user is not allowed to use NFC to beam out data from apps.
729 * The default value is <code>false</code>.
730 *
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 Yamasani26af8292014-09-09 09:57:27 -0700735 * @see #getUserRestrictions()
736 */
737 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
738
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000739 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100740 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
741 * generally means that wallpapers are not supported for the particular user. This user
742 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000743 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100744 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700745 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
746 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000747 * @see #getUserRestrictions()
748 */
749 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
750
751 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100752 * User restriction to disallow setting a wallpaper. Profile owner and device owner
753 * are able to set wallpaper regardless of this restriction.
754 * The default value is <code>false</code>.
755 *
756 * <p>Key for user restrictions.
757 * <p>Type: Boolean
758 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
759 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
760 * @see #getUserRestrictions()
761 */
762 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
763
764 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000765 * Specifies if the user is not allowed to reboot the device into safe boot mode.
766 * This can only be set by device owners and profile owners on the primary user.
767 * The default value is <code>false</code>.
768 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800769 * <p>Key for user restrictions.
770 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700771 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
772 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000773 * @see #getUserRestrictions()
774 */
775 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
776
777 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700778 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
779 * background users. The default value is <code>false</code>.
780 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700781 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
782 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700783 * @see #getUserRestrictions()
784 * @hide
785 */
Andrei Oneadcb67732019-03-18 11:37:25 +0000786 @UnsupportedAppUsage
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700787 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
788
789 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700790 * Specifies if a user is not allowed to run in the background and should be stopped during
791 * user switch. The default value is <code>false</code>.
792 *
793 * <p>This restriction can be set by device owners and profile owners.
794 *
795 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
796 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
797 * @see #getUserRestrictions()
798 * @hide
799 */
Robin Lee6cfb7a92017-12-18 15:14:46 +0100800 @SystemApi
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700801 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
802
803 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700804 * Specifies if a user is not allowed to use the camera.
805 *
806 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
807 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
808 * @see #getUserRestrictions()
809 * @hide
810 */
811 public static final String DISALLOW_CAMERA = "no_camera";
812
813 /**
Tony Makc1205112016-07-22 16:02:59 +0100814 * Specifies if a user is not allowed to unmute the device's master volume.
815 *
816 * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
817 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
818 * @see #getUserRestrictions()
819 * @hide
820 */
Esteban Talavera492b4722017-02-13 14:59:45 +0000821 public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
Tony Makc1205112016-07-22 16:02:59 +0100822
823 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000824 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
825 * device owners. The default value is <code>false</code>.
826 *
827 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
828 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
829 * @see #getUserRestrictions()
830 */
831 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
832
833 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100834 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
835 * can set this restriction. When it is set by device owner, only the target user will be
836 * affected. The default value is <code>false</code>.
837 *
838 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100839 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100840 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
841 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
842 * @see #getUserRestrictions()
843 */
844 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
845
846 /**
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100847 * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100848 * <code>false</code>. Setting this restriction has no effect if the bootloader is already
849 * unlocked.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100850 *
Lenka Trochtova12b04962016-11-29 21:00:12 +0100851 * <p>Not for use by third-party applications.
852 *
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100853 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
854 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
855 * @see #getUserRestrictions()
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000856 * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100857 * @hide
858 */
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000859 @Deprecated
Lenka Trochtova12b04962016-11-29 21:00:12 +0100860 @SystemApi
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100861 public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
862
863 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +0100864 * Specifies that the managed profile is not allowed to have unified lock screen challenge with
865 * the primary user.
866 *
867 * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a
868 * separate challenge. Profile owner can ask the user to set a new password using
869 * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using
870 * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}.
871 *
872 * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed
873 * profile owner. Has no effect on non-managed profiles or users.
874 * <p>Key for user restrictions.
875 * <p>Type: Boolean
876 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
877 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
878 * @see #getUserRestrictions()
879 */
880 public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password";
881
882 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700883 * Allows apps in the parent profile to handle web links from the managed profile.
884 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700885 * This user restriction has an effect only in a managed profile.
886 * If set:
887 * Intent filters of activities in the parent profile with action
888 * {@link android.content.Intent#ACTION_VIEW},
889 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
890 * define a host can handle intents from the managed profile.
891 * The default value is <code>false</code>.
892 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800893 * <p>Key for user restrictions.
894 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700895 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
896 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700897 * @see #getUserRestrictions()
898 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700899 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
900 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700901
902 /**
Felipe Leme24d58932017-03-21 14:13:58 -0700903 * Specifies if a user is not allowed to use Autofill Services.
904 *
905 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
906 * only the target user will be affected.
907 *
908 * <p>The default value is <code>false</code>.
909 *
910 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
911 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
912 * @see #getUserRestrictions()
913 */
914 public static final String DISALLOW_AUTOFILL = "no_autofill";
915
916 /**
Benjamin Franzff66fa92017-08-10 10:39:44 +0100917 * Specifies if user switching is blocked on the current user.
918 *
919 * <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 +0800920 * Device owner can still switch user via
921 * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is
922 * set.
Benjamin Franzff66fa92017-08-10 10:39:44 +0100923 *
924 * <p>The default value is <code>false</code>.
925 *
926 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
927 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
928 * @see #getUserRestrictions()
929 */
930 public static final String DISALLOW_USER_SWITCH = "no_user_switch";
931
932 /**
Rubin Xucc391c22018-01-02 20:37:35 +0000933 * Specifies whether the user can share file / picture / data from the primary user into the
934 * managed profile, either by sending them from the primary side, or by picking up data within
935 * an app in the managed profile.
936 * <p>
937 * When a managed profile is created, the system allows the user to send data from the primary
938 * side to the profile by setting up certain default cross profile intent filters. If
939 * this is undesired, this restriction can be set to disallow it. Note that this restriction
940 * will not block any sharing allowed by explicit
941 * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner.
942 * <p>
943 * This restriction is only meaningful when set by profile owner. When it is set by device
944 * owner, it does not have any effect.
945 * <p>
946 * The default value is <code>false</code>.
947 *
948 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
949 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
950 * @see #getUserRestrictions()
951 */
952 public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile";
Vladislav Kuzkokov622b9f92018-01-25 16:33:05 +0100953
954 /**
955 * Specifies whether the user is allowed to print.
956 *
957 * This restriction can be set by device or profile owner.
958 *
959 * The default value is {@code false}.
960 *
961 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
962 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
963 * @see #getUserRestrictions()
964 */
965 public static final String DISALLOW_PRINTING = "no_printing";
966
Rubin Xucc391c22018-01-02 20:37:35 +0000967 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000968 * Application restriction key that is used to indicate the pending arrival
969 * of real restrictions for the app.
970 *
971 * <p>
972 * Applications that support restrictions should check for the presence of this key.
973 * A <code>true</code> value indicates that restrictions may be applied in the near
974 * future but are not available yet. It is the responsibility of any
975 * management application that sets this flag to update it when the final
976 * restrictions are enforced.
977 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800978 * <p>Key for application restrictions.
979 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +0000980 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
981 * android.content.ComponentName, String, Bundle)
982 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
983 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000984 */
985 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
986
Amith Yamasani12747872015-12-07 14:19:49 -0800987 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
988
989 /**
990 * Extra containing a name for the user being created. Optional parameter passed to
991 * ACTION_CREATE_USER activity.
992 * @hide
993 */
994 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
995
996 /**
997 * Extra containing account name for the user being created. Optional parameter passed to
998 * ACTION_CREATE_USER activity.
999 * @hide
1000 */
1001 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
1002
1003 /**
1004 * Extra containing account type for the user being created. Optional parameter passed to
1005 * ACTION_CREATE_USER activity.
1006 * @hide
1007 */
1008 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
1009
1010 /**
1011 * Extra containing account-specific data for the user being created. Optional parameter passed
1012 * to ACTION_CREATE_USER activity.
1013 * @hide
1014 */
1015 public static final String EXTRA_USER_ACCOUNT_OPTIONS
1016 = "android.os.extra.USER_ACCOUNT_OPTIONS";
1017
Amith Yamasani655d0e22013-06-12 14:19:10 -07001018 /** @hide */
1019 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
1020 /** @hide */
1021 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
1022 /** @hide */
1023 public static final int PIN_VERIFICATION_SUCCESS = -1;
1024
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001025 /**
Makoto Onukie72f81b2017-03-16 14:08:19 -07001026 * Sent when user restrictions have changed.
1027 *
1028 * @hide
1029 */
1030 @SystemApi
1031 @TestApi // To allow seeing it from CTS.
1032 public static final String ACTION_USER_RESTRICTIONS_CHANGED =
1033 "android.os.action.USER_RESTRICTIONS_CHANGED";
1034
1035 /**
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001036 * Error result indicating that this user is not allowed to add other users on this device.
1037 * This is a result code returned from the activity created by the intent
1038 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1039 */
1040 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
1041
1042 /**
1043 * Error result indicating that no more users can be created on this device.
1044 * This is a result code returned from the activity created by the intent
1045 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1046 */
1047 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
1048
Alex Chau89386ba2018-02-13 11:09:17 +08001049 /**
1050 * Indicates user operation is successful.
1051 */
1052 public static final int USER_OPERATION_SUCCESS = 0;
1053
1054 /**
1055 * Indicates user operation failed for unknown reason.
1056 */
1057 public static final int USER_OPERATION_ERROR_UNKNOWN = 1;
1058
1059 /**
1060 * Indicates user operation failed because target user is a managed profile.
1061 */
1062 public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2;
1063
1064 /**
1065 * Indicates user operation failed because maximum running user limit has been reached.
1066 */
1067 public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3;
1068
1069 /**
1070 * Indicates user operation failed because the target user is in the foreground.
1071 */
1072 public static final int USER_OPERATION_ERROR_CURRENT_USER = 4;
1073
1074 /**
1075 * Indicates user operation failed because device has low data storage.
1076 */
1077 public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5;
1078
1079 /**
1080 * Indicates user operation failed because maximum user limit has been reached.
1081 */
1082 public static final int USER_OPERATION_ERROR_MAX_USERS = 6;
1083
1084 /**
1085 * Result returned from various user operations.
1086 *
1087 * @hide
1088 */
1089 @Retention(RetentionPolicy.SOURCE)
1090 @IntDef(prefix = { "USER_OPERATION_" }, value = {
1091 USER_OPERATION_SUCCESS,
1092 USER_OPERATION_ERROR_UNKNOWN,
1093 USER_OPERATION_ERROR_MANAGED_PROFILE,
1094 USER_OPERATION_ERROR_MAX_RUNNING_USERS,
1095 USER_OPERATION_ERROR_CURRENT_USER,
1096 USER_OPERATION_ERROR_LOW_STORAGE,
1097 USER_OPERATION_ERROR_MAX_USERS
1098 })
1099 public @interface UserOperationResult {}
1100
1101 /**
1102 * Thrown to indicate user operation failed.
1103 */
1104 public static class UserOperationException extends RuntimeException {
1105 private final @UserOperationResult int mUserOperationResult;
1106
1107 /**
1108 * Constructs a UserOperationException with specific result code.
1109 *
1110 * @param message the detail message
1111 * @param userOperationResult the result code
1112 * @hide
1113 */
1114 public UserOperationException(String message,
1115 @UserOperationResult int userOperationResult) {
1116 super(message);
1117 mUserOperationResult = userOperationResult;
1118 }
1119
1120 /**
1121 * Returns the operation result code.
1122 */
1123 public @UserOperationResult int getUserOperationResult() {
1124 return mUserOperationResult;
1125 }
1126 }
1127
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001128 /** @hide */
Andrei Oneadcb67732019-03-18 11:37:25 +00001129 @UnsupportedAppUsage
Amith Yamasanic0688302015-10-30 10:40:03 -07001130 public static UserManager get(Context context) {
1131 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -07001132 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001133
Amith Yamasani258848d2012-08-10 17:06:33 -07001134 /** @hide */
1135 public UserManager(Context context, IUserManager service) {
1136 mService = service;
Fyodor Kupolov5200e1c2016-10-17 18:46:16 -07001137 mContext = context.getApplicationContext();
Amith Yamasani258848d2012-08-10 17:06:33 -07001138 }
1139
1140 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001141 * Returns whether this device supports multiple users with their own login and customizable
1142 * space.
1143 * @return whether the device supports multiple users.
Amith Yamasani258848d2012-08-10 17:06:33 -07001144 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -07001145 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +00001146 return getMaxSupportedUsers() > 1
1147 && SystemProperties.getBoolean("fw.show_multiuserui",
1148 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -07001149 }
1150
Maggie Benthall67944582013-02-22 14:58:27 -05001151 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001152 * @hide
1153 * @return Whether the device is running with split system user. It means the system user and
1154 * primary user are two separate users. Previously system user and primary user are combined as
1155 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
1156 */
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001157 @TestApi
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001158 public static boolean isSplitSystemUser() {
John Reckaa67f682016-09-20 14:24:21 -07001159 return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001160 }
1161
1162 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001163 * @return Whether guest user is always ephemeral
1164 * @hide
1165 */
1166 public static boolean isGuestUserEphemeral() {
1167 return Resources.getSystem()
1168 .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
1169 }
1170
1171 /**
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001172 * Returns whether switching users is currently allowed.
1173 * <p>For instance switching users is not allowed if the current user is in a phone call,
Benjamin Franzff66fa92017-08-10 10:39:44 +01001174 * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set.
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001175 * @hide
1176 */
1177 public boolean canSwitchUsers() {
1178 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
1179 mContext.getContentResolver(),
1180 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
1181 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
1182 boolean inCall = TelephonyManager.getDefault().getCallState()
1183 != TelephonyManager.CALL_STATE_IDLE;
Benjamin Franzff66fa92017-08-10 10:39:44 +01001184 boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
1185 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
1186 && !isUserSwitchDisallowed;
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001187 }
1188
1189 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001190 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +01001191 *
Amith Yamasani5760e172015-04-17 18:42:41 -07001192 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -07001193 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -05001194 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001195 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001196 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001197 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -07001198 }
1199
1200 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001201 * Returns the user name of the user making this call. This call is only
1202 * available to applications on the system image; it requires the
1203 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001204 * @return the user name
1205 */
1206 public String getUserName() {
Will Harmond9dcfb12017-05-18 15:41:15 -07001207 UserInfo user = getUserInfo(getUserHandle());
1208 return user == null ? "" : user.name;
Amith Yamasani258848d2012-08-10 17:06:33 -07001209 }
1210
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001211 /**
Fyodor Kupolov605b12a2017-05-10 15:58:09 -07001212 * Returns whether user name has been set.
1213 * <p>This method can be used to check that the value returned by {@link #getUserName()} was
1214 * set by the user and is not a placeholder string provided by the system.
1215 * @hide
1216 */
1217 public boolean isUserNameSet() {
1218 try {
1219 return mService.isUserNameSet(getUserHandle());
1220 } catch (RemoteException re) {
1221 throw re.rethrowFromSystemServer();
1222 }
1223 }
1224
1225 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -07001226 * Used to determine whether the user making this call is subject to
1227 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001228 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001229 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001230 * now automatically identify goats using advanced goat recognition technology.</p>
1231 *
1232 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -07001233 */
1234 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -07001235 return mContext.getPackageManager()
1236 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -07001237 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001238
1239 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001240 * Used to check if this process is running under the primary user. The primary user
1241 * is the first human user on a device.
1242 *
1243 * @return whether this process is running under the primary user.
1244 * @hide
1245 */
1246 public boolean isPrimaryUser() {
1247 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001248 return user != null && user.isPrimary();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001249 }
1250
1251 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001252 * Used to check if this process is running under the system user. The system user
1253 * is the initial user that is implicitly created on first boot and hosts most of the
1254 * system services.
1255 *
1256 * @return whether this process is running under the system user.
1257 */
1258 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001259 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -07001260 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001261
Amith Yamasani5760e172015-04-17 18:42:41 -07001262 /**
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001263 * @hide
1264 * Returns whether the caller is running as an admin user. There can be more than one admin
1265 * user.
1266 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001267 @UnsupportedAppUsage
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001268 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001269 return isUserAdmin(UserHandle.myUserId());
1270 }
1271
1272 /**
1273 * @hide
1274 * Returns whether the provided user is an admin user. There can be more than one admin
1275 * user.
1276 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001277 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001278 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001279 UserInfo user = getUserInfo(userId);
1280 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001281 }
1282
1283 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001284 * @hide
1285 * @deprecated Use {@link #isRestrictedProfile()}
1286 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001287 @UnsupportedAppUsage
Fyodor Kupolovca177562017-11-09 17:43:01 -08001288 @Deprecated
1289 public boolean isLinkedUser() {
1290 return isRestrictedProfile();
1291 }
1292
1293 /**
1294 * Returns whether the caller is running as restricted profile. Restricted profile may have
Amith Yamasani46bc4eb2013-04-12 13:26:50 -07001295 * a reduced number of available apps, app restrictions and account restrictions.
Amith Yamasanie1375902013-04-13 16:48:35 -07001296 * @return whether the user making this call is a linked user
Amith Yamasani2555daf2013-04-25 13:39:27 -07001297 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001298 */
Fyodor Kupolovca177562017-11-09 17:43:01 -08001299 @SystemApi
1300 public boolean isRestrictedProfile() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001301 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001302 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001303 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001304 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001305 }
1306 }
1307
Amith Yamasani258848d2012-08-10 17:06:33 -07001308 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001309 * Checks if specified user can have restricted profile.
1310 * @hide
1311 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001312 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001313 try {
1314 return mService.canHaveRestrictedProfile(userId);
1315 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001316 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001317 }
1318 }
1319
1320 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001321 * Returns whether the calling user has at least one restricted profile associated with it.
1322 * @return
1323 * @hide
1324 */
1325 @SystemApi
1326 public boolean hasRestrictedProfiles() {
1327 try {
1328 return mService.hasRestrictedProfiles();
1329 } catch (RemoteException re) {
1330 throw re.rethrowFromSystemServer();
1331 }
1332 }
1333
1334 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001335 * Checks if a user is a guest user.
1336 * @return whether user is a guest user.
1337 * @hide
1338 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001339 @UnsupportedAppUsage
Evan Rosky13a58a92016-07-27 15:51:09 -07001340 public boolean isGuestUser(int id) {
1341 UserInfo user = getUserInfo(id);
1342 return user != null && user.isGuest();
1343 }
1344
1345 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001346 * Checks if the calling app is running as a guest user.
1347 * @return whether the caller is a guest user.
1348 * @hide
1349 */
1350 public boolean isGuestUser() {
1351 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001352 return user != null && user.isGuest();
1353 }
1354
Fyodor Kupolovca177562017-11-09 17:43:01 -08001355
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001356 /**
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001357 * Checks if the calling app is running in a demo user. When running in a demo user,
1358 * apps can be more helpful to the user, or explain their features in more detail.
1359 *
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001360 * @return whether the caller is a demo user.
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001361 */
1362 public boolean isDemoUser() {
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001363 try {
1364 return mService.isDemoUser(UserHandle.myUserId());
1365 } catch (RemoteException re) {
1366 throw re.rethrowFromSystemServer();
1367 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001368 }
1369
1370 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001371 * Checks if the calling app is running in a managed profile.
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001372 *
1373 * @return whether the caller is in a managed profile.
1374 * @hide
1375 */
1376 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001377 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001378 public boolean isManagedProfile() {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001379 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1380 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1381 if (mIsManagedProfileCached != null) {
1382 return mIsManagedProfileCached;
1383 }
Tony Mak8673b282016-03-21 21:10:59 +00001384 try {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001385 mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1386 return mIsManagedProfileCached;
Tony Mak8673b282016-03-21 21:10:59 +00001387 } catch (RemoteException re) {
1388 throw re.rethrowFromSystemServer();
1389 }
1390 }
1391
1392 /**
1393 * Checks if the specified user is a managed profile.
1394 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1395 * must be in the same profile group of specified user.
1396 *
1397 * @return whether the specified user is a managed profile.
1398 * @hide
1399 */
1400 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001401 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Tony Mak8673b282016-03-21 21:10:59 +00001402 public boolean isManagedProfile(@UserIdInt int userId) {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001403 if (userId == UserHandle.myUserId()) {
1404 return isManagedProfile();
1405 }
Tony Mak8673b282016-03-21 21:10:59 +00001406 try {
1407 return mService.isManagedProfile(userId);
1408 } catch (RemoteException re) {
1409 throw re.rethrowFromSystemServer();
1410 }
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001411 }
1412
1413 /**
Kenny Guy02c89902016-11-15 19:36:38 +00001414 * Gets badge for a managed profile.
1415 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1416 * must be in the same profile group of specified user.
1417 *
1418 * @return which badge to use for the managed profile badge id will be less than
1419 * UserManagerService.getMaxManagedProfiles()
1420 * @hide
1421 */
1422 public int getManagedProfileBadge(@UserIdInt int userId) {
1423 try {
1424 return mService.getManagedProfileBadge(userId);
1425 } catch (RemoteException re) {
1426 throw re.rethrowFromSystemServer();
1427 }
1428 }
1429
1430 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001431 * Checks if the calling app is running as an ephemeral user.
1432 *
1433 * @return whether the caller is an ephemeral user.
1434 * @hide
1435 */
1436 public boolean isEphemeralUser() {
1437 return isUserEphemeral(UserHandle.myUserId());
1438 }
1439
1440 /**
1441 * Returns whether the specified user is ephemeral.
1442 * @hide
1443 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001444 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001445 final UserInfo user = getUserInfo(userId);
1446 return user != null && user.isEphemeral();
1447 }
1448
1449 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001450 * Return whether the given user is actively running. This means that
1451 * the user is in the "started" state, not "stopped" -- it is currently
1452 * allowed to run code through scheduled alarms, receiving broadcasts,
1453 * etc. A started user may be either the current foreground user or a
1454 * background user; the result here does not distinguish between the two.
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001455 *
1456 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1457 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1458 * in order to check other profile's status.
1459 * Since Android Nougat MR1 (SDK version >= 25;
1460 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1461 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001462 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001463 * @param user The user to retrieve the running state for.
1464 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001465 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001466 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -07001467 return isUserRunning(user.getIdentifier());
1468 }
1469
1470 /** {@hide} */
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001471 public boolean isUserRunning(@UserIdInt int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001472 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001473 return mService.isUserRunning(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001474 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001475 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001476 }
1477 }
1478
1479 /**
1480 * Return whether the given user is actively running <em>or</em> stopping.
1481 * This is like {@link #isUserRunning(UserHandle)}, but will also return
1482 * true if the user had been running but is in the process of being stopped
1483 * (but is not yet fully stopped, and still running some code).
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001484 *
1485 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1486 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1487 * in order to check other profile's status.
1488 * Since Android Nougat MR1 (SDK version >= 25;
1489 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1490 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001491 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001492 * @param user The user to retrieve the running state for.
1493 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001494 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001495 public boolean isUserRunningOrStopping(UserHandle user) {
1496 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001497 // TODO: reconcile stopped vs stopping?
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001498 return ActivityManager.getService().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001499 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001500 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001501 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001502 }
1503 }
1504
Jeff Sharkey0825ab22015-12-02 13:04:49 -07001505 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001506 * Return whether the calling user is running in an "unlocked" state.
1507 * <p>
1508 * On devices with direct boot, a user is unlocked only after they've
1509 * entered their credentials (such as a lock pattern or PIN). On devices
1510 * without direct boot, a user is unlocked as soon as it starts.
1511 * <p>
1512 * When a user is locked, only device-protected data storage is available.
1513 * When a user is unlocked, both device-protected and credential-protected
1514 * private app data storage is available.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001515 *
1516 * @see Intent#ACTION_USER_UNLOCKED
1517 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001518 */
1519 public boolean isUserUnlocked() {
1520 return isUserUnlocked(Process.myUserHandle());
1521 }
1522
1523 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001524 * Return whether the given user is running in an "unlocked" state.
1525 * <p>
1526 * On devices with direct boot, a user is unlocked only after they've
1527 * entered their credentials (such as a lock pattern or PIN). On devices
1528 * without direct boot, a user is unlocked as soon as it starts.
1529 * <p>
1530 * When a user is locked, only device-protected data storage is available.
1531 * When a user is unlocked, both device-protected and credential-protected
1532 * private app data storage is available.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001533 * <p>Requires {@code android.permission.MANAGE_USERS} or
1534 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1535 * must be the calling user or a managed profile associated with it.
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001536 *
1537 * @param user to retrieve the unlocked state for.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001538 * @see Intent#ACTION_USER_UNLOCKED
1539 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001540 */
1541 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -07001542 return isUserUnlocked(user.getIdentifier());
1543 }
1544
1545 /** {@hide} */
Andrei Oneadcb67732019-03-18 11:37:25 +00001546 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001547 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001548 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001549 return mService.isUserUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001550 } catch (RemoteException re) {
1551 throw re.rethrowFromSystemServer();
1552 }
1553 }
1554
1555 /** {@hide} */
1556 public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1557 return isUserUnlockingOrUnlocked(user.getIdentifier());
1558 }
1559
1560 /** {@hide} */
1561 public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1562 try {
Fyodor Kupolovc413f702016-10-06 17:11:14 -07001563 return mService.isUserUnlockingOrUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001564 } catch (RemoteException re) {
1565 throw re.rethrowFromSystemServer();
1566 }
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001567 }
1568
1569 /**
Makoto Onuki73dded22017-12-20 13:14:48 +09001570 * Return the time when the calling user started in elapsed milliseconds since boot,
1571 * or 0 if not started.
1572 *
1573 * @hide
1574 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001575 @UnsupportedAppUsage
Makoto Onuki73dded22017-12-20 13:14:48 +09001576 public long getUserStartRealtime() {
1577 try {
1578 return mService.getUserStartRealtime();
1579 } catch (RemoteException re) {
1580 throw re.rethrowFromSystemServer();
1581 }
1582 }
1583
1584 /**
1585 * Return the time when the calling user was unlocked elapsed milliseconds since boot,
1586 * or 0 if not unlocked.
1587 *
1588 * @hide
1589 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001590 @UnsupportedAppUsage
Makoto Onuki73dded22017-12-20 13:14:48 +09001591 public long getUserUnlockRealtime() {
1592 try {
1593 return mService.getUserUnlockRealtime();
1594 } catch (RemoteException re) {
1595 throw re.rethrowFromSystemServer();
1596 }
1597 }
1598
1599 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001600 * Returns the UserInfo object describing a specific user.
Tony Mak8673b282016-03-21 21:10:59 +00001601 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001602 * @param userHandle the user handle of the user whose information is being requested.
1603 * @return the UserInfo object for a specific user.
1604 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001605 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001606 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001607 public UserInfo getUserInfo(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001608 try {
1609 return mService.getUserInfo(userHandle);
1610 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001611 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001612 }
1613 }
1614
Amith Yamasani71e6c692013-03-24 17:39:28 -07001615 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001616 * @hide
1617 *
1618 * Returns who set a user restriction on a user.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001619 * @param restrictionKey the string key representing the restriction
1620 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1621 * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1622 * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1623 * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
Pavel Grafov6a40f092016-10-25 15:46:51 +01001624 * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001625 */
Pavel Grafov6a40f092016-10-25 15:46:51 +01001626 @Deprecated
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001627 @SystemApi
1628 @UserRestrictionSource
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001629 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001630 public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1631 try {
1632 return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1633 } catch (RemoteException re) {
1634 throw re.rethrowFromSystemServer();
1635 }
1636 }
1637
1638 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +01001639 * @hide
1640 *
1641 * Returns a list of users who set a user restriction on a given user.
Pavel Grafov6a40f092016-10-25 15:46:51 +01001642 * @param restrictionKey the string key representing the restriction
1643 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1644 * @return a list of user ids enforcing this restriction.
1645 */
1646 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001647 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Pavel Grafov6a40f092016-10-25 15:46:51 +01001648 public List<EnforcingUser> getUserRestrictionSources(
1649 String restrictionKey, UserHandle userHandle) {
1650 try {
1651 return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
1652 } catch (RemoteException re) {
1653 throw re.rethrowFromSystemServer();
1654 }
1655 }
1656
1657 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07001658 * Returns the user-wide restrictions imposed on this user.
1659 * @return a Bundle containing all the restrictions.
1660 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001661 public Bundle getUserRestrictions() {
1662 return getUserRestrictions(Process.myUserHandle());
1663 }
1664
Amith Yamasani71e6c692013-03-24 17:39:28 -07001665 /**
1666 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
1667 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1668 * @return a Bundle containing all the restrictions.
1669 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001670 public Bundle getUserRestrictions(UserHandle userHandle) {
1671 try {
1672 return mService.getUserRestrictions(userHandle.getIdentifier());
1673 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001674 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001675 }
1676 }
1677
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001678 /**
1679 * @hide
1680 * Returns whether the given user has been disallowed from performing certain actions
1681 * or setting certain settings through UserManager. This method disregards restrictions
1682 * set by device policy.
1683 * @param restrictionKey the string key representing the restriction
1684 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1685 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001686 @UnsupportedAppUsage
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001687 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
1688 try {
1689 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
1690 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001691 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001692 }
1693 }
1694
Amith Yamasani71e6c692013-03-24 17:39:28 -07001695 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001696 * This will no longer work. Device owners and profile owners should use
1697 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001698 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001699 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001700 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001701 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001702 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001703 }
1704
Amith Yamasani71e6c692013-03-24 17:39:28 -07001705 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001706 * This will no longer work. Device owners and profile owners should use
1707 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001708 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001709 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001710 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001711 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001712 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001713 }
1714
Amith Yamasani71e6c692013-03-24 17:39:28 -07001715 /**
1716 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07001717 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001718 * @param key the key of the restriction
1719 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001720 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1721 * android.content.ComponentName, String)} or
1722 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1723 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001724 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001725 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07001726 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001727 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07001728 }
1729
1730 /**
1731 * @hide
1732 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07001733 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001734 * @param key the key of the restriction
1735 * @param value the value for the restriction
1736 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001737 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1738 * android.content.ComponentName, String)} or
1739 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1740 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001741 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001742 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05001743 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001744 try {
1745 mService.setUserRestriction(key, value, userHandle.getIdentifier());
1746 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001747 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001748 }
Maggie Benthall67944582013-02-22 14:58:27 -05001749 }
1750
Amith Yamasani258848d2012-08-10 17:06:33 -07001751 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001752 * Returns whether the current user has been disallowed from performing certain actions
1753 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04001754 *
1755 * @param restrictionKey The string key representing the restriction.
1756 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001757 */
1758 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -07001759 return hasUserRestriction(restrictionKey, Process.myUserHandle());
1760 }
1761
1762 /**
1763 * @hide
1764 * Returns whether the given user has been disallowed from performing certain actions
1765 * or setting certain settings.
1766 * @param restrictionKey the string key representing the restriction
1767 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1768 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001769 @UnsupportedAppUsage
David Christieb12ba932013-09-03 17:15:28 -07001770 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001771 try {
1772 return mService.hasUserRestriction(restrictionKey,
1773 userHandle.getIdentifier());
1774 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001775 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001776 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001777 }
1778
1779 /**
Makoto Onukiacc50462018-02-14 14:13:49 -08001780 * @hide
1781 * Returns whether any user on the device has the given user restriction set.
1782 */
1783 public boolean hasUserRestrictionOnAnyUser(String restrictionKey) {
1784 try {
1785 return mService.hasUserRestrictionOnAnyUser(restrictionKey);
1786 } catch (RemoteException re) {
1787 throw re.rethrowFromSystemServer();
1788 }
1789 }
1790
1791 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001792 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001793 * number assigned to that user; if the user is deleted and then a new
1794 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001795 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001796 * @return The serial number of the given user; returns -1 if the
1797 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001798 * @see #getUserForSerialNumber(long)
1799 */
1800 public long getSerialNumberForUser(UserHandle user) {
1801 return getUserSerialNumber(user.getIdentifier());
1802 }
1803
1804 /**
1805 * Return the user associated with a serial number previously
1806 * returned by {@link #getSerialNumberForUser(UserHandle)}.
1807 * @param serialNumber The serial number of the user that is being
1808 * retrieved.
1809 * @return Return the user associated with the serial number, or null
1810 * if there is not one.
1811 * @see #getSerialNumberForUser(UserHandle)
1812 */
1813 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07001814 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001815 return ident >= 0 ? new UserHandle(ident) : null;
1816 }
1817
1818 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001819 * Creates a user with the specified name and options. For non-admin users, default user
1820 * restrictions are going to be applied.
Amith Yamasani195263742012-08-21 15:40:12 -07001821 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001822 *
1823 * @param name the user's name
1824 * @param flags flags that identify the type of user and other properties.
1825 * @see UserInfo
1826 *
1827 * @return the UserInfo object for the created user, or null if the user could not be created.
1828 * @hide
1829 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001830 @UnsupportedAppUsage
Amith Yamasani258848d2012-08-10 17:06:33 -07001831 public UserInfo createUser(String name, int flags) {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001832 UserInfo user = null;
Amith Yamasani258848d2012-08-10 17:06:33 -07001833 try {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001834 user = mService.createUser(name, flags);
phweisse9c44062016-02-10 12:57:38 +01001835 // TODO: Keep this in sync with
1836 // UserManagerService.LocalService.createUserEvenWhenDisallowed
Christine Franks97a54802017-08-09 10:06:43 -07001837 if (user != null && !user.isAdmin() && !user.isDemo()) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001838 mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1839 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001840 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001841 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001842 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001843 }
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001844 return user;
Amith Yamasani258848d2012-08-10 17:06:33 -07001845 }
1846
1847 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001848 * Creates a guest user and configures it.
1849 * @param context an application context
1850 * @param name the name to set for the user
1851 * @hide
1852 */
1853 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001854 UserInfo guest = null;
1855 try {
1856 guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1857 if (guest != null) {
1858 Settings.Secure.putStringForUser(context.getContentResolver(),
1859 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001860 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07001861 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001862 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001863 }
1864 return guest;
1865 }
1866
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07001867 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001868 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001869 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1870 *
1871 * @param name the user's name
1872 * @param flags flags that identify the type of user and other properties.
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001873 * @param userHandle new user will be a profile of this user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001874 *
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001875 * @return the {@link UserInfo} object for the created user, or null if the user
1876 * could not be created.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001877 * @hide
1878 */
Andrei Oneadcb67732019-03-18 11:37:25 +00001879 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001880 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001881 return createProfileForUser(name, flags, userHandle, null);
1882 }
1883
1884 /**
1885 * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
1886 * any packages that should not be installed in the new profile by default, these packages can
1887 * still be installed later by the user if needed.
1888 *
1889 * @param name the user's name
1890 * @param flags flags that identify the type of user and other properties.
1891 * @param userHandle new user will be a profile of this user.
1892 * @param disallowedPackages packages that will not be installed in the profile being created.
1893 *
1894 * @return the {@link UserInfo} object for the created user, or null if the user
1895 * could not be created.
1896 * @hide
1897 */
1898 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
1899 String[] disallowedPackages) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001900 try {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001901 return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001902 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001903 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001904 }
1905 }
1906
1907 /**
Tony Mak6dc428f2016-10-10 15:48:27 +01001908 * Similar to {@link #createProfileForUser(String, int, int, String[])}
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001909 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
Tony Mak6dc428f2016-10-10 15:48:27 +01001910 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1911 *
1912 * @see #createProfileForUser(String, int, int, String[])
1913 * @hide
1914 */
1915 public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
1916 @UserIdInt int userHandle, String[] disallowedPackages) {
1917 try {
1918 return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
1919 disallowedPackages);
1920 } catch (RemoteException re) {
1921 throw re.rethrowFromSystemServer();
1922 }
1923 }
1924
1925 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001926 * Creates a restricted profile with the specified name. This method also sets necessary
1927 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001928 *
1929 * @param name profile's name
1930 * @return UserInfo object for the created user, or null if the user could not be created.
1931 * @hide
1932 */
1933 public UserInfo createRestrictedProfile(String name) {
1934 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001935 UserHandle parentUserHandle = Process.myUserHandle();
1936 UserInfo user = mService.createRestrictedProfile(name,
1937 parentUserHandle.getIdentifier());
1938 if (user != null) {
1939 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
1940 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001941 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001942 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001943 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001944 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001945 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001946 }
1947
1948 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001949 * Returns an intent to create a user for the provided name and account name. The name
1950 * and account name will be used when the setup process for the new user is started.
1951 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001952 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001953 * indicate if the user consented to adding a new user and if the operation succeeded. Any
1954 * errors in creating the user will be returned in the result code. If the user cancels the
1955 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
1956 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani06964342016-04-15 13:55:01 -07001957 * <p>
1958 * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
1959 * at all.
1960 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001961 * The new user is created but not initialized. After switching into the user for the first
1962 * time, the preferred user name and account information are used by the setup process for that
1963 * user.
1964 *
1965 * @param userName Optional name to assign to the user.
Amith Yamasani06964342016-04-15 13:55:01 -07001966 * @param accountName Optional account name that will be used by the setup wizard to initialize
Amith Yamasani12747872015-12-07 14:19:49 -08001967 * the user.
1968 * @param accountType Optional account type for the account to be created. This is required
1969 * if the account name is specified.
1970 * @param accountOptions Optional bundle of data to be passed in during account creation in the
1971 * new user via {@link AccountManager#addAccount(String, String, String[],
1972 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
1973 * Handler)}.
Amith Yamasani06964342016-04-15 13:55:01 -07001974 * @return An Intent that can be launched from an Activity.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001975 * @see #USER_CREATION_FAILED_NOT_PERMITTED
1976 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani06964342016-04-15 13:55:01 -07001977 * @see #supportsMultipleUsers
Amith Yamasani12747872015-12-07 14:19:49 -08001978 */
1979 public static Intent createUserCreationIntent(@Nullable String userName,
1980 @Nullable String accountName,
1981 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
Amith Yamasani12747872015-12-07 14:19:49 -08001982 Intent intent = new Intent(ACTION_CREATE_USER);
1983 if (userName != null) {
1984 intent.putExtra(EXTRA_USER_NAME, userName);
1985 }
1986 if (accountName != null && accountType == null) {
1987 throw new IllegalArgumentException("accountType must be specified if accountName is "
1988 + "specified");
1989 }
1990 if (accountName != null) {
1991 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
1992 }
1993 if (accountType != null) {
1994 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
1995 }
1996 if (accountOptions != null) {
1997 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
1998 }
1999 return intent;
2000 }
2001
2002 /**
2003 * @hide
2004 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002005 * Returns the preferred account name for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002006 */
2007 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002008 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002009 public String getSeedAccountName() {
2010 try {
2011 return mService.getSeedAccountName();
2012 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002013 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002014 }
2015 }
2016
2017 /**
2018 * @hide
2019 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002020 * Returns the preferred account type for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002021 */
2022 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002023 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002024 public String getSeedAccountType() {
2025 try {
2026 return mService.getSeedAccountType();
2027 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002028 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002029 }
2030 }
2031
2032 /**
2033 * @hide
2034 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002035 * Returns the preferred account's options bundle for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002036 * @return Any options set by the requestor that created the user.
2037 */
2038 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002039 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002040 public PersistableBundle getSeedAccountOptions() {
2041 try {
2042 return mService.getSeedAccountOptions();
2043 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002044 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002045 }
2046 }
2047
2048 /**
2049 * @hide
2050 *
2051 * Called by a system activity to set the seed account information of a user created
2052 * through the user creation intent.
2053 * @param userId
2054 * @param accountName
2055 * @param accountType
2056 * @param accountOptions
2057 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
2058 */
2059 public void setSeedAccountData(int userId, String accountName, String accountType,
2060 PersistableBundle accountOptions) {
2061 try {
2062 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
2063 /* persist= */ true);
2064 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002065 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002066 }
2067 }
2068
2069 /**
2070 * @hide
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002071 * Clears the seed information used to create this user.
Amith Yamasani12747872015-12-07 14:19:49 -08002072 */
2073 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002074 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002075 public void clearSeedAccountData() {
2076 try {
2077 mService.clearSeedAccountData();
2078 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002079 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002080 }
2081 }
2082
2083 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07002084 * @hide
2085 * Marks the guest user for deletion to allow a new guest to be created before deleting
2086 * the current user who is a guest.
2087 * @param userHandle
2088 * @return
2089 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002090 public boolean markGuestForDeletion(@UserIdInt int userHandle) {
Amith Yamasani1df14732014-08-29 21:37:27 -07002091 try {
2092 return mService.markGuestForDeletion(userHandle);
2093 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002094 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07002095 }
2096 }
2097
2098 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002099 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01002100 *
2101 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2102 *
2103 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
2104 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
2105 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002106 *
jovanakf24ad492018-05-18 12:15:59 -07002107 * @param userId the id of the profile to enable
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002108 * @hide
2109 */
jovanakf24ad492018-05-18 12:15:59 -07002110 public void setUserEnabled(@UserIdInt int userId) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002111 try {
jovanakf24ad492018-05-18 12:15:59 -07002112 mService.setUserEnabled(userId);
2113 } catch (RemoteException re) {
2114 throw re.rethrowFromSystemServer();
2115 }
2116 }
2117
2118 /**
2119 * Assigns admin privileges to the user, if such a user exists.
2120 *
2121 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} and
2122 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions.
2123 *
2124 * @param userHandle the id of the user to become admin
2125 * @hide
2126 */
2127 @RequiresPermission(allOf = {
2128 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2129 Manifest.permission.MANAGE_USERS
2130 })
2131 public void setUserAdmin(@UserIdInt int userHandle) {
2132 try {
2133 mService.setUserAdmin(userHandle);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002134 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002135 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002136 }
2137 }
2138
2139 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002140 * Evicts the user's credential encryption key from memory by stopping and restarting the user.
2141 *
2142 * @hide
2143 */
2144 public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
2145 try {
2146 mService.evictCredentialEncryptionKey(userHandle);
2147 } catch (RemoteException re) {
2148 throw re.rethrowFromSystemServer();
2149 }
2150 }
2151
2152 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002153 * Return the number of users currently created on the device.
2154 */
2155 public int getUserCount() {
2156 List<UserInfo> users = getUsers();
2157 return users != null ? users.size() : 1;
2158 }
2159
2160 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07002161 * Returns information for all users on this device, including ones marked for deletion.
2162 * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
2163 * <p>
Amith Yamasani195263742012-08-21 15:40:12 -07002164 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002165 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07002166 * @hide
2167 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002168 @UnsupportedAppUsage
Amith Yamasani258848d2012-08-10 17:06:33 -07002169 public List<UserInfo> getUsers() {
2170 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07002171 return mService.getUsers(false);
2172 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002173 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07002174 }
2175 }
2176
2177 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002178 * Returns serial numbers of all users on this device.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002179 *
2180 * @param excludeDying specify if the list should exclude users being removed.
2181 * @return the list of serial numbers of users that exist on the device.
2182 * @hide
2183 */
2184 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002185 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002186 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
2187 try {
2188 List<UserInfo> users = mService.getUsers(excludeDying);
2189 long[] result = new long[users.size()];
2190 for (int i = 0; i < result.length; i++) {
2191 result[i] = users.get(i).serialNumber;
2192 }
2193 return result;
2194 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002195 throw re.rethrowFromSystemServer();
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002196 }
2197 }
2198
2199 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002200 * @return the user's account name, null if not found.
2201 * @hide
2202 */
2203 @RequiresPermission( allOf = {
2204 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2205 Manifest.permission.MANAGE_USERS
2206 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002207 public @Nullable String getUserAccount(@UserIdInt int userHandle) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002208 try {
2209 return mService.getUserAccount(userHandle);
2210 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002211 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002212 }
2213 }
2214
2215 /**
2216 * Set account name for the given user.
2217 * @hide
2218 */
2219 @RequiresPermission( allOf = {
2220 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2221 Manifest.permission.MANAGE_USERS
2222 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002223 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002224 try {
2225 mService.setUserAccount(userHandle, accountName);
2226 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002227 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002228 }
2229 }
2230
2231 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002232 * Returns information for Primary user.
2233 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2234 *
2235 * @return the Primary user, null if not found.
2236 * @hide
2237 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002238 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002239 try {
2240 return mService.getPrimaryUser();
2241 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002242 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002243 }
2244 }
2245
2246 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07002247 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
2248 * permission.
2249 *
2250 * @return true if more users can be added, false if limit has been reached.
2251 * @hide
2252 */
2253 public boolean canAddMoreUsers() {
2254 final List<UserInfo> users = getUsers(true);
2255 final int totalUserCount = users.size();
2256 int aliveUserCount = 0;
2257 for (int i = 0; i < totalUserCount; i++) {
2258 UserInfo user = users.get(i);
2259 if (!user.isGuest()) {
2260 aliveUserCount++;
2261 }
2262 }
2263 return aliveUserCount < getMaxSupportedUsers();
2264 }
2265
2266 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07002267 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
2268 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002269 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
2270 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07002271 *
2272 * @return true if more managed profiles can be added, false if limit has been reached.
2273 * @hide
2274 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002275 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07002276 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002277 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07002278 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002279 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07002280 }
2281 }
2282
2283 /**
Kenny Guy2a764942014-04-02 13:29:20 +01002284 * Returns list of the profiles of userHandle including
2285 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07002286 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07002287 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08002288 *
Kenny Guy2a764942014-04-02 13:29:20 +01002289 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2290 * @param userHandle profiles of this user will be returned.
2291 * @return the list of profiles.
2292 * @hide
2293 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002294 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002295 public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00002296 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002297 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00002298 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002299 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00002300 }
2301 }
2302
2303 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002304 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2305 * @param userId one of the two user ids to check.
2306 * @param otherUserId one of the two user ids to check.
2307 * @return true if the two user ids are in the same profile group.
2308 * @hide
2309 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002310 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002311 try {
2312 return mService.isSameProfileGroup(userId, otherUserId);
2313 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002314 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002315 }
2316 }
2317
2318 /**
Ruben Brunk7f75da22015-04-30 17:46:30 -07002319 * Returns list of the profiles of userHandle including
2320 * userHandle itself.
2321 * Note that this returns only enabled.
2322 *
2323 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2324 * @param userHandle profiles of this user will be returned.
2325 * @return the list of profiles.
2326 * @hide
2327 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002328 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002329 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07002330 try {
2331 return mService.getProfiles(userHandle, true /* enabledOnly */);
2332 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002333 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07002334 }
2335 }
2336
2337 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002338 * Returns a list of UserHandles for profiles associated with the user that the calling process
2339 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08002340 *
2341 * @return A non-empty list of UserHandles associated with the calling user.
2342 */
2343 public List<UserHandle> getUserProfiles() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002344 int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
2345 List<UserHandle> result = new ArrayList<>(userIds.length);
2346 for (int userId : userIds) {
2347 result.add(UserHandle.of(userId));
2348 }
2349 return result;
2350 }
2351
2352 /**
2353 * Returns a list of ids for profiles associated with the specified user including the user
2354 * itself.
2355 *
2356 * @param userId id of the user to return profiles for
2357 * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
2358 * @return A non-empty list of ids of profiles associated with the specified user.
2359 *
2360 * @hide
2361 */
2362 public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002363 try {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002364 return mService.getProfileIds(userId, enabledOnly);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002365 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002366 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002367 }
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002368 }
2369
2370 /**
2371 * @see #getProfileIds(int, boolean)
2372 * @hide
2373 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002374 @UnsupportedAppUsage
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002375 public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
2376 return getProfileIds(userId, false /* enabledOnly */);
2377 }
2378
2379 /**
2380 * @see #getProfileIds(int, boolean)
2381 * @hide
2382 */
2383 public int[] getEnabledProfileIds(@UserIdInt int userId) {
2384 return getProfileIds(userId, true /* enabledOnly */);
Amith Yamasani4f582632014-02-19 14:31:52 -08002385 }
2386
Amith Yamasani7dda2652014-04-11 14:57:12 -07002387 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07002388 * Returns the device credential owner id of the profile from
2389 * which this method is called, or userHandle if called from a user that
2390 * is not a profile.
2391 *
2392 * @hide
2393 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002394 public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
Andres Moralesc5548c02015-08-05 10:23:12 -07002395 try {
2396 return mService.getCredentialOwnerProfile(userHandle);
2397 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002398 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07002399 }
2400 }
2401
2402 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002403 * Returns the parent of the profile which this method is called from
2404 * or null if called from a user that is not a profile.
2405 *
2406 * @hide
2407 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002408 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002409 public UserInfo getProfileParent(@UserIdInt int userHandle) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01002410 try {
2411 return mService.getProfileParent(userHandle);
2412 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002413 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01002414 }
2415 }
2416
2417 /**
Tony Make3d1f652017-12-12 11:00:37 +00002418 * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a
2419 * managed profile don't run, generate notifications, or consume data or battery.
2420 * <p>
2421 * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be
2422 * shown to the user.
2423 * <p>
2424 * The change may not happen instantly, however apps can listen for
2425 * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and
2426 * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of
2427 * the change of the quiet mode. Apps can also check the current state of quiet mode by
2428 * calling {@link #isQuietModeEnabled(UserHandle)}.
2429 * <p>
2430 * The caller must either be the foreground default launcher or have one of these permissions:
2431 * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002432 *
Tony Make3d1f652017-12-12 11:00:37 +00002433 * @param enableQuietMode whether quiet mode should be enabled or disabled
2434 * @param userHandle user handle of the profile
2435 * @return {@code false} if user's credential is needed in order to turn off quiet mode,
2436 * {@code true} otherwise
2437 * @throws SecurityException if the caller is invalid
2438 * @throws IllegalArgumentException if {@code userHandle} is not a managed profile
2439 *
2440 * @see #isQuietModeEnabled(UserHandle)
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002441 */
Tony Makbece85d2018-01-12 12:10:17 +00002442 public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) {
2443 return requestQuietModeEnabled(enableQuietMode, userHandle, null);
Tony Makb7e6fd42017-12-05 19:40:28 +00002444 }
2445
2446 /**
Tony Makbece85d2018-01-12 12:10:17 +00002447 * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify
Tony Makd390ae92017-12-28 13:23:10 +00002448 * a target to start when user is unlocked. If {@code target} is specified, caller must have
2449 * the {@link android.Manifest.permission#MANAGE_USERS} permission.
Tony Makb7e6fd42017-12-05 19:40:28 +00002450 *
Tony Makbece85d2018-01-12 12:10:17 +00002451 * @see {@link #requestQuietModeEnabled(boolean, UserHandle)}
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002452 * @hide
2453 */
Tony Makbece85d2018-01-12 12:10:17 +00002454 public boolean requestQuietModeEnabled(
Tony Makb7e6fd42017-12-05 19:40:28 +00002455 boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002456 try {
Tony Makbece85d2018-01-12 12:10:17 +00002457 return mService.requestQuietModeEnabled(
Tony Make3d1f652017-12-12 11:00:37 +00002458 mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002459 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002460 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002461 }
2462 }
2463
2464 /**
2465 * Returns whether the given profile is in quiet mode or not.
Ricky Wai7881cf82016-04-15 17:20:12 +01002466 * Notes: Quiet mode is only supported for managed profiles.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002467 *
2468 * @param userHandle The user handle of the profile to be queried.
2469 * @return true if the profile is in quiet mode, false otherwise.
2470 */
2471 public boolean isQuietModeEnabled(UserHandle userHandle) {
2472 try {
2473 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002474 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002475 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002476 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002477 }
2478
2479 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -07002480 * If the target user is a managed profile of the calling user or the caller
2481 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07002482 * icon to be able to distinguish it from the original icon. For badging an
2483 * arbitrary drawable use {@link #getBadgedDrawableForUser(
2484 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2485 * <p>
2486 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002487 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002488 * is performed in place and the original drawable is returned.
2489 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07002490 *
2491 * @param icon The icon to badge.
2492 * @param user The target user.
2493 * @return A drawable that combines the original icon and a badge as
2494 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002495 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07002496 */
Svetoslavc71c42f2014-08-05 18:57:05 -07002497 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002498 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002499 }
2500
Kenny Guy701ea7c2014-05-08 23:34:12 +01002501 /**
2502 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -07002503 * is itself a managed profile, then this returns a badged copy of the given
2504 * drawable allowing the user to distinguish it from the original drawable.
2505 * The caller can specify the location in the bounds of the drawable to be
2506 * badged where the badge should be applied as well as the density of the
2507 * badge to be used.
2508 * <p>
2509 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002510 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002511 * is performed in place and the original drawable is returned.
2512 * </p>
2513 *
2514 * @param badgedDrawable The drawable to badge.
2515 * @param user The target user.
2516 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002517 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07002518 * drawable being badged.
2519 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002520 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07002521 * the density of the display is used.
2522 * @return A drawable that combines the original drawable and a badge as
2523 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002524 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07002525 */
2526 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2527 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002528 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2529 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07002530 }
2531
2532 /**
2533 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002534 * is itself a managed profile, then this returns a copy of the label with
2535 * badging for accessibility services like talkback. E.g. passing in "Email"
2536 * and it might return "Work Email" for Email in the work profile.
2537 *
2538 * @param label The label to change.
2539 * @param user The target user.
2540 * @return A label that combines the original label and a badge as
2541 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002542 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002543 */
Kenny Guy237aecd2014-07-21 14:06:09 +01002544 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002545 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002546 }
2547
2548 /**
2549 * Returns information for all users on this device. Requires
2550 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04002551 *
Amith Yamasani4f582632014-02-19 14:31:52 -08002552 * @param excludeDying specify if the list should exclude users being
2553 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07002554 * @return the list of users that were created.
2555 * @hide
2556 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002557 @UnsupportedAppUsage
Adam Lesinskiada8deb2017-05-12 13:50:42 -07002558 public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
Amith Yamasani920ace02012-09-20 22:15:37 -07002559 try {
2560 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07002561 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002562 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002563 }
2564 }
2565
2566 /**
2567 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07002568 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002569 * @param userHandle the integer handle of the user, where 0 is the primary user.
2570 * @hide
2571 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002572 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002573 public boolean removeUser(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002574 try {
2575 return mService.removeUser(userHandle);
2576 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002577 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002578 }
2579 }
2580
2581 /**
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00002582 * Similar to {@link #removeUser(int)} except bypassing the checking of
2583 * {@link UserManager#DISALLOW_REMOVE_USER}
2584 * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2585 *
2586 * @see {@link #removeUser(int)}
2587 * @hide
2588 */
2589 public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2590 try {
2591 return mService.removeUserEvenWhenDisallowed(userHandle);
2592 } catch (RemoteException re) {
2593 throw re.rethrowFromSystemServer();
2594 }
2595 }
2596
2597 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002598 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07002599 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002600 *
2601 * @param userHandle the user's integer handle
2602 * @param name the new name for the user
2603 * @hide
2604 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002605 public void setUserName(@UserIdInt int userHandle, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002606 try {
2607 mService.setUserName(userHandle, name);
2608 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002609 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002610 }
2611 }
2612
2613 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002614 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002615 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002616 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002617 * @hide
2618 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002619 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002620 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002621 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07002622 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002623 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002624 }
2625 }
2626
2627 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07002628 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
2629 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002630 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002631 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07002632 * @hide
2633 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002634 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002635 public Bitmap getUserIcon(@UserIdInt int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07002636 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01002637 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
2638 if (fd != null) {
2639 try {
2640 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
2641 } finally {
2642 try {
2643 fd.close();
2644 } catch (IOException e) {
2645 }
2646 }
2647 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07002648 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002649 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07002650 }
Adrian Roos1bdff912015-02-17 15:51:35 +01002651 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07002652 }
2653
2654 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002655 * Returns the maximum number of users that can be created on this device. A return value
2656 * of 1 means that it is a single user device.
2657 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002658 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07002659 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002660 @UnsupportedAppUsage
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002661 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07002662 // Don't allow multiple users on certain builds
2663 if (android.os.Build.ID.startsWith("JVP")) return 1;
Robin Lee83c79312018-02-09 19:27:18 +01002664 if (ActivityManager.isLowRamDeviceStatic()) {
2665 // Low-ram devices are Svelte. Most of the time they don't get multi-user.
2666 if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
2667 != Configuration.UI_MODE_TYPE_TELEVISION) {
2668 return 1;
2669 }
2670 }
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002671 return SystemProperties.getInt("fw.max_users",
2672 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07002673 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002674
2675 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002676 * Returns true if the user switcher should be shown, this will be if device supports multi-user
2677 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00002678 * @hide
2679 * @return true if user switcher should be shown.
2680 */
2681 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002682 if (!supportsMultipleUsers()) {
2683 return false;
2684 }
Benjamin Franzff66fa92017-08-10 10:39:44 +01002685 if (hasUserRestriction(DISALLOW_USER_SWITCH)) {
2686 return false;
2687 }
Amith Yamasanieb437d42016-04-29 09:31:25 -07002688 // If Demo Mode is on, don't show user switcher
2689 if (isDeviceInDemoMode(mContext)) {
2690 return false;
2691 }
Kenny Guy1a447532014-02-20 21:55:32 +00002692 List<UserInfo> users = getUsers(true);
2693 if (users == null) {
2694 return false;
2695 }
2696 int switchableUserCount = 0;
2697 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002698 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00002699 ++switchableUserCount;
2700 }
2701 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002702 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2703 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07002704 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00002705 }
2706
2707 /**
Amith Yamasanieb437d42016-04-29 09:31:25 -07002708 * @hide
2709 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002710 @UnsupportedAppUsage
Amith Yamasanieb437d42016-04-29 09:31:25 -07002711 public static boolean isDeviceInDemoMode(Context context) {
2712 return Settings.Global.getInt(context.getContentResolver(),
2713 Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2714 }
2715
2716 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07002717 * Returns a serial number on this device for a given userHandle. User handles can be recycled
2718 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
2719 * @param userHandle
2720 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
2721 * @hide
2722 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002723 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002724 public int getUserSerialNumber(@UserIdInt int userHandle) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002725 try {
2726 return mService.getUserSerialNumber(userHandle);
2727 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002728 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002729 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002730 }
2731
2732 /**
2733 * Returns a userHandle on this device for a given user serial number. User handles can be
2734 * recycled when deleting and creating users, but serial numbers are not reused until the device
2735 * is wiped.
2736 * @param userSerialNumber
2737 * @return the userHandle associated with that user serial number, or -1 if the serial number
2738 * is not valid.
2739 * @hide
2740 */
Andrei Oneadcb67732019-03-18 11:37:25 +00002741 @UnsupportedAppUsage
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002742 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002743 try {
2744 return mService.getUserHandle(userSerialNumber);
2745 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002746 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002747 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002748 }
Maggie Benthall67944582013-02-22 14:58:27 -05002749
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002750 /**
Esteban Talavera953fe482016-06-07 15:25:20 +01002751 * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002752 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002753 *
2754 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
2755 * where the types of values may be:
2756 * <ul>
2757 * <li>{@code boolean}
2758 * <li>{@code int}
2759 * <li>{@code String} or {@code String[]}
2760 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
2761 * </ul>
2762 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002763 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
2764 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002765 * @param packageName the package name of the calling application
Esteban Talavera953fe482016-06-07 15:25:20 +01002766 * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2767 * if there are no saved restrictions.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002768 *
2769 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002770 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002771 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002772 public Bundle getApplicationRestrictions(String packageName) {
2773 try {
2774 return mService.getApplicationRestrictions(packageName);
2775 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002776 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002777 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002778 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002779
2780 /**
2781 * @hide
2782 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002783 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002784 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002785 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002786 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002787 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002788 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002789 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002790 }
2791
2792 /**
2793 * @hide
2794 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002795 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002796 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002797 UserHandle user) {
2798 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002799 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002800 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002801 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002802 }
2803 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002804
2805 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07002806 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2807 * apps and requires the MANAGE_USERS permission.
2808 * @param newPin the PIN to use for challenge dialogs.
2809 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07002810 * @deprecated The restrictions PIN functionality is no longer provided by the system.
2811 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07002812 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07002813 @Deprecated
Amith Yamasanid304af62013-09-05 09:30:23 -07002814 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002815 return false;
2816 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07002817
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302818 /**
2819 * @hide
2820 * Set restrictions that should apply to any future guest user that's created.
2821 */
2822 public void setDefaultGuestRestrictions(Bundle restrictions) {
2823 try {
2824 mService.setDefaultGuestRestrictions(restrictions);
2825 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002826 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302827 }
2828 }
2829
2830 /**
2831 * @hide
2832 * Gets the default guest restrictions.
2833 */
2834 public Bundle getDefaultGuestRestrictions() {
2835 try {
2836 return mService.getDefaultGuestRestrictions();
2837 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002838 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302839 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302840 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002841
2842 /**
2843 * Returns creation time of the user or of a managed profile associated with the calling user.
2844 * @param userHandle user handle of the user or a managed profile associated with the
2845 * calling user.
2846 * @return creation time in milliseconds since Epoch time.
2847 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07002848 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002849 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07002850 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002851 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002852 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002853 }
2854 }
Amith Yamasani12747872015-12-07 14:19:49 -08002855
2856 /**
2857 * @hide
2858 * Checks if any uninitialized user has the specific seed account name and type.
2859 *
Pavel Grafov6a40f092016-10-25 15:46:51 +01002860 * @param accountName The account name to check for
2861 * @param accountType The account type of the account to check for
Amith Yamasani12747872015-12-07 14:19:49 -08002862 * @return whether the seed account was found
2863 */
2864 public boolean someUserHasSeedAccount(String accountName, String accountType) {
2865 try {
2866 return mService.someUserHasSeedAccount(accountName, accountType);
2867 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002868 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002869 }
2870 }
Pavel Grafov6a40f092016-10-25 15:46:51 +01002871
2872 /**
2873 * @hide
2874 * User that enforces a restriction.
2875 *
2876 * @see #getUserRestrictionSources(String, UserHandle)
2877 */
2878 @SystemApi
2879 public static final class EnforcingUser implements Parcelable {
2880 private final @UserIdInt int userId;
2881 private final @UserRestrictionSource int userRestrictionSource;
2882
2883 /**
2884 * @hide
2885 */
2886 public EnforcingUser(
2887 @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
2888 this.userId = userId;
2889 this.userRestrictionSource = userRestrictionSource;
2890 }
2891
2892 private EnforcingUser(Parcel in) {
2893 userId = in.readInt();
2894 userRestrictionSource = in.readInt();
2895 }
2896
2897 public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
2898 @Override
2899 public EnforcingUser createFromParcel(Parcel in) {
2900 return new EnforcingUser(in);
2901 }
2902
2903 @Override
2904 public EnforcingUser[] newArray(int size) {
2905 return new EnforcingUser[size];
2906 }
2907 };
2908
2909 @Override
2910 public int describeContents() {
2911 return 0;
2912 }
2913
2914 @Override
2915 public void writeToParcel(Parcel dest, int flags) {
2916 dest.writeInt(userId);
2917 dest.writeInt(userRestrictionSource);
2918 }
2919
2920 /**
2921 * Returns an id of the enforcing user.
2922 *
2923 * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
2924 */
2925 public UserHandle getUserHandle() {
2926 return UserHandle.of(userId);
2927 }
2928
2929 /**
2930 * Returns the status of the enforcing user.
2931 *
2932 * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
2933 * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
2934 * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
2935 */
2936 public @UserRestrictionSource int getUserRestrictionSource() {
2937 return userRestrictionSource;
2938 }
2939 }
Amith Yamasani258848d2012-08-10 17:06:33 -07002940}