UserManager.java revision 462ac3a2aa5e1c974d056dc7221805e2b8ac7823
1/*
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
18import android.annotation.SystemApi;
19import android.app.ActivityManager;
20import android.app.ActivityManagerNative;
21import android.content.Context;
22import android.content.pm.UserInfo;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
26import android.graphics.Rect;
27import android.graphics.drawable.Drawable;
28import android.provider.Settings;
29import android.util.Log;
30import android.view.WindowManager.LayoutParams;
31
32import com.android.internal.R;
33
34import java.io.IOException;
35import java.util.ArrayList;
36import 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
47    /**
48     * Specifies if a user is disallowed from adding and removing accounts.
49     * The default value is <code>false</code>.
50     *
51     * <p/>Key for user restrictions.
52     * <p/>Type: Boolean
53     * @see #setUserRestrictions(Bundle)
54     * @see #getUserRestrictions()
55     */
56    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
57
58    /**
59     * Specifies if a user is disallowed from changing Wi-Fi
60     * access points. The default value is <code>false</code>.
61     * <p/>This restriction has no effect in a managed profile.
62     *
63     * <p/>Key for user restrictions.
64     * <p/>Type: Boolean
65     * @see #setUserRestrictions(Bundle)
66     * @see #getUserRestrictions()
67     */
68    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
69
70    /**
71     * Specifies if a user is disallowed from installing applications.
72     * The default value is <code>false</code>.
73     *
74     * <p/>Key for user restrictions.
75     * <p/>Type: Boolean
76     * @see #setUserRestrictions(Bundle)
77     * @see #getUserRestrictions()
78     */
79    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
80
81    /**
82     * Specifies if a user is disallowed from uninstalling applications.
83     * The default value is <code>false</code>.
84     *
85     * <p/>Key for user restrictions.
86     * <p/>Type: Boolean
87     * @see #setUserRestrictions(Bundle)
88     * @see #getUserRestrictions()
89     */
90    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
91
92    /**
93     * Specifies if a user is disallowed from turning on location sharing.
94     * The default value is <code>false</code>.
95     * <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.
97     *
98     * <p/>Key for user restrictions.
99     * <p/>Type: Boolean
100     * @see #setUserRestrictions(Bundle)
101     * @see #getUserRestrictions()
102     */
103    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
104
105    /**
106     * Specifies if a user is disallowed from enabling the
107     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
108     * The default value is <code>false</code>.
109     *
110     * <p/>Key for user restrictions.
111     * <p/>Type: Boolean
112     * @see #setUserRestrictions(Bundle)
113     * @see #getUserRestrictions()
114     */
115    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
116
117    /**
118     * Specifies if a user is disallowed from configuring bluetooth.
119     * This does <em>not</em> restrict the user from turning bluetooth on or off.
120     * The default value is <code>false</code>.
121     * <p/>This restriction has no effect in a managed profile.
122     *
123     * <p/>Key for user restrictions.
124     * <p/>Type: Boolean
125     * @see #setUserRestrictions(Bundle)
126     * @see #getUserRestrictions()
127     */
128    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
129
130    /**
131     * Specifies if a user is disallowed from transferring files over
132     * USB. This can only be set by device owners and profile owners on the primary user.
133     * The default value is <code>false</code>.
134     *
135     * <p/>Key for user restrictions.
136     * <p/>Type: Boolean
137     * @see #setUserRestrictions(Bundle)
138     * @see #getUserRestrictions()
139     */
140    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
141
142    /**
143     * Specifies if a user is disallowed from configuring user
144     * credentials. The default value is <code>false</code>.
145     *
146     * <p/>Key for user restrictions.
147     * <p/>Type: Boolean
148     * @see #setUserRestrictions(Bundle)
149     * @see #getUserRestrictions()
150     */
151    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
152
153    /**
154     * 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>.
158     *
159     * <p/>Key for user restrictions.
160     * <p/>Type: Boolean
161     * @see #setUserRestrictions(Bundle)
162     * @see #getUserRestrictions()
163     */
164    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
165
166    /**
167     * Specifies if a user is disallowed from enabling or
168     * accessing debugging features. The default value is <code>false</code>.
169     *
170     * <p/>Key for user restrictions.
171     * <p/>Type: Boolean
172     * @see #setUserRestrictions(Bundle)
173     * @see #getUserRestrictions()
174     */
175    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
176
177    /**
178     * Specifies if a user is disallowed from configuring VPN.
179     * The default value is <code>false</code>.
180     * This restriction has an effect in a managed profile only from
181     * {@link android.os.Build.VERSION_CODES#MNC}
182     *
183     * <p/>Key for user restrictions.
184     * <p/>Type: Boolean
185     * @see #setUserRestrictions(Bundle)
186     * @see #getUserRestrictions()
187     */
188    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
189
190    /**
191     * Specifies if a user is disallowed from configuring Tethering
192     * & portable hotspots. This can only be set by device owners and profile owners on the
193     * primary user. The default value is <code>false</code>.
194     *
195     * <p/>Key for user restrictions.
196     * <p/>Type: Boolean
197     * @see #setUserRestrictions(Bundle)
198     * @see #getUserRestrictions()
199     */
200    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
201
202    /**
203     * Specifies if a user is disallowed from resetting network settings
204     * from Settings. This can only be set by device owners and profile owners on the primary user.
205     * The default value is <code>false</code>.
206     * <p/>This restriction has no effect on secondary users and managed profiles since only the
207     * primary user can reset the network settings of the device.
208     *
209     * <p/>Key for user restrictions.
210     * <p/>Type: Boolean
211     * @see #setUserRestrictions(Bundle)
212     * @see #getUserRestrictions()
213     */
214    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
215
216    /**
217     * Specifies if a user is disallowed from factory resetting
218     * from Settings. This can only be set by device owners and profile owners on the primary user.
219     * The default value is <code>false</code>.
220     * <p/>This restriction has no effect on secondary users and managed profiles since only the
221     * primary user can factory reset the device.
222     *
223     * <p/>Key for user restrictions.
224     * <p/>Type: Boolean
225     * @see #setUserRestrictions(Bundle)
226     * @see #getUserRestrictions()
227     */
228    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
229
230    /**
231     * Specifies if a user is disallowed from adding new users and
232     * profiles. This can only be set by device owners and profile owners on the primary user.
233     * The default value is <code>false</code>.
234     * <p/>This restriction has no effect on secondary users and managed profiles since only the
235     * primary user can add other users.
236     *
237     * <p/>Key for user restrictions.
238     * <p/>Type: Boolean
239     * @see #setUserRestrictions(Bundle)
240     * @see #getUserRestrictions()
241     */
242    public static final String DISALLOW_ADD_USER = "no_add_user";
243
244    /**
245     * Specifies if a user is disallowed from disabling application
246     * verification. The default value is <code>false</code>.
247     *
248     * <p/>Key for user restrictions.
249     * <p/>Type: Boolean
250     * @see #setUserRestrictions(Bundle)
251     * @see #getUserRestrictions()
252     */
253    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
254
255    /**
256     * Specifies if a user is disallowed from configuring cell
257     * broadcasts. This can only be set by device owners and profile owners on the primary user.
258     * The default value is <code>false</code>.
259     * <p/>This restriction has no effect on secondary users and managed profiles since only the
260     * primary user can configure cell broadcasts.
261     *
262     * <p/>Key for user restrictions.
263     * <p/>Type: Boolean
264     * @see #setUserRestrictions(Bundle)
265     * @see #getUserRestrictions()
266     */
267    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
268
269    /**
270     * Specifies if a user is disallowed from configuring mobile
271     * networks. This can only be set by device owners and profile owners on the primary user.
272     * The default value is <code>false</code>.
273     * <p/>This restriction has no effect on secondary users and managed profiles since only the
274     * primary user can configure mobile networks.
275     *
276     * <p/>Key for user restrictions.
277     * <p/>Type: Boolean
278     * @see #setUserRestrictions(Bundle)
279     * @see #getUserRestrictions()
280     */
281    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
282
283    /**
284     * Specifies if a user is disallowed from modifying
285     * applications in Settings or launchers. The following actions will not be allowed when this
286     * restriction is enabled:
287     * <li>uninstalling apps</li>
288     * <li>disabling apps</li>
289     * <li>clearing app caches</li>
290     * <li>clearing app data</li>
291     * <li>force stopping apps</li>
292     * <li>clearing app defaults</li>
293     * <p>
294     * The default value is <code>false</code>.
295     *
296     * <p/>Key for user restrictions.
297     * <p/>Type: Boolean
298     * @see #setUserRestrictions(Bundle)
299     * @see #getUserRestrictions()
300     */
301    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
302
303    /**
304     * Specifies if a user is disallowed from mounting
305     * physical external media. This can only be set by device owners and profile owners on the
306     * primary user. The default value is <code>false</code>.
307     *
308     * <p/>Key for user restrictions.
309     * <p/>Type: Boolean
310     * @see #setUserRestrictions(Bundle)
311     * @see #getUserRestrictions()
312     */
313    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
314
315    /**
316     * Specifies if a user is disallowed from adjusting microphone
317     * volume. If set, the microphone will be muted. This can only be set by device owners
318     * and profile owners on the primary user. The default value is <code>false</code>.
319     *
320     * <p/>Key for user restrictions.
321     * <p/>Type: Boolean
322     * @see #setUserRestrictions(Bundle)
323     * @see #getUserRestrictions()
324     */
325    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
326
327    /**
328     * Specifies if a user is disallowed from adjusting the master
329     * volume. If set, the master volume will be muted. This can only be set by device owners
330     * and profile owners on the primary user. The default value is <code>false</code>.
331     *
332     * <p/>Key for user restrictions.
333     * <p/>Type: Boolean
334     * @see #setUserRestrictions(Bundle)
335     * @see #getUserRestrictions()
336     */
337    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
338
339    /**
340     * Specifies that the user is not allowed to make outgoing
341     * phone calls. Emergency calls are still permitted.
342     * The default value is <code>false</code>.
343     * <p/>This restriction has no effect on managed profiles since call intents are normally
344     * forwarded to the primary user.
345     *
346     * <p/>Key for user restrictions.
347     * <p/>Type: Boolean
348     * @see #setUserRestrictions(Bundle)
349     * @see #getUserRestrictions()
350     */
351    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
352
353    /**
354     * Specifies that the user is not allowed to send or receive
355     * SMS messages. The default value is <code>false</code>.
356     *
357     * <p/>Key for user restrictions.
358     * <p/>Type: Boolean
359     * @see #setUserRestrictions(Bundle)
360     * @see #getUserRestrictions()
361     */
362    public static final String DISALLOW_SMS = "no_sms";
363
364    /**
365     * Specifies if the user is not allowed to have fun. In some cases, the
366     * device owner may wish to prevent the user from experiencing amusement or
367     * joy while using the device. The default value is <code>false</code>.
368     *
369     * <p/>Key for user restrictions.
370     * <p/>Type: Boolean
371     * @see #setUserRestrictions(Bundle)
372     * @see #getUserRestrictions()
373     */
374    public static final String DISALLOW_FUN = "no_fun";
375
376    /**
377     * Specifies that windows besides app windows should not be
378     * created. This will block the creation of the following types of windows.
379     * <li>{@link LayoutParams#TYPE_TOAST}</li>
380     * <li>{@link LayoutParams#TYPE_PHONE}</li>
381     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
382     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
383     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
384     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
385     *
386     * <p>This can only be set by device owners and profile owners on the primary user.
387     * The default value is <code>false</code>.
388     *
389     * <p/>Key for user restrictions.
390     * <p/>Type: Boolean
391     * @see #setUserRestrictions(Bundle)
392     * @see #getUserRestrictions()
393     */
394    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
395
396    /**
397     * Specifies if what is copied in the clipboard of this profile can
398     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
399     * pasted in this profile.
400     * The default value is <code>false</code>.
401     *
402     * <p/>Key for user restrictions.
403     * <p/>Type: Boolean
404     * @see #setUserRestrictions(Bundle)
405     * @see #getUserRestrictions()
406     */
407    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
408
409    /**
410     * Specifies if the user is not allowed to use NFC to beam out data from apps.
411     * The default value is <code>false</code>.
412     *
413     * <p/>Key for user restrictions.
414     * <p/>Type: Boolean
415     * @see #setUserRestrictions(Bundle)
416     * @see #getUserRestrictions()
417     */
418    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
419
420    /**
421     * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
422     * is always set for managed profiles.
423     * @hide
424     * @see #setUserRestrictions(Bundle)
425     * @see #getUserRestrictions()
426     */
427    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
428
429    /**
430     * Specifies if the user is not allowed to reboot the device into safe boot mode.
431     * This can only be set by device owners and profile owners on the primary user.
432     * The default value is <code>false</code>.
433     *
434     * <p/>Key for user restrictions.
435     * <p/>Type: Boolean
436     * @see #setUserRestrictions(Bundle)
437     * @see #getUserRestrictions()
438     */
439    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
440
441    /**
442     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
443     * background users. The default value is <code>false</code>.
444     *
445     * @see #setUserRestrictions(Bundle)
446     * @see #getUserRestrictions()
447     * @hide
448     */
449    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
450
451    /**
452     * Allows apps in the parent profile to handle web links from the managed profile.
453     *
454     * This user restriction has an effect only in a managed profile.
455     * If set:
456     * Intent filters of activities in the parent profile with action
457     * {@link android.content.Intent#ACTION_VIEW},
458     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
459     * define a host can handle intents from the managed profile.
460     * The default value is <code>false</code>.
461     *
462     * <p/>Key for user restrictions.
463     * <p/>Type: Boolean
464     * @see #setUserRestrictions(Bundle)
465     * @see #getUserRestrictions()
466     */
467    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
468            = "allow_parent_profile_app_linking";
469
470    /**
471     * Application restriction key that is used to indicate the pending arrival
472     * of real restrictions for the app.
473     *
474     * <p>
475     * Applications that support restrictions should check for the presence of this key.
476     * A <code>true</code> value indicates that restrictions may be applied in the near
477     * future but are not available yet. It is the responsibility of any
478     * management application that sets this flag to update it when the final
479     * restrictions are enforced.
480     *
481     * <p/>Key for application restrictions.
482     * <p/>Type: Boolean
483     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
484     *      android.content.ComponentName, String, Bundle)
485     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
486     *      android.content.ComponentName, String)
487     */
488    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
489
490    /** @hide */
491    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
492    /** @hide */
493    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
494    /** @hide */
495    public static final int PIN_VERIFICATION_SUCCESS = -1;
496
497    private static UserManager sInstance = null;
498
499    /** @hide */
500    public synchronized static UserManager get(Context context) {
501        if (sInstance == null) {
502            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
503        }
504        return sInstance;
505    }
506
507    /** @hide */
508    public UserManager(Context context, IUserManager service) {
509        mService = service;
510        mContext = context;
511    }
512
513    /**
514     * Returns whether the system supports multiple users.
515     * @return true if multiple users can be created by user, false if it is a single user device.
516     * @hide
517     */
518    public static boolean supportsMultipleUsers() {
519        return getMaxSupportedUsers() > 1
520                && SystemProperties.getBoolean("fw.show_multiuserui",
521                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
522    }
523
524    /**
525     * Returns the user handle for the user that this process is running under.
526     *
527     * @return the user handle of this process.
528     * @hide
529     */
530    public int getUserHandle() {
531        return UserHandle.myUserId();
532    }
533
534    /**
535     * Returns the user name of the user making this call.  This call is only
536     * available to applications on the system image; it requires the
537     * MANAGE_USERS permission.
538     * @return the user name
539     */
540    public String getUserName() {
541        try {
542            return mService.getUserInfo(getUserHandle()).name;
543        } catch (RemoteException re) {
544            Log.w(TAG, "Could not get user name", re);
545            return "";
546        }
547    }
548
549    /**
550     * Used to determine whether the user making this call is subject to
551     * teleportations.
552     *
553     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
554     * now automatically identify goats using advanced goat recognition technology.</p>
555     *
556     * @return Returns true if the user making this call is a goat.
557     */
558    public boolean isUserAGoat() {
559        return mContext.getPackageManager()
560                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
561    }
562
563    /**
564     * Used to check if this process is running under the system user. The system user
565     * is the initial user that is implicitly created on first boot and hosts most of the
566     * system services.
567     *
568     * @return whether this process is running under the system user.
569     */
570    public boolean isSystemUser() {
571        return UserHandle.myUserId() == UserHandle.USER_OWNER;
572    }
573
574    /**
575     * @hide
576     * Returns whether the caller is running as an admin user. There can be more than one admin
577     * user.
578     */
579    public boolean isAdminUser() {
580        UserInfo user = getUserInfo(UserHandle.myUserId());
581        return user != null ? user.isAdmin() : false;
582    }
583
584    /**
585     * Used to check if the user making this call is linked to another user. Linked users may have
586     * a reduced number of available apps, app restrictions and account restrictions.
587     * @return whether the user making this call is a linked user
588     * @hide
589     */
590    public boolean isLinkedUser() {
591        try {
592            return mService.isRestricted();
593        } catch (RemoteException re) {
594            Log.w(TAG, "Could not check if user is limited ", re);
595            return false;
596        }
597    }
598
599    /**
600     * Checks if the calling app is running as a guest user.
601     * @return whether the caller is a guest user.
602     * @hide
603     */
604    public boolean isGuestUser() {
605        UserInfo user = getUserInfo(UserHandle.myUserId());
606        return user != null ? user.isGuest() : false;
607    }
608
609    /**
610     * Checks if the calling app is running in a managed profile.
611     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
612     *
613     * @return whether the caller is in a managed profile.
614     * @hide
615     */
616    @SystemApi
617    public boolean isManagedProfile() {
618        UserInfo user = getUserInfo(UserHandle.myUserId());
619        return user != null ? user.isManagedProfile() : false;
620    }
621
622    /**
623     * Return whether the given user is actively running.  This means that
624     * the user is in the "started" state, not "stopped" -- it is currently
625     * allowed to run code through scheduled alarms, receiving broadcasts,
626     * etc.  A started user may be either the current foreground user or a
627     * background user; the result here does not distinguish between the two.
628     * @param user The user to retrieve the running state for.
629     */
630    public boolean isUserRunning(UserHandle user) {
631        try {
632            return ActivityManagerNative.getDefault().isUserRunning(
633                    user.getIdentifier(), false);
634        } catch (RemoteException e) {
635            return false;
636        }
637    }
638
639    /**
640     * Return whether the given user is actively running <em>or</em> stopping.
641     * This is like {@link #isUserRunning(UserHandle)}, but will also return
642     * true if the user had been running but is in the process of being stopped
643     * (but is not yet fully stopped, and still running some code).
644     * @param user The user to retrieve the running state for.
645     */
646    public boolean isUserRunningOrStopping(UserHandle user) {
647        try {
648            return ActivityManagerNative.getDefault().isUserRunning(
649                    user.getIdentifier(), true);
650        } catch (RemoteException e) {
651            return false;
652        }
653    }
654
655    /**
656     * Returns the UserInfo object describing a specific user.
657     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
658     * @param userHandle the user handle of the user whose information is being requested.
659     * @return the UserInfo object for a specific user.
660     * @hide
661     */
662    public UserInfo getUserInfo(int userHandle) {
663        try {
664            return mService.getUserInfo(userHandle);
665        } catch (RemoteException re) {
666            Log.w(TAG, "Could not get user info", re);
667            return null;
668        }
669    }
670
671    /**
672     * Returns the user-wide restrictions imposed on this user.
673     * @return a Bundle containing all the restrictions.
674     */
675    public Bundle getUserRestrictions() {
676        return getUserRestrictions(Process.myUserHandle());
677    }
678
679    /**
680     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
681     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
682     * @return a Bundle containing all the restrictions.
683     */
684    public Bundle getUserRestrictions(UserHandle userHandle) {
685        try {
686            return mService.getUserRestrictions(userHandle.getIdentifier());
687        } catch (RemoteException re) {
688            Log.w(TAG, "Could not get user restrictions", re);
689            return Bundle.EMPTY;
690        }
691    }
692
693    /**
694     * Sets all the user-wide restrictions for this user.
695     * Requires the MANAGE_USERS permission.
696     * @param restrictions the Bundle containing all the restrictions.
697     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
698     * android.content.ComponentName, String)} or
699     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
700     * android.content.ComponentName, String)} instead.
701     */
702    @Deprecated
703    public void setUserRestrictions(Bundle restrictions) {
704        setUserRestrictions(restrictions, Process.myUserHandle());
705    }
706
707    /**
708     * Sets all the user-wide restrictions for the specified user.
709     * Requires the MANAGE_USERS permission.
710     * @param restrictions the Bundle containing all the restrictions.
711     * @param userHandle the UserHandle of the user for whom to set the restrictions.
712     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
713     * android.content.ComponentName, String)} or
714     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
715     * android.content.ComponentName, String)} instead.
716     */
717    @Deprecated
718    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
719        try {
720            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
721        } catch (RemoteException re) {
722            Log.w(TAG, "Could not set user restrictions", re);
723        }
724    }
725
726    /**
727     * Sets the value of a specific restriction.
728     * Requires the MANAGE_USERS permission.
729     * @param key the key of the restriction
730     * @param value the value for the restriction
731     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
732     * android.content.ComponentName, String)} or
733     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
734     * android.content.ComponentName, String)} instead.
735     */
736    @Deprecated
737    public void setUserRestriction(String key, boolean value) {
738        Bundle bundle = getUserRestrictions();
739        bundle.putBoolean(key, value);
740        setUserRestrictions(bundle);
741    }
742
743    /**
744     * @hide
745     * Sets the value of a specific restriction on a specific user.
746     * Requires the MANAGE_USERS permission.
747     * @param key the key of the restriction
748     * @param value the value for the restriction
749     * @param userHandle the user whose restriction is to be changed.
750     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
751     * android.content.ComponentName, String)} or
752     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
753     * android.content.ComponentName, String)} instead.
754     */
755    @Deprecated
756    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
757        try {
758            mService.setUserRestriction(key, value, userHandle.getIdentifier());
759        } catch (RemoteException re) {
760            Log.w(TAG, "Could not set user restriction", re);
761        }
762    }
763
764    /**
765     * Returns whether the current user has been disallowed from performing certain actions
766     * or setting certain settings.
767     *
768     * @param restrictionKey The string key representing the restriction.
769     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
770     */
771    public boolean hasUserRestriction(String restrictionKey) {
772        return hasUserRestriction(restrictionKey, Process.myUserHandle());
773    }
774
775    /**
776     * @hide
777     * Returns whether the given user has been disallowed from performing certain actions
778     * or setting certain settings.
779     * @param restrictionKey the string key representing the restriction
780     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
781     */
782    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
783        try {
784            return mService.hasUserRestriction(restrictionKey,
785                    userHandle.getIdentifier());
786        } catch (RemoteException re) {
787            Log.w(TAG, "Could not check user restrictions", re);
788            return false;
789        }
790    }
791
792    /**
793     * Return the serial number for a user.  This is a device-unique
794     * number assigned to that user; if the user is deleted and then a new
795     * user created, the new users will not be given the same serial number.
796     * @param user The user whose serial number is to be retrieved.
797     * @return The serial number of the given user; returns -1 if the
798     * given UserHandle does not exist.
799     * @see #getUserForSerialNumber(long)
800     */
801    public long getSerialNumberForUser(UserHandle user) {
802        return getUserSerialNumber(user.getIdentifier());
803    }
804
805    /**
806     * Return the user associated with a serial number previously
807     * returned by {@link #getSerialNumberForUser(UserHandle)}.
808     * @param serialNumber The serial number of the user that is being
809     * retrieved.
810     * @return Return the user associated with the serial number, or null
811     * if there is not one.
812     * @see #getSerialNumberForUser(UserHandle)
813     */
814    public UserHandle getUserForSerialNumber(long serialNumber) {
815        int ident = getUserHandle((int) serialNumber);
816        return ident >= 0 ? new UserHandle(ident) : null;
817    }
818
819    /**
820     * Creates a user with the specified name and options.
821     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
822     *
823     * @param name the user's name
824     * @param flags flags that identify the type of user and other properties.
825     * @see UserInfo
826     *
827     * @return the UserInfo object for the created user, or null if the user could not be created.
828     * @hide
829     */
830    public UserInfo createUser(String name, int flags) {
831        try {
832            return mService.createUser(name, flags);
833        } catch (RemoteException re) {
834            Log.w(TAG, "Could not create a user", re);
835            return null;
836        }
837    }
838
839    /**
840     * Creates a guest user and configures it.
841     * @param context an application context
842     * @param name the name to set for the user
843     * @hide
844     */
845    public UserInfo createGuest(Context context, String name) {
846        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
847        if (guest != null) {
848            Settings.Secure.putStringForUser(context.getContentResolver(),
849                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
850            try {
851                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
852                guestRestrictions.putBoolean(DISALLOW_SMS, true);
853                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
854                mService.setUserRestrictions(guestRestrictions, guest.id);
855            } catch (RemoteException re) {
856                Log.w(TAG, "Could not update guest restrictions");
857            }
858        }
859        return guest;
860    }
861
862    /**
863     * Creates a secondary user with the specified name and options and configures it with default
864     * restrictions.
865     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
866     *
867     * @param name the user's name
868     * @param flags flags that identify the type of user and other properties.
869     * @see UserInfo
870     *
871     * @return the UserInfo object for the created user, or null if the user could not be created.
872     * @hide
873     */
874    public UserInfo createSecondaryUser(String name, int flags) {
875        try {
876            UserInfo user = mService.createUser(name, flags);
877            if (user == null) {
878                return null;
879            }
880            Bundle userRestrictions = mService.getUserRestrictions(user.id);
881            addDefaultUserRestrictions(userRestrictions);
882            mService.setUserRestrictions(userRestrictions, user.id);
883            return user;
884        } catch (RemoteException re) {
885            Log.w(TAG, "Could not create a user", re);
886            return null;
887        }
888    }
889
890    private static void addDefaultUserRestrictions(Bundle restrictions) {
891        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
892        restrictions.putBoolean(DISALLOW_SMS, true);
893    }
894
895    /**
896     * Creates a user with the specified name and options as a profile of another user.
897     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
898     *
899     * @param name the user's name
900     * @param flags flags that identify the type of user and other properties.
901     * @see UserInfo
902     * @param userHandle new user will be a profile of this use.
903     *
904     * @return the UserInfo object for the created user, or null if the user could not be created.
905     * @hide
906     */
907    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
908        try {
909            return mService.createProfileForUser(name, flags, userHandle);
910        } catch (RemoteException re) {
911            Log.w(TAG, "Could not create a user", re);
912            return null;
913        }
914    }
915
916    /**
917     * @hide
918     * Marks the guest user for deletion to allow a new guest to be created before deleting
919     * the current user who is a guest.
920     * @param userHandle
921     * @return
922     */
923    public boolean markGuestForDeletion(int userHandle) {
924        try {
925            return mService.markGuestForDeletion(userHandle);
926        } catch (RemoteException re) {
927            Log.w(TAG, "Could not mark guest for deletion", re);
928            return false;
929        }
930    }
931
932    /**
933     * Sets the user as enabled, if such an user exists.
934     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
935     * Note that the default is true, it's only that managed profiles might not be enabled.
936     *
937     * @param userHandle the id of the profile to enable
938     * @hide
939     */
940    public void setUserEnabled(int userHandle) {
941        try {
942            mService.setUserEnabled(userHandle);
943        } catch (RemoteException e) {
944            Log.w(TAG, "Could not enable the profile", e);
945        }
946    }
947
948    /**
949     * Return the number of users currently created on the device.
950     */
951    public int getUserCount() {
952        List<UserInfo> users = getUsers();
953        return users != null ? users.size() : 1;
954    }
955
956    /**
957     * Returns information for all users on this device.
958     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
959     * @return the list of users that were created.
960     * @hide
961     */
962    public List<UserInfo> getUsers() {
963        try {
964            return mService.getUsers(false);
965        } catch (RemoteException re) {
966            Log.w(TAG, "Could not get user list", re);
967            return null;
968        }
969    }
970
971    /**
972     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
973     * permission.
974     *
975     * @return true if more users can be added, false if limit has been reached.
976     * @hide
977     */
978    public boolean canAddMoreUsers() {
979        final List<UserInfo> users = getUsers(true);
980        final int totalUserCount = users.size();
981        int aliveUserCount = 0;
982        for (int i = 0; i < totalUserCount; i++) {
983            UserInfo user = users.get(i);
984            if (!user.isGuest()) {
985                aliveUserCount++;
986            }
987        }
988        return aliveUserCount < getMaxSupportedUsers();
989    }
990
991    /**
992     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
993     * permission.
994     *
995     * @return true if more managed profiles can be added, false if limit has been reached.
996     * @hide
997     */
998    public boolean canAddMoreManagedProfiles() {
999        try {
1000            return mService.canAddMoreManagedProfiles();
1001        } catch (RemoteException re) {
1002            Log.w(TAG, "Could not check if we can add more managed profiles", re);
1003            return false;
1004        }
1005    }
1006
1007    /**
1008     * Returns list of the profiles of userHandle including
1009     * userHandle itself.
1010     * Note that this returns both enabled and not enabled profiles. See
1011     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
1012     *
1013     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1014     * @param userHandle profiles of this user will be returned.
1015     * @return the list of profiles.
1016     * @hide
1017     */
1018    public List<UserInfo> getProfiles(int userHandle) {
1019        try {
1020            return mService.getProfiles(userHandle, false /* enabledOnly */);
1021        } catch (RemoteException re) {
1022            Log.w(TAG, "Could not get user list", re);
1023            return null;
1024        }
1025    }
1026
1027    /**
1028     * Returns list of the profiles of userHandle including
1029     * userHandle itself.
1030     * Note that this returns only enabled.
1031     *
1032     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1033     * @param userHandle profiles of this user will be returned.
1034     * @return the list of profiles.
1035     * @hide
1036     */
1037    public List<UserInfo> getEnabledProfiles(int userHandle) {
1038        try {
1039            return mService.getProfiles(userHandle, true /* enabledOnly */);
1040        } catch (RemoteException re) {
1041            Log.w(TAG, "Could not get user list", re);
1042            return null;
1043        }
1044    }
1045
1046    /**
1047     * Returns a list of UserHandles for profiles associated with the user that the calling process
1048     * is running on, including the user itself.
1049     *
1050     * @return A non-empty list of UserHandles associated with the calling user.
1051     */
1052    public List<UserHandle> getUserProfiles() {
1053        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
1054        List<UserInfo> users = new ArrayList<UserInfo>();
1055        try {
1056            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1057        } catch (RemoteException re) {
1058            Log.w(TAG, "Could not get user list", re);
1059            return null;
1060        }
1061        for (UserInfo info : users) {
1062            UserHandle userHandle = new UserHandle(info.id);
1063            profiles.add(userHandle);
1064        }
1065        return profiles;
1066    }
1067
1068    /**
1069     * Returns the parent of the profile which this method is called from
1070     * or null if called from a user that is not a profile.
1071     *
1072     * @hide
1073     */
1074    public UserInfo getProfileParent(int userHandle) {
1075        try {
1076            return mService.getProfileParent(userHandle);
1077        } catch (RemoteException re) {
1078            Log.w(TAG, "Could not get profile parent", re);
1079            return null;
1080        }
1081    }
1082
1083    /**
1084     * If the target user is a managed profile of the calling user or the caller
1085     * is itself a managed profile, then this returns a badged copy of the given
1086     * icon to be able to distinguish it from the original icon. For badging an
1087     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1088     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1089     * <p>
1090     * If the original drawable is a BitmapDrawable and the backing bitmap is
1091     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1092     * is performed in place and the original drawable is returned.
1093     * </p>
1094     *
1095     * @param icon The icon to badge.
1096     * @param user The target user.
1097     * @return A drawable that combines the original icon and a badge as
1098     *         determined by the system.
1099     * @removed
1100     */
1101    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1102        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1103    }
1104
1105    /**
1106     * If the target user is a managed profile of the calling user or the caller
1107     * is itself a managed profile, then this returns a badged copy of the given
1108     * drawable allowing the user to distinguish it from the original drawable.
1109     * The caller can specify the location in the bounds of the drawable to be
1110     * badged where the badge should be applied as well as the density of the
1111     * badge to be used.
1112     * <p>
1113     * If the original drawable is a BitmapDrawable and the backing bitmap is
1114     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1115     * is performed in place and the original drawable is returned.
1116     * </p>
1117     *
1118     * @param badgedDrawable The drawable to badge.
1119     * @param user The target user.
1120     * @param badgeLocation Where in the bounds of the badged drawable to place
1121     *         the badge. If not provided, the badge is applied on top of the entire
1122     *         drawable being badged.
1123     * @param badgeDensity The optional desired density for the badge as per
1124     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1125     *         the density of the display is used.
1126     * @return A drawable that combines the original drawable and a badge as
1127     *         determined by the system.
1128     * @removed
1129     */
1130    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1131            Rect badgeLocation, int badgeDensity) {
1132        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1133                badgeLocation, badgeDensity);
1134    }
1135
1136    /**
1137     * If the target user is a managed profile of the calling user or the caller
1138     * is itself a managed profile, then this returns a copy of the label with
1139     * badging for accessibility services like talkback. E.g. passing in "Email"
1140     * and it might return "Work Email" for Email in the work profile.
1141     *
1142     * @param label The label to change.
1143     * @param user The target user.
1144     * @return A label that combines the original label and a badge as
1145     *         determined by the system.
1146     * @removed
1147     */
1148    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1149        return mContext.getPackageManager().getUserBadgedLabel(label, user);
1150    }
1151
1152    /**
1153     * Returns information for all users on this device. Requires
1154     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1155     *
1156     * @param excludeDying specify if the list should exclude users being
1157     *            removed.
1158     * @return the list of users that were created.
1159     * @hide
1160     */
1161    public List<UserInfo> getUsers(boolean excludeDying) {
1162        try {
1163            return mService.getUsers(excludeDying);
1164        } catch (RemoteException re) {
1165            Log.w(TAG, "Could not get user list", re);
1166            return null;
1167        }
1168    }
1169
1170    /**
1171     * Removes a user and all associated data.
1172     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1173     * @param userHandle the integer handle of the user, where 0 is the primary user.
1174     * @hide
1175     */
1176    public boolean removeUser(int userHandle) {
1177        try {
1178            return mService.removeUser(userHandle);
1179        } catch (RemoteException re) {
1180            Log.w(TAG, "Could not remove user ", re);
1181            return false;
1182        }
1183    }
1184
1185    /**
1186     * Updates the user's name.
1187     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1188     *
1189     * @param userHandle the user's integer handle
1190     * @param name the new name for the user
1191     * @hide
1192     */
1193    public void setUserName(int userHandle, String name) {
1194        try {
1195            mService.setUserName(userHandle, name);
1196        } catch (RemoteException re) {
1197            Log.w(TAG, "Could not set the user name ", re);
1198        }
1199    }
1200
1201    /**
1202     * Sets the user's photo.
1203     * @param userHandle the user for whom to change the photo.
1204     * @param icon the bitmap to set as the photo.
1205     * @hide
1206     */
1207    public void setUserIcon(int userHandle, Bitmap icon) {
1208        try {
1209            mService.setUserIcon(userHandle, icon);
1210        } catch (RemoteException re) {
1211            Log.w(TAG, "Could not set the user icon ", re);
1212        }
1213    }
1214
1215    /**
1216     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
1217     * @param userHandle the user whose photo we want to read.
1218     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
1219     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
1220     * @hide
1221     */
1222    public Bitmap getUserIcon(int userHandle) {
1223        try {
1224            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
1225            if (fd != null) {
1226                try {
1227                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
1228                } finally {
1229                    try {
1230                        fd.close();
1231                    } catch (IOException e) {
1232                    }
1233                }
1234            }
1235        } catch (RemoteException re) {
1236            Log.w(TAG, "Could not get the user icon ", re);
1237        }
1238        return null;
1239    }
1240
1241    /**
1242     * Returns the maximum number of users that can be created on this device. A return value
1243     * of 1 means that it is a single user device.
1244     * @hide
1245     * @return a value greater than or equal to 1
1246     */
1247    public static int getMaxSupportedUsers() {
1248        // Don't allow multiple users on certain builds
1249        if (android.os.Build.ID.startsWith("JVP")) return 1;
1250        // Svelte devices don't get multi-user.
1251        if (ActivityManager.isLowRamDeviceStatic()) return 1;
1252        return SystemProperties.getInt("fw.max_users",
1253                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1254    }
1255
1256    /**
1257     * Returns true if the user switcher should be shown, this will be if there
1258     * are multiple users that aren't managed profiles.
1259     * @hide
1260     * @return true if user switcher should be shown.
1261     */
1262    public boolean isUserSwitcherEnabled() {
1263        List<UserInfo> users = getUsers(true);
1264        if (users == null) {
1265           return false;
1266        }
1267        int switchableUserCount = 0;
1268        for (UserInfo user : users) {
1269            if (user.supportsSwitchTo()) {
1270                ++switchableUserCount;
1271            }
1272        }
1273        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1274                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1275        return switchableUserCount > 1 || guestEnabled;
1276    }
1277
1278    /**
1279     * Returns a serial number on this device for a given userHandle. User handles can be recycled
1280     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
1281     * @param userHandle
1282     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
1283     * @hide
1284     */
1285    public int getUserSerialNumber(int userHandle) {
1286        try {
1287            return mService.getUserSerialNumber(userHandle);
1288        } catch (RemoteException re) {
1289            Log.w(TAG, "Could not get serial number for user " + userHandle);
1290        }
1291        return -1;
1292    }
1293
1294    /**
1295     * Returns a userHandle on this device for a given user serial number. User handles can be
1296     * recycled when deleting and creating users, but serial numbers are not reused until the device
1297     * is wiped.
1298     * @param userSerialNumber
1299     * @return the userHandle associated with that user serial number, or -1 if the serial number
1300     * is not valid.
1301     * @hide
1302     */
1303    public int getUserHandle(int userSerialNumber) {
1304        try {
1305            return mService.getUserHandle(userSerialNumber);
1306        } catch (RemoteException re) {
1307            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
1308        }
1309        return -1;
1310    }
1311
1312    /**
1313     * Returns a Bundle containing any saved application restrictions for this user, for the
1314     * given package name. Only an application with this package name can call this method.
1315     * @param packageName the package name of the calling application
1316     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
1317     * saved restrictions. The values can be of type Boolean, String or String[], depending
1318     * on the restriction type, as defined by the application.
1319     */
1320    public Bundle getApplicationRestrictions(String packageName) {
1321        try {
1322            return mService.getApplicationRestrictions(packageName);
1323        } catch (RemoteException re) {
1324            Log.w(TAG, "Could not get application restrictions for package " + packageName);
1325        }
1326        return null;
1327    }
1328
1329    /**
1330     * @hide
1331     */
1332    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1333        try {
1334            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1335        } catch (RemoteException re) {
1336            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1337        }
1338        return null;
1339    }
1340
1341    /**
1342     * @hide
1343     */
1344    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1345            UserHandle user) {
1346        try {
1347            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1348        } catch (RemoteException re) {
1349            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1350        }
1351    }
1352
1353    /**
1354     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1355     * apps and requires the MANAGE_USERS permission.
1356     * @param newPin the PIN to use for challenge dialogs.
1357     * @return Returns true if the challenge PIN was set successfully.
1358     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1359     * This method is preserved for backwards compatibility reasons and always returns false.
1360     */
1361    public boolean setRestrictionsChallenge(String newPin) {
1362        return false;
1363    }
1364
1365    /** @hide */
1366    public void removeRestrictions() {
1367        try {
1368            mService.removeRestrictions();
1369        } catch (RemoteException re) {
1370            Log.w(TAG, "Could not change restrictions pin");
1371        }
1372    }
1373
1374    /**
1375     * @hide
1376     * Set restrictions that should apply to any future guest user that's created.
1377     */
1378    public void setDefaultGuestRestrictions(Bundle restrictions) {
1379        try {
1380            mService.setDefaultGuestRestrictions(restrictions);
1381        } catch (RemoteException re) {
1382            Log.w(TAG, "Could not set guest restrictions");
1383        }
1384    }
1385
1386    /**
1387     * @hide
1388     * Gets the default guest restrictions.
1389     */
1390    public Bundle getDefaultGuestRestrictions() {
1391        try {
1392            return mService.getDefaultGuestRestrictions();
1393        } catch (RemoteException re) {
1394            Log.w(TAG, "Could not set guest restrictions");
1395        }
1396        return new Bundle();
1397    }
1398
1399    /**
1400     * Returns creation time of the user or of a managed profile associated with the calling user.
1401     * @param userHandle user handle of the user or a managed profile associated with the
1402     *                   calling user.
1403     * @return creation time in milliseconds since Epoch time.
1404     */
1405    public long getUserCreationTime(UserHandle userHandle) {
1406        try {
1407            return mService.getUserCreationTime(userHandle.getIdentifier());
1408        } catch (RemoteException re) {
1409            Log.w(TAG, "Could not get user creation time", re);
1410            return 0;
1411        }
1412    }
1413}
1414