blob: b5918519d8728109869342811e4f4235e192d547 [file] [log] [blame]
Amith Yamasani258848d2012-08-10 17:06:33 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -060016
Amith Yamasani258848d2012-08-10 17:06:33 -070017package android.os;
18
Xiaohui Chenb3b92582015-12-07 11:22:13 -080019import android.Manifest;
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -070020import android.accounts.AccountManager;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010021import android.annotation.IntDef;
Adam Lesinskiada8deb2017-05-12 13:50:42 -070022import android.annotation.NonNull;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -070023import android.annotation.Nullable;
Xiaohui Chenb3b92582015-12-07 11:22:13 -080024import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070025import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SystemService;
Makoto Onukie72f81b2017-03-16 14:08:19 -070027import android.annotation.TestApi;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070028import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070029import android.annotation.WorkerThread;
Amith Yamasani37ed8d12016-01-27 14:40:16 -080030import android.app.Activity;
Dianne Hackborn409297d2014-07-10 17:39:20 -070031import android.app.ActivityManager;
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -070032import android.app.admin.DevicePolicyManager;
Makoto Onuki068c54a2015-10-13 14:34:03 -070033import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070034import android.content.Context;
Amith Yamasani12747872015-12-07 14:19:49 -080035import android.content.Intent;
Esteban Talavera8bd7c522017-02-13 12:35:04 +000036import android.content.IntentFilter;
Benjamin Franzf02420c2016-04-04 18:52:21 +010037import android.content.IntentSender;
Amith Yamasani258848d2012-08-10 17:06:33 -070038import android.content.pm.UserInfo;
Robin Lee83c79312018-02-09 19:27:18 +010039import android.content.res.Configuration;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070040import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050041import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010042import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080043import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080044import android.graphics.drawable.Drawable;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070045import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080046import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040047import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070048
Maggie Benthall67944582013-02-22 14:58:27 -050049import com.android.internal.R;
John Reckaa67f682016-09-20 14:24:21 -070050import com.android.internal.os.RoSystemProperties;
Maggie Benthall67944582013-02-22 14:58:27 -050051
Adrian Roos1bdff912015-02-17 15:51:35 +010052import java.io.IOException;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010053import java.lang.annotation.Retention;
54import java.lang.annotation.RetentionPolicy;
Amith Yamasani4f582632014-02-19 14:31:52 -080055import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070056import java.util.List;
57
58/**
Amith Yamasani06964342016-04-15 13:55:01 -070059 * Manages users and user details on a multi-user system. There are two major categories of
60 * users: fully customizable users with their own login, and managed profiles that share a workspace
61 * with a related user.
62 * <p>
63 * Users are different from accounts, which are managed by
64 * {@link AccountManager}. Each user can have their own set of accounts.
65 * <p>
66 * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
Amith Yamasani258848d2012-08-10 17:06:33 -070067 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060068@SystemService(Context.USER_SERVICE)
Amith Yamasani258848d2012-08-10 17:06:33 -070069public class UserManager {
70
Pavel Grafov4f4f6f82017-03-28 13:44:04 +010071 private static final String TAG = "UserManager";
Amith Yamasani258848d2012-08-10 17:06:33 -070072 private final IUserManager mService;
73 private final Context mContext;
74
Makoto Onukid49f3fa2017-01-25 14:09:48 -080075 private Boolean mIsManagedProfileCached;
76
Amith Yamasanie4cf7342012-12-17 11:12:09 -080077 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010078 * @hide
79 * No user restriction.
80 */
81 @SystemApi
82 public static final int RESTRICTION_NOT_SET = 0x0;
83
84 /**
85 * @hide
86 * User restriction set by system/user.
87 */
88 @SystemApi
89 public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
90
91 /**
92 * @hide
93 * User restriction set by a device owner.
94 */
95 @SystemApi
96 public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
97
98 /**
99 * @hide
100 * User restriction set by a profile owner.
101 */
102 @SystemApi
103 public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
104
105 /** @hide */
106 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700107 @IntDef(flag = true, prefix = { "RESTRICTION_" }, value = {
108 RESTRICTION_NOT_SET,
109 RESTRICTION_SOURCE_SYSTEM,
110 RESTRICTION_SOURCE_DEVICE_OWNER,
111 RESTRICTION_SOURCE_PROFILE_OWNER
112 })
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +0100113 @SystemApi
114 public @interface UserRestrictionSource {}
115
116 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -0700117 * Specifies if a user is disallowed from adding and removing accounts, unless they are
118 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
119 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700120 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700121 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +0000122 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
123 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
124 * management is disallowed.
125 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800126 * <p>Key for user restrictions.
127 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700128 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
129 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800130 * @see #getUserRestrictions()
131 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700132 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800133
134 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700135 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -0400136 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800137 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700138 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800139 * <p>Key for user restrictions.
140 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700141 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
142 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800143 * @see #getUserRestrictions()
144 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700145 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800146
147 /**
Christine Franks1bade5d2017-10-10 15:41:50 -0700148 * Specifies if a user is disallowed from changing the device
149 * language. The default value is <code>false</code>.
150 *
151 * <p>Key for user restrictions.
152 * <p>Type: Boolean
153 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
154 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
155 * @see #getUserRestrictions()
156 */
157 public static final String DISALLOW_CONFIG_LOCALE = "no_config_locale";
158
159 /**
Benjamin Millerf1c3ed12018-05-03 10:56:28 +0000160 * Specifies if a user is disallowed from installing applications. This user restriction also
161 * prevents device owners and profile owners installing apps. The default value is
162 * {@code false}.
Amith Yamasani26af8292014-09-09 09:57:27 -0700163 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800164 * <p>Key for user restrictions.
165 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700166 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
167 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800168 * @see #getUserRestrictions()
169 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700170 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800171
172 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700173 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700174 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700175 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800176 * <p>Key for user restrictions.
177 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700178 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
179 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800180 * @see #getUserRestrictions()
181 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700182 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800183
Amith Yamasani71e6c692013-03-24 17:39:28 -0700184 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800185 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700186 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800187 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800188 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700189 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800190 * <p>Key for user restrictions.
191 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700192 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
193 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500194 * @see #getUserRestrictions()
195 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700196 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500197
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400198 /**
yuemingw5fe75dc2017-11-29 15:52:56 +0000199 * Specifies if airplane mode is disallowed on the device.
200 *
201 * <p> This restriction can only be set by the device owner and the profile owner on the
202 * primary user and it applies globally - i.e. it disables airplane mode on the entire device.
203 * <p>The default value is <code>false</code>.
204 *
205 * <p>Key for user restrictions.
206 * <p>Type: Boolean
207 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
208 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
209 * @see #getUserRestrictions()
210 */
211 public static final String DISALLOW_AIRPLANE_MODE = "no_airplane_mode";
212
213 /**
yuemingwc6ac29d2018-01-10 16:54:08 +0000214 * Specifies if a user is disallowed from configuring brightness. When device owner sets it,
215 * it'll only be applied on the target(system) user.
216 *
217 * <p>The default value is <code>false</code>.
218 *
219 * <p>This user restriction has no effect on managed profiles.
220 * <p>Key for user restrictions.
221 * <p>Type: Boolean
222 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
223 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
224 * @see #getUserRestrictions()
225 */
226 public static final String DISALLOW_CONFIG_BRIGHTNESS = "no_config_brightness";
227
228 /**
yuemingwa1781442018-01-10 18:59:43 +0000229 * Specifies if ambient display is disallowed for the user.
230 *
231 * <p>The default value is <code>false</code>.
232 *
233 * <p>This user restriction has no effect on managed profiles.
234 * <p>Key for user restrictions.
235 * <p>Type: Boolean
236 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
237 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
238 * @see #getUserRestrictions()
239 */
240 public static final String DISALLOW_AMBIENT_DISPLAY = "no_ambient_display";
241
242 /**
yuemingw5cda3ae2018-01-15 10:26:19 +0000243 * Specifies if a user is disallowed from changing screen off timeout.
244 *
245 * <p>The default value is <code>false</code>.
246 *
247 * <p>This user restriction has no effect on managed profiles.
248 * <p>Key for user restrictions.
249 * <p>Type: Boolean
250 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
251 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
252 * @see #getUserRestrictions()
253 */
254 public static final String DISALLOW_CONFIG_SCREEN_TIMEOUT = "no_config_screen_timeout";
255
256 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700257 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400258 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
259 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700260 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800261 * <p>Key for user restrictions.
262 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700263 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
264 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400265 * @see #getUserRestrictions()
266 */
267 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
268
269 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700270 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000271 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400272 * The default value is <code>false</code>.
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100273 * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
274 * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800275 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700276 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800277 * <p>Key for user restrictions.
278 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700279 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
280 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400281 * @see #getUserRestrictions()
282 */
283 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
284
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400285 /**
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100286 * Specifies if bluetooth is disallowed on the device.
287 *
288 * <p> This restriction can only be set by the device owner and the profile owner on the
289 * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
290 * <p>The default value is <code>false</code>.
291 * <p>Key for user restrictions.
292 * <p>Type: Boolean
293 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
294 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
295 * @see #getUserRestrictions()
296 */
297 public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
298
299 /**
Pavel Grafov4f4f6f82017-03-28 13:44:04 +0100300 * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
301 * owner can set this restriction. When it is set by device owner, all users on this device will
302 * be affected.
303 *
304 * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
305 * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
306 * managed profiles.
307 *
308 * <p>Key for user restrictions.
309 * <p>Type: Boolean
310 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
311 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
312 * @see #getUserRestrictions()
313 */
314 public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
315
316 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700317 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700318 * USB. This can only be set by device owners and profile owners on the primary user.
319 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700320 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800321 * <p>Key for user restrictions.
322 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700323 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
324 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400325 * @see #getUserRestrictions()
326 */
327 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
328
Emily Bernierb223f732013-04-11 15:46:36 -0400329 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700330 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400331 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700332 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800333 * <p>Key for user restrictions.
334 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700335 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
336 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400337 * @see #getUserRestrictions()
338 */
339 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
340
341 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800342 * When set on the primary user this specifies if the user can remove other users.
343 * When set on a secondary user, this specifies if the user can remove itself.
344 * This restriction has no effect on managed profiles.
345 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700346 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800347 * <p>Key for user restrictions.
348 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700349 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
350 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400351 * @see #getUserRestrictions()
352 */
353 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
354
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400355 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000356 * Specifies if managed profiles of this user can be removed, other than by its profile owner.
357 * The default value is <code>false</code>.
358 * <p>
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000359 * This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000360 *
361 * <p>Key for user restrictions.
362 * <p>Type: Boolean
363 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
364 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
365 * @see #getUserRestrictions()
366 */
367 public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
368
369 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700370 * Specifies if a user is disallowed from enabling or
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400371 * accessing debugging features. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700372 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800373 * <p>Key for user restrictions.
374 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700375 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
376 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400377 * @see #getUserRestrictions()
378 */
379 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
380
381 /**
Benjamin Miller05fef7e2017-07-24 10:11:39 +0200382 * Specifies if a user is disallowed from configuring a VPN. The default value is
383 * <code>false</code>. This restriction has an effect when set by device owners and, in Android
384 * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners.
385 * <p>This restriction also prevents VPNs from starting. However, in Android 7.0
386 * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does
387 * start always-on VPNs created by the device or profile owner.
Amith Yamasani26af8292014-09-09 09:57:27 -0700388 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800389 * <p>Key for user restrictions.
390 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700391 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
392 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400393 * @see #getUserRestrictions()
394 */
395 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
396
397 /**
yuemingw7810b8b2018-02-01 17:32:25 +0000398 * Specifies if a user is disallowed from enabling or disabling location providers. As a
399 * result, user is disallowed from turning on or off location. Device owner and profile owners
400 * can set this restriction and it only applies on the managed user.
yuemingw7cc2c4c2017-11-28 17:20:01 +0000401 *
402 * <p>In a managed profile, location sharing is forced off when it's off on primary user, so
403 * user can still turn off location sharing on managed profile when the restriction is set by
404 * profile owner on managed profile.
405 *
406 * <p>This user restriction is different from {@link #DISALLOW_SHARE_LOCATION},
407 * as the device owner or profile owner can still enable or disable location mode via
408 * {@link DevicePolicyManager#setSecureSetting} when this restriction is on.
409 *
410 * <p>The default value is <code>false</code>.
411 *
412 * <p>Key for user restrictions.
413 * <p>Type: Boolean
yuemingw7810b8b2018-02-01 17:32:25 +0000414 * @see android.location.LocationManager#isProviderEnabled(String)
yuemingw7cc2c4c2017-11-28 17:20:01 +0000415 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
416 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
417 * @see #getUserRestrictions()
418 */
yuemingw7810b8b2018-02-01 17:32:25 +0000419 public static final String DISALLOW_CONFIG_LOCATION = "no_config_location";
yuemingw7cc2c4c2017-11-28 17:20:01 +0000420
421 /**
yuemingwa9772f362017-10-23 18:34:35 +0100422 * Specifies if date, time and timezone configuring is disallowed.
423 *
424 * <p>When restriction is set by device owners, it applies globally - i.e., it disables date,
425 * time and timezone setting on the entire device and all users will be affected. When it's set
426 * by profile owners, it's only applied to the managed user.
427 * <p>The default value is <code>false</code>.
428 *
429 * <p>This user restriction has no effect on managed profiles.
430 * <p>Key for user restrictions.
431 * <p>Type: Boolean
432 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
433 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
434 * @see #getUserRestrictions()
435 */
436 public static final String DISALLOW_CONFIG_DATE_TIME = "no_config_date_time";
437
438 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700439 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700440 * & portable hotspots. This can only be set by device owners and profile owners on the
441 * primary user. The default value is <code>false</code>.
Rubin Xu1faf1442017-08-23 15:48:12 +0100442 * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set,
443 * tethering will be automatically turned off.
Amith Yamasani26af8292014-09-09 09:57:27 -0700444 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800445 * <p>Key for user restrictions.
446 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700447 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
448 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400449 * @see #getUserRestrictions()
450 */
451 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
452
453 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700454 * Specifies if a user is disallowed from resetting network settings
455 * from Settings. This can only be set by device owners and profile owners on the primary user.
456 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800457 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700458 * primary user can reset the network settings of the device.
459 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800460 * <p>Key for user restrictions.
461 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700462 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
463 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700464 * @see #getUserRestrictions()
465 */
466 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
467
468 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700469 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700470 * from Settings. This can only be set by device owners and profile owners on the primary user.
471 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800472 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800473 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700474 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800475 * <p>Key for user restrictions.
476 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700477 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
478 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400479 * @see #getUserRestrictions()
480 */
481 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
482
483 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000484 * Specifies if a user is disallowed from adding new users. This can only be set by device
485 * owners and profile owners on the primary user.
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700486 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800487 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800488 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700489 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800490 * <p>Key for user restrictions.
491 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700492 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
493 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400494 * @see #getUserRestrictions()
495 */
496 public static final String DISALLOW_ADD_USER = "no_add_user";
497
498 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000499 * Specifies if a user is disallowed from adding managed profiles.
500 * <p>The default value for an unmanaged user is <code>false</code>.
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000501 * For users with a device owner set, the default is <code>true</code>.
502 * <p>This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000503 *
504 * <p>Key for user restrictions.
505 * <p>Type: Boolean
506 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
507 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
508 * @see #getUserRestrictions()
509 */
510 public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
511
512 /**
Benjamin Millerd41a9fc2017-07-17 17:24:44 +0200513 * Specifies if a user is disallowed from disabling application verification. The default
514 * value is <code>false</code>.
515 *
516 * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher,
517 * this is a global user restriction. If a device owner or profile owner sets this restriction,
518 * the system enforces app verification across all users on the device. Running in earlier
519 * Android versions, this restriction affects only the profile that sets it.
Amith Yamasani26af8292014-09-09 09:57:27 -0700520 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800521 * <p>Key for user restrictions.
522 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700523 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
524 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400525 * @see #getUserRestrictions()
526 */
527 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
528
529 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700530 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700531 * broadcasts. This can only be set by device owners and profile owners on the primary user.
532 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800533 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800534 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700535 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800536 * <p>Key for user restrictions.
537 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700538 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
539 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400540 * @see #getUserRestrictions()
541 */
542 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
543
544 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700545 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700546 * networks. This can only be set by device owners and profile owners on the primary user.
547 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800548 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800549 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700550 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800551 * <p>Key for user restrictions.
552 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700553 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
554 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400555 * @see #getUserRestrictions()
556 */
557 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
558
559 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700560 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400561 * applications in Settings or launchers. The following actions will not be allowed when this
562 * restriction is enabled:
563 * <li>uninstalling apps</li>
564 * <li>disabling apps</li>
565 * <li>clearing app caches</li>
566 * <li>clearing app data</li>
567 * <li>force stopping apps</li>
568 * <li>clearing app defaults</li>
569 * <p>
570 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700571 *
Esteban Talavera8bd7c522017-02-13 12:35:04 +0000572 * <p><strong>Note:</strong> The user will still be able to perform those actions via other
573 * means (such as adb). Third party apps will also be able to uninstall apps via the
574 * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
575 * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
576 * used to prevent the user from uninstalling apps completely, and
577 * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
578 * to add a default intent handler for a given intent filter.
579 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800580 * <p>Key for user restrictions.
581 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700582 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
583 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400584 * @see #getUserRestrictions()
585 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400586 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400587
Emily Bernier394a6cd2014-05-07 12:49:20 -0400588 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700589 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700590 * physical external media. This can only be set by device owners and profile owners on the
591 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700592 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800593 * <p>Key for user restrictions.
594 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700595 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
596 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400597 * @see #getUserRestrictions()
598 */
599 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
600
601 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100602 * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
603 * will be muted. This can be set by device owners and profile owners. The default value is
604 * <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700605 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100606 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800607 * <p>Key for user restrictions.
608 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700609 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
610 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400611 * @see #getUserRestrictions()
612 */
613 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
614
615 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100616 * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
Wen ZHANG61ed0dc2017-08-23 14:27:02 +0100617 * will be muted. This can be set by device owners from API 21 and profile owners from API 24.
618 * The default value is <code>false</code>.
619 *
620 * <p>When the restriction is set by profile owners, then it only applies to relevant
621 * profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700622 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100623 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800624 * <p>Key for user restrictions.
625 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700626 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
627 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400628 * @see #getUserRestrictions()
629 */
630 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
631
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700632 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700633 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700634 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700635 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000636 * <p>This restriction has no effect on managed profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700637 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800638 * <p>Key for user restrictions.
639 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700640 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
641 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700642 * @see #getUserRestrictions()
643 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700644 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
645
646 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700647 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700648 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700649 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800650 * <p>Key for user restrictions.
651 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700652 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
653 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700654 * @see #getUserRestrictions()
655 */
656 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700657
Jason Monk1c7c3192014-06-26 12:52:18 -0400658 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700659 * Specifies if the user is not allowed to have fun. In some cases, the
660 * device owner may wish to prevent the user from experiencing amusement or
661 * joy while using the device. The default value is <code>false</code>.
662 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800663 * <p>Key for user restrictions.
664 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700665 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
666 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700667 * @see #getUserRestrictions()
668 */
669 public static final String DISALLOW_FUN = "no_fun";
670
671 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700672 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400673 * created. This will block the creation of the following types of windows.
674 * <li>{@link LayoutParams#TYPE_TOAST}</li>
675 * <li>{@link LayoutParams#TYPE_PHONE}</li>
676 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
677 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
678 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
679 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800680 * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
Jason Monk1c7c3192014-06-26 12:52:18 -0400681 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700682 * <p>This can only be set by device owners and profile owners on the primary user.
683 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700684 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800685 * <p>Key for user restrictions.
686 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700687 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
688 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400689 * @see #getUserRestrictions()
690 */
691 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
692
Nicolas Prevotf1939902014-06-25 09:29:02 +0100693 /**
Charles He22ff6f9d2017-10-05 21:28:55 +0100694 * Specifies that system error dialogs for crashed or unresponsive apps should not be shown.
695 * 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 +0000696 * option on the UI. A feedback report isn't collected as there is no way for the user to
697 * provide explicit consent. The default value is <code>false</code>.
Charles He22ff6f9d2017-10-05 21:28:55 +0100698 *
Benjamin Franz0c86fe12018-02-28 09:49:17 +0000699 * <p>When this user restriction is set by device owners, it's applied to all users. When set by
700 * the profile owner of the primary user or a secondary user, the restriction affects only the
701 * calling user. This user restriction has no effect on managed profiles.
Charles He22ff6f9d2017-10-05 21:28:55 +0100702 *
Charles He22ff6f9d2017-10-05 21:28:55 +0100703 * <p>Key for user restrictions.
704 * <p>Type: Boolean
705 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
706 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
707 * @see #getUserRestrictions()
708 */
709 public static final String DISALLOW_SYSTEM_ERROR_DIALOGS = "no_system_error_dialogs";
710
711 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700712 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100713 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
714 * pasted in this profile.
715 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700716 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800717 * <p>Key for user restrictions.
718 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700719 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
720 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100721 * @see #getUserRestrictions()
722 */
723 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
724
Amith Yamasani26af8292014-09-09 09:57:27 -0700725 /**
726 * Specifies if the user is not allowed to use NFC to beam out data from apps.
727 * The default value is <code>false</code>.
728 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800729 * <p>Key for user restrictions.
730 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700731 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
732 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani26af8292014-09-09 09:57:27 -0700733 * @see #getUserRestrictions()
734 */
735 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
736
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000737 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100738 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
739 * generally means that wallpapers are not supported for the particular user. This user
740 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000741 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100742 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700743 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
744 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000745 * @see #getUserRestrictions()
746 */
747 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
748
749 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100750 * User restriction to disallow setting a wallpaper. Profile owner and device owner
751 * are able to set wallpaper regardless of this restriction.
752 * The default value is <code>false</code>.
753 *
754 * <p>Key for user restrictions.
755 * <p>Type: Boolean
756 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
757 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
758 * @see #getUserRestrictions()
759 */
760 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
761
762 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000763 * Specifies if the user is not allowed to reboot the device into safe boot mode.
764 * This can only be set by device owners and profile owners on the primary user.
765 * The default value is <code>false</code>.
766 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800767 * <p>Key for user restrictions.
768 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700769 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
770 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000771 * @see #getUserRestrictions()
772 */
773 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
774
775 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700776 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
777 * background users. The default value is <code>false</code>.
778 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700779 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
780 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700781 * @see #getUserRestrictions()
782 * @hide
783 */
784 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
785
786 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700787 * Specifies if a user is not allowed to run in the background and should be stopped during
788 * user switch. The default value is <code>false</code>.
789 *
790 * <p>This restriction can be set by device owners and profile owners.
791 *
792 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
793 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
794 * @see #getUserRestrictions()
795 * @hide
796 */
Robin Lee6cfb7a92017-12-18 15:14:46 +0100797 @SystemApi
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700798 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
799
800 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700801 * Specifies if a user is not allowed to use the camera.
802 *
803 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
804 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
805 * @see #getUserRestrictions()
806 * @hide
807 */
808 public static final String DISALLOW_CAMERA = "no_camera";
809
810 /**
Tony Makc1205112016-07-22 16:02:59 +0100811 * Specifies if a user is not allowed to unmute the device's master volume.
812 *
813 * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
814 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
815 * @see #getUserRestrictions()
816 * @hide
817 */
Esteban Talavera492b4722017-02-13 14:59:45 +0000818 public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
Tony Makc1205112016-07-22 16:02:59 +0100819
820 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000821 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
822 * device owners. The default value is <code>false</code>.
823 *
824 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
825 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
826 * @see #getUserRestrictions()
827 */
828 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
829
830 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100831 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
832 * can set this restriction. When it is set by device owner, only the target user will be
833 * affected. The default value is <code>false</code>.
834 *
835 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100836 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100837 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
838 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
839 * @see #getUserRestrictions()
840 */
841 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
842
843 /**
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100844 * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100845 * <code>false</code>. Setting this restriction has no effect if the bootloader is already
846 * unlocked.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100847 *
Lenka Trochtova12b04962016-11-29 21:00:12 +0100848 * <p>Not for use by third-party applications.
849 *
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100850 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
851 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
852 * @see #getUserRestrictions()
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000853 * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100854 * @hide
855 */
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000856 @Deprecated
Lenka Trochtova12b04962016-11-29 21:00:12 +0100857 @SystemApi
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100858 public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
859
860 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +0100861 * Specifies that the managed profile is not allowed to have unified lock screen challenge with
862 * the primary user.
863 *
864 * <p><strong>Note:</strong> Setting this restriction alone doesn't automatically set a
865 * separate challenge. Profile owner can ask the user to set a new password using
866 * {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and verify it using
867 * {@link DevicePolicyManager#isUsingUnifiedPassword(ComponentName)}.
868 *
869 * <p>Can be set by profile owners. It only has effect on managed profiles when set by managed
870 * profile owner. Has no effect on non-managed profiles or users.
871 * <p>Key for user restrictions.
872 * <p>Type: Boolean
873 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
874 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
875 * @see #getUserRestrictions()
876 */
877 public static final String DISALLOW_UNIFIED_PASSWORD = "no_unified_password";
878
879 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700880 * Allows apps in the parent profile to handle web links from the managed profile.
881 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700882 * This user restriction has an effect only in a managed profile.
883 * If set:
884 * Intent filters of activities in the parent profile with action
885 * {@link android.content.Intent#ACTION_VIEW},
886 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
887 * define a host can handle intents from the managed profile.
888 * The default value is <code>false</code>.
889 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800890 * <p>Key for user restrictions.
891 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700892 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
893 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700894 * @see #getUserRestrictions()
895 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700896 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
897 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700898
899 /**
Felipe Leme24d58932017-03-21 14:13:58 -0700900 * Specifies if a user is not allowed to use Autofill Services.
901 *
902 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
903 * only the target user will be affected.
904 *
905 * <p>The default value is <code>false</code>.
906 *
907 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
908 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
909 * @see #getUserRestrictions()
910 */
911 public static final String DISALLOW_AUTOFILL = "no_autofill";
912
913 /**
Benjamin Franzff66fa92017-08-10 10:39:44 +0100914 * Specifies if user switching is blocked on the current user.
915 *
916 * <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 +0800917 * Device owner can still switch user via
918 * {@link DevicePolicyManager#switchUser(ComponentName, UserHandle)} when this restriction is
919 * set.
Benjamin Franzff66fa92017-08-10 10:39:44 +0100920 *
921 * <p>The default value is <code>false</code>.
922 *
923 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
924 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
925 * @see #getUserRestrictions()
926 */
927 public static final String DISALLOW_USER_SWITCH = "no_user_switch";
928
929 /**
Rubin Xucc391c22018-01-02 20:37:35 +0000930 * Specifies whether the user can share file / picture / data from the primary user into the
931 * managed profile, either by sending them from the primary side, or by picking up data within
932 * an app in the managed profile.
933 * <p>
934 * When a managed profile is created, the system allows the user to send data from the primary
935 * side to the profile by setting up certain default cross profile intent filters. If
936 * this is undesired, this restriction can be set to disallow it. Note that this restriction
937 * will not block any sharing allowed by explicit
938 * {@link DevicePolicyManager#addCrossProfileIntentFilter} calls by the profile owner.
939 * <p>
940 * This restriction is only meaningful when set by profile owner. When it is set by device
941 * owner, it does not have any effect.
942 * <p>
943 * The default value is <code>false</code>.
944 *
945 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
946 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
947 * @see #getUserRestrictions()
948 */
949 public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile";
Vladislav Kuzkokov622b9f92018-01-25 16:33:05 +0100950
951 /**
952 * Specifies whether the user is allowed to print.
953 *
954 * This restriction can be set by device or profile owner.
955 *
956 * The default value is {@code false}.
957 *
958 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
959 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
960 * @see #getUserRestrictions()
961 */
962 public static final String DISALLOW_PRINTING = "no_printing";
963
Rubin Xucc391c22018-01-02 20:37:35 +0000964 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000965 * Application restriction key that is used to indicate the pending arrival
966 * of real restrictions for the app.
967 *
968 * <p>
969 * Applications that support restrictions should check for the presence of this key.
970 * A <code>true</code> value indicates that restrictions may be applied in the near
971 * future but are not available yet. It is the responsibility of any
972 * management application that sets this flag to update it when the final
973 * restrictions are enforced.
974 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800975 * <p>Key for application restrictions.
976 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +0000977 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
978 * android.content.ComponentName, String, Bundle)
979 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
980 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000981 */
982 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
983
Amith Yamasani12747872015-12-07 14:19:49 -0800984 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
985
986 /**
987 * Extra containing a name for the user being created. Optional parameter passed to
988 * ACTION_CREATE_USER activity.
989 * @hide
990 */
991 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
992
993 /**
994 * Extra containing account name for the user being created. Optional parameter passed to
995 * ACTION_CREATE_USER activity.
996 * @hide
997 */
998 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
999
1000 /**
1001 * Extra containing account type for the user being created. Optional parameter passed to
1002 * ACTION_CREATE_USER activity.
1003 * @hide
1004 */
1005 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
1006
1007 /**
1008 * Extra containing account-specific data for the user being created. Optional parameter passed
1009 * to ACTION_CREATE_USER activity.
1010 * @hide
1011 */
1012 public static final String EXTRA_USER_ACCOUNT_OPTIONS
1013 = "android.os.extra.USER_ACCOUNT_OPTIONS";
1014
Amith Yamasani655d0e22013-06-12 14:19:10 -07001015 /** @hide */
1016 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
1017 /** @hide */
1018 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
1019 /** @hide */
1020 public static final int PIN_VERIFICATION_SUCCESS = -1;
1021
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001022 /**
Makoto Onukie72f81b2017-03-16 14:08:19 -07001023 * Sent when user restrictions have changed.
1024 *
1025 * @hide
1026 */
1027 @SystemApi
1028 @TestApi // To allow seeing it from CTS.
1029 public static final String ACTION_USER_RESTRICTIONS_CHANGED =
1030 "android.os.action.USER_RESTRICTIONS_CHANGED";
1031
1032 /**
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001033 * Error result indicating that this user is not allowed to add other users on this device.
1034 * This is a result code returned from the activity created by the intent
1035 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1036 */
1037 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
1038
1039 /**
1040 * Error result indicating that no more users can be created on this device.
1041 * This is a result code returned from the activity created by the intent
1042 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
1043 */
1044 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
1045
Alex Chau89386ba2018-02-13 11:09:17 +08001046 /**
1047 * Indicates user operation is successful.
1048 */
1049 public static final int USER_OPERATION_SUCCESS = 0;
1050
1051 /**
1052 * Indicates user operation failed for unknown reason.
1053 */
1054 public static final int USER_OPERATION_ERROR_UNKNOWN = 1;
1055
1056 /**
1057 * Indicates user operation failed because target user is a managed profile.
1058 */
1059 public static final int USER_OPERATION_ERROR_MANAGED_PROFILE = 2;
1060
1061 /**
1062 * Indicates user operation failed because maximum running user limit has been reached.
1063 */
1064 public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS = 3;
1065
1066 /**
1067 * Indicates user operation failed because the target user is in the foreground.
1068 */
1069 public static final int USER_OPERATION_ERROR_CURRENT_USER = 4;
1070
1071 /**
1072 * Indicates user operation failed because device has low data storage.
1073 */
1074 public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5;
1075
1076 /**
1077 * Indicates user operation failed because maximum user limit has been reached.
1078 */
1079 public static final int USER_OPERATION_ERROR_MAX_USERS = 6;
1080
1081 /**
1082 * Result returned from various user operations.
1083 *
1084 * @hide
1085 */
1086 @Retention(RetentionPolicy.SOURCE)
1087 @IntDef(prefix = { "USER_OPERATION_" }, value = {
1088 USER_OPERATION_SUCCESS,
1089 USER_OPERATION_ERROR_UNKNOWN,
1090 USER_OPERATION_ERROR_MANAGED_PROFILE,
1091 USER_OPERATION_ERROR_MAX_RUNNING_USERS,
1092 USER_OPERATION_ERROR_CURRENT_USER,
1093 USER_OPERATION_ERROR_LOW_STORAGE,
1094 USER_OPERATION_ERROR_MAX_USERS
1095 })
1096 public @interface UserOperationResult {}
1097
1098 /**
1099 * Thrown to indicate user operation failed.
1100 */
1101 public static class UserOperationException extends RuntimeException {
1102 private final @UserOperationResult int mUserOperationResult;
1103
1104 /**
1105 * Constructs a UserOperationException with specific result code.
1106 *
1107 * @param message the detail message
1108 * @param userOperationResult the result code
1109 * @hide
1110 */
1111 public UserOperationException(String message,
1112 @UserOperationResult int userOperationResult) {
1113 super(message);
1114 mUserOperationResult = userOperationResult;
1115 }
1116
1117 /**
1118 * Returns the operation result code.
1119 */
1120 public @UserOperationResult int getUserOperationResult() {
1121 return mUserOperationResult;
1122 }
1123 }
1124
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001125 /** @hide */
Amith Yamasanic0688302015-10-30 10:40:03 -07001126 public static UserManager get(Context context) {
1127 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -07001128 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001129
Amith Yamasani258848d2012-08-10 17:06:33 -07001130 /** @hide */
1131 public UserManager(Context context, IUserManager service) {
1132 mService = service;
Fyodor Kupolov5200e1c2016-10-17 18:46:16 -07001133 mContext = context.getApplicationContext();
Amith Yamasani258848d2012-08-10 17:06:33 -07001134 }
1135
1136 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001137 * Returns whether this device supports multiple users with their own login and customizable
1138 * space.
1139 * @return whether the device supports multiple users.
Amith Yamasani258848d2012-08-10 17:06:33 -07001140 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -07001141 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +00001142 return getMaxSupportedUsers() > 1
1143 && SystemProperties.getBoolean("fw.show_multiuserui",
1144 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -07001145 }
1146
Maggie Benthall67944582013-02-22 14:58:27 -05001147 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001148 * @hide
1149 * @return Whether the device is running with split system user. It means the system user and
1150 * primary user are two separate users. Previously system user and primary user are combined as
1151 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
1152 */
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001153 @TestApi
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001154 public static boolean isSplitSystemUser() {
John Reckaa67f682016-09-20 14:24:21 -07001155 return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001156 }
1157
1158 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001159 * @return Whether guest user is always ephemeral
1160 * @hide
1161 */
1162 public static boolean isGuestUserEphemeral() {
1163 return Resources.getSystem()
1164 .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
1165 }
1166
1167 /**
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001168 * Returns whether switching users is currently allowed.
1169 * <p>For instance switching users is not allowed if the current user is in a phone call,
Benjamin Franzff66fa92017-08-10 10:39:44 +01001170 * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set.
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001171 * @hide
1172 */
1173 public boolean canSwitchUsers() {
1174 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
1175 mContext.getContentResolver(),
1176 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
1177 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
1178 boolean inCall = TelephonyManager.getDefault().getCallState()
1179 != TelephonyManager.CALL_STATE_IDLE;
Benjamin Franzff66fa92017-08-10 10:39:44 +01001180 boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
1181 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
1182 && !isUserSwitchDisallowed;
Fyodor Kupolov523c4042016-02-24 15:03:13 -08001183 }
1184
1185 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001186 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +01001187 *
Amith Yamasani5760e172015-04-17 18:42:41 -07001188 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -07001189 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -05001190 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001191 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001192 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -07001193 }
1194
1195 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001196 * Returns the user name of the user making this call. This call is only
1197 * available to applications on the system image; it requires the
1198 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001199 * @return the user name
1200 */
1201 public String getUserName() {
Will Harmond9dcfb12017-05-18 15:41:15 -07001202 UserInfo user = getUserInfo(getUserHandle());
1203 return user == null ? "" : user.name;
Amith Yamasani258848d2012-08-10 17:06:33 -07001204 }
1205
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001206 /**
Fyodor Kupolov605b12a2017-05-10 15:58:09 -07001207 * Returns whether user name has been set.
1208 * <p>This method can be used to check that the value returned by {@link #getUserName()} was
1209 * set by the user and is not a placeholder string provided by the system.
1210 * @hide
1211 */
1212 public boolean isUserNameSet() {
1213 try {
1214 return mService.isUserNameSet(getUserHandle());
1215 } catch (RemoteException re) {
1216 throw re.rethrowFromSystemServer();
1217 }
1218 }
1219
1220 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -07001221 * Used to determine whether the user making this call is subject to
1222 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001223 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001224 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -07001225 * now automatically identify goats using advanced goat recognition technology.</p>
1226 *
1227 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -07001228 */
1229 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -07001230 return mContext.getPackageManager()
1231 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -07001232 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001233
1234 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001235 * Used to check if this process is running under the primary user. The primary user
1236 * is the first human user on a device.
1237 *
1238 * @return whether this process is running under the primary user.
1239 * @hide
1240 */
1241 public boolean isPrimaryUser() {
1242 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001243 return user != null && user.isPrimary();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001244 }
1245
1246 /**
Amith Yamasani5760e172015-04-17 18:42:41 -07001247 * Used to check if this process is running under the system user. The system user
1248 * is the initial user that is implicitly created on first boot and hosts most of the
1249 * system services.
1250 *
1251 * @return whether this process is running under the system user.
1252 */
1253 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001254 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -07001255 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001256
Amith Yamasani5760e172015-04-17 18:42:41 -07001257 /**
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001258 * @hide
1259 * Returns whether the caller is running as an admin user. There can be more than one admin
1260 * user.
1261 */
1262 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001263 return isUserAdmin(UserHandle.myUserId());
1264 }
1265
1266 /**
1267 * @hide
1268 * Returns whether the provided user is an admin user. There can be more than one admin
1269 * user.
1270 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001271 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001272 UserInfo user = getUserInfo(userId);
1273 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -07001274 }
1275
1276 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001277 * @hide
1278 * @deprecated Use {@link #isRestrictedProfile()}
1279 */
1280 @Deprecated
1281 public boolean isLinkedUser() {
1282 return isRestrictedProfile();
1283 }
1284
1285 /**
1286 * Returns whether the caller is running as restricted profile. Restricted profile may have
Amith Yamasani46bc4eb2013-04-12 13:26:50 -07001287 * a reduced number of available apps, app restrictions and account restrictions.
Amith Yamasanie1375902013-04-13 16:48:35 -07001288 * @return whether the user making this call is a linked user
Amith Yamasani2555daf2013-04-25 13:39:27 -07001289 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001290 */
Fyodor Kupolovca177562017-11-09 17:43:01 -08001291 @SystemApi
1292 public boolean isRestrictedProfile() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001293 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001294 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001295 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001296 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001297 }
1298 }
1299
Amith Yamasani258848d2012-08-10 17:06:33 -07001300 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001301 * Checks if specified user can have restricted profile.
1302 * @hide
1303 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001304 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001305 try {
1306 return mService.canHaveRestrictedProfile(userId);
1307 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001308 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001309 }
1310 }
1311
1312 /**
Fyodor Kupolovca177562017-11-09 17:43:01 -08001313 * Returns whether the calling user has at least one restricted profile associated with it.
1314 * @return
1315 * @hide
1316 */
1317 @SystemApi
1318 public boolean hasRestrictedProfiles() {
1319 try {
1320 return mService.hasRestrictedProfiles();
1321 } catch (RemoteException re) {
1322 throw re.rethrowFromSystemServer();
1323 }
1324 }
1325
1326 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001327 * Checks if a user is a guest user.
1328 * @return whether user is a guest user.
1329 * @hide
1330 */
1331 public boolean isGuestUser(int id) {
1332 UserInfo user = getUserInfo(id);
1333 return user != null && user.isGuest();
1334 }
1335
1336 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001337 * Checks if the calling app is running as a guest user.
1338 * @return whether the caller is a guest user.
1339 * @hide
1340 */
1341 public boolean isGuestUser() {
1342 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001343 return user != null && user.isGuest();
1344 }
1345
Fyodor Kupolovca177562017-11-09 17:43:01 -08001346
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001347 /**
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001348 * Checks if the calling app is running in a demo user. When running in a demo user,
1349 * apps can be more helpful to the user, or explain their features in more detail.
1350 *
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001351 * @return whether the caller is a demo user.
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001352 */
1353 public boolean isDemoUser() {
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001354 try {
1355 return mService.isDemoUser(UserHandle.myUserId());
1356 } catch (RemoteException re) {
1357 throw re.rethrowFromSystemServer();
1358 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001359 }
1360
1361 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001362 * Checks if the calling app is running in a managed profile.
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001363 *
1364 * @return whether the caller is in a managed profile.
1365 * @hide
1366 */
1367 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001368 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001369 public boolean isManagedProfile() {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001370 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1371 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1372 if (mIsManagedProfileCached != null) {
1373 return mIsManagedProfileCached;
1374 }
Tony Mak8673b282016-03-21 21:10:59 +00001375 try {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001376 mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1377 return mIsManagedProfileCached;
Tony Mak8673b282016-03-21 21:10:59 +00001378 } catch (RemoteException re) {
1379 throw re.rethrowFromSystemServer();
1380 }
1381 }
1382
1383 /**
1384 * Checks if the specified user is a managed profile.
1385 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1386 * must be in the same profile group of specified user.
1387 *
1388 * @return whether the specified user is a managed profile.
1389 * @hide
1390 */
1391 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001392 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Tony Mak8673b282016-03-21 21:10:59 +00001393 public boolean isManagedProfile(@UserIdInt int userId) {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001394 if (userId == UserHandle.myUserId()) {
1395 return isManagedProfile();
1396 }
Tony Mak8673b282016-03-21 21:10:59 +00001397 try {
1398 return mService.isManagedProfile(userId);
1399 } catch (RemoteException re) {
1400 throw re.rethrowFromSystemServer();
1401 }
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001402 }
1403
1404 /**
Kenny Guy02c89902016-11-15 19:36:38 +00001405 * Gets badge for a managed profile.
1406 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1407 * must be in the same profile group of specified user.
1408 *
1409 * @return which badge to use for the managed profile badge id will be less than
1410 * UserManagerService.getMaxManagedProfiles()
1411 * @hide
1412 */
1413 public int getManagedProfileBadge(@UserIdInt int userId) {
1414 try {
1415 return mService.getManagedProfileBadge(userId);
1416 } catch (RemoteException re) {
1417 throw re.rethrowFromSystemServer();
1418 }
1419 }
1420
1421 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001422 * Checks if the calling app is running as an ephemeral user.
1423 *
1424 * @return whether the caller is an ephemeral user.
1425 * @hide
1426 */
1427 public boolean isEphemeralUser() {
1428 return isUserEphemeral(UserHandle.myUserId());
1429 }
1430
1431 /**
1432 * Returns whether the specified user is ephemeral.
1433 * @hide
1434 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001435 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001436 final UserInfo user = getUserInfo(userId);
1437 return user != null && user.isEphemeral();
1438 }
1439
1440 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001441 * Return whether the given user is actively running. This means that
1442 * the user is in the "started" state, not "stopped" -- it is currently
1443 * allowed to run code through scheduled alarms, receiving broadcasts,
1444 * etc. A started user may be either the current foreground user or a
1445 * background user; the result here does not distinguish between the two.
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001446 *
1447 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1448 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1449 * in order to check other profile's status.
1450 * Since Android Nougat MR1 (SDK version >= 25;
1451 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1452 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001453 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001454 * @param user The user to retrieve the running state for.
1455 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001456 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001457 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -07001458 return isUserRunning(user.getIdentifier());
1459 }
1460
1461 /** {@hide} */
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001462 public boolean isUserRunning(@UserIdInt int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001463 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001464 return mService.isUserRunning(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001465 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001466 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001467 }
1468 }
1469
1470 /**
1471 * Return whether the given user is actively running <em>or</em> stopping.
1472 * This is like {@link #isUserRunning(UserHandle)}, but will also return
1473 * true if the user had been running but is in the process of being stopped
1474 * (but is not yet fully stopped, and still running some code).
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001475 *
1476 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1477 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1478 * in order to check other profile's status.
1479 * Since Android Nougat MR1 (SDK version >= 25;
1480 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1481 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001482 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001483 * @param user The user to retrieve the running state for.
1484 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001485 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001486 public boolean isUserRunningOrStopping(UserHandle user) {
1487 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001488 // TODO: reconcile stopped vs stopping?
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001489 return ActivityManager.getService().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001490 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001491 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001492 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001493 }
1494 }
1495
Jeff Sharkey0825ab22015-12-02 13:04:49 -07001496 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001497 * Return whether the calling user is running in an "unlocked" state.
1498 * <p>
1499 * On devices with direct boot, a user is unlocked only after they've
1500 * entered their credentials (such as a lock pattern or PIN). On devices
1501 * without direct boot, a user is unlocked as soon as it starts.
1502 * <p>
1503 * When a user is locked, only device-protected data storage is available.
1504 * When a user is unlocked, both device-protected and credential-protected
1505 * private app data storage is available.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001506 *
1507 * @see Intent#ACTION_USER_UNLOCKED
1508 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001509 */
1510 public boolean isUserUnlocked() {
1511 return isUserUnlocked(Process.myUserHandle());
1512 }
1513
1514 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001515 * Return whether the given user is running in an "unlocked" state.
1516 * <p>
1517 * On devices with direct boot, a user is unlocked only after they've
1518 * entered their credentials (such as a lock pattern or PIN). On devices
1519 * without direct boot, a user is unlocked as soon as it starts.
1520 * <p>
1521 * When a user is locked, only device-protected data storage is available.
1522 * When a user is unlocked, both device-protected and credential-protected
1523 * private app data storage is available.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001524 * <p>Requires {@code android.permission.MANAGE_USERS} or
1525 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1526 * must be the calling user or a managed profile associated with it.
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001527 *
1528 * @param user to retrieve the unlocked state for.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001529 * @see Intent#ACTION_USER_UNLOCKED
1530 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001531 */
1532 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -07001533 return isUserUnlocked(user.getIdentifier());
1534 }
1535
1536 /** {@hide} */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001537 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001538 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001539 return mService.isUserUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001540 } catch (RemoteException re) {
1541 throw re.rethrowFromSystemServer();
1542 }
1543 }
1544
1545 /** {@hide} */
1546 public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1547 return isUserUnlockingOrUnlocked(user.getIdentifier());
1548 }
1549
1550 /** {@hide} */
1551 public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1552 try {
Fyodor Kupolovc413f702016-10-06 17:11:14 -07001553 return mService.isUserUnlockingOrUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001554 } catch (RemoteException re) {
1555 throw re.rethrowFromSystemServer();
1556 }
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001557 }
1558
1559 /**
Makoto Onuki73dded22017-12-20 13:14:48 +09001560 * Return the time when the calling user started in elapsed milliseconds since boot,
1561 * or 0 if not started.
1562 *
1563 * @hide
1564 */
1565 public long getUserStartRealtime() {
1566 try {
1567 return mService.getUserStartRealtime();
1568 } catch (RemoteException re) {
1569 throw re.rethrowFromSystemServer();
1570 }
1571 }
1572
1573 /**
1574 * Return the time when the calling user was unlocked elapsed milliseconds since boot,
1575 * or 0 if not unlocked.
1576 *
1577 * @hide
1578 */
1579 public long getUserUnlockRealtime() {
1580 try {
1581 return mService.getUserUnlockRealtime();
1582 } catch (RemoteException re) {
1583 throw re.rethrowFromSystemServer();
1584 }
1585 }
1586
1587 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001588 * Returns the UserInfo object describing a specific user.
Tony Mak8673b282016-03-21 21:10:59 +00001589 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001590 * @param userHandle the user handle of the user whose information is being requested.
1591 * @return the UserInfo object for a specific user.
1592 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001593 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001594 public UserInfo getUserInfo(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001595 try {
1596 return mService.getUserInfo(userHandle);
1597 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001598 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001599 }
1600 }
1601
Amith Yamasani71e6c692013-03-24 17:39:28 -07001602 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001603 * @hide
1604 *
1605 * Returns who set a user restriction on a user.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001606 * @param restrictionKey the string key representing the restriction
1607 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1608 * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1609 * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1610 * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
Pavel Grafov6a40f092016-10-25 15:46:51 +01001611 * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001612 */
Pavel Grafov6a40f092016-10-25 15:46:51 +01001613 @Deprecated
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001614 @SystemApi
1615 @UserRestrictionSource
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001616 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001617 public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1618 try {
1619 return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1620 } catch (RemoteException re) {
1621 throw re.rethrowFromSystemServer();
1622 }
1623 }
1624
1625 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +01001626 * @hide
1627 *
1628 * Returns a list of users who set a user restriction on a given user.
Pavel Grafov6a40f092016-10-25 15:46:51 +01001629 * @param restrictionKey the string key representing the restriction
1630 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1631 * @return a list of user ids enforcing this restriction.
1632 */
1633 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001634 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Pavel Grafov6a40f092016-10-25 15:46:51 +01001635 public List<EnforcingUser> getUserRestrictionSources(
1636 String restrictionKey, UserHandle userHandle) {
1637 try {
1638 return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
1639 } catch (RemoteException re) {
1640 throw re.rethrowFromSystemServer();
1641 }
1642 }
1643
1644 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07001645 * Returns the user-wide restrictions imposed on this user.
1646 * @return a Bundle containing all the restrictions.
1647 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001648 public Bundle getUserRestrictions() {
1649 return getUserRestrictions(Process.myUserHandle());
1650 }
1651
Amith Yamasani71e6c692013-03-24 17:39:28 -07001652 /**
1653 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
1654 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1655 * @return a Bundle containing all the restrictions.
1656 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001657 public Bundle getUserRestrictions(UserHandle userHandle) {
1658 try {
1659 return mService.getUserRestrictions(userHandle.getIdentifier());
1660 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001661 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001662 }
1663 }
1664
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001665 /**
1666 * @hide
1667 * Returns whether the given user has been disallowed from performing certain actions
1668 * or setting certain settings through UserManager. This method disregards restrictions
1669 * set by device policy.
1670 * @param restrictionKey the string key representing the restriction
1671 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1672 */
1673 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
1674 try {
1675 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
1676 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001677 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001678 }
1679 }
1680
Amith Yamasani71e6c692013-03-24 17:39:28 -07001681 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001682 * This will no longer work. Device owners and profile owners should use
1683 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001684 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001685 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001686 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001687 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001688 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001689 }
1690
Amith Yamasani71e6c692013-03-24 17:39:28 -07001691 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001692 * This will no longer work. Device owners and profile owners should use
1693 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001694 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001695 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001696 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001697 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001698 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001699 }
1700
Amith Yamasani71e6c692013-03-24 17:39:28 -07001701 /**
1702 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07001703 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001704 * @param key the key of the restriction
1705 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001706 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1707 * android.content.ComponentName, String)} or
1708 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1709 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001710 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001711 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07001712 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001713 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07001714 }
1715
1716 /**
1717 * @hide
1718 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07001719 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001720 * @param key the key of the restriction
1721 * @param value the value for the restriction
1722 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001723 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1724 * android.content.ComponentName, String)} or
1725 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1726 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001727 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001728 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05001729 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001730 try {
1731 mService.setUserRestriction(key, value, userHandle.getIdentifier());
1732 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001733 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001734 }
Maggie Benthall67944582013-02-22 14:58:27 -05001735 }
1736
Amith Yamasani258848d2012-08-10 17:06:33 -07001737 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001738 * Returns whether the current user has been disallowed from performing certain actions
1739 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04001740 *
1741 * @param restrictionKey The string key representing the restriction.
1742 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001743 */
1744 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -07001745 return hasUserRestriction(restrictionKey, Process.myUserHandle());
1746 }
1747
1748 /**
1749 * @hide
1750 * Returns whether the given user has been disallowed from performing certain actions
1751 * or setting certain settings.
1752 * @param restrictionKey the string key representing the restriction
1753 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1754 */
1755 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001756 try {
1757 return mService.hasUserRestriction(restrictionKey,
1758 userHandle.getIdentifier());
1759 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001760 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001761 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001762 }
1763
1764 /**
Makoto Onukiacc50462018-02-14 14:13:49 -08001765 * @hide
1766 * Returns whether any user on the device has the given user restriction set.
1767 */
1768 public boolean hasUserRestrictionOnAnyUser(String restrictionKey) {
1769 try {
1770 return mService.hasUserRestrictionOnAnyUser(restrictionKey);
1771 } catch (RemoteException re) {
1772 throw re.rethrowFromSystemServer();
1773 }
1774 }
1775
1776 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001777 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001778 * number assigned to that user; if the user is deleted and then a new
1779 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001780 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001781 * @return The serial number of the given user; returns -1 if the
1782 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001783 * @see #getUserForSerialNumber(long)
1784 */
1785 public long getSerialNumberForUser(UserHandle user) {
1786 return getUserSerialNumber(user.getIdentifier());
1787 }
1788
1789 /**
1790 * Return the user associated with a serial number previously
1791 * returned by {@link #getSerialNumberForUser(UserHandle)}.
1792 * @param serialNumber The serial number of the user that is being
1793 * retrieved.
1794 * @return Return the user associated with the serial number, or null
1795 * if there is not one.
1796 * @see #getSerialNumberForUser(UserHandle)
1797 */
1798 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07001799 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001800 return ident >= 0 ? new UserHandle(ident) : null;
1801 }
1802
1803 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001804 * Creates a user with the specified name and options. For non-admin users, default user
1805 * restrictions are going to be applied.
Amith Yamasani195263742012-08-21 15:40:12 -07001806 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001807 *
1808 * @param name the user's name
1809 * @param flags flags that identify the type of user and other properties.
1810 * @see UserInfo
1811 *
1812 * @return the UserInfo object for the created user, or null if the user could not be created.
1813 * @hide
1814 */
1815 public UserInfo createUser(String name, int flags) {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001816 UserInfo user = null;
Amith Yamasani258848d2012-08-10 17:06:33 -07001817 try {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001818 user = mService.createUser(name, flags);
phweisse9c44062016-02-10 12:57:38 +01001819 // TODO: Keep this in sync with
1820 // UserManagerService.LocalService.createUserEvenWhenDisallowed
Christine Franks97a54802017-08-09 10:06:43 -07001821 if (user != null && !user.isAdmin() && !user.isDemo()) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001822 mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1823 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001824 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001825 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001826 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001827 }
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001828 return user;
Amith Yamasani258848d2012-08-10 17:06:33 -07001829 }
1830
1831 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001832 * Creates a guest user and configures it.
1833 * @param context an application context
1834 * @param name the name to set for the user
1835 * @hide
1836 */
1837 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001838 UserInfo guest = null;
1839 try {
1840 guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1841 if (guest != null) {
1842 Settings.Secure.putStringForUser(context.getContentResolver(),
1843 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001844 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07001845 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001846 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001847 }
1848 return guest;
1849 }
1850
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07001851 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001852 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001853 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1854 *
1855 * @param name the user's name
1856 * @param flags flags that identify the type of user and other properties.
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001857 * @param userHandle new user will be a profile of this user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001858 *
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001859 * @return the {@link UserInfo} object for the created user, or null if the user
1860 * could not be created.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001861 * @hide
1862 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001863 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001864 return createProfileForUser(name, flags, userHandle, null);
1865 }
1866
1867 /**
1868 * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
1869 * any packages that should not be installed in the new profile by default, these packages can
1870 * still be installed later by the user if needed.
1871 *
1872 * @param name the user's name
1873 * @param flags flags that identify the type of user and other properties.
1874 * @param userHandle new user will be a profile of this user.
1875 * @param disallowedPackages packages that will not be installed in the profile being created.
1876 *
1877 * @return the {@link UserInfo} object for the created user, or null if the user
1878 * could not be created.
1879 * @hide
1880 */
1881 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
1882 String[] disallowedPackages) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001883 try {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001884 return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001885 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001886 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001887 }
1888 }
1889
1890 /**
Tony Mak6dc428f2016-10-10 15:48:27 +01001891 * Similar to {@link #createProfileForUser(String, int, int, String[])}
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001892 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
Tony Mak6dc428f2016-10-10 15:48:27 +01001893 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1894 *
1895 * @see #createProfileForUser(String, int, int, String[])
1896 * @hide
1897 */
1898 public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
1899 @UserIdInt int userHandle, String[] disallowedPackages) {
1900 try {
1901 return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
1902 disallowedPackages);
1903 } catch (RemoteException re) {
1904 throw re.rethrowFromSystemServer();
1905 }
1906 }
1907
1908 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001909 * Creates a restricted profile with the specified name. This method also sets necessary
1910 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001911 *
1912 * @param name profile's name
1913 * @return UserInfo object for the created user, or null if the user could not be created.
1914 * @hide
1915 */
1916 public UserInfo createRestrictedProfile(String name) {
1917 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001918 UserHandle parentUserHandle = Process.myUserHandle();
1919 UserInfo user = mService.createRestrictedProfile(name,
1920 parentUserHandle.getIdentifier());
1921 if (user != null) {
1922 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
1923 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001924 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001925 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001926 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001927 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001928 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001929 }
1930
1931 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001932 * Returns an intent to create a user for the provided name and account name. The name
1933 * and account name will be used when the setup process for the new user is started.
1934 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001935 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001936 * indicate if the user consented to adding a new user and if the operation succeeded. Any
1937 * errors in creating the user will be returned in the result code. If the user cancels the
1938 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
1939 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani06964342016-04-15 13:55:01 -07001940 * <p>
1941 * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
1942 * at all.
1943 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001944 * The new user is created but not initialized. After switching into the user for the first
1945 * time, the preferred user name and account information are used by the setup process for that
1946 * user.
1947 *
1948 * @param userName Optional name to assign to the user.
Amith Yamasani06964342016-04-15 13:55:01 -07001949 * @param accountName Optional account name that will be used by the setup wizard to initialize
Amith Yamasani12747872015-12-07 14:19:49 -08001950 * the user.
1951 * @param accountType Optional account type for the account to be created. This is required
1952 * if the account name is specified.
1953 * @param accountOptions Optional bundle of data to be passed in during account creation in the
1954 * new user via {@link AccountManager#addAccount(String, String, String[],
1955 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
1956 * Handler)}.
Amith Yamasani06964342016-04-15 13:55:01 -07001957 * @return An Intent that can be launched from an Activity.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001958 * @see #USER_CREATION_FAILED_NOT_PERMITTED
1959 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani06964342016-04-15 13:55:01 -07001960 * @see #supportsMultipleUsers
Amith Yamasani12747872015-12-07 14:19:49 -08001961 */
1962 public static Intent createUserCreationIntent(@Nullable String userName,
1963 @Nullable String accountName,
1964 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
Amith Yamasani12747872015-12-07 14:19:49 -08001965 Intent intent = new Intent(ACTION_CREATE_USER);
1966 if (userName != null) {
1967 intent.putExtra(EXTRA_USER_NAME, userName);
1968 }
1969 if (accountName != null && accountType == null) {
1970 throw new IllegalArgumentException("accountType must be specified if accountName is "
1971 + "specified");
1972 }
1973 if (accountName != null) {
1974 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
1975 }
1976 if (accountType != null) {
1977 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
1978 }
1979 if (accountOptions != null) {
1980 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
1981 }
1982 return intent;
1983 }
1984
1985 /**
1986 * @hide
1987 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001988 * Returns the preferred account name for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08001989 */
1990 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001991 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08001992 public String getSeedAccountName() {
1993 try {
1994 return mService.getSeedAccountName();
1995 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001996 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001997 }
1998 }
1999
2000 /**
2001 * @hide
2002 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002003 * Returns the preferred account type for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002004 */
2005 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002006 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002007 public String getSeedAccountType() {
2008 try {
2009 return mService.getSeedAccountType();
2010 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002011 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002012 }
2013 }
2014
2015 /**
2016 * @hide
2017 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002018 * Returns the preferred account's options bundle for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08002019 * @return Any options set by the requestor that created the user.
2020 */
2021 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002022 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002023 public PersistableBundle getSeedAccountOptions() {
2024 try {
2025 return mService.getSeedAccountOptions();
2026 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002027 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002028 }
2029 }
2030
2031 /**
2032 * @hide
2033 *
2034 * Called by a system activity to set the seed account information of a user created
2035 * through the user creation intent.
2036 * @param userId
2037 * @param accountName
2038 * @param accountType
2039 * @param accountOptions
2040 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
2041 */
2042 public void setSeedAccountData(int userId, String accountName, String accountType,
2043 PersistableBundle accountOptions) {
2044 try {
2045 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
2046 /* persist= */ true);
2047 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002048 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002049 }
2050 }
2051
2052 /**
2053 * @hide
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002054 * Clears the seed information used to create this user.
Amith Yamasani12747872015-12-07 14:19:49 -08002055 */
2056 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002057 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08002058 public void clearSeedAccountData() {
2059 try {
2060 mService.clearSeedAccountData();
2061 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002062 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002063 }
2064 }
2065
2066 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07002067 * @hide
2068 * Marks the guest user for deletion to allow a new guest to be created before deleting
2069 * the current user who is a guest.
2070 * @param userHandle
2071 * @return
2072 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002073 public boolean markGuestForDeletion(@UserIdInt int userHandle) {
Amith Yamasani1df14732014-08-29 21:37:27 -07002074 try {
2075 return mService.markGuestForDeletion(userHandle);
2076 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002077 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07002078 }
2079 }
2080
2081 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002082 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01002083 *
2084 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2085 *
2086 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
2087 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
2088 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002089 *
jovanakf24ad492018-05-18 12:15:59 -07002090 * @param userId the id of the profile to enable
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002091 * @hide
2092 */
jovanakf24ad492018-05-18 12:15:59 -07002093 public void setUserEnabled(@UserIdInt int userId) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002094 try {
jovanakf24ad492018-05-18 12:15:59 -07002095 mService.setUserEnabled(userId);
2096 } catch (RemoteException re) {
2097 throw re.rethrowFromSystemServer();
2098 }
2099 }
2100
2101 /**
2102 * Assigns admin privileges to the user, if such a user exists.
2103 *
2104 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} and
2105 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions.
2106 *
2107 * @param userHandle the id of the user to become admin
2108 * @hide
2109 */
2110 @RequiresPermission(allOf = {
2111 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2112 Manifest.permission.MANAGE_USERS
2113 })
2114 public void setUserAdmin(@UserIdInt int userHandle) {
2115 try {
2116 mService.setUserAdmin(userHandle);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002117 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002118 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002119 }
2120 }
2121
2122 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002123 * Evicts the user's credential encryption key from memory by stopping and restarting the user.
2124 *
2125 * @hide
2126 */
2127 public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
2128 try {
2129 mService.evictCredentialEncryptionKey(userHandle);
2130 } catch (RemoteException re) {
2131 throw re.rethrowFromSystemServer();
2132 }
2133 }
2134
2135 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07002136 * Return the number of users currently created on the device.
2137 */
2138 public int getUserCount() {
2139 List<UserInfo> users = getUsers();
2140 return users != null ? users.size() : 1;
2141 }
2142
2143 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07002144 * Returns information for all users on this device, including ones marked for deletion.
2145 * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
2146 * <p>
Amith Yamasani195263742012-08-21 15:40:12 -07002147 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002148 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07002149 * @hide
2150 */
2151 public List<UserInfo> getUsers() {
2152 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07002153 return mService.getUsers(false);
2154 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002155 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07002156 }
2157 }
2158
2159 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002160 * Returns serial numbers of all users on this device.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002161 *
2162 * @param excludeDying specify if the list should exclude users being removed.
2163 * @return the list of serial numbers of users that exist on the device.
2164 * @hide
2165 */
2166 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002167 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002168 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
2169 try {
2170 List<UserInfo> users = mService.getUsers(excludeDying);
2171 long[] result = new long[users.size()];
2172 for (int i = 0; i < result.length; i++) {
2173 result[i] = users.get(i).serialNumber;
2174 }
2175 return result;
2176 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002177 throw re.rethrowFromSystemServer();
Fyodor Kupolov940e8572016-01-26 12:03:51 -08002178 }
2179 }
2180
2181 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002182 * @return the user's account name, null if not found.
2183 * @hide
2184 */
2185 @RequiresPermission( allOf = {
2186 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2187 Manifest.permission.MANAGE_USERS
2188 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002189 public @Nullable String getUserAccount(@UserIdInt int userHandle) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002190 try {
2191 return mService.getUserAccount(userHandle);
2192 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002193 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002194 }
2195 }
2196
2197 /**
2198 * Set account name for the given user.
2199 * @hide
2200 */
2201 @RequiresPermission( allOf = {
2202 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
2203 Manifest.permission.MANAGE_USERS
2204 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002205 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002206 try {
2207 mService.setUserAccount(userHandle, accountName);
2208 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002209 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08002210 }
2211 }
2212
2213 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002214 * Returns information for Primary user.
2215 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2216 *
2217 * @return the Primary user, null if not found.
2218 * @hide
2219 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002220 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002221 try {
2222 return mService.getPrimaryUser();
2223 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002224 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07002225 }
2226 }
2227
2228 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07002229 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
2230 * permission.
2231 *
2232 * @return true if more users can be added, false if limit has been reached.
2233 * @hide
2234 */
2235 public boolean canAddMoreUsers() {
2236 final List<UserInfo> users = getUsers(true);
2237 final int totalUserCount = users.size();
2238 int aliveUserCount = 0;
2239 for (int i = 0; i < totalUserCount; i++) {
2240 UserInfo user = users.get(i);
2241 if (!user.isGuest()) {
2242 aliveUserCount++;
2243 }
2244 }
2245 return aliveUserCount < getMaxSupportedUsers();
2246 }
2247
2248 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07002249 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
2250 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002251 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
2252 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07002253 *
2254 * @return true if more managed profiles can be added, false if limit has been reached.
2255 * @hide
2256 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002257 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07002258 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00002259 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07002260 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002261 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07002262 }
2263 }
2264
2265 /**
Kenny Guy2a764942014-04-02 13:29:20 +01002266 * Returns list of the profiles of userHandle including
2267 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07002268 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07002269 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08002270 *
Kenny Guy2a764942014-04-02 13:29:20 +01002271 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2272 * @param userHandle profiles of this user will be returned.
2273 * @return the list of profiles.
2274 * @hide
2275 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002276 public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00002277 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002278 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00002279 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002280 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00002281 }
2282 }
2283
2284 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002285 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2286 * @param userId one of the two user ids to check.
2287 * @param otherUserId one of the two user ids to check.
2288 * @return true if the two user ids are in the same profile group.
2289 * @hide
2290 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002291 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002292 try {
2293 return mService.isSameProfileGroup(userId, otherUserId);
2294 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002295 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07002296 }
2297 }
2298
2299 /**
Ruben Brunk7f75da22015-04-30 17:46:30 -07002300 * Returns list of the profiles of userHandle including
2301 * userHandle itself.
2302 * Note that this returns only enabled.
2303 *
2304 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2305 * @param userHandle profiles of this user will be returned.
2306 * @return the list of profiles.
2307 * @hide
2308 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002309 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07002310 try {
2311 return mService.getProfiles(userHandle, true /* enabledOnly */);
2312 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002313 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07002314 }
2315 }
2316
2317 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002318 * Returns a list of UserHandles for profiles associated with the user that the calling process
2319 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08002320 *
2321 * @return A non-empty list of UserHandles associated with the calling user.
2322 */
2323 public List<UserHandle> getUserProfiles() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002324 int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
2325 List<UserHandle> result = new ArrayList<>(userIds.length);
2326 for (int userId : userIds) {
2327 result.add(UserHandle.of(userId));
2328 }
2329 return result;
2330 }
2331
2332 /**
2333 * Returns a list of ids for profiles associated with the specified user including the user
2334 * itself.
2335 *
2336 * @param userId id of the user to return profiles for
2337 * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
2338 * @return A non-empty list of ids of profiles associated with the specified user.
2339 *
2340 * @hide
2341 */
2342 public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002343 try {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002344 return mService.getProfileIds(userId, enabledOnly);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002345 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002346 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01002347 }
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07002348 }
2349
2350 /**
2351 * @see #getProfileIds(int, boolean)
2352 * @hide
2353 */
2354 public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
2355 return getProfileIds(userId, false /* enabledOnly */);
2356 }
2357
2358 /**
2359 * @see #getProfileIds(int, boolean)
2360 * @hide
2361 */
2362 public int[] getEnabledProfileIds(@UserIdInt int userId) {
2363 return getProfileIds(userId, true /* enabledOnly */);
Amith Yamasani4f582632014-02-19 14:31:52 -08002364 }
2365
Amith Yamasani7dda2652014-04-11 14:57:12 -07002366 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07002367 * Returns the device credential owner id of the profile from
2368 * which this method is called, or userHandle if called from a user that
2369 * is not a profile.
2370 *
2371 * @hide
2372 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002373 public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
Andres Moralesc5548c02015-08-05 10:23:12 -07002374 try {
2375 return mService.getCredentialOwnerProfile(userHandle);
2376 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002377 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07002378 }
2379 }
2380
2381 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002382 * Returns the parent of the profile which this method is called from
2383 * or null if called from a user that is not a profile.
2384 *
2385 * @hide
2386 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002387 public UserInfo getProfileParent(@UserIdInt int userHandle) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01002388 try {
2389 return mService.getProfileParent(userHandle);
2390 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002391 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01002392 }
2393 }
2394
2395 /**
Tony Make3d1f652017-12-12 11:00:37 +00002396 * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a
2397 * managed profile don't run, generate notifications, or consume data or battery.
2398 * <p>
2399 * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be
2400 * shown to the user.
2401 * <p>
2402 * The change may not happen instantly, however apps can listen for
2403 * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and
2404 * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of
2405 * the change of the quiet mode. Apps can also check the current state of quiet mode by
2406 * calling {@link #isQuietModeEnabled(UserHandle)}.
2407 * <p>
2408 * The caller must either be the foreground default launcher or have one of these permissions:
2409 * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002410 *
Tony Make3d1f652017-12-12 11:00:37 +00002411 * @param enableQuietMode whether quiet mode should be enabled or disabled
2412 * @param userHandle user handle of the profile
2413 * @return {@code false} if user's credential is needed in order to turn off quiet mode,
2414 * {@code true} otherwise
2415 * @throws SecurityException if the caller is invalid
2416 * @throws IllegalArgumentException if {@code userHandle} is not a managed profile
2417 *
2418 * @see #isQuietModeEnabled(UserHandle)
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002419 */
Tony Makbece85d2018-01-12 12:10:17 +00002420 public boolean requestQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) {
2421 return requestQuietModeEnabled(enableQuietMode, userHandle, null);
Tony Makb7e6fd42017-12-05 19:40:28 +00002422 }
2423
2424 /**
Tony Makbece85d2018-01-12 12:10:17 +00002425 * Similar to {@link #requestQuietModeEnabled(boolean, UserHandle)}, except you can specify
Tony Makd390ae92017-12-28 13:23:10 +00002426 * a target to start when user is unlocked. If {@code target} is specified, caller must have
2427 * the {@link android.Manifest.permission#MANAGE_USERS} permission.
Tony Makb7e6fd42017-12-05 19:40:28 +00002428 *
Tony Makbece85d2018-01-12 12:10:17 +00002429 * @see {@link #requestQuietModeEnabled(boolean, UserHandle)}
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002430 * @hide
2431 */
Tony Makbece85d2018-01-12 12:10:17 +00002432 public boolean requestQuietModeEnabled(
Tony Makb7e6fd42017-12-05 19:40:28 +00002433 boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002434 try {
Tony Makbece85d2018-01-12 12:10:17 +00002435 return mService.requestQuietModeEnabled(
Tony Make3d1f652017-12-12 11:00:37 +00002436 mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002437 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002438 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002439 }
2440 }
2441
2442 /**
2443 * Returns whether the given profile is in quiet mode or not.
Ricky Wai7881cf82016-04-15 17:20:12 +01002444 * Notes: Quiet mode is only supported for managed profiles.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002445 *
2446 * @param userHandle The user handle of the profile to be queried.
2447 * @return true if the profile is in quiet mode, false otherwise.
2448 */
2449 public boolean isQuietModeEnabled(UserHandle userHandle) {
2450 try {
2451 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002452 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002453 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002454 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002455 }
2456
2457 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -07002458 * If the target user is a managed profile of the calling user or the caller
2459 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07002460 * icon to be able to distinguish it from the original icon. For badging an
2461 * arbitrary drawable use {@link #getBadgedDrawableForUser(
2462 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2463 * <p>
2464 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002465 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002466 * is performed in place and the original drawable is returned.
2467 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07002468 *
2469 * @param icon The icon to badge.
2470 * @param user The target user.
2471 * @return A drawable that combines the original icon and a badge as
2472 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002473 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07002474 */
Svetoslavc71c42f2014-08-05 18:57:05 -07002475 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002476 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002477 }
2478
Kenny Guy701ea7c2014-05-08 23:34:12 +01002479 /**
2480 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -07002481 * is itself a managed profile, then this returns a badged copy of the given
2482 * drawable allowing the user to distinguish it from the original drawable.
2483 * The caller can specify the location in the bounds of the drawable to be
2484 * badged where the badge should be applied as well as the density of the
2485 * badge to be used.
2486 * <p>
2487 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002488 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002489 * is performed in place and the original drawable is returned.
2490 * </p>
2491 *
2492 * @param badgedDrawable The drawable to badge.
2493 * @param user The target user.
2494 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002495 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07002496 * drawable being badged.
2497 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002498 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07002499 * the density of the display is used.
2500 * @return A drawable that combines the original drawable and a badge as
2501 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002502 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07002503 */
2504 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2505 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002506 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2507 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07002508 }
2509
2510 /**
2511 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002512 * is itself a managed profile, then this returns a copy of the label with
2513 * badging for accessibility services like talkback. E.g. passing in "Email"
2514 * and it might return "Work Email" for Email in the work profile.
2515 *
2516 * @param label The label to change.
2517 * @param user The target user.
2518 * @return A label that combines the original label and a badge as
2519 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002520 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002521 */
Kenny Guy237aecd2014-07-21 14:06:09 +01002522 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002523 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002524 }
2525
2526 /**
2527 * Returns information for all users on this device. Requires
2528 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04002529 *
Amith Yamasani4f582632014-02-19 14:31:52 -08002530 * @param excludeDying specify if the list should exclude users being
2531 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07002532 * @return the list of users that were created.
2533 * @hide
2534 */
Adam Lesinskiada8deb2017-05-12 13:50:42 -07002535 public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
Amith Yamasani920ace02012-09-20 22:15:37 -07002536 try {
2537 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07002538 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002539 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002540 }
2541 }
2542
2543 /**
2544 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07002545 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002546 * @param userHandle the integer handle of the user, where 0 is the primary user.
2547 * @hide
2548 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002549 public boolean removeUser(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002550 try {
2551 return mService.removeUser(userHandle);
2552 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002553 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002554 }
2555 }
2556
2557 /**
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00002558 * Similar to {@link #removeUser(int)} except bypassing the checking of
2559 * {@link UserManager#DISALLOW_REMOVE_USER}
2560 * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2561 *
2562 * @see {@link #removeUser(int)}
2563 * @hide
2564 */
2565 public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2566 try {
2567 return mService.removeUserEvenWhenDisallowed(userHandle);
2568 } catch (RemoteException re) {
2569 throw re.rethrowFromSystemServer();
2570 }
2571 }
2572
2573 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002574 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07002575 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002576 *
2577 * @param userHandle the user's integer handle
2578 * @param name the new name for the user
2579 * @hide
2580 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002581 public void setUserName(@UserIdInt int userHandle, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002582 try {
2583 mService.setUserName(userHandle, name);
2584 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002585 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002586 }
2587 }
2588
2589 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002590 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002591 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002592 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002593 * @hide
2594 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002595 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002596 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002597 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07002598 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002599 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002600 }
2601 }
2602
2603 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07002604 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
2605 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002606 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002607 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07002608 * @hide
2609 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002610 public Bitmap getUserIcon(@UserIdInt int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07002611 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01002612 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
2613 if (fd != null) {
2614 try {
2615 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
2616 } finally {
2617 try {
2618 fd.close();
2619 } catch (IOException e) {
2620 }
2621 }
2622 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07002623 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002624 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07002625 }
Adrian Roos1bdff912015-02-17 15:51:35 +01002626 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07002627 }
2628
2629 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002630 * Returns the maximum number of users that can be created on this device. A return value
2631 * of 1 means that it is a single user device.
2632 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002633 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07002634 */
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002635 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07002636 // Don't allow multiple users on certain builds
2637 if (android.os.Build.ID.startsWith("JVP")) return 1;
Robin Lee83c79312018-02-09 19:27:18 +01002638 if (ActivityManager.isLowRamDeviceStatic()) {
2639 // Low-ram devices are Svelte. Most of the time they don't get multi-user.
2640 if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
2641 != Configuration.UI_MODE_TYPE_TELEVISION) {
2642 return 1;
2643 }
2644 }
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002645 return SystemProperties.getInt("fw.max_users",
2646 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07002647 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002648
2649 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002650 * Returns true if the user switcher should be shown, this will be if device supports multi-user
2651 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00002652 * @hide
2653 * @return true if user switcher should be shown.
2654 */
2655 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002656 if (!supportsMultipleUsers()) {
2657 return false;
2658 }
Benjamin Franzff66fa92017-08-10 10:39:44 +01002659 if (hasUserRestriction(DISALLOW_USER_SWITCH)) {
2660 return false;
2661 }
Amith Yamasanieb437d42016-04-29 09:31:25 -07002662 // If Demo Mode is on, don't show user switcher
2663 if (isDeviceInDemoMode(mContext)) {
2664 return false;
2665 }
Kenny Guy1a447532014-02-20 21:55:32 +00002666 List<UserInfo> users = getUsers(true);
2667 if (users == null) {
2668 return false;
2669 }
2670 int switchableUserCount = 0;
2671 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002672 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00002673 ++switchableUserCount;
2674 }
2675 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002676 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2677 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07002678 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00002679 }
2680
2681 /**
Amith Yamasanieb437d42016-04-29 09:31:25 -07002682 * @hide
2683 */
2684 public static boolean isDeviceInDemoMode(Context context) {
2685 return Settings.Global.getInt(context.getContentResolver(),
2686 Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2687 }
2688
2689 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07002690 * Returns a serial number on this device for a given userHandle. User handles can be recycled
2691 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
2692 * @param userHandle
2693 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
2694 * @hide
2695 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002696 public int getUserSerialNumber(@UserIdInt int userHandle) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002697 try {
2698 return mService.getUserSerialNumber(userHandle);
2699 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002700 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002701 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002702 }
2703
2704 /**
2705 * Returns a userHandle on this device for a given user serial number. User handles can be
2706 * recycled when deleting and creating users, but serial numbers are not reused until the device
2707 * is wiped.
2708 * @param userSerialNumber
2709 * @return the userHandle associated with that user serial number, or -1 if the serial number
2710 * is not valid.
2711 * @hide
2712 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002713 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002714 try {
2715 return mService.getUserHandle(userSerialNumber);
2716 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002717 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002718 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002719 }
Maggie Benthall67944582013-02-22 14:58:27 -05002720
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002721 /**
Esteban Talavera953fe482016-06-07 15:25:20 +01002722 * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002723 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002724 *
2725 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
2726 * where the types of values may be:
2727 * <ul>
2728 * <li>{@code boolean}
2729 * <li>{@code int}
2730 * <li>{@code String} or {@code String[]}
2731 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
2732 * </ul>
2733 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002734 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
2735 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002736 * @param packageName the package name of the calling application
Esteban Talavera953fe482016-06-07 15:25:20 +01002737 * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2738 * if there are no saved restrictions.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002739 *
2740 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002741 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002742 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002743 public Bundle getApplicationRestrictions(String packageName) {
2744 try {
2745 return mService.getApplicationRestrictions(packageName);
2746 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002747 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002748 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002749 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002750
2751 /**
2752 * @hide
2753 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002754 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002755 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002756 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002757 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002758 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002759 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002760 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002761 }
2762
2763 /**
2764 * @hide
2765 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002766 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002767 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002768 UserHandle user) {
2769 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002770 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002771 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002772 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002773 }
2774 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002775
2776 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07002777 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2778 * apps and requires the MANAGE_USERS permission.
2779 * @param newPin the PIN to use for challenge dialogs.
2780 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07002781 * @deprecated The restrictions PIN functionality is no longer provided by the system.
2782 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07002783 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07002784 @Deprecated
Amith Yamasanid304af62013-09-05 09:30:23 -07002785 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002786 return false;
2787 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07002788
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302789 /**
2790 * @hide
2791 * Set restrictions that should apply to any future guest user that's created.
2792 */
2793 public void setDefaultGuestRestrictions(Bundle restrictions) {
2794 try {
2795 mService.setDefaultGuestRestrictions(restrictions);
2796 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002797 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302798 }
2799 }
2800
2801 /**
2802 * @hide
2803 * Gets the default guest restrictions.
2804 */
2805 public Bundle getDefaultGuestRestrictions() {
2806 try {
2807 return mService.getDefaultGuestRestrictions();
2808 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002809 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302810 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302811 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002812
2813 /**
2814 * Returns creation time of the user or of a managed profile associated with the calling user.
2815 * @param userHandle user handle of the user or a managed profile associated with the
2816 * calling user.
2817 * @return creation time in milliseconds since Epoch time.
2818 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07002819 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002820 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07002821 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002822 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002823 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002824 }
2825 }
Amith Yamasani12747872015-12-07 14:19:49 -08002826
2827 /**
2828 * @hide
2829 * Checks if any uninitialized user has the specific seed account name and type.
2830 *
Pavel Grafov6a40f092016-10-25 15:46:51 +01002831 * @param accountName The account name to check for
2832 * @param accountType The account type of the account to check for
Amith Yamasani12747872015-12-07 14:19:49 -08002833 * @return whether the seed account was found
2834 */
2835 public boolean someUserHasSeedAccount(String accountName, String accountType) {
2836 try {
2837 return mService.someUserHasSeedAccount(accountName, accountType);
2838 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002839 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002840 }
2841 }
Pavel Grafov6a40f092016-10-25 15:46:51 +01002842
2843 /**
2844 * @hide
2845 * User that enforces a restriction.
2846 *
2847 * @see #getUserRestrictionSources(String, UserHandle)
2848 */
2849 @SystemApi
2850 public static final class EnforcingUser implements Parcelable {
2851 private final @UserIdInt int userId;
2852 private final @UserRestrictionSource int userRestrictionSource;
2853
2854 /**
2855 * @hide
2856 */
2857 public EnforcingUser(
2858 @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
2859 this.userId = userId;
2860 this.userRestrictionSource = userRestrictionSource;
2861 }
2862
2863 private EnforcingUser(Parcel in) {
2864 userId = in.readInt();
2865 userRestrictionSource = in.readInt();
2866 }
2867
2868 public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
2869 @Override
2870 public EnforcingUser createFromParcel(Parcel in) {
2871 return new EnforcingUser(in);
2872 }
2873
2874 @Override
2875 public EnforcingUser[] newArray(int size) {
2876 return new EnforcingUser[size];
2877 }
2878 };
2879
2880 @Override
2881 public int describeContents() {
2882 return 0;
2883 }
2884
2885 @Override
2886 public void writeToParcel(Parcel dest, int flags) {
2887 dest.writeInt(userId);
2888 dest.writeInt(userRestrictionSource);
2889 }
2890
2891 /**
2892 * Returns an id of the enforcing user.
2893 *
2894 * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
2895 */
2896 public UserHandle getUserHandle() {
2897 return UserHandle.of(userId);
2898 }
2899
2900 /**
2901 * Returns the status of the enforcing user.
2902 *
2903 * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
2904 * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
2905 * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
2906 */
2907 public @UserRestrictionSource int getUserRestrictionSource() {
2908 return userRestrictionSource;
2909 }
2910 }
Amith Yamasani258848d2012-08-10 17:06:33 -07002911}