UserManager.java revision 7cb69df507f5f7956c52a2868a0d6e89aec6dde2
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
187cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable;
190e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
20409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
21a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
22258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
23258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
256794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
261bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
291e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
311c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
346794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
351bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException;
364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
48e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding and removing accounts.
5071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
5226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
5326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
54e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
59e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from changing Wi-Fi
612cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
62150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
6326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
6426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
6526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
68e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from installing applications.
7371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
7526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
7626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
79e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
81e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
82e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
8326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from uninstalling applications.
8471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
8626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
8726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
88e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
89e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
90e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
9171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
92e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
9371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
94150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * Specifies if a user is disallowed from turning on location sharing.
9571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
96150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>In a managed profile, location sharing always reflects the primary user's setting, but
97150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * can be overridden and forced off by setting this restriction to true in the managed profile.
9826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
9926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
10026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
1016794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
1026794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
1036794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
10471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
1056794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
10726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling the
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
11026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
11126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
11226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
11926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring bluetooth.
1201c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot     * This does <em>not</em> restrict the user from turning bluetooth on or off.
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
122150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect in a managed profile.
12326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
12426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
12526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
129a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
130a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
131a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
13226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from transferring files over
133c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * USB. This can only be set by device owners and profile owners on the primary user.
134c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
13526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
13726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
138a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
139a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
140a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
141a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
142a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
143b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
14426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring user
145b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
14626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
14726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
149b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
150b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
151b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
152b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
153b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
154b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
155150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on the primary user this specifies if the user can remove other users.
156150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * When set on a secondary user, this specifies if the user can remove itself.
157150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * This restriction has no effect on managed profiles.
158150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * The default value is <code>false</code>.
15926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
16026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
16126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
162b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
163b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
164b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
165b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
166b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
167d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
16826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from enabling or
169d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
17026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
17126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
17226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
173d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
174d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
175d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
176d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
178d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
17926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring VPN.
180d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
181298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * This restriction has an effect in a managed profile only from
182298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot     * {@link android.os.Build.VERSION_CODES#MNC}
18326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
18426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
18526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
186d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
187d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
188d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
189d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
19226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring Tethering
193c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * & portable hotspots. This can only be set by device owners and profile owners on the
194c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
19526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
19626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
19726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
198d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
204e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * Specifies if a user is disallowed from resetting network settings
205e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * from Settings. This can only be set by device owners and profile owners on the primary user.
206e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * The default value is <code>false</code>.
207e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>This restriction has no effect on secondary users and managed profiles since only the
208e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * primary user can reset the network settings of the device.
209e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     *
210e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Key for user restrictions.
211e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * <p/>Type: Boolean
212e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #setUserRestrictions(Bundle)
213e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     * @see #getUserRestrictions()
214e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott     */
215e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
216e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott
217e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott    /**
21826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from factory resetting
219c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * from Settings. This can only be set by device owners and profile owners on the primary user.
220c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
221150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
222150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can factory reset the device.
22326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
22426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
22526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
228d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
229d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
231d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
23226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adding new users and
233c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * profiles. This can only be set by device owners and profile owners on the primary user.
234c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
235150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
236150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can add other users.
23726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
23826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
23926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
240d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
241d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
242d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
243d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
244d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
245d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
24626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from disabling application
247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
24826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
24926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
25026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
252d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
253d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
254d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
255d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
256d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
25726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring cell
258c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * broadcasts. This can only be set by device owners and profile owners on the primary user.
259c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
260150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
261150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure cell broadcasts.
26226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
26326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
26426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
265d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
266d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
267d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
268d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
269d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
270d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
27126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from configuring mobile
272c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * networks. This can only be set by device owners and profile owners on the primary user.
273c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
274150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on secondary users and managed profiles since only the
275150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * primary user can configure mobile networks.
27626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
27726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
27826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
279d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
280d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
281d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
282d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
283d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
284d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
28526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from modifying
286c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
287c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
288c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
289c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
290c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
291c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
292c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
293c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
294c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
295c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
29626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
29726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
29826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
299d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
300d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
301d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
30236fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
303d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
304394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
30526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from mounting
306c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * physical external media. This can only be set by device owners and profile owners on the
307c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * primary user. The default value is <code>false</code>.
30826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
31026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
311394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
312394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
313394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
314394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
315394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
316394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
31726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting microphone
318c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the microphone will be muted. This can only be set by device owners
319c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
32226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
323394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
324394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
325394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
326394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
327394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
328394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
32926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if a user is disallowed from adjusting the master
330c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * volume. If set, the master volume will be muted. This can only be set by device owners
331c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * and profile owners on the primary user. The default value is <code>false</code>.
33226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
33426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
335394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
336394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
337394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
338394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
339394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
3409f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
34126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to make outgoing
342390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
343390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
344150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * <p/>This restriction has no effect on managed profiles since call intents are normally
345150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani     * forwarded to the primary user.
34626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
34726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
34826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
349390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #setUserRestrictions(Bundle)
350390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
351390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
352390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
353390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
354390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
35526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that the user is not allowed to send or receive
356c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * SMS messages. The default value is <code>false</code>.
35726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
35826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
35926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3609f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
3619f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3629f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
363390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3649f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3651c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
3662cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * Specifies if the user is not allowed to have fun. In some cases, the
3672cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * device owner may wish to prevent the user from experiencing amusement or
3682cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * joy while using the device. The default value is <code>false</code>.
3692cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     *
3702cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Key for user restrictions.
3712cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * <p/>Type: Boolean
3722cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #setUserRestrictions(Bundle)
3732cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     * @see #getUserRestrictions()
3742cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey     */
3752cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    public static final String DISALLOW_FUN = "no_fun";
3762cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey
3772cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey    /**
37826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies that windows besides app windows should not be
3791c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
3801c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
3811c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
3821c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
3831c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
3841c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
3851c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
3861c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
387c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * <p>This can only be set by device owners and profile owners on the primary user.
388c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani     * The default value is <code>false</code>.
38926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
39026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
39126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
3921c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
3931c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
3941c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3951c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
3961c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
397f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
39826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if what is copied in the clipboard of this profile can
399f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
400f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
401f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
40226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
40326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
40426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
405f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #setUserRestrictions(Bundle)
406f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
407f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
408f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
409f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
41026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    /**
41126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * Specifies if the user is not allowed to use NFC to beam out data from apps.
41226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * The default value is <code>false</code>.
41326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     *
41426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Key for user restrictions.
41526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * <p/>Type: Boolean
41626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #setUserRestrictions(Bundle)
41726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     * @see #getUserRestrictions()
41826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani     */
41926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani    public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
42026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani
42153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    /**
422f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
423f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * is always set for managed profiles.
424f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @hide
425f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #setUserRestrictions(Bundle)
426f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     * @see #getUserRestrictions()
427f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz     */
428f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    public static final String DISALLOW_WALLPAPER = "no_wallpaper";
429f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz
430f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz    /**
431bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * Specifies if the user is not allowed to reboot the device into safe boot mode.
432bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * This can only be set by device owners and profile owners on the primary user.
433bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * The default value is <code>false</code>.
434bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     *
435bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Key for user restrictions.
436bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * <p/>Type: Boolean
437bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #setUserRestrictions(Bundle)
438bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     * @see #getUserRestrictions()
439bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz     */
440bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
441bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz
442bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz    /**
443b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * Specifies if a user is not allowed to record audio. This restriction is always enabled for
444b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * background users. The default value is <code>false</code>.
445b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     *
446b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #setUserRestrictions(Bundle)
447b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @see #getUserRestrictions()
448b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     * @hide
449b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov     */
450b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
451b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov
452b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov    /**
453f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     * Allows apps in the parent profile to handle web links from the managed profile.
454f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot     *
4559edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * This user restriction has an effect only in a managed profile.
4569edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * If set:
4579edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * Intent filters of activities in the parent profile with action
4589edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * {@link android.content.Intent#ACTION_VIEW},
4599edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
4609edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * define a host can handle intents from the managed profile.
4619edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * The default value is <code>false</code>.
4629edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     *
4639edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Key for user restrictions.
4649edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * <p/>Type: Boolean
4659edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #setUserRestrictions(Bundle)
4669edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     * @see #getUserRestrictions()
4679edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot     */
468f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot    public static final String ALLOW_PARENT_PROFILE_APP_LINKING
469f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot            = "allow_parent_profile_app_linking";
4709edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot
4719edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot    /**
47253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Application restriction key that is used to indicate the pending arrival
47353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * of real restrictions for the app.
47453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
47553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p>
47653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * Applications that support restrictions should check for the presence of this key.
47753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * A <code>true</code> value indicates that restrictions may be applied in the near
47853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * future but are not available yet. It is the responsibility of any
47953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * management application that sets this flag to update it when the final
48053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * restrictions are enforced.
48153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     *
48253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Key for application restrictions.
48353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     * <p/>Type: Boolean
484b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
485b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String, Bundle)
486b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
487b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot     *      android.content.ComponentName, String)
48853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse     */
48953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse    public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
49053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse
491655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
492655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
493655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
494655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
495655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
496655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
497655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
49827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
49927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
5007e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
50127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
50227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
50327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
50427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
50527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
50627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
507a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
508258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
509258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
510258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
512258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
513258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
514258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
5161a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
517e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
518258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
5194673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
5201a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
5211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
5221a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
524258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
5256794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
5267cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @hide
5277cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * @return Whether the device is running with split system user. It means the system user and
5287cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * primary user are two separate users. Previously system user and primary user are combined as
5297cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
5307cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen     */
5317cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public static boolean isSplitSystemUser() {
5327cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen        return SystemProperties.getBoolean("ro.fw.system_user_split", false);
5337cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    }
5347cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen
5357cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    /**
5365760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Returns the user handle for the user that this process is running under.
537be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
5385760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return the user handle of this process.
539258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
5406794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
541258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
54279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
543258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
544258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
545258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5468832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
5478832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
5488832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
549258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
550258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
551258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
558258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
559258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
56067a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn    /**
561e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
562e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
56367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
564955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
56567a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * now automatically identify goats using advanced goat recognition technology.</p>
56667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     *
56767a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn     * @return Returns true if the user making this call is a goat.
568e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
569e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
570988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell        return mContext.getPackageManager()
571988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell                .isPackageAvailable("com.coffeestainstudios.goatsimulator");
572e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
573df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
574df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
57570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Used to check if this process is running under the primary user. The primary user
57670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * is the first human user on a device.
57770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
57870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return whether this process is running under the primary user.
57970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
58070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
58170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    public boolean isPrimaryUser() {
58270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        UserInfo user = getUserInfo(UserHandle.myUserId());
58370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return user != null ? user.isPrimary() : false;
58470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
58570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
58670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
5875760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * Used to check if this process is running under the system user. The system user
5885760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * is the initial user that is implicitly created on first boot and hosts most of the
5895760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * system services.
5905760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     *
5915760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     * @return whether this process is running under the system user.
5925760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani     */
5935760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    public boolean isSystemUser() {
59470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        return UserHandle.myUserId() == UserHandle.USER_SYSTEM;
5955760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    }
5965760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani    /**
597462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * @hide
598462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * Returns whether the caller is running as an admin user. There can be more than one admin
599462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     * user.
600462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani     */
601462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    public boolean isAdminUser() {
602462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
603462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani        return user != null ? user.isAdmin() : false;
604462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    }
605462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani
606462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani    /**
607e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
60846bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
609e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
6102555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
611df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
612e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
613df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
61471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
615df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
61646bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
617df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
618df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
619df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
620df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
621258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
6231e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
6241e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
6251e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
6261e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
6271e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
6281e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
6291e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
6301e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
6311e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
6320e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
6330e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
6340e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
6350e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
6360e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
6370e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
6380e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
6390e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
6400e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
6410e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
6420e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
6430e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
6440e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
645a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
646a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
647a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
648a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
649a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
650a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
651a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
652a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
653a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
654a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
655a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
656a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
657a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
658a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
659a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
660a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
661a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
662a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
663a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
664a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
665a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
666a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
667a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
668a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
669a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
670a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
671a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
672a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
673a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
674a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
675a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
676a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
677a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
678258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
6791952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
680258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
681258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
682258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
683b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
684258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
685258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
686258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
687258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
688258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
689258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
690258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
691258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
692258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
69371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
69471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
69571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
69671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
697e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
698e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
699e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
700e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
70171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
70271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
70371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
70471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
70571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
706e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
707e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
708e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
709e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
710e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
711e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
712e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
713e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
714e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
71571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
71671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
717be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
71871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
7193d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7203d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7213d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7223d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
72371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7243d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
725e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
726e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
727e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
728e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
72971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
73071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
731be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
73271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
73371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
7343d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7353d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7363d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7373d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
73871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7393d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
740e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
741e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
742e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
743e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
744e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
745e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
746e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
747e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
74871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
74971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
750be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
75171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
75271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
7533d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7543d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7553d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7563d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
75771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7583d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
75971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
76071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
76171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
76271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
76371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
76471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
76571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
76671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
76771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
768be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
76971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
77071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
77171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
7723d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
7733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
7743d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
7753d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
77671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
7773d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
7786794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
779b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        try {
780b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            mService.setUserRestriction(key, value, userHandle.getIdentifier());
781b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        } catch (RemoteException re) {
782b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov            Log.w(TAG, "Could not set user restriction", re);
783b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov        }
7846794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
7856794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
786258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
787a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
788a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
7892b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
7902b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
7912b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
792a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
793a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
794b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
795b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
796b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
797b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
798b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
799b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
800b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
801b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
802b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
803b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
804b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
8058cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        try {
8068cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return mService.hasUserRestriction(restrictionKey,
8078cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani                    userHandle.getIdentifier());
8088cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        } catch (RemoteException re) {
8098cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            Log.w(TAG, "Could not check user restrictions", re);
8108cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani            return false;
8118cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani        }
812a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
813a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
814a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
81533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
816b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
817b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
81833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
819b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
820b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
82133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
82233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
82333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
82433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
82533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
82633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
82733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
82833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
82933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
83033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
83133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
83233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
83333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
83433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
83533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
83633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
837ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov        int ident = getUserHandle((int) serialNumber);
83833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
83933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
84033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
84133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
842258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
8431952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
844258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
845258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
846258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
847258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
848258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
849258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
850258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
852258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
853258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
854258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
855258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
856258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
857258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
858258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
859258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
860258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
861258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8621e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
8631e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
8641e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
8651e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
8661e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
8671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
8681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
8691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
8701e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
8711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
872bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            try {
8738616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
8748616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_SMS, true);
87529ce85bab94a2d0dc98d9075ae86c8a282367117Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
8768616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                mService.setUserRestrictions(guestRestrictions, guest.id);
877bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            } catch (RemoteException re) {
878bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani                Log.w(TAG, "Could not update guest restrictions");
879bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
8801e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
8811e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
8821e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
8831e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
8841e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
885aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * Creates a secondary user with the specified name and options and configures it with default
886aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * restrictions.
887aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
888aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     *
889aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @param name the user's name
890aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @param flags flags that identify the type of user and other properties.
891aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @see UserInfo
892aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     *
893aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
894aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     * @hide
895aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani     */
896aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    public UserInfo createSecondaryUser(String name, int flags) {
897aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        try {
898aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            UserInfo user = mService.createUser(name, flags);
899aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            if (user == null) {
900aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani                return null;
901aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            }
902aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            Bundle userRestrictions = mService.getUserRestrictions(user.id);
903aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            addDefaultUserRestrictions(userRestrictions);
904aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            mService.setUserRestrictions(userRestrictions, user.id);
905aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            return user;
906aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        } catch (RemoteException re) {
907aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            Log.w(TAG, "Could not create a user", re);
908aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani            return null;
909aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        }
910aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    }
911aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani
912aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    private static void addDefaultUserRestrictions(Bundle restrictions) {
913aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
914aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani        restrictions.putBoolean(DISALLOW_SMS, true);
915aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    }
916aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani
917aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani    /**
9182a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
919a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
920a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
921a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
922a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
923a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
9242a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
925a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
926a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
927a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
928a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
9292a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
930a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
9312a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
932a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
933a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
934a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
935a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
936a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
937a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
938a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
9391df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
9401df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
9411df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
9421df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
9431df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
9441df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
9451df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
9461df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
9471df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
9481df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
9491df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
9501df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
9511df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
9521df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
9531df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
9541df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
955df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
956df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
957df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
958df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
959df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
960df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
961df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
962df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
963df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
964df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
965df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
966df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
967df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
968df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
969df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
970df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
971b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
972b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
973b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
974b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
975b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
976b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
977b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
978b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
979258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
9801952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
981258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
982258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
983258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
984258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
985258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
986920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
987920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
988920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
989920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
990920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
991920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
992920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
993920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
99470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Returns information for Primary user.
99570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
99670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     *
99770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @return the Primary user, null if not found.
99870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     * @hide
99970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen     */
10007cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen    public @Nullable UserInfo getPrimaryUser() {
100170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        try {
100270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return mService.getPrimaryUser();
100370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        } catch (RemoteException re) {
100470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            Log.w(TAG, "Could not get Primary user", re);
100570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen            return null;
100670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen        }
100770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    }
100870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen
100970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen    /**
101095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
101195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
101295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
101395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
101495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
101595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
101695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
101795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
101895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
101995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
102095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
102195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
102295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
102395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
102495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
102595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
102695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
102795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
102895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
102995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
103072434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
103172434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * permission.
103272434b7088591828082dd952496d523ef3622de2Nicolas Prevot     *
103372434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @return true if more managed profiles can be added, false if limit has been reached.
103472434b7088591828082dd952496d523ef3622de2Nicolas Prevot     * @hide
103572434b7088591828082dd952496d523ef3622de2Nicolas Prevot     */
103672434b7088591828082dd952496d523ef3622de2Nicolas Prevot    public boolean canAddMoreManagedProfiles() {
103772434b7088591828082dd952496d523ef3622de2Nicolas Prevot        try {
103872434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return mService.canAddMoreManagedProfiles();
103972434b7088591828082dd952496d523ef3622de2Nicolas Prevot        } catch (RemoteException re) {
104072434b7088591828082dd952496d523ef3622de2Nicolas Prevot            Log.w(TAG, "Could not check if we can add more managed profiles", re);
104172434b7088591828082dd952496d523ef3622de2Nicolas Prevot            return false;
104272434b7088591828082dd952496d523ef3622de2Nicolas Prevot        }
104372434b7088591828082dd952496d523ef3622de2Nicolas Prevot    }
104472434b7088591828082dd952496d523ef3622de2Nicolas Prevot
104572434b7088591828082dd952496d523ef3622de2Nicolas Prevot    /**
10462a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
10472a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
10484f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
10497f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * {@link #getEnabledProfiles(int)} if you need only the enabled ones.
10504f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
10512a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
10522a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
10532a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
10542a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
10552a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
10562a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
1057a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
1058385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
1059a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
1060a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
1061a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
1062a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
1063a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
1064a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
1065a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
10667f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Returns list of the profiles of userHandle including
10677f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * userHandle itself.
10687f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Note that this returns only enabled.
10697f75da2405cd910854448bb3801f776e036f926aRuben Brunk     *
10707f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
10717f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @param userHandle profiles of this user will be returned.
10727f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @return the list of profiles.
10737f75da2405cd910854448bb3801f776e036f926aRuben Brunk     * @hide
10747f75da2405cd910854448bb3801f776e036f926aRuben Brunk     */
10757f75da2405cd910854448bb3801f776e036f926aRuben Brunk    public List<UserInfo> getEnabledProfiles(int userHandle) {
10767f75da2405cd910854448bb3801f776e036f926aRuben Brunk        try {
10777f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return mService.getProfiles(userHandle, true /* enabledOnly */);
10787f75da2405cd910854448bb3801f776e036f926aRuben Brunk        } catch (RemoteException re) {
10797f75da2405cd910854448bb3801f776e036f926aRuben Brunk            Log.w(TAG, "Could not get user list", re);
10807f75da2405cd910854448bb3801f776e036f926aRuben Brunk            return null;
10817f75da2405cd910854448bb3801f776e036f926aRuben Brunk        }
10827f75da2405cd910854448bb3801f776e036f926aRuben Brunk    }
10837f75da2405cd910854448bb3801f776e036f926aRuben Brunk
10847f75da2405cd910854448bb3801f776e036f926aRuben Brunk    /**
1085be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
1086be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
10874f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
10884f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
10894f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
10904f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
10914f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
1092385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
1093385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
1094f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
1095385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
1096385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
1097385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
1098385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
10994f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
11004f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
11014f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
11024f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
11034f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
11044f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11054f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
11067dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
1107be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
1108be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
1109be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
1110be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
1111be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
1112be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
1113be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
1114be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
1115be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
1116be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
1117be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
1118be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
1119be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
1120be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
1121be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
11227dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
11237dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
1124c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
1125c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
1126c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
1127c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1128c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1129c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1130c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1131c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1132c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1133c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
1134c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1135c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
1136c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1137c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1138c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1139c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
1140c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedIcon(icon, user);
1141c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
1142c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1143c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
1144c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
1145c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
1146c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
1147c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
1148c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
1149c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
1150c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
1151c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
1152c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
1153c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
1154c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
1155c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
1156c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
1157c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
1158c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
1159c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
1160c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
1161c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
1162c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
1163c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
1164c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
1165c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
1166c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1167c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
1168c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
1169c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
1170c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
1171c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav                badgeLocation, badgeDensity);
11724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
1174701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
1175701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
1176f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
1177f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
1178f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
1179f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
1180f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
1181f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
1182f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
1183f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
1184c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav     * @removed
1185f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
1186237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
1187c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav        return mContext.getPackageManager().getUserBadgedLabel(label, user);
11884f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
11894f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
11904f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
11914f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
11924f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1193394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
11944f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
11954f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
1196920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
1197920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
1198920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
1199920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
1200920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
1201920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
1202258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1203258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
1204258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
1205258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1206258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1207258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1208258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1209258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
12101952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1211258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
1212258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1213258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1214258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
1215258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1216258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
1217258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1218258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
1219258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
1220258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1221258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1222258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1223258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1224258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
12251952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1226258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1227258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
1228258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
1229258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1230258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1231258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
1232258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1233258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
1234258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1235258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
1236258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1237258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1238258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1239258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1240e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
1241258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
1242e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
1243258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1244258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1245e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
1246258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1247e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
1248258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1249258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1250258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1251258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1252258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1253258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
12543b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
12553b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1256e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
125764d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina     * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
12583b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
12593b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1260e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
12613b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
12621bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
12631bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            if (fd != null) {
12641bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                try {
12651bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
12661bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                } finally {
12671bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    try {
12681bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                        fd.close();
12691bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    } catch (IOException e) {
12701bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                    }
12711bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos                }
12721bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos            }
12733b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1274e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
12753b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
12761bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos        return null;
12773b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
12783b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
12793b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1280258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1281258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1282258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1283a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1284258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
128527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1286ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1287ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1288409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1289409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
129027bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
129127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1292258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
12932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
12942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
12951a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
12961a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
12971a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
12981a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
12991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
13001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
13011a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
13021a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
13031a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
13041a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
13051a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
13061a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
13077cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen            if (user.supportsSwitchToByUser()) {
13081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
13091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
13101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1311a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1312a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1313a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
13141a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
13151a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
13161a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
13172a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
13182a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
13192a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
13202a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
13212a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
13222a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
13232a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
13242a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
13252a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
13262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
13272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
13282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
13292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
13302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
13312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
13322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
13332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
13342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
13352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
13362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
13372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
13382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
13392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
13402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
13412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
13422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
13432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
13442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
13452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
13462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
13472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
13482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
13496794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
13507e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
13517e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
13527e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
13537e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
13547e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
13557e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
13567e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
13577e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
13587e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
13597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
13607e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
13617e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
13627e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
13637e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
13647e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
13657e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1366df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1367df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1368df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1369df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
13707e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1371df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
13727e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1373df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1374df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1375df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1376df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1377df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1378df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1379df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1380df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1381df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
13827e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1383df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1384df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
13857e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1386df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1387df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1388df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1389df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1390655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1391655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1392d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1393d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1394d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1395d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1396ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * @deprecated The restrictions PIN functionality is no longer provided by the system.
1397ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov     * This method is preserved for backwards compatibility reasons and always returns false.
1398655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1399d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1400655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1401655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
14021a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
14031a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
14041a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
14051a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
14061a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
14071a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
14081a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
14091a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
14101a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1411e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1412e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1413e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1414e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1415e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1416e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1417e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1418e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1419e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1420e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1421e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1422e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1423e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1424e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1425e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1426e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1427e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1428e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1429e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1430e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1431e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1432e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1433e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1434e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1435e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1436ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov
1437ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    /**
1438ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * Returns creation time of the user or of a managed profile associated with the calling user.
1439ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @param userHandle user handle of the user or a managed profile associated with the
1440ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     *                   calling user.
1441ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     * @return creation time in milliseconds since Epoch time.
1442ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov     */
1443385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov    public long getUserCreationTime(UserHandle userHandle) {
1444ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        try {
1445385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov            return mService.getUserCreationTime(userHandle.getIdentifier());
1446ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        } catch (RemoteException re) {
1447ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            Log.w(TAG, "Could not get user creation time", re);
1448ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov            return 0;
1449ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov        }
1450ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov    }
1451258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1452