blob: 430a5e3e72811126bb6d1e4f5842a72f04045561 [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;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070039import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050040import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010041import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080042import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080043import android.graphics.drawable.Drawable;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070044import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080045import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040046import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070047
Maggie Benthall67944582013-02-22 14:58:27 -050048import com.android.internal.R;
John Reckaa67f682016-09-20 14:24:21 -070049import com.android.internal.os.RoSystemProperties;
Maggie Benthall67944582013-02-22 14:58:27 -050050
Adrian Roos1bdff912015-02-17 15:51:35 +010051import java.io.IOException;
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010052import java.lang.annotation.Retention;
53import java.lang.annotation.RetentionPolicy;
Amith Yamasani4f582632014-02-19 14:31:52 -080054import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070055import java.util.List;
56
57/**
Amith Yamasani06964342016-04-15 13:55:01 -070058 * Manages users and user details on a multi-user system. There are two major categories of
59 * users: fully customizable users with their own login, and managed profiles that share a workspace
60 * with a related user.
61 * <p>
62 * Users are different from accounts, which are managed by
63 * {@link AccountManager}. Each user can have their own set of accounts.
64 * <p>
65 * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
Amith Yamasani258848d2012-08-10 17:06:33 -070066 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060067@SystemService(Context.USER_SERVICE)
Amith Yamasani258848d2012-08-10 17:06:33 -070068public class UserManager {
69
Pavel Grafov4f4f6f82017-03-28 13:44:04 +010070 private static final String TAG = "UserManager";
Amith Yamasani258848d2012-08-10 17:06:33 -070071 private final IUserManager mService;
72 private final Context mContext;
73
Makoto Onukid49f3fa2017-01-25 14:09:48 -080074 private Boolean mIsManagedProfileCached;
75
Amith Yamasanie4cf7342012-12-17 11:12:09 -080076 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +010077 * @hide
78 * No user restriction.
79 */
80 @SystemApi
81 public static final int RESTRICTION_NOT_SET = 0x0;
82
83 /**
84 * @hide
85 * User restriction set by system/user.
86 */
87 @SystemApi
88 public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
89
90 /**
91 * @hide
92 * User restriction set by a device owner.
93 */
94 @SystemApi
95 public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
96
97 /**
98 * @hide
99 * User restriction set by a profile owner.
100 */
101 @SystemApi
102 public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
103
104 /** @hide */
105 @Retention(RetentionPolicy.SOURCE)
106 @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM,
107 RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER})
108 @SystemApi
109 public @interface UserRestrictionSource {}
110
111 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -0700112 * Specifies if a user is disallowed from adding and removing accounts, unless they are
113 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
114 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700115 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700116 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +0000117 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
118 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
119 * management is disallowed.
120 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800121 * <p>Key for user restrictions.
122 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700123 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
124 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800125 * @see #getUserRestrictions()
126 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700127 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800128
129 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700130 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -0400131 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800132 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700133 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800134 * <p>Key for user restrictions.
135 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700136 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
137 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800138 * @see #getUserRestrictions()
139 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700140 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800141
142 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700143 * Specifies if a user is disallowed from installing applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700144 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700145 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800146 * <p>Key for user restrictions.
147 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700148 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
149 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800150 * @see #getUserRestrictions()
151 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700152 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800153
154 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700155 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700156 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700157 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800158 * <p>Key for user restrictions.
159 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700160 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
161 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800162 * @see #getUserRestrictions()
163 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700164 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800165
Amith Yamasani71e6c692013-03-24 17:39:28 -0700166 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800167 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700168 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800169 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800170 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700171 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800172 * <p>Key for user restrictions.
173 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700174 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
175 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500176 * @see #getUserRestrictions()
177 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700178 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500179
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400180 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700181 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400182 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
183 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700184 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800185 * <p>Key for user restrictions.
186 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700187 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
188 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400189 * @see #getUserRestrictions()
190 */
191 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
192
193 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700194 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000195 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400196 * The default value is <code>false</code>.
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100197 * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
198 * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800199 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700200 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800201 * <p>Key for user restrictions.
202 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700203 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
204 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400205 * @see #getUserRestrictions()
206 */
207 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
208
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400209 /**
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100210 * Specifies if bluetooth is disallowed on the device.
211 *
212 * <p> This restriction can only be set by the device owner and the profile owner on the
213 * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
214 * <p>The default value is <code>false</code>.
215 * <p>Key for user restrictions.
216 * <p>Type: Boolean
217 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
218 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
219 * @see #getUserRestrictions()
220 */
221 public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
222
223 /**
Pavel Grafov4f4f6f82017-03-28 13:44:04 +0100224 * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
225 * owner can set this restriction. When it is set by device owner, all users on this device will
226 * be affected.
227 *
228 * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
229 * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
230 * managed profiles.
231 *
232 * <p>Key for user restrictions.
233 * <p>Type: Boolean
234 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
235 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
236 * @see #getUserRestrictions()
237 */
238 public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
239
240 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700241 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700242 * USB. This can only be set by device owners and profile owners on the primary user.
243 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700244 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800245 * <p>Key for user restrictions.
246 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700247 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
248 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400249 * @see #getUserRestrictions()
250 */
251 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
252
Emily Bernierb223f732013-04-11 15:46:36 -0400253 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700254 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400255 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700256 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800257 * <p>Key for user restrictions.
258 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700259 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
260 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400261 * @see #getUserRestrictions()
262 */
263 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
264
265 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800266 * When set on the primary user this specifies if the user can remove other users.
267 * When set on a secondary user, this specifies if the user can remove itself.
268 * This restriction has no effect on managed profiles.
269 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700270 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800271 * <p>Key for user restrictions.
272 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700273 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
274 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400275 * @see #getUserRestrictions()
276 */
277 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
278
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400279 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000280 * Specifies if managed profiles of this user can be removed, other than by its profile owner.
281 * The default value is <code>false</code>.
282 * <p>
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000283 * This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000284 *
285 * <p>Key for user restrictions.
286 * <p>Type: Boolean
287 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
288 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
289 * @see #getUserRestrictions()
290 */
291 public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
292
293 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700294 * Specifies if a user is disallowed from enabling or
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400295 * accessing debugging features. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700296 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800297 * <p>Key for user restrictions.
298 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700299 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
300 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400301 * @see #getUserRestrictions()
302 */
303 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
304
305 /**
Benjamin Miller05fef7e2017-07-24 10:11:39 +0200306 * Specifies if a user is disallowed from configuring a VPN. The default value is
307 * <code>false</code>. This restriction has an effect when set by device owners and, in Android
308 * 6.0 ({@linkplain android.os.Build.VERSION_CODES#M API level 23}) or higher, profile owners.
309 * <p>This restriction also prevents VPNs from starting. However, in Android 7.0
310 * ({@linkplain android.os.Build.VERSION_CODES#N API level 24}) or higher, the system does
311 * start always-on VPNs created by the device or profile owner.
Amith Yamasani26af8292014-09-09 09:57:27 -0700312 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800313 * <p>Key for user restrictions.
314 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700315 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
316 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400317 * @see #getUserRestrictions()
318 */
319 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
320
321 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700322 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700323 * & portable hotspots. This can only be set by device owners and profile owners on the
324 * primary user. The default value is <code>false</code>.
Rubin Xu1faf1442017-08-23 15:48:12 +0100325 * <p>In Android 9.0 or higher, if tethering is enabled when this restriction is set,
326 * tethering will be automatically turned off.
Amith Yamasani26af8292014-09-09 09:57:27 -0700327 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800328 * <p>Key for user restrictions.
329 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700330 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
331 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400332 * @see #getUserRestrictions()
333 */
334 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
335
336 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700337 * Specifies if a user is disallowed from resetting network settings
338 * from Settings. This can only be set by device owners and profile owners on the primary user.
339 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800340 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700341 * primary user can reset the network settings of the device.
342 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800343 * <p>Key for user restrictions.
344 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700345 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
346 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700347 * @see #getUserRestrictions()
348 */
349 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
350
351 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700352 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700353 * from Settings. This can only be set by device owners and profile owners on the primary user.
354 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800355 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800356 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700357 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800358 * <p>Key for user restrictions.
359 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700360 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
361 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400362 * @see #getUserRestrictions()
363 */
364 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
365
366 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000367 * Specifies if a user is disallowed from adding new users. This can only be set by device
368 * owners and profile owners on the primary user.
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700369 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800370 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800371 * primary user can add other users.
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_ADD_USER = "no_add_user";
380
381 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000382 * Specifies if a user is disallowed from adding managed profiles.
383 * <p>The default value for an unmanaged user is <code>false</code>.
Nicolas Prevot2ea46fe2017-01-05 10:29:34 +0000384 * For users with a device owner set, the default is <code>true</code>.
385 * <p>This restriction has no effect on managed profiles.
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000386 *
387 * <p>Key for user restrictions.
388 * <p>Type: Boolean
389 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
390 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
391 * @see #getUserRestrictions()
392 */
393 public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
394
395 /**
Benjamin Millerd41a9fc2017-07-17 17:24:44 +0200396 * Specifies if a user is disallowed from disabling application verification. The default
397 * value is <code>false</code>.
398 *
399 * <p>In Android 8.0 ({@linkplain android.os.Build.VERSION_CODES#O API level 26}) and higher,
400 * this is a global user restriction. If a device owner or profile owner sets this restriction,
401 * the system enforces app verification across all users on the device. Running in earlier
402 * Android versions, this restriction affects only the profile that sets it.
Amith Yamasani26af8292014-09-09 09:57:27 -0700403 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800404 * <p>Key for user restrictions.
405 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700406 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
407 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400408 * @see #getUserRestrictions()
409 */
410 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
411
412 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700413 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700414 * broadcasts. This can only be set by device owners and profile owners on the primary user.
415 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800416 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800417 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700418 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800419 * <p>Key for user restrictions.
420 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700421 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
422 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400423 * @see #getUserRestrictions()
424 */
425 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
426
427 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700428 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700429 * networks. This can only be set by device owners and profile owners on the primary user.
430 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800431 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800432 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700433 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800434 * <p>Key for user restrictions.
435 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700436 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
437 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400438 * @see #getUserRestrictions()
439 */
440 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
441
442 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700443 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400444 * applications in Settings or launchers. The following actions will not be allowed when this
445 * restriction is enabled:
446 * <li>uninstalling apps</li>
447 * <li>disabling apps</li>
448 * <li>clearing app caches</li>
449 * <li>clearing app data</li>
450 * <li>force stopping apps</li>
451 * <li>clearing app defaults</li>
452 * <p>
453 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700454 *
Esteban Talavera8bd7c522017-02-13 12:35:04 +0000455 * <p><strong>Note:</strong> The user will still be able to perform those actions via other
456 * means (such as adb). Third party apps will also be able to uninstall apps via the
457 * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
458 * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
459 * used to prevent the user from uninstalling apps completely, and
460 * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
461 * to add a default intent handler for a given intent filter.
462 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800463 * <p>Key for user restrictions.
464 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700465 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
466 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400467 * @see #getUserRestrictions()
468 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400469 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400470
Emily Bernier394a6cd2014-05-07 12:49:20 -0400471 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700472 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700473 * physical external media. This can only be set by device owners and profile owners on the
474 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700475 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800476 * <p>Key for user restrictions.
477 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700478 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
479 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400480 * @see #getUserRestrictions()
481 */
482 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
483
484 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100485 * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
486 * will be muted. This can be set by device owners and profile owners. The default value is
487 * <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700488 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100489 * <p>This restriction has no effect on managed profiles.
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)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400494 * @see #getUserRestrictions()
495 */
496 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
497
498 /**
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100499 * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
Wen ZHANG61ed0dc2017-08-23 14:27:02 +0100500 * will be muted. This can be set by device owners from API 21 and profile owners from API 24.
501 * The default value is <code>false</code>.
502 *
503 * <p>When the restriction is set by profile owners, then it only applies to relevant
504 * profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700505 *
Pavel Grafovce3e1a32017-04-21 14:48:21 +0100506 * <p>This restriction has no effect on managed profiles.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800507 * <p>Key for user restrictions.
508 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700509 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
510 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400511 * @see #getUserRestrictions()
512 */
513 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
514
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700515 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700516 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700517 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700518 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000519 * <p>This restriction has no effect on managed profiles.
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)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700525 * @see #getUserRestrictions()
526 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700527 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
528
529 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700530 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700531 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700532 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800533 * <p>Key for user restrictions.
534 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700535 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
536 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700537 * @see #getUserRestrictions()
538 */
539 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700540
Jason Monk1c7c3192014-06-26 12:52:18 -0400541 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700542 * Specifies if the user is not allowed to have fun. In some cases, the
543 * device owner may wish to prevent the user from experiencing amusement or
544 * joy while using the device. The default value is <code>false</code>.
545 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800546 * <p>Key for user restrictions.
547 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700548 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
549 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700550 * @see #getUserRestrictions()
551 */
552 public static final String DISALLOW_FUN = "no_fun";
553
554 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700555 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400556 * created. This will block the creation of the following types of windows.
557 * <li>{@link LayoutParams#TYPE_TOAST}</li>
558 * <li>{@link LayoutParams#TYPE_PHONE}</li>
559 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
560 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
561 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
562 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800563 * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
Jason Monk1c7c3192014-06-26 12:52:18 -0400564 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700565 * <p>This can only be set by device owners and profile owners on the primary user.
566 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700567 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800568 * <p>Key for user restrictions.
569 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700570 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
571 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400572 * @see #getUserRestrictions()
573 */
574 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
575
Nicolas Prevotf1939902014-06-25 09:29:02 +0100576 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700577 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100578 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
579 * pasted in this profile.
580 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700581 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800582 * <p>Key for user restrictions.
583 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700584 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
585 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100586 * @see #getUserRestrictions()
587 */
588 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
589
Amith Yamasani26af8292014-09-09 09:57:27 -0700590 /**
591 * Specifies if the user is not allowed to use NFC to beam out data from apps.
592 * The default value is <code>false</code>.
593 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800594 * <p>Key for user restrictions.
595 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700596 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
597 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani26af8292014-09-09 09:57:27 -0700598 * @see #getUserRestrictions()
599 */
600 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
601
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000602 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100603 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
604 * generally means that wallpapers are not supported for the particular user. This user
605 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000606 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100607 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700608 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
609 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000610 * @see #getUserRestrictions()
611 */
612 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
613
614 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100615 * User restriction to disallow setting a wallpaper. Profile owner and device owner
616 * are able to set wallpaper regardless of this restriction.
617 * The default value is <code>false</code>.
618 *
619 * <p>Key for user restrictions.
620 * <p>Type: Boolean
621 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
622 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
623 * @see #getUserRestrictions()
624 */
625 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
626
627 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000628 * Specifies if the user is not allowed to reboot the device into safe boot mode.
629 * This can only be set by device owners and profile owners on the primary user.
630 * The default value is <code>false</code>.
631 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800632 * <p>Key for user restrictions.
633 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700634 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
635 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000636 * @see #getUserRestrictions()
637 */
638 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
639
640 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700641 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
642 * background users. The default value is <code>false</code>.
643 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700644 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
645 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700646 * @see #getUserRestrictions()
647 * @hide
648 */
649 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
650
651 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700652 * Specifies if a user is not allowed to run in the background and should be stopped during
653 * user switch. The default value is <code>false</code>.
654 *
655 * <p>This restriction can be set by device owners and profile owners.
656 *
657 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
658 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
659 * @see #getUserRestrictions()
660 * @hide
661 */
662 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
663
664 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700665 * Specifies if a user is not allowed to use the camera.
666 *
667 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
668 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
669 * @see #getUserRestrictions()
670 * @hide
671 */
672 public static final String DISALLOW_CAMERA = "no_camera";
673
674 /**
Tony Makc1205112016-07-22 16:02:59 +0100675 * Specifies if a user is not allowed to unmute the device's master volume.
676 *
677 * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
678 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
679 * @see #getUserRestrictions()
680 * @hide
681 */
Esteban Talavera492b4722017-02-13 14:59:45 +0000682 public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
Tony Makc1205112016-07-22 16:02:59 +0100683
684 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000685 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
686 * device owners. The default value is <code>false</code>.
687 *
688 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
689 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
690 * @see #getUserRestrictions()
691 */
692 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
693
694 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100695 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
696 * can set this restriction. When it is set by device owner, only the target user will be
697 * affected. The default value is <code>false</code>.
698 *
699 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100700 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100701 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
702 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
703 * @see #getUserRestrictions()
704 */
705 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
706
707 /**
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100708 * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100709 * <code>false</code>. Setting this restriction has no effect if the bootloader is already
710 * unlocked.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100711 *
Lenka Trochtova12b04962016-11-29 21:00:12 +0100712 * <p>Not for use by third-party applications.
713 *
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100714 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
715 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
716 * @see #getUserRestrictions()
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000717 * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100718 * @hide
719 */
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000720 @Deprecated
Lenka Trochtova12b04962016-11-29 21:00:12 +0100721 @SystemApi
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100722 public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
723
724 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700725 * Allows apps in the parent profile to handle web links from the managed profile.
726 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700727 * This user restriction has an effect only in a managed profile.
728 * If set:
729 * Intent filters of activities in the parent profile with action
730 * {@link android.content.Intent#ACTION_VIEW},
731 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
732 * define a host can handle intents from the managed profile.
733 * The default value is <code>false</code>.
734 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800735 * <p>Key for user restrictions.
736 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700737 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
738 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700739 * @see #getUserRestrictions()
740 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700741 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
742 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700743
744 /**
Felipe Leme24d58932017-03-21 14:13:58 -0700745 * Specifies if a user is not allowed to use Autofill Services.
746 *
747 * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
748 * only the target user will be affected.
749 *
750 * <p>The default value is <code>false</code>.
751 *
752 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
753 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
754 * @see #getUserRestrictions()
755 */
756 public static final String DISALLOW_AUTOFILL = "no_autofill";
757
758 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000759 * Application restriction key that is used to indicate the pending arrival
760 * of real restrictions for the app.
761 *
762 * <p>
763 * Applications that support restrictions should check for the presence of this key.
764 * A <code>true</code> value indicates that restrictions may be applied in the near
765 * future but are not available yet. It is the responsibility of any
766 * management application that sets this flag to update it when the final
767 * restrictions are enforced.
768 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800769 * <p>Key for application restrictions.
770 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +0000771 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
772 * android.content.ComponentName, String, Bundle)
773 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
774 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000775 */
776 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
777
Amith Yamasani12747872015-12-07 14:19:49 -0800778 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
779
780 /**
781 * Extra containing a name for the user being created. Optional parameter passed to
782 * ACTION_CREATE_USER activity.
783 * @hide
784 */
785 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
786
787 /**
788 * Extra containing account name for the user being created. Optional parameter passed to
789 * ACTION_CREATE_USER activity.
790 * @hide
791 */
792 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
793
794 /**
795 * Extra containing account type for the user being created. Optional parameter passed to
796 * ACTION_CREATE_USER activity.
797 * @hide
798 */
799 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
800
801 /**
802 * Extra containing account-specific data for the user being created. Optional parameter passed
803 * to ACTION_CREATE_USER activity.
804 * @hide
805 */
806 public static final String EXTRA_USER_ACCOUNT_OPTIONS
807 = "android.os.extra.USER_ACCOUNT_OPTIONS";
808
Amith Yamasani655d0e22013-06-12 14:19:10 -0700809 /** @hide */
810 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
811 /** @hide */
812 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
813 /** @hide */
814 public static final int PIN_VERIFICATION_SUCCESS = -1;
815
Amith Yamasani37ed8d12016-01-27 14:40:16 -0800816 /**
Makoto Onukie72f81b2017-03-16 14:08:19 -0700817 * Sent when user restrictions have changed.
818 *
819 * @hide
820 */
821 @SystemApi
822 @TestApi // To allow seeing it from CTS.
823 public static final String ACTION_USER_RESTRICTIONS_CHANGED =
824 "android.os.action.USER_RESTRICTIONS_CHANGED";
825
826 /**
Amith Yamasani37ed8d12016-01-27 14:40:16 -0800827 * Error result indicating that this user is not allowed to add other users on this device.
828 * This is a result code returned from the activity created by the intent
829 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
830 */
831 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
832
833 /**
834 * Error result indicating that no more users can be created on this device.
835 * This is a result code returned from the activity created by the intent
836 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
837 */
838 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
839
Amith Yamasani7e99bc02013-04-16 18:24:51 -0700840 /** @hide */
Amith Yamasanic0688302015-10-30 10:40:03 -0700841 public static UserManager get(Context context) {
842 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -0700843 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400844
Amith Yamasani258848d2012-08-10 17:06:33 -0700845 /** @hide */
846 public UserManager(Context context, IUserManager service) {
847 mService = service;
Fyodor Kupolov5200e1c2016-10-17 18:46:16 -0700848 mContext = context.getApplicationContext();
Amith Yamasani258848d2012-08-10 17:06:33 -0700849 }
850
851 /**
Amith Yamasani06964342016-04-15 13:55:01 -0700852 * Returns whether this device supports multiple users with their own login and customizable
853 * space.
854 * @return whether the device supports multiple users.
Amith Yamasani258848d2012-08-10 17:06:33 -0700855 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -0700856 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +0000857 return getMaxSupportedUsers() > 1
858 && SystemProperties.getBoolean("fw.show_multiuserui",
859 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -0700860 }
861
Maggie Benthall67944582013-02-22 14:58:27 -0500862 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -0700863 * @hide
864 * @return Whether the device is running with split system user. It means the system user and
865 * primary user are two separate users. Previously system user and primary user are combined as
866 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
867 */
868 public static boolean isSplitSystemUser() {
John Reckaa67f682016-09-20 14:24:21 -0700869 return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -0700870 }
871
872 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700873 * @return Whether guest user is always ephemeral
874 * @hide
875 */
876 public static boolean isGuestUserEphemeral() {
877 return Resources.getSystem()
878 .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
879 }
880
881 /**
Fyodor Kupolov523c4042016-02-24 15:03:13 -0800882 * Returns whether switching users is currently allowed.
883 * <p>For instance switching users is not allowed if the current user is in a phone call,
884 * or system user hasn't been unlocked yet
885 * @hide
886 */
887 public boolean canSwitchUsers() {
888 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
889 mContext.getContentResolver(),
890 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
891 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
892 boolean inCall = TelephonyManager.getDefault().getCallState()
893 != TelephonyManager.CALL_STATE_IDLE;
894 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall;
895 }
896
897 /**
Amith Yamasani5760e172015-04-17 18:42:41 -0700898 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +0100899 *
Amith Yamasani5760e172015-04-17 18:42:41 -0700900 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -0700901 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -0500902 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700903 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700904 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -0700905 }
906
907 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700908 * Returns the user name of the user making this call. This call is only
909 * available to applications on the system image; it requires the
910 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700911 * @return the user name
912 */
913 public String getUserName() {
Will Harmond9dcfb12017-05-18 15:41:15 -0700914 UserInfo user = getUserInfo(getUserHandle());
915 return user == null ? "" : user.name;
Amith Yamasani258848d2012-08-10 17:06:33 -0700916 }
917
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700918 /**
Fyodor Kupolov605b12a2017-05-10 15:58:09 -0700919 * Returns whether user name has been set.
920 * <p>This method can be used to check that the value returned by {@link #getUserName()} was
921 * set by the user and is not a placeholder string provided by the system.
922 * @hide
923 */
924 public boolean isUserNameSet() {
925 try {
926 return mService.isUserNameSet(getUserHandle());
927 } catch (RemoteException re) {
928 throw re.rethrowFromSystemServer();
929 }
930 }
931
932 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -0700933 * Used to determine whether the user making this call is subject to
934 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700935 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700936 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700937 * now automatically identify goats using advanced goat recognition technology.</p>
938 *
939 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -0700940 */
941 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -0700942 return mContext.getPackageManager()
943 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -0700944 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800945
946 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -0700947 * Used to check if this process is running under the primary user. The primary user
948 * is the first human user on a device.
949 *
950 * @return whether this process is running under the primary user.
951 * @hide
952 */
953 public boolean isPrimaryUser() {
954 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -0700955 return user != null && user.isPrimary();
Xiaohui Chen70f6c382015-04-28 14:21:43 -0700956 }
957
958 /**
Amith Yamasani5760e172015-04-17 18:42:41 -0700959 * Used to check if this process is running under the system user. The system user
960 * is the initial user that is implicitly created on first boot and hosts most of the
961 * system services.
962 *
963 * @return whether this process is running under the system user.
964 */
965 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -0700966 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -0700967 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700968
Amith Yamasani5760e172015-04-17 18:42:41 -0700969 /**
Amith Yamasani462ac3a2015-06-30 14:21:01 -0700970 * @hide
971 * Returns whether the caller is running as an admin user. There can be more than one admin
972 * user.
973 */
974 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700975 return isUserAdmin(UserHandle.myUserId());
976 }
977
978 /**
979 * @hide
980 * Returns whether the provided user is an admin user. There can be more than one admin
981 * user.
982 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700983 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700984 UserInfo user = getUserInfo(userId);
985 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -0700986 }
987
988 /**
Amith Yamasanie1375902013-04-13 16:48:35 -0700989 * Used to check if the user making this call is linked to another user. Linked users may have
Amith Yamasani46bc4eb2013-04-12 13:26:50 -0700990 * a reduced number of available apps, app restrictions and account restrictions.
Amith Yamasanie1375902013-04-13 16:48:35 -0700991 * @return whether the user making this call is a linked user
Amith Yamasani2555daf2013-04-25 13:39:27 -0700992 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800993 */
Amith Yamasanie1375902013-04-13 16:48:35 -0700994 public boolean isLinkedUser() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800995 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -0700996 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800997 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700998 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800999 }
1000 }
1001
Amith Yamasani258848d2012-08-10 17:06:33 -07001002 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001003 * Checks if specified user can have restricted profile.
1004 * @hide
1005 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001006 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001007 try {
1008 return mService.canHaveRestrictedProfile(userId);
1009 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001010 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -07001011 }
1012 }
1013
1014 /**
Evan Rosky13a58a92016-07-27 15:51:09 -07001015 * Checks if a user is a guest user.
1016 * @return whether user is a guest user.
1017 * @hide
1018 */
1019 public boolean isGuestUser(int id) {
1020 UserInfo user = getUserInfo(id);
1021 return user != null && user.isGuest();
1022 }
1023
1024 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001025 * Checks if the calling app is running as a guest user.
1026 * @return whether the caller is a guest user.
1027 * @hide
1028 */
1029 public boolean isGuestUser() {
1030 UserInfo user = getUserInfo(UserHandle.myUserId());
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001031 return user != null && user.isGuest();
1032 }
1033
1034 /**
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001035 * Checks if the calling app is running in a demo user. When running in a demo user,
1036 * apps can be more helpful to the user, or explain their features in more detail.
1037 *
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001038 * @return whether the caller is a demo user.
Amith Yamasanid35a89c2016-05-26 16:58:43 -07001039 */
1040 public boolean isDemoUser() {
Amith Yamasani1c41dc82016-06-28 16:13:15 -07001041 try {
1042 return mService.isDemoUser(UserHandle.myUserId());
1043 } catch (RemoteException re) {
1044 throw re.rethrowFromSystemServer();
1045 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001046 }
1047
1048 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001049 * Checks if the calling app is running in a managed profile.
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001050 *
1051 * @return whether the caller is in a managed profile.
1052 * @hide
1053 */
1054 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001055 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001056 public boolean isManagedProfile() {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001057 // No need for synchronization. Once it becomes non-null, it'll be non-null forever.
1058 // Worst case we might end up calling the AIDL method multiple times but that's fine.
1059 if (mIsManagedProfileCached != null) {
1060 return mIsManagedProfileCached;
1061 }
Tony Mak8673b282016-03-21 21:10:59 +00001062 try {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001063 mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1064 return mIsManagedProfileCached;
Tony Mak8673b282016-03-21 21:10:59 +00001065 } catch (RemoteException re) {
1066 throw re.rethrowFromSystemServer();
1067 }
1068 }
1069
1070 /**
1071 * Checks if the specified user is a managed profile.
1072 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1073 * must be in the same profile group of specified user.
1074 *
1075 * @return whether the specified user is a managed profile.
1076 * @hide
1077 */
1078 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001079 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Tony Mak8673b282016-03-21 21:10:59 +00001080 public boolean isManagedProfile(@UserIdInt int userId) {
Makoto Onukid49f3fa2017-01-25 14:09:48 -08001081 if (userId == UserHandle.myUserId()) {
1082 return isManagedProfile();
1083 }
Tony Mak8673b282016-03-21 21:10:59 +00001084 try {
1085 return mService.isManagedProfile(userId);
1086 } catch (RemoteException re) {
1087 throw re.rethrowFromSystemServer();
1088 }
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07001089 }
1090
1091 /**
Kenny Guy02c89902016-11-15 19:36:38 +00001092 * Gets badge for a managed profile.
1093 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
1094 * must be in the same profile group of specified user.
1095 *
1096 * @return which badge to use for the managed profile badge id will be less than
1097 * UserManagerService.getMaxManagedProfiles()
1098 * @hide
1099 */
1100 public int getManagedProfileBadge(@UserIdInt int userId) {
1101 try {
1102 return mService.getManagedProfileBadge(userId);
1103 } catch (RemoteException re) {
1104 throw re.rethrowFromSystemServer();
1105 }
1106 }
1107
1108 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001109 * Checks if the calling app is running as an ephemeral user.
1110 *
1111 * @return whether the caller is an ephemeral user.
1112 * @hide
1113 */
1114 public boolean isEphemeralUser() {
1115 return isUserEphemeral(UserHandle.myUserId());
1116 }
1117
1118 /**
1119 * Returns whether the specified user is ephemeral.
1120 * @hide
1121 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001122 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +01001123 final UserInfo user = getUserInfo(userId);
1124 return user != null && user.isEphemeral();
1125 }
1126
1127 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001128 * Return whether the given user is actively running. This means that
1129 * the user is in the "started" state, not "stopped" -- it is currently
1130 * allowed to run code through scheduled alarms, receiving broadcasts,
1131 * etc. A started user may be either the current foreground user or a
1132 * background user; the result here does not distinguish between the two.
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001133 *
1134 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1135 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1136 * in order to check other profile's status.
1137 * Since Android Nougat MR1 (SDK version >= 25;
1138 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1139 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001140 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001141 * @param user The user to retrieve the running state for.
1142 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001143 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001144 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -07001145 return isUserRunning(user.getIdentifier());
1146 }
1147
1148 /** {@hide} */
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001149 public boolean isUserRunning(@UserIdInt int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001150 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001151 return mService.isUserRunning(userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001152 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001153 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001154 }
1155 }
1156
1157 /**
1158 * Return whether the given user is actively running <em>or</em> stopping.
1159 * This is like {@link #isUserRunning(UserHandle)}, but will also return
1160 * true if the user had been running but is in the process of being stopped
1161 * (but is not yet fully stopped, and still running some code).
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001162 *
1163 * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
1164 * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
1165 * in order to check other profile's status.
1166 * Since Android Nougat MR1 (SDK version >= 25;
1167 * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
1168 * it'll accept any {@link UserHandle} within the same profile group as the caller.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001169 *
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001170 * @param user The user to retrieve the running state for.
1171 */
Makoto Onuki5eef50d2017-03-02 16:38:45 -08001172 // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001173 public boolean isUserRunningOrStopping(UserHandle user) {
1174 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001175 // TODO: reconcile stopped vs stopping?
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001176 return ActivityManager.getService().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -08001177 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001178 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001179 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -07001180 }
1181 }
1182
Jeff Sharkey0825ab22015-12-02 13:04:49 -07001183 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001184 * Return whether the calling user is running in an "unlocked" state.
1185 * <p>
1186 * On devices with direct boot, a user is unlocked only after they've
1187 * entered their credentials (such as a lock pattern or PIN). On devices
1188 * without direct boot, a user is unlocked as soon as it starts.
1189 * <p>
1190 * When a user is locked, only device-protected data storage is available.
1191 * When a user is unlocked, both device-protected and credential-protected
1192 * private app data storage is available.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001193 *
1194 * @see Intent#ACTION_USER_UNLOCKED
1195 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001196 */
1197 public boolean isUserUnlocked() {
1198 return isUserUnlocked(Process.myUserHandle());
1199 }
1200
1201 /**
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001202 * Return whether the given user is running in an "unlocked" state.
1203 * <p>
1204 * On devices with direct boot, a user is unlocked only after they've
1205 * entered their credentials (such as a lock pattern or PIN). On devices
1206 * without direct boot, a user is unlocked as soon as it starts.
1207 * <p>
1208 * When a user is locked, only device-protected data storage is available.
1209 * When a user is unlocked, both device-protected and credential-protected
1210 * private app data storage is available.
Fyodor Kupolovcdb3c2f2017-02-10 11:48:32 -08001211 * <p>Requires {@code android.permission.MANAGE_USERS} or
1212 * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1213 * must be the calling user or a managed profile associated with it.
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001214 *
1215 * @param user to retrieve the unlocked state for.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001216 * @see Intent#ACTION_USER_UNLOCKED
1217 * @see Context#createDeviceProtectedStorageContext()
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001218 */
1219 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -07001220 return isUserUnlocked(user.getIdentifier());
1221 }
1222
1223 /** {@hide} */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001224 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001225 try {
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -08001226 return mService.isUserUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001227 } catch (RemoteException re) {
1228 throw re.rethrowFromSystemServer();
1229 }
1230 }
1231
1232 /** {@hide} */
1233 public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1234 return isUserUnlockingOrUnlocked(user.getIdentifier());
1235 }
1236
1237 /** {@hide} */
1238 public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1239 try {
Fyodor Kupolovc413f702016-10-06 17:11:14 -07001240 return mService.isUserUnlockingOrUnlocked(userId);
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001241 } catch (RemoteException re) {
1242 throw re.rethrowFromSystemServer();
1243 }
Jeff Sharkeyb6423872015-12-11 11:11:58 -07001244 }
1245
1246 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001247 * Returns the UserInfo object describing a specific user.
Tony Mak8673b282016-03-21 21:10:59 +00001248 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001249 * @param userHandle the user handle of the user whose information is being requested.
1250 * @return the UserInfo object for a specific user.
1251 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001252 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001253 public UserInfo getUserInfo(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001254 try {
1255 return mService.getUserInfo(userHandle);
1256 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001257 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001258 }
1259 }
1260
Amith Yamasani71e6c692013-03-24 17:39:28 -07001261 /**
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001262 * @hide
1263 *
1264 * Returns who set a user restriction on a user.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001265 * @param restrictionKey the string key representing the restriction
1266 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1267 * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1268 * {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1269 * and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
Pavel Grafov6a40f092016-10-25 15:46:51 +01001270 * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001271 */
Pavel Grafov6a40f092016-10-25 15:46:51 +01001272 @Deprecated
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001273 @SystemApi
1274 @UserRestrictionSource
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001275 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Zoltan Szatmary-Bane7834602016-04-08 18:41:11 +01001276 public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1277 try {
1278 return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1279 } catch (RemoteException re) {
1280 throw re.rethrowFromSystemServer();
1281 }
1282 }
1283
1284 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +01001285 * @hide
1286 *
1287 * Returns a list of users who set a user restriction on a given user.
Pavel Grafov6a40f092016-10-25 15:46:51 +01001288 * @param restrictionKey the string key representing the restriction
1289 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1290 * @return a list of user ids enforcing this restriction.
1291 */
1292 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001293 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Pavel Grafov6a40f092016-10-25 15:46:51 +01001294 public List<EnforcingUser> getUserRestrictionSources(
1295 String restrictionKey, UserHandle userHandle) {
1296 try {
1297 return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
1298 } catch (RemoteException re) {
1299 throw re.rethrowFromSystemServer();
1300 }
1301 }
1302
1303 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07001304 * Returns the user-wide restrictions imposed on this user.
1305 * @return a Bundle containing all the restrictions.
1306 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001307 public Bundle getUserRestrictions() {
1308 return getUserRestrictions(Process.myUserHandle());
1309 }
1310
Amith Yamasani71e6c692013-03-24 17:39:28 -07001311 /**
1312 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
1313 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1314 * @return a Bundle containing all the restrictions.
1315 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001316 public Bundle getUserRestrictions(UserHandle userHandle) {
1317 try {
1318 return mService.getUserRestrictions(userHandle.getIdentifier());
1319 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001320 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001321 }
1322 }
1323
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001324 /**
1325 * @hide
1326 * Returns whether the given user has been disallowed from performing certain actions
1327 * or setting certain settings through UserManager. This method disregards restrictions
1328 * set by device policy.
1329 * @param restrictionKey the string key representing the restriction
1330 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1331 */
1332 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
1333 try {
1334 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
1335 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001336 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001337 }
1338 }
1339
Amith Yamasani71e6c692013-03-24 17:39:28 -07001340 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001341 * This will no longer work. Device owners and profile owners should use
1342 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001343 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001344 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001345 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001346 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001347 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001348 }
1349
Amith Yamasani71e6c692013-03-24 17:39:28 -07001350 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001351 * This will no longer work. Device owners and profile owners should use
1352 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001353 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001354 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001355 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001356 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001357 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001358 }
1359
Amith Yamasani71e6c692013-03-24 17:39:28 -07001360 /**
1361 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07001362 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001363 * @param key the key of the restriction
1364 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001365 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1366 * android.content.ComponentName, String)} or
1367 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1368 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001369 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001370 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07001371 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001372 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07001373 }
1374
1375 /**
1376 * @hide
1377 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07001378 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001379 * @param key the key of the restriction
1380 * @param value the value for the restriction
1381 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001382 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1383 * android.content.ComponentName, String)} or
1384 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1385 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001386 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001387 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05001388 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001389 try {
1390 mService.setUserRestriction(key, value, userHandle.getIdentifier());
1391 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001392 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001393 }
Maggie Benthall67944582013-02-22 14:58:27 -05001394 }
1395
Amith Yamasani258848d2012-08-10 17:06:33 -07001396 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001397 * Returns whether the current user has been disallowed from performing certain actions
1398 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04001399 *
1400 * @param restrictionKey The string key representing the restriction.
1401 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001402 */
1403 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -07001404 return hasUserRestriction(restrictionKey, Process.myUserHandle());
1405 }
1406
1407 /**
1408 * @hide
1409 * Returns whether the given user has been disallowed from performing certain actions
1410 * or setting certain settings.
1411 * @param restrictionKey the string key representing the restriction
1412 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1413 */
1414 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001415 try {
1416 return mService.hasUserRestriction(restrictionKey,
1417 userHandle.getIdentifier());
1418 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001419 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001420 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001421 }
1422
1423 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001424 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001425 * number assigned to that user; if the user is deleted and then a new
1426 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001427 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001428 * @return The serial number of the given user; returns -1 if the
1429 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001430 * @see #getUserForSerialNumber(long)
1431 */
1432 public long getSerialNumberForUser(UserHandle user) {
1433 return getUserSerialNumber(user.getIdentifier());
1434 }
1435
1436 /**
1437 * Return the user associated with a serial number previously
1438 * returned by {@link #getSerialNumberForUser(UserHandle)}.
1439 * @param serialNumber The serial number of the user that is being
1440 * retrieved.
1441 * @return Return the user associated with the serial number, or null
1442 * if there is not one.
1443 * @see #getSerialNumberForUser(UserHandle)
1444 */
1445 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07001446 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001447 return ident >= 0 ? new UserHandle(ident) : null;
1448 }
1449
1450 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001451 * Creates a user with the specified name and options. For non-admin users, default user
1452 * restrictions are going to be applied.
Amith Yamasani195263742012-08-21 15:40:12 -07001453 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001454 *
1455 * @param name the user's name
1456 * @param flags flags that identify the type of user and other properties.
1457 * @see UserInfo
1458 *
1459 * @return the UserInfo object for the created user, or null if the user could not be created.
1460 * @hide
1461 */
1462 public UserInfo createUser(String name, int flags) {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001463 UserInfo user = null;
Amith Yamasani258848d2012-08-10 17:06:33 -07001464 try {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001465 user = mService.createUser(name, flags);
phweisse9c44062016-02-10 12:57:38 +01001466 // TODO: Keep this in sync with
1467 // UserManagerService.LocalService.createUserEvenWhenDisallowed
Christine Franks97a54802017-08-09 10:06:43 -07001468 if (user != null && !user.isAdmin() && !user.isDemo()) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001469 mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1470 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001471 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001472 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001473 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001474 }
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001475 return user;
Amith Yamasani258848d2012-08-10 17:06:33 -07001476 }
1477
1478 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001479 * Creates a guest user and configures it.
1480 * @param context an application context
1481 * @param name the name to set for the user
1482 * @hide
1483 */
1484 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001485 UserInfo guest = null;
1486 try {
1487 guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1488 if (guest != null) {
1489 Settings.Secure.putStringForUser(context.getContentResolver(),
1490 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001491 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07001492 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001493 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001494 }
1495 return guest;
1496 }
1497
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07001498 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001499 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001500 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1501 *
1502 * @param name the user's name
1503 * @param flags flags that identify the type of user and other properties.
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001504 * @param userHandle new user will be a profile of this user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001505 *
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001506 * @return the {@link UserInfo} object for the created user, or null if the user
1507 * could not be created.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001508 * @hide
1509 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001510 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001511 return createProfileForUser(name, flags, userHandle, null);
1512 }
1513
1514 /**
1515 * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
1516 * any packages that should not be installed in the new profile by default, these packages can
1517 * still be installed later by the user if needed.
1518 *
1519 * @param name the user's name
1520 * @param flags flags that identify the type of user and other properties.
1521 * @param userHandle new user will be a profile of this user.
1522 * @param disallowedPackages packages that will not be installed in the profile being created.
1523 *
1524 * @return the {@link UserInfo} object for the created user, or null if the user
1525 * could not be created.
1526 * @hide
1527 */
1528 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
1529 String[] disallowedPackages) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001530 try {
Sudheer Shanka7cb54a32016-09-16 12:59:05 -07001531 return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001532 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001533 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001534 }
1535 }
1536
1537 /**
Tony Mak6dc428f2016-10-10 15:48:27 +01001538 * Similar to {@link #createProfileForUser(String, int, int, String[])}
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001539 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
Tony Mak6dc428f2016-10-10 15:48:27 +01001540 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1541 *
1542 * @see #createProfileForUser(String, int, int, String[])
1543 * @hide
1544 */
1545 public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
1546 @UserIdInt int userHandle, String[] disallowedPackages) {
1547 try {
1548 return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
1549 disallowedPackages);
1550 } catch (RemoteException re) {
1551 throw re.rethrowFromSystemServer();
1552 }
1553 }
1554
1555 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001556 * Creates a restricted profile with the specified name. This method also sets necessary
1557 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001558 *
1559 * @param name profile's name
1560 * @return UserInfo object for the created user, or null if the user could not be created.
1561 * @hide
1562 */
1563 public UserInfo createRestrictedProfile(String name) {
1564 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001565 UserHandle parentUserHandle = Process.myUserHandle();
1566 UserInfo user = mService.createRestrictedProfile(name,
1567 parentUserHandle.getIdentifier());
1568 if (user != null) {
1569 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
1570 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001571 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001572 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001573 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001574 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001575 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001576 }
1577
1578 /**
Amith Yamasani06964342016-04-15 13:55:01 -07001579 * Returns an intent to create a user for the provided name and account name. The name
1580 * and account name will be used when the setup process for the new user is started.
1581 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001582 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001583 * indicate if the user consented to adding a new user and if the operation succeeded. Any
1584 * errors in creating the user will be returned in the result code. If the user cancels the
1585 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
1586 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani06964342016-04-15 13:55:01 -07001587 * <p>
1588 * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
1589 * at all.
1590 * <p>
Amith Yamasani12747872015-12-07 14:19:49 -08001591 * The new user is created but not initialized. After switching into the user for the first
1592 * time, the preferred user name and account information are used by the setup process for that
1593 * user.
1594 *
1595 * @param userName Optional name to assign to the user.
Amith Yamasani06964342016-04-15 13:55:01 -07001596 * @param accountName Optional account name that will be used by the setup wizard to initialize
Amith Yamasani12747872015-12-07 14:19:49 -08001597 * the user.
1598 * @param accountType Optional account type for the account to be created. This is required
1599 * if the account name is specified.
1600 * @param accountOptions Optional bundle of data to be passed in during account creation in the
1601 * new user via {@link AccountManager#addAccount(String, String, String[],
1602 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
1603 * Handler)}.
Amith Yamasani06964342016-04-15 13:55:01 -07001604 * @return An Intent that can be launched from an Activity.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001605 * @see #USER_CREATION_FAILED_NOT_PERMITTED
1606 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani06964342016-04-15 13:55:01 -07001607 * @see #supportsMultipleUsers
Amith Yamasani12747872015-12-07 14:19:49 -08001608 */
1609 public static Intent createUserCreationIntent(@Nullable String userName,
1610 @Nullable String accountName,
1611 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
Amith Yamasani12747872015-12-07 14:19:49 -08001612 Intent intent = new Intent(ACTION_CREATE_USER);
1613 if (userName != null) {
1614 intent.putExtra(EXTRA_USER_NAME, userName);
1615 }
1616 if (accountName != null && accountType == null) {
1617 throw new IllegalArgumentException("accountType must be specified if accountName is "
1618 + "specified");
1619 }
1620 if (accountName != null) {
1621 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
1622 }
1623 if (accountType != null) {
1624 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
1625 }
1626 if (accountOptions != null) {
1627 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
1628 }
1629 return intent;
1630 }
1631
1632 /**
1633 * @hide
1634 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001635 * Returns the preferred account name for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08001636 */
1637 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001638 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08001639 public String getSeedAccountName() {
1640 try {
1641 return mService.getSeedAccountName();
1642 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001643 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001644 }
1645 }
1646
1647 /**
1648 * @hide
1649 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001650 * Returns the preferred account type for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08001651 */
1652 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001653 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08001654 public String getSeedAccountType() {
1655 try {
1656 return mService.getSeedAccountType();
1657 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001658 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001659 }
1660 }
1661
1662 /**
1663 * @hide
1664 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001665 * Returns the preferred account's options bundle for user creation.
Amith Yamasani12747872015-12-07 14:19:49 -08001666 * @return Any options set by the requestor that created the user.
1667 */
1668 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001669 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08001670 public PersistableBundle getSeedAccountOptions() {
1671 try {
1672 return mService.getSeedAccountOptions();
1673 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001674 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001675 }
1676 }
1677
1678 /**
1679 * @hide
1680 *
1681 * Called by a system activity to set the seed account information of a user created
1682 * through the user creation intent.
1683 * @param userId
1684 * @param accountName
1685 * @param accountType
1686 * @param accountOptions
1687 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
1688 */
1689 public void setSeedAccountData(int userId, String accountName, String accountType,
1690 PersistableBundle accountOptions) {
1691 try {
1692 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
1693 /* persist= */ true);
1694 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001695 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001696 }
1697 }
1698
1699 /**
1700 * @hide
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001701 * Clears the seed information used to create this user.
Amith Yamasani12747872015-12-07 14:19:49 -08001702 */
1703 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001704 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Amith Yamasani12747872015-12-07 14:19:49 -08001705 public void clearSeedAccountData() {
1706 try {
1707 mService.clearSeedAccountData();
1708 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001709 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001710 }
1711 }
1712
1713 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07001714 * @hide
1715 * Marks the guest user for deletion to allow a new guest to be created before deleting
1716 * the current user who is a guest.
1717 * @param userHandle
1718 * @return
1719 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001720 public boolean markGuestForDeletion(@UserIdInt int userHandle) {
Amith Yamasani1df14732014-08-29 21:37:27 -07001721 try {
1722 return mService.markGuestForDeletion(userHandle);
1723 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001724 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07001725 }
1726 }
1727
1728 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001729 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01001730 *
1731 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1732 *
1733 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
1734 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
1735 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001736 *
1737 * @param userHandle the id of the profile to enable
1738 * @hide
1739 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001740 public void setUserEnabled(@UserIdInt int userHandle) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001741 try {
1742 mService.setUserEnabled(userHandle);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001743 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001744 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001745 }
1746 }
1747
1748 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01001749 * Evicts the user's credential encryption key from memory by stopping and restarting the user.
1750 *
1751 * @hide
1752 */
1753 public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
1754 try {
1755 mService.evictCredentialEncryptionKey(userHandle);
1756 } catch (RemoteException re) {
1757 throw re.rethrowFromSystemServer();
1758 }
1759 }
1760
1761 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001762 * Return the number of users currently created on the device.
1763 */
1764 public int getUserCount() {
1765 List<UserInfo> users = getUsers();
1766 return users != null ? users.size() : 1;
1767 }
1768
1769 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07001770 * Returns information for all users on this device, including ones marked for deletion.
1771 * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
1772 * <p>
Amith Yamasani195263742012-08-21 15:40:12 -07001773 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001774 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07001775 * @hide
1776 */
1777 public List<UserInfo> getUsers() {
1778 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07001779 return mService.getUsers(false);
1780 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001781 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07001782 }
1783 }
1784
1785 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001786 * Returns serial numbers of all users on this device.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001787 *
1788 * @param excludeDying specify if the list should exclude users being removed.
1789 * @return the list of serial numbers of users that exist on the device.
1790 * @hide
1791 */
1792 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001793 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001794 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
1795 try {
1796 List<UserInfo> users = mService.getUsers(excludeDying);
1797 long[] result = new long[users.size()];
1798 for (int i = 0; i < result.length; i++) {
1799 result[i] = users.get(i).serialNumber;
1800 }
1801 return result;
1802 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001803 throw re.rethrowFromSystemServer();
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001804 }
1805 }
1806
1807 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001808 * @return the user's account name, null if not found.
1809 * @hide
1810 */
1811 @RequiresPermission( allOf = {
1812 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1813 Manifest.permission.MANAGE_USERS
1814 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001815 public @Nullable String getUserAccount(@UserIdInt int userHandle) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001816 try {
1817 return mService.getUserAccount(userHandle);
1818 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001819 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001820 }
1821 }
1822
1823 /**
1824 * Set account name for the given user.
1825 * @hide
1826 */
1827 @RequiresPermission( allOf = {
1828 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1829 Manifest.permission.MANAGE_USERS
1830 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001831 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001832 try {
1833 mService.setUserAccount(userHandle, accountName);
1834 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001835 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001836 }
1837 }
1838
1839 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001840 * Returns information for Primary user.
1841 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1842 *
1843 * @return the Primary user, null if not found.
1844 * @hide
1845 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001846 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001847 try {
1848 return mService.getPrimaryUser();
1849 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001850 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001851 }
1852 }
1853
1854 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07001855 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
1856 * permission.
1857 *
1858 * @return true if more users can be added, false if limit has been reached.
1859 * @hide
1860 */
1861 public boolean canAddMoreUsers() {
1862 final List<UserInfo> users = getUsers(true);
1863 final int totalUserCount = users.size();
1864 int aliveUserCount = 0;
1865 for (int i = 0; i < totalUserCount; i++) {
1866 UserInfo user = users.get(i);
1867 if (!user.isGuest()) {
1868 aliveUserCount++;
1869 }
1870 }
1871 return aliveUserCount < getMaxSupportedUsers();
1872 }
1873
1874 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07001875 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
1876 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00001877 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
1878 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07001879 *
1880 * @return true if more managed profiles can be added, false if limit has been reached.
1881 * @hide
1882 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001883 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07001884 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00001885 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07001886 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001887 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07001888 }
1889 }
1890
1891 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001892 * Returns list of the profiles of userHandle including
1893 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07001894 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07001895 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08001896 *
Kenny Guy2a764942014-04-02 13:29:20 +01001897 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1898 * @param userHandle profiles of this user will be returned.
1899 * @return the list of profiles.
1900 * @hide
1901 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001902 public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001903 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001904 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001905 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001906 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001907 }
1908 }
1909
1910 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001911 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1912 * @param userId one of the two user ids to check.
1913 * @param otherUserId one of the two user ids to check.
1914 * @return true if the two user ids are in the same profile group.
1915 * @hide
1916 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001917 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001918 try {
1919 return mService.isSameProfileGroup(userId, otherUserId);
1920 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001921 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001922 }
1923 }
1924
1925 /**
Ruben Brunk7f75da22015-04-30 17:46:30 -07001926 * Returns list of the profiles of userHandle including
1927 * userHandle itself.
1928 * Note that this returns only enabled.
1929 *
1930 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1931 * @param userHandle profiles of this user will be returned.
1932 * @return the list of profiles.
1933 * @hide
1934 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001935 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07001936 try {
1937 return mService.getProfiles(userHandle, true /* enabledOnly */);
1938 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001939 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07001940 }
1941 }
1942
1943 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01001944 * Returns a list of UserHandles for profiles associated with the user that the calling process
1945 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08001946 *
1947 * @return A non-empty list of UserHandles associated with the calling user.
1948 */
1949 public List<UserHandle> getUserProfiles() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001950 int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
1951 List<UserHandle> result = new ArrayList<>(userIds.length);
1952 for (int userId : userIds) {
1953 result.add(UserHandle.of(userId));
1954 }
1955 return result;
1956 }
1957
1958 /**
1959 * Returns a list of ids for profiles associated with the specified user including the user
1960 * itself.
1961 *
1962 * @param userId id of the user to return profiles for
1963 * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
1964 * @return A non-empty list of ids of profiles associated with the specified user.
1965 *
1966 * @hide
1967 */
1968 public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001969 try {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001970 return mService.getProfileIds(userId, enabledOnly);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001971 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001972 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001973 }
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001974 }
1975
1976 /**
1977 * @see #getProfileIds(int, boolean)
1978 * @hide
1979 */
1980 public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
1981 return getProfileIds(userId, false /* enabledOnly */);
1982 }
1983
1984 /**
1985 * @see #getProfileIds(int, boolean)
1986 * @hide
1987 */
1988 public int[] getEnabledProfileIds(@UserIdInt int userId) {
1989 return getProfileIds(userId, true /* enabledOnly */);
Amith Yamasani4f582632014-02-19 14:31:52 -08001990 }
1991
Amith Yamasani7dda2652014-04-11 14:57:12 -07001992 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07001993 * Returns the device credential owner id of the profile from
1994 * which this method is called, or userHandle if called from a user that
1995 * is not a profile.
1996 *
1997 * @hide
1998 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001999 public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
Andres Moralesc5548c02015-08-05 10:23:12 -07002000 try {
2001 return mService.getCredentialOwnerProfile(userHandle);
2002 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002003 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07002004 }
2005 }
2006
2007 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01002008 * Returns the parent of the profile which this method is called from
2009 * or null if called from a user that is not a profile.
2010 *
2011 * @hide
2012 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002013 public UserInfo getProfileParent(@UserIdInt int userHandle) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01002014 try {
2015 return mService.getProfileParent(userHandle);
2016 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002017 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01002018 }
2019 }
2020
2021 /**
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002022 * Set quiet mode of a managed profile.
2023 *
2024 * @param userHandle The user handle of the profile.
2025 * @param enableQuietMode Whether quiet mode should be enabled or disabled.
2026 * @hide
2027 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002028 public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002029 try {
2030 mService.setQuietModeEnabled(userHandle, enableQuietMode);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002031 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002032 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002033 }
2034 }
2035
2036 /**
2037 * Returns whether the given profile is in quiet mode or not.
Ricky Wai7881cf82016-04-15 17:20:12 +01002038 * Notes: Quiet mode is only supported for managed profiles.
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002039 *
2040 * @param userHandle The user handle of the profile to be queried.
2041 * @return true if the profile is in quiet mode, false otherwise.
2042 */
2043 public boolean isQuietModeEnabled(UserHandle userHandle) {
2044 try {
2045 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002046 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002047 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002048 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00002049 }
2050
2051 /**
Benjamin Franzf02420c2016-04-04 18:52:21 +01002052 * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user
2053 * first by showing the confirm credentials screen and disable quiet mode upon successful
2054 * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled}
2055 * directly.
2056 *
2057 * @return true if the quiet mode was disabled immediately
2058 * @hide
2059 */
2060 public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) {
2061 try {
2062 return mService.trySetQuietModeDisabled(userHandle, target);
2063 } catch (RemoteException re) {
2064 throw re.rethrowFromSystemServer();
2065 }
2066 }
2067
2068 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -07002069 * If the target user is a managed profile of the calling user or the caller
2070 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07002071 * icon to be able to distinguish it from the original icon. For badging an
2072 * arbitrary drawable use {@link #getBadgedDrawableForUser(
2073 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2074 * <p>
2075 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002076 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002077 * is performed in place and the original drawable is returned.
2078 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07002079 *
2080 * @param icon The icon to badge.
2081 * @param user The target user.
2082 * @return A drawable that combines the original icon and a badge as
2083 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002084 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07002085 */
Svetoslavc71c42f2014-08-05 18:57:05 -07002086 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002087 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002088 }
2089
Kenny Guy701ea7c2014-05-08 23:34:12 +01002090 /**
2091 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -07002092 * is itself a managed profile, then this returns a badged copy of the given
2093 * drawable allowing the user to distinguish it from the original drawable.
2094 * The caller can specify the location in the bounds of the drawable to be
2095 * badged where the badge should be applied as well as the density of the
2096 * badge to be used.
2097 * <p>
2098 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002099 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07002100 * is performed in place and the original drawable is returned.
2101 * </p>
2102 *
2103 * @param badgedDrawable The drawable to badge.
2104 * @param user The target user.
2105 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002106 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07002107 * drawable being badged.
2108 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08002109 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07002110 * the density of the display is used.
2111 * @return A drawable that combines the original drawable and a badge as
2112 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002113 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07002114 */
2115 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2116 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002117 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2118 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07002119 }
2120
2121 /**
2122 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002123 * is itself a managed profile, then this returns a copy of the label with
2124 * badging for accessibility services like talkback. E.g. passing in "Email"
2125 * and it might return "Work Email" for Email in the work profile.
2126 *
2127 * @param label The label to change.
2128 * @param user The target user.
2129 * @return A label that combines the original label and a badge as
2130 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07002131 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01002132 */
Kenny Guy237aecd2014-07-21 14:06:09 +01002133 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07002134 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08002135 }
2136
2137 /**
2138 * Returns information for all users on this device. Requires
2139 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04002140 *
Amith Yamasani4f582632014-02-19 14:31:52 -08002141 * @param excludeDying specify if the list should exclude users being
2142 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07002143 * @return the list of users that were created.
2144 * @hide
2145 */
Adam Lesinskiada8deb2017-05-12 13:50:42 -07002146 public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
Amith Yamasani920ace02012-09-20 22:15:37 -07002147 try {
2148 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07002149 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002150 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002151 }
2152 }
2153
2154 /**
2155 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07002156 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002157 * @param userHandle the integer handle of the user, where 0 is the primary user.
2158 * @hide
2159 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002160 public boolean removeUser(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002161 try {
2162 return mService.removeUser(userHandle);
2163 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002164 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002165 }
2166 }
2167
2168 /**
Nicolas Prevotd37c4a92017-01-23 11:56:00 +00002169 * Similar to {@link #removeUser(int)} except bypassing the checking of
2170 * {@link UserManager#DISALLOW_REMOVE_USER}
2171 * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2172 *
2173 * @see {@link #removeUser(int)}
2174 * @hide
2175 */
2176 public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2177 try {
2178 return mService.removeUserEvenWhenDisallowed(userHandle);
2179 } catch (RemoteException re) {
2180 throw re.rethrowFromSystemServer();
2181 }
2182 }
2183
2184 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002185 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07002186 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07002187 *
2188 * @param userHandle the user's integer handle
2189 * @param name the new name for the user
2190 * @hide
2191 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002192 public void setUserName(@UserIdInt int userHandle, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002193 try {
2194 mService.setUserName(userHandle, name);
2195 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002196 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002197 }
2198 }
2199
2200 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002201 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002202 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002203 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07002204 * @hide
2205 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002206 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07002207 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002208 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07002209 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002210 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07002211 }
2212 }
2213
2214 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07002215 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
2216 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07002217 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002218 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07002219 * @hide
2220 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002221 public Bitmap getUserIcon(@UserIdInt int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07002222 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01002223 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
2224 if (fd != null) {
2225 try {
2226 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
2227 } finally {
2228 try {
2229 fd.close();
2230 } catch (IOException e) {
2231 }
2232 }
2233 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07002234 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002235 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07002236 }
Adrian Roos1bdff912015-02-17 15:51:35 +01002237 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07002238 }
2239
2240 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002241 * Returns the maximum number of users that can be created on this device. A return value
2242 * of 1 means that it is a single user device.
2243 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04002244 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07002245 */
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002246 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07002247 // Don't allow multiple users on certain builds
2248 if (android.os.Build.ID.startsWith("JVP")) return 1;
Dianne Hackborn409297d2014-07-10 17:39:20 -07002249 // Svelte devices don't get multi-user.
2250 if (ActivityManager.isLowRamDeviceStatic()) return 1;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07002251 return SystemProperties.getInt("fw.max_users",
2252 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07002253 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002254
2255 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002256 * Returns true if the user switcher should be shown, this will be if device supports multi-user
2257 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00002258 * @hide
2259 * @return true if user switcher should be shown.
2260 */
2261 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002262 if (!supportsMultipleUsers()) {
2263 return false;
2264 }
Amith Yamasanieb437d42016-04-29 09:31:25 -07002265 // If Demo Mode is on, don't show user switcher
2266 if (isDeviceInDemoMode(mContext)) {
2267 return false;
2268 }
Kenny Guy1a447532014-02-20 21:55:32 +00002269 List<UserInfo> users = getUsers(true);
2270 if (users == null) {
2271 return false;
2272 }
2273 int switchableUserCount = 0;
2274 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07002275 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00002276 ++switchableUserCount;
2277 }
2278 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002279 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2280 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07002281 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00002282 }
2283
2284 /**
Amith Yamasanieb437d42016-04-29 09:31:25 -07002285 * @hide
2286 */
2287 public static boolean isDeviceInDemoMode(Context context) {
2288 return Settings.Global.getInt(context.getContentResolver(),
2289 Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2290 }
2291
2292 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07002293 * Returns a serial number on this device for a given userHandle. User handles can be recycled
2294 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
2295 * @param userHandle
2296 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
2297 * @hide
2298 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002299 public int getUserSerialNumber(@UserIdInt int userHandle) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002300 try {
2301 return mService.getUserSerialNumber(userHandle);
2302 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002303 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002304 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002305 }
2306
2307 /**
2308 * Returns a userHandle on this device for a given user serial number. User handles can be
2309 * recycled when deleting and creating users, but serial numbers are not reused until the device
2310 * is wiped.
2311 * @param userSerialNumber
2312 * @return the userHandle associated with that user serial number, or -1 if the serial number
2313 * is not valid.
2314 * @hide
2315 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07002316 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07002317 try {
2318 return mService.getUserHandle(userSerialNumber);
2319 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002320 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07002321 }
Amith Yamasani2a003292012-08-14 18:25:45 -07002322 }
Maggie Benthall67944582013-02-22 14:58:27 -05002323
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002324 /**
Esteban Talavera953fe482016-06-07 15:25:20 +01002325 * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002326 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002327 *
2328 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
2329 * where the types of values may be:
2330 * <ul>
2331 * <li>{@code boolean}
2332 * <li>{@code int}
2333 * <li>{@code String} or {@code String[]}
2334 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
2335 * </ul>
2336 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002337 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
2338 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002339 * @param packageName the package name of the calling application
Esteban Talavera953fe482016-06-07 15:25:20 +01002340 * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2341 * if there are no saved restrictions.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00002342 *
2343 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002344 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002345 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002346 public Bundle getApplicationRestrictions(String packageName) {
2347 try {
2348 return mService.getApplicationRestrictions(packageName);
2349 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002350 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002351 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002352 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002353
2354 /**
2355 * @hide
2356 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002357 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002358 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002359 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002360 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002361 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002362 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002363 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002364 }
2365
2366 /**
2367 * @hide
2368 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07002369 @WorkerThread
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002370 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002371 UserHandle user) {
2372 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07002373 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002374 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002375 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08002376 }
2377 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002378
2379 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07002380 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2381 * apps and requires the MANAGE_USERS permission.
2382 * @param newPin the PIN to use for challenge dialogs.
2383 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07002384 * @deprecated The restrictions PIN functionality is no longer provided by the system.
2385 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07002386 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07002387 @Deprecated
Amith Yamasanid304af62013-09-05 09:30:23 -07002388 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002389 return false;
2390 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07002391
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302392 /**
2393 * @hide
2394 * Set restrictions that should apply to any future guest user that's created.
2395 */
2396 public void setDefaultGuestRestrictions(Bundle restrictions) {
2397 try {
2398 mService.setDefaultGuestRestrictions(restrictions);
2399 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002400 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302401 }
2402 }
2403
2404 /**
2405 * @hide
2406 * Gets the default guest restrictions.
2407 */
2408 public Bundle getDefaultGuestRestrictions() {
2409 try {
2410 return mService.getDefaultGuestRestrictions();
2411 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002412 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302413 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05302414 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002415
2416 /**
2417 * Returns creation time of the user or of a managed profile associated with the calling user.
2418 * @param userHandle user handle of the user or a managed profile associated with the
2419 * calling user.
2420 * @return creation time in milliseconds since Epoch time.
2421 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07002422 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002423 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07002424 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002425 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002426 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07002427 }
2428 }
Amith Yamasani12747872015-12-07 14:19:49 -08002429
2430 /**
2431 * @hide
2432 * Checks if any uninitialized user has the specific seed account name and type.
2433 *
Pavel Grafov6a40f092016-10-25 15:46:51 +01002434 * @param accountName The account name to check for
2435 * @param accountType The account type of the account to check for
Amith Yamasani12747872015-12-07 14:19:49 -08002436 * @return whether the seed account was found
2437 */
2438 public boolean someUserHasSeedAccount(String accountName, String accountType) {
2439 try {
2440 return mService.someUserHasSeedAccount(accountName, accountType);
2441 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002442 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08002443 }
2444 }
Pavel Grafov6a40f092016-10-25 15:46:51 +01002445
2446 /**
2447 * @hide
2448 * User that enforces a restriction.
2449 *
2450 * @see #getUserRestrictionSources(String, UserHandle)
2451 */
2452 @SystemApi
2453 public static final class EnforcingUser implements Parcelable {
2454 private final @UserIdInt int userId;
2455 private final @UserRestrictionSource int userRestrictionSource;
2456
2457 /**
2458 * @hide
2459 */
2460 public EnforcingUser(
2461 @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
2462 this.userId = userId;
2463 this.userRestrictionSource = userRestrictionSource;
2464 }
2465
2466 private EnforcingUser(Parcel in) {
2467 userId = in.readInt();
2468 userRestrictionSource = in.readInt();
2469 }
2470
2471 public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
2472 @Override
2473 public EnforcingUser createFromParcel(Parcel in) {
2474 return new EnforcingUser(in);
2475 }
2476
2477 @Override
2478 public EnforcingUser[] newArray(int size) {
2479 return new EnforcingUser[size];
2480 }
2481 };
2482
2483 @Override
2484 public int describeContents() {
2485 return 0;
2486 }
2487
2488 @Override
2489 public void writeToParcel(Parcel dest, int flags) {
2490 dest.writeInt(userId);
2491 dest.writeInt(userRestrictionSource);
2492 }
2493
2494 /**
2495 * Returns an id of the enforcing user.
2496 *
2497 * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
2498 */
2499 public UserHandle getUserHandle() {
2500 return UserHandle.of(userId);
2501 }
2502
2503 /**
2504 * Returns the status of the enforcing user.
2505 *
2506 * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
2507 * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
2508 * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
2509 */
2510 public @UserRestrictionSource int getUserRestrictionSource() {
2511 return userRestrictionSource;
2512 }
2513 }
Amith Yamasani258848d2012-08-10 17:06:33 -07002514}