UserManager.java revision ada8deb43649aed879ceba28daee4af69ae0cc8d
1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/*
2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project
3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License");
5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License.
6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at
7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *      http://www.apache.org/licenses/LICENSE-2.0
9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software
11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS,
12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and
14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License.
15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
168a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey
17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os;
18258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
19b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.Manifest;
2002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolovimport android.accounts.AccountManager;
21e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport android.annotation.IntDef;
22ada8deb43649aed879ceba28daee4af69ae0cc8dAdam Lesinskiimport android.annotation.NonNull;
237cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable;
24b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.annotation.RequiresPermission;
250e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
26e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onukiimport android.annotation.TestApi;
278588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkeyimport android.annotation.UserIdInt;
284e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolovimport android.annotation.WorkerThread;
2937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasaniimport android.app.Activity;
30409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
31cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager;
32068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName;
33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
3412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasaniimport android.content.Intent;
358bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talaveraimport android.content.IntentFilter;
36f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franzimport android.content.IntentSender;
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
3827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
396794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
401bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
424f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
431e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
44523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolovimport android.telephony.TelephonyManager;
451c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
476794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
48aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reckimport com.android.internal.os.RoSystemProperties;
496794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
501bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
51e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.Retention;
52e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.RetentionPolicy;
534f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
54258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
55258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
56258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
570696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Manages users and user details on a multi-user system. There are two major categories of
580696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * users: fully customizable users with their own login, and managed profiles that share a workspace
590696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * with a related user.
600696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p>
610696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Users are different from accounts, which are managed by
620696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * {@link AccountManager}. Each user can have their own set of accounts.
630696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p>
640696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
65258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
66258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
67258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
684f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov    private static final String TAG = "UserManager";
69258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
70258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
71258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
72d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki    private Boolean mIsManagedProfileCached;
73d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
75e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
76e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * No user restriction.
77e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
78e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
79e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_NOT_SET = 0x0;
80e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
81e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
82e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
83e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by system/user.
84e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
85e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
86e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
87e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
88e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
89e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
90e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by a device owner.
91e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
92e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
93e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
94e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
95e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
96e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
97e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by a profile owner.
98e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
99e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
100e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
101e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
102e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /** @hide */
103e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @Retention(RetentionPolicy.SOURCE)
104e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM,
105e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER})
106e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
107e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public @interface UserRestrictionSource {}
108e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
109e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
11053019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Specifies if a user is disallowed from adding and removing accounts, unless they are
11153019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
11253019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Authenticator.
11371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
11426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
115b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
116b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
117b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * management is disallowed.
118b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     *
1190ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1200ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
121068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
122068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
123e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
124e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
12571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
126e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
127e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
12826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
1292cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
1300ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect in a managed profile.
13126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1320ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1330ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
134068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
135068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
136e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
137e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
13871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
139e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
140e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
14126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
14271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
14326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1450ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
146068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
147068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
148e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
149e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
15071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
151e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
152e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
15326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
15471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
15526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
158068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
159068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
160e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
161e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
16271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
163e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
16471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
165150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
16671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
1670ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>In a managed profile, location sharing always reflects the primary user's setting, but
168150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
16926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1710ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
172068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
173068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1746794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1756794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
17671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1776794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
178a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
17926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
180a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
181a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
18226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1840ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
185068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
186068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
187a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
188a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
189a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
190a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
191a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
19226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1931c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
194a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
19563d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
19663d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
1970ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect in a managed profile.
19826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2000ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
201068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
202068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
203a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
204a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
205a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
206a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
207a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
20863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * Specifies if bluetooth is disallowed on the device.
20963d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     *
21063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p> This restriction can only be set by the device owner and the profile owner on the
21163d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
21263d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>The default value is <code>false</code>.
21363d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>Key for user restrictions.
21463d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>Type: Boolean
21563d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
21663d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
21763d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see #getUserRestrictions()
21863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     */
21963d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova    public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
22063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova
22163d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova    /**
2224f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * Specifies if outgoing bluetooth sharing is disallowed on the device. Device owner and profile
2234f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * owner can set this restriction. When it is set by device owner, all users on this device will
2244f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * be affected.
2254f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     *
2264f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * <p>Default is <code>true</code> for managed profiles and false for otherwise. When a device
2274f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * upgrades to {@link android.os.Build.VERSION_CODES#O}, the system sets it for all existing
2284f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * managed profiles.
2294f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     *
2304f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * <p>Key for user restrictions.
2314f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * <p>Type: Boolean
2324f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
2334f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
2344f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     * @see #getUserRestrictions()
2354f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov     */
2364f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov    public static final String DISALLOW_BLUETOOTH_SHARING = "no_bluetooth_sharing";
2374f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov
2384f4f6f83c20162814e95e9ca0654eee89a818bdePavel Grafov    /**
23926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
240c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
241c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
24226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
245068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
246068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
247a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
248a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
249a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
250a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
251b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
253b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
25426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2550ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
257068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
258068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
259b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
260b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
261b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
262b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
263b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
264150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
265150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
266150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
267150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
26826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
271068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
272068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
273b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
274b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
275b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
276b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
277d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
2786c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if managed profiles of this user can be removed, other than by its profile owner.
2796c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * The default value is <code>false</code>.
2806c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>
2812ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * This restriction has no effect on managed profiles.
2826c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     *
2836c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Key for user restrictions.
2846c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Type: Boolean
2856c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
2866c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
2876c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see #getUserRestrictions()
2886c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     */
2896c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
2906c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera
2916c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    /**
29226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
293d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
29426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
297068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
298068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
299d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
300d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
301d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
302d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
303d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
30426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
306298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
3070e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn     * {@link android.os.Build.VERSION_CODES#M}
30826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3100ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
311068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
312068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
313d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
314d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
315d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
316d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
317d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
31826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
319c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
320c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3230ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
324068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
325068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
326d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
327d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
328d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
329d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
330d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
331e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
332e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
333e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
3340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
335e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
336e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
3370ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3380ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
339068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
340068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
341e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
342e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
343e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
344e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
345e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
34626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
347c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
348c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
3490ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
350150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
35126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3520ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3530ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
354068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
355068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
356d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
357d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
358d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
359d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
360d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
3616c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if a user is disallowed from adding new users. This can only be set by device
3626c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * owners and profile owners on the primary user.
363c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
3640ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
365150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
36626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3670ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3680ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
369068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
370068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
371d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
372d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
373d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
374d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
375d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
3766c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if a user is disallowed from adding managed profiles.
3776c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>The default value for an unmanaged user is <code>false</code>.
3782ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * For users with a device owner set, the default is <code>true</code>.
3792ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * <p>This restriction has no effect on managed profiles.
3806c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     *
3816c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Key for user restrictions.
3826c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Type: Boolean
3836c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
3846c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
3856c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see #getUserRestrictions()
3866c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     */
3876c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
3886c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera
3896c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    /**
3909f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu     * Specifies if a user is disallowed from disabling application verification.
3919f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu     * Starting from {@link android.os.Build.VERSION_CODES#O}, application verification
3929f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu     * is enforced across all users on the device if a profile owner or device owner sets
3939f592dbca32c698cabcf38a5e07cbb118fbf44ddRubin Xu     * this restriction to <code>true</code>. The default value is <code>false</code>.
39426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
397068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
398068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
399d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
400d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
401d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
402d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
403d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
40426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
405c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
406c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
4070ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
408150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
40926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4100ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4110ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
412068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
413068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
414d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
415d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
416d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
417d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
418d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
41926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
420c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
421c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
4220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
423150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
42426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4250ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4260ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
427068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
428068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
429d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
430d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
431d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
432d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
433d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
43426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
435c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
436c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
437c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
438c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
439c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
440c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
441c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
442c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
443c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
444c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
44526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4468bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * <p><strong>Note:</strong> The user will still be able to perform those actions via other
4478bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * means (such as adb). Third party apps will also be able to uninstall apps via the
4488bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
4498bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
4508bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * used to prevent the user from uninstalling apps completely, and
4518bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
4528bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * to add a default intent handler for a given intent filter.
4538bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     *
4540ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4550ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
456068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
457068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
458d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
459d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
46036fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
461d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
462394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
46326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
464c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
465c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
46626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4670ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4680ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
469068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
470068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
471394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
472394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
473394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
474394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
475394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
476ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone
477ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * will be muted. This can be set by device owners and profile owners. The default value is
478ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * <code>false</code>.
47926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
480ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * <p>This restriction has no effect on managed profiles.
4810ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4820ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
483068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
484068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
485394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
486394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
487394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
488394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
489394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
490ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * Specifies if a user is disallowed from adjusting the master volume. If set, the master volume
491ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * will be muted. This can be set by device owners and profile owners. The default value is
492ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * <code>false</code>.
49326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
494ce3e1a3c5fb881ebdea6ba219dae68c9b63ba108Pavel Grafov     * <p>This restriction has no effect on managed profiles.
4950ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
497068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
498068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
499394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
500394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
501394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
502394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
5039f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
50426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
505390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
506390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
507eb83ab52b28766adf1743db76484515bc9b9e08aTony Mak     * <p>This restriction has no effect on managed profiles.
50826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5090ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5100ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
511068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
512068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
513390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
514390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
515390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
516390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
517390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
51826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
519c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
52026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5210ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5220ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
523068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
524068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5259f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
5269f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
527390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
5289f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
5291c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
5302cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
5312cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
5322cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
5332cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
5340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5350ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
536068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
537068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5382cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
5392cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
5402cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
5412cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
5422cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
54326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
5441c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
5451c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
5461c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
5471c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
5481c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
5491c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
5501c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
5515cd907d3d6ceebf8731ef1f69347cce6f76109e9Wale Ogunwale     * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
5521c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
553c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
554c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
55526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
558068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
559068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5601c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
5611c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
5621c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
5631c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
564f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
56526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
566f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
567f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
568f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
56926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5710ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
572068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
573068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
574f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
575f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
576f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
577f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
57826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
57926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
58026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
58126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5820ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
584068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
585068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
58626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
58726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
58826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
58926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
59053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
591f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
592f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * generally means that wallpapers are not supported for the particular user. This user
593f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * restriction is always set for managed profiles, because such profiles don't have wallpapers.
594f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
595f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see #DISALLOW_SET_WALLPAPER
596068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
597068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
598f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
599f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
600f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
601f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
602f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
603f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * User restriction to disallow setting a wallpaper. Profile owner and device owner
604f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * are able to set wallpaper regardless of this restriction.
605f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * The default value is <code>false</code>.
606f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     *
607f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * <p>Key for user restrictions.
608f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * <p>Type: Boolean
609f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
610f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
611f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see #getUserRestrictions()
612f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     */
613f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi    public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
614f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi
615f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi    /**
616bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
617bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
618bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
619bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
6200ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
6210ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
622068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
623068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
624bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
625bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
626bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
627bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
628bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
629b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
630b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
631b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
632068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
633068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
634b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
635b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
636b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
637b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
638b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
639b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
6409cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * Specifies if a user is not allowed to run in the background and should be stopped during
6419cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * user switch. The default value is <code>false</code>.
6429cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
6439cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * <p>This restriction can be set by device owners and profile owners.
6449cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
6459cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
6469cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
6479cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see #getUserRestrictions()
6489cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @hide
6499cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     */
6509cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
6519cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov
6529cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    /**
653759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * Specifies if a user is not allowed to use the camera.
654759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     *
655759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
656759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
657759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see #getUserRestrictions()
658759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @hide
659759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     */
660759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    public static final String DISALLOW_CAMERA = "no_camera";
661759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki
662759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    /**
663c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * Specifies if a user is not allowed to unmute the device's master volume.
664c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     *
665c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
666c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
667c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see #getUserRestrictions()
668c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @hide
669c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     */
670492b4724fb42adf29f3978f01ebc5238f893d194Esteban Talavera    public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
671c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak
672c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak    /**
673dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
674dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * device owners. The default value is <code>false</code>.
675dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     *
676dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
677dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
678dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see #getUserRestrictions()
679dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     */
680dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra    public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
681dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra
682dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra    /**
6837f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * Specifies if a user is not allowed to change their icon. Device owner and profile owner
6847f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * can set this restriction. When it is set by device owner, only the target user will be
6857f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * affected. The default value is <code>false</code>.
6867f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     *
6877f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * <p>Key for user restrictions.
6887f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * <p>Type: Boolean
6897f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
6907f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
6917f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see #getUserRestrictions()
6927f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     */
6937f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi    public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
6947f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi
6957f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi    /**
6963d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
697c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera     * <code>false</code>. Setting this restriction has no effect if the bootloader is already
698c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera     * unlocked.
6993d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     *
70012b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova     * <p>Not for use by third-party applications.
70112b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova     *
7023d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
7033d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
7043d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see #getUserRestrictions()
7053b8b46f3a46ccf35a6bb6a828af0f2d011cc9abeAndrew Scull     * @deprecated use {@link OemLockManager#setOemUnlockAllowedByCarrier(boolean, byte[])} instead.
7063d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @hide
7073d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     */
7083b8b46f3a46ccf35a6bb6a828af0f2d011cc9abeAndrew Scull    @Deprecated
70912b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova    @SystemApi
7103d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra    public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
7113d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra
7123d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra    /**
713f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     * Allows apps in the parent profile to handle web links from the managed profile.
714f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     *
7159edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * This user restriction has an effect only in a managed profile.
7169edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * If set:
7179edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * Intent filters of activities in the parent profile with action
7189edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * {@link android.content.Intent#ACTION_VIEW},
7199edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
7209edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * define a host can handle intents from the managed profile.
7219edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * The default value is <code>false</code>.
7229edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     *
7230ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
7240ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
725068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
726068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
7279edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #getUserRestrictions()
7289edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     */
729f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
730f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot            = "allow_parent_profile_app_linking";
7319edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot
7329edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot    /**
73324d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * Specifies if a user is not allowed to use Autofill Services.
73424d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     *
73524d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * <p>Device owner and profile owner can set this restriction. When it is set by device owner,
73624d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * only the target user will be affected.
73724d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     *
73824d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * <p>The default value is <code>false</code>.
73924d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     *
74024d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
74124d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
74224d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     * @see #getUserRestrictions()
74324d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme     */
74424d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme    public static final String DISALLOW_AUTOFILL = "no_autofill";
74524d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme
74624d5893b25ce62b7bc9ed9f35fa72b9d47f23cddFelipe Leme    /**
74753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
74853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
74953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
75053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
75153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
75253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
75353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
75453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
75553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
75653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
7570ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for application restrictions.
7580ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
759b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
760b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
761b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
762b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
76353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
76453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
76553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
76612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
76712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
76812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
76912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing a name for the user being created. Optional parameter passed to
77012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
77112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
77212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
77312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
77412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
77512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
77612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account name for the user being created. Optional parameter passed to
77712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
77812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
77912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
78012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
78112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
78212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
78312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account type for the user being created. Optional parameter passed to
78412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
78512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
78612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
78712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
78812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
78912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
79012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account-specific data for the user being created. Optional parameter passed
79112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * to ACTION_CREATE_USER activity.
79212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
79312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
79412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_OPTIONS
79512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            = "android.os.extra.USER_ACCOUNT_OPTIONS";
79612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
797655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
798655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
799655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
800655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
801655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
802655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
803655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
80437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    /**
805e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     * Sent when user restrictions have changed.
806e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     *
807e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     * @hide
808e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     */
809e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    @SystemApi
810e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    @TestApi // To allow seeing it from CTS.
811e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    public static final String ACTION_USER_RESTRICTIONS_CHANGED =
812e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki            "android.os.action.USER_RESTRICTIONS_CHANGED";
813e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki
814e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    /**
81537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * Error result indicating that this user is not allowed to add other users on this device.
81637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * This is a result code returned from the activity created by the intent
81737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
81837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     */
81937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
82037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani
82137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    /**
82237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * Error result indicating that no more users can be created on this device.
82337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * This is a result code returned from the activity created by the intent
82437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
82537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     */
82637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
82737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani
8287e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
829c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani    public static UserManager get(Context context) {
830c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani        return (UserManager) context.getSystemService(Context.USER_SERVICE);
83127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
832a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
833258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
834258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
835258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
8365200e1cb07190a1f6874d72a4561064cad3ee3e0Fyodor Kupolov        mContext = context.getApplicationContext();
837258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
838258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
839258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8400696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Returns whether this device supports multiple users with their own login and customizable
8410696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * space.
8420696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @return whether the device supports multiple users.
843258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
8444673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
8451a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
8461a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
8471a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
848258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
849258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
8506794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
8517cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @hide
8527cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @return Whether the device is running with split system user. It means the system user and
8537cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * primary user are two separate users. Previously system user and primary user are combined as
8547cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
8557cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     */
8567cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public static boolean isSplitSystemUser() {
857aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reck        return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
8587cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    }
8597cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen
8607cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    /**
86113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @return Whether guest user is always ephemeral
86213a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @hide
86313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     */
86413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    public static boolean isGuestUserEphemeral() {
86513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        return Resources.getSystem()
86613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky                .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
86713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    }
86813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky
86913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    /**
870523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * Returns whether switching users is currently allowed.
871523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * <p>For instance switching users is not allowed if the current user is in a phone call,
872523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * or system user hasn't been unlocked yet
873523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * @hide
874523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     */
875523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    public boolean canSwitchUsers() {
876523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
877523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                mContext.getContentResolver(),
878523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
879523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
880523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean inCall = TelephonyManager.getDefault().getCallState()
881523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                != TelephonyManager.CALL_STATE_IDLE;
882523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall;
883523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    }
884523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov
885523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    /**
8865760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
887be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
8885760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
889258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
8906794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
8918588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @UserIdInt int getUserHandle() {
89279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
893258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
894258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
895258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8968832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
8978832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
8988832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
899258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
900258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
901258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
902258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
903258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
904258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
905605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov            throw re.rethrowFromSystemServer();
906605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov        }
907605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov    }
908605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov
909605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov    /**
910605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov     * Returns whether user name has been set.
911605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov     * <p>This method can be used to check that the value returned by {@link #getUserName()} was
912605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov     * set by the user and is not a placeholder string provided by the system.
913605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov     * @hide
914605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov     */
915605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov    public boolean isUserNameSet() {
916605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov        try {
917605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov            return mService.isUserNameSet(getUserHandle());
918605b12a6d0110c81d63e78e93f299a6b5753da46Fyodor Kupolov        } catch (RemoteException re) {
919f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
920258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
921258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
922258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
92367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
924e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
925e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
92667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
927955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
92867a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
92967a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
93067a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
931e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
932e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
933988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
934988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
935e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
936df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
937df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
93870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Used to check if this process is running under the primary user. The primary user
93970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * is the first human user on a device.
94070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
94170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return whether this process is running under the primary user.
94270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
94370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
94470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    public boolean isPrimaryUser() {
94570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        UserInfo user = getUserInfo(UserHandle.myUserId());
946d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani        return user != null && user.isPrimary();
94770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
94870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
94970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
9505760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
9515760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
9525760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
9535760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
9545760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
9555760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
9565760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
95770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
9585760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
9592b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
9605760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
961462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * @hide
962462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * Returns whether the caller is running as an admin user. There can be more than one admin
963462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * user.
964462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     */
965462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    public boolean isAdminUser() {
9662b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return isUserAdmin(UserHandle.myUserId());
9672b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    }
9682b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
9692b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    /**
9702b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * @hide
9712b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * Returns whether the provided user is an admin user. There can be more than one admin
9722b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * user.
9732b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     */
9748588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserAdmin(@UserIdInt int userId) {
9752b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        UserInfo user = getUserInfo(userId);
9762b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return user != null && user.isAdmin();
977462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    }
978462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani
979462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    /**
980e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
98146bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
982e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
9832555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
984df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
985e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
986df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
98771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
988df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
989f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
990df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
991df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
992df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
993258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
9941c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * Checks if specified user can have restricted profile.
9951c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * @hide
9961c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     */
9978588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
9981c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        try {
9991c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return mService.canHaveRestrictedProfile(userId);
10001c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        } catch (RemoteException re) {
1001f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
10021c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        }
10031c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    }
10041c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov
10051c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    /**
100613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * Checks if a user is a guest user.
100713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @return whether user is a guest user.
100813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @hide
100913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     */
101013a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    public boolean isGuestUser(int id) {
101113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        UserInfo user = getUserInfo(id);
101213a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        return user != null && user.isGuest();
101313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    }
101413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky
101513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    /**
10161e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
10171e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
10181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
10191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
10201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
10211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
1022d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani        return user != null && user.isGuest();
1023d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    }
1024d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani
1025d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    /**
10261c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     * Checks if the calling app is running in a demo user. When running in a demo user,
10271c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     * apps can be more helpful to the user, or explain their features in more detail.
10281c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     *
1029d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani     * @return whether the caller is a demo user.
1030d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani     */
1031d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    public boolean isDemoUser() {
10321c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        try {
10331c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani            return mService.isDemoUser(UserHandle.myUserId());
10341c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        } catch (RemoteException re) {
10351c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani            throw re.rethrowFromSystemServer();
10361c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        }
10371e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
10381e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
10391e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
10400e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
10410e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
10420e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
10430e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
10440e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
10450e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
10460e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
10470e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
1048d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        // No need for synchronization.  Once it becomes non-null, it'll be non-null forever.
1049d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        // Worst case we might end up calling the AIDL method multiple times but that's fine.
1050d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        if (mIsManagedProfileCached != null) {
1051d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return mIsManagedProfileCached;
1052d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        }
10538673b2899e775014336efff44ea88dcac2b25bddTony Mak        try {
1054d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1055d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return mIsManagedProfileCached;
10568673b2899e775014336efff44ea88dcac2b25bddTony Mak        } catch (RemoteException re) {
10578673b2899e775014336efff44ea88dcac2b25bddTony Mak            throw re.rethrowFromSystemServer();
10588673b2899e775014336efff44ea88dcac2b25bddTony Mak        }
10598673b2899e775014336efff44ea88dcac2b25bddTony Mak    }
10608673b2899e775014336efff44ea88dcac2b25bddTony Mak
10618673b2899e775014336efff44ea88dcac2b25bddTony Mak    /**
10628673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Checks if the specified user is a managed profile.
10638673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
10648673b2899e775014336efff44ea88dcac2b25bddTony Mak     * must be in the same profile group of specified user.
10658673b2899e775014336efff44ea88dcac2b25bddTony Mak     *
10668673b2899e775014336efff44ea88dcac2b25bddTony Mak     * @return whether the specified user is a managed profile.
10678673b2899e775014336efff44ea88dcac2b25bddTony Mak     * @hide
10688673b2899e775014336efff44ea88dcac2b25bddTony Mak     */
10698673b2899e775014336efff44ea88dcac2b25bddTony Mak    @SystemApi
10708673b2899e775014336efff44ea88dcac2b25bddTony Mak    public boolean isManagedProfile(@UserIdInt int userId) {
1071d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        if (userId == UserHandle.myUserId()) {
1072d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return isManagedProfile();
1073d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        }
10748673b2899e775014336efff44ea88dcac2b25bddTony Mak        try {
10758673b2899e775014336efff44ea88dcac2b25bddTony Mak            return mService.isManagedProfile(userId);
10768673b2899e775014336efff44ea88dcac2b25bddTony Mak        } catch (RemoteException re) {
10778673b2899e775014336efff44ea88dcac2b25bddTony Mak            throw re.rethrowFromSystemServer();
10788673b2899e775014336efff44ea88dcac2b25bddTony Mak        }
10790e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
10800e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
10810e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
108202c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * Gets badge for a managed profile.
108302c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
108402c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * must be in the same profile group of specified user.
108502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     *
108602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * @return which badge to use for the managed profile badge id will be less than
108702c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     *         UserManagerService.getMaxManagedProfiles()
108802c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * @hide
108902c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     */
109002c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    public int getManagedProfileBadge(@UserIdInt int userId) {
109102c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        try {
109202c8990bd6125f05cb32561727d559dc9327a601Kenny Guy            return mService.getManagedProfileBadge(userId);
109302c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        } catch (RemoteException re) {
109402c8990bd6125f05cb32561727d559dc9327a601Kenny Guy            throw re.rethrowFromSystemServer();
109502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        }
109602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    }
109702c8990bd6125f05cb32561727d559dc9327a601Kenny Guy
109802c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    /**
1099c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Checks if the calling app is running as an ephemeral user.
1100c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     *
1101c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @return whether the caller is an ephemeral user.
1102c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
1103c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
1104c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    public boolean isEphemeralUser() {
1105c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return isUserEphemeral(UserHandle.myUserId());
1106c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
1107c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
1108c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
1109c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Returns whether the specified user is ephemeral.
1110c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
1111c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
11128588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserEphemeral(@UserIdInt int userId) {
1113c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        final UserInfo user = getUserInfo(userId);
1114c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return user != null && user.isEphemeral();
1115c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
1116c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
1117c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
1118a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
1119a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
1120a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
1121a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
1122a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
11235eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     *
11245eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
11255eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
11265eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * in order to check other profile's status.
11275eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * Since Android Nougat MR1 (SDK version >= 25;
11285eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
11295eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * it'll accept any {@link UserHandle} within the same profile group as the caller.
1130cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     *
1131a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
1132a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
11335eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
1134a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
11350e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey        return isUserRunning(user.getIdentifier());
11360e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey    }
11370e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey
11380e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey    /** {@hide} */
11392e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov    public boolean isUserRunning(@UserIdInt int userId) {
1140a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
11412e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov            return mService.isUserRunning(userId);
114227b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1143f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1144a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
1145a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
1146a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
1147a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
1148a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
1149a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
1150a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
1151a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
11525eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     *
11535eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
11545eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
11555eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * in order to check other profile's status.
11565eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * Since Android Nougat MR1 (SDK version >= 25;
11575eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
11585eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * it'll accept any {@link UserHandle} within the same profile group as the caller.
1159cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     *
1160a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
1161a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
11625eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
1163a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
1164a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
1165e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey            // TODO: reconcile stopped vs stopping?
1166dc589ac82b5fe2063f4cfd94c8ae26d43d5420a0Sudheer Shanka            return ActivityManager.getService().isUserRunning(
1167e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey                    user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
116827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1169f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1170a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
1171a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
1172a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
11730825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey    /**
1174cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * Return whether the calling user is running in an "unlocked" state.
1175cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1176cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * On devices with direct boot, a user is unlocked only after they've
1177cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * entered their credentials (such as a lock pattern or PIN). On devices
1178cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * without direct boot, a user is unlocked as soon as it starts.
1179cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1180cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is locked, only device-protected data storage is available.
1181cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is unlocked, both device-protected and credential-protected
1182cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * private app data storage is available.
11838a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     *
11848a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Intent#ACTION_USER_UNLOCKED
11858a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Context#createDeviceProtectedStorageContext()
1186b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     */
1187b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    public boolean isUserUnlocked() {
1188b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey        return isUserUnlocked(Process.myUserHandle());
1189b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    }
1190b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey
1191b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    /**
1192cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * Return whether the given user is running in an "unlocked" state.
1193cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1194cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * On devices with direct boot, a user is unlocked only after they've
1195cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * entered their credentials (such as a lock pattern or PIN). On devices
1196cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * without direct boot, a user is unlocked as soon as it starts.
1197cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1198cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is locked, only device-protected data storage is available.
1199cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is unlocked, both device-protected and credential-protected
1200cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * private app data storage is available.
1201cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * <p>Requires {@code android.permission.MANAGE_USERS} or
1202cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1203cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * must be the calling user or a managed profile associated with it.
1204b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     *
1205b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     * @param user to retrieve the unlocked state for.
12068a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Intent#ACTION_USER_UNLOCKED
12078a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Context#createDeviceProtectedStorageContext()
1208b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     */
1209b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    public boolean isUserUnlocked(UserHandle user) {
12100999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey        return isUserUnlocked(user.getIdentifier());
12110999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey    }
12120999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey
12130999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey    /** {@hide} */
12148588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserUnlocked(@UserIdInt int userId) {
1215ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        try {
12162e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov            return mService.isUserUnlocked(userId);
1217ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        } catch (RemoteException re) {
1218ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey            throw re.rethrowFromSystemServer();
1219ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        }
1220ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    }
1221ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey
1222ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    /** {@hide} */
1223ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1224ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        return isUserUnlockingOrUnlocked(user.getIdentifier());
1225ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    }
1226ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey
1227ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    /** {@hide} */
1228ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1229ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        try {
1230c413f7078d2a69badcb4a2326a4a3d55c25da020Fyodor Kupolov            return mService.isUserUnlockingOrUnlocked(userId);
1231ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        } catch (RemoteException re) {
1232ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey            throw re.rethrowFromSystemServer();
1233ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        }
1234b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    }
1235b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey
1236b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    /**
1237258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
12388673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1239258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
1240258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
1241258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1242b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
12438588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo getUserInfo(@UserIdInt int userHandle) {
1244258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1245258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
1246258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1247f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1248258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1249258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1250258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
125171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1252e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
1253e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *
1254e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * Returns who set a user restriction on a user.
1255e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1256e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @param restrictionKey the string key representing the restriction
1257e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1258e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1259e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *         {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1260e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *         and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
12616a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
1262e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
12636a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @Deprecated
1264e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
1265e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @UserRestrictionSource
1266e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1267e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        try {
1268e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1269e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        } catch (RemoteException re) {
1270e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            throw re.rethrowFromSystemServer();
1271e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        }
1272e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    }
1273e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
1274e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
12756a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @hide
12766a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     *
12776a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * Returns a list of users who set a user restriction on a given user.
12786a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
12796a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param restrictionKey the string key representing the restriction
12806a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
12816a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @return a list of user ids enforcing this restriction.
12826a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     */
12836a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @SystemApi
12846a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    public List<EnforcingUser> getUserRestrictionSources(
12856a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            String restrictionKey, UserHandle userHandle) {
12866a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        try {
12876a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
12886a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        } catch (RemoteException re) {
12896a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            throw re.rethrowFromSystemServer();
12906a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
12916a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    }
12926a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
12936a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    /**
129471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
129571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
129671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1297e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
1298e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
1299e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1300e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
130171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
130271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
130371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
130471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
130571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1306e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
1307e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
1308e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
1309e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
1310f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1311e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
1312e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1313e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
13143bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     /**
13153bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @hide
13163bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * Returns whether the given user has been disallowed from performing certain actions
13173bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * or setting certain settings through UserManager. This method disregards restrictions
13183bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * set by device policy.
13193bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param restrictionKey the string key representing the restriction
13203bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
13213bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     */
13223bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
13233bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        try {
13243bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban            return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
13253bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        } catch (RemoteException re) {
1326f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
13273bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        }
13283bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    }
13293bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban
133071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1331a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
1332a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
133371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1334a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
13353d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
1336e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
1337068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
1338e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1339e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
134071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1341a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
1342a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
134371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1344a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
13453d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
1346e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
1347068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
1348e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1349e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
135071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
135171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
1352be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
135371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
135471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
13553d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
13563d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
13573d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
13583d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
135971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
13603d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
136171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
1362068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        setUserRestriction(key, value, Process.myUserHandle());
136371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
136471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
136571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
136671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
136771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
1368be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
136971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
137071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
137171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
13723d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
13733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
13743d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
13753d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
137671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
13773d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
13786794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
1379b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
1380b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
1381b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
1382f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1383b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
13846794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
13856794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
1386258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1387a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
1388a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
13892b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
13902b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
13912b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
1392a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
1393a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
1394b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
1395b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
1396b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
1397b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
1398b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
1399b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
1400b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
1401b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
1402b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1403b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
1404b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
14058cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
14068cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
14078cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
14088cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
1409f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
14108cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
1411a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
1412a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
1413a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
141433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
1415b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
1416b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
141733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
1418b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
1419b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
142033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
142133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
142233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
142333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
142433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
142533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
142633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
142733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
142833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
142933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
143033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
143133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
143233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
143333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
143433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
143533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
1436ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
143733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
143833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
143933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
144033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
1441cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * Creates a user with the specified name and options. For non-admin users, default user
1442cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * restrictions are going to be applied.
14431952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1444258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1445258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
1446258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
1447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
1448258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1449258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
1450258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1451258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1452258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
1453cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        UserInfo user = null;
1454258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1455cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            user = mService.createUser(name, flags);
1456e9c440638e27a123a82feb5e4677ce1242785288phweiss            // TODO: Keep this in sync with
1457e9c440638e27a123a82feb5e4677ce1242785288phweiss            // UserManagerService.LocalService.createUserEvenWhenDisallowed
1458cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            if (user != null && !user.isAdmin()) {
1459068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1460068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
1461cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            }
1462258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1463f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1464258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1465cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        return user;
1466258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1467258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1468258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
14691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
14701e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
14711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
14721e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
14731e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
14741e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
1475068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        UserInfo guest = null;
1476068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        try {
1477068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1478068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            if (guest != null) {
1479068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                Settings.Secure.putStringForUser(context.getContentResolver(),
1480068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                        Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
1481bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
1482068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        } catch (RemoteException re) {
1483f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
14841e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
14851e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
14861e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
14871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
1488aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
14892a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
1490a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1491a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
1492a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
1493a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
14947cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param userHandle new user will be a profile of this user.
1495a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
14967cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @return the {@link UserInfo} object for the created user, or null if the user
14977cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *         could not be created.
1498a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
1499a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
15008588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
15017cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka        return createProfileForUser(name, flags, userHandle, null);
15027cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    }
15037cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka
15047cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    /**
15057cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
15067cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * any packages that should not be installed in the new profile by default, these packages can
15077cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * still be installed later by the user if needed.
15087cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *
15097cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param name the user's name
15107cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param flags flags that identify the type of user and other properties.
15117cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param userHandle new user will be a profile of this user.
15127cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param disallowedPackages packages that will not be installed in the profile being created.
15137cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *
15147cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @return the {@link UserInfo} object for the created user, or null if the user
15157cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *         could not be created.
15167cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @hide
15177cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     */
15187cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
15197cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka            String[] disallowedPackages) {
1520a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
15217cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka            return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
1522a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1523f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1524a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1525a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1526a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1527a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
15286dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * Similar to {@link #createProfileForUser(String, int, int, String[])}
15296c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
15306dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
15316dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     *
15326dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * @see #createProfileForUser(String, int, int, String[])
15336dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * @hide
15346dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     */
15356dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
15366dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            @UserIdInt int userHandle, String[] disallowedPackages) {
15376dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        try {
15386dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
15396dc428f677f2b80b085466961e9495972e1c88c9Tony Mak                    disallowedPackages);
15406dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        } catch (RemoteException re) {
15416dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            throw re.rethrowFromSystemServer();
15426dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        }
15436dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    }
15446dc428f677f2b80b085466961e9495972e1c88c9Tony Mak
15456dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    /**
154602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * Creates a restricted profile with the specified name. This method also sets necessary
154702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * restrictions and adds shared accounts.
154806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     *
154906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @param name profile's name
155006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @return UserInfo object for the created user, or null if the user could not be created.
155106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @hide
155206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     */
155306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    public UserInfo createRestrictedProfile(String name) {
155406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        try {
155502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserHandle parentUserHandle = Process.myUserHandle();
155602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserInfo user = mService.createRestrictedProfile(name,
155702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                    parentUserHandle.getIdentifier());
155802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            if (user != null) {
155902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
156002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                        UserHandle.of(user.id));
156106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            }
156202cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            return user;
156327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1564f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
156506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        }
156606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    }
156706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov
156806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    /**
15690696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Returns an intent to create a user for the provided name and account name. The name
15700696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * and account name will be used when the setup process for the new user is started.
15710696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
157212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * The intent should be launched using startActivityForResult and the return result will
157337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * indicate if the user consented to adding a new user and if the operation succeeded. Any
157437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * errors in creating the user will be returned in the result code. If the user cancels the
157537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
157637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * result code will be {@link Activity#RESULT_OK}.
15770696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
15780696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
15790696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * at all.
15800696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
158112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * The new user is created but not initialized. After switching into the user for the first
158212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * time, the preferred user name and account information are used by the setup process for that
158312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * user.
158412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
158512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param userName Optional name to assign to the user.
15860696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @param accountName Optional account name that will be used by the setup wizard to initialize
158712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                    the user.
158812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountType Optional account type for the account to be created. This is required
158912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                    if the account name is specified.
159012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountOptions Optional bundle of data to be passed in during account creation in the
159112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       new user via {@link AccountManager#addAccount(String, String, String[],
159212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
159312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       Handler)}.
15940696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @return An Intent that can be launched from an Activity.
159537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * @see #USER_CREATION_FAILED_NOT_PERMITTED
159637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * @see #USER_CREATION_FAILED_NO_MORE_USERS
15970696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @see #supportsMultipleUsers
159812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
159912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static Intent createUserCreationIntent(@Nullable String userName,
160012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            @Nullable String accountName,
160112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
160212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        Intent intent = new Intent(ACTION_CREATE_USER);
160312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (userName != null) {
160412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_NAME, userName);
160512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
160612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountName != null && accountType == null) {
160712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            throw new IllegalArgumentException("accountType must be specified if accountName is "
160812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani                    + "specified");
160912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
161012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountName != null) {
161112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
161212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
161312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountType != null) {
161412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
161512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
161612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountOptions != null) {
161712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
161812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
161912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        return intent;
162012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
162112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
162212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
162312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
162412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
162512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account name for user creation. Requires MANAGE_USERS permission.
162612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
162712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
162812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public String getSeedAccountName() {
162912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
163012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountName();
163112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1632f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
163312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
163412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
163512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
163612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
163712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
163812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
163912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account type for user creation. Requires MANAGE_USERS permission.
164012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
164112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
164212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public String getSeedAccountType() {
164312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
164412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountType();
164512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1646f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
164712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
164812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
164912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
165012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
165112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
165212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
165312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS
165412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * permission.
165512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @return Any options set by the requestor that created the user.
165612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
165712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
165812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public PersistableBundle getSeedAccountOptions() {
165912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
166012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountOptions();
166112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1662f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
166312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
166412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
166512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
166612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
166712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
166812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
166912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Called by a system activity to set the seed account information of a user created
167012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * through the user creation intent.
167112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param userId
167212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountName
167312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountType
167412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountOptions
167512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @see #createUserCreationIntent(String, String, String, PersistableBundle)
167612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
167712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public void setSeedAccountData(int userId, String accountName, String accountType,
167812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            PersistableBundle accountOptions) {
167912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
168012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
168112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani                    /* persist= */ true);
168212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1683f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
168412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
168512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
168612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
168712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
168812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
168912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Clears the seed information used to create this user. Requires MANAGE_USERS permission.
169012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
169112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
169212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public void clearSeedAccountData() {
169312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
169412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            mService.clearSeedAccountData();
169512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1696f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
169712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
169812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
169912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
170012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
17011df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
17021df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
17031df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
17041df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
17051df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
17061df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
17078588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean markGuestForDeletion(@UserIdInt int userHandle) {
17081df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
17091df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
17101df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
1711f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
17121df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
17131df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
17141df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
17151df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
1716df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
17171ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     *
17181ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
17191ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     *
17201ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * <p>Note that the default is true, it's only that managed profiles might not be enabled.
17211ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * Also ephemeral users can be disabled to indicate that their removal is in progress and they
17221ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
1723df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
1724df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
1725df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
1726df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
17278588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserEnabled(@UserIdInt int userHandle) {
1728df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
1729df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
173027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1731f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1732df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
1733df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
1734df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
1735df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
173685a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     * Evicts the user's credential encryption key from memory by stopping and restarting the user.
173785a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     *
173885a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     * @hide
173985a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     */
174085a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
174185a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        try {
174285a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull            mService.evictCredentialEncryptionKey(userHandle);
174385a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        } catch (RemoteException re) {
174485a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull            throw re.rethrowFromSystemServer();
174585a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        }
174685a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    }
174785a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull
174885a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    /**
1749b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
1750b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
1751b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
1752b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
1753b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
1754b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
1755b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
1756b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
1757d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * Returns information for all users on this device, including ones marked for deletion.
1758d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
1759d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * <p>
17601952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1761940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @return the list of users that exist on the device.
1762258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1763258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1764258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
1765258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1766920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
1767920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
1768f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1769920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
1770920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
1771920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
1772920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
1773940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * Returns serial numbers of all users on this device.
1774940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1775940e8577a1569140521fb605336997863529f7adFyodor Kupolov     *
1776940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @param excludeDying specify if the list should exclude users being removed.
1777940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @return the list of serial numbers of users that exist on the device.
1778940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @hide
1779940e8577a1569140521fb605336997863529f7adFyodor Kupolov     */
1780940e8577a1569140521fb605336997863529f7adFyodor Kupolov    @SystemApi
1781940e8577a1569140521fb605336997863529f7adFyodor Kupolov    public long[] getSerialNumbersOfUsers(boolean excludeDying) {
1782940e8577a1569140521fb605336997863529f7adFyodor Kupolov        try {
1783940e8577a1569140521fb605336997863529f7adFyodor Kupolov            List<UserInfo> users = mService.getUsers(excludeDying);
1784940e8577a1569140521fb605336997863529f7adFyodor Kupolov            long[] result = new long[users.size()];
1785940e8577a1569140521fb605336997863529f7adFyodor Kupolov            for (int i = 0; i < result.length; i++) {
1786940e8577a1569140521fb605336997863529f7adFyodor Kupolov                result[i] = users.get(i).serialNumber;
1787940e8577a1569140521fb605336997863529f7adFyodor Kupolov            }
1788940e8577a1569140521fb605336997863529f7adFyodor Kupolov            return result;
1789940e8577a1569140521fb605336997863529f7adFyodor Kupolov        } catch (RemoteException re) {
1790f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1791940e8577a1569140521fb605336997863529f7adFyodor Kupolov        }
1792940e8577a1569140521fb605336997863529f7adFyodor Kupolov    }
1793940e8577a1569140521fb605336997863529f7adFyodor Kupolov
1794940e8577a1569140521fb605336997863529f7adFyodor Kupolov    /**
1795b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @return the user's account name, null if not found.
1796b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @hide
1797b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     */
1798b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    @RequiresPermission( allOf = {
1799b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1800b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.MANAGE_USERS
1801b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    })
18028588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @Nullable String getUserAccount(@UserIdInt int userHandle) {
1803b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        try {
1804b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            return mService.getUserAccount(userHandle);
1805b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        } catch (RemoteException re) {
1806f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1807b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        }
1808b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    }
1809b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen
1810b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    /**
1811b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * Set account name for the given user.
1812b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @hide
1813b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     */
1814b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    @RequiresPermission( allOf = {
1815b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1816b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.MANAGE_USERS
1817b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    })
18188588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
1819b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        try {
1820b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            mService.setUserAccount(userHandle, accountName);
1821b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        } catch (RemoteException re) {
1822f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1823b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        }
1824b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    }
1825b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen
1826b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    /**
182770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Returns information for Primary user.
182870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
182970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
183070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return the Primary user, null if not found.
183170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
183270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
18337cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public @Nullable UserInfo getPrimaryUser() {
183470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        try {
183570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return mService.getPrimaryUser();
183670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        } catch (RemoteException re) {
1837f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
183870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        }
183970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
184070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
184170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
184295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
184395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
184495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
184595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
184695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
184795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
184895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
184995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
185095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
185195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
185295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
185395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
185495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
185595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
185695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
185795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
185895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
185995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
186095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
186195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
186272434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
186372434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
186407387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
186507387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * we could add a new managed profile to this user after removing the existing one.
186672434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
186772434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
186872434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
186972434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
18708588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
187172434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
187207387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot            return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
187372434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
1874f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
187572434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
187672434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
187772434b7088591828082dd952496d523ef3622de2Nicolas Prevot
187872434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
18792a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
18802a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
18814f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
18827f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
18834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
18842a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
18852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
18862a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
18872a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
18882a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
18898588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
1890a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
1891385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
1892a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1893f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1894a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1895a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1896a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1897a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
1898fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1899fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param userId one of the two user ids to check.
1900fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param otherUserId one of the two user ids to check.
1901fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @return true if the two user ids are in the same profile group.
1902fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @hide
1903fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     */
19048588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
1905fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        try {
1906fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return mService.isSameProfileGroup(userId, otherUserId);
1907fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        } catch (RemoteException re) {
1908f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1909fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        }
1910fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    }
1911fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen
1912fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    /**
19137f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
19147f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
19157f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
19167f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
19177f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
19187f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
19197f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
19207f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
19217f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
19228588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
19237f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
19247f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
19257f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
1926f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
19277f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
19287f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
19297f75da2405cd910854448bb3801f776e036f926aRuben Brunk
19307f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1931be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1932be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
19334f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
19344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
19354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
19364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
19377f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
19387f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        List<UserHandle> result = new ArrayList<>(userIds.length);
19397f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        for (int userId : userIds) {
19407f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov            result.add(UserHandle.of(userId));
19417f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        }
19427f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return result;
19437f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
19447f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
19457f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
19467f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * Returns a list of ids for profiles associated with the specified user including the user
19477f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * itself.
19487f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     *
19497f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @param userId      id of the user to return profiles for
19507f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
19517f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @return A non-empty list of ids of profiles associated with the specified user.
19527f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     *
19537f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19547f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19557f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
1956385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
19577f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov            return mService.getProfileIds(userId, enabledOnly);
1958385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1959f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1960385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
19617f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
19627f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
19637f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
19647f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @see #getProfileIds(int, boolean)
19657f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19667f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19677f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
19687f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return getProfileIds(userId, false /* enabledOnly */);
19697f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
19707f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
19717f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
19727f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @see #getProfileIds(int, boolean)
19737f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19747f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19757f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getEnabledProfileIds(@UserIdInt int userId) {
19767f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return getProfileIds(userId, true /* enabledOnly */);
19774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
19784f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
19797dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1980c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * Returns the device credential owner id of the profile from
1981c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * which this method is called, or userHandle if called from a user that
1982c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * is not a profile.
1983c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     *
1984c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * @hide
1985c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     */
19868588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
1987c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        try {
1988c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return mService.getCredentialOwnerProfile(userHandle);
1989c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        } catch (RemoteException re) {
1990f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1991c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        }
1992c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    }
1993c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales
1994c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    /**
1995be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1996be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1997be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1998be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1999be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
20008588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo getProfileParent(@UserIdInt int userHandle) {
2001be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
2002be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
2003be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
2004f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2005be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
2006be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
2007be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
2008be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
20090a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Set quiet mode of a managed profile.
20100a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
20110a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile.
20120a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param enableQuietMode Whether quiet mode should be enabled or disabled.
20130a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @hide
20140a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
20158588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
20160a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
20170a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            mService.setQuietModeEnabled(userHandle, enableQuietMode);
201827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
2019f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
20200a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
20210a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
20220a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
20230a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
20240a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Returns whether the given profile is in quiet mode or not.
20257881cf8f818317cc6efe4d6a4c42da94d6bab223Ricky Wai     * Notes: Quiet mode is only supported for managed profiles.
20260a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
20270a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile to be queried.
20280a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @return true if the profile is in quiet mode, false otherwise.
20290a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
20300a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    public boolean isQuietModeEnabled(UserHandle userHandle) {
20310a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
20320a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            return mService.isQuietModeEnabled(userHandle.getIdentifier());
203327b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
2034f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
20350a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
20360a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
20370a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
20380a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
2039f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user
2040f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * first by showing the confirm credentials screen and disable quiet mode upon successful
2041f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled}
2042f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * directly.
2043f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     *
2044f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * @return true if the quiet mode was disabled immediately
2045f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * @hide
2046f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     */
2047f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) {
2048f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        try {
2049f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz            return mService.trySetQuietModeDisabled(userHandle, target);
2050f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        } catch (RemoteException re) {
2051f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz            throw re.rethrowFromSystemServer();
2052f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        }
2053f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    }
2054f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz
2055f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    /**
20567dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
20577dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
2058c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
2059c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
2060c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2061c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
2062c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
206366ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
2064c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
2065c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
2066c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
2067c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
2068c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
2069c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
2070c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
2071c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2072c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
2073c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
2074c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
2075c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
2076c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
2077c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
2078c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
2079c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
2080c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
2081c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
2082c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
2083c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
2084c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
2085c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
208666ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
2087c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
2088c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
2089c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
2090c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
2091c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
2092c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
209366ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     *         the badge. If it's {@code null}, the badge is applied on top of the entire
2094c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
2095c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
209666ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
2097c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
2098c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
2099c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
2100c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2101c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
2102c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2103c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
2104c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2105c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
21064f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
21074f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
2108701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
2109701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
2110f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
2111f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
2112f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
2113f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
2114f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
2115f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
2116f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
2117f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
2118c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2119f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
2120237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
2121c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
21224f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
21234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
21244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
21254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
21264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
2127394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
21284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
21294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
2130920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
2131920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
2132920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
2133ada8deb43649aed879ceba28daee4af69ae0cc8dAdam Lesinski    public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
2134920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
2135920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
2136258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2137f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2138258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2139258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2140258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2141258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
21431952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2144258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
2145258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2146258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
21478588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean removeUser(@UserIdInt int userHandle) {
2148258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2149258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
2150258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2151f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2152258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2153258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2154258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2155258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2156d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * Similar to {@link #removeUser(int)} except bypassing the checking of
2157d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * {@link UserManager#DISALLOW_REMOVE_USER}
2158d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2159d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     *
2160d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * @see {@link #removeUser(int)}
2161d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * @hide
2162d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     */
2163d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2164d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        try {
2165d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot            return mService.removeUserEvenWhenDisallowed(userHandle);
2166d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        } catch (RemoteException re) {
2167d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot            throw re.rethrowFromSystemServer();
2168d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        }
2169d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    }
2170d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot
2171d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    /**
2172258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
21731952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2174258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
2175258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
2176258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
2177258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2178258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
21798588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserName(@UserIdInt int userHandle, String name) {
2180258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2181258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
2182258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2183f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2185258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2186258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2187258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2188e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
2189258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
2190e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
2191258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2192258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
21938588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
2194258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2195e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
2196258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2197f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2198258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2199258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2200258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2201258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
22023b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
22033b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
2204e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
220564d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
22063b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
22073b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
22088588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public Bitmap getUserIcon(@UserIdInt int userHandle) {
22093b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
22101bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
22111bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
22121bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
22131bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
22141bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
22151bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
22161bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
22171bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
22181bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
22191bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
22201bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
22213b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
2222f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
22233b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
22241bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
22253b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
22263b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
22273b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
2228258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
2229258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
2230258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2231a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
2232258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
223327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
2234ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
2235ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
2236409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
2237409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
223827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
223927bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
2240258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
22412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
22422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
2243cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * Returns true if the user switcher should be shown, this will be if device supports multi-user
2244cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * and there are at least 2 users available that are not managed profiles.
22451a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
22461a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
22471a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
22481a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
2249cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        if (!supportsMultipleUsers()) {
2250cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov            return false;
2251cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        }
2252eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        // If Demo Mode is on, don't show user switcher
2253eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        if (isDeviceInDemoMode(mContext)) {
2254eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani            return false;
2255eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        }
22561a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
22571a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
22581a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
22591a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
22601a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
22611a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
22627cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen            if (user.supportsSwitchToByUser()) {
22631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
22641a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
22651a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
2266cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2267cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov                .getGuestUserDisabled(null);
2268a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
22691a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
22701a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
22711a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
2272eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani     * @hide
2273eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani     */
2274eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    public static boolean isDeviceInDemoMode(Context context) {
2275eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        return Settings.Global.getInt(context.getContentResolver(),
2276eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani                Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2277eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    }
2278eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani
2279eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    /**
22802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
22812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
22822a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
22832a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
22842a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
22852a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
22868588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public int getUserSerialNumber(@UserIdInt int userHandle) {
22872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
22882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
22892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
2290f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
22912a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
22922a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
22932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
22942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
22952a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
22962a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
22972a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
22982a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
22992a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
23002a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
23012a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
23022a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
23038588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @UserIdInt int getUserHandle(int userSerialNumber) {
23042a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
23052a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
23062a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
2307f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
23082a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
23092a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
23106794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
23117e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
2312953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
23137e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
23145b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
23155b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
23165b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * where the types of values may be:
23175b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <ul>
23185b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code boolean}
23195b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code int}
23205b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code String} or {@code String[]}
23215b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
23225b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * </ul>
23235b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
23244e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov     * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
23254e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov     *
23267e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
2327953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2328953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * if there are no saved restrictions.
23295b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
23305b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * @see #KEY_RESTRICTIONS_PENDING
23317e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
23324e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
23337e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
23347e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
23357e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
23367e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
2337f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
23387e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
23397e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
2340df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
2341df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
2342df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
2343df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
23444e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
23457e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
2346df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
23477e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
2348df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
2349f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2350df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
2351df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
2352df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
2353df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
2354df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
2355df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
23564e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
23577e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
2358df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
2359df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
23607e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
2361df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
2362f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2363df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
2364df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
2365655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
2366655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
2367d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2368d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
2369d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
2370d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
2371ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
2372ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
2373655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
2374514c5ef8d5774d8820ed1bf90fe53af1606cf106Aurimas Liutikas    @Deprecated
2375d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
2376655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
2377655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
23781a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
2379e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
2380e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
2381e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
2382e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
2383e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
2384e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
2385e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
2386e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
2387f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2388e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
2389e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
2390e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
2391e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
2392e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
2393e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
2394e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
2395e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
2396e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
2397e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
2398e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
2399f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2400e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
2401e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
2402ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
2403ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
2404ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
2405ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
2406ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
2407ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
2408ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
2409385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
2410ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
2411385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
2412ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
2413f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2414ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
2415ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
241612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
241712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
241812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
241912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Checks if any uninitialized user has the specific seed account name and type.
242012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
24216a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param accountName The account name to check for
24226a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param accountType The account type of the account to check for
242312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @return whether the seed account was found
242412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
242512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public boolean someUserHasSeedAccount(String accountName, String accountType) {
242612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
242712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.someUserHasSeedAccount(accountName, accountType);
242812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
2429f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
243012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
243112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
24326a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24336a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    /**
24346a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @hide
24356a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * User that enforces a restriction.
24366a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     *
24376a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @see #getUserRestrictionSources(String, UserHandle)
24386a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     */
24396a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @SystemApi
24406a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    public static final class EnforcingUser implements Parcelable {
24416a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private final @UserIdInt int userId;
24426a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private final @UserRestrictionSource int userRestrictionSource;
24436a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24446a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
24456a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * @hide
24466a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
24476a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public EnforcingUser(
24486a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
24496a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            this.userId = userId;
24506a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            this.userRestrictionSource = userRestrictionSource;
24516a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24526a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24536a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private EnforcingUser(Parcel in) {
24546a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            userId = in.readInt();
24556a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            userRestrictionSource = in.readInt();
24566a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24576a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24586a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
24596a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            @Override
24606a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            public EnforcingUser createFromParcel(Parcel in) {
24616a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                return new EnforcingUser(in);
24626a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            }
24636a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24646a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            @Override
24656a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            public EnforcingUser[] newArray(int size) {
24666a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                return new EnforcingUser[size];
24676a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            }
24686a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        };
24696a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24706a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        @Override
24716a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public int describeContents() {
24726a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return 0;
24736a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24746a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24756a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        @Override
24766a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public void writeToParcel(Parcel dest, int flags) {
24776a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            dest.writeInt(userId);
24786a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            dest.writeInt(userRestrictionSource);
24796a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24806a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24816a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
24826a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * Returns an id of the enforcing user.
24836a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         *
24846a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
24856a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
24866a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public UserHandle getUserHandle() {
24876a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return UserHandle.of(userId);
24886a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24896a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24906a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
24916a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * Returns the status of the enforcing user.
24926a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         *
24936a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
24946a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
24956a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
24966a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
24976a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public @UserRestrictionSource int getUserRestrictionSource() {
24986a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return userRestrictionSource;
24996a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
25006a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    }
2501258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
2502