blob: b9e307fa24f92709f426d128fa8bfc7cfc9ff8e4 [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
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070018import android.annotation.SystemApi;
Dianne Hackborn409297d2014-07-10 17:39:20 -070019import android.app.ActivityManager;
Dianne Hackborna8a9bd62012-10-09 15:36:59 -070020import android.app.ActivityManagerNative;
Amith Yamasani258848d2012-08-10 17:06:33 -070021import android.content.Context;
22import android.content.pm.UserInfo;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -070023import android.content.res.Resources;
Maggie Benthall67944582013-02-22 14:58:27 -050024import android.graphics.Bitmap;
Adrian Roos1bdff912015-02-17 15:51:35 +010025import android.graphics.BitmapFactory;
Amith Yamasani4f582632014-02-19 14:31:52 -080026import android.graphics.Rect;
Amith Yamasani4f582632014-02-19 14:31:52 -080027import android.graphics.drawable.Drawable;
Amith Yamasani1e9c2182014-06-11 17:25:51 -070028import android.provider.Settings;
Amith Yamasani258848d2012-08-10 17:06:33 -070029import android.util.Log;
Jason Monk1c7c3192014-06-26 12:52:18 -040030import android.view.WindowManager.LayoutParams;
Amith Yamasani258848d2012-08-10 17:06:33 -070031
Maggie Benthall67944582013-02-22 14:58:27 -050032import com.android.internal.R;
33
Adrian Roos1bdff912015-02-17 15:51:35 +010034import java.io.IOException;
Amith Yamasani4f582632014-02-19 14:31:52 -080035import java.util.ArrayList;
Amith Yamasani258848d2012-08-10 17:06:33 -070036import java.util.List;
37
38/**
39 * Manages users and user details on a multi-user system.
40 */
41public class UserManager {
42
43 private static String TAG = "UserManager";
44 private final IUserManager mService;
45 private final Context mContext;
46
Amith Yamasanie4cf7342012-12-17 11:12:09 -080047 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070048 * Specifies if a user is disallowed from adding and removing accounts.
Amith Yamasani71e6c692013-03-24 17:39:28 -070049 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -070050 *
51 * <p/>Key for user restrictions.
52 * <p/>Type: Boolean
Amith Yamasanie4cf7342012-12-17 11:12:09 -080053 * @see #setUserRestrictions(Bundle)
54 * @see #getUserRestrictions()
55 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070056 public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080057
58 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070059 * Specifies if a user is disallowed from changing Wi-Fi
Julia Reynolds2cb384f2014-08-13 15:15:55 -040060 * access points. The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -080061 * <p/>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -070062 *
63 * <p/>Key for user restrictions.
64 * <p/>Type: Boolean
Amith Yamasanie4cf7342012-12-17 11:12:09 -080065 * @see #setUserRestrictions(Bundle)
66 * @see #getUserRestrictions()
67 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070068 public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080069
70 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070071 * Specifies if a user is disallowed from installing applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -070072 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -070073 *
74 * <p/>Key for user restrictions.
75 * <p/>Type: Boolean
Amith Yamasanie4cf7342012-12-17 11:12:09 -080076 * @see #setUserRestrictions(Bundle)
77 * @see #getUserRestrictions()
78 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070079 public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080080
81 /**
Amith Yamasani26af8292014-09-09 09:57:27 -070082 * Specifies if a user is disallowed from uninstalling applications.
Amith Yamasani71e6c692013-03-24 17:39:28 -070083 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -070084 *
85 * <p/>Key for user restrictions.
86 * <p/>Type: Boolean
Amith Yamasanie4cf7342012-12-17 11:12:09 -080087 * @see #setUserRestrictions(Bundle)
88 * @see #getUserRestrictions()
89 */
Amith Yamasani71e6c692013-03-24 17:39:28 -070090 public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
Amith Yamasanie4cf7342012-12-17 11:12:09 -080091
Amith Yamasani71e6c692013-03-24 17:39:28 -070092 /**
Amith Yamasani150514b2015-01-07 16:05:05 -080093 * Specifies if a user is disallowed from turning on location sharing.
Amith Yamasani71e6c692013-03-24 17:39:28 -070094 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -080095 * <p/>In a managed profile, location sharing always reflects the primary user's setting, but
96 * can be overridden and forced off by setting this restriction to true in the managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -070097 *
98 * <p/>Key for user restrictions.
99 * <p/>Type: Boolean
Maggie Benthall67944582013-02-22 14:58:27 -0500100 * @see #setUserRestrictions(Bundle)
101 * @see #getUserRestrictions()
102 */
Amith Yamasani71e6c692013-03-24 17:39:28 -0700103 public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
Maggie Benthall67944582013-02-22 14:58:27 -0500104
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400105 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700106 * Specifies if a user is disallowed from enabling the
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400107 * "Unknown Sources" setting, that allows installation of apps from unknown sources.
108 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700109 *
110 * <p/>Key for user restrictions.
111 * <p/>Type: Boolean
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400112 * @see #setUserRestrictions(Bundle)
113 * @see #getUserRestrictions()
114 */
115 public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
116
117 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700118 * Specifies if a user is disallowed from configuring bluetooth.
Nicolas Prevot1c4c4422015-02-16 11:32:21 +0000119 * This does <em>not</em> restrict the user from turning bluetooth on or off.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400120 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800121 * <p/>This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700122 *
123 * <p/>Key for user restrictions.
124 * <p/>Type: Boolean
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400125 * @see #setUserRestrictions(Bundle)
126 * @see #getUserRestrictions()
127 */
128 public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
129
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400130 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700131 * Specifies if a user is disallowed from transferring files over
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700132 * USB. This can only be set by device owners and profile owners on the primary user.
133 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700134 *
135 * <p/>Key for user restrictions.
136 * <p/>Type: Boolean
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400137 * @see #setUserRestrictions(Bundle)
138 * @see #getUserRestrictions()
139 */
140 public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
141
Emily Bernierb223f732013-04-11 15:46:36 -0400142 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700143 * Specifies if a user is disallowed from configuring user
Emily Bernierb223f732013-04-11 15:46:36 -0400144 * credentials. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700145 *
146 * <p/>Key for user restrictions.
147 * <p/>Type: Boolean
Emily Bernierb223f732013-04-11 15:46:36 -0400148 * @see #setUserRestrictions(Bundle)
149 * @see #getUserRestrictions()
150 */
151 public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
152
153 /**
Amith Yamasani150514b2015-01-07 16:05:05 -0800154 * When set on the primary user this specifies if the user can remove other users.
155 * When set on a secondary user, this specifies if the user can remove itself.
156 * This restriction has no effect on managed profiles.
157 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700158 *
159 * <p/>Key for user restrictions.
160 * <p/>Type: Boolean
Emily Bernierb223f732013-04-11 15:46:36 -0400161 * @see #setUserRestrictions(Bundle)
162 * @see #getUserRestrictions()
163 */
164 public static final String DISALLOW_REMOVE_USER = "no_remove_user";
165
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400166 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700167 * Specifies if a user is disallowed from enabling or
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400168 * accessing debugging features. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700169 *
170 * <p/>Key for user restrictions.
171 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400172 * @see #setUserRestrictions(Bundle)
173 * @see #getUserRestrictions()
174 */
175 public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
176
177 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700178 * Specifies if a user is disallowed from configuring VPN.
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400179 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800180 * This restriction has no effect in a managed profile.
Amith Yamasani26af8292014-09-09 09:57:27 -0700181 *
182 * <p/>Key for user restrictions.
183 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400184 * @see #setUserRestrictions(Bundle)
185 * @see #getUserRestrictions()
186 */
187 public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
188
189 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700190 * Specifies if a user is disallowed from configuring Tethering
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700191 * & portable hotspots. This can only be set by device owners and profile owners on the
192 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700193 *
194 * <p/>Key for user restrictions.
195 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400196 * @see #setUserRestrictions(Bundle)
197 * @see #getUserRestrictions()
198 */
199 public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
200
201 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700202 * Specifies if a user is disallowed from factory resetting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700203 * from Settings. This can only be set by device owners and profile owners on the primary user.
204 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800205 * <p/>This restriction has no effect on secondary users and managed profiles since only the
206 * primary user can factory reset the device.
Amith Yamasani26af8292014-09-09 09:57:27 -0700207 *
208 * <p/>Key for user restrictions.
209 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400210 * @see #setUserRestrictions(Bundle)
211 * @see #getUserRestrictions()
212 */
213 public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
214
215 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700216 * Specifies if a user is disallowed from adding new users and
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700217 * profiles. This can only be set by device owners and profile owners on the primary user.
218 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800219 * <p/>This restriction has no effect on secondary users and managed profiles since only the
220 * primary user can add other users.
Amith Yamasani26af8292014-09-09 09:57:27 -0700221 *
222 * <p/>Key for user restrictions.
223 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400224 * @see #setUserRestrictions(Bundle)
225 * @see #getUserRestrictions()
226 */
227 public static final String DISALLOW_ADD_USER = "no_add_user";
228
229 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700230 * Specifies if a user is disallowed from disabling application
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400231 * verification. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700232 *
233 * <p/>Key for user restrictions.
234 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400235 * @see #setUserRestrictions(Bundle)
236 * @see #getUserRestrictions()
237 */
238 public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
239
240 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700241 * Specifies if a user is disallowed from configuring cell
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700242 * broadcasts. This can only be set by device owners and profile owners on the primary user.
243 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800244 * <p/>This restriction has no effect on secondary users and managed profiles since only the
245 * primary user can configure cell broadcasts.
Amith Yamasani26af8292014-09-09 09:57:27 -0700246 *
247 * <p/>Key for user restrictions.
248 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400249 * @see #setUserRestrictions(Bundle)
250 * @see #getUserRestrictions()
251 */
252 public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
253
254 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700255 * Specifies if a user is disallowed from configuring mobile
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700256 * networks. This can only be set by device owners and profile owners on the primary user.
257 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800258 * <p/>This restriction has no effect on secondary users and managed profiles since only the
259 * primary user can configure mobile networks.
Amith Yamasani26af8292014-09-09 09:57:27 -0700260 *
261 * <p/>Key for user restrictions.
262 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400263 * @see #setUserRestrictions(Bundle)
264 * @see #getUserRestrictions()
265 */
266 public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
267
268 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700269 * Specifies if a user is disallowed from modifying
Julia Reynoldsc617f812014-07-25 16:32:27 -0400270 * applications in Settings or launchers. The following actions will not be allowed when this
271 * restriction is enabled:
272 * <li>uninstalling apps</li>
273 * <li>disabling apps</li>
274 * <li>clearing app caches</li>
275 * <li>clearing app data</li>
276 * <li>force stopping apps</li>
277 * <li>clearing app defaults</li>
278 * <p>
279 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700280 *
281 * <p/>Key for user restrictions.
282 * <p/>Type: Boolean
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400283 * @see #setUserRestrictions(Bundle)
284 * @see #getUserRestrictions()
285 */
Julia Reynolds36fbc8d2014-06-18 09:26:30 -0400286 public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
Julia Reynoldsd46d0f92014-04-23 15:23:24 -0400287
Emily Bernier394a6cd2014-05-07 12:49:20 -0400288 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700289 * Specifies if a user is disallowed from mounting
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700290 * physical external media. This can only be set by device owners and profile owners on the
291 * primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700292 *
293 * <p/>Key for user restrictions.
294 * <p/>Type: Boolean
Emily Bernier394a6cd2014-05-07 12:49:20 -0400295 * @see #setUserRestrictions(Bundle)
296 * @see #getUserRestrictions()
297 */
298 public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
299
300 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700301 * Specifies if a user is disallowed from adjusting microphone
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700302 * volume. If set, the microphone will be muted. This can only be set by device owners
303 * and profile owners on the primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700304 *
305 * <p/>Key for user restrictions.
306 * <p/>Type: Boolean
Emily Bernier394a6cd2014-05-07 12:49:20 -0400307 * @see #setUserRestrictions(Bundle)
308 * @see #getUserRestrictions()
309 */
310 public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
311
312 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700313 * Specifies if a user is disallowed from adjusting the master
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700314 * volume. If set, the master volume will be muted. This can only be set by device owners
315 * and profile owners on the primary user. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700316 *
317 * <p/>Key for user restrictions.
318 * <p/>Type: Boolean
Emily Bernier394a6cd2014-05-07 12:49:20 -0400319 * @see #setUserRestrictions(Bundle)
320 * @see #getUserRestrictions()
321 */
322 public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
323
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700324 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700325 * Specifies that the user is not allowed to make outgoing
Amith Yamasani390989d2014-07-17 10:52:03 -0700326 * phone calls. Emergency calls are still permitted.
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700327 * The default value is <code>false</code>.
Amith Yamasani150514b2015-01-07 16:05:05 -0800328 * <p/>This restriction has no effect on managed profiles since call intents are normally
329 * forwarded to the primary user.
Amith Yamasani26af8292014-09-09 09:57:27 -0700330 *
331 * <p/>Key for user restrictions.
332 * <p/>Type: Boolean
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700333 * @see #setUserRestrictions(Bundle)
334 * @see #getUserRestrictions()
335 */
Amith Yamasani390989d2014-07-17 10:52:03 -0700336 public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
337
338 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700339 * Specifies that the user is not allowed to send or receive
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700340 * SMS messages. The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700341 *
342 * <p/>Key for user restrictions.
343 * <p/>Type: Boolean
Amith Yamasani390989d2014-07-17 10:52:03 -0700344 * @see #setUserRestrictions(Bundle)
345 * @see #getUserRestrictions()
346 */
347 public static final String DISALLOW_SMS = "no_sms";
Amith Yamasani9f6c25f2014-05-16 14:49:15 -0700348
Jason Monk1c7c3192014-06-26 12:52:18 -0400349 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700350 * Specifies that windows besides app windows should not be
Jason Monk1c7c3192014-06-26 12:52:18 -0400351 * created. This will block the creation of the following types of windows.
352 * <li>{@link LayoutParams#TYPE_TOAST}</li>
353 * <li>{@link LayoutParams#TYPE_PHONE}</li>
354 * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
355 * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
356 * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
357 * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
358 *
Amith Yamasanic34dc7c2014-09-18 09:42:42 -0700359 * <p>This can only be set by device owners and profile owners on the primary user.
360 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700361 *
362 * <p/>Key for user restrictions.
363 * <p/>Type: Boolean
Jason Monk1c7c3192014-06-26 12:52:18 -0400364 * @see #setUserRestrictions(Bundle)
365 * @see #getUserRestrictions()
366 */
367 public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
368
Nicolas Prevotf1939902014-06-25 09:29:02 +0100369 /**
Amith Yamasani26af8292014-09-09 09:57:27 -0700370 * Specifies if what is copied in the clipboard of this profile can
Nicolas Prevotf1939902014-06-25 09:29:02 +0100371 * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
372 * pasted in this profile.
373 * The default value is <code>false</code>.
Amith Yamasani26af8292014-09-09 09:57:27 -0700374 *
375 * <p/>Key for user restrictions.
376 * <p/>Type: Boolean
Nicolas Prevotf1939902014-06-25 09:29:02 +0100377 * @see #setUserRestrictions(Bundle)
378 * @see #getUserRestrictions()
379 */
380 public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
381
Amith Yamasani26af8292014-09-09 09:57:27 -0700382 /**
383 * Specifies if the user is not allowed to use NFC to beam out data from apps.
384 * The default value is <code>false</code>.
385 *
386 * <p/>Key for user restrictions.
387 * <p/>Type: Boolean
388 * @see #setUserRestrictions(Bundle)
389 * @see #getUserRestrictions()
390 */
391 public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
392
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000393 /**
Benjamin Franzf3ece362015-02-11 10:51:10 +0000394 * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
395 * is always set for managed profiles.
396 * @hide
397 * @see #setUserRestrictions(Bundle)
398 * @see #getUserRestrictions()
399 */
400 public static final String DISALLOW_WALLPAPER = "no_wallpaper";
401
402 /**
Benjamin Franzbff46ba2015-03-05 18:33:51 +0000403 * Specifies if the user is not allowed to reboot the device into safe boot mode.
404 * This can only be set by device owners and profile owners on the primary user.
405 * The default value is <code>false</code>.
406 *
407 * <p/>Key for user restrictions.
408 * <p/>Type: Boolean
409 * @see #setUserRestrictions(Bundle)
410 * @see #getUserRestrictions()
411 */
412 public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
413
414 /**
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000415 * Application restriction key that is used to indicate the pending arrival
416 * of real restrictions for the app.
417 *
418 * <p>
419 * Applications that support restrictions should check for the presence of this key.
420 * A <code>true</code> value indicates that restrictions may be applied in the near
421 * future but are not available yet. It is the responsibility of any
422 * management application that sets this flag to update it when the final
423 * restrictions are enforced.
424 *
425 * <p/>Key for application restrictions.
426 * <p/>Type: Boolean
Nicolas Prevotb14ed952015-01-13 14:23:53 +0000427 * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
428 * android.content.ComponentName, String, Bundle)
429 * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
430 * android.content.ComponentName, String)
Sander Alewijnse53d63dc2014-11-07 21:43:00 +0000431 */
432 public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
433
Amith Yamasani655d0e22013-06-12 14:19:10 -0700434 /** @hide */
435 public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
436 /** @hide */
437 public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
438 /** @hide */
439 public static final int PIN_VERIFICATION_SUCCESS = -1;
440
Amith Yamasani27db4682013-03-30 17:07:47 -0700441 private static UserManager sInstance = null;
442
Amith Yamasani7e99bc02013-04-16 18:24:51 -0700443 /** @hide */
Amith Yamasani27db4682013-03-30 17:07:47 -0700444 public synchronized static UserManager get(Context context) {
445 if (sInstance == null) {
446 sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
447 }
448 return sInstance;
449 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400450
Amith Yamasani258848d2012-08-10 17:06:33 -0700451 /** @hide */
452 public UserManager(Context context, IUserManager service) {
453 mService = service;
454 mContext = context;
455 }
456
457 /**
458 * Returns whether the system supports multiple users.
Kenny Guy1a447532014-02-20 21:55:32 +0000459 * @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 -0700460 * @hide
Amith Yamasani258848d2012-08-10 17:06:33 -0700461 */
Jeff Sharkey4673e7e2012-09-19 13:14:30 -0700462 public static boolean supportsMultipleUsers() {
Kenny Guy1a447532014-02-20 21:55:32 +0000463 return getMaxSupportedUsers() > 1
464 && SystemProperties.getBoolean("fw.show_multiuserui",
465 Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
Amith Yamasani258848d2012-08-10 17:06:33 -0700466 }
467
Maggie Benthall67944582013-02-22 14:58:27 -0500468 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +0100469 * Returns the user handle for the user that the calling process is running on.
470 *
Amith Yamasani258848d2012-08-10 17:06:33 -0700471 * @return the user handle of the user making this call.
472 * @hide
Maggie Benthall67944582013-02-22 14:58:27 -0500473 */
Amith Yamasani258848d2012-08-10 17:06:33 -0700474 public int getUserHandle() {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700475 return UserHandle.myUserId();
Amith Yamasani258848d2012-08-10 17:06:33 -0700476 }
477
478 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700479 * Returns the user name of the user making this call. This call is only
480 * available to applications on the system image; it requires the
481 * MANAGE_USERS permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700482 * @return the user name
483 */
484 public String getUserName() {
485 try {
486 return mService.getUserInfo(getUserHandle()).name;
487 } catch (RemoteException re) {
488 Log.w(TAG, "Could not get user name", re);
489 return "";
490 }
491 }
492
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700493 /**
Dan Morrille4ab16a2012-09-20 20:25:55 -0700494 * Used to determine whether the user making this call is subject to
495 * teleportations.
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700496 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700497 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
Dianne Hackborn67a101a2014-10-02 12:42:18 -0700498 * now automatically identify goats using advanced goat recognition technology.</p>
499 *
500 * @return Returns true if the user making this call is a goat.
Dan Morrille4ab16a2012-09-20 20:25:55 -0700501 */
502 public boolean isUserAGoat() {
Adam Powell988ae302014-09-17 17:58:33 -0700503 return mContext.getPackageManager()
504 .isPackageAvailable("com.coffeestainstudios.goatsimulator");
Dan Morrille4ab16a2012-09-20 20:25:55 -0700505 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800506
507 /**
Amith Yamasanie1375902013-04-13 16:48:35 -0700508 * 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 -0700509 * a reduced number of available apps, app restrictions and account restrictions.
Amith Yamasanie1375902013-04-13 16:48:35 -0700510 * @return whether the user making this call is a linked user
Amith Yamasani2555daf2013-04-25 13:39:27 -0700511 * @hide
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800512 */
Amith Yamasanie1375902013-04-13 16:48:35 -0700513 public boolean isLinkedUser() {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800514 try {
Amith Yamasani71e6c692013-03-24 17:39:28 -0700515 return mService.isRestricted();
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800516 } catch (RemoteException re) {
Amith Yamasani46bc4eb2013-04-12 13:26:50 -0700517 Log.w(TAG, "Could not check if user is limited ", re);
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800518 return false;
519 }
520 }
521
Amith Yamasani258848d2012-08-10 17:06:33 -0700522 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -0700523 * Checks if the calling app is running as a guest user.
524 * @return whether the caller is a guest user.
525 * @hide
526 */
527 public boolean isGuestUser() {
528 UserInfo user = getUserInfo(UserHandle.myUserId());
529 return user != null ? user.isGuest() : false;
530 }
531
532 /**
Amith Yamasani0e8d7d62014-09-03 13:17:28 -0700533 * Checks if the calling app is running in a managed profile.
534 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
535 *
536 * @return whether the caller is in a managed profile.
537 * @hide
538 */
539 @SystemApi
540 public boolean isManagedProfile() {
541 UserInfo user = getUserInfo(UserHandle.myUserId());
542 return user != null ? user.isManagedProfile() : false;
543 }
544
545 /**
Dianne Hackborna8a9bd62012-10-09 15:36:59 -0700546 * Return whether the given user is actively running. This means that
547 * the user is in the "started" state, not "stopped" -- it is currently
548 * allowed to run code through scheduled alarms, receiving broadcasts,
549 * etc. A started user may be either the current foreground user or a
550 * background user; the result here does not distinguish between the two.
551 * @param user The user to retrieve the running state for.
552 */
553 public boolean isUserRunning(UserHandle user) {
554 try {
555 return ActivityManagerNative.getDefault().isUserRunning(
556 user.getIdentifier(), false);
557 } catch (RemoteException e) {
558 return false;
559 }
560 }
561
562 /**
563 * Return whether the given user is actively running <em>or</em> stopping.
564 * This is like {@link #isUserRunning(UserHandle)}, but will also return
565 * true if the user had been running but is in the process of being stopped
566 * (but is not yet fully stopped, and still running some code).
567 * @param user The user to retrieve the running state for.
568 */
569 public boolean isUserRunningOrStopping(UserHandle user) {
570 try {
571 return ActivityManagerNative.getDefault().isUserRunning(
572 user.getIdentifier(), true);
573 } catch (RemoteException e) {
574 return false;
575 }
576 }
577
578 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700579 * Returns the UserInfo object describing a specific user.
Amith Yamasani195263742012-08-21 15:40:12 -0700580 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700581 * @param userHandle the user handle of the user whose information is being requested.
582 * @return the UserInfo object for a specific user.
583 * @hide
Dianne Hackbornb26306a2012-10-24 15:22:21 -0700584 */
Amith Yamasani258848d2012-08-10 17:06:33 -0700585 public UserInfo getUserInfo(int userHandle) {
586 try {
587 return mService.getUserInfo(userHandle);
588 } catch (RemoteException re) {
589 Log.w(TAG, "Could not get user info", re);
590 return null;
591 }
592 }
593
Amith Yamasani71e6c692013-03-24 17:39:28 -0700594 /**
595 * Returns the user-wide restrictions imposed on this user.
596 * @return a Bundle containing all the restrictions.
597 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800598 public Bundle getUserRestrictions() {
599 return getUserRestrictions(Process.myUserHandle());
600 }
601
Amith Yamasani71e6c692013-03-24 17:39:28 -0700602 /**
603 * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
604 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
605 * @return a Bundle containing all the restrictions.
606 */
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800607 public Bundle getUserRestrictions(UserHandle userHandle) {
608 try {
609 return mService.getUserRestrictions(userHandle.getIdentifier());
610 } catch (RemoteException re) {
611 Log.w(TAG, "Could not get user restrictions", re);
612 return Bundle.EMPTY;
613 }
614 }
615
Amith Yamasani71e6c692013-03-24 17:39:28 -0700616 /**
617 * Sets all the user-wide restrictions for this user.
Amith Yamasanibe465322014-04-24 13:45:17 -0700618 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700619 * @param restrictions the Bundle containing all the restrictions.
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400620 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
621 * android.content.ComponentName, String)} or
622 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
623 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700624 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400625 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800626 public void setUserRestrictions(Bundle restrictions) {
627 setUserRestrictions(restrictions, Process.myUserHandle());
628 }
629
Amith Yamasani71e6c692013-03-24 17:39:28 -0700630 /**
631 * Sets all the user-wide restrictions for the specified user.
Amith Yamasanibe465322014-04-24 13:45:17 -0700632 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700633 * @param restrictions the Bundle containing all the restrictions.
634 * @param userHandle the UserHandle of the user for whom to set the restrictions.
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400635 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
636 * android.content.ComponentName, String)} or
637 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
638 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700639 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400640 @Deprecated
Amith Yamasanie4cf7342012-12-17 11:12:09 -0800641 public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
642 try {
643 mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
644 } catch (RemoteException re) {
645 Log.w(TAG, "Could not set user restrictions", re);
646 }
647 }
648
Amith Yamasani71e6c692013-03-24 17:39:28 -0700649 /**
650 * Sets the value of a specific restriction.
Amith Yamasanibe465322014-04-24 13:45:17 -0700651 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700652 * @param key the key of the restriction
653 * @param value the value for the restriction
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400654 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
655 * android.content.ComponentName, String)} or
656 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
657 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700658 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400659 @Deprecated
Amith Yamasani71e6c692013-03-24 17:39:28 -0700660 public void setUserRestriction(String key, boolean value) {
661 Bundle bundle = getUserRestrictions();
662 bundle.putBoolean(key, value);
663 setUserRestrictions(bundle);
664 }
665
666 /**
667 * @hide
668 * Sets the value of a specific restriction on a specific user.
Amith Yamasanibe465322014-04-24 13:45:17 -0700669 * Requires the MANAGE_USERS permission.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700670 * @param key the key of the restriction
671 * @param value the value for the restriction
672 * @param userHandle the user whose restriction is to be changed.
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400673 * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
674 * android.content.ComponentName, String)} or
675 * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
676 * android.content.ComponentName, String)} instead.
Amith Yamasani71e6c692013-03-24 17:39:28 -0700677 */
Julia Reynolds3d9eb782014-08-11 16:40:08 -0400678 @Deprecated
Maggie Benthall67944582013-02-22 14:58:27 -0500679 public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
680 Bundle bundle = getUserRestrictions(userHandle);
681 bundle.putBoolean(key, value);
682 setUserRestrictions(bundle, userHandle);
683 }
684
Amith Yamasani258848d2012-08-10 17:06:33 -0700685 /**
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400686 * Returns whether the current user has been disallowed from performing certain actions
687 * or setting certain settings.
Julia Reynolds2b2cf722014-06-06 11:41:04 -0400688 *
689 * @param restrictionKey The string key representing the restriction.
690 * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400691 */
692 public boolean hasUserRestriction(String restrictionKey) {
David Christieb12ba932013-09-03 17:15:28 -0700693 return hasUserRestriction(restrictionKey, Process.myUserHandle());
694 }
695
696 /**
697 * @hide
698 * Returns whether the given user has been disallowed from performing certain actions
699 * or setting certain settings.
700 * @param restrictionKey the string key representing the restriction
701 * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
702 */
703 public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
Amith Yamasani8cd28b52014-06-08 17:54:27 -0700704 try {
705 return mService.hasUserRestriction(restrictionKey,
706 userHandle.getIdentifier());
707 } catch (RemoteException re) {
708 Log.w(TAG, "Could not check user restrictions", re);
709 return false;
710 }
Maggie Benthalla12fccf2013-03-14 18:02:12 -0400711 }
712
713 /**
Dianne Hackborn33f9cb82012-10-04 17:15:10 -0700714 * Return the serial number for a user. This is a device-unique
Dianne Hackbornb26306a2012-10-24 15:22:21 -0700715 * number assigned to that user; if the user is deleted and then a new
716 * user created, the new users will not be given the same serial number.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -0700717 * @param user The user whose serial number is to be retrieved.
Dianne Hackbornb26306a2012-10-24 15:22:21 -0700718 * @return The serial number of the given user; returns -1 if the
719 * given UserHandle does not exist.
Dianne Hackborn33f9cb82012-10-04 17:15:10 -0700720 * @see #getUserForSerialNumber(long)
721 */
722 public long getSerialNumberForUser(UserHandle user) {
723 return getUserSerialNumber(user.getIdentifier());
724 }
725
726 /**
727 * Return the user associated with a serial number previously
728 * returned by {@link #getSerialNumberForUser(UserHandle)}.
729 * @param serialNumber The serial number of the user that is being
730 * retrieved.
731 * @return Return the user associated with the serial number, or null
732 * if there is not one.
733 * @see #getSerialNumberForUser(UserHandle)
734 */
735 public UserHandle getUserForSerialNumber(long serialNumber) {
736 int ident = getUserHandle((int)serialNumber);
737 return ident >= 0 ? new UserHandle(ident) : null;
738 }
739
740 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700741 * Creates a user with the specified name and options.
Amith Yamasani195263742012-08-21 15:40:12 -0700742 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700743 *
744 * @param name the user's name
745 * @param flags flags that identify the type of user and other properties.
746 * @see UserInfo
747 *
748 * @return the UserInfo object for the created user, or null if the user could not be created.
749 * @hide
750 */
751 public UserInfo createUser(String name, int flags) {
752 try {
753 return mService.createUser(name, flags);
754 } catch (RemoteException re) {
755 Log.w(TAG, "Could not create a user", re);
756 return null;
757 }
758 }
759
760 /**
Amith Yamasani1e9c2182014-06-11 17:25:51 -0700761 * Creates a guest user and configures it.
762 * @param context an application context
763 * @param name the name to set for the user
764 * @hide
765 */
766 public UserInfo createGuest(Context context, String name) {
767 UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
768 if (guest != null) {
769 Settings.Secure.putStringForUser(context.getContentResolver(),
770 Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700771 try {
Amith Yamasani8616af12014-07-31 14:16:04 -0700772 Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
773 guestRestrictions.putBoolean(DISALLOW_SMS, true);
Amith Yamasani29ce85b2014-09-03 17:30:43 -0700774 guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
Amith Yamasani8616af12014-07-31 14:16:04 -0700775 mService.setUserRestrictions(guestRestrictions, guest.id);
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700776 } catch (RemoteException re) {
777 Log.w(TAG, "Could not update guest restrictions");
778 }
Amith Yamasani1e9c2182014-06-11 17:25:51 -0700779 }
780 return guest;
781 }
782
783 /**
Amith Yamasaniaa6634e2014-10-06 14:20:28 -0700784 * Creates a secondary user with the specified name and options and configures it with default
785 * restrictions.
786 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
787 *
788 * @param name the user's name
789 * @param flags flags that identify the type of user and other properties.
790 * @see UserInfo
791 *
792 * @return the UserInfo object for the created user, or null if the user could not be created.
793 * @hide
794 */
795 public UserInfo createSecondaryUser(String name, int flags) {
796 try {
797 UserInfo user = mService.createUser(name, flags);
798 if (user == null) {
799 return null;
800 }
801 Bundle userRestrictions = mService.getUserRestrictions(user.id);
802 addDefaultUserRestrictions(userRestrictions);
803 mService.setUserRestrictions(userRestrictions, user.id);
804 return user;
805 } catch (RemoteException re) {
806 Log.w(TAG, "Could not create a user", re);
807 return null;
808 }
809 }
810
811 private static void addDefaultUserRestrictions(Bundle restrictions) {
812 restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
813 restrictions.putBoolean(DISALLOW_SMS, true);
814 }
815
816 /**
Kenny Guy2a764942014-04-02 13:29:20 +0100817 * Creates a user with the specified name and options as a profile of another user.
Kenny Guya52dc3e2014-02-11 15:33:14 +0000818 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
819 *
820 * @param name the user's name
821 * @param flags flags that identify the type of user and other properties.
822 * @see UserInfo
Kenny Guy2a764942014-04-02 13:29:20 +0100823 * @param userHandle new user will be a profile of this use.
Kenny Guya52dc3e2014-02-11 15:33:14 +0000824 *
825 * @return the UserInfo object for the created user, or null if the user could not be created.
826 * @hide
827 */
Kenny Guy2a764942014-04-02 13:29:20 +0100828 public UserInfo createProfileForUser(String name, int flags, int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +0000829 try {
Kenny Guy2a764942014-04-02 13:29:20 +0100830 return mService.createProfileForUser(name, flags, userHandle);
Kenny Guya52dc3e2014-02-11 15:33:14 +0000831 } catch (RemoteException re) {
832 Log.w(TAG, "Could not create a user", re);
833 return null;
834 }
835 }
836
837 /**
Amith Yamasani1df14732014-08-29 21:37:27 -0700838 * @hide
839 * Marks the guest user for deletion to allow a new guest to be created before deleting
840 * the current user who is a guest.
841 * @param userHandle
842 * @return
843 */
844 public boolean markGuestForDeletion(int userHandle) {
845 try {
846 return mService.markGuestForDeletion(userHandle);
847 } catch (RemoteException re) {
848 Log.w(TAG, "Could not mark guest for deletion", re);
849 return false;
850 }
851 }
852
853 /**
Alexandra Gherghinadf35d572014-04-09 13:54:39 +0100854 * Sets the user as enabled, if such an user exists.
855 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
856 * Note that the default is true, it's only that managed profiles might not be enabled.
857 *
858 * @param userHandle the id of the profile to enable
859 * @hide
860 */
861 public void setUserEnabled(int userHandle) {
862 try {
863 mService.setUserEnabled(userHandle);
864 } catch (RemoteException e) {
865 Log.w(TAG, "Could not enable the profile", e);
866 }
867 }
868
869 /**
Dianne Hackbornb26306a2012-10-24 15:22:21 -0700870 * Return the number of users currently created on the device.
871 */
872 public int getUserCount() {
873 List<UserInfo> users = getUsers();
874 return users != null ? users.size() : 1;
875 }
876
877 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700878 * Returns information for all users on this device.
Amith Yamasani195263742012-08-21 15:40:12 -0700879 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700880 * @return the list of users that were created.
881 * @hide
882 */
883 public List<UserInfo> getUsers() {
884 try {
Amith Yamasani920ace02012-09-20 22:15:37 -0700885 return mService.getUsers(false);
886 } catch (RemoteException re) {
887 Log.w(TAG, "Could not get user list", re);
888 return null;
889 }
890 }
891
892 /**
Amith Yamasani95ab7842014-08-11 17:09:26 -0700893 * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
894 * permission.
895 *
896 * @return true if more users can be added, false if limit has been reached.
897 * @hide
898 */
899 public boolean canAddMoreUsers() {
900 final List<UserInfo> users = getUsers(true);
901 final int totalUserCount = users.size();
902 int aliveUserCount = 0;
903 for (int i = 0; i < totalUserCount; i++) {
904 UserInfo user = users.get(i);
905 if (!user.isGuest()) {
906 aliveUserCount++;
907 }
908 }
909 return aliveUserCount < getMaxSupportedUsers();
910 }
911
912 /**
Kenny Guy2a764942014-04-02 13:29:20 +0100913 * Returns list of the profiles of userHandle including
914 * userHandle itself.
Amith Yamasani4f7e2e32014-08-14 18:49:48 -0700915 * Note that this returns both enabled and not enabled profiles. See
Alexandra Gherghina385124d2014-04-03 13:37:39 +0100916 * {@link #getUserProfiles()} if you need only the enabled ones.
Amith Yamasani4f582632014-02-19 14:31:52 -0800917 *
Kenny Guy2a764942014-04-02 13:29:20 +0100918 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
919 * @param userHandle profiles of this user will be returned.
920 * @return the list of profiles.
921 * @hide
922 */
923 public List<UserInfo> getProfiles(int userHandle) {
Kenny Guya52dc3e2014-02-11 15:33:14 +0000924 try {
Alexandra Gherghina385124d2014-04-03 13:37:39 +0100925 return mService.getProfiles(userHandle, false /* enabledOnly */);
Kenny Guya52dc3e2014-02-11 15:33:14 +0000926 } catch (RemoteException re) {
927 Log.w(TAG, "Could not get user list", re);
928 return null;
929 }
930 }
931
932 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +0100933 * Returns a list of UserHandles for profiles associated with the user that the calling process
934 * is running on, including the user itself.
Amith Yamasani4f582632014-02-19 14:31:52 -0800935 *
936 * @return A non-empty list of UserHandles associated with the calling user.
937 */
938 public List<UserHandle> getUserProfiles() {
939 ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
Alexandra Gherghina385124d2014-04-03 13:37:39 +0100940 List<UserInfo> users = new ArrayList<UserInfo>();
941 try {
Alexandra Gherghinaf2e7b3f2014-04-30 17:01:03 +0000942 users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
Alexandra Gherghina385124d2014-04-03 13:37:39 +0100943 } catch (RemoteException re) {
944 Log.w(TAG, "Could not get user list", re);
945 return null;
946 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800947 for (UserInfo info : users) {
948 UserHandle userHandle = new UserHandle(info.id);
949 profiles.add(userHandle);
950 }
951 return profiles;
952 }
953
Amith Yamasani7dda2652014-04-11 14:57:12 -0700954 /**
Jessica Hummelbe81c802014-04-22 15:49:22 +0100955 * Returns the parent of the profile which this method is called from
956 * or null if called from a user that is not a profile.
957 *
958 * @hide
959 */
960 public UserInfo getProfileParent(int userHandle) {
961 try {
962 return mService.getProfileParent(userHandle);
963 } catch (RemoteException re) {
964 Log.w(TAG, "Could not get profile parent", re);
965 return null;
966 }
967 }
968
969 /**
Amith Yamasani7dda2652014-04-11 14:57:12 -0700970 * If the target user is a managed profile of the calling user or the caller
971 * is itself a managed profile, then this returns a badged copy of the given
Svetoslavc71c42f2014-08-05 18:57:05 -0700972 * icon to be able to distinguish it from the original icon. For badging an
973 * arbitrary drawable use {@link #getBadgedDrawableForUser(
974 * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
975 * <p>
976 * If the original drawable is a BitmapDrawable and the backing bitmap is
977 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
978 * is performed in place and the original drawable is returned.
979 * </p>
Amith Yamasani7dda2652014-04-11 14:57:12 -0700980 *
981 * @param icon The icon to badge.
982 * @param user The target user.
983 * @return A drawable that combines the original icon and a badge as
984 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -0700985 * @removed
Amith Yamasani7dda2652014-04-11 14:57:12 -0700986 */
Svetoslavc71c42f2014-08-05 18:57:05 -0700987 public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -0700988 return mContext.getPackageManager().getUserBadgedIcon(icon, user);
Amith Yamasani4f582632014-02-19 14:31:52 -0800989 }
990
Kenny Guy701ea7c2014-05-08 23:34:12 +0100991 /**
992 * If the target user is a managed profile of the calling user or the caller
Svetoslavc71c42f2014-08-05 18:57:05 -0700993 * is itself a managed profile, then this returns a badged copy of the given
994 * drawable allowing the user to distinguish it from the original drawable.
995 * The caller can specify the location in the bounds of the drawable to be
996 * badged where the badge should be applied as well as the density of the
997 * badge to be used.
998 * <p>
999 * If the original drawable is a BitmapDrawable and the backing bitmap is
1000 * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1001 * is performed in place and the original drawable is returned.
1002 * </p>
1003 *
1004 * @param badgedDrawable The drawable to badge.
1005 * @param user The target user.
1006 * @param badgeLocation Where in the bounds of the badged drawable to place
1007 * the badge. If not provided, the badge is applied on top of the entire
1008 * drawable being badged.
1009 * @param badgeDensity The optional desired density for the badge as per
1010 * {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1011 * the density of the display is used.
1012 * @return A drawable that combines the original drawable and a badge as
1013 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07001014 * @removed
Svetoslavc71c42f2014-08-05 18:57:05 -07001015 */
1016 public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1017 Rect badgeLocation, int badgeDensity) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001018 return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1019 badgeLocation, badgeDensity);
Svetoslavc71c42f2014-08-05 18:57:05 -07001020 }
1021
1022 /**
1023 * If the target user is a managed profile of the calling user or the caller
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01001024 * is itself a managed profile, then this returns a copy of the label with
1025 * badging for accessibility services like talkback. E.g. passing in "Email"
1026 * and it might return "Work Email" for Email in the work profile.
1027 *
1028 * @param label The label to change.
1029 * @param user The target user.
1030 * @return A label that combines the original label and a badge as
1031 * determined by the system.
Svetoslavc7d62f02014-09-04 15:39:54 -07001032 * @removed
Kenny Guyf7ecf7c2014-06-18 11:32:05 +01001033 */
Kenny Guy237aecd2014-07-21 14:06:09 +01001034 public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001035 return mContext.getPackageManager().getUserBadgedLabel(label, user);
Amith Yamasani4f582632014-02-19 14:31:52 -08001036 }
1037
1038 /**
1039 * Returns information for all users on this device. Requires
1040 * {@link android.Manifest.permission#MANAGE_USERS} permission.
Emily Bernier394a6cd2014-05-07 12:49:20 -04001041 *
Amith Yamasani4f582632014-02-19 14:31:52 -08001042 * @param excludeDying specify if the list should exclude users being
1043 * removed.
Amith Yamasani920ace02012-09-20 22:15:37 -07001044 * @return the list of users that were created.
1045 * @hide
1046 */
1047 public List<UserInfo> getUsers(boolean excludeDying) {
1048 try {
1049 return mService.getUsers(excludeDying);
Amith Yamasani258848d2012-08-10 17:06:33 -07001050 } catch (RemoteException re) {
1051 Log.w(TAG, "Could not get user list", re);
1052 return null;
1053 }
1054 }
1055
1056 /**
1057 * Removes a user and all associated data.
Amith Yamasani195263742012-08-21 15:40:12 -07001058 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001059 * @param userHandle the integer handle of the user, where 0 is the primary user.
1060 * @hide
1061 */
1062 public boolean removeUser(int userHandle) {
1063 try {
1064 return mService.removeUser(userHandle);
1065 } catch (RemoteException re) {
1066 Log.w(TAG, "Could not remove user ", re);
1067 return false;
1068 }
1069 }
1070
1071 /**
1072 * Updates the user's name.
Amith Yamasani195263742012-08-21 15:40:12 -07001073 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001074 *
1075 * @param userHandle the user's integer handle
1076 * @param name the new name for the user
1077 * @hide
1078 */
1079 public void setUserName(int userHandle, String name) {
1080 try {
1081 mService.setUserName(userHandle, name);
1082 } catch (RemoteException re) {
1083 Log.w(TAG, "Could not set the user name ", re);
1084 }
1085 }
1086
1087 /**
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001088 * Sets the user's photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07001089 * @param userHandle the user for whom to change the photo.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001090 * @param icon the bitmap to set as the photo.
Amith Yamasani258848d2012-08-10 17:06:33 -07001091 * @hide
1092 */
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001093 public void setUserIcon(int userHandle, Bitmap icon) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001094 try {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001095 mService.setUserIcon(userHandle, icon);
Amith Yamasani258848d2012-08-10 17:06:33 -07001096 } catch (RemoteException re) {
1097 Log.w(TAG, "Could not set the user icon ", re);
Amith Yamasani258848d2012-08-10 17:06:33 -07001098 }
1099 }
1100
1101 /**
Amith Yamasani3b49f072012-09-17 10:21:43 -07001102 * Returns a file descriptor for the user's photo. PNG data can be read from this file.
1103 * @param userHandle the user whose photo we want to read.
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001104 * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01001105 * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
Amith Yamasani3b49f072012-09-17 10:21:43 -07001106 * @hide
1107 */
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001108 public Bitmap getUserIcon(int userHandle) {
Amith Yamasani3b49f072012-09-17 10:21:43 -07001109 try {
Adrian Roos1bdff912015-02-17 15:51:35 +01001110 ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
1111 if (fd != null) {
1112 try {
1113 return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
1114 } finally {
1115 try {
1116 fd.close();
1117 } catch (IOException e) {
1118 }
1119 }
1120 }
Amith Yamasani3b49f072012-09-17 10:21:43 -07001121 } catch (RemoteException re) {
Amith Yamasanie928d7d2012-09-17 21:46:51 -07001122 Log.w(TAG, "Could not get the user icon ", re);
Amith Yamasani3b49f072012-09-17 10:21:43 -07001123 }
Adrian Roos1bdff912015-02-17 15:51:35 +01001124 return null;
Amith Yamasani3b49f072012-09-17 10:21:43 -07001125 }
1126
1127 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07001128 * Returns the maximum number of users that can be created on this device. A return value
1129 * of 1 means that it is a single user device.
1130 * @hide
Maggie Benthalla12fccf2013-03-14 18:02:12 -04001131 * @return a value greater than or equal to 1
Amith Yamasani258848d2012-08-10 17:06:33 -07001132 */
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07001133 public static int getMaxSupportedUsers() {
Amith Yamasaniff549202012-10-12 12:44:49 -07001134 // Don't allow multiple users on certain builds
1135 if (android.os.Build.ID.startsWith("JVP")) return 1;
Dianne Hackborn409297d2014-07-10 17:39:20 -07001136 // Svelte devices don't get multi-user.
1137 if (ActivityManager.isLowRamDeviceStatic()) return 1;
Jeff Sharkey27bd34d2012-09-16 12:49:00 -07001138 return SystemProperties.getInt("fw.max_users",
1139 Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
Amith Yamasani258848d2012-08-10 17:06:33 -07001140 }
Amith Yamasani2a003292012-08-14 18:25:45 -07001141
1142 /**
Kenny Guy1a447532014-02-20 21:55:32 +00001143 * Returns true if the user switcher should be shown, this will be if there
1144 * are multiple users that aren't managed profiles.
1145 * @hide
1146 * @return true if user switcher should be shown.
1147 */
1148 public boolean isUserSwitcherEnabled() {
1149 List<UserInfo> users = getUsers(true);
1150 if (users == null) {
1151 return false;
1152 }
1153 int switchableUserCount = 0;
1154 for (UserInfo user : users) {
1155 if (user.supportsSwitchTo()) {
1156 ++switchableUserCount;
1157 }
1158 }
Amith Yamasania596ff82014-06-12 18:12:38 -07001159 final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1160 Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1161 return switchableUserCount > 1 || guestEnabled;
Kenny Guy1a447532014-02-20 21:55:32 +00001162 }
1163
1164 /**
Amith Yamasani2a003292012-08-14 18:25:45 -07001165 * Returns a serial number on this device for a given userHandle. User handles can be recycled
1166 * when deleting and creating users, but serial numbers are not reused until the device is wiped.
1167 * @param userHandle
1168 * @return a serial number associated with that user, or -1 if the userHandle is not valid.
1169 * @hide
1170 */
1171 public int getUserSerialNumber(int userHandle) {
1172 try {
1173 return mService.getUserSerialNumber(userHandle);
1174 } catch (RemoteException re) {
1175 Log.w(TAG, "Could not get serial number for user " + userHandle);
1176 }
1177 return -1;
1178 }
1179
1180 /**
1181 * Returns a userHandle on this device for a given user serial number. User handles can be
1182 * recycled when deleting and creating users, but serial numbers are not reused until the device
1183 * is wiped.
1184 * @param userSerialNumber
1185 * @return the userHandle associated with that user serial number, or -1 if the serial number
1186 * is not valid.
1187 * @hide
1188 */
1189 public int getUserHandle(int userSerialNumber) {
1190 try {
1191 return mService.getUserHandle(userSerialNumber);
1192 } catch (RemoteException re) {
1193 Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
1194 }
1195 return -1;
1196 }
Maggie Benthall67944582013-02-22 14:58:27 -05001197
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001198 /**
1199 * Returns a Bundle containing any saved application restrictions for this user, for the
1200 * given package name. Only an application with this package name can call this method.
1201 * @param packageName the package name of the calling application
1202 * @return a Bundle with the restrictions as key/value pairs, or null if there are no
1203 * saved restrictions. The values can be of type Boolean, String or String[], depending
1204 * on the restriction type, as defined by the application.
1205 */
1206 public Bundle getApplicationRestrictions(String packageName) {
1207 try {
1208 return mService.getApplicationRestrictions(packageName);
1209 } catch (RemoteException re) {
1210 Log.w(TAG, "Could not get application restrictions for package " + packageName);
1211 }
1212 return null;
1213 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001214
1215 /**
1216 * @hide
1217 */
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001218 public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001219 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001220 return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001221 } catch (RemoteException re) {
1222 Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1223 }
1224 return null;
1225 }
1226
1227 /**
1228 * @hide
1229 */
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001230 public void setApplicationRestrictions(String packageName, Bundle restrictions,
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001231 UserHandle user) {
1232 try {
Amith Yamasani7e99bc02013-04-16 18:24:51 -07001233 mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001234 } catch (RemoteException re) {
1235 Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1236 }
1237 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07001238
1239 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07001240 * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1241 * apps and requires the MANAGE_USERS permission.
1242 * @param newPin the PIN to use for challenge dialogs.
1243 * @return Returns true if the challenge PIN was set successfully.
Amith Yamasani655d0e22013-06-12 14:19:10 -07001244 */
Amith Yamasanid304af62013-09-05 09:30:23 -07001245 public boolean setRestrictionsChallenge(String newPin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001246 try {
Amith Yamasanid304af62013-09-05 09:30:23 -07001247 return mService.setRestrictionsChallenge(newPin);
Amith Yamasani655d0e22013-06-12 14:19:10 -07001248 } catch (RemoteException re) {
1249 Log.w(TAG, "Could not change restrictions pin");
1250 }
1251 return false;
1252 }
1253
1254 /**
1255 * @hide
1256 * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
1257 * allowing the user to enter the PIN.
1258 * @return Returns a positive number (including zero) for how many milliseconds before
1259 * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
1260 * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
1261 * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
1262 */
Amith Yamasanid304af62013-09-05 09:30:23 -07001263 public int checkRestrictionsChallenge(String pin) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001264 try {
Amith Yamasanid304af62013-09-05 09:30:23 -07001265 return mService.checkRestrictionsChallenge(pin);
Amith Yamasani655d0e22013-06-12 14:19:10 -07001266 } catch (RemoteException re) {
1267 Log.w(TAG, "Could not check restrictions pin");
1268 }
1269 return PIN_VERIFICATION_FAILED_INCORRECT;
1270 }
1271
1272 /**
Amith Yamasanid304af62013-09-05 09:30:23 -07001273 * @hide
Amith Yamasani655d0e22013-06-12 14:19:10 -07001274 * Checks whether the user has restrictions that are PIN-protected. An application that
1275 * participates in restrictions can check if the owner has requested a PIN challenge for
1276 * any restricted operations. If there is a PIN in effect, the application should launch
Amith Yamasanid304af62013-09-05 09:30:23 -07001277 * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
1278 * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
Amith Yamasani655d0e22013-06-12 14:19:10 -07001279 * @return whether a restrictions PIN is in effect.
1280 */
Amith Yamasanid304af62013-09-05 09:30:23 -07001281 public boolean hasRestrictionsChallenge() {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001282 try {
Amith Yamasanid304af62013-09-05 09:30:23 -07001283 return mService.hasRestrictionsChallenge();
Amith Yamasani655d0e22013-06-12 14:19:10 -07001284 } catch (RemoteException re) {
1285 Log.w(TAG, "Could not change restrictions pin");
1286 }
1287 return false;
1288 }
Amith Yamasani1a7472e2013-07-02 11:17:30 -07001289
1290 /** @hide */
1291 public void removeRestrictions() {
1292 try {
1293 mService.removeRestrictions();
1294 } catch (RemoteException re) {
1295 Log.w(TAG, "Could not change restrictions pin");
1296 }
1297 }
Amith Yamasanie4afaa32014-06-30 14:55:07 +05301298
1299 /**
1300 * @hide
1301 * Set restrictions that should apply to any future guest user that's created.
1302 */
1303 public void setDefaultGuestRestrictions(Bundle restrictions) {
1304 try {
1305 mService.setDefaultGuestRestrictions(restrictions);
1306 } catch (RemoteException re) {
1307 Log.w(TAG, "Could not set guest restrictions");
1308 }
1309 }
1310
1311 /**
1312 * @hide
1313 * Gets the default guest restrictions.
1314 */
1315 public Bundle getDefaultGuestRestrictions() {
1316 try {
1317 return mService.getDefaultGuestRestrictions();
1318 } catch (RemoteException re) {
1319 Log.w(TAG, "Could not set guest restrictions");
1320 }
1321 return new Bundle();
1322 }
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001323
1324 /**
1325 * Returns creation time of the user or of a managed profile associated with the calling user.
1326 * @param userHandle user handle of the user or a managed profile associated with the
1327 * calling user.
1328 * @return creation time in milliseconds since Epoch time.
1329 */
Fyodor Kupolov385de622015-04-10 18:00:19 -07001330 public long getUserCreationTime(UserHandle userHandle) {
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001331 try {
Fyodor Kupolov385de622015-04-10 18:00:19 -07001332 return mService.getUserCreationTime(userHandle.getIdentifier());
Fyodor Kupolovff7233e2015-04-08 11:28:52 -07001333 } catch (RemoteException re) {
1334 Log.w(TAG, "Could not get user creation time", re);
1335 return 0;
1336 }
1337 }
Amith Yamasani258848d2012-08-10 17:06:33 -07001338}