blob: 7223dfbdccdb07fdae03be54475c206b39017568 [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 */
16package android.os;
17
Xiaohui Chenb3b92582015-12-07 11:22:13 -080018import android.Manifest;
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -070019import android.accounts.AccountManager;
Xiaohui Chen7cb69df2015-07-13 16:01:01 -070020import android.annotation.Nullable;
Xiaohui Chenb3b92582015-12-07 11:22:13 -080021import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070022import android.annotation.SystemApi;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070023import android.annotation.UserIdInt;
Amith Yamasani37ed8d12016-01-27 14:40:16 -080024import android.app.Activity;
Dianne Hackborn409297d2014-07-10 17:39:20 -070025import android.app.ActivityManager;
Dianne Hackborna8a9bd62012-10-09 15:36:59 -070026import android.app.ActivityManagerNative;
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -070027import android.app.admin.DevicePolicyManager;
Makoto Onuki068c54a2015-10-13 14:34:03 -070028import android.content.ComponentName;
Amith Yamasani258848d2012-08-10 17:06:33 -070029import android.content.Context;
Amith Yamasani12747872015-12-07 14:19:49 -080030import android.content.Intent;
Amith Yamasani258848d2012-08-10 17:06:33 -070031import android.content.pm.UserInfo;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070032import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050033import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010034import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080035import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080036import android.graphics.drawable.Drawable;
Jeff Sharkey5b0e5202015-12-18 17:18:09 -070037import android.os.storage.StorageManager;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070038import android.provider.Settings;
Fyodor Kupolov523c4042016-02-24 15:03:13 -080039import android.telephony.TelephonyManager;
Jason Monk1c7c3192014-06-26 12:52:18 -040040import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070041
Maggie Benthall67944582013-02-22 14:58:27 -050042import com.android.internal.R;
43
Adrian Roos1bdff912015-02-17 15:51:35 +010044import java.io.IOException;
Amith Yamasani4f582632014-02-19 14:31:52 -080045import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070046import java.util.List;
47
48/**
49 * Manages users and user details on a multi-user system.
50 */
51public class UserManager {
52
53 private static String TAG = "UserManager";
54 private final IUserManager mService;
55 private final Context mContext;
56
Amith Yamasanie4cf7342012-12-17 11:12:09 -080057 /**
Fyodor Kupolov53019282015-07-21 11:48:18 -070058 * Specifies if a user is disallowed from adding and removing accounts, unless they are
59 * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
60 * Authenticator.
Amith Yamasani71e6c692013-03-24 17:39:28 -070061 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -070062 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +000063 * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
64 * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
65 * management is disallowed.
66 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -080067 * <p>Key for user restrictions.
68 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -070069 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
70 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -080071 * @see #getUserRestrictions()
72 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070073 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080074
75 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070076 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -040077 * access points. The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -080078 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -070079 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -080080 * <p>Key for user restrictions.
81 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -070082 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
83 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -080084 * @see #getUserRestrictions()
85 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070086 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080087
88 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070089 * Specifies if a user is disallowed from installing applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -070090 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -070091 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -080092 * <p>Key for user restrictions.
93 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -070094 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
95 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -080096 * @see #getUserRestrictions()
97 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070098 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080099
100 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700101 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700102 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700103 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800104 * <p>Key for user restrictions.
105 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700106 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
107 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800108 * @see #getUserRestrictions()
109 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700110 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800111
Amith Yamasani71e6c692013-03-24 17:39:28 -0700112 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800113 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700114 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800115 * <p>In a managed profile, location sharing always reflects the primary user's setting, but
Amith Yamasani150514b2015-01-07 16:05:05 -0800116 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700117 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800118 * <p>Key for user restrictions.
119 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700120 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
121 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthall67944582013-02-22 14:58:27 -0500122 * @see #getUserRestrictions()
123 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700124 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500125
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400126 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700127 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400128 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
129 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700130 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800131 * <p>Key for user restrictions.
132 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700133 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
134 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400135 * @see #getUserRestrictions()
136 */
137 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
138
139 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700140 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000141 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400142 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800143 * <p>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700144 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800145 * <p>Key for user restrictions.
146 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700147 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
148 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400149 * @see #getUserRestrictions()
150 */
151 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
152
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400153 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700154 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700155 * USB. This can only be set by device owners and profile owners on the primary user.
156 * 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)
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400162 * @see #getUserRestrictions()
163 */
164 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
165
Emily Bernierb223f732013-04-11 15:46:36 -0400166 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700167 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400168 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700169 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800170 * <p>Key for user restrictions.
171 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700172 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
173 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400174 * @see #getUserRestrictions()
175 */
176 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
177
178 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800179 * When set on the primary user this specifies if the user can remove other users.
180 * When set on a secondary user, this specifies if the user can remove itself.
181 * This restriction has no effect on managed profiles.
182 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700183 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800184 * <p>Key for user restrictions.
185 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700186 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
187 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernierb223f732013-04-11 15:46:36 -0400188 * @see #getUserRestrictions()
189 */
190 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
191
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400192 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700193 * Specifies if a user is disallowed from enabling or
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400194 * accessing debugging features. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700195 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800196 * <p>Key for user restrictions.
197 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700198 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
199 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400200 * @see #getUserRestrictions()
201 */
202 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
203
204 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700205 * Specifies if a user is disallowed from configuring VPN.
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400206 * The default value is <code>false</code>.
Nicolas Prevot298f98f2015-05-22 16:43:03 -0700207 * This restriction has an effect in a managed profile only from
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700208 * {@link android.os.Build.VERSION_CODES#M}
Amith Yamasani26af8292014-09-09 09:57:27 -0700209 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800210 * <p>Key for user restrictions.
211 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700212 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
213 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400214 * @see #getUserRestrictions()
215 */
216 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
217
218 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700219 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700220 * & portable hotspots. This can only be set by device owners and profile owners on the
221 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700222 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800223 * <p>Key for user restrictions.
224 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700225 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
226 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400227 * @see #getUserRestrictions()
228 */
229 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
230
231 /**
Stuart Scotte3e314d2015-04-20 14:07:45 -0700232 * Specifies if a user is disallowed from resetting network settings
233 * from Settings. This can only be set by device owners and profile owners on the primary user.
234 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800235 * <p>This restriction has no effect on secondary users and managed profiles since only the
Stuart Scotte3e314d2015-04-20 14:07:45 -0700236 * primary user can reset the network settings of the device.
237 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800238 * <p>Key for user restrictions.
239 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700240 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
241 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Stuart Scotte3e314d2015-04-20 14:07:45 -0700242 * @see #getUserRestrictions()
243 */
244 public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
245
246 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700247 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700248 * from Settings. This can only be set by device owners and profile owners on the primary user.
249 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800250 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800251 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700252 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800253 * <p>Key for user restrictions.
254 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700255 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
256 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400257 * @see #getUserRestrictions()
258 */
259 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
260
261 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700262 * Specifies if a user is disallowed from adding new users and
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700263 * profiles. This can only be set by device owners and profile owners on the primary user.
264 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800265 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800266 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700267 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800268 * <p>Key for user restrictions.
269 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700270 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
271 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400272 * @see #getUserRestrictions()
273 */
274 public static final String DISALLOW_ADD_USER = "no_add_user";
275
276 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700277 * Specifies if a user is disallowed from disabling application
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400278 * verification. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700279 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800280 * <p>Key for user restrictions.
281 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700282 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
283 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400284 * @see #getUserRestrictions()
285 */
286 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
287
288 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700289 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700290 * broadcasts. This can only be set by device owners and profile owners on the primary user.
291 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800292 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800293 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700294 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800295 * <p>Key for user restrictions.
296 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700297 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
298 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400299 * @see #getUserRestrictions()
300 */
301 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
302
303 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700304 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700305 * networks. This can only be set by device owners and profile owners on the primary user.
306 * The default value is <code>false</code>.
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800307 * <p>This restriction has no effect on secondary users and managed profiles since only the
Amith Yamasani150514b2015-01-07 16:05:05 -0800308 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700309 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800310 * <p>Key for user restrictions.
311 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700312 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
313 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400314 * @see #getUserRestrictions()
315 */
316 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
317
318 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700319 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400320 * applications in Settings or launchers. The following actions will not be allowed when this
321 * restriction is enabled:
322 * <li>uninstalling apps</li>
323 * <li>disabling apps</li>
324 * <li>clearing app caches</li>
325 * <li>clearing app data</li>
326 * <li>force stopping apps</li>
327 * <li>clearing app defaults</li>
328 * <p>
329 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700330 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800331 * <p>Key for user restrictions.
332 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700333 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
334 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400335 * @see #getUserRestrictions()
336 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400337 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400338
Emily Bernier394a6cd2014-05-07 12:49:20 -0400339 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700340 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700341 * physical external media. This can only be set by device owners and profile owners on the
342 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700343 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800344 * <p>Key for user restrictions.
345 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700346 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
347 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400348 * @see #getUserRestrictions()
349 */
350 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
351
352 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700353 * Specifies if a user is disallowed from adjusting microphone
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700354 * volume. If set, the microphone will be muted. This can only be set by device owners
355 * and profile owners on the primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700356 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800357 * <p>Key for user restrictions.
358 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700359 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
360 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400361 * @see #getUserRestrictions()
362 */
363 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
364
365 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700366 * Specifies if a user is disallowed from adjusting the master
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700367 * volume. If set, the master volume will be muted. This can only be set by device owners
368 * and profile owners on the primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700369 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800370 * <p>Key for user restrictions.
371 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700372 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
373 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Emily Bernier394a6cd2014-05-07 12:49:20 -0400374 * @see #getUserRestrictions()
375 */
376 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
377
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700378 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700379 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700380 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700381 * The default value is <code>false</code>.
Tony Makeb83ab52016-02-22 18:36:08 +0000382 * <p>This restriction has no effect on managed profiles.
Amith Yamasani26af8292014-09-09 09:57:27 -0700383 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800384 * <p>Key for user restrictions.
385 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700386 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
387 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700388 * @see #getUserRestrictions()
389 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700390 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
391
392 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700393 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700394 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700395 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800396 * <p>Key for user restrictions.
397 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700398 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
399 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani390989d2014-07-17 10:52:03 -0700400 * @see #getUserRestrictions()
401 */
402 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700403
Jason Monk1c7c3192014-06-26 12:52:18 -0400404 /**
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700405 * Specifies if the user is not allowed to have fun. In some cases, the
406 * device owner may wish to prevent the user from experiencing amusement or
407 * joy while using the device. The default value is <code>false</code>.
408 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800409 * <p>Key for user restrictions.
410 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700411 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
412 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jeff Sharkey2cc03e52015-03-20 11:24:04 -0700413 * @see #getUserRestrictions()
414 */
415 public static final String DISALLOW_FUN = "no_fun";
416
417 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700418 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400419 * created. This will block the creation of the following types of windows.
420 * <li>{@link LayoutParams#TYPE_TOAST}</li>
421 * <li>{@link LayoutParams#TYPE_PHONE}</li>
422 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
423 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
424 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
425 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
426 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700427 * <p>This can only be set by device owners and profile owners on the primary user.
428 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700429 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800430 * <p>Key for user restrictions.
431 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700432 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
433 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Jason Monk1c7c3192014-06-26 12:52:18 -0400434 * @see #getUserRestrictions()
435 */
436 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
437
Nicolas Prevotf1939902014-06-25 09:29:02 +0100438 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700439 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100440 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
441 * pasted in this profile.
442 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700443 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800444 * <p>Key for user restrictions.
445 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700446 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
447 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevotf1939902014-06-25 09:29:02 +0100448 * @see #getUserRestrictions()
449 */
450 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
451
Amith Yamasani26af8292014-09-09 09:57:27 -0700452 /**
453 * Specifies if the user is not allowed to use NFC to beam out data from apps.
454 * The default value is <code>false</code>.
455 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800456 * <p>Key for user restrictions.
457 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700458 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
459 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Amith Yamasani26af8292014-09-09 09:57:27 -0700460 * @see #getUserRestrictions()
461 */
462 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
463
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000464 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100465 * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
466 * generally means that wallpapers are not supported for the particular user. This user
467 * restriction is always set for managed profiles, because such profiles don't have wallpapers.
Benjamin Franzf3ece362015-02-11 10:51:10 +0000468 * @hide
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100469 * @see #DISALLOW_SET_WALLPAPER
Makoto Onuki068c54a2015-10-13 14:34:03 -0700470 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
471 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzf3ece362015-02-11 10:51:10 +0000472 * @see #getUserRestrictions()
473 */
474 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
475
476 /**
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100477 * User restriction to disallow setting a wallpaper. Profile owner and device owner
478 * are able to set wallpaper regardless of this restriction.
479 * The default value is <code>false</code>.
480 *
481 * <p>Key for user restrictions.
482 * <p>Type: Boolean
483 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
484 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
485 * @see #getUserRestrictions()
486 */
487 public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
488
489 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000490 * Specifies if the user is not allowed to reboot the device into safe boot mode.
491 * This can only be set by device owners and profile owners on the primary user.
492 * The default value is <code>false</code>.
493 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800494 * <p>Key for user restrictions.
495 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700496 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
497 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000498 * @see #getUserRestrictions()
499 */
500 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
501
502 /**
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700503 * Specifies if a user is not allowed to record audio. This restriction is always enabled for
504 * background users. The default value is <code>false</code>.
505 *
Makoto Onuki068c54a2015-10-13 14:34:03 -0700506 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
507 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700508 * @see #getUserRestrictions()
509 * @hide
510 */
511 public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
512
513 /**
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700514 * Specifies if a user is not allowed to run in the background and should be stopped during
515 * user switch. The default value is <code>false</code>.
516 *
517 * <p>This restriction can be set by device owners and profile owners.
518 *
519 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
520 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
521 * @see #getUserRestrictions()
522 * @hide
523 */
524 public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
525
526 /**
Makoto Onuki759a7632015-10-28 16:43:10 -0700527 * Specifies if a user is not allowed to use the camera.
528 *
529 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
530 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
531 * @see #getUserRestrictions()
532 * @hide
533 */
534 public static final String DISALLOW_CAMERA = "no_camera";
535
536 /**
Mahaver Chopradea471e2015-12-17 11:02:37 +0000537 * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
538 * device owners. The default value is <code>false</code>.
539 *
540 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
541 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
542 * @see #getUserRestrictions()
543 */
544 public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
545
546 /**
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100547 * Specifies if a user is not allowed to change their icon. Device owner and profile owner
548 * can set this restriction. When it is set by device owner, only the target user will be
549 * affected. The default value is <code>false</code>.
550 *
551 * <p>Key for user restrictions.
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100552 * <p>Type: Boolean
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100553 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
554 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
555 * @see #getUserRestrictions()
556 */
557 public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
558
559 /**
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700560 * Allows apps in the parent profile to handle web links from the managed profile.
561 *
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700562 * This user restriction has an effect only in a managed profile.
563 * If set:
564 * Intent filters of activities in the parent profile with action
565 * {@link android.content.Intent#ACTION_VIEW},
566 * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
567 * define a host can handle intents from the managed profile.
568 * The default value is <code>false</code>.
569 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800570 * <p>Key for user restrictions.
571 * <p>Type: Boolean
Makoto Onuki068c54a2015-10-13 14:34:03 -0700572 * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
573 * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700574 * @see #getUserRestrictions()
575 */
Nicolas Prevotf0029c12015-06-25 14:25:41 -0700576 public static final String ALLOW_PARENT_PROFILE_APP_LINKING
577 = "allow_parent_profile_app_linking";
Nicolas Prevot9edbda12015-06-17 11:09:48 -0700578
579 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000580 * Application restriction key that is used to indicate the pending arrival
581 * of real restrictions for the app.
582 *
583 * <p>
584 * Applications that support restrictions should check for the presence of this key.
585 * A <code>true</code> value indicates that restrictions may be applied in the near
586 * future but are not available yet. It is the responsibility of any
587 * management application that sets this flag to update it when the final
588 * restrictions are enforced.
589 *
Fyodor Kupolov0ffbfea2016-01-19 10:07:54 -0800590 * <p>Key for application restrictions.
591 * <p>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +0000592 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
593 * android.content.ComponentName, String, Bundle)
594 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
595 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000596 */
597 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
598
Amith Yamasani12747872015-12-07 14:19:49 -0800599 private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
600
601 /**
602 * Extra containing a name for the user being created. Optional parameter passed to
603 * ACTION_CREATE_USER activity.
604 * @hide
605 */
606 public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
607
608 /**
609 * Extra containing account name for the user being created. Optional parameter passed to
610 * ACTION_CREATE_USER activity.
611 * @hide
612 */
613 public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
614
615 /**
616 * Extra containing account type for the user being created. Optional parameter passed to
617 * ACTION_CREATE_USER activity.
618 * @hide
619 */
620 public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
621
622 /**
623 * Extra containing account-specific data for the user being created. Optional parameter passed
624 * to ACTION_CREATE_USER activity.
625 * @hide
626 */
627 public static final String EXTRA_USER_ACCOUNT_OPTIONS
628 = "android.os.extra.USER_ACCOUNT_OPTIONS";
629
Amith Yamasani655d0e22013-06-12 14:19:10 -0700630 /** @hide */
631 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
632 /** @hide */
633 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
634 /** @hide */
635 public static final int PIN_VERIFICATION_SUCCESS = -1;
636
Amith Yamasani37ed8d12016-01-27 14:40:16 -0800637 /**
638 * Error result indicating that this user is not allowed to add other users on this device.
639 * This is a result code returned from the activity created by the intent
640 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
641 */
642 public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
643
644 /**
645 * Error result indicating that no more users can be created on this device.
646 * This is a result code returned from the activity created by the intent
647 * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
648 */
649 public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
650
Amith Yamasani7e99bc02013-04-16 18:24:51 -0700651 /** @hide */
Amith Yamasanic0688302015-10-30 10:40:03 -0700652 public static UserManager get(Context context) {
653 return (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani27db4682013-03-30 17:07:47 -0700654 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400655
Amith Yamasani258848d2012-08-10 17:06:33 -0700656 /** @hide */
657 public UserManager(Context context, IUserManager service) {
658 mService = service;
659 mContext = context;
660 }
661
662 /**
663 * Returns whether the system supports multiple users.
Kenny Guy1a447532014-02-20 21:55:32 +0000664 * @return true if multiple users can be created by user, false if it is a single user device.
Amith Yamasanie928d7d2012-09-17 21:46:51 -0700665 * @hide
Amith Yamasani258848d2012-08-10 17:06:33 -0700666 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -0700667 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +0000668 return getMaxSupportedUsers() > 1
669 && SystemProperties.getBoolean("fw.show_multiuserui",
670 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -0700671 }
672
Maggie Benthall67944582013-02-22 14:58:27 -0500673 /**
Xiaohui Chen7cb69df2015-07-13 16:01:01 -0700674 * @hide
675 * @return Whether the device is running with split system user. It means the system user and
676 * primary user are two separate users. Previously system user and primary user are combined as
677 * a single owner user. see @link {android.os.UserHandle#USER_OWNER}
678 */
679 public static boolean isSplitSystemUser() {
680 return SystemProperties.getBoolean("ro.fw.system_user_split", false);
681 }
682
683 /**
Fyodor Kupolov523c4042016-02-24 15:03:13 -0800684 * Returns whether switching users is currently allowed.
685 * <p>For instance switching users is not allowed if the current user is in a phone call,
686 * or system user hasn't been unlocked yet
687 * @hide
688 */
689 public boolean canSwitchUsers() {
690 boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
691 mContext.getContentResolver(),
692 Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
693 boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
694 boolean inCall = TelephonyManager.getDefault().getCallState()
695 != TelephonyManager.CALL_STATE_IDLE;
696 return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall;
697 }
698
699 /**
Amith Yamasani5760e172015-04-17 18:42:41 -0700700 * Returns the user handle for the user that this process is running under.
Jessica Hummelbe81c802014-04-22 15:49:22 +0100701 *
Amith Yamasani5760e172015-04-17 18:42:41 -0700702 * @return the user handle of this process.
Amith Yamasani258848d2012-08-10 17:06:33 -0700703 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -0500704 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700705 public @UserIdInt int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700706 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -0700707 }
708
709 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700710 * Returns the user name of the user making this call. This call is only
711 * available to applications on the system image; it requires the
712 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700713 * @return the user name
714 */
715 public String getUserName() {
716 try {
717 return mService.getUserInfo(getUserHandle()).name;
718 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700719 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -0700720 }
721 }
722
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700723 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -0700724 * Used to determine whether the user making this call is subject to
725 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700726 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700727 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700728 * now automatically identify goats using advanced goat recognition technology.</p>
729 *
730 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -0700731 */
732 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -0700733 return mContext.getPackageManager()
734 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -0700735 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800736
737 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -0700738 * Used to check if this process is running under the primary user. The primary user
739 * is the first human user on a device.
740 *
741 * @return whether this process is running under the primary user.
742 * @hide
743 */
744 public boolean isPrimaryUser() {
745 UserInfo user = getUserInfo(UserHandle.myUserId());
746 return user != null ? user.isPrimary() : false;
747 }
748
749 /**
Amith Yamasani5760e172015-04-17 18:42:41 -0700750 * Used to check if this process is running under the system user. The system user
751 * is the initial user that is implicitly created on first boot and hosts most of the
752 * system services.
753 *
754 * @return whether this process is running under the system user.
755 */
756 public boolean isSystemUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -0700757 return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
Amith Yamasani5760e172015-04-17 18:42:41 -0700758 }
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700759
Amith Yamasani5760e172015-04-17 18:42:41 -0700760 /**
Amith Yamasani462ac3a2015-06-30 14:21:01 -0700761 * @hide
762 * Returns whether the caller is running as an admin user. There can be more than one admin
763 * user.
764 */
765 public boolean isAdminUser() {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700766 return isUserAdmin(UserHandle.myUserId());
767 }
768
769 /**
770 * @hide
771 * Returns whether the provided user is an admin user. There can be more than one admin
772 * user.
773 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700774 public boolean isUserAdmin(@UserIdInt int userId) {
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -0700775 UserInfo user = getUserInfo(userId);
776 return user != null && user.isAdmin();
Amith Yamasani462ac3a2015-06-30 14:21:01 -0700777 }
778
779 /**
Amith Yamasanie1375902013-04-13 16:48:35 -0700780 * 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 -0700781 * a reduced number of available apps, app restrictions and account restrictions.
Amith Yamasanie1375902013-04-13 16:48:35 -0700782 * @return whether the user making this call is a linked user
Amith Yamasani2555daf2013-04-25 13:39:27 -0700783 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800784 */
Amith Yamasanie1375902013-04-13 16:48:35 -0700785 public boolean isLinkedUser() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800786 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -0700787 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800788 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700789 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800790 }
791 }
792
Amith Yamasani258848d2012-08-10 17:06:33 -0700793 /**
Fyodor Kupolov1c363152015-09-02 13:27:21 -0700794 * Checks if specified user can have restricted profile.
795 * @hide
796 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700797 public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
Fyodor Kupolov1c363152015-09-02 13:27:21 -0700798 try {
799 return mService.canHaveRestrictedProfile(userId);
800 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700801 throw re.rethrowFromSystemServer();
Fyodor Kupolov1c363152015-09-02 13:27:21 -0700802 }
803 }
804
805 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -0700806 * Checks if the calling app is running as a guest user.
807 * @return whether the caller is a guest user.
808 * @hide
809 */
810 public boolean isGuestUser() {
811 UserInfo user = getUserInfo(UserHandle.myUserId());
812 return user != null ? user.isGuest() : false;
813 }
814
815 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -0700816 * Checks if the calling app is running in a managed profile.
817 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
818 *
819 * @return whether the caller is in a managed profile.
820 * @hide
821 */
822 @SystemApi
823 public boolean isManagedProfile() {
824 UserInfo user = getUserInfo(UserHandle.myUserId());
825 return user != null ? user.isManagedProfile() : false;
826 }
827
828 /**
Lenka Trochtovac4dd0212015-11-18 12:22:06 +0100829 * Checks if the calling app is running as an ephemeral user.
830 *
831 * @return whether the caller is an ephemeral user.
832 * @hide
833 */
834 public boolean isEphemeralUser() {
835 return isUserEphemeral(UserHandle.myUserId());
836 }
837
838 /**
839 * Returns whether the specified user is ephemeral.
840 * @hide
841 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700842 public boolean isUserEphemeral(@UserIdInt int userId) {
Lenka Trochtovac4dd0212015-11-18 12:22:06 +0100843 final UserInfo user = getUserInfo(userId);
844 return user != null && user.isEphemeral();
845 }
846
847 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700848 * Return whether the given user is actively running. This means that
849 * the user is in the "started" state, not "stopped" -- it is currently
850 * allowed to run code through scheduled alarms, receiving broadcasts,
851 * etc. A started user may be either the current foreground user or a
852 * background user; the result here does not distinguish between the two.
853 * @param user The user to retrieve the running state for.
854 */
855 public boolean isUserRunning(UserHandle user) {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -0700856 return isUserRunning(user.getIdentifier());
857 }
858
859 /** {@hide} */
860 public boolean isUserRunning(int userId) {
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700861 try {
Jeff Sharkey0e62384c2016-01-13 18:52:55 -0700862 return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700863 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700864 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700865 }
866 }
867
868 /**
869 * Return whether the given user is actively running <em>or</em> stopping.
870 * This is like {@link #isUserRunning(UserHandle)}, but will also return
871 * true if the user had been running but is in the process of being stopped
872 * (but is not yet fully stopped, and still running some code).
873 * @param user The user to retrieve the running state for.
874 */
875 public boolean isUserRunningOrStopping(UserHandle user) {
876 try {
Jeff Sharkeye17ac152015-11-06 22:40:29 -0800877 // TODO: reconcile stopped vs stopping?
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700878 return ActivityManagerNative.getDefault().isUserRunning(
Jeff Sharkeye17ac152015-11-06 22:40:29 -0800879 user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700880 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700881 throw re.rethrowFromSystemServer();
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700882 }
883 }
884
885 /**
Jeff Sharkeye13529a2015-12-09 14:15:27 -0700886 * Return whether the calling user is running in a "locked" state. A user is
887 * unlocked only after they've entered their credentials (such as a lock
888 * pattern or PIN), and credential-encrypted private app data storage is
889 * available.
890 */
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700891 @Deprecated
Jeff Sharkeye13529a2015-12-09 14:15:27 -0700892 public boolean isUserRunningAndLocked() {
893 return isUserRunningAndLocked(Process.myUserHandle());
894 }
895
896 /**
Jeff Sharkey9d8a1042015-12-03 17:56:20 -0700897 * Return whether the given user is running in a "locked" state. A user
898 * is unlocked only after they've entered their credentials (such as a lock
899 * pattern or PIN), and credential-encrypted private app data storage is
900 * available.
901 *
902 * @param user to retrieve the unlocked state for.
903 */
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700904 @Deprecated
Jeff Sharkey9d8a1042015-12-03 17:56:20 -0700905 public boolean isUserRunningAndLocked(UserHandle user) {
906 try {
907 return ActivityManagerNative.getDefault().isUserRunning(
908 user.getIdentifier(), ActivityManager.FLAG_AND_LOCKED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700909 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700910 throw re.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -0700911 }
912 }
913
914 /**
Jeff Sharkeye13529a2015-12-09 14:15:27 -0700915 * Return whether the calling user is running in an "unlocked" state. A user
916 * is unlocked only after they've entered their credentials (such as a lock
917 * pattern or PIN), and credential-encrypted private app data storage is
918 * available.
919 */
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700920 @Deprecated
Jeff Sharkeye13529a2015-12-09 14:15:27 -0700921 public boolean isUserRunningAndUnlocked() {
922 return isUserRunningAndUnlocked(Process.myUserHandle());
923 }
924
925 /**
Jeff Sharkey0825ab22015-12-02 13:04:49 -0700926 * Return whether the given user is running in an "unlocked" state. A user
927 * is unlocked only after they've entered their credentials (such as a lock
928 * pattern or PIN), and credential-encrypted private app data storage is
929 * available.
930 *
931 * @param user to retrieve the unlocked state for.
932 */
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700933 @Deprecated
Jeff Sharkey9d8a1042015-12-03 17:56:20 -0700934 public boolean isUserRunningAndUnlocked(UserHandle user) {
Jeff Sharkey0825ab22015-12-02 13:04:49 -0700935 try {
936 return ActivityManagerNative.getDefault().isUserRunning(
937 user.getIdentifier(), ActivityManager.FLAG_AND_UNLOCKED);
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700938 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700939 throw re.rethrowFromSystemServer();
Jeff Sharkey0825ab22015-12-02 13:04:49 -0700940 }
941 }
942
943 /**
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700944 * Return whether the calling user is running in an "unlocked" state. A user
945 * is unlocked only after they've entered their credentials (such as a lock
946 * pattern or PIN), and credential-encrypted private app data storage is
947 * available.
948 */
949 public boolean isUserUnlocked() {
950 return isUserUnlocked(Process.myUserHandle());
951 }
952
953 /**
954 * Return whether the given user is running in an "unlocked" state. A user
955 * is unlocked only after they've entered their credentials (such as a lock
956 * pattern or PIN), and credential-encrypted private app data storage is
957 * available.
958 *
959 * @param user to retrieve the unlocked state for.
960 */
961 public boolean isUserUnlocked(UserHandle user) {
Jeff Sharkey0999c0d2015-12-17 15:12:22 -0700962 return isUserUnlocked(user.getIdentifier());
963 }
964
965 /** {@hide} */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700966 public boolean isUserUnlocked(@UserIdInt int userId) {
Jeff Sharkey5b0e5202015-12-18 17:18:09 -0700967 // TODO: eventually pivot this back to look at ActivityManager state,
968 // but there is race where we can start a non-encryption-aware launcher
969 // before that lifecycle has entered the running unlocked state.
970 return mContext.getSystemService(StorageManager.class).isUserKeyUnlocked(userId);
Jeff Sharkeyb6423872015-12-11 11:11:58 -0700971 }
972
973 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700974 * Returns the UserInfo object describing a specific user.
Amith Yamasani195263742012-08-21 15:40:12 -0700975 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700976 * @param userHandle the user handle of the user whose information is being requested.
977 * @return the UserInfo object for a specific user.
978 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -0700979 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700980 public UserInfo getUserInfo(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -0700981 try {
982 return mService.getUserInfo(userHandle);
983 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700984 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -0700985 }
986 }
987
Amith Yamasani71e6c692013-03-24 17:39:28 -0700988 /**
989 * Returns the user-wide restrictions imposed on this user.
990 * @return a Bundle containing all the restrictions.
991 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800992 public Bundle getUserRestrictions() {
993 return getUserRestrictions(Process.myUserHandle());
994 }
995
Amith Yamasani71e6c692013-03-24 17:39:28 -0700996 /**
997 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
998 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
999 * @return a Bundle containing all the restrictions.
1000 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001001 public Bundle getUserRestrictions(UserHandle userHandle) {
1002 try {
1003 return mService.getUserRestrictions(userHandle.getIdentifier());
1004 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001005 throw re.rethrowFromSystemServer();
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001006 }
1007 }
1008
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001009 /**
1010 * @hide
1011 * Returns whether the given user has been disallowed from performing certain actions
1012 * or setting certain settings through UserManager. This method disregards restrictions
1013 * set by device policy.
1014 * @param restrictionKey the string key representing the restriction
1015 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1016 */
1017 public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
1018 try {
1019 return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
1020 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001021 throw re.rethrowFromSystemServer();
Zoltan Szatmary-Ban3bbcedd2015-11-26 13:45:51 +00001022 }
1023 }
1024
Amith Yamasani71e6c692013-03-24 17:39:28 -07001025 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001026 * This will no longer work. Device owners and profile owners should use
1027 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001028 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001029 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001030 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001031 public void setUserRestrictions(Bundle restrictions) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001032 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001033 }
1034
Amith Yamasani71e6c692013-03-24 17:39:28 -07001035 /**
Makoto Onukia3c12502015-10-28 10:18:32 -07001036 * This will no longer work. Device owners and profile owners should use
1037 * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001038 */
Makoto Onukia3c12502015-10-28 10:18:32 -07001039 // System apps should use UserManager.setUserRestriction() instead.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001040 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001041 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001042 throw new UnsupportedOperationException("This method is no longer supported");
Amith Yamasanie4cf7342012-12-17 11:12:09 -08001043 }
1044
Amith Yamasani71e6c692013-03-24 17:39:28 -07001045 /**
1046 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -07001047 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001048 * @param key the key of the restriction
1049 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001050 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1051 * android.content.ComponentName, String)} or
1052 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1053 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001054 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001055 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -07001056 public void setUserRestriction(String key, boolean value) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001057 setUserRestriction(key, value, Process.myUserHandle());
Amith Yamasani71e6c692013-03-24 17:39:28 -07001058 }
1059
1060 /**
1061 * @hide
1062 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -07001063 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001064 * @param key the key of the restriction
1065 * @param value the value for the restriction
1066 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001067 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
1068 * android.content.ComponentName, String)} or
1069 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
1070 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001071 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -04001072 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -05001073 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001074 try {
1075 mService.setUserRestriction(key, value, userHandle.getIdentifier());
1076 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001077 throw re.rethrowFromSystemServer();
Fyodor Kupolovb5013302015-04-17 17:59:14 -07001078 }
Maggie Benthall67944582013-02-22 14:58:27 -05001079 }
1080
Amith Yamasani258848d2012-08-10 17:06:33 -07001081 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001082 * Returns whether the current user has been disallowed from performing certain actions
1083 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -04001084 *
1085 * @param restrictionKey The string key representing the restriction.
1086 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001087 */
1088 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -07001089 return hasUserRestriction(restrictionKey, Process.myUserHandle());
1090 }
1091
1092 /**
1093 * @hide
1094 * Returns whether the given user has been disallowed from performing certain actions
1095 * or setting certain settings.
1096 * @param restrictionKey the string key representing the restriction
1097 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1098 */
1099 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001100 try {
1101 return mService.hasUserRestriction(restrictionKey,
1102 userHandle.getIdentifier());
1103 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001104 throw re.rethrowFromSystemServer();
Amith Yamasani8cd28b52014-06-08 17:54:27 -07001105 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001106 }
1107
1108 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001109 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001110 * number assigned to that user; if the user is deleted and then a new
1111 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001112 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001113 * @return The serial number of the given user; returns -1 if the
1114 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001115 * @see #getUserForSerialNumber(long)
1116 */
1117 public long getSerialNumberForUser(UserHandle user) {
1118 return getUserSerialNumber(user.getIdentifier());
1119 }
1120
1121 /**
1122 * Return the user associated with a serial number previously
1123 * returned by {@link #getSerialNumberForUser(UserHandle)}.
1124 * @param serialNumber The serial number of the user that is being
1125 * retrieved.
1126 * @return Return the user associated with the serial number, or null
1127 * if there is not one.
1128 * @see #getSerialNumberForUser(UserHandle)
1129 */
1130 public UserHandle getUserForSerialNumber(long serialNumber) {
Fyodor Kupolovef249092015-05-06 13:18:46 -07001131 int ident = getUserHandle((int) serialNumber);
Dianne Hackborn33f9cb82012-10-04 17:15:10 -07001132 return ident >= 0 ? new UserHandle(ident) : null;
1133 }
1134
1135 /**
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001136 * Creates a user with the specified name and options. For non-admin users, default user
1137 * restrictions are going to be applied.
Amith Yamasani195263742012-08-21 15:40:12 -07001138 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001139 *
1140 * @param name the user's name
1141 * @param flags flags that identify the type of user and other properties.
1142 * @see UserInfo
1143 *
1144 * @return the UserInfo object for the created user, or null if the user could not be created.
1145 * @hide
1146 */
1147 public UserInfo createUser(String name, int flags) {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001148 UserInfo user = null;
Amith Yamasani258848d2012-08-10 17:06:33 -07001149 try {
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001150 user = mService.createUser(name, flags);
phweisse9c44062016-02-10 12:57:38 +01001151 // TODO: Keep this in sync with
1152 // UserManagerService.LocalService.createUserEvenWhenDisallowed
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001153 if (user != null && !user.isAdmin()) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001154 mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1155 mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001156 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001157 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001158 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001159 }
Xiaohui Chencfe64c82015-07-16 14:30:50 -07001160 return user;
Amith Yamasani258848d2012-08-10 17:06:33 -07001161 }
1162
1163 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001164 * Creates a guest user and configures it.
1165 * @param context an application context
1166 * @param name the name to set for the user
1167 * @hide
1168 */
1169 public UserInfo createGuest(Context context, String name) {
Makoto Onuki068c54a2015-10-13 14:34:03 -07001170 UserInfo guest = null;
1171 try {
1172 guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1173 if (guest != null) {
1174 Settings.Secure.putStringForUser(context.getContentResolver(),
1175 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001176 }
Makoto Onuki068c54a2015-10-13 14:34:03 -07001177 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001178 throw re.rethrowFromSystemServer();
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001179 }
1180 return guest;
1181 }
1182
Amith Yamasaniaa6634e2014-10-06 14:20:28 -07001183 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001184 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001185 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1186 *
1187 * @param name the user's name
1188 * @param flags flags that identify the type of user and other properties.
1189 * @see UserInfo
Kenny Guy2a764942014-04-02 13:29:20 +01001190 * @param userHandle new user will be a profile of this use.
Kenny Guya52dc3e2014-02-11 15:33:14 +00001191 *
1192 * @return the UserInfo object for the created user, or null if the user could not be created.
1193 * @hide
1194 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001195 public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001196 try {
Kenny Guy2a764942014-04-02 13:29:20 +01001197 return mService.createProfileForUser(name, flags, userHandle);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001198 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001199 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001200 }
1201 }
1202
1203 /**
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001204 * Creates a restricted profile with the specified name. This method also sets necessary
1205 * restrictions and adds shared accounts.
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001206 *
1207 * @param name profile's name
1208 * @return UserInfo object for the created user, or null if the user could not be created.
1209 * @hide
1210 */
1211 public UserInfo createRestrictedProfile(String name) {
1212 try {
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001213 UserHandle parentUserHandle = Process.myUserHandle();
1214 UserInfo user = mService.createRestrictedProfile(name,
1215 parentUserHandle.getIdentifier());
1216 if (user != null) {
1217 AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
1218 UserHandle.of(user.id));
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001219 }
Fyodor Kupolov02cb6e72015-09-18 18:20:55 -07001220 return user;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001221 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001222 throw re.rethrowFromSystemServer();
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001223 }
Fyodor Kupolov06a484a2015-08-21 16:33:20 -07001224 }
1225
1226 /**
Amith Yamasani12747872015-12-07 14:19:49 -08001227 * Returns an intent to create a user for the provided name and email address. The name
1228 * and email address will be used when the setup process for the new user is started.
1229 * If this device does not support multiple users, null is returned.
1230 * <p/>
1231 * The intent should be launched using startActivityForResult and the return result will
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001232 * indicate if the user consented to adding a new user and if the operation succeeded. Any
1233 * errors in creating the user will be returned in the result code. If the user cancels the
1234 * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
1235 * result code will be {@link Activity#RESULT_OK}.
Amith Yamasani12747872015-12-07 14:19:49 -08001236 * <p/>
1237 * The new user is created but not initialized. After switching into the user for the first
1238 * time, the preferred user name and account information are used by the setup process for that
1239 * user.
1240 *
1241 * @param userName Optional name to assign to the user.
1242 * @param accountName Optional email address that will be used by the setup wizard to initialize
1243 * the user.
1244 * @param accountType Optional account type for the account to be created. This is required
1245 * if the account name is specified.
1246 * @param accountOptions Optional bundle of data to be passed in during account creation in the
1247 * new user via {@link AccountManager#addAccount(String, String, String[],
1248 * Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
1249 * Handler)}.
1250 * @return An Intent that can be launched from an Activity or null if creating users is not
1251 * supported on this device.
Amith Yamasani37ed8d12016-01-27 14:40:16 -08001252 * @see #USER_CREATION_FAILED_NOT_PERMITTED
1253 * @see #USER_CREATION_FAILED_NO_MORE_USERS
Amith Yamasani12747872015-12-07 14:19:49 -08001254 */
1255 public static Intent createUserCreationIntent(@Nullable String userName,
1256 @Nullable String accountName,
1257 @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
1258 if (!supportsMultipleUsers() || getMaxSupportedUsers() < 2) {
1259 return null;
1260 }
1261 Intent intent = new Intent(ACTION_CREATE_USER);
1262 if (userName != null) {
1263 intent.putExtra(EXTRA_USER_NAME, userName);
1264 }
1265 if (accountName != null && accountType == null) {
1266 throw new IllegalArgumentException("accountType must be specified if accountName is "
1267 + "specified");
1268 }
1269 if (accountName != null) {
1270 intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
1271 }
1272 if (accountType != null) {
1273 intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
1274 }
1275 if (accountOptions != null) {
1276 intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
1277 }
1278 return intent;
1279 }
1280
1281 /**
1282 * @hide
1283 *
1284 * Returns the preferred account name for user creation. Requires MANAGE_USERS permission.
1285 */
1286 @SystemApi
1287 public String getSeedAccountName() {
1288 try {
1289 return mService.getSeedAccountName();
1290 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001291 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001292 }
1293 }
1294
1295 /**
1296 * @hide
1297 *
1298 * Returns the preferred account type for user creation. Requires MANAGE_USERS permission.
1299 */
1300 @SystemApi
1301 public String getSeedAccountType() {
1302 try {
1303 return mService.getSeedAccountType();
1304 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001305 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001306 }
1307 }
1308
1309 /**
1310 * @hide
1311 *
1312 * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS
1313 * permission.
1314 * @return Any options set by the requestor that created the user.
1315 */
1316 @SystemApi
1317 public PersistableBundle getSeedAccountOptions() {
1318 try {
1319 return mService.getSeedAccountOptions();
1320 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001321 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001322 }
1323 }
1324
1325 /**
1326 * @hide
1327 *
1328 * Called by a system activity to set the seed account information of a user created
1329 * through the user creation intent.
1330 * @param userId
1331 * @param accountName
1332 * @param accountType
1333 * @param accountOptions
1334 * @see #createUserCreationIntent(String, String, String, PersistableBundle)
1335 */
1336 public void setSeedAccountData(int userId, String accountName, String accountType,
1337 PersistableBundle accountOptions) {
1338 try {
1339 mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
1340 /* persist= */ true);
1341 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001342 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001343 }
1344 }
1345
1346 /**
1347 * @hide
1348 * Clears the seed information used to create this user. Requires MANAGE_USERS permission.
1349 */
1350 @SystemApi
1351 public void clearSeedAccountData() {
1352 try {
1353 mService.clearSeedAccountData();
1354 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001355 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001356 }
1357 }
1358
1359 /**
Amith Yamasani1df14732014-08-29 21:37:27 -07001360 * @hide
1361 * Marks the guest user for deletion to allow a new guest to be created before deleting
1362 * the current user who is a guest.
1363 * @param userHandle
1364 * @return
1365 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001366 public boolean markGuestForDeletion(@UserIdInt int userHandle) {
Amith Yamasani1df14732014-08-29 21:37:27 -07001367 try {
1368 return mService.markGuestForDeletion(userHandle);
1369 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001370 throw re.rethrowFromSystemServer();
Amith Yamasani1df14732014-08-29 21:37:27 -07001371 }
1372 }
1373
1374 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001375 * Sets the user as enabled, if such an user exists.
Lenka Trochtova1ddda472016-02-12 10:42:12 +01001376 *
1377 * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1378 *
1379 * <p>Note that the default is true, it's only that managed profiles might not be enabled.
1380 * Also ephemeral users can be disabled to indicate that their removal is in progress and they
1381 * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001382 *
1383 * @param userHandle the id of the profile to enable
1384 * @hide
1385 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001386 public void setUserEnabled(@UserIdInt int userHandle) {
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001387 try {
1388 mService.setUserEnabled(userHandle);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001389 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001390 throw re.rethrowFromSystemServer();
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001391 }
1392 }
1393
1394 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -07001395 * Return the number of users currently created on the device.
1396 */
1397 public int getUserCount() {
1398 List<UserInfo> users = getUsers();
1399 return users != null ? users.size() : 1;
1400 }
1401
1402 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001403 * Returns information for all users on this device.
Amith Yamasani195263742012-08-21 15:40:12 -07001404 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001405 * @return the list of users that exist on the device.
Amith Yamasani258848d2012-08-10 17:06:33 -07001406 * @hide
1407 */
1408 public List<UserInfo> getUsers() {
1409 try {
Amith Yamasani920ace02012-09-20 22:15:37 -07001410 return mService.getUsers(false);
1411 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001412 throw re.rethrowFromSystemServer();
Amith Yamasani920ace02012-09-20 22:15:37 -07001413 }
1414 }
1415
1416 /**
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001417 * Returns serial numbers of all users on this device.
1418 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1419 *
1420 * @param excludeDying specify if the list should exclude users being removed.
1421 * @return the list of serial numbers of users that exist on the device.
1422 * @hide
1423 */
1424 @SystemApi
1425 public long[] getSerialNumbersOfUsers(boolean excludeDying) {
1426 try {
1427 List<UserInfo> users = mService.getUsers(excludeDying);
1428 long[] result = new long[users.size()];
1429 for (int i = 0; i < result.length; i++) {
1430 result[i] = users.get(i).serialNumber;
1431 }
1432 return result;
1433 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001434 throw re.rethrowFromSystemServer();
Fyodor Kupolov940e8572016-01-26 12:03:51 -08001435 }
1436 }
1437
1438 /**
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001439 * @return the user's account name, null if not found.
1440 * @hide
1441 */
1442 @RequiresPermission( allOf = {
1443 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1444 Manifest.permission.MANAGE_USERS
1445 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001446 public @Nullable String getUserAccount(@UserIdInt int userHandle) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001447 try {
1448 return mService.getUserAccount(userHandle);
1449 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001450 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001451 }
1452 }
1453
1454 /**
1455 * Set account name for the given user.
1456 * @hide
1457 */
1458 @RequiresPermission( allOf = {
1459 Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1460 Manifest.permission.MANAGE_USERS
1461 })
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001462 public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001463 try {
1464 mService.setUserAccount(userHandle, accountName);
1465 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001466 throw re.rethrowFromSystemServer();
Xiaohui Chenb3b92582015-12-07 11:22:13 -08001467 }
1468 }
1469
1470 /**
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001471 * Returns information for Primary user.
1472 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1473 *
1474 * @return the Primary user, null if not found.
1475 * @hide
1476 */
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001477 public @Nullable UserInfo getPrimaryUser() {
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001478 try {
1479 return mService.getPrimaryUser();
1480 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001481 throw re.rethrowFromSystemServer();
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001482 }
1483 }
1484
1485 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -07001486 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
1487 * permission.
1488 *
1489 * @return true if more users can be added, false if limit has been reached.
1490 * @hide
1491 */
1492 public boolean canAddMoreUsers() {
1493 final List<UserInfo> users = getUsers(true);
1494 final int totalUserCount = users.size();
1495 int aliveUserCount = 0;
1496 for (int i = 0; i < totalUserCount; i++) {
1497 UserInfo user = users.get(i);
1498 if (!user.isGuest()) {
1499 aliveUserCount++;
1500 }
1501 }
1502 return aliveUserCount < getMaxSupportedUsers();
1503 }
1504
1505 /**
Nicolas Prevot72434b72015-05-13 12:15:03 -07001506 * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
1507 * permission.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00001508 * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
1509 * we could add a new managed profile to this user after removing the existing one.
Nicolas Prevot72434b72015-05-13 12:15:03 -07001510 *
1511 * @return true if more managed profiles can be added, false if limit has been reached.
1512 * @hide
1513 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001514 public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
Nicolas Prevot72434b72015-05-13 12:15:03 -07001515 try {
Nicolas Prevot07387fe2015-10-30 17:53:30 +00001516 return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
Nicolas Prevot72434b72015-05-13 12:15:03 -07001517 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001518 throw re.rethrowFromSystemServer();
Nicolas Prevot72434b72015-05-13 12:15:03 -07001519 }
1520 }
1521
1522 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001523 * Returns list of the profiles of userHandle including
1524 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -07001525 * Note that this returns both enabled and not enabled profiles. See
Ruben Brunk7f75da22015-04-30 17:46:30 -07001526 * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -08001527 *
Kenny Guy2a764942014-04-02 13:29:20 +01001528 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1529 * @param userHandle profiles of this user will be returned.
1530 * @return the list of profiles.
1531 * @hide
1532 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001533 public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +00001534 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001535 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +00001536 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001537 throw re.rethrowFromSystemServer();
Kenny Guya52dc3e2014-02-11 15:33:14 +00001538 }
1539 }
1540
1541 /**
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001542 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1543 * @param userId one of the two user ids to check.
1544 * @param otherUserId one of the two user ids to check.
1545 * @return true if the two user ids are in the same profile group.
1546 * @hide
1547 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001548 public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001549 try {
1550 return mService.isSameProfileGroup(userId, otherUserId);
1551 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001552 throw re.rethrowFromSystemServer();
Xiaohui Chenfd5b7742015-10-14 15:47:04 -07001553 }
1554 }
1555
1556 /**
Ruben Brunk7f75da22015-04-30 17:46:30 -07001557 * Returns list of the profiles of userHandle including
1558 * userHandle itself.
1559 * Note that this returns only enabled.
1560 *
1561 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1562 * @param userHandle profiles of this user will be returned.
1563 * @return the list of profiles.
1564 * @hide
1565 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001566 public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
Ruben Brunk7f75da22015-04-30 17:46:30 -07001567 try {
1568 return mService.getProfiles(userHandle, true /* enabledOnly */);
1569 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001570 throw re.rethrowFromSystemServer();
Ruben Brunk7f75da22015-04-30 17:46:30 -07001571 }
1572 }
1573
1574 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01001575 * Returns a list of UserHandles for profiles associated with the user that the calling process
1576 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -08001577 *
1578 * @return A non-empty list of UserHandles associated with the calling user.
1579 */
1580 public List<UserHandle> getUserProfiles() {
1581 ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
Xiaohui Chen2b45f8a2015-08-04 15:12:23 -07001582 List<UserInfo> users;
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001583 try {
Alexandra Gherghinaf2e7b3f2014-04-30 17:01:03 +00001584 users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001585 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001586 throw re.rethrowFromSystemServer();
Alexandra Gherghina385124d2014-04-03 13:37:39 +01001587 }
Amith Yamasani4f582632014-02-19 14:31:52 -08001588 for (UserInfo info : users) {
1589 UserHandle userHandle = new UserHandle(info.id);
1590 profiles.add(userHandle);
1591 }
1592 return profiles;
1593 }
1594
Amith Yamasani7dda2652014-04-11 14:57:12 -07001595 /**
Andres Moralesc5548c02015-08-05 10:23:12 -07001596 * Returns the device credential owner id of the profile from
1597 * which this method is called, or userHandle if called from a user that
1598 * is not a profile.
1599 *
1600 * @hide
1601 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001602 public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
Andres Moralesc5548c02015-08-05 10:23:12 -07001603 try {
1604 return mService.getCredentialOwnerProfile(userHandle);
1605 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001606 throw re.rethrowFromSystemServer();
Andres Moralesc5548c02015-08-05 10:23:12 -07001607 }
1608 }
1609
1610 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +01001611 * Returns the parent of the profile which this method is called from
1612 * or null if called from a user that is not a profile.
1613 *
1614 * @hide
1615 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001616 public UserInfo getProfileParent(@UserIdInt int userHandle) {
Jessica Hummelbe81c802014-04-22 15:49:22 +01001617 try {
1618 return mService.getProfileParent(userHandle);
1619 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001620 throw re.rethrowFromSystemServer();
Jessica Hummelbe81c802014-04-22 15:49:22 +01001621 }
1622 }
1623
1624 /**
Rubin Xu0a29ecd2015-11-04 15:11:48 +00001625 * Set quiet mode of a managed profile.
1626 *
1627 * @param userHandle The user handle of the profile.
1628 * @param enableQuietMode Whether quiet mode should be enabled or disabled.
1629 * @hide
1630 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001631 public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
Rubin Xu0a29ecd2015-11-04 15:11:48 +00001632 try {
1633 mService.setQuietModeEnabled(userHandle, enableQuietMode);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001634 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001635 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00001636 }
1637 }
1638
1639 /**
1640 * Returns whether the given profile is in quiet mode or not.
1641 *
1642 * @param userHandle The user handle of the profile to be queried.
1643 * @return true if the profile is in quiet mode, false otherwise.
1644 */
1645 public boolean isQuietModeEnabled(UserHandle userHandle) {
1646 try {
1647 return mService.isQuietModeEnabled(userHandle.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001648 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001649 throw re.rethrowFromSystemServer();
Rubin Xu0a29ecd2015-11-04 15:11:48 +00001650 }
Rubin Xu0a29ecd2015-11-04 15:11:48 +00001651 }
1652
1653 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -07001654 * If the target user is a managed profile of the calling user or the caller
1655 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -07001656 * icon to be able to distinguish it from the original icon. For badging an
1657 * arbitrary drawable use {@link #getBadgedDrawableForUser(
1658 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1659 * <p>
1660 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001661 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07001662 * is performed in place and the original drawable is returned.
1663 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -07001664 *
1665 * @param icon The icon to badge.
1666 * @param user The target user.
1667 * @return A drawable that combines the original icon and a badge as
1668 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07001669 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -07001670 */
Svetoslavc71c42f2014-08-05 18:57:05 -07001671 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001672 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08001673 }
1674
Kenny Guy701ea7c2014-05-08 23:34:12 +01001675 /**
1676 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -07001677 * is itself a managed profile, then this returns a badged copy of the given
1678 * drawable allowing the user to distinguish it from the original drawable.
1679 * The caller can specify the location in the bounds of the drawable to be
1680 * badged where the badge should be applied as well as the density of the
1681 * badge to be used.
1682 * <p>
1683 * If the original drawable is a BitmapDrawable and the backing bitmap is
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001684 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
Svetoslavc71c42f2014-08-05 18:57:05 -07001685 * is performed in place and the original drawable is returned.
1686 * </p>
1687 *
1688 * @param badgedDrawable The drawable to badge.
1689 * @param user The target user.
1690 * @param badgeLocation Where in the bounds of the badged drawable to place
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001691 * the badge. If it's {@code null}, the badge is applied on top of the entire
Svetoslavc71c42f2014-08-05 18:57:05 -07001692 * drawable being badged.
1693 * @param badgeDensity The optional desired density for the badge as per
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001694 * {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
Svetoslavc71c42f2014-08-05 18:57:05 -07001695 * the density of the display is used.
1696 * @return A drawable that combines the original drawable and a badge as
1697 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07001698 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07001699 */
1700 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1701 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001702 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1703 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07001704 }
1705
1706 /**
1707 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01001708 * is itself a managed profile, then this returns a copy of the label with
1709 * badging for accessibility services like talkback. E.g. passing in "Email"
1710 * and it might return "Work Email" for Email in the work profile.
1711 *
1712 * @param label The label to change.
1713 * @param user The target user.
1714 * @return A label that combines the original label and a badge as
1715 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07001716 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01001717 */
Kenny Guy237aecd2014-07-21 14:06:09 +01001718 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001719 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08001720 }
1721
1722 /**
1723 * Returns information for all users on this device. Requires
1724 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04001725 *
Amith Yamasani4f582632014-02-19 14:31:52 -08001726 * @param excludeDying specify if the list should exclude users being
1727 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07001728 * @return the list of users that were created.
1729 * @hide
1730 */
1731 public List<UserInfo> getUsers(boolean excludeDying) {
1732 try {
1733 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07001734 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001735 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001736 }
1737 }
1738
1739 /**
1740 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07001741 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001742 * @param userHandle the integer handle of the user, where 0 is the primary user.
1743 * @hide
1744 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001745 public boolean removeUser(@UserIdInt int userHandle) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001746 try {
1747 return mService.removeUser(userHandle);
1748 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001749 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001750 }
1751 }
1752
1753 /**
1754 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07001755 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001756 *
1757 * @param userHandle the user's integer handle
1758 * @param name the new name for the user
1759 * @hide
1760 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001761 public void setUserName(@UserIdInt int userHandle, String name) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001762 try {
1763 mService.setUserName(userHandle, name);
1764 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001765 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001766 }
1767 }
1768
1769 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001770 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07001771 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001772 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07001773 * @hide
1774 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001775 public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001776 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001777 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07001778 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001779 throw re.rethrowFromSystemServer();
Amith Yamasani258848d2012-08-10 17:06:33 -07001780 }
1781 }
1782
1783 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07001784 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
1785 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001786 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01001787 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07001788 * @hide
1789 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001790 public Bitmap getUserIcon(@UserIdInt int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07001791 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01001792 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
1793 if (fd != null) {
1794 try {
1795 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
1796 } finally {
1797 try {
1798 fd.close();
1799 } catch (IOException e) {
1800 }
1801 }
1802 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07001803 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001804 throw re.rethrowFromSystemServer();
Amith Yamasani3b49f072012-09-17 10:21:43 -07001805 }
Adrian Roos1bdff912015-02-17 15:51:35 +01001806 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07001807 }
1808
1809 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001810 * Returns the maximum number of users that can be created on this device. A return value
1811 * of 1 means that it is a single user device.
1812 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001813 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07001814 */
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07001815 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07001816 // Don't allow multiple users on certain builds
1817 if (android.os.Build.ID.startsWith("JVP")) return 1;
Dianne Hackborn409297d2014-07-10 17:39:20 -07001818 // Svelte devices don't get multi-user.
1819 if (ActivityManager.isLowRamDeviceStatic()) return 1;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07001820 return SystemProperties.getInt("fw.max_users",
1821 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07001822 }
Amith Yamasani2a003292012-08-14 18:25:45 -07001823
1824 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001825 * Returns true if the user switcher should be shown, this will be if device supports multi-user
1826 * and there are at least 2 users available that are not managed profiles.
Kenny Guy1a447532014-02-20 21:55:32 +00001827 * @hide
1828 * @return true if user switcher should be shown.
1829 */
1830 public boolean isUserSwitcherEnabled() {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001831 if (!supportsMultipleUsers()) {
1832 return false;
1833 }
Kenny Guy1a447532014-02-20 21:55:32 +00001834 List<UserInfo> users = getUsers(true);
1835 if (users == null) {
1836 return false;
1837 }
1838 int switchableUserCount = 0;
1839 for (UserInfo user : users) {
Xiaohui Chen7cb69df2015-07-13 16:01:01 -07001840 if (user.supportsSwitchToByUser()) {
Kenny Guy1a447532014-02-20 21:55:32 +00001841 ++switchableUserCount;
1842 }
1843 }
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001844 final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
1845 .getGuestUserDisabled(null);
Amith Yamasania596ff82014-06-12 18:12:38 -07001846 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00001847 }
1848
1849 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07001850 * Returns a serial number on this device for a given userHandle. User handles can be recycled
1851 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
1852 * @param userHandle
1853 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
1854 * @hide
1855 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001856 public int getUserSerialNumber(@UserIdInt int userHandle) {
Amith Yamasani2a003292012-08-14 18:25:45 -07001857 try {
1858 return mService.getUserSerialNumber(userHandle);
1859 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001860 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07001861 }
Amith Yamasani2a003292012-08-14 18:25:45 -07001862 }
1863
1864 /**
1865 * Returns a userHandle on this device for a given user serial number. User handles can be
1866 * recycled when deleting and creating users, but serial numbers are not reused until the device
1867 * is wiped.
1868 * @param userSerialNumber
1869 * @return the userHandle associated with that user serial number, or -1 if the serial number
1870 * is not valid.
1871 * @hide
1872 */
Jeff Sharkey8588bc12016-01-06 16:47:42 -07001873 public @UserIdInt int getUserHandle(int userSerialNumber) {
Amith Yamasani2a003292012-08-14 18:25:45 -07001874 try {
1875 return mService.getUserHandle(userSerialNumber);
1876 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001877 throw re.rethrowFromSystemServer();
Amith Yamasani2a003292012-08-14 18:25:45 -07001878 }
Amith Yamasani2a003292012-08-14 18:25:45 -07001879 }
Maggie Benthall67944582013-02-22 14:58:27 -05001880
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001881 /**
Esteban Talavera5b9f1672015-12-11 15:22:34 +00001882 * Returns a {@code Bundle} containing any saved application restrictions for this user, for the
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001883 * given package name. Only an application with this package name can call this method.
Esteban Talavera5b9f1672015-12-11 15:22:34 +00001884 *
1885 * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
1886 * where the types of values may be:
1887 * <ul>
1888 * <li>{@code boolean}
1889 * <li>{@code int}
1890 * <li>{@code String} or {@code String[]}
1891 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
1892 * </ul>
1893 *
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001894 * @param packageName the package name of the calling application
Esteban Talavera5b9f1672015-12-11 15:22:34 +00001895 * @return a {@code Bundle} with the restrictions for that package, or {@code null} if there
1896 * are no saved restrictions.
1897 *
1898 * @see #KEY_RESTRICTIONS_PENDING
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001899 */
1900 public Bundle getApplicationRestrictions(String packageName) {
1901 try {
1902 return mService.getApplicationRestrictions(packageName);
1903 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001904 throw re.rethrowFromSystemServer();
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001905 }
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001906 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001907
1908 /**
1909 * @hide
1910 */
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001911 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001912 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001913 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001914 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001915 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001916 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001917 }
1918
1919 /**
1920 * @hide
1921 */
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001922 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001923 UserHandle user) {
1924 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001925 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001926 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001927 throw re.rethrowFromSystemServer();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001928 }
1929 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07001930
1931 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07001932 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1933 * apps and requires the MANAGE_USERS permission.
1934 * @param newPin the PIN to use for challenge dialogs.
1935 * @return Returns true if the challenge PIN was set successfully.
Fyodor Kupolovef249092015-05-06 13:18:46 -07001936 * @deprecated The restrictions PIN functionality is no longer provided by the system.
1937 * This method is preserved for backwards compatibility reasons and always returns false.
Amith Yamasani655d0e22013-06-12 14:19:10 -07001938 */
Amith Yamasanid304af62013-09-05 09:30:23 -07001939 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001940 return false;
1941 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07001942
Amith Yamasanie4afaa32014-06-30 14:55:07 +05301943 /**
1944 * @hide
1945 * Set restrictions that should apply to any future guest user that's created.
1946 */
1947 public void setDefaultGuestRestrictions(Bundle restrictions) {
1948 try {
1949 mService.setDefaultGuestRestrictions(restrictions);
1950 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001951 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05301952 }
1953 }
1954
1955 /**
1956 * @hide
1957 * Gets the default guest restrictions.
1958 */
1959 public Bundle getDefaultGuestRestrictions() {
1960 try {
1961 return mService.getDefaultGuestRestrictions();
1962 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001963 throw re.rethrowFromSystemServer();
Amith Yamasanie4afaa32014-06-30 14:55:07 +05301964 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05301965 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001966
1967 /**
1968 * Returns creation time of the user or of a managed profile associated with the calling user.
1969 * @param userHandle user handle of the user or a managed profile associated with the
1970 * calling user.
1971 * @return creation time in milliseconds since Epoch time.
1972 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07001973 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001974 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07001975 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001976 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001977 throw re.rethrowFromSystemServer();
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001978 }
1979 }
Amith Yamasani12747872015-12-07 14:19:49 -08001980
1981 /**
1982 * @hide
1983 * Checks if any uninitialized user has the specific seed account name and type.
1984 *
1985 * @param mAccountName The account name to check for
1986 * @param mAccountType The account type of the account to check for
1987 * @return whether the seed account was found
1988 */
1989 public boolean someUserHasSeedAccount(String accountName, String accountType) {
1990 try {
1991 return mService.someUserHasSeedAccount(accountName, accountType);
1992 } catch (RemoteException re) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001993 throw re.rethrowFromSystemServer();
Amith Yamasani12747872015-12-07 14:19:49 -08001994 }
1995 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001996}