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