UserManager.java revision 2cc03e5606ad7cd473283898400506d5ac2237ba
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 */
16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os;
17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
180e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
19409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
20a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
22258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
246794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
251bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
281e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
301c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
326794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
341bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
47e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding and removing accounts.
4971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
5226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
53e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
54e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
602cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
61150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
6226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
6326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
6426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
69e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
7426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
7526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
80e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
81e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
8226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
8371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
8526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
8626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
87e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
88e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
89e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
91e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
9271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
93150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
9471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
95150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>In a managed profile, location sharing always reflects the primary user's setting, but
96150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
9726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
9826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
9926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
1006794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
1016794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1026794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
10371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1046794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
10626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
10926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
11026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
11126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
11826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1191c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
121150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
12226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
12326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
12426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
129a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
130a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
13126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
132c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
133c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
13426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
13526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
137a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
138a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
139a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
140a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
141a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
142b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
14326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
144b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
14526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
14626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
14726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
148b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
149b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
150b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
151b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
152b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
153b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
154150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
155150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
156150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
157150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
15826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
15926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
16026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
161b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
162b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
163b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
164b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
165b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
166d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
16726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
168d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
16926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
17026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
17126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
172d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
173d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
174d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
175d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
176d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
17826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
179d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
180298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
181298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * {@link android.os.Build.VERSION_CODES#MNC}
18226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
18326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
18426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
185d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
186d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
187d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
188d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
189d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
19126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
192c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
193c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
19426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
19526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
19626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
197d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
198d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
203e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
204e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
205e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
206e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>This restriction has no effect on secondary users and managed profiles since only the
207e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
208e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
209e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Key for user restrictions.
210e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Type: Boolean
211e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #setUserRestrictions(Bundle)
212e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
213e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
214e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
215e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
216e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
21726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
218c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
219c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
220150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
221150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
22226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
22326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
22426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
225d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
228d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
229d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
23126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding new users and
232c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * profiles. This can only be set by device owners and profile owners on the primary user.
233c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
234150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
235150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
23626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
23726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
23826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
239d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
240d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
241d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
242d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
243d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
244d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
24526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
246d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
24726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
24826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
24926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
250d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
252d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
253d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
254d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
255d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
25626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
257c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
258c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
259150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
260150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
26126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
26226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
26326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
264d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
265d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
266d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
267d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
268d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
269d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
27026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
271c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
272c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
273150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
274150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
27526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
27626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
27726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
278d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
279d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
280d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
281d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
282d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
283d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
28426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
285c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
286c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
287c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
288c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
289c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
290c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
291c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
292c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
293c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
294c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
29526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
29626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
29726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
298d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
299d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
300d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
30136fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
302d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
303394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
30426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
305c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
306c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
30726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
30826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
310394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
311394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
312394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
313394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
314394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
315394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
31626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
317c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
318c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
31926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
322394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
323394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
324394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
325394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
326394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
327394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
32826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
329c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
330c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
33126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
33226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
334394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
335394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
336394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
337394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
338394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
3399f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
34026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
341390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
342390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
343150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on managed profiles since call intents are normally
344150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * forwarded to the primary user.
34526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
34626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
34726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
348390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #setUserRestrictions(Bundle)
349390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
350390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
351390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
352390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
353390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
35426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
355c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
35626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
35726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
35826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3599f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
3609f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3619f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
362390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3639f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3641c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
3652cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
3662cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
3672cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
3682cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
3692cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Key for user restrictions.
3702cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Type: Boolean
3712cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #setUserRestrictions(Bundle)
3722cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
3732cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
3742cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
3752cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
3762cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
37726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
3781c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
3791c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
3801c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
3811c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
3821c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
3831c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
3841c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
3851c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
386c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
387c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
38826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
38926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
39026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3911c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
3921c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
3931c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3941c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
3951c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
396f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
39726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
398f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
399f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
400f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
40126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
40226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
40326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
404f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #setUserRestrictions(Bundle)
405f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
406f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
407f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
408f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
40926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
41026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
41126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
41226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
41326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
41426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
41526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #setUserRestrictions(Bundle)
41626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
41726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
41826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
41926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
42053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
421f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
422f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * is always set for managed profiles.
423f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
424f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #setUserRestrictions(Bundle)
425f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
426f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
427f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
428f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
429f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
430bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
431bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
432bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
433bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
434bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Key for user restrictions.
435bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Type: Boolean
436bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #setUserRestrictions(Bundle)
437bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
438bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
439bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
440bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
441bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
442b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
443b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
444b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
445b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #setUserRestrictions(Bundle)
446b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
447b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
448b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
449b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
450b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
451b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
45253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
45353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
45453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
45553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
45653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
45753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
45853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
45953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
46053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
46153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
46253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Key for application restrictions.
46353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Type: Boolean
464b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
465b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
466b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
467b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
46853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
46953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
47053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
471655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
472655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
473655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
474655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
475655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
476655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
477655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
47827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
47927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
4807e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
48127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
48227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
48327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
48427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
48527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
48627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
487a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
488258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
489258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
490258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
491258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
492258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
493258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
494258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
495258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
4961a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
497e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
498258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
4994673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
5001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
5011a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
5021a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
503258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
504258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
5056794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
5065760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
507be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
5085760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
509258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
5106794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
51279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
513258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
514258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5168832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
5178832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
5188832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
519258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
520258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
521258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
522258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
524258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
525258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
526258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
527258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
528258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
529258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
53067a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
531e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
532e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
53367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
534955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
53567a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
53667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
53767a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
538e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
539e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
540988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
541988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
542e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
543df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
544df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
5455760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
5465760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
5475760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
5485760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
5495760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
5505760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
5515760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
5525760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani        return UserHandle.myUserId() == UserHandle.USER_OWNER;
5535760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
5545760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani
5555760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
556e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
55746bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
558e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
5592555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
560df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
561e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
562df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
56371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
564df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
56546bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
566df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
567df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
568df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
569df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
570258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
5721e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
5731e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
5741e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
5751e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
5761e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
5771e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
5781e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
5791e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
5801e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
5810e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
5820e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
5830e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
5840e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
5850e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
5860e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
5870e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
5880e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
5890e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
5900e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
5910e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
5920e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
5930e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
594a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
595a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
596a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
597a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
598a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
599a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
600a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
601a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
602a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
603a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
604a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
605a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
606a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
607a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
608a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
609a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
610a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
611a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
612a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
613a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
614a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
615a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
616a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
617a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
618a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
619a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
620a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
621a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
622a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
623a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
624a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
625a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
626a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
627258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
6281952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
629258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
630258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
631258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
632b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
633258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
634258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
635258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
636258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
637258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
638258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
639258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
640258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
641258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
64271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
64371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
64471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
64571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
646e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
647e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
648e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
649e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
65071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
65171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
65271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
65371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
65471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
655e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
656e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
657e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
658e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
659e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
660e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
661e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
662e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
663e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
66471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
66571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
666be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
66771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
6683d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
6693d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
6703d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
6713d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
67271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
6733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
674e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
675e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
676e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
677e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
67871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
67971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
680be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
68171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
68271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
6833d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
6843d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
6853d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
6863d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
68771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
6883d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
689e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
690e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
691e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
692e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
693e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
694e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
695e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
696e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
69771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
69871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
699be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
70071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
70171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
7023d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7033d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7043d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7053d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
70671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7073d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
70871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
70971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
71071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
71171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
71271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
71371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
71471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
71571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
71671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
717be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
71871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
71971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
72071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
7213d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7223d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7233d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7243d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
72571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7263d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
7276794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
728b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
729b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
730b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
731b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            Log.w(TAG, "Could not set user restriction", re);
732b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
7336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
7346794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
735258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
736a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
737a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
7382b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
7392b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
7402b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
741a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
742a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
743b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
744b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
745b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
746b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
747b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
748b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
749b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
750b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
751b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
752b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
753b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
7548cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
7558cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
7568cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
7578cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
7588cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            Log.w(TAG, "Could not check user restrictions", re);
7598cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return false;
7608cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
761a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
762a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
763a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
76433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
765b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
766b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
76733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
768b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
769b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
77033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
77133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
77233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
77333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
77433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
77533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
77633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
77733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
77833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
77933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
78033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
78133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
78233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
78333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
78433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
78533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
786ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
78733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
78833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
78933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
79033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
791258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
7921952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
793258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
794258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
795258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
796258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
797258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
798258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
799258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
800258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
801258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
802258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
803258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
804258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
805258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
806258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
807258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
808258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
809258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
810258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8111e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
8121e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
8131e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
8141e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
8151e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
8161e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
8171e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
8181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
8191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
8201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
821bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            try {
8228616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
8238616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_SMS, true);
82429ce85bab94a2d0dc98d9075ae86c8a282367117Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
8258616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                mService.setUserRestrictions(guestRestrictions, guest.id);
826bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            } catch (RemoteException re) {
827bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani                Log.w(TAG, "Could not update guest restrictions");
828bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
8291e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
8301e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
8311e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
8321e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
8331e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
834aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * Creates a secondary user with the specified name and options and configures it with default
835aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * restrictions.
836aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
837aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     *
838aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @param name the user's name
839aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @param flags flags that identify the type of user and other properties.
840aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @see UserInfo
841aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     *
842aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
843aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @hide
844aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     */
845aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    public UserInfo createSecondaryUser(String name, int flags) {
846aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        try {
847aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            UserInfo user = mService.createUser(name, flags);
848aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            if (user == null) {
849aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani                return null;
850aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            }
851aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            Bundle userRestrictions = mService.getUserRestrictions(user.id);
852aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            addDefaultUserRestrictions(userRestrictions);
853aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            mService.setUserRestrictions(userRestrictions, user.id);
854aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            return user;
855aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        } catch (RemoteException re) {
856aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            Log.w(TAG, "Could not create a user", re);
857aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            return null;
858aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        }
859aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    }
860aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani
861aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    private static void addDefaultUserRestrictions(Bundle restrictions) {
862aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
863aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_SMS, true);
864aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    }
865aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani
866aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
8672a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
868a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
869a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
870a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
871a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
872a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
8732a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
874a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
875a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
876a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
877a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
8782a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
879a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
8802a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
881a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
882a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
883a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
884a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
885a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
886a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
887a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
8881df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
8891df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
8901df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
8911df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
8921df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
8931df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
8941df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
8951df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
8961df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
8971df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
8981df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
8991df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
9001df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
9011df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
9021df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
9031df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
904df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
905df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
906df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
907df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
908df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
909df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
910df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
911df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
912df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
913df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
914df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
915df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
916df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
917df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
918df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
919df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
920b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
921b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
922b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
923b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
924b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
925b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
926b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
927b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
928258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
9291952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
930258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
931258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
932258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
933258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
934258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
935920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
936920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
937920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
938920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
939920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
940920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
941920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
942920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
94395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
94495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
94595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
94695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
94795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
94895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
94995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
95095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
95195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
95295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
95395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
95495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
95595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
95695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
95795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
95895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
95995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
96095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
96195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
96295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
96372434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
96472434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
96572434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
96672434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
96772434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
96872434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
96972434b7088591828082dd952496d523ef3622de2Nicolas Prevot    public boolean canAddMoreManagedProfiles() {
97072434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
97172434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return mService.canAddMoreManagedProfiles();
97272434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
97372434b7088591828082dd952496d523ef3622de2Nicolas Prevot            Log.w(TAG, "Could not check if we can add more managed profiles", re);
97472434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return false;
97572434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
97672434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
97772434b7088591828082dd952496d523ef3622de2Nicolas Prevot
97872434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
9792a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
9802a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
9814f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
9827f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
9834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
9842a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
9852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
9862a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
9872a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
9882a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
9892a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
990a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
991385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
992a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
993a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
994a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
995a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
996a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
997a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
998a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
9997f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
10007f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
10017f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
10027f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
10037f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
10047f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
10057f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
10067f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
10077f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
10087f75da2405cd910854448bb3801f776e036f926aRuben Brunk    public List<UserInfo> getEnabledProfiles(int userHandle) {
10097f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
10107f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
10117f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
10127f75da2405cd910854448bb3801f776e036f926aRuben Brunk            Log.w(TAG, "Could not get user list", re);
10137f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return null;
10147f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
10157f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
10167f75da2405cd910854448bb3801f776e036f926aRuben Brunk
10177f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1018be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1019be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
10204f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
10214f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
10224f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
10234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
10244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
1025385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
1026385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
1027f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1028385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1029385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
1030385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
1031385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
10324f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
10334f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
10344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
10354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
10364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
10374f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
10384f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
10397dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1040be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1041be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1042be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1043be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1044be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
1045be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
1046be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
1047be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
1048be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
1049be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
1050be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
1051be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
1052be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
1053be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
1054be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
10557dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
10567dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
1057c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
1058c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1059c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1060c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1061c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1062c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1063c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1064c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1065c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1066c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
1067c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1068c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
1069c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1070c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1071c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1072c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1073c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1074c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
1075c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1076c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
1077c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
1078c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
1079c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
1080c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
1081c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
1082c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
1083c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1084c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1085c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1086c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1087c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1088c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1089c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
1090c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1091c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
1092c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
1093c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
1094c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
1095c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1096c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
1097c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
1098c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1099c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1100c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1101c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1102c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
1103c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1104c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
11054f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11064f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
1107701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
1108701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
1109f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
1110f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
1111f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
1112f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
1113f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
1114f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
1115f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
1116f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
1117c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1118f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
1119237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1120c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
11214f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11224f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
11234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
11244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
11254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1126394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
11274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
11284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
1129920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
1130920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
1131920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
1132920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
1133920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
1134920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
1135258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1136258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
1137258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
1138258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1139258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1140258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1141258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
11431952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1144258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
1145258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1146258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1147258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
1148258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1149258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
1150258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1151258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
1152258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
1153258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1154258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1155258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1156258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1157258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
11581952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1159258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1160258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
1161258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
1162258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1163258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1164258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
1165258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1166258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
1167258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1168258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
1169258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1170258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1171258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1172258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1173e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
1174258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
1175e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
1176258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1177258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1178e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
1179258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1180e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
1181258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1182258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1183258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1185258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1186258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
11873b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
11883b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1189e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
119064d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
11913b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
11923b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1193e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
11943b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
11951bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
11961bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
11971bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
11981bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
11991bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
12001bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
12011bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
12021bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
12031bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
12041bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
12051bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
12063b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1207e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
12083b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
12091bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
12103b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
12113b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
12123b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1213258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1214258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1215258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1216a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1217258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
121827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1219ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1220ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1221409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1222409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
122327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
122427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1225258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
12262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
12272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
12281a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
12291a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
12301a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
12311a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
12321a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
12331a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
12341a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
12351a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
12361a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
12371a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
12381a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
12391a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
12401a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            if (user.supportsSwitchTo()) {
12411a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
12421a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
12431a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1244a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1245a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1246a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
12471a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
12481a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
12491a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
12502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
12512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
12522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
12532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
12542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
12552a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
12562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
12572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
12582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
12592a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
12602a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
12612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
12622a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
12632a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
12642a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
12652a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
12662a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
12672a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
12682a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
12692a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
12702a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
12712a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
12722a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
12732a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
12742a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
12752a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
12762a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
12772a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
12782a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
12792a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
12802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
12812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
12826794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
12837e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
12847e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
12857e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
12867e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
12877e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
12887e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
12897e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
12907e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
12917e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
12927e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
12937e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
12947e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
12957e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
12967e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
12977e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
12987e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1299df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1300df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1301df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1302df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
13037e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1304df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
13057e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1306df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1307df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1308df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1309df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1310df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1311df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1312df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1313df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1314df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
13157e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1316df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1317df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
13187e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1319df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1320df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1321df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1322df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1323655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1324655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1325d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1326d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1327d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1328d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1329ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1330ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
1331655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1332d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1333655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1334655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
13351a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
13361a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
13371a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
13381a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
13391a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
13401a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
13411a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
13421a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
13431a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1344e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1345e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1346e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1347e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1348e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1349e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1350e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1351e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1352e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1353e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1354e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1355e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1356e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1357e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1358e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1359e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1360e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1361e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1362e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1363e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1364e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1365e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1366e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1367e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1368e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1369ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
1370ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
1371ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
1372ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
1373ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
1374ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
1375ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
1376385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
1377ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
1378385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
1379ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
1380ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            Log.w(TAG, "Could not get user creation time", re);
1381ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            return 0;
1382ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
1383ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
1384258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1385