UserManager.java revision f0029c1ddb2875583e62c6a3f96d288e21f2efe2
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     * Used to check if the user making this call is linked to another user. Linked users may have
576     * a reduced number of available apps, app restrictions and account restrictions.
577     * @return whether the user making this call is a linked user
578     * @hide
579     */
580    public boolean isLinkedUser() {
581        try {
582            return mService.isRestricted();
583        } catch (RemoteException re) {
584            Log.w(TAG, "Could not check if user is limited ", re);
585            return false;
586        }
587    }
588
589    /**
590     * Checks if the calling app is running as a guest user.
591     * @return whether the caller is a guest user.
592     * @hide
593     */
594    public boolean isGuestUser() {
595        UserInfo user = getUserInfo(UserHandle.myUserId());
596        return user != null ? user.isGuest() : false;
597    }
598
599    /**
600     * Checks if the calling app is running in a managed profile.
601     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
602     *
603     * @return whether the caller is in a managed profile.
604     * @hide
605     */
606    @SystemApi
607    public boolean isManagedProfile() {
608        UserInfo user = getUserInfo(UserHandle.myUserId());
609        return user != null ? user.isManagedProfile() : false;
610    }
611
612    /**
613     * Return whether the given user is actively running.  This means that
614     * the user is in the "started" state, not "stopped" -- it is currently
615     * allowed to run code through scheduled alarms, receiving broadcasts,
616     * etc.  A started user may be either the current foreground user or a
617     * background user; the result here does not distinguish between the two.
618     * @param user The user to retrieve the running state for.
619     */
620    public boolean isUserRunning(UserHandle user) {
621        try {
622            return ActivityManagerNative.getDefault().isUserRunning(
623                    user.getIdentifier(), false);
624        } catch (RemoteException e) {
625            return false;
626        }
627    }
628
629    /**
630     * Return whether the given user is actively running <em>or</em> stopping.
631     * This is like {@link #isUserRunning(UserHandle)}, but will also return
632     * true if the user had been running but is in the process of being stopped
633     * (but is not yet fully stopped, and still running some code).
634     * @param user The user to retrieve the running state for.
635     */
636    public boolean isUserRunningOrStopping(UserHandle user) {
637        try {
638            return ActivityManagerNative.getDefault().isUserRunning(
639                    user.getIdentifier(), true);
640        } catch (RemoteException e) {
641            return false;
642        }
643    }
644
645    /**
646     * Returns the UserInfo object describing a specific user.
647     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
648     * @param userHandle the user handle of the user whose information is being requested.
649     * @return the UserInfo object for a specific user.
650     * @hide
651     */
652    public UserInfo getUserInfo(int userHandle) {
653        try {
654            return mService.getUserInfo(userHandle);
655        } catch (RemoteException re) {
656            Log.w(TAG, "Could not get user info", re);
657            return null;
658        }
659    }
660
661    /**
662     * Returns the user-wide restrictions imposed on this user.
663     * @return a Bundle containing all the restrictions.
664     */
665    public Bundle getUserRestrictions() {
666        return getUserRestrictions(Process.myUserHandle());
667    }
668
669    /**
670     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
671     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
672     * @return a Bundle containing all the restrictions.
673     */
674    public Bundle getUserRestrictions(UserHandle userHandle) {
675        try {
676            return mService.getUserRestrictions(userHandle.getIdentifier());
677        } catch (RemoteException re) {
678            Log.w(TAG, "Could not get user restrictions", re);
679            return Bundle.EMPTY;
680        }
681    }
682
683    /**
684     * Sets all the user-wide restrictions for this user.
685     * Requires the MANAGE_USERS permission.
686     * @param restrictions the Bundle containing all the restrictions.
687     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
688     * android.content.ComponentName, String)} or
689     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
690     * android.content.ComponentName, String)} instead.
691     */
692    @Deprecated
693    public void setUserRestrictions(Bundle restrictions) {
694        setUserRestrictions(restrictions, Process.myUserHandle());
695    }
696
697    /**
698     * Sets all the user-wide restrictions for the specified user.
699     * Requires the MANAGE_USERS permission.
700     * @param restrictions the Bundle containing all the restrictions.
701     * @param userHandle the UserHandle of the user for whom to set the restrictions.
702     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
703     * android.content.ComponentName, String)} or
704     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
705     * android.content.ComponentName, String)} instead.
706     */
707    @Deprecated
708    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
709        try {
710            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
711        } catch (RemoteException re) {
712            Log.w(TAG, "Could not set user restrictions", re);
713        }
714    }
715
716    /**
717     * Sets the value of a specific restriction.
718     * Requires the MANAGE_USERS permission.
719     * @param key the key of the restriction
720     * @param value the value for the restriction
721     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
722     * android.content.ComponentName, String)} or
723     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
724     * android.content.ComponentName, String)} instead.
725     */
726    @Deprecated
727    public void setUserRestriction(String key, boolean value) {
728        Bundle bundle = getUserRestrictions();
729        bundle.putBoolean(key, value);
730        setUserRestrictions(bundle);
731    }
732
733    /**
734     * @hide
735     * Sets the value of a specific restriction on a specific user.
736     * Requires the MANAGE_USERS permission.
737     * @param key the key of the restriction
738     * @param value the value for the restriction
739     * @param userHandle the user whose restriction is to be changed.
740     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
741     * android.content.ComponentName, String)} or
742     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
743     * android.content.ComponentName, String)} instead.
744     */
745    @Deprecated
746    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
747        try {
748            mService.setUserRestriction(key, value, userHandle.getIdentifier());
749        } catch (RemoteException re) {
750            Log.w(TAG, "Could not set user restriction", re);
751        }
752    }
753
754    /**
755     * Returns whether the current user has been disallowed from performing certain actions
756     * or setting certain settings.
757     *
758     * @param restrictionKey The string key representing the restriction.
759     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
760     */
761    public boolean hasUserRestriction(String restrictionKey) {
762        return hasUserRestriction(restrictionKey, Process.myUserHandle());
763    }
764
765    /**
766     * @hide
767     * Returns whether the given user has been disallowed from performing certain actions
768     * or setting certain settings.
769     * @param restrictionKey the string key representing the restriction
770     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
771     */
772    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
773        try {
774            return mService.hasUserRestriction(restrictionKey,
775                    userHandle.getIdentifier());
776        } catch (RemoteException re) {
777            Log.w(TAG, "Could not check user restrictions", re);
778            return false;
779        }
780    }
781
782    /**
783     * Return the serial number for a user.  This is a device-unique
784     * number assigned to that user; if the user is deleted and then a new
785     * user created, the new users will not be given the same serial number.
786     * @param user The user whose serial number is to be retrieved.
787     * @return The serial number of the given user; returns -1 if the
788     * given UserHandle does not exist.
789     * @see #getUserForSerialNumber(long)
790     */
791    public long getSerialNumberForUser(UserHandle user) {
792        return getUserSerialNumber(user.getIdentifier());
793    }
794
795    /**
796     * Return the user associated with a serial number previously
797     * returned by {@link #getSerialNumberForUser(UserHandle)}.
798     * @param serialNumber The serial number of the user that is being
799     * retrieved.
800     * @return Return the user associated with the serial number, or null
801     * if there is not one.
802     * @see #getSerialNumberForUser(UserHandle)
803     */
804    public UserHandle getUserForSerialNumber(long serialNumber) {
805        int ident = getUserHandle((int) serialNumber);
806        return ident >= 0 ? new UserHandle(ident) : null;
807    }
808
809    /**
810     * Creates a user with the specified name and options.
811     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
812     *
813     * @param name the user's name
814     * @param flags flags that identify the type of user and other properties.
815     * @see UserInfo
816     *
817     * @return the UserInfo object for the created user, or null if the user could not be created.
818     * @hide
819     */
820    public UserInfo createUser(String name, int flags) {
821        try {
822            return mService.createUser(name, flags);
823        } catch (RemoteException re) {
824            Log.w(TAG, "Could not create a user", re);
825            return null;
826        }
827    }
828
829    /**
830     * Creates a guest user and configures it.
831     * @param context an application context
832     * @param name the name to set for the user
833     * @hide
834     */
835    public UserInfo createGuest(Context context, String name) {
836        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
837        if (guest != null) {
838            Settings.Secure.putStringForUser(context.getContentResolver(),
839                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
840            try {
841                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
842                guestRestrictions.putBoolean(DISALLOW_SMS, true);
843                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
844                mService.setUserRestrictions(guestRestrictions, guest.id);
845            } catch (RemoteException re) {
846                Log.w(TAG, "Could not update guest restrictions");
847            }
848        }
849        return guest;
850    }
851
852    /**
853     * Creates a secondary user with the specified name and options and configures it with default
854     * restrictions.
855     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
856     *
857     * @param name the user's name
858     * @param flags flags that identify the type of user and other properties.
859     * @see UserInfo
860     *
861     * @return the UserInfo object for the created user, or null if the user could not be created.
862     * @hide
863     */
864    public UserInfo createSecondaryUser(String name, int flags) {
865        try {
866            UserInfo user = mService.createUser(name, flags);
867            if (user == null) {
868                return null;
869            }
870            Bundle userRestrictions = mService.getUserRestrictions(user.id);
871            addDefaultUserRestrictions(userRestrictions);
872            mService.setUserRestrictions(userRestrictions, user.id);
873            return user;
874        } catch (RemoteException re) {
875            Log.w(TAG, "Could not create a user", re);
876            return null;
877        }
878    }
879
880    private static void addDefaultUserRestrictions(Bundle restrictions) {
881        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
882        restrictions.putBoolean(DISALLOW_SMS, true);
883    }
884
885    /**
886     * Creates a user with the specified name and options as a profile of another user.
887     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
888     *
889     * @param name the user's name
890     * @param flags flags that identify the type of user and other properties.
891     * @see UserInfo
892     * @param userHandle new user will be a profile of this use.
893     *
894     * @return the UserInfo object for the created user, or null if the user could not be created.
895     * @hide
896     */
897    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
898        try {
899            return mService.createProfileForUser(name, flags, userHandle);
900        } catch (RemoteException re) {
901            Log.w(TAG, "Could not create a user", re);
902            return null;
903        }
904    }
905
906    /**
907     * @hide
908     * Marks the guest user for deletion to allow a new guest to be created before deleting
909     * the current user who is a guest.
910     * @param userHandle
911     * @return
912     */
913    public boolean markGuestForDeletion(int userHandle) {
914        try {
915            return mService.markGuestForDeletion(userHandle);
916        } catch (RemoteException re) {
917            Log.w(TAG, "Could not mark guest for deletion", re);
918            return false;
919        }
920    }
921
922    /**
923     * Sets the user as enabled, if such an user exists.
924     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
925     * Note that the default is true, it's only that managed profiles might not be enabled.
926     *
927     * @param userHandle the id of the profile to enable
928     * @hide
929     */
930    public void setUserEnabled(int userHandle) {
931        try {
932            mService.setUserEnabled(userHandle);
933        } catch (RemoteException e) {
934            Log.w(TAG, "Could not enable the profile", e);
935        }
936    }
937
938    /**
939     * Return the number of users currently created on the device.
940     */
941    public int getUserCount() {
942        List<UserInfo> users = getUsers();
943        return users != null ? users.size() : 1;
944    }
945
946    /**
947     * Returns information for all users on this device.
948     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
949     * @return the list of users that were created.
950     * @hide
951     */
952    public List<UserInfo> getUsers() {
953        try {
954            return mService.getUsers(false);
955        } catch (RemoteException re) {
956            Log.w(TAG, "Could not get user list", re);
957            return null;
958        }
959    }
960
961    /**
962     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
963     * permission.
964     *
965     * @return true if more users can be added, false if limit has been reached.
966     * @hide
967     */
968    public boolean canAddMoreUsers() {
969        final List<UserInfo> users = getUsers(true);
970        final int totalUserCount = users.size();
971        int aliveUserCount = 0;
972        for (int i = 0; i < totalUserCount; i++) {
973            UserInfo user = users.get(i);
974            if (!user.isGuest()) {
975                aliveUserCount++;
976            }
977        }
978        return aliveUserCount < getMaxSupportedUsers();
979    }
980
981    /**
982     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
983     * permission.
984     *
985     * @return true if more managed profiles can be added, false if limit has been reached.
986     * @hide
987     */
988    public boolean canAddMoreManagedProfiles() {
989        try {
990            return mService.canAddMoreManagedProfiles();
991        } catch (RemoteException re) {
992            Log.w(TAG, "Could not check if we can add more managed profiles", re);
993            return false;
994        }
995    }
996
997    /**
998     * Returns list of the profiles of userHandle including
999     * userHandle itself.
1000     * Note that this returns both enabled and not enabled profiles. See
1001     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
1002     *
1003     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1004     * @param userHandle profiles of this user will be returned.
1005     * @return the list of profiles.
1006     * @hide
1007     */
1008    public List<UserInfo> getProfiles(int userHandle) {
1009        try {
1010            return mService.getProfiles(userHandle, false /* enabledOnly */);
1011        } catch (RemoteException re) {
1012            Log.w(TAG, "Could not get user list", re);
1013            return null;
1014        }
1015    }
1016
1017    /**
1018     * Returns list of the profiles of userHandle including
1019     * userHandle itself.
1020     * Note that this returns only enabled.
1021     *
1022     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1023     * @param userHandle profiles of this user will be returned.
1024     * @return the list of profiles.
1025     * @hide
1026     */
1027    public List<UserInfo> getEnabledProfiles(int userHandle) {
1028        try {
1029            return mService.getProfiles(userHandle, true /* enabledOnly */);
1030        } catch (RemoteException re) {
1031            Log.w(TAG, "Could not get user list", re);
1032            return null;
1033        }
1034    }
1035
1036    /**
1037     * Returns a list of UserHandles for profiles associated with the user that the calling process
1038     * is running on, including the user itself.
1039     *
1040     * @return A non-empty list of UserHandles associated with the calling user.
1041     */
1042    public List<UserHandle> getUserProfiles() {
1043        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
1044        List<UserInfo> users = new ArrayList<UserInfo>();
1045        try {
1046            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1047        } catch (RemoteException re) {
1048            Log.w(TAG, "Could not get user list", re);
1049            return null;
1050        }
1051        for (UserInfo info : users) {
1052            UserHandle userHandle = new UserHandle(info.id);
1053            profiles.add(userHandle);
1054        }
1055        return profiles;
1056    }
1057
1058    /**
1059     * Returns the parent of the profile which this method is called from
1060     * or null if called from a user that is not a profile.
1061     *
1062     * @hide
1063     */
1064    public UserInfo getProfileParent(int userHandle) {
1065        try {
1066            return mService.getProfileParent(userHandle);
1067        } catch (RemoteException re) {
1068            Log.w(TAG, "Could not get profile parent", re);
1069            return null;
1070        }
1071    }
1072
1073    /**
1074     * If the target user is a managed profile of the calling user or the caller
1075     * is itself a managed profile, then this returns a badged copy of the given
1076     * icon to be able to distinguish it from the original icon. For badging an
1077     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1078     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1079     * <p>
1080     * If the original drawable is a BitmapDrawable and the backing bitmap is
1081     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1082     * is performed in place and the original drawable is returned.
1083     * </p>
1084     *
1085     * @param icon The icon to badge.
1086     * @param user The target user.
1087     * @return A drawable that combines the original icon and a badge as
1088     *         determined by the system.
1089     * @removed
1090     */
1091    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1092        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1093    }
1094
1095    /**
1096     * If the target user is a managed profile of the calling user or the caller
1097     * is itself a managed profile, then this returns a badged copy of the given
1098     * drawable allowing the user to distinguish it from the original drawable.
1099     * The caller can specify the location in the bounds of the drawable to be
1100     * badged where the badge should be applied as well as the density of the
1101     * badge to be used.
1102     * <p>
1103     * If the original drawable is a BitmapDrawable and the backing bitmap is
1104     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1105     * is performed in place and the original drawable is returned.
1106     * </p>
1107     *
1108     * @param badgedDrawable The drawable to badge.
1109     * @param user The target user.
1110     * @param badgeLocation Where in the bounds of the badged drawable to place
1111     *         the badge. If not provided, the badge is applied on top of the entire
1112     *         drawable being badged.
1113     * @param badgeDensity The optional desired density for the badge as per
1114     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1115     *         the density of the display is used.
1116     * @return A drawable that combines the original drawable and a badge as
1117     *         determined by the system.
1118     * @removed
1119     */
1120    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1121            Rect badgeLocation, int badgeDensity) {
1122        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1123                badgeLocation, badgeDensity);
1124    }
1125
1126    /**
1127     * If the target user is a managed profile of the calling user or the caller
1128     * is itself a managed profile, then this returns a copy of the label with
1129     * badging for accessibility services like talkback. E.g. passing in "Email"
1130     * and it might return "Work Email" for Email in the work profile.
1131     *
1132     * @param label The label to change.
1133     * @param user The target user.
1134     * @return A label that combines the original label and a badge as
1135     *         determined by the system.
1136     * @removed
1137     */
1138    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1139        return mContext.getPackageManager().getUserBadgedLabel(label, user);
1140    }
1141
1142    /**
1143     * Returns information for all users on this device. Requires
1144     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1145     *
1146     * @param excludeDying specify if the list should exclude users being
1147     *            removed.
1148     * @return the list of users that were created.
1149     * @hide
1150     */
1151    public List<UserInfo> getUsers(boolean excludeDying) {
1152        try {
1153            return mService.getUsers(excludeDying);
1154        } catch (RemoteException re) {
1155            Log.w(TAG, "Could not get user list", re);
1156            return null;
1157        }
1158    }
1159
1160    /**
1161     * Removes a user and all associated data.
1162     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1163     * @param userHandle the integer handle of the user, where 0 is the primary user.
1164     * @hide
1165     */
1166    public boolean removeUser(int userHandle) {
1167        try {
1168            return mService.removeUser(userHandle);
1169        } catch (RemoteException re) {
1170            Log.w(TAG, "Could not remove user ", re);
1171            return false;
1172        }
1173    }
1174
1175    /**
1176     * Updates the user's name.
1177     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1178     *
1179     * @param userHandle the user's integer handle
1180     * @param name the new name for the user
1181     * @hide
1182     */
1183    public void setUserName(int userHandle, String name) {
1184        try {
1185            mService.setUserName(userHandle, name);
1186        } catch (RemoteException re) {
1187            Log.w(TAG, "Could not set the user name ", re);
1188        }
1189    }
1190
1191    /**
1192     * Sets the user's photo.
1193     * @param userHandle the user for whom to change the photo.
1194     * @param icon the bitmap to set as the photo.
1195     * @hide
1196     */
1197    public void setUserIcon(int userHandle, Bitmap icon) {
1198        try {
1199            mService.setUserIcon(userHandle, icon);
1200        } catch (RemoteException re) {
1201            Log.w(TAG, "Could not set the user icon ", re);
1202        }
1203    }
1204
1205    /**
1206     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
1207     * @param userHandle the user whose photo we want to read.
1208     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
1209     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
1210     * @hide
1211     */
1212    public Bitmap getUserIcon(int userHandle) {
1213        try {
1214            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
1215            if (fd != null) {
1216                try {
1217                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
1218                } finally {
1219                    try {
1220                        fd.close();
1221                    } catch (IOException e) {
1222                    }
1223                }
1224            }
1225        } catch (RemoteException re) {
1226            Log.w(TAG, "Could not get the user icon ", re);
1227        }
1228        return null;
1229    }
1230
1231    /**
1232     * Returns the maximum number of users that can be created on this device. A return value
1233     * of 1 means that it is a single user device.
1234     * @hide
1235     * @return a value greater than or equal to 1
1236     */
1237    public static int getMaxSupportedUsers() {
1238        // Don't allow multiple users on certain builds
1239        if (android.os.Build.ID.startsWith("JVP")) return 1;
1240        // Svelte devices don't get multi-user.
1241        if (ActivityManager.isLowRamDeviceStatic()) return 1;
1242        return SystemProperties.getInt("fw.max_users",
1243                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1244    }
1245
1246    /**
1247     * Returns true if the user switcher should be shown, this will be if there
1248     * are multiple users that aren't managed profiles.
1249     * @hide
1250     * @return true if user switcher should be shown.
1251     */
1252    public boolean isUserSwitcherEnabled() {
1253        List<UserInfo> users = getUsers(true);
1254        if (users == null) {
1255           return false;
1256        }
1257        int switchableUserCount = 0;
1258        for (UserInfo user : users) {
1259            if (user.supportsSwitchTo()) {
1260                ++switchableUserCount;
1261            }
1262        }
1263        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1264                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1265        return switchableUserCount > 1 || guestEnabled;
1266    }
1267
1268    /**
1269     * Returns a serial number on this device for a given userHandle. User handles can be recycled
1270     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
1271     * @param userHandle
1272     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
1273     * @hide
1274     */
1275    public int getUserSerialNumber(int userHandle) {
1276        try {
1277            return mService.getUserSerialNumber(userHandle);
1278        } catch (RemoteException re) {
1279            Log.w(TAG, "Could not get serial number for user " + userHandle);
1280        }
1281        return -1;
1282    }
1283
1284    /**
1285     * Returns a userHandle on this device for a given user serial number. User handles can be
1286     * recycled when deleting and creating users, but serial numbers are not reused until the device
1287     * is wiped.
1288     * @param userSerialNumber
1289     * @return the userHandle associated with that user serial number, or -1 if the serial number
1290     * is not valid.
1291     * @hide
1292     */
1293    public int getUserHandle(int userSerialNumber) {
1294        try {
1295            return mService.getUserHandle(userSerialNumber);
1296        } catch (RemoteException re) {
1297            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
1298        }
1299        return -1;
1300    }
1301
1302    /**
1303     * Returns a Bundle containing any saved application restrictions for this user, for the
1304     * given package name. Only an application with this package name can call this method.
1305     * @param packageName the package name of the calling application
1306     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
1307     * saved restrictions. The values can be of type Boolean, String or String[], depending
1308     * on the restriction type, as defined by the application.
1309     */
1310    public Bundle getApplicationRestrictions(String packageName) {
1311        try {
1312            return mService.getApplicationRestrictions(packageName);
1313        } catch (RemoteException re) {
1314            Log.w(TAG, "Could not get application restrictions for package " + packageName);
1315        }
1316        return null;
1317    }
1318
1319    /**
1320     * @hide
1321     */
1322    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1323        try {
1324            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1325        } catch (RemoteException re) {
1326            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1327        }
1328        return null;
1329    }
1330
1331    /**
1332     * @hide
1333     */
1334    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1335            UserHandle user) {
1336        try {
1337            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1338        } catch (RemoteException re) {
1339            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1340        }
1341    }
1342
1343    /**
1344     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1345     * apps and requires the MANAGE_USERS permission.
1346     * @param newPin the PIN to use for challenge dialogs.
1347     * @return Returns true if the challenge PIN was set successfully.
1348     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1349     * This method is preserved for backwards compatibility reasons and always returns false.
1350     */
1351    public boolean setRestrictionsChallenge(String newPin) {
1352        return false;
1353    }
1354
1355    /** @hide */
1356    public void removeRestrictions() {
1357        try {
1358            mService.removeRestrictions();
1359        } catch (RemoteException re) {
1360            Log.w(TAG, "Could not change restrictions pin");
1361        }
1362    }
1363
1364    /**
1365     * @hide
1366     * Set restrictions that should apply to any future guest user that's created.
1367     */
1368    public void setDefaultGuestRestrictions(Bundle restrictions) {
1369        try {
1370            mService.setDefaultGuestRestrictions(restrictions);
1371        } catch (RemoteException re) {
1372            Log.w(TAG, "Could not set guest restrictions");
1373        }
1374    }
1375
1376    /**
1377     * @hide
1378     * Gets the default guest restrictions.
1379     */
1380    public Bundle getDefaultGuestRestrictions() {
1381        try {
1382            return mService.getDefaultGuestRestrictions();
1383        } catch (RemoteException re) {
1384            Log.w(TAG, "Could not set guest restrictions");
1385        }
1386        return new Bundle();
1387    }
1388
1389    /**
1390     * Returns creation time of the user or of a managed profile associated with the calling user.
1391     * @param userHandle user handle of the user or a managed profile associated with the
1392     *                   calling user.
1393     * @return creation time in milliseconds since Epoch time.
1394     */
1395    public long getUserCreationTime(UserHandle userHandle) {
1396        try {
1397            return mService.getUserCreationTime(userHandle.getIdentifier());
1398        } catch (RemoteException re) {
1399            Log.w(TAG, "Could not get user creation time", re);
1400            return 0;
1401        }
1402    }
1403}
1404