UserManager.java revision e72f81b64d356149c81104ecbdeca1abea31da85
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;
227cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable;
23b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chenimport android.annotation.RequiresPermission;
240e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
25e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onukiimport android.annotation.TestApi;
268588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkeyimport android.annotation.UserIdInt;
274e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolovimport android.annotation.WorkerThread;
2837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasaniimport android.app.Activity;
29409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
30cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager;
31068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName;
32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
3312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasaniimport android.content.Intent;
348bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talaveraimport android.content.IntentFilter;
35f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franzimport android.content.IntentSender;
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
3727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
386794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
391bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
414f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
421e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
43523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolovimport android.telephony.TelephonyManager;
441c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
466794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
47aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reckimport com.android.internal.os.RoSystemProperties;
486794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
491bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
50e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.Retention;
51e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Banimport java.lang.annotation.RetentionPolicy;
524f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
53258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
54258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
55258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
560696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Manages users and user details on a multi-user system. There are two major categories of
570696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * users: fully customizable users with their own login, and managed profiles that share a workspace
580696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * with a related user.
590696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p>
600696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * Users are different from accounts, which are managed by
610696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * {@link AccountManager}. Each user can have their own set of accounts.
620696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * <p>
630696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
64258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
65258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
66258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
67258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
68258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
69258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
70258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
71d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki    private Boolean mIsManagedProfileCached;
72d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki
73e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
74e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
75e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * No user restriction.
76e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
77e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
78e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_NOT_SET = 0x0;
79e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
80e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
81e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
82e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by system/user.
83e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
84e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
85e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_SYSTEM = 0x1;
86e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
87e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
88e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
89e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by a device owner.
90e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
91e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
92e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_DEVICE_OWNER = 0x2;
93e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
94e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
95e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
96e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * User restriction set by a profile owner.
97e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
98e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
99e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public static final int RESTRICTION_SOURCE_PROFILE_OWNER = 0x4;
100e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
101e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /** @hide */
102e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @Retention(RetentionPolicy.SOURCE)
103e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @IntDef(flag=true, value={RESTRICTION_NOT_SET, RESTRICTION_SOURCE_SYSTEM,
104e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            RESTRICTION_SOURCE_DEVICE_OWNER, RESTRICTION_SOURCE_PROFILE_OWNER})
105e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
106e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public @interface UserRestrictionSource {}
107e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
108e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
10953019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Specifies if a user is disallowed from adding and removing accounts, unless they are
11053019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by
11153019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov     * Authenticator.
11271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
11326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
114b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * <p>From {@link android.os.Build.VERSION_CODES#N} a profile or device owner app can still
115b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * use {@link android.accounts.AccountManager} APIs to add or remove accounts when account
116b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     * management is disallowed.
117b6c0ce4ac915cd5ab9a308cb0a4861c4e2cd7dfbBenjamin Franz     *
1180ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1190ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
120068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
121068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
122e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
123e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
12471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
125e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
126e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
12726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
1282cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
1290ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect in a managed profile.
13026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1320ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
133068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
134068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
135e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
136e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
13771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
138e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
139e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
14026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
14171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
14226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1430ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1440ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
145068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
146068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
147e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
148e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
14971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
150e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
151e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
15226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
15371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
15426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1550ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1560ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
157068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
158068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
159e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
160e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
16171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
162e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
16371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
164150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
16571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
1660ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>In a managed profile, location sharing always reflects the primary user's setting, but
167150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
16826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1690ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1700ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
171068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
172068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
1736794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1746794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
17571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1766794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
177a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
17826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
179a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
180a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
18126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1820ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1830ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
184068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
185068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
186a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
187a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
188a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
189a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
190a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
19126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1921c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
193a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
19463d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of
19563d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}.
1960ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect in a managed profile.
19726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
1980ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
1990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
200068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
201068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
202a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
203a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
204a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
205a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
206a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
20763d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * Specifies if bluetooth is disallowed on the device.
20863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     *
20963d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p> This restriction can only be set by the device owner and the profile owner on the
21063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * primary user and it applies globally - i.e. it disables bluetooth on the entire device.
21163d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>The default value is <code>false</code>.
21263d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>Key for user restrictions.
21363d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * <p>Type: Boolean
21463d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
21563d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
21663d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     * @see #getUserRestrictions()
21763d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova     */
21863d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova    public static final String DISALLOW_BLUETOOTH = "no_bluetooth";
21963d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova
22063d5e4a7491b707235654cb081d2fc9074a5a65aLenka Trochtova    /**
22126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
222c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
223c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
22426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2250ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2260ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
227068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
228068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
229a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
230a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
231a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
232a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
233b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
23426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
235b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
23626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2370ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2380ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
239068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
240068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
241b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
242b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
243b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
244b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
245b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
246150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
247150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
248150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
249150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
25026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2510ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2520ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
253068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
254068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
255b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
256b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
257b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
258b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
259d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
2606c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if managed profiles of this user can be removed, other than by its profile owner.
2616c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * The default value is <code>false</code>.
2626c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>
2632ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * This restriction has no effect on managed profiles.
2646c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     *
2656c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Key for user restrictions.
2666c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Type: Boolean
2676c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
2686c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
2696c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see #getUserRestrictions()
2706c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     */
2716c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    public static final String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile";
2726c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera
2736c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    /**
27426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
275d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
27626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2770ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2780ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
279068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
280068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
281d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
282d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
283d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
284d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
285d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
28626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
287d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
288298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
2890e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn     * {@link android.os.Build.VERSION_CODES#M}
29026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
2910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
2920ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
293068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
294068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
295d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
296d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
297d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
298d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
299d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
30026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
301c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
302c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
30326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3040ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3050ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
306068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
307068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
308d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
309d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
310d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
311d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
312d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
313e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
314e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
315e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
3160ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
317e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
318e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
3190ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3200ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
321068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
322068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
323e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
324e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
325e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
326e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
327e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
32826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
329c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
330c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
3310ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
332150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3350ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
336068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
337068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
338d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
339d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
340d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
341d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
342d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
3436c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if a user is disallowed from adding new users. This can only be set by device
3446c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * owners and profile owners on the primary user.
345c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
3460ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
347150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
34826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3490ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3500ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
351068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
352068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
353d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
354d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
355d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
356d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
357d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
3586c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * Specifies if a user is disallowed from adding managed profiles.
3596c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>The default value for an unmanaged user is <code>false</code>.
3602ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * For users with a device owner set, the default is <code>true</code>.
3612ea46fe658c5a977a11372d7180e8ed9abf261e8Nicolas Prevot     * <p>This restriction has no effect on managed profiles.
3626c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     *
3636c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Key for user restrictions.
3646c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * <p>Type: Boolean
3656c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
3666c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
3676c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * @see #getUserRestrictions()
3686c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     */
3696c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    public static final String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
3706c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera
3716c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera    /**
37226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
373d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
37426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3750ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3760ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
377068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
378068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
379d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
380d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
381d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
382d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
383d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
38426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
385c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
386c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
3870ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
388150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
38926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
3900ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
3910ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
392068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
393068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
394d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
395d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
396d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
397d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
398d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
39926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
400c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
401c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
4020ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>This restriction has no effect on secondary users and managed profiles since only the
403150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
40426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4050ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4060ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
407068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
408068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
409d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
410d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
411d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
412d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
413d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
41426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
415c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
416c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
417c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
418c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
419c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
420c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
421c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
422c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
423c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
424c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
42526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4268bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * <p><strong>Note:</strong> The user will still be able to perform those actions via other
4278bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * means (such as adb). Third party apps will also be able to uninstall apps via the
4288bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link android.content.pm.PackageInstaller}. {@link #DISALLOW_UNINSTALL_APPS} or
4298bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link DevicePolicyManager#setUninstallBlocked(ComponentName, String, boolean)} should be
4308bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * used to prevent the user from uninstalling apps completely, and
4318bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * {@link DevicePolicyManager#addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}
4328bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     * to add a default intent handler for a given intent filter.
4338bd7c52fb0724892da4804aa78458d6de24af4e1Esteban Talavera     *
4340ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4350ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
436068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
437068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
438d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
439d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
44036fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
441d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
442394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
44326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
444c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
445c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
44626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4470ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4480ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
449068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
450068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
451394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
452394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
453394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
454394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
455394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
45626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
457c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
458c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
45926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4600ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4610ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
462068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
463068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
464394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
465394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
466394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
467394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
468394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
46926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
470c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
471c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
47226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4730ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4740ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
475068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
476068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
477394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
478394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
479394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
480394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
4819f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
48226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
483390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
484390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
485eb83ab52b28766adf1743db76484515bc9b9e08aTony Mak     * <p>This restriction has no effect on managed profiles.
48626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4870ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
4880ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
489068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
490068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
491390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
492390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
493390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
494390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
495390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
49626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
497c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
49826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
4990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5000ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
501068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
502068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5039f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
5049f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
505390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
5069f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
5071c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
5082cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
5092cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
5102cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
5112cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
5120ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5130ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
514068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
515068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
5162cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
5172cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
5182cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
5192cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
5202cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
52126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
5221c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
5231c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
5241c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
5251c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
5261c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
5271c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
5281c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
5295cd907d3d6ceebf8731ef1f69347cce6f76109e9Wale Ogunwale     * <li>{@link LayoutParams#TYPE_APPLICATION_OVERLAY}</li>
5301c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
531c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
532c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
53326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
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)
5381c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
5391c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
5401c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
5411c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
542f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
54326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
544f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
545f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
546f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
54726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5480ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5490ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
550068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
551068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
552f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
553f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
554f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
555f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
55626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
55726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
55826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
55926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5600ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5610ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
562068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
563068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
56426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
56526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
56626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
56726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
56853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
569f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * Hidden user restriction to disallow access to wallpaper manager APIs. This restriction
570f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * generally means that wallpapers are not supported for the particular user. This user
571f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * restriction is always set for managed profiles, because such profiles don't have wallpapers.
572f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
573f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see #DISALLOW_SET_WALLPAPER
574068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
575068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
576f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
577f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
578f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
579f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
580f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
581f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * User restriction to disallow setting a wallpaper. Profile owner and device owner
582f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * are able to set wallpaper regardless of this restriction.
583f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * The default value is <code>false</code>.
584f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     *
585f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * <p>Key for user restrictions.
586f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * <p>Type: Boolean
587f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
588f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
589f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     * @see #getUserRestrictions()
590f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi     */
591f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi    public static final String DISALLOW_SET_WALLPAPER = "no_set_wallpaper";
592f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi
593f2519814cc7136773a115b770d20cf4c92945952Oleksandr Peletskyi    /**
594bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
595bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
596bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
597bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
5980ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
5990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
600068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
601068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
602bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
603bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
604bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
605bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
606bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
607b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
608b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
609b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
610068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
611068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
612b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
613b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
614b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
615b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
616b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
617b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
6189cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * Specifies if a user is not allowed to run in the background and should be stopped during
6199cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * user switch. The default value is <code>false</code>.
6209cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
6219cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * <p>This restriction can be set by device owners and profile owners.
6229cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     *
6239cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
6249cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
6259cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @see #getUserRestrictions()
6269cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     * @hide
6279cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov     */
6289cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    public static final String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
6299cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov
6309cbfc9e212151e84910a22387365644916dde446Fyodor Kupolov    /**
631759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * Specifies if a user is not allowed to use the camera.
632759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     *
633759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
634759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
635759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @see #getUserRestrictions()
636759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     * @hide
637759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki     */
638759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    public static final String DISALLOW_CAMERA = "no_camera";
639759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki
640759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki    /**
641c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * Specifies if a user is not allowed to unmute the device's master volume.
642c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     *
643c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see DevicePolicyManager#setMasterVolumeMuted(ComponentName, boolean)
644c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
645c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @see #getUserRestrictions()
646c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     * @hide
647c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak     */
648492b4724fb42adf29f3978f01ebc5238f893d194Esteban Talavera    public static final String DISALLOW_UNMUTE_DEVICE = "disallow_unmute_device";
649c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak
650c1205111a92b52283078f1a2e86c8d32c5928b92Tony Mak    /**
651dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
652dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * device owners. The default value is <code>false</code>.
653dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     *
654dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
655dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
656dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     * @see #getUserRestrictions()
657dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra     */
658dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra    public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
659dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra
660dea471ef548f09e04e178c5ec2d71a4b79bdb8f8Mahaver Chopra    /**
6617f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * Specifies if a user is not allowed to change their icon. Device owner and profile owner
6627f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * can set this restriction. When it is set by device owner, only the target user will be
6637f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * affected. The default value is <code>false</code>.
6647f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     *
6657f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * <p>Key for user restrictions.
6667f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * <p>Type: Boolean
6677f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
6687f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
6697f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     * @see #getUserRestrictions()
6707f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi     */
6717f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi    public static final String DISALLOW_SET_USER_ICON = "no_set_user_icon";
6727f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi
6737f1f1dfc8713fbecbab60cfbe14ab4d97d27deeeOleksandr Peletskyi    /**
6743d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * Specifies if a user is not allowed to enable the oem unlock setting. The default value is
675c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera     * <code>false</code>. Setting this restriction has no effect if the bootloader is already
676c48b20f8f1d3e07e8a931b195669b0ab8895006cEsteban Talavera     * unlocked.
6773d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     *
67812b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova     * <p>Not for use by third-party applications.
67912b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova     *
6803d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
6813d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
6823d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @see #getUserRestrictions()
6833d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     * @hide
6843d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra     */
68512b0496944381437a1e9974b0e79f56e766bbbdcLenka Trochtova    @SystemApi
6863d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra    public static final String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
6873d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra
6883d9805d50281882b4420ee2d4ede8a8bdd94d455Mahaver Chopra    /**
689f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     * Allows apps in the parent profile to handle web links from the managed profile.
690f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     *
6919edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * This user restriction has an effect only in a managed profile.
6929edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * If set:
6939edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * Intent filters of activities in the parent profile with action
6949edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * {@link android.content.Intent#ACTION_VIEW},
6959edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
6969edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * define a host can handle intents from the managed profile.
6979edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * The default value is <code>false</code>.
6989edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     *
6990ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for user restrictions.
7000ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
701068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
702068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
7039edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #getUserRestrictions()
7049edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     */
705f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
706f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot            = "allow_parent_profile_app_linking";
7079edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot
7089edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot    /**
70953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
71053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
71153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
71253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
71353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
71453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
71553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
71653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
71753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
71853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
7190ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Key for application restrictions.
7200ffbfea423e37f924d1e6d5a1023b848218f5623Fyodor Kupolov     * <p>Type: Boolean
721b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
722b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
723b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
724b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
72553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
72653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
72753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
72812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER";
72912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
73012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
73112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing a name for the user being created. Optional parameter passed to
73212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
73312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
73412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
73512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_NAME = "android.os.extra.USER_NAME";
73612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
73712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
73812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account name for the user being created. Optional parameter passed to
73912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
74012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
74112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
74212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_NAME = "android.os.extra.USER_ACCOUNT_NAME";
74312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
74412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
74512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account type for the user being created. Optional parameter passed to
74612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * ACTION_CREATE_USER activity.
74712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
74812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
74912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_TYPE = "android.os.extra.USER_ACCOUNT_TYPE";
75012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
75112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
75212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Extra containing account-specific data for the user being created. Optional parameter passed
75312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * to ACTION_CREATE_USER activity.
75412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
75512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
75612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static final String EXTRA_USER_ACCOUNT_OPTIONS
75712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            = "android.os.extra.USER_ACCOUNT_OPTIONS";
75812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
759655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
760655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
761655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
762655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
763655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
764655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
765655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
76637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    /**
767e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     * Sent when user restrictions have changed.
768e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     *
769e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     * @hide
770e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki     */
771e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    @SystemApi
772e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    @TestApi // To allow seeing it from CTS.
773e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    public static final String ACTION_USER_RESTRICTIONS_CHANGED =
774e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki            "android.os.action.USER_RESTRICTIONS_CHANGED";
775e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki
776e72f81b64d356149c81104ecbdeca1abea31da85Makoto Onuki    /**
77737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * Error result indicating that this user is not allowed to add other users on this device.
77837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * This is a result code returned from the activity created by the intent
77937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
78037ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     */
78137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    public static final int USER_CREATION_FAILED_NOT_PERMITTED = Activity.RESULT_FIRST_USER;
78237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani
78337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    /**
78437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * Error result indicating that no more users can be created on this device.
78537ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * This is a result code returned from the activity created by the intent
78637ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * {@link #createUserCreationIntent(String, String, String, PersistableBundle)}.
78737ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     */
78837ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani    public static final int USER_CREATION_FAILED_NO_MORE_USERS = Activity.RESULT_FIRST_USER + 1;
78937ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani
7907e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
791c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani    public static UserManager get(Context context) {
792c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani        return (UserManager) context.getSystemService(Context.USER_SERVICE);
79327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
794a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
795258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
796258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
797258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
7985200e1cb07190a1f6874d72a4561064cad3ee3e0Fyodor Kupolov        mContext = context.getApplicationContext();
799258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
800258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
801258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8020696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Returns whether this device supports multiple users with their own login and customizable
8030696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * space.
8040696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @return whether the device supports multiple users.
805258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
8064673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
8071a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
8081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
8091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
810258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
811258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
8126794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
8137cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @hide
8147cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @return Whether the device is running with split system user. It means the system user and
8157cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * primary user are two separate users. Previously system user and primary user are combined as
8167cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
8177cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     */
8187cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public static boolean isSplitSystemUser() {
819aa67f684ff43c81e3280c846245ec6ebe907787eJohn Reck        return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
8207cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    }
8217cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen
8227cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    /**
82313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @return Whether guest user is always ephemeral
82413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @hide
82513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     */
82613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    public static boolean isGuestUserEphemeral() {
82713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        return Resources.getSystem()
82813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky                .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
82913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    }
83013a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky
83113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    /**
832523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * Returns whether switching users is currently allowed.
833523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * <p>For instance switching users is not allowed if the current user is in a phone call,
834523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * or system user hasn't been unlocked yet
835523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     * @hide
836523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov     */
837523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    public boolean canSwitchUsers() {
838523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
839523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                mContext.getContentResolver(),
840523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
841523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
842523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        boolean inCall = TelephonyManager.getDefault().getCallState()
843523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov                != TelephonyManager.CALL_STATE_IDLE;
844523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov        return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall;
845523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    }
846523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov
847523c404612c634f6901205fee4f4cae594f62982Fyodor Kupolov    /**
8485760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
849be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
8505760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
8526794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
8538588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @UserIdInt int getUserHandle() {
85479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
855258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
856258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
857258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8588832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
8598832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
8608832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
861258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
862258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
863258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
864258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
865258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
866258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
867f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
868258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
869258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
870258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
87167a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
872e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
873e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
87467a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
875955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
87667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
87767a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
87867a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
879e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
880e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
881988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
882988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
883e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
884df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
885df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
88670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Used to check if this process is running under the primary user. The primary user
88770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * is the first human user on a device.
88870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
88970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return whether this process is running under the primary user.
89070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
89170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
89270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    public boolean isPrimaryUser() {
89370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        UserInfo user = getUserInfo(UserHandle.myUserId());
894d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani        return user != null && user.isPrimary();
89570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
89670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
89770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
8985760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
8995760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
9005760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
9015760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
9025760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
9035760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
9045760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
90570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
9065760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
9072b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
9085760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
909462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * @hide
910462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * Returns whether the caller is running as an admin user. There can be more than one admin
911462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * user.
912462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     */
913462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    public boolean isAdminUser() {
9142b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return isUserAdmin(UserHandle.myUserId());
9152b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    }
9162b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen
9172b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen    /**
9182b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * @hide
9192b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * Returns whether the provided user is an admin user. There can be more than one admin
9202b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     * user.
9212b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen     */
9228588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserAdmin(@UserIdInt int userId) {
9232b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        UserInfo user = getUserInfo(userId);
9242b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen        return user != null && user.isAdmin();
925462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    }
926462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani
927462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    /**
928e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
92946bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
930e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
9312555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
932df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
933e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
934df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
93571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
936df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
937f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
938df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
939df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
940df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
941258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
9421c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * Checks if specified user can have restricted profile.
9431c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     * @hide
9441c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov     */
9458588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
9461c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        try {
9471c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov            return mService.canHaveRestrictedProfile(userId);
9481c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        } catch (RemoteException re) {
949f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
9501c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov        }
9511c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    }
9521c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov
9531c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov    /**
95413a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * Checks if a user is a guest user.
95513a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @return whether user is a guest user.
95613a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     * @hide
95713a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky     */
95813a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    public boolean isGuestUser(int id) {
95913a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        UserInfo user = getUserInfo(id);
96013a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky        return user != null && user.isGuest();
96113a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    }
96213a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky
96313a58a91d362e74933b3064a65be4bf4449cfdc4Evan Rosky    /**
9641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
9651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
9661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
9671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
9681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
9691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
970d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani        return user != null && user.isGuest();
971d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    }
972d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani
973d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    /**
9741c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     * Checks if the calling app is running in a demo user. When running in a demo user,
9751c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     * apps can be more helpful to the user, or explain their features in more detail.
9761c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani     *
977d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani     * @return whether the caller is a demo user.
978d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani     */
979d35a89cd80c6cdb4b61fc4c9d88d935ee26612e1Amith Yamasani    public boolean isDemoUser() {
9801c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        try {
9811c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani            return mService.isDemoUser(UserHandle.myUserId());
9821c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        } catch (RemoteException re) {
9831c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani            throw re.rethrowFromSystemServer();
9841c41dc8ec59db15cfc050f420f857fcbf0ff2bf0Amith Yamasani        }
9851e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
9861e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
9871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
9880e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
9890e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
9900e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
9910e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
9920e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
9930e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
9940e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
9950e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
996d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        // No need for synchronization.  Once it becomes non-null, it'll be non-null forever.
997d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        // Worst case we might end up calling the AIDL method multiple times but that's fine.
998d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        if (mIsManagedProfileCached != null) {
999d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return mIsManagedProfileCached;
1000d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        }
10018673b2899e775014336efff44ea88dcac2b25bddTony Mak        try {
1002d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            mIsManagedProfileCached = mService.isManagedProfile(UserHandle.myUserId());
1003d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return mIsManagedProfileCached;
10048673b2899e775014336efff44ea88dcac2b25bddTony Mak        } catch (RemoteException re) {
10058673b2899e775014336efff44ea88dcac2b25bddTony Mak            throw re.rethrowFromSystemServer();
10068673b2899e775014336efff44ea88dcac2b25bddTony Mak        }
10078673b2899e775014336efff44ea88dcac2b25bddTony Mak    }
10088673b2899e775014336efff44ea88dcac2b25bddTony Mak
10098673b2899e775014336efff44ea88dcac2b25bddTony Mak    /**
10108673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Checks if the specified user is a managed profile.
10118673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
10128673b2899e775014336efff44ea88dcac2b25bddTony Mak     * must be in the same profile group of specified user.
10138673b2899e775014336efff44ea88dcac2b25bddTony Mak     *
10148673b2899e775014336efff44ea88dcac2b25bddTony Mak     * @return whether the specified user is a managed profile.
10158673b2899e775014336efff44ea88dcac2b25bddTony Mak     * @hide
10168673b2899e775014336efff44ea88dcac2b25bddTony Mak     */
10178673b2899e775014336efff44ea88dcac2b25bddTony Mak    @SystemApi
10188673b2899e775014336efff44ea88dcac2b25bddTony Mak    public boolean isManagedProfile(@UserIdInt int userId) {
1019d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        if (userId == UserHandle.myUserId()) {
1020d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki            return isManagedProfile();
1021d49f3fa8062257d22537c31def79d29879b6e7cbMakoto Onuki        }
10228673b2899e775014336efff44ea88dcac2b25bddTony Mak        try {
10238673b2899e775014336efff44ea88dcac2b25bddTony Mak            return mService.isManagedProfile(userId);
10248673b2899e775014336efff44ea88dcac2b25bddTony Mak        } catch (RemoteException re) {
10258673b2899e775014336efff44ea88dcac2b25bddTony Mak            throw re.rethrowFromSystemServer();
10268673b2899e775014336efff44ea88dcac2b25bddTony Mak        }
10270e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
10280e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
10290e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
103002c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * Gets badge for a managed profile.
103102c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission, otherwise the caller
103202c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * must be in the same profile group of specified user.
103302c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     *
103402c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * @return which badge to use for the managed profile badge id will be less than
103502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     *         UserManagerService.getMaxManagedProfiles()
103602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     * @hide
103702c8990bd6125f05cb32561727d559dc9327a601Kenny Guy     */
103802c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    public int getManagedProfileBadge(@UserIdInt int userId) {
103902c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        try {
104002c8990bd6125f05cb32561727d559dc9327a601Kenny Guy            return mService.getManagedProfileBadge(userId);
104102c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        } catch (RemoteException re) {
104202c8990bd6125f05cb32561727d559dc9327a601Kenny Guy            throw re.rethrowFromSystemServer();
104302c8990bd6125f05cb32561727d559dc9327a601Kenny Guy        }
104402c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    }
104502c8990bd6125f05cb32561727d559dc9327a601Kenny Guy
104602c8990bd6125f05cb32561727d559dc9327a601Kenny Guy    /**
1047c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Checks if the calling app is running as an ephemeral user.
1048c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     *
1049c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @return whether the caller is an ephemeral user.
1050c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
1051c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
1052c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    public boolean isEphemeralUser() {
1053c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return isUserEphemeral(UserHandle.myUserId());
1054c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
1055c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
1056c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
1057c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * Returns whether the specified user is ephemeral.
1058c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     * @hide
1059c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova     */
10608588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserEphemeral(@UserIdInt int userId) {
1061c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        final UserInfo user = getUserInfo(userId);
1062c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova        return user != null && user.isEphemeral();
1063c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    }
1064c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova
1065c4dd021322d38ea32ac49930e904b6d08ce6490cLenka Trochtova    /**
1066a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
1067a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
1068a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
1069a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
1070a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
10715eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     *
10725eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
10735eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
10745eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * in order to check other profile's status.
10755eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * Since Android Nougat MR1 (SDK version >= 25;
10765eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
10775eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * it'll accept any {@link UserHandle} within the same profile group as the caller.
1078cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     *
1079a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
1080a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
10815eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
1082a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
10830e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey        return isUserRunning(user.getIdentifier());
10840e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey    }
10850e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey
10860e62384ccbd00e9f78851929ca88b919679ee32eJeff Sharkey    /** {@hide} */
10872e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov    public boolean isUserRunning(@UserIdInt int userId) {
1088a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
10892e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov            return mService.isUserRunning(userId);
109027b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1091f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1092a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
1093a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
1094a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
1095a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
1096a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
1097a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
1098a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
1099a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
11005eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     *
11015eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * <p>Note prior to Android Nougat MR1 (SDK version <= 24;
11025eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N), this API required a system permission
11035eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * in order to check other profile's status.
11045eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * Since Android Nougat MR1 (SDK version >= 25;
11055eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * {@link android.os.Build.VERSION_CODES#N_MR1)), the restriction has been relaxed, and now
11065eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki     * it'll accept any {@link UserHandle} within the same profile group as the caller.
1107cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     *
1108a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
1109a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
11105eef50d86bbef65178873303cc03e9ff492c9ba2Makoto Onuki    // Note this requires either INTERACT_ACROSS_USERS or MANAGE_USERS.
1111a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
1112a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
1113e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey            // TODO: reconcile stopped vs stopping?
1114dc589ac82b5fe2063f4cfd94c8ae26d43d5420a0Sudheer Shanka            return ActivityManager.getService().isUserRunning(
1115e17ac1569793c333bb4dce86607a342e7c982ae7Jeff Sharkey                    user.getIdentifier(), ActivityManager.FLAG_OR_STOPPED);
111627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1117f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1118a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
1119a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
1120a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
11210825ab284c01402d030a24471ac5a6491d79d28bJeff Sharkey    /**
1122cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * Return whether the calling user is running in an "unlocked" state.
1123cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1124cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * On devices with direct boot, a user is unlocked only after they've
1125cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * entered their credentials (such as a lock pattern or PIN). On devices
1126cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * without direct boot, a user is unlocked as soon as it starts.
1127cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1128cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is locked, only device-protected data storage is available.
1129cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is unlocked, both device-protected and credential-protected
1130cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * private app data storage is available.
11318a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     *
11328a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Intent#ACTION_USER_UNLOCKED
11338a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Context#createDeviceProtectedStorageContext()
1134b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     */
1135b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    public boolean isUserUnlocked() {
1136b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey        return isUserUnlocked(Process.myUserHandle());
1137b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    }
1138b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey
1139b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    /**
1140cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * Return whether the given user is running in an "unlocked" state.
1141cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1142cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * On devices with direct boot, a user is unlocked only after they've
1143cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * entered their credentials (such as a lock pattern or PIN). On devices
1144cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * without direct boot, a user is unlocked as soon as it starts.
1145cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * <p>
1146cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is locked, only device-protected data storage is available.
1147cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * When a user is unlocked, both device-protected and credential-protected
1148cf3f0a11a83e7a798e0586a78efdafc82a7f3d08Jeff Sharkey     * private app data storage is available.
1149cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * <p>Requires {@code android.permission.MANAGE_USERS} or
1150cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user}
1151cdb3c2fd0420daa6d26a733df0ec8dcc79676402Fyodor Kupolov     * must be the calling user or a managed profile associated with it.
1152b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     *
1153b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     * @param user to retrieve the unlocked state for.
11548a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Intent#ACTION_USER_UNLOCKED
11558a372a0a280127743ce9a7ce4b6198c7a02d2a4fJeff Sharkey     * @see Context#createDeviceProtectedStorageContext()
1156b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey     */
1157b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    public boolean isUserUnlocked(UserHandle user) {
11580999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey        return isUserUnlocked(user.getIdentifier());
11590999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey    }
11600999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey
11610999c0d6e9c83873d9595ee764b6388dbc49dcb8Jeff Sharkey    /** {@hide} */
11628588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isUserUnlocked(@UserIdInt int userId) {
1163ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        try {
11642e7e09685a69cc6b9e3418065507c6c7f843b446Fyodor Kupolov            return mService.isUserUnlocked(userId);
1165ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        } catch (RemoteException re) {
1166ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey            throw re.rethrowFromSystemServer();
1167ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        }
1168ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    }
1169ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey
1170ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    /** {@hide} */
1171ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    public boolean isUserUnlockingOrUnlocked(UserHandle user) {
1172ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        return isUserUnlockingOrUnlocked(user.getIdentifier());
1173ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    }
1174ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey
1175ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    /** {@hide} */
1176ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey    public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
1177ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        try {
1178c413f7078d2a69badcb4a2326a4a3d55c25da020Fyodor Kupolov            return mService.isUserUnlockingOrUnlocked(userId);
1179ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        } catch (RemoteException re) {
1180ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey            throw re.rethrowFromSystemServer();
1181ce18c8167766f92856f94a8e88e19de4698960e6Jeff Sharkey        }
1182b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    }
1183b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey
1184b642387b43417e2f342a1bc16e4f639b5d6c4b97Jeff Sharkey    /**
1185258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
11868673b2899e775014336efff44ea88dcac2b25bddTony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1187258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
1188258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
1189258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1190b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
11918588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo getUserInfo(@UserIdInt int userHandle) {
1192258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1193258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
1194258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1195f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1196258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1197258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1198258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
119971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1200e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @hide
1201e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *
1202e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * Returns who set a user restriction on a user.
1203e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1204e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @param restrictionKey the string key representing the restriction
1205e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1206e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     * @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
1207e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *         {@link #RESTRICTION_SOURCE_SYSTEM}, {@link #RESTRICTION_SOURCE_DEVICE_OWNER}
1208e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     *         and {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
12096a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @deprecated use {@link #getUserRestrictionSources(String, int)} instead.
1210e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban     */
12116a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @Deprecated
1212e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @SystemApi
1213e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    @UserRestrictionSource
1214e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
1215e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        try {
1216e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
1217e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        } catch (RemoteException re) {
1218e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban            throw re.rethrowFromSystemServer();
1219e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban        }
1220e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    }
1221e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban
1222e783460274047ab38e3b9c4294339ff130fe566cZoltan Szatmary-Ban    /**
12236a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @hide
12246a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     *
12256a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * Returns a list of users who set a user restriction on a given user.
12266a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
12276a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param restrictionKey the string key representing the restriction
12286a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
12296a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @return a list of user ids enforcing this restriction.
12306a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     */
12316a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @SystemApi
12326a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    public List<EnforcingUser> getUserRestrictionSources(
12336a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            String restrictionKey, UserHandle userHandle) {
12346a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        try {
12356a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return mService.getUserRestrictionSources(restrictionKey, userHandle.getIdentifier());
12366a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        } catch (RemoteException re) {
12376a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            throw re.rethrowFromSystemServer();
12386a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
12396a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    }
12406a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
12416a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    /**
124271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
124371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
124471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1245e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
1246e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
1247e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1248e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
124971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
125071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
125171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
125271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
125371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1254e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
1255e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
1256e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
1257e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
1258f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1259e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
1260e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1261e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
12623bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     /**
12633bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @hide
12643bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * Returns whether the given user has been disallowed from performing certain actions
12653bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * or setting certain settings through UserManager. This method disregards restrictions
12663bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * set by device policy.
12673bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param restrictionKey the string key representing the restriction
12683bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
12693bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban     */
12703bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
12713bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        try {
12723bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban            return mService.hasBaseUserRestriction(restrictionKey, userHandle.getIdentifier());
12733bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        } catch (RemoteException re) {
1274f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
12753bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban        }
12763bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban    }
12773bbceddb94d627495c0022d6e3f92a5cb16aebeaZoltan Szatmary-Ban
127871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1279a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
1280a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
128171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1282a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
12833d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
1284e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
1285068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
1286e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1287e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
128871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
1289a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * This will no longer work.  Device owners and profile owners should use
1290a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki     * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead.
129171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
1292a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki    // System apps should use UserManager.setUserRestriction() instead.
12933d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
1294e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
1295068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        throw new UnsupportedOperationException("This method is no longer supported");
1296e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
1297e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
129871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
129971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
1300be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
130171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
130271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
13033d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
13043d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
13053d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
13063d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
130771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
13083d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
130971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
1310068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        setUserRestriction(key, value, Process.myUserHandle());
131171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
131271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
131371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
131471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
131571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
1316be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
131771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
131871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
131971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
13203d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
13213d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
13223d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
13233d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
132471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
13253d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
13266794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
1327b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
1328b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
1329b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
1330f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1331b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
13326794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
13336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
1334258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1335a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
1336a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
13372b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
13382b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
13392b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
1340a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
1341a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
1342b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
1343b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
1344b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
1345b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
1346b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
1347b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
1348b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
1349b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
1350b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
1351b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
1352b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
13538cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
13548cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
13558cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
13568cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
1357f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
13588cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
1359a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
1360a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
1361a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
136233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
1363b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
1364b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
136533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
1366b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
1367b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
136833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
136933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
137033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
137133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
137233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
137333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
137433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
137533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
137633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
137733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
137833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
137933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
138033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
138133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
138233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
138333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
1384ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
138533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
138633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
138733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
138833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
1389cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * Creates a user with the specified name and options. For non-admin users, default user
1390cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen     * restrictions are going to be applied.
13911952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1392258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1393258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
1394258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
1395258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
1396258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1397258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
1398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1399258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1400258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
1401cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        UserInfo user = null;
1402258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1403cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            user = mService.createUser(name, flags);
1404e9c440638e27a123a82feb5e4677ce1242785288phweiss            // TODO: Keep this in sync with
1405e9c440638e27a123a82feb5e4677ce1242785288phweiss            // UserManagerService.LocalService.createUserEvenWhenDisallowed
1406cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            if (user != null && !user.isAdmin()) {
1407068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_SMS, true, user.id);
1408068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
1409cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen            }
1410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1411f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1413cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen        return user;
1414258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1415258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1416258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
14171e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
14181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
14191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
14201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
14211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
14221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
1423068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        UserInfo guest = null;
1424068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        try {
1425068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            guest = mService.createUser(name, UserInfo.FLAG_GUEST);
1426068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki            if (guest != null) {
1427068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                Settings.Secure.putStringForUser(context.getContentResolver(),
1428068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki                        Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
1429bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
1430068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki        } catch (RemoteException re) {
1431f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
14321e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
14331e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
14341e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
14351e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
1436aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
14372a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
1438a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1439a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
1440a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
1441a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
14427cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param userHandle new user will be a profile of this user.
1443a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
14447cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @return the {@link UserInfo} object for the created user, or null if the user
14457cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *         could not be created.
1446a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
1447a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
14488588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
14497cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka        return createProfileForUser(name, flags, userHandle, null);
14507cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    }
14517cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka
14527cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    /**
14537cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * Version of {@link #createProfileForUser(String, int, int)} that allows you to specify
14547cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * any packages that should not be installed in the new profile by default, these packages can
14557cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * still be installed later by the user if needed.
14567cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *
14577cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param name the user's name
14587cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param flags flags that identify the type of user and other properties.
14597cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param userHandle new user will be a profile of this user.
14607cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @param disallowedPackages packages that will not be installed in the profile being created.
14617cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *
14627cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @return the {@link UserInfo} object for the created user, or null if the user
14637cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     *         could not be created.
14647cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     * @hide
14657cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka     */
14667cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle,
14677cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka            String[] disallowedPackages) {
1468a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
14697cb54a34c44547b55200e4be15be397f6a363c55Sudheer Shanka            return mService.createProfileForUser(name, flags, userHandle, disallowedPackages);
1470a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1471f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1472a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1473a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1474a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1475a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
14766dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * Similar to {@link #createProfileForUser(String, int, int, String[])}
14776c9116a6430ca5cd55b1b926213a5e8de77e4fc6Esteban Talavera     * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
14786dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
14796dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     *
14806dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * @see #createProfileForUser(String, int, int, String[])
14816dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     * @hide
14826dc428f677f2b80b085466961e9495972e1c88c9Tony Mak     */
14836dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
14846dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            @UserIdInt int userHandle, String[] disallowedPackages) {
14856dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        try {
14866dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
14876dc428f677f2b80b085466961e9495972e1c88c9Tony Mak                    disallowedPackages);
14886dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        } catch (RemoteException re) {
14896dc428f677f2b80b085466961e9495972e1c88c9Tony Mak            throw re.rethrowFromSystemServer();
14906dc428f677f2b80b085466961e9495972e1c88c9Tony Mak        }
14916dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    }
14926dc428f677f2b80b085466961e9495972e1c88c9Tony Mak
14936dc428f677f2b80b085466961e9495972e1c88c9Tony Mak    /**
149402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * Creates a restricted profile with the specified name. This method also sets necessary
149502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov     * restrictions and adds shared accounts.
149606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     *
149706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @param name profile's name
149806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @return UserInfo object for the created user, or null if the user could not be created.
149906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     * @hide
150006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov     */
150106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    public UserInfo createRestrictedProfile(String name) {
150206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        try {
150302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserHandle parentUserHandle = Process.myUserHandle();
150402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            UserInfo user = mService.createRestrictedProfile(name,
150502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                    parentUserHandle.getIdentifier());
150602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            if (user != null) {
150702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle,
150802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov                        UserHandle.of(user.id));
150906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov            }
151002cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov            return user;
151127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1512f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
151306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov        }
151406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    }
151506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov
151606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov    /**
15170696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Returns an intent to create a user for the provided name and account name. The name
15180696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * and account name will be used when the setup process for the new user is started.
15190696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
152012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * The intent should be launched using startActivityForResult and the return result will
152137ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * indicate if the user consented to adding a new user and if the operation succeeded. Any
152237ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * errors in creating the user will be returned in the result code. If the user cancels the
152337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * request, the return result will be {@link Activity#RESULT_CANCELED}. On success, the
152437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * result code will be {@link Activity#RESULT_OK}.
15250696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
15260696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * Use {@link #supportsMultipleUsers()} to first check if the device supports this operation
15270696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * at all.
15280696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * <p>
152912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * The new user is created but not initialized. After switching into the user for the first
153012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * time, the preferred user name and account information are used by the setup process for that
153112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * user.
153212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
153312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param userName Optional name to assign to the user.
15340696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @param accountName Optional account name that will be used by the setup wizard to initialize
153512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                    the user.
153612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountType Optional account type for the account to be created. This is required
153712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                    if the account name is specified.
153812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountOptions Optional bundle of data to be passed in during account creation in the
153912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       new user via {@link AccountManager#addAccount(String, String, String[],
154012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
154112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *                       Handler)}.
15420696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @return An Intent that can be launched from an Activity.
154337ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * @see #USER_CREATION_FAILED_NOT_PERMITTED
154437ed8d1ce0ffa1e570e868a357b6cb6d509c4e91Amith Yamasani     * @see #USER_CREATION_FAILED_NO_MORE_USERS
15450696434c623dced9fe9ed3873f59b64334f240e7Amith Yamasani     * @see #supportsMultipleUsers
154612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
154712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public static Intent createUserCreationIntent(@Nullable String userName,
154812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            @Nullable String accountName,
154912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            @Nullable String accountType, @Nullable PersistableBundle accountOptions) {
155012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        Intent intent = new Intent(ACTION_CREATE_USER);
155112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (userName != null) {
155212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_NAME, userName);
155312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
155412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountName != null && accountType == null) {
155512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            throw new IllegalArgumentException("accountType must be specified if accountName is "
155612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani                    + "specified");
155712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
155812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountName != null) {
155912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_NAME, accountName);
156012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
156112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountType != null) {
156212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_TYPE, accountType);
156312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
156412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        if (accountOptions != null) {
156512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            intent.putExtra(EXTRA_USER_ACCOUNT_OPTIONS, accountOptions);
156612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
156712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        return intent;
156812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
156912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
157012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
157112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
157212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
157312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account name for user creation. Requires MANAGE_USERS permission.
157412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
157512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
157612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public String getSeedAccountName() {
157712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
157812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountName();
157912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1580f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
158112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
158212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
158312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
158412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
158512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
158612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
158712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account type for user creation. Requires MANAGE_USERS permission.
158812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
158912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
159012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public String getSeedAccountType() {
159112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
159212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountType();
159312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1594f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
159512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
159612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
159712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
159812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
159912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
160012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
160112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS
160212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * permission.
160312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @return Any options set by the requestor that created the user.
160412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
160512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
160612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public PersistableBundle getSeedAccountOptions() {
160712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
160812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.getSeedAccountOptions();
160912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1610f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
161112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
161212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
161312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
161412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
161512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
161612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
161712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Called by a system activity to set the seed account information of a user created
161812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * through the user creation intent.
161912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param userId
162012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountName
162112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountType
162212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @param accountOptions
162312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @see #createUserCreationIntent(String, String, String, PersistableBundle)
162412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
162512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public void setSeedAccountData(int userId, String accountName, String accountType,
162612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            PersistableBundle accountOptions) {
162712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
162812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            mService.setSeedAccountData(userId, accountName, accountType, accountOptions,
162912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani                    /* persist= */ true);
163012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1631f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
163212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
163312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
163412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
163512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
163612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
163712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Clears the seed information used to create this user. Requires MANAGE_USERS permission.
163812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
163912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    @SystemApi
164012747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public void clearSeedAccountData() {
164112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
164212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            mService.clearSeedAccountData();
164312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
1644f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
164512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
164612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
164712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
164812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
16491df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
16501df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
16511df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
16521df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
16531df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
16541df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
16558588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean markGuestForDeletion(@UserIdInt int userHandle) {
16561df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
16571df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
16581df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
1659f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
16601df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
16611df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
16621df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
16631df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
1664df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
16651ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     *
16661ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
16671ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     *
16681ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * <p>Note that the default is true, it's only that managed profiles might not be enabled.
16691ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * Also ephemeral users can be disabled to indicate that their removal is in progress and they
16701ddda4793c26fd249590fd3549cf060ecb7c157bLenka Trochtova     * shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
1671df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
1672df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
1673df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
1674df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
16758588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserEnabled(@UserIdInt int userHandle) {
1676df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
1677df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
167827b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1679f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1680df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
1681df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
1682df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
1683df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
168485a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     * Evicts the user's credential encryption key from memory by stopping and restarting the user.
168585a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     *
168685a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     * @hide
168785a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull     */
168885a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    public void evictCredentialEncryptionKey(@UserIdInt int userHandle) {
168985a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        try {
169085a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull            mService.evictCredentialEncryptionKey(userHandle);
169185a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        } catch (RemoteException re) {
169285a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull            throw re.rethrowFromSystemServer();
169385a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull        }
169485a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    }
169585a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull
169685a63bc1a06870b5a86926b0bce94a2bf559e3f0Andrew Scull    /**
1697b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
1698b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
1699b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
1700b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
1701b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
1702b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
1703b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
1704b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
1705d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * Returns information for all users on this device, including ones marked for deletion.
1706d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
1707d04aaa323c3a788d26f18fc66e0a59b47e525b38Amith Yamasani     * <p>
17081952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1709940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @return the list of users that exist on the device.
1710258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1711258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1712258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
1713258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1714920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
1715920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
1716f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1717920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
1718920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
1719920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
1720920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
1721940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * Returns serial numbers of all users on this device.
1722940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1723940e8577a1569140521fb605336997863529f7adFyodor Kupolov     *
1724940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @param excludeDying specify if the list should exclude users being removed.
1725940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @return the list of serial numbers of users that exist on the device.
1726940e8577a1569140521fb605336997863529f7adFyodor Kupolov     * @hide
1727940e8577a1569140521fb605336997863529f7adFyodor Kupolov     */
1728940e8577a1569140521fb605336997863529f7adFyodor Kupolov    @SystemApi
1729940e8577a1569140521fb605336997863529f7adFyodor Kupolov    public long[] getSerialNumbersOfUsers(boolean excludeDying) {
1730940e8577a1569140521fb605336997863529f7adFyodor Kupolov        try {
1731940e8577a1569140521fb605336997863529f7adFyodor Kupolov            List<UserInfo> users = mService.getUsers(excludeDying);
1732940e8577a1569140521fb605336997863529f7adFyodor Kupolov            long[] result = new long[users.size()];
1733940e8577a1569140521fb605336997863529f7adFyodor Kupolov            for (int i = 0; i < result.length; i++) {
1734940e8577a1569140521fb605336997863529f7adFyodor Kupolov                result[i] = users.get(i).serialNumber;
1735940e8577a1569140521fb605336997863529f7adFyodor Kupolov            }
1736940e8577a1569140521fb605336997863529f7adFyodor Kupolov            return result;
1737940e8577a1569140521fb605336997863529f7adFyodor Kupolov        } catch (RemoteException re) {
1738f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1739940e8577a1569140521fb605336997863529f7adFyodor Kupolov        }
1740940e8577a1569140521fb605336997863529f7adFyodor Kupolov    }
1741940e8577a1569140521fb605336997863529f7adFyodor Kupolov
1742940e8577a1569140521fb605336997863529f7adFyodor Kupolov    /**
1743b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @return the user's account name, null if not found.
1744b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @hide
1745b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     */
1746b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    @RequiresPermission( allOf = {
1747b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1748b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.MANAGE_USERS
1749b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    })
17508588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @Nullable String getUserAccount(@UserIdInt int userHandle) {
1751b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        try {
1752b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            return mService.getUserAccount(userHandle);
1753b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        } catch (RemoteException re) {
1754f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1755b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        }
1756b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    }
1757b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen
1758b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    /**
1759b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * Set account name for the given user.
1760b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     * @hide
1761b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen     */
1762b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    @RequiresPermission( allOf = {
1763b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.INTERACT_ACROSS_USERS_FULL,
1764b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            Manifest.permission.MANAGE_USERS
1765b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    })
17668588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
1767b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        try {
1768b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen            mService.setUserAccount(userHandle, accountName);
1769b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        } catch (RemoteException re) {
1770f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1771b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen        }
1772b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    }
1773b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen
1774b3b9258ab6a01af5e0df4b8385b73084cd9ec530Xiaohui Chen    /**
177570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Returns information for Primary user.
177670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
177770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
177870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return the Primary user, null if not found.
177970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
178070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
17817cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public @Nullable UserInfo getPrimaryUser() {
178270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        try {
178370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return mService.getPrimaryUser();
178470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        } catch (RemoteException re) {
1785f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
178670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        }
178770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
178870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
178970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
179095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
179195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
179295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
179395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
179495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
179595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
179695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
179795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
179895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
179995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
180095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
180195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
180295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
180395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
180495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
180595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
180695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
180795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
180895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
180995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
181072434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
181172434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
181207387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * if allowedToRemoveOne is true and if the user already has a managed profile, then return if
181307387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot     * we could add a new managed profile to this user after removing the existing one.
181472434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
181572434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
181672434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
181772434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
18188588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
181972434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
182007387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot            return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
182172434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
1822f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
182372434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
182472434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
182572434b7088591828082dd952496d523ef3622de2Nicolas Prevot
182672434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
18272a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
18282a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
18294f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
18307f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
18314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
18322a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
18332a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
18342a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
18352a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
18362a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
18378588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
1838a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
1839385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
1840a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1841f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1842a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1843a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1844a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1845a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
1846fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1847fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param userId one of the two user ids to check.
1848fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @param otherUserId one of the two user ids to check.
1849fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @return true if the two user ids are in the same profile group.
1850fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     * @hide
1851fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen     */
18528588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
1853fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        try {
1854fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen            return mService.isSameProfileGroup(userId, otherUserId);
1855fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        } catch (RemoteException re) {
1856f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1857fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen        }
1858fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    }
1859fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen
1860fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen    /**
18617f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
18627f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
18637f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
18647f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
18657f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
18667f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
18677f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
18687f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
18697f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
18708588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
18717f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
18727f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
18737f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
1874f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
18757f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
18767f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
18777f75da2405cd910854448bb3801f776e036f926aRuben Brunk
18787f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1879be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1880be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
18814f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
18824f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
18834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
18844f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
18857f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
18867f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        List<UserHandle> result = new ArrayList<>(userIds.length);
18877f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        for (int userId : userIds) {
18887f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov            result.add(UserHandle.of(userId));
18897f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        }
18907f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return result;
18917f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
18927f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
18937f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
18947f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * Returns a list of ids for profiles associated with the specified user including the user
18957f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * itself.
18967f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     *
18977f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @param userId      id of the user to return profiles for
18987f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles
18997f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @return A non-empty list of ids of profiles associated with the specified user.
19007f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     *
19017f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19027f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19037f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) {
1904385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
19057f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov            return mService.getProfileIds(userId, enabledOnly);
1906385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1907f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1908385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
19097f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
19107f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
19117f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
19127f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @see #getProfileIds(int, boolean)
19137f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19147f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19157f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
19167f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return getProfileIds(userId, false /* enabledOnly */);
19177f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    }
19187f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov
19197f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    /**
19207f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @see #getProfileIds(int, boolean)
19217f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     * @hide
19227f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov     */
19237f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov    public int[] getEnabledProfileIds(@UserIdInt int userId) {
19247f98aa4aa93497692f200c553d2d6fff402e3de2Fyodor Kupolov        return getProfileIds(userId, true /* enabledOnly */);
19254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
19264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
19277dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1928c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * Returns the device credential owner id of the profile from
1929c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * which this method is called, or userHandle if called from a user that
1930c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * is not a profile.
1931c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     *
1932c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     * @hide
1933c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales     */
19348588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
1935c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        try {
1936c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales            return mService.getCredentialOwnerProfile(userHandle);
1937c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        } catch (RemoteException re) {
1938f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1939c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales        }
1940c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    }
1941c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales
1942c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales    /**
1943be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1944be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1945be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1946be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1947be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
19488588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public UserInfo getProfileParent(@UserIdInt int userHandle) {
1949be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
1950be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
1951be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
1952f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
1953be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
1954be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
1955be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
1956be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
19570a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Set quiet mode of a managed profile.
19580a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
19590a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile.
19600a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param enableQuietMode Whether quiet mode should be enabled or disabled.
19610a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @hide
19620a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
19638588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
19640a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
19650a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            mService.setQuietModeEnabled(userHandle, enableQuietMode);
196627b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1967f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
19680a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
19690a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
19700a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
19710a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
19720a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * Returns whether the given profile is in quiet mode or not.
19737881cf8f818317cc6efe4d6a4c42da94d6bab223Ricky Wai     * Notes: Quiet mode is only supported for managed profiles.
19740a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     *
19750a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @param userHandle The user handle of the profile to be queried.
19760a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     * @return true if the profile is in quiet mode, false otherwise.
19770a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu     */
19780a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    public boolean isQuietModeEnabled(UserHandle userHandle) {
19790a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        try {
19800a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu            return mService.isQuietModeEnabled(userHandle.getIdentifier());
198127b2e6978716f9886db40f4fcf2e060b50637ac5Jeff Sharkey        } catch (RemoteException re) {
1982f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
19830a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu        }
19840a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    }
19850a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu
19860a29ecd8a53b5ac63b628e870a344650ff34c4b0Rubin Xu    /**
1987f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user
1988f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * first by showing the confirm credentials screen and disable quiet mode upon successful
1989f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled}
1990f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * directly.
1991f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     *
1992f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * @return true if the quiet mode was disabled immediately
1993f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     * @hide
1994f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz     */
1995f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    public boolean trySetQuietModeDisabled(@UserIdInt int userHandle, IntentSender target) {
1996f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        try {
1997f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz            return mService.trySetQuietModeDisabled(userHandle, target);
1998f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        } catch (RemoteException re) {
1999f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz            throw re.rethrowFromSystemServer();
2000f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz        }
2001f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    }
2002f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz
2003f02420c5e1bcc8b2c278f272aca633fe6d2b4e88Benjamin Franz    /**
20047dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
20057dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
2006c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
2007c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
2008c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2009c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
2010c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
201166ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
2012c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
2013c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
2014c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
2015c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
2016c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
2017c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
2018c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
2019c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2020c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
2021c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
2022c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
2023c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
2024c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
2025c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
2026c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
2027c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
2028c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
2029c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
2030c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
2031c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
2032c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
2033c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
203466ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
2035c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
2036c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
2037c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
2038c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
2039c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
2040c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
204166ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     *         the badge. If it's {@code null}, the badge is applied on top of the entire
2042c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
2043c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
204466ae66a7f74ee835807a141a216afbb254664510Vadim Tryshev     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
2045c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
2046c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
2047c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
2048c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2049c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
2050c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
2051c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
2052c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
2053c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
20544f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
20554f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
2056701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
2057701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
2058f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
2059f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
2060f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
2061f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
2062f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
2063f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
2064f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
2065f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
2066c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
2067f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
2068237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
2069c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
20704f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
20714f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
20724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
20734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
20744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
2075394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
20764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
20774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
2078920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
2079920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
2080920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
2081920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
2082920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
2083920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
2084258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2085f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2086258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2087258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2088258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2089258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2090258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
20911952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2092258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
2093258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2094258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
20958588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public boolean removeUser(@UserIdInt int userHandle) {
2096258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2097258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
2098258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2099f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2100258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2101258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2102258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2103258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2104d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * Similar to {@link #removeUser(int)} except bypassing the checking of
2105d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * {@link UserManager#DISALLOW_REMOVE_USER}
2106d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * or {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE}.
2107d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     *
2108d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * @see {@link #removeUser(int)}
2109d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     * @hide
2110d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot     */
2111d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    public boolean removeUserEvenWhenDisallowed(@UserIdInt int userHandle) {
2112d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        try {
2113d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot            return mService.removeUserEvenWhenDisallowed(userHandle);
2114d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        } catch (RemoteException re) {
2115d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot            throw re.rethrowFromSystemServer();
2116d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot        }
2117d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    }
2118d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot
2119d37c4a99b2602dd4483ca2985e63b5316e8f4f63Nicolas Prevot    /**
2120258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
21211952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
2122258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
2123258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
2124258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
2125258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2126258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
21278588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserName(@UserIdInt int userHandle, String name) {
2128258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2129258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
2130258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2131f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2132258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2133258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2134258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2135258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
2136e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
2137258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
2138e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
2139258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2140258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
21418588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
2142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
2143e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
2144258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
2145f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2146258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
2147258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
2148258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
2149258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
21503b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
21513b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
2152e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
215364d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
21543b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
21553b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
21568588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public Bitmap getUserIcon(@UserIdInt int userHandle) {
21573b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
21581bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
21591bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
21601bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
21611bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
21621bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
21631bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
21641bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
21651bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
21661bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
21671bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
21681bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
21693b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
2170f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
21713b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
21721bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
21733b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
21743b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
21753b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
2176258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
2177258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
2178258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
2179a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
2180258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
218127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
2182ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
2183ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
2184409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
2185409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
218627bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
218727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
2188258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
21892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
21902a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
2191cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * Returns true if the user switcher should be shown, this will be if device supports multi-user
2192cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov     * and there are at least 2 users available that are not managed profiles.
21931a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
21941a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
21951a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
21961a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
2197cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        if (!supportsMultipleUsers()) {
2198cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov            return false;
2199cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        }
2200eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        // If Demo Mode is on, don't show user switcher
2201eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        if (isDeviceInDemoMode(mContext)) {
2202eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani            return false;
2203eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        }
22041a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
22051a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
22061a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
22071a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
22081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
22091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
22107cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen            if (user.supportsSwitchToByUser()) {
22111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
22121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
22131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
2214cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov        final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
2215cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov                .getGuestUserDisabled(null);
2216a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
22171a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
22181a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
22191a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
2220eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani     * @hide
2221eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani     */
2222eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    public static boolean isDeviceInDemoMode(Context context) {
2223eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani        return Settings.Global.getInt(context.getContentResolver(),
2224eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani                Settings.Global.DEVICE_DEMO_MODE, 0) > 0;
2225eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    }
2226eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani
2227eb437d4dffb310857e19bb619778dc5b6b7febffAmith Yamasani    /**
22282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
22292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
22302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
22312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
22322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
22332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
22348588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public int getUserSerialNumber(@UserIdInt int userHandle) {
22352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
22362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
22372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
2238f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
22392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
22402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
22412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
22422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
22432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
22442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
22452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
22462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
22472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
22482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
22492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
22502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
22518588bc1ef1f020bbe4a24d46874f675708149a57Jeff Sharkey    public @UserIdInt int getUserHandle(int userSerialNumber) {
22522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
22532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
22542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
2255f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
22562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
22572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
22586794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
22597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
2260953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * Returns a {@link Bundle} containing any saved application restrictions for this user, for the
22617e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
22625b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
22635b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <p>The returned {@link Bundle} consists of key-value pairs, as defined by the application,
22645b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * where the types of values may be:
22655b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <ul>
22665b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code boolean}
22675b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code int}
22685b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>{@code String} or {@code String[]}
22695b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
22705b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * </ul>
22715b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
22724e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov     * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
22734e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov     *
22747e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
2275953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * @return a {@link Bundle} with the restrictions for that package, or an empty {@link Bundle}
2276953fe483298bff46558a4e0b2d891924c0c9c813Esteban Talavera     * if there are no saved restrictions.
22775b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     *
22785b9f167a8e7395ca54fc0ef78af4523858de87a7Esteban Talavera     * @see #KEY_RESTRICTIONS_PENDING
22797e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
22804e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
22817e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
22827e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
22837e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
22847e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
2285f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
22867e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
22877e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
2288df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
2289df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
2290df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
2291df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
22924e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
22937e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
2294df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
22957e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
2296df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
2297f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2298df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
2299df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
2300df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
2301df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
2302df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
2303df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
23044e9af0657615e52c0cd5eebe34a277e197876bc5Fyodor Kupolov    @WorkerThread
23057e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
2306df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
2307df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
23087e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
2309df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
2310f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2311df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
2312df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
2313655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
2314655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
2315d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
2316d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
2317d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
2318d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
2319ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
2320ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
2321655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
2322514c5ef8d5774d8820ed1bf90fe53af1606cf106Aurimas Liutikas    @Deprecated
2323d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
2324655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
2325655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
23261a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
2327e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
2328e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
2329e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
2330e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
2331e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
2332e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
2333e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
2334e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
2335f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2336e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
2337e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
2338e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
2339e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
2340e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
2341e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
2342e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
2343e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
2344e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
2345e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
2346e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
2347f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2348e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
2349e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
2350ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
2351ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
2352ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
2353ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
2354ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
2355ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
2356ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
2357385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
2358ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
2359385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
2360ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
2361f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
2362ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
2363ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
236412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani
236512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    /**
236612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @hide
236712747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * Checks if any uninitialized user has the specific seed account name and type.
236812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     *
23696a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param accountName The account name to check for
23706a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @param accountType The account type of the account to check for
237112747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     * @return whether the seed account was found
237212747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani     */
237312747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    public boolean someUserHasSeedAccount(String accountName, String accountType) {
237412747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        try {
237512747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani            return mService.someUserHasSeedAccount(accountName, accountType);
237612747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        } catch (RemoteException re) {
2377f8880561e67e1da246970b49b14285efd4164ab1Jeff Sharkey            throw re.rethrowFromSystemServer();
237812747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani        }
237912747879b0204b9dfee997eddc981d09289e8b77Amith Yamasani    }
23806a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
23816a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    /**
23826a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @hide
23836a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * User that enforces a restriction.
23846a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     *
23856a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     * @see #getUserRestrictionSources(String, UserHandle)
23866a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov     */
23876a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    @SystemApi
23886a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    public static final class EnforcingUser implements Parcelable {
23896a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private final @UserIdInt int userId;
23906a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private final @UserRestrictionSource int userRestrictionSource;
23916a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
23926a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
23936a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * @hide
23946a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
23956a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public EnforcingUser(
23966a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                @UserIdInt int userId, @UserRestrictionSource int userRestrictionSource) {
23976a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            this.userId = userId;
23986a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            this.userRestrictionSource = userRestrictionSource;
23996a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24006a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24016a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        private EnforcingUser(Parcel in) {
24026a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            userId = in.readInt();
24036a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            userRestrictionSource = in.readInt();
24046a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24056a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24066a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public static final Creator<EnforcingUser> CREATOR = new Creator<EnforcingUser>() {
24076a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            @Override
24086a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            public EnforcingUser createFromParcel(Parcel in) {
24096a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                return new EnforcingUser(in);
24106a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            }
24116a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24126a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            @Override
24136a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            public EnforcingUser[] newArray(int size) {
24146a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov                return new EnforcingUser[size];
24156a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            }
24166a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        };
24176a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24186a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        @Override
24196a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public int describeContents() {
24206a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return 0;
24216a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24226a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24236a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        @Override
24246a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public void writeToParcel(Parcel dest, int flags) {
24256a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            dest.writeInt(userId);
24266a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            dest.writeInt(userRestrictionSource);
24276a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24286a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24296a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
24306a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * Returns an id of the enforcing user.
24316a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         *
24326a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * <p> Will be UserHandle.USER_NULL when restriction is set by the system.
24336a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
24346a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public UserHandle getUserHandle() {
24356a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return UserHandle.of(userId);
24366a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24376a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov
24386a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        /**
24396a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * Returns the status of the enforcing user.
24406a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         *
24416a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * <p> One of {@link #RESTRICTION_SOURCE_SYSTEM},
24426a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * {@link #RESTRICTION_SOURCE_DEVICE_OWNER} and
24436a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         * {@link #RESTRICTION_SOURCE_PROFILE_OWNER}
24446a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov         */
24456a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        public @UserRestrictionSource int getUserRestrictionSource() {
24466a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov            return userRestrictionSource;
24476a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov        }
24486a40f09083fc52acc3309d0b04401fca02df6372Pavel Grafov    }
2449258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
2450