UserManager.java revision 0e8d7d63ba439cc0604af7055679dae3d30fdc48
1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/*
2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project
3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License");
5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License.
6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at
7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *      http://www.apache.org/licenses/LICENSE-2.0
9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software
11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS,
12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and
14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License.
15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os;
17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
180e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi;
19409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
20a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
22258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
246794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Canvas;
264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Bitmap.Config;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.BitmapDrawable;
294f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
301e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
321c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
346794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
356794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
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    /**
4971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from adding and removing
5071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * accounts.
5171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
53e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * 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    /**
6071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi
612cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * access points. The default value is <code>false</code>.
6271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
63e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
68e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
69e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from installing applications.
7171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
73e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
79e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications.
8171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
83e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
84e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
85e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
8771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
88e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
8971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing.
9171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
9271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
936794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * Type: Boolean
946794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
956794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
966794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
9771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
986794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
99a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
100a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from enabling the
101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
102a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth.
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from transferring files over
1222cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * USB. This can only be set by device owners. The default value is <code>false</code>.
123a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
124a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
129a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
130b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
131b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Key for user restrictions. Specifies if a user is disallowed from configuring user
132b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
133b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
134b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
135b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
136b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
137b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
138b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
139b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
140b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
1415b8224901b5de0cfe7b4a1d3cb158e38243ef99fJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from removing itself and other
1422cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * users. The default value is <code>false</code>.
143b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
144b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
145b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
146b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
147b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
148b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
149b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
150d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
151d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from enabling or
152d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
153d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
154d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
155d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
156d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
157d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
158d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
159d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
160d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
161d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring VPN.
162d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
163d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
164d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
165d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
166d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
167d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
168d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
169d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
170d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
171d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring Tethering
1722cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * & portable hotspots. This can only be set by device owners. The default value is
1732cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * <code>false</code>.
174d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
175d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
176d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
177d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
178d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
179d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
180d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
181d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
182d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from factory resetting
1832cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * from Settings. This can only be set by device owners. The default value is
1842cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * <code>false</code>.
185d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
186d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
187d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
188d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
189d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from adding new users and
1932cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * profiles. This can only be set by device owners. The default value is <code>false</code>.
194d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
195d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
196d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
197d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
198d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
199d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_ADD_USER = "no_add_user";
200d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
201d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
202d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from disabling application
203d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * verification. The default value is <code>false</code>.
204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
206d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
207d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
208d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
209d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
210d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
211d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
212d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring cell
2132cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * broadcasts. This can only be set by device owners. The default value is <code>false</code>.
214d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
215d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
216d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
217d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
218d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
219d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
220d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
221d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
222d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring mobile
2232cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * networks. This can only be set by device owners. The default value is <code>false</code>.
224d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
225d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
226d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
227d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
228d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
229d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
230d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
231d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
232c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from modifying
233c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * applications in Settings or launchers. The following actions will not be allowed when this
234c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * restriction is enabled:
235c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>uninstalling apps</li>
236c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>disabling apps</li>
237c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app caches</li>
238c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app data</li>
239c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>force stopping apps</li>
240c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <li>clearing app defaults</li>
241c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * <p>
242c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds     * The default value is <code>false</code>.
243d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
244d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
245d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
246d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
24836fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
250394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
251394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from mounting
2522cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * physical external media. This can only be set by device owners. The default value is
2532cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * <code>false</code>.
254394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
255394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
256394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
257394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
258394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
259394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
260394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
261394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
262394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting microphone
2632cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * volume. If set, the microphone will be muted. This can only be set by device owners.
264394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
265394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
266394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
267394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
268394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
269394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
270394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
271394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
272394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
273394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting the master
2742cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * volume. If set, the master volume will be muted. This can only be set by device owners.
275394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
276394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
277394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
278394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
279394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
280394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
281394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
282394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
2839f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
284390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * Key for user restrictions. Specifies that the user is not allowed to make outgoing
285390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * phone calls. Emergency calls are still permitted.
286390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * The default value is <code>false</code>.
287390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * <p/>
288390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * Type: Boolean
289390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #setUserRestrictions(Bundle)
290390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     * @see #getUserRestrictions()
291390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani     */
292390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
293390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani
294390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    /**
2959f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Key for user restrictions. Specifies that the user is not allowed to send or receive
2962cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * SMS messages. This can only be set by device owners. The default value is <code>false</code>.
2979f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * <p/>
2989f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Type: Boolean
2999f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
3009f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
3019f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
302390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani    public static final String DISALLOW_SMS = "no_sms";
3039f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
3041c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
3051c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * Key for user restrictions. Specifies that windows besides app windows should not be
3061c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
3071c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
3081c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
3091c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
3101c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
3111c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
3121c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
3131c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
3142cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds     * <p>This can only be set by device owners. The default value is <code>false</code>.
3151c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <p/>
3161c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * Type: Boolean
3171c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
3181c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
3191c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3201c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
3211c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
322f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    /**
323f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * Key for user restrictions. Specifies if what is copied in the clipboard of this profile can
324f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
325f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * pasted in this profile.
326f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * The default value is <code>false</code>.
327f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * <p/>
328f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * Type: Boolean
329f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #setUserRestrictions(Bundle)
330f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     * @see #getUserRestrictions()
331f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot     */
332f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot    public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
333f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot
334655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
335655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
336655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
337655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
338655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
339655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
340655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
34127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
34227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
3437e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
34427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
34527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
34627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
34727db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
34827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
34927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
350a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
351258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
352258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
353258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
354258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
355258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
356258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
357258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
358258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
3591a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
360e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
361258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
3624673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
3631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
3641a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
3651a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
366258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
367258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
3686794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
369be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the user handle for the user that the calling process is running on.
370be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
371258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user handle of the user making this call.
372258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
3736794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
374258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
37579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
376258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
377258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
378258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
3798832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
3808832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
3818832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
382258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
383258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
384258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
385258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
386258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
387258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
388258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
389258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
390258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
391258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
392258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
393e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill   /**
394e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
395e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
396a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return whether the user making this call is a goat
397e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
398e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
399e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill        return false;
400e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
401df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
402df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
403e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
40446bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
405e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
4062555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
407df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
408e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
409df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
41071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
411df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
41246bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
413df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
414df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
415df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
416df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
417258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
4181e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
4191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
4201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
4211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
4221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
4231e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
4241e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
4251e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
4261e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
4271e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
4280e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Checks if the calling app is running in a managed profile.
4290e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
4300e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     *
4310e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @return whether the caller is in a managed profile.
4320e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     * @hide
4330e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani     */
4340e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    @SystemApi
4350e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    public boolean isManagedProfile() {
4360e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
4370e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani        return user != null ? user.isManagedProfile() : false;
4380e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    }
4390e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani
4400e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani    /**
441a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
442a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
443a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
444a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
445a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
446a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
447a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
448a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
449a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
450a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
451a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
452a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
453a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
454a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
455a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
456a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
457a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
458a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
459a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
460a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
461a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
462a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
463a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
464a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
465a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
466a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
467a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
468a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
469a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
470a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
471a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
472a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
473a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
474258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
4751952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
476258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
477258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
478258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
479b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
480258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
481258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
482258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
483258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
484258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
485258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
486258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
487258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
488258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
48971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
49071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
49171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
49271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
493e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
494e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
495e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
496e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
49771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
49871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
49971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
50071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
50171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
502e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
503e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
504e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
505e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
506e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
507e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
508e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
509e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
510e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
51171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
51271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
513be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
51471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
5153d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5163d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5173d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5183d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
51971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5203d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
521e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
522e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
523e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
524e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
52571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
52671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
527be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
52871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
52971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
5303d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5313d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5323d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5333d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
53471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5353d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
536e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
537e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
538e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
539e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
540e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
541e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
542e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
543e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
54471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
54571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
546be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
54771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
54871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
5493d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5503d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5513d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5523d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
55371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5543d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
55571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
55671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
55771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
55871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
55971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
56071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
56171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
56271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
56371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
564be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
56571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
56671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
56771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
5683d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
5693d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} or
5703d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
5713d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds     * android.content.ComponentName, String)} instead.
57271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5733d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds    @Deprecated
5746794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
5756794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        Bundle bundle = getUserRestrictions(userHandle);
5766794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        bundle.putBoolean(key, value);
5776794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        setUserRestrictions(bundle, userHandle);
5786794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
5796794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
580258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
581a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
582a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
5832b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
5842b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
5852b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
586a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
587a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
588b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
589b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
590b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
591b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
592b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
593b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
594b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
595b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
596b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
597b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
598b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
599b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return getUserRestrictions(userHandle).getBoolean(restrictionKey, false);
600a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
601a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
602a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
60333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
604b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
605b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
60633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
607b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
608b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
60933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
61033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
61133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
61233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
61333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
61433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
61533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
61633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
61733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
61833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
61933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
62033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
62133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
62233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
62333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
62433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
62533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        int ident = getUserHandle((int)serialNumber);
62633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
62733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
62833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
62933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
630258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
6311952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
632258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
633258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
634258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
635258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
636258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
637258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
638258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
639258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
640258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
641258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
642258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
643258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
644258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
645258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
646258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
647258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
648258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
649258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
6501e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
6511e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
6521e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
6531e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
6541e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
6551e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
6561e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
6571e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
6581e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
6591e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
660bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            try {
6618616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
6628616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                guestRestrictions.putBoolean(DISALLOW_SMS, true);
6638616af1a4dd1877996fbd5bb0179659f4f123573Amith Yamasani                mService.setUserRestrictions(guestRestrictions, guest.id);
664bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            } catch (RemoteException re) {
665bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani                Log.w(TAG, "Could not update guest restrictions");
666bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani            }
6671e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
6681e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
6691e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
6701e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
6711e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
6722a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
673a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
674a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
675a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
676a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
677a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
6782a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
679a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
680a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
681a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
682a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
6832a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
684a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
6852a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
686a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
687a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
688a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
689a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
690a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
691a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
692a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
6931df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @hide
6941df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * Marks the guest user for deletion to allow a new guest to be created before deleting
6951df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * the current user who is a guest.
6961df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @param userHandle
6971df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     * @return
6981df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani     */
6991df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    public boolean markGuestForDeletion(int userHandle) {
7001df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        try {
7011df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return mService.markGuestForDeletion(userHandle);
7021df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        } catch (RemoteException re) {
7031df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            Log.w(TAG, "Could not mark guest for deletion", re);
7041df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani            return false;
7051df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani        }
7061df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    }
7071df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani
7081df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani    /**
709df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
710df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
711df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
712df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
713df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
714df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
715df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
716df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
717df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
718df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
719df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
720df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
721df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
722df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
723df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
724df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
725b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
726b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
727b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
728b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
729b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
730b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
731b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
732b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
733258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
7341952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
735258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
736258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
737258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
738258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
739258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
740920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
741920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
742920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
743920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
744920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
745920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
746920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
747920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
74895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
74995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * permission.
75095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     *
75195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @return true if more users can be added, false if limit has been reached.
75295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     * @hide
75395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani     */
75495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    public boolean canAddMoreUsers() {
75595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final List<UserInfo> users = getUsers(true);
75695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        final int totalUserCount = users.size();
75795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        int aliveUserCount = 0;
75895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        for (int i = 0; i < totalUserCount; i++) {
75995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            UserInfo user = users.get(i);
76095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            if (!user.isGuest()) {
76195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani                aliveUserCount++;
76295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani            }
76395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        }
76495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani        return aliveUserCount < getMaxSupportedUsers();
76595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    }
76695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani
76795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani    /**
7682a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
7692a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
7704f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani     * Note that this returns both enabled and not enabled profiles. See
771385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * {@link #getUserProfiles()} if you need only the enabled ones.
7724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
7732a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
7742a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
7752a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
7762a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
7772a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
7782a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
779a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
780385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
781a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
782a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
783a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
784a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
785a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
786a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
787a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
788be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
789be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
7904f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
7914f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
7924f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
7934f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
7944f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
795385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
796385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
797f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
798385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
799385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
800385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
801385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
8024f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
8034f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
8044f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
8054f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
8064f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
8074f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
8084f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
8097dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
810be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
811be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
812be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
813be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
814be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
815be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
816be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
817be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
818be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
819be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
820be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
821be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
822be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
823be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
824be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
8257dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
8267dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
827c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * icon to be able to distinguish it from the original icon. For badging an
828c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * arbitrary drawable use {@link #getBadgedDrawableForUser(
829c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
830c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
831c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
832c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
833c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
834c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
835c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
836c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param icon The icon to badge.
837c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
838c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original icon and a badge as
839c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
840c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
841c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
842c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
843c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (badgeResId == 0) {
844c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            return icon;
845c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        }
846c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        Drawable badgeIcon = mContext.getPackageManager()
847c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                .getDrawable("system", badgeResId, null);
848c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        return getBadgedDrawable(icon, badgeIcon, null, true);
849c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
850c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
851c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
852c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
853c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
8547dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * icon to be able to distinguish it from the original icon.
855c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
8567dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the original drawable is not a BitmapDrawable, then the original
8577dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * drawable is returned.
858c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
8597dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *
8607dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param icon The icon to badge.
8617dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param user The target user.
8627dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @return A drawable that combines the original icon and a badge as
8637dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *         determined by the system.
864c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
865c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @deprecation Use {@link #getBadgedIconForUser(
866c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *     android.graphics.drawable.Drawable, UserHandle)}
867c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
868c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @hide
8697dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     */
870c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    @Deprecated
8714f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public Drawable getBadgedDrawableForUser(Drawable icon, UserHandle user) {
8724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        int badgeResId = getBadgeResIdForUser(user.getIdentifier());
8734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        if (badgeResId == 0) {
8744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            return icon;
8754f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        } else {
8764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            Drawable badgeIcon = mContext.getPackageManager()
8774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani                    .getDrawable("system", badgeResId, null);
878c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            return getBadgedDrawable(icon, badgeIcon, null, false);
879c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        }
880c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    }
881c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
882c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    /**
883c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the target user is a managed profile of the calling user or the caller
884c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is itself a managed profile, then this returns a badged copy of the given
885c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * drawable allowing the user to distinguish it from the original drawable.
886c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * The caller can specify the location in the bounds of the drawable to be
887c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badged where the badge should be applied as well as the density of the
888c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * badge to be used.
889c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * <p>
890c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * If the original drawable is a BitmapDrawable and the backing bitmap is
891c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
892c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * is performed in place and the original drawable is returned.
893c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * </p>
894c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *
895c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgedDrawable The drawable to badge.
896c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param user The target user.
897c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeLocation Where in the bounds of the badged drawable to place
898c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the badge. If not provided, the badge is applied on top of the entire
899c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         drawable being badged.
900c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param badgeDensity The optional desired density for the badge as per
901c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
902c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the display is used.
903c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @return A drawable that combines the original drawable and a badge as
904c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         determined by the system.
905c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     */
906c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
907c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, int badgeDensity) {
908c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        Drawable badgeDrawable = getBadgeForUser(user, badgeDensity);
909c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (badgeDrawable == null) {
910c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            return badgedDrawable;
9114f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
912c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        return getBadgedDrawable(badgedDrawable, badgeDrawable, badgeLocation, true);
9134f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
9144f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
915701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
916701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
917f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
918f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
919f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
920f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
921f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
922f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
923f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
924f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
925f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
926237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy    public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
927f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
928f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
929f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy            return Resources.getSystem().getString(
930f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy                    R.string.managed_profile_label_badge, label);
931f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        }
932f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        return label;
933f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    }
934f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy
935f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    /**
936f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * If the target user is a managed profile of the calling user or the caller
937701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * is itself a managed profile, then this returns a drawable to use as a small
938701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * icon to include in a view to distinguish it from the original icon.
939701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *
940701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @param user The target user.
941c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     * @param density The optional desired density for the badge as per
942c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
943c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav     *         the density of the current display is used.
944701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return the drawable or null if no drawable is required.
945701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @hide
946701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
947c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    public Drawable getBadgeForUser(UserHandle user, int density) {
948701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
949701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
950c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            if (density <= 0) {
951c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                density = mContext.getResources().getDisplayMetrics().densityDpi;
952c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            }
953c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            return Resources.getSystem().getDrawableForDensity(
954c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                    com.android.internal.R.drawable.ic_corp_badge, density);
955701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
956701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
957701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
958701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
9594f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    private int getBadgeResIdForUser(int userHandle) {
9604f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        // Return the framework-provided badge.
961701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(userHandle);
962701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
963701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            return com.android.internal.R.drawable.ic_corp_icon_badge;
964701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
965701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return 0;
966701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
967701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
968701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
969701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return UserInfo for userHandle if it exists and is a profile of the current
970701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *         user or null.
971701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
972701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    private UserInfo getUserIfProfile(int userHandle) {
973be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        List<UserInfo> userProfiles = getProfiles(getUserHandle());
9745abdbb656063160ff8df2306bd01feba0714d4c1Amith Yamasani        for (UserInfo user : userProfiles) {
975701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            if (user.id == userHandle) {
976701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy                return user;
9774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            }
9784f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
979701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
9804f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
9814f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
982c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav    private Drawable getBadgedDrawable(Drawable badgedDrawable, Drawable badgeDrawable,
983c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            Rect badgeLocation, boolean tryBadgeInPlace) {
984c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        final int badgedWidth = badgedDrawable.getIntrinsicWidth();
985c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        final int badgedHeight = badgedDrawable.getIntrinsicHeight();
986c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        final boolean canBadgeInPlace = tryBadgeInPlace
987c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                && (badgedDrawable instanceof BitmapDrawable)
988c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                && ((BitmapDrawable) badgedDrawable).getBitmap().isMutable();
989c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
990c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        final Bitmap bitmap;
991c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (canBadgeInPlace) {
992c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            bitmap = ((BitmapDrawable) badgedDrawable).getBitmap();
993c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        } else {
994c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Config.ARGB_8888);
995c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        }
9964f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        Canvas canvas = new Canvas(bitmap);
997c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
998c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (!canBadgeInPlace) {
999c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgedDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
1000c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgedDrawable.draw(canvas);
10014f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
1002c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1003c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (badgeLocation != null) {
1004c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            if (badgeLocation.left < 0 || badgeLocation.top < 0
1005681bf60ce2a3973d5982f9b7a405bcef5fb72f20Sunny Goyal                    || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
1006c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                throw new IllegalArgumentException("Badge location " + badgeLocation
1007c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                        + " not in badged drawable bounds "
1008c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                        + new Rect(0, 0, badgedWidth, badgedHeight));
1009c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            }
1010c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
1011c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1012c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            canvas.save();
1013c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            canvas.translate(badgeLocation.left, badgeLocation.top);
1014c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgeDrawable.draw(canvas);
1015c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            canvas.restore();
1016c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        } else {
1017c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
1018c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            badgeDrawable.draw(canvas);
1019c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        }
1020c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1021c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        if (!canBadgeInPlace) {
1022c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
1023c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1024c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            if (badgedDrawable instanceof BitmapDrawable) {
1025c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                BitmapDrawable bitmapDrawable = (BitmapDrawable) badgedDrawable;
1026c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav                mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
1027c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            }
1028c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1029c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav            return mergedDrawable;
1030c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        }
1031c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav
1032c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav        return badgedDrawable;
10334f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
10344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
10354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
10364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
10374f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
1038394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
10394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
10404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
1041920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
1042920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
1043920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
1044920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
1045920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
1046920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
1047258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1048258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
1049258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
1050258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1051258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1052258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1053258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1054258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
10551952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1056258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
1057258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1058258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1059258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
1060258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1061258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
1062258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1063258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
1064258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
1065258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1066258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1067258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1068258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1069258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
10701952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
1071258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
1072258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
1073258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
1074258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1075258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1076258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
1077258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1078258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
1079258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1080258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
1081258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1082258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1083258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1084258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1085e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
1086258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
1087e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
1088258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1089258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1090e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
1091258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
1092e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
1093258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
1094258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
1095258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
1096258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
1097258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1098258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
10993b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
11003b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
1101e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
11023b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
11033b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
1104e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
11053b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
11063b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return mService.getUserIcon(userHandle);
11073b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
1108e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
11093b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return null;
11103b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
11113b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
11123b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
11133b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
1114258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
1115258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
1116258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
1118258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
111927bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
1120ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
1121ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
1122409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
1123409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
112427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
112527bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
1126258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
11272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
11282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
11291a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
11301a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
11311a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
11321a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
11331a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
11341a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
11351a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
11361a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
11371a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
11381a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
11391a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
11401a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
11411a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            if (user.supportsSwitchTo()) {
11421a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
11431a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
11441a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
1145a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
1146a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
1147a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
11481a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
11491a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
11501a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
11512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
11522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
11532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
11542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
11552a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
11562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
11572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
11582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
11592a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
11602a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
11612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
11622a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
11632a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
11642a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
11652a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
11662a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
11672a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
11682a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
11692a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
11702a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
11712a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
11722a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
11732a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
11742a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
11752a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
11762a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
11772a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
11782a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
11792a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
11802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
11812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
11822a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
11836794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
11847e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
11857e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
11867e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
11877e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
11887e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
11897e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
11907e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
11917e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
11927e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
11937e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
11947e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
11957e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
11967e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
11977e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
11987e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
11997e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
1200df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1201df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1202df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1203df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
12047e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
1205df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
12067e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
1207df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1208df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
1209df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1210df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
1211df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1212df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
1213df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
1214df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
1215df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
12167e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1217df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1218df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
12197e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1220df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1221df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1222df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1223df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1224655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1225655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1226d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1227d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1228d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1229d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1230655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1231d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1232655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1233d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.setRestrictionsChallenge(newPin);
1234655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1235655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1236655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1237655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1238655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1239655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1240655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1241655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @hide
1242655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
1243655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * allowing the user to enter the PIN.
1244655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return Returns a positive number (including zero) for how many milliseconds before
1245655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
1246655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
1247655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
1248655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1249d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public int checkRestrictionsChallenge(String pin) {
1250655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1251d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.checkRestrictionsChallenge(pin);
1252655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1253655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not check restrictions pin");
1254655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1255655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return PIN_VERIFICATION_FAILED_INCORRECT;
1256655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1257655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1258655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1259d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @hide
1260655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Checks whether the user has restrictions that are PIN-protected. An application that
1261655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * participates in restrictions can check if the owner has requested a PIN challenge for
1262655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * any restricted operations. If there is a PIN in effect, the application should launch
1263d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
1264d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
1265655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return whether a restrictions PIN is in effect.
1266655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1267d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean hasRestrictionsChallenge() {
1268655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1269d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.hasRestrictionsChallenge();
1270655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1271655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1272655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1273655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1274655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
12751a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
12761a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
12771a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
12781a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
12791a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
12801a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
12811a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
12821a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
12831a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1284e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1285e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1286e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1287e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1288e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1289e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1290e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1291e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1292e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1293e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1294e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1295e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1296e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1297e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1298e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1299e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1300e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1301e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1302e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1303e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1304e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1305e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1306e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1307e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1308e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1309258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1310