UserManager.java revision 5b8224901b5de0cfe7b4a1d3cb158e38243ef99f
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
18409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager;
19a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
20258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
236794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
244f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Canvas;
254f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Bitmap.Config;
264f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect;
274f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.BitmapDrawable;
284f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable;
291e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings;
30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
311c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams;
32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
336794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
346794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList;
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
39258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
47e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from adding and removing
4971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * accounts.
5071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
52e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
53e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
54e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi
6071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * access points.
6171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * 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
122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * USB. 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
1425b8224901b5de0cfe7b4a1d3cb158e38243ef99fJulia Reynolds     * users.
143b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * The default value is <code>false</code>.
144b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
145b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
146b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
147b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
148b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
149b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
150b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
151d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
152d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from enabling or
153d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * accessing debugging features. The default value is <code>false</code>.
154d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
155d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
156d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
157d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
158d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
159d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
160d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
161d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
162d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring VPN.
163d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <code>false</code>.
164d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p/>
165d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
166d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
167d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
168d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
169d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
170d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
171d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds    /**
172d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from configuring Tethering
173d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * & portable hotspots. The default value is <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
183d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * from Settings.
184d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * The default value is <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
193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * profiles. 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
213d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * broadcasts. 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
223d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * networks. 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    /**
23236fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds     * Key for user restrictions. Specifies if a user is disallowed from controlling
233d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * applications in Settings. The default value is <code>false</code>.
234d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * <p>
235d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * Type: Boolean
236d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #setUserRestrictions(Bundle)
237d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     * @see #getUserRestrictions()
238d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds     */
23936fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds    public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
240d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds
241394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
242394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from mounting
243394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * physical external media. The default value is <code>false</code>.
244394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
245394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
246394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
247394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
248394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
249394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
250394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
251394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
252394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting microphone
253394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * volume.
254394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
255394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
256394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
257394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
258394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
259394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
260394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
261394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
262394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    /**
263394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Key for user restrictions. Specifies if a user is disallowed from adjusting the master
264394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * volume.
265394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * The default value is <code>false</code>.
266394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * <p/>
267394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * Type: Boolean
268394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #setUserRestrictions(Bundle)
269394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     * @see #getUserRestrictions()
270394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     */
271394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier    public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
272394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier
2739f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    /**
2749f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Key for user restrictions. Specifies that the user is not allowed to send or receive
2759f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * phone calls or text messages. Emergency calls may still be permitted.
2769f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * The default value is <code>false</code>.
2779f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * <p/>
2789f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * Type: Boolean
2799f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #setUserRestrictions(Bundle)
2809f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     * @see #getUserRestrictions()
2819f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani     */
2829f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani    public static final String DISALLOW_TELEPHONY = "no_telephony";
2839f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani
2841c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    /**
2851c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * Key for user restrictions. Specifies that windows besides app windows should not be
2861c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * created. This will block the creation of the following types of windows.
2871c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_TOAST}</li>
2881c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PHONE}</li>
2891c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
2901c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
2911c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
2921c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
2931c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     *
2941c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <p>The default value is <code>false</code>.
2951c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * <p/>
2961c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * Type: Boolean
2971c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #setUserRestrictions(Bundle)
2981c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     * @see #getUserRestrictions()
2991c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk     */
3001c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk    public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
3011c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk
302655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
303655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
304655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
305655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
306655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
307655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
308655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
30927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
31027db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
3117e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
31227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
31327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
31427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
31527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
31627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
31727db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
318a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
319258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
320258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
321258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
322258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
323258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
324258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
325258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
326258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
3271a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if multiple users can be created by user, false if it is a single user device.
328e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
329258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
3304673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
3311a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        return getMaxSupportedUsers() > 1
3321a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                && SystemProperties.getBoolean("fw.show_multiuserui",
3331a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
334258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
335258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
3366794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
337be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the user handle for the user that the calling process is running on.
338be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
339258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user handle of the user making this call.
340258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
3416794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
342258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
34379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
344258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
345258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
346258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
3478832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
3488832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
3498832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
350258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
351258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
352258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
353258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
354258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
355258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
356258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
357258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
358258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
359258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
360258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
361e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill   /**
362e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
363e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
364a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return whether the user making this call is a goat
365e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
366e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
367e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill        return false;
368e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
369df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
370df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
371e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
37246bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
373e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
3742555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
375df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
376e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
377df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
37871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
379df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
38046bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
381df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
382df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
383df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
384df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
385258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
3861e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Checks if the calling app is running as a guest user.
3871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @return whether the caller is a guest user.
3881e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
3891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
3901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public boolean isGuestUser() {
3911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo user = getUserInfo(UserHandle.myUserId());
3921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return user != null ? user.isGuest() : false;
3931e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
3941e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
3951e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
396a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
397a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
398a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
399a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
400a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
401a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
402a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
403a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
404a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
405a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
406a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
407a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
408a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
409a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
410a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
411a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
412a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
413a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
414a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
415a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
416a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
417a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
418a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
419a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
420a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
421a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
422a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
423a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
424a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
425a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
426a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
427a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
428a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
429258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
4301952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
431258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
432258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
433258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
434b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
435258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
436258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
437258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
438258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
439258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
440258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
441258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
442258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
443258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
44471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
44571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
44671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
44771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
448e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
449e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
450e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
451e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
45271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
45371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
45471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
45571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
45671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
457e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
458e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
459e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
460e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
461e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
462e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
463e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
464e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
465e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
46671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
46771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
468be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
46971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
47071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
471e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
472e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
473e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
474e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
47571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
47671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
477be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
47871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
47971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
48071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
481e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
482e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
483e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
484e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
485e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
486e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
487e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
488e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
48971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
49071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
491be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
49271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
49371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
49471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
49571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
49671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
49771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
49871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
49971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
50071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
50171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
50271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
50371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
504be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani     * Requires the MANAGE_USERS permission.
50571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
50671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
50771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
50871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
5096794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
5106794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        Bundle bundle = getUserRestrictions(userHandle);
5116794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        bundle.putBoolean(key, value);
5126794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        setUserRestrictions(bundle, userHandle);
5136794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
5146794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
516a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
517a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
5182b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     *
5192b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @param restrictionKey The string key representing the restriction.
5202b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds     * @return {@code true} if the current user has the given restriction, {@code false} otherwise.
521a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
522a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
523b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
524b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
525b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
526b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
527b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
528b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
529b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
530b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
531b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
532b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
533b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
534b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return getUserRestrictions(userHandle).getBoolean(restrictionKey, false);
535a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
536a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
537a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
53833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
539b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
540b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
54133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
542b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
543b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
54433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
54533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
54633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
54733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
54833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
54933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
55033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
55133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
55233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
55333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
55433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
55533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
55633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
55733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
55833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
55933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
56033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        int ident = getUserHandle((int)serialNumber);
56133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
56233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
56333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
56433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
565258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
5661952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
567258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
568258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
569258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
570258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
571258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
572258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
573258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
574258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
575258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
576258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
577258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
578258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
579258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
580258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
581258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
582258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
583258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
584258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
5851e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * Creates a guest user and configures it.
5861e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param context an application context
5871e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @param name the name to set for the user
5881e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     * @hide
5891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani     */
5901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    public UserInfo createGuest(Context context, String name) {
5911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
5921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        if (guest != null) {
5931e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani            Settings.Secure.putStringForUser(context.getContentResolver(),
5941e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
5951e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        }
5961e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani        return guest;
5971e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    }
5981e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani
5991e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani    /**
6002a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Creates a user with the specified name and options as a profile of another user.
601a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
602a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
603a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param name the user's name
604a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @param flags flags that identify the type of user and other properties.
605a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @see UserInfo
6062a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle new user will be a profile of this use.
607a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     *
608a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @return the UserInfo object for the created user, or null if the user could not be created.
609a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     * @hide
610a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy     */
6112a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
612a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
6132a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy            return mService.createProfileForUser(name, flags, userHandle);
614a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
615a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not create a user", re);
616a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
617a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
618a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
619a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
620a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
621df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Sets the user as enabled, if such an user exists.
622df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
623df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * Note that the default is true, it's only that managed profiles might not be enabled.
624df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     *
625df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @param userHandle the id of the profile to enable
626df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     * @hide
627df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina     */
628df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    public void setUserEnabled(int userHandle) {
629df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        try {
630df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            mService.setUserEnabled(userHandle);
631df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        } catch (RemoteException e) {
632df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina            Log.w(TAG, "Could not enable the profile", e);
633df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina        }
634df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    }
635df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina
636df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina    /**
637b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
638b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
639b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
640b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
641b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
642b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
643b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
644b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
645258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
6461952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
647258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
648258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
649258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
650258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
651258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
652920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
653920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
654920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
655920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
656920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
657920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
658920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
659920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
6602a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Returns list of the profiles of userHandle including
6612a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * userHandle itself.
662385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * Note that it this returns both enabled and not enabled profiles. See
663385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina     * {@link #getUserProfiles()} if you need only the enabled ones.
6644f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
6652a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
6662a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @param userHandle profiles of this user will be returned.
6672a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @return the list of profiles.
6682a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     * @hide
6692a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy     */
6702a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy    public List<UserInfo> getProfiles(int userHandle) {
671a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        try {
672385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return mService.getProfiles(userHandle, false /* enabledOnly */);
673a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        } catch (RemoteException re) {
674a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            Log.w(TAG, "Could not get user list", re);
675a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy            return null;
676a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy        }
677a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    }
678a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy
679a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy    /**
680be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns a list of UserHandles for profiles associated with the user that the calling process
681be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * is running on, including the user itself.
6824f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *
6834f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @return A non-empty list of UserHandles associated with the calling user.
6844f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     */
6854f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public List<UserHandle> getUserProfiles() {
6864f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
687385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        List<UserInfo> users = new ArrayList<UserInfo>();
688385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        try {
689f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina            users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
690385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        } catch (RemoteException re) {
691385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            Log.w(TAG, "Could not get user list", re);
692385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina            return null;
693385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina        }
6944f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        for (UserInfo info : users) {
6954f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            UserHandle userHandle = new UserHandle(info.id);
6964f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            profiles.add(userHandle);
6974f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
6984f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return profiles;
6994f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
7004f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
7017dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani    /**
702be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * Returns the parent of the profile which this method is called from
703be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * or null if called from a user that is not a profile.
704be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     *
705be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     * @hide
706be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel     */
707be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    public UserInfo getProfileParent(int userHandle) {
708be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        try {
709be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return mService.getProfileParent(userHandle);
710be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        } catch (RemoteException re) {
711be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            Log.w(TAG, "Could not get profile parent", re);
712be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel            return null;
713be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        }
714be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    }
715be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel
716be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel    /**
7177dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the target user is a managed profile of the calling user or the caller
7187dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * is itself a managed profile, then this returns a badged copy of the given
7197dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * icon to be able to distinguish it from the original icon.
7207dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * <P>
7217dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * If the original drawable is not a BitmapDrawable, then the original
7227dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * drawable is returned.
7237dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * </P>
7247dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *
7257dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param icon The icon to badge.
7267dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @param user The target user.
7277dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     * @return A drawable that combines the original icon and a badge as
7287dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     *         determined by the system.
7297dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani     */
7304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    public Drawable getBadgedDrawableForUser(Drawable icon, UserHandle user) {
7314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        int badgeResId = getBadgeResIdForUser(user.getIdentifier());
7324f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        if (badgeResId == 0) {
7334f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            return icon;
7344f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        } else {
7354f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            Drawable badgeIcon = mContext.getPackageManager()
7364f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani                    .getDrawable("system", badgeResId, null);
7374f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            return getMergedDrawable(icon, badgeIcon);
7384f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
7394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
7404f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
741701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
742701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * If the target user is a managed profile of the calling user or the caller
743f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * is itself a managed profile, then this returns a copy of the label with
744f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * badging for accessibility services like talkback. E.g. passing in "Email"
745f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * and it might return "Work Email" for Email in the work profile.
746f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *
747f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param label The label to change.
748f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @param user The target user.
749f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * @return A label that combines the original label and a badge as
750f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     *         determined by the system.
751f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     */
752f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    public String getBadgedLabelForUser(String label, UserHandle user) {
753f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
754f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
755f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy            return Resources.getSystem().getString(
756f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy                    R.string.managed_profile_label_badge, label);
757f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        }
758f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy        return label;
759f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    }
760f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy
761f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy    /**
762f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy     * If the target user is a managed profile of the calling user or the caller
763701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * is itself a managed profile, then this returns a drawable to use as a small
764701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * icon to include in a view to distinguish it from the original icon.
765701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *
766701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @param user The target user.
767701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return the drawable or null if no drawable is required.
768701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @hide
769701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
770701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    public Drawable getBadgeForUser(UserHandle user) {
771701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(user.getIdentifier());
772701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
773701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            return Resources.getSystem().getDrawable(
774701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy                    com.android.internal.R.drawable.ic_corp_badge);
775701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
776701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
777701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
778701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
7794f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    private int getBadgeResIdForUser(int userHandle) {
7804f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        // Return the framework-provided badge.
781701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        UserInfo userInfo = getUserIfProfile(userHandle);
782701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        if (userInfo != null && userInfo.isManagedProfile()) {
783701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            return com.android.internal.R.drawable.ic_corp_icon_badge;
784701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        }
785701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return 0;
786701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    }
787701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy
788701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    /**
789701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     * @return UserInfo for userHandle if it exists and is a profile of the current
790701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     *         user or null.
791701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy     */
792701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy    private UserInfo getUserIfProfile(int userHandle) {
793be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel        List<UserInfo> userProfiles = getProfiles(getUserHandle());
7945abdbb656063160ff8df2306bd01feba0714d4c1Amith Yamasani        for (UserInfo user : userProfiles) {
795701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy            if (user.id == userHandle) {
796701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy                return user;
7974f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            }
7984f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
799701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy        return null;
8004f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
8014f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
8024f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    private Drawable getMergedDrawable(Drawable icon, Drawable badge) {
8034f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        final int width = icon.getIntrinsicWidth();
8044f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        final int height = icon.getIntrinsicHeight();
8054f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
8064f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        Canvas canvas = new Canvas(bitmap);
8074f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        icon.setBounds(0, 0, width, height);
8084f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        icon.draw(canvas);
8094f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        badge.setBounds(0, 0, width, height);
8104f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        badge.draw(canvas);
8114f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        BitmapDrawable merged = new BitmapDrawable(bitmap);
8124f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        if (icon instanceof BitmapDrawable) {
8134f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani            merged.setTargetDensity(((BitmapDrawable) icon).getBitmap().getDensity());
8144f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        }
8154f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani        return merged;
8164f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    }
8174f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani
8184f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani    /**
8194f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * Returns information for all users on this device. Requires
8204f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * {@link android.Manifest.permission#MANAGE_USERS} permission.
821394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier     *
8224f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     * @param excludeDying specify if the list should exclude users being
8234f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani     *            removed.
824920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
825920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
826920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
827920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
828920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
829920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
830258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
831258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
832258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
833258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
834258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
835258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
836258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
837258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
8381952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
839258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
840258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
841258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
842258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
843258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
844258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
845258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
846258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
847258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
848258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
849258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
850258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
851258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
852258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
8531952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
854258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
855258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
856258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
857258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
858258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
859258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
860258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
861258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
862258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
863258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
864258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
865258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
866258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
867258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
868e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
869258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
870e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
871258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
872258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
873e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
874258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
875e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
876258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
877258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
878258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
879258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
880258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
881258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
8823b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
8833b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
884e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
8853b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
8863b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
887e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
8883b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
8893b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return mService.getUserIcon(userHandle);
8903b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
891e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
8923b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return null;
8933b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
8943b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
8953b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
8963b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
897258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
898258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
899258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
900a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
901258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
90227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
903ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
904ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
905409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        // Svelte devices don't get multi-user.
906409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn        if (ActivityManager.isLowRamDeviceStatic()) return 1;
90727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
90827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
909258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
9102a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
9112a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
9121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * Returns true if the user switcher should be shown, this will be if there
9131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * are multiple users that aren't managed profiles.
9141a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @hide
9151a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     * @return true if user switcher should be shown.
9161a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy     */
9171a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    public boolean isUserSwitcherEnabled() {
9181a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        List<UserInfo> users = getUsers(true);
9191a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        if (users == null) {
9201a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy           return false;
9211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
9221a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        int switchableUserCount = 0;
9231a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        for (UserInfo user : users) {
9241a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            if (user.supportsSwitchTo()) {
9251a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy                ++switchableUserCount;
9261a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy            }
9271a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy        }
928a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
929a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani                Settings.Global.GUEST_USER_ENABLED, 0) == 1;
930a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani        return switchableUserCount > 1 || guestEnabled;
9311a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    }
9321a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy
9331a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy    /**
9342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
9352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
9362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
9372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
9382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
9392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
9402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
9412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
9422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
9432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
9442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
9452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
9462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
9472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
9482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
9492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
9502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
9512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
9522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
9532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
9542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
9552a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
9562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
9572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
9582a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
9592a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
9602a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
9612a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
9622a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
9632a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
9642a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
9652a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
9666794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
9677e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
9687e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
9697e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
9707e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
9717e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
9727e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
9737e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
9747e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
9757e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
9767e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
9777e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
9787e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
9797e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
9807e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
9817e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
9827e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
983df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
984df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
985df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
986df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
9877e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
988df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
9897e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
990df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
991df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
992df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
993df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
994df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
995df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
996df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
997df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
998df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
9997e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
1000df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
1001df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
10027e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
1003df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
1004df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
1005df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
1006df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
1007655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1008655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1009d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
1010d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
1011d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
1012d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
1013655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1014d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
1015655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1016d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.setRestrictionsChallenge(newPin);
1017655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1018655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1019655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1020655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1021655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1022655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1023655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1024655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @hide
1025655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
1026655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * allowing the user to enter the PIN.
1027655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return Returns a positive number (including zero) for how many milliseconds before
1028655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
1029655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
1030655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
1031655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1032d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public int checkRestrictionsChallenge(String pin) {
1033655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1034d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.checkRestrictionsChallenge(pin);
1035655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1036655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not check restrictions pin");
1037655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1038655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return PIN_VERIFICATION_FAILED_INCORRECT;
1039655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
1040655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
1041655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
1042d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @hide
1043655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Checks whether the user has restrictions that are PIN-protected. An application that
1044655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * participates in restrictions can check if the owner has requested a PIN challenge for
1045655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * any restricted operations. If there is a PIN in effect, the application should launch
1046d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
1047d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
1048655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return whether a restrictions PIN is in effect.
1049655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
1050d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean hasRestrictionsChallenge() {
1051655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
1052d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.hasRestrictionsChallenge();
1053655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
1054655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
1055655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
1056655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
1057655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
10581a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
10591a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
10601a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
10611a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
10621a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
10631a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
10641a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
10651a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
10661a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
1067e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1068e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1069e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1070e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Set restrictions that should apply to any future guest user that's created.
1071e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1072e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public void setDefaultGuestRestrictions(Bundle restrictions) {
1073e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1074e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            mService.setDefaultGuestRestrictions(restrictions);
1075e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1076e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1077e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1078e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1079e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani
1080e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    /**
1081e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * @hide
1082e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     * Gets the default guest restrictions.
1083e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani     */
1084e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    public Bundle getDefaultGuestRestrictions() {
1085e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        try {
1086e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            return mService.getDefaultGuestRestrictions();
1087e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        } catch (RemoteException re) {
1088e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani            Log.w(TAG, "Could not set guest restrictions");
1089e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        }
1090e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani        return new Bundle();
1091e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani    }
1092258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
1093